The OpenFlight API does not have a function to decompose a mesh to polygons. This is a bit too high level for it currently. This is a very straightforward operation however. There is a sample plugin (called meshtest) that shows how to create and to traverse the "primitives" of a mesh.
Following is some pseudo-code that shows you the framework of what you will have to do:
For each primitive in the mesh:
Create a new polygon (mgNewRec (fltPolygon))
Copy the mesh attributes you want to keep to the new polygon created
For each vertex in the mesh primitive:
Create a new vertex in the new polygon (mgNewRec (fltVertex)
Copy the attributes from the mesh primitive vertex to the new vertex created
You can look at the code in the meshtest plugin to see how to traverse the mesh primitives and primitive vertices.
If you have any questions, let us know.
Thanks for the reply, it really helped me get started. I sort of have something working now but I am stuck on copying the attributes for the vertices. I use mgMeshGetVtxCoord and mgMeshGetVtxNormal to get the values from the original mesh and I get the correct values in my variables. When I do mgSetVtxCoord and mgSetVtxNormal on my new vertex only the coordinates are set correctly. My normals are not set and just appear blank in creator.
For the polygons I just used mgGetAttList and mgSetAttList and that seemed to work great. Should I be using the setAttList for my vertices instead of the mgSetVtx calls?
When I do mgSetVtxCoord and mgSetVtxNormal on my new vertex only the coordinates are set correctly. My normals are not set and just appear blank in creator.
Hmmm... this should work, you can use the mgSetVtx functions or mgSetAttList function interchangeably. In fact for vertex normals, mgSetVtxNormal is recommended over mgSetAttList. I am very surprised this is not working for you and suspect something else may be the culprit after you "set" the normal - something during the file save and the subsequent re-opening of it.
Let's start some debugging...
First... if you're not already doing this, check the return value of mgSetVtxNormal (it returns mgbool you can check). If it succeeds immediately call mgGetVtxNormal to see if the vertex normal is there at that moment. Finally before you save, there is a fltHeader field called fltHdrSaveVtxNorms. Make sure this is not MG_FALSE. If it is, this would explain why the normals don't show up after you save/reopen the file.
Let us know what you find out.
Also, can you tell me which version of the OpenFlight API you are using?
fltHdrSaveVtxNorms was set to false. Changing that to true fixed it and now my normals are being copied correctly. Thank you so much!
I am using API 13
When I set the color index on my vertex through creator the rgb and intensity values are updated automatically. When I set it through mgSetAttList and open in creator the values are all 0. Is there something I can call to update those values?
This should be fine... Can you show us the code you are using to call mgSetAttList? There may be something there that is not correct.
mgSetAttList(vtxRec, fltVColor, colorIndex, fltVU, u0, fltVV, v0, fltLayerU1, u1, fltLayerV1, v1, MG_NULL);
Everything seems to be set correctly, other than rgb and intensity are 0. Also, the vertex I am looking at returns -1 as colorIndex when I call mgMeshGetVtxColor. That value seems to work fine when I enter it through the UI though so I don't think its the problem.
You are not setting the intensity. If it is 0, then RGBs would all be 0. Try setting fltVIntensity on the vertex also (normally you will set it to 1.0 unless you want a darker shade of fltVColor).
mgSetAttList(vtxRec, fltVColor, -1, fltVIntensity, 1.0, fltVU, u0, fltVV, v0, fltLayerU1, u1, fltLayerV1, v1, MG_NULL);
but the value is still 0 for the intensity and rgbs :(
Hmmm... I can't explain that. I cut/pasted your code into a sample plugin here and I don't see what you're seeing. Are you looking on the Vertex Attribute page in Creator? Or are you looking somewhere else at the RGB values? Is your db Color Index or RGB (check fltHeader fltHdrRgbMode attribute) ?
Also some things to check:
1) Is mgSetAttList returning the correct number? It returns the number of attributes successfully set. In your case it should be 6.
2) What happens in your program after you call mgSetAttList? Perhaps something after mgSetAttList is causing the problem? Have you tried calling mgGetAttList immediately after to check the new values set?
I am looking at the vertex attribute page. fltHdrRgbMode returns false (so this means im in index mode I think?)
mgSetAttList returns 6
calling mgGetAttList immediately after mgSetAttList returns the correct values.
After the set call I do nothing more other than append to parent node and move on to next vertex.
I really appreciate all the help Steve.
After you append and do more vertices, are you saving and reopening in Creator? You might try setting up a function that calls mgGetAttList for the attrs you want to check and keep calling that function after each subsequent step in your procedure. At some point, it sure sounds like the values are getting whacked.
If the file is small enough, you can zip it up and post on the forum. I can run it through a raw OpenFlight record parser to see what the vertex colors are before Creator has a chance at them.
Here is the output of my program.
Got it... which vertex should I look at? I just grabbed several at random and see all RGB and intensities correct. Here is a typical vertex attr page:
In the creator application there is a decompose mesh function that converts meshes to faces. This is pretty much exactly what I need my program to do. I haven't had a chance to use this API before so I was just wondering if there is a call I can make or some sort of sample code I could look at that does this before I get started?