Exchanging color to texture?
-
Yes, but you would have to use a library like ImageMagik though. (free)
-
Ok, thanks.
I'm afraid it sounds a bit over my ability though.
Anyone else interested in doing this? -
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")
-
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?
-
hmm, I tested in SU, PS and TotalCmd Imagine viewer plugin and it works ok
-
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 ?
-
@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.
-
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:
-
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 itdef 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")
-
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? -
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
-
Still doesnt work in Sketchup.
-
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
-
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? -
@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
Advertisement