Start a new topic

Adding New Textures to a DB Via Script

Original Post by: Fri Jun 24 17:16:58 2016


I am currently importing files from a different digital content creation package into Creator, and have noticed that the export to OpenFlight process only brings over diffuse textures. I started to work on a script that would copy the UVs and texture from the default layer 0 to layer 1, and my hope was to replace the diffuse texture with a similarly named specular texture after that point.


The issue I am running into, however, is that the specular texture is not currently in the scene, and I am unsure if there is a way to import a new texture via scripting.


I was shown that to do it manually you can open the Texture Palette window and navigate to File > Read Pattern..., but I couldn't find anything similar to Read Pattern under the Creator Script Tools, nor did I find much in the OpenFlight API documentation, either.


Has anyone tried this or a different method for applying specular maps to a new texture layer procedurally?


Original Post by: SteveThompson Fri Jun 24 18:34:46 2016


There are a couple different steps needed here.

First, you need to read the texture into the DB palette. There are a few ways to do this using OpenFlightScript. Check mgReadTexture for the details.This will let you load the texture into the palette and return to you the index of the texture added.

Next you need to assign that texture index to the corresponding texture layer attribute on the polygon. You assign all attributes using mgSetAttList again in OpenFlight script. You can find all the attributes of all nodes (and the one you need is fltTextureLayer1) in the OpenFlight Data Dictionary (part of the OpenFlight API reference).

Finally you need to set up the UVs on that layer. That's a bit trickier. You can use OpenFlight Script to manually copy the corresponding attributes of the vertices using mgGetAttList (to get the UVs you want to copy) and mgSetAttList to assign those values to the destination layer attribute. Again use OpenFlight Data Dictionary to get vertex attribute codes you need.

Another way to copy UVs from one layer to another is the Creator Script command "Copy Texture Layers". This corresponds to the similarly named command in Creator to which you specify the source and destination layers.


For further information on the first two parts, check the OpenFlight Users/Developer Guide Volume 1. There is a whole chapter on Textures which describes in much more detail what I have outlined here.


Also do search this and the OpemFlight API forum. This (or similar) question has been raised before and you are likely to find more good info there.


And finally check the sample code (both c language and OpenFlight Scripts) included with the API SDK. There are some there that do what you are asking about.


Good luck and let us know if you have further questions.

Original Post by: Fri Jun 24 19:05:08 2016


Check mgReadTexture for the details.This will let you load the texture into the palette and return to you the index of the texture added. Next you need to assign that texture index to the corresponding texture layer attribute on the polygon. You assign all attributes using mgSetAttList again in OpenFlight script. You can find all the attributes of all nodes (and the one you need is fltTextureLayer1) in the OpenFlight Data Dictionary (part of the OpenFlight API reference).

Finally you need to set up the UVs on that layer. That's a bit trickier. You can use OpenFlight Script to manually copy the corresponding attributes of the vertices using mgGetAttList (to get the UVs you want to copy) and mgSetAttList to assign those values to the destination layer attribute. Again use OpenFlight Data Dictionary to get vertex attribute codes you need.

Another way to copy UVs from one layer to another is the Creator Script command "Copy Texture Layers". This corresponds to the similarly named command in Creator to which you specify the source and destination layers.


Thank you, mgReadTexture was exactly what I was looking for to get me headed in the right direction.


For further information on the first two parts, check the OpenFlight Users/Developer Guide Volume 1. There is a whole chapter on Textures which describes in much more detail what I have outlined here.


Also do search this and the OpemFlight API forum. This (or similar) question has been raised before and you are likely to find more good info there.


And finally check the sample code (both c language and OpenFlight Scripts) included with the API SDK. There are some there that do what you are asking about.


Good luck and let us know if you have further questions.


I did a couple searches of the forums but since I didn't know exactly what I was looking for, I didn't find much that was applicable to my specific problem. I will however check out the OpenFlight Users/Developer Guide Volume 1, as I don't think I have referenced that yet, but I have been skimming through the other API documentation and code samples.


Thanks again!

Login to post a comment