sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Exchanging color to texture?

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 4 Posters 1.7k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      todd burch
      last edited by

      Yes, you would just need a lookup table to map the color to the texture. Then, iterate through the model, looking for a material of that color and swapping it out for the texture.

      Todd

      1 Reply Last reply Reply Quote 0
      • PixeroP Offline
        Pixero
        last edited by

        Would it also be possible to actually create a corresponding png or jpg texture from within SketchUp with that color and apply it?

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by

          Yes, but you would have to use a library like ImageMagik though. (free)

          1 Reply Last reply Reply Quote 0
          • PixeroP Offline
            Pixero
            last edited by

            Ok, thanks.
            I'm afraid it sounds a bit over my ability though.
            Anyone else interested in doing this?

            1 Reply Last reply Reply Quote 0
            • tbdT Offline
              tbd
              last edited by

              here is a small test that creates an 8bit indexed pallete png that works in SU
              (dont know if your engine supports it)

              you then go through all color materials, create pngs and replace the color with those textures

              def create_small_png(red,green,blue, filename)
              
                small_png = %{iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAMAAACeL25MAAAABlBMVEUAAP8A
                AAB7Yr8+AAAADklEQVR42mJgwAQAAQYAABQAAWhJMmMAAAAASUVORK5CYII=
                }.unpack("m").to_s
                color_pos = 41
              
                small_png[color_pos]   = red.chr
                small_png[color_pos+1] = green.chr
                small_png[color_pos+2] = blue.chr
                
                File.open(filename,"wb") {|x| x.write small_png}  
              end
              
              create_small_png(255,255,0,"d;/test.png")
              

              SketchUp Ruby Consultant | Podium 1.x developer
              http://plugins.ro

              1 Reply Last reply Reply Quote 0
              • PixeroP Offline
                Pixero
                last edited by

                Thanks, I just tested the code and there seem to be something wrong with the file that it creates. I cant open it in any image editor I have including Photoshop. Says cant parse the file. Any ideas?

                1 Reply Last reply Reply Quote 0
                • tbdT Offline
                  tbd
                  last edited by

                  hmm, I tested in SU, PS and TotalCmd Imagine viewer plugin and it works ok

                  SketchUp Ruby Consultant | Podium 1.x developer
                  http://plugins.ro

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    Masta Squidge
                    last edited by

                    Couldn't you just go through the colors after you placed them all and then manually edit each one to the texture you want? this would automatically replace every color in the model with the texture you change it to. I do it on most of my models. Granted my models stink half the time but hey, it works. Like say, you want Grey (or is it Gray 😛) to be a wall texture on a bunch of different walls, but not all of them. Just paint the grey color on the walls then edit that material later. It also doesnt mess up the default colors of SU and on a new file they load default. Im guessing you use colors as placeholders (thats what I do) because textures slow down SU?

                    Or am I missing something totally and have no idea what you are talking about 😮 ?

                    1 Reply Last reply Reply Quote 0
                    • PixeroP Offline
                      Pixero
                      last edited by

                      @masta squidge said:

                      Couldn't you just go through the colors after you placed them all and then manually edit each one to the texture you want? this would automatically replace every color in the model with the texture you change it to. I do it on most of my models. Granted my models stink half the time but hey, it works. Like say, you want Grey (or is it Gray 😛) to be a wall texture on a bunch of different walls, but not all of them. Just paint the grey color on the walls then edit that material later. It also doesnt mess up the default colors of SU and on a new file they load default. Im guessing you use colors as placeholders (thats what I do) because textures slow down SU?

                      Or am I missing something totally and have no idea what you are talking about 😮 ?

                      I'm currently evaluating a possible future workflow for real time presentations. (Modelling in SketchUp, lightmapping in another program and finally viewing in a third.)
                      Doing it once or twice is one thing. Doing it a lot of times is another. Therefor I'm looking into a automated way of doing it.

                      TBD, I have to look into this further.

                      1 Reply Last reply Reply Quote 0
                      • PixeroP Offline
                        Pixero
                        last edited by

                        I still havent got this to work.
                        TBD, I've tried your code on several PC's and it creates a png but I still can´t open it with either photoshop or sketchup.
                        Any ideas? Is there another way?

                        Edit: I opened the created png in a texteditor and it looks like this:

                        ‰PNG
                        SUB
                        NUL NUL NUL
                        IHDR NUL NUL NUL EOT NUL NUL NUL EOT BS ETX NUL NUL NUL ž/nL NUL NUL NUL ACK PLTEÿÿ NUL NUL
                        
                        

                        Another edit: I attach the png:


                        test.png

                        1 Reply Last reply Reply Quote 0
                        • tbdT Offline
                          tbd
                          last edited by

                          can you open this png ? it was generated from the code posted above
                          I can see it with TotalCmd image viewer, but Sketchup cannot use it 😞

                          
                          def create_small_png(red,green,blue, filename)
                          
                            small_png = %{iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAAA1BMVEX/AAAZ4gk3AAAACklEQVQYV2NgAAAAAgABo9o9lAAAAABJRU5ErkJggg==}.unpack("m").to_s
                            color_pos = 41
                          
                            small_png[color_pos]   = red.chr
                            small_png[color_pos+1] = green.chr
                            small_png[color_pos+2] = blue.chr
                           
                            File.open(filename,"wb") {|x| x.write small_png} 
                          end
                          
                          create_small_png(255,0,0,"d;/test.png")
                          
                          

                          test.zip

                          SketchUp Ruby Consultant | Podium 1.x developer
                          http://plugins.ro

                          1 Reply Last reply Reply Quote 0
                          • PixeroP Offline
                            Pixero
                            last edited by

                            I can open your image in Photoshop but not in SketchUp. So no good. 😞
                            Is there a way of having the png as rgb instead of as indexed pallete png?
                            Is that why its not working in SketchUp?

                            1 Reply Last reply Reply Quote 0
                            • tbdT Offline
                              tbd
                              last edited by

                              have you tried latest code (forgot to modify the text on the message as well) - for me it works in Sketchup as well.
                              weird as the material shows as color based, not as texture - but it works.

                              I used a an indexed because it is easier to change colors and have a base png to start of. using a rgb is much more harder and needs more code for it 😉

                              SketchUp Ruby Consultant | Podium 1.x developer
                              http://plugins.ro

                              1 Reply Last reply Reply Quote 0
                              • PixeroP Offline
                                Pixero
                                last edited by

                                Still doesnt work in Sketchup.

                                1 Reply Last reply Reply Quote 0
                                • tbdT Offline
                                  tbd
                                  last edited by

                                  here it works 😄 ... it creates an 82 bytes png, which I can drag and drop
                                  in SU (using ALT to have it fill the face underneath the bucket)

                                  as I said before - works only in Shaded mode, in Shaded with Textures I get a white face 😲

                                  SketchUp Ruby Consultant | Podium 1.x developer
                                  http://plugins.ro

                                  1 Reply Last reply Reply Quote 0
                                  • PixeroP Offline
                                    Pixero
                                    last edited by

                                    Tried again and on a different PC still not working in SU.
                                    How would the RGB way look?

                                    If I open the png in PS and change it to RGB it works the way you say in SU but not in textured mode.
                                    What if the image was bigger say 64x64 pixels?

                                    1 Reply Last reply Reply Quote 0
                                    • tbdT Offline
                                      tbd
                                      last edited by

                                      @unknownuser said:

                                      How would the RGB way look?

                                      a lot more complicated 😄 ... you can try to save as png, find the offset inside the file where color is store, pack("m")

                                      @unknownuser said:

                                      What if the image was bigger say 64x64 pixels?

                                      donno. i used 1x1 pixel to keep the file to minimum

                                      make a hash of the file that you create via the script to see if it is written properly

                                      SketchUp Ruby Consultant | Podium 1.x developer
                                      http://plugins.ro

                                      1 Reply Last reply Reply Quote 0
                                      • 1 / 1
                                      • First post
                                        Last post
                                      Buy SketchPlus
                                      Buy SUbD
                                      Buy WrapR
                                      Buy eBook
                                      Buy Modelur
                                      Buy Vertex Tools
                                      Buy SketchCuisine
                                      Buy FormFonts

                                      Advertisement