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.
Sorry, I was away for the holidays and missed this topic.
You can take a look at the sample script egimageio1.py found in the OpenFlight API's /samples/scripts folder. This has a lot of information on the topic. Perhaps a little too much! It does show how to allocate the pixels in python as well as how to address them depending on the image type.
For a quick highlight of info, take a look at the code below:
def clear_texels (pixels, width, height): for i in range (0, width * height ): pixels[i] = 0 pixels = mgunsignedchar(width * height) clear_texels (pixels, width, height)
This shows how to allocate the pixel data using mgunsignedchar and passing in the total number of texels for a 1 channel image. (INT)
You need to multiply the number of texels by the channels if you are using more than one channel: ( width * height * channels )
The API documentation shows how to pack the texels in the image. single channel is easy, but multi-channel is not much more complicated. You just need to know the packing order and take that into account when addressing the texels. Sometimes the texels are written in an order like RGBRGBRGB... Other times they are written RRR...RGGG...GBBBB...BAAA...A
Such is the nature of asking questions around the holidays. Hope you had a good time off though!
Perhaps in my reading of documentation I spent too much time reading the API rather than looking through the sample scripts provided. It is as you said: the solution was contained within egimageio1. Notably, I appreciate you clarifying the texel count being multiplied by the number of channels. That was giving me a lot of crashes moving to RGB and RGBA, even after I read the sample script.
I'd say my core issue in applying face colors as textures is thoroughly solved. As this is primarily a work-around for the fbx exporter, might there be documentation detailing what is included and excluded by Creator's fbx importer/exporter plug in?
Glad to hear your workaround is... well working. :)
Unfortunately there is official no documentation on what is included in the FBX exporter. It is always a challenge converting one format to another and the exporter is still evolving. You are not the only person that has had to resort to workaround scripts to get fbx models to satisfy some other software's requirements. At some point we will need to collect the experiences of customers and compile that into a set of improvements, best practices and solid format conversion documentation.
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.