Hi, there. I have been looking at the Autodesk 3ds Maxscript documentation lately. I believe that this piece of code I have should work, but for some reason it does not. So, "theBitmap" code appears to work - I don't receive errors. But, "thePixels" code appears to throw errors. I don't know why it would when "theBitmap" is already opened for reading. I must be missing something small. Basically, I want to read all of the pixels from the bitmap, and print them to hex in an array as: 0xRRGGBBAA. The texture is 32x32 in size, so I only need to loop through 1024 times.
texel_count = 0
format "unsigned int %[] = { \n" (getFilenameFile(selection[1].material.diffusemap.filename)) to:fStream
theBitmap = openbitmap(getFilenameFile(selection[1].material.diffusemap.filename))
thePixels = getPixels theBitmap [0,0] 1 linear:false
for i = 1 to 1024 do
(
format "%%%%%" (bit.intashex(thePixels.r)) (bit.intashex(thePixels.g)) (bit.intashex(thePixels.b)) (bit.intashex(255)) "," to:fStream
texel_count += 1
if (texel_count >= 32) do
(
format " \n" to:fStream
texel_count = 0
)
)
format "}; \n" to:fStream
format " \n" to:fStream
I am aware that "thePixels" line of code is only looking at the top corner: [0,0]. But, in order to at least check the other pixels in the array, I must figure out how to read the first one. I will keep working to see if I can figure this out. I appreciate any help and advice that I can receive. Thanks.
Replies
I think you're misunderstanding how the bitmap data is structured. It's been ages so I'm sure there's a more elegant way to collect the data etc. But it should get you going.
Thank you for taking the time to help me out. I agree, I'm definitely misunderstanding the structure. This explains a lot of things actually. I don't want to have to select the bitmap, although I may have to in this regard. I've been working on a batch exporter for textured models, and wanted to be able to get the textured bitmap from the objects they're applied to, just so I wouldn't have to go and load each one at a time. The objects already have materials and textures applied to those materials - if that makes sense. Although, I guess I could load the textures before hand, and just save them all in the right format.
Thank you very much, I will see what I can do.
Edit: It seems to have trouble trying to get the colors. Either 'r', 'red', or even 'x' return as undefined.
Thank you so much for your examples! Honestly, I don't know why Maxscript has been acting this way recently. Perhaps my loops are off by a single number. I will try these out and see what I can do. I really appreciate this.
Here is my final code:
Those functions will definitely come in handy. I just thought of it now, but I should also check if the "count" is greater than or equal to the width of the image, then go to the next line. As it is, the code is best for 32x32 sizes. You're awesome! Thanks again for your work; it really means a lot to me.