Hello, everyone.
The title is pretty self-explanatory. There isn't much more to be said than that. I'm trying to write a script to get every pixel from every texture applied to a model in Blender 2.79. I've found a URL that is already leading me in the right direction:
https://blender.stackexchange.com/questions/124264/how-to-read-a-pixel-from-an-image-texture-with-pythonHowever, it simply refers to a texture already loaded in memory. I'd like to get the texture or textures specifically from the model itself. If anyone is wondering why I want to get the pixels from textures, it's because I want to be able to convert my textures to C arrays for the N64. Rather than having to do all of the texture conversions outside of Blender - I feel it'd be easier to simply convert the textures already mapped on to the object itself. Additionally, this will help me further in my development processes.
Thank you very much in advance. Any additional help is greatly appreciated.
Replies
I know this looks a bit strange. Basically, I'm exporting the bitmap to be used as a C array of colored pixels for Nintendo 64 homebrew textures. I'm not entirely sure why the for-loop needed three parameters instead of two, but it works as expected. Also, I don't understand why the array needs to get the value of 'i' twice - there's a colon inside, too. Could anyone explain why that part works the way it does? I'm just trying to wrap my head around it. I'm just happy it works as intended. Thanks.
The third arg to the for loop is step size so its looking at 0,4,8 etc.. Rather than 0,1,2,3 etc
It's grabbing groups of pixels, putting them in a list and then you're getting them out of the new list for the output.
- Get the textures of the material (method depends on if you're using nodes, with material.node_tree, or the legacy texture slots from the Blender Render engine, with the iterable material.texture_slots -> slot.texture)