Currently this works to achieve the goal, but it is very slow as the number of verts increases.
I was hoping someone might know a faster way of doing this. (I removed all the checks of MStatus because it just took up space in this example. In my code it is actually there)
I am using my exported code in OpenGL and need the Number of UV's, Normals and Verts to match up.
This is using Maya 6.0.
Here is a current exporter version snip:
MDagPath dagPath;
// create dag iterator that looks for meshes
MStatus status;
MItDag dagIterator( MItDag::kDepthFirst, MFn::kMesh, &status);
std::vector<VertUVNormalSet> tempVert;
VertUVNormalSet m\_Face[3];
unsigned int face = 0;
// iterate through all meshes
for ( ; !dagIterator.isDone(); dagIterator.next() )
{
// get dag path of current mesh
MStatus status = dagIterator.getPath( dagPath );
// make a copy mesh to read
MFnMesh mesh( dagPath, &status);
MPointArray meshPositions;
MFloatVectorArray meshNormals;
MFloatArray meshUs,meshVs;
// get positions, nomals, uvs of each mesh
mesh.getPoints( meshPositions, MSpace::kWorld ); //gets array of points of mesh
mesh.getNormals( meshNormals, MSpace::kWorld ); //gets array of normal points of mesh
mesh.getUVs( meshUs, meshVs ); //gets array's of U and V of mesh
////////////////////////////////////////////////////////////////////////////////////////////////////////
// make a polygon iterator to traverse each face in a mesh
MItMeshPolygon faceIterator( dagPath, MObject::kNullObj, &status );
int index;
// Get All Position/Normals/UVs from the face List and put them in a temporary Buffer
for ( ; !faceIterator.isDone(); faceIterator.next() )
{
// get position of each vert
m\_Face[ 0 ].pos = meshPositions[ faceIterator.vertexIndex( 0 ) ];
m\_Face[ 1 ].pos = meshPositions[ faceIterator.vertexIndex( 1 ) ];
m\_Face[ 2 ].pos = meshPositions[ faceIterator.vertexIndex( 2 ) ];
// get normal of each vert
m\_Face[ 0 ].nor = meshNormals[faceIterator.normalIndex( 0 ) ];
m\_Face[ 1 ].nor = meshNormals[faceIterator.normalIndex( 1 ) ];
m\_Face[ 2 ].nor = meshNormals[faceIterator.normalIndex( 2 ) ];
// get uv coords of each vert
faceIterator.getUVIndex(0,index);
m\_Face[0].u =meshUs[index];
m\_Face[0].v =meshVs[index];
faceIterator.getUVIndex(1,index);
m\_Face[1].u =meshUs[index];
m\_Face[1].v =meshVs[index];
faceIterator.getUVIndex(2,index);
m\_Face[2].u =meshUs[index];
m\_Face[2].v =meshVs[index];
// Should have Duplicates
tempVert.push\_back(m\_Face[0]);
tempVert.push\_back(m\_Face[1]);
tempVert.push\_back(m\_Face[2]);
m\_vFaces.push\_back(face++);
m\_vFaces.push\_back(face++);
m\_vFaces.push\_back(face++);
}
VertCount += mrfVerts.size();
////////////////////////////////////////////////////////////////////////////////////////////////////////
}
unsigned i = 0;
for(; i < tempVert.size(); i++)
{
bool Push = true;
if(!mrfVerts.empty())
{
int VertUVNormalSetToCheckIndex = 0;
for( ; VertUVNormalSetToCheckIndex !=mrfVerts.size(); VertUVNormalSetToCheckIndex++)
{
// Check to see if CurrentVert a copy of an another vert
if(tempVert[i] == mrfVerts[VertUVNormalSetToCheckIndex])
{
// Set Reference to point already in mrfVert List.
m\_vFaces[i]=VertUVNormalSetToCheckIndex;
Push=false;
break;
}
}
}
if(Push)
{
m\_vFaces[i] = (unsigned int) mrfVerts.size();
mrfVerts.push\_back(tempVert[i]);
}
}