// ---------------------------------------- uint GeometryPolygonExporter::getShaderPolygonsCount( const MFnMesh &fnMesh ) { uint numPolygons = 0; // Iterate through all polygons of the current mesh. // Check their polygons for holes and retrieve the vertexCountList. MItMeshPolygon meshPolygonsIter ( fnMesh.object() ); for ( meshPolygonsIter.reset(); !meshPolygonsIter.isDone(); meshPolygonsIter.next() ) { // Is this polygon shaded by this shader? int polyIndex = meshPolygonsIter.index(); uint realShaderCount = ( uint ) mShaders.length(); if ( mShaderPosition < realShaderCount && ( uint ) mShaderIndices[polyIndex] != mShaderPosition ) continue; if ( mShaderPosition >= realShaderCount && ( mShaderIndices[polyIndex] >= 0 && mShaderIndices[polyIndex] < ( int ) realShaderCount ) ) continue; // Get the polygon count uint numMeshPolygons = 0, numVertices = 0; // Get the number of vertices in the current mesh's polygon int polygonVertexCount = meshPolygonsIter.polygonVertexCount(); if ( triangulated && polygonVertexCount > 3 ) { int numTriangles; meshPolygonsIter.numTriangles ( numTriangles ); if ( numTriangles > 0 ) numMeshPolygons = (uint) numTriangles; } else if ( polygonVertexCount >= 3 ) { numMeshPolygons = 1; } numPolygons += numMeshPolygons; } return numPolygons; }
// -------------------------------------------------------- void GeometryPolygonExporter::retrieveVertexIndices ( MIntArray &vertexIndices, MItMeshPolygon &meshPolygonsIter, uint &numPolygons, uint &numVertices ) { // Get the number of vertices in the current mesh's polygon int polygonVertexCount = meshPolygonsIter.polygonVertexCount(); if ( triangulated && polygonVertexCount > 3 ) { int numTriangles; meshPolygonsIter.numTriangles ( numTriangles ); if ( numTriangles > 0 ) { numVertices = 3; MPointArray vertexPositions; MIntArray meshVertexIndices; meshPolygonsIter.getTriangles ( vertexPositions, meshVertexIndices ); vertexIndices.setLength ( meshVertexIndices.length() ); numPolygons = meshVertexIndices.length() / numVertices; // Map the vertex indices to iterator vertex indices so that we can // get information from the iterator about normals and such. uint meshVertexIndexCount = meshVertexIndices.length(); for ( uint mvi = 0; mvi < meshVertexIndexCount; ++mvi ) { int meshVertexIndex = meshVertexIndices[mvi]; int polygonVertexCount = meshPolygonsIter.polygonVertexCount(); int iteratorVertexIndex = 0; for ( int pv = 0; pv < polygonVertexCount; ++pv ) { if ( ( int ) meshPolygonsIter.vertexIndex ( pv ) == meshVertexIndex ) { iteratorVertexIndex = pv; } } vertexIndices[mvi] = iteratorVertexIndex; } } else numPolygons = 0; } else if ( polygonVertexCount >= 3 ) { numPolygons = 1; vertexIndices.setLength ( polygonVertexCount ); for ( int pv = 0; pv < polygonVertexCount; ++pv ) { vertexIndices[pv] = pv; } #ifdef VALIDATE_DATA // Skip over any duplicate vertices in this face. // Very rarely, a cunning user manages to corrupt // a face entry on the mesh and somehow configure // a face to include the same vertex multiple times. // This will cause the read-back of this data to // reject the face, and can crash other COLLADA // consumers, so better to lose the data here for ( uint n = 0; n < vertexIndices.length() - 1; ++n ) { for ( uint m = n + 1; m < vertexIndices.length(); ) { if ( vertexIndices[n] == vertexIndices[m] ) { vertexIndices.remove ( m ); } else ++m; } } // Get the number of vertices of the current polygon. numVertices = vertexIndices->length(); #else // Get the number of vertices of the current polygon. numVertices = polygonVertexCount; #endif } }