Start a new topic

Save a Color to a Texture

Hello. I'm currently exploring using Creator to export FBX files. I noticed that FBX files exported retain any textures assigned, but do not contain assigned colors. Thus, if exporting colors in FBX is not an option, I was wondering if I could add the colors to my texture palette via script?

My strategy is to search for every face with a color assigned but no texture, capture that color, then create a new texture that is filled in with said color. I believe I can manage coding the attribute searches necessary to identify faces that meet my criteria, and how to get a snapshot of a color. What I am having great trouble with is creating and editing a texture's texel components via script. mgNewTexture seemed like the place to start, but in using Python, I am unsure how to input the texels as an unsigned char * for the function's third argument. I tried arrays, strings, arrays of strings, and more, but am unsure of what this is asking for me or what the Python equivalent of this is.

I did note that I can manually create a blank texture pattern, then edit it with any color in my color palette. I'm unsure how to do this via code, if it is possible at all.

Any help and insight would be appreciated. Thank you for your time.

Alex Wiese

1 Comment

I looked further into my troubles - particularly regarding mgNewTexture and texels.

My copying the texels from a pre-existing image, I was able to apply those in mgNewTexture to create a texture, add it to the palette, and save it to disk as an rgb file. I found functions named mgSetTextureTexels and mgGetTextureTexels, which then point to mgReadImage and mgWriteImage explaining how to pack pixel data as type MIMG_RGB or something similar. 

This is probably the answer I am looking for, but I still have not found any examples of what an unsigned char * data type would look like in Python besides calling a function that gets it. Moreover, assuming I understand texels as "a texture's pixels" and not something else, copying the texels from one image to another did not maintain the size of the image nor the pixel color values. the documentation in mgGetTextureTexels does state not to assign the value directly, which may be the problem. 

In short: I still do not understand how to call mgNewTexture without having a preexisting texture from which to grab texels, and I am still not sure of a way to change a texture's individual pixel color values through code.

Login to post a comment