// --------------------------------------------------------
void GeometryPolygonExporter::exportPolygonSources (
    MFnMesh& fnMesh,
    const String& meshId,
    MStringArray& uvSetNames,
    MStringArray& colorSetNames,
    Sources* polygonSources,
    Sources* vertexSources,
    const bool hasFaceVertexNorms )
{
    // Initialize the members
    mMeshId = meshId;
    mUvSetNames = uvSetNames;
    mPolygonSources = polygonSources;
    mVertexSources = vertexSources;
    mHasFaceVertexNormals = hasFaceVertexNorms;
    mColorSetNames = colorSetNames;

    // If triangulation is requested, verify that it is
    // feasible by checking with all the mesh polygons
    if ( ExportOptions::exportTriangles() )
    {
        triangulated = true;

        for ( MItMeshPolygon polyIt ( fnMesh.object() ); triangulated && !polyIt.isDone(); polyIt.next() )
        {
            triangulated = polyIt.hasValidTriangulation();
        }
    }

    // If we have a hole in a polygon, we can't write a <polylist>.
    // Either we write <polygons> with holes or we write triangles.
    // Get hole information from the mesh node.
    // The format for the holes information is explained in the MFnMesh documentation.
    MStatus status;
    fnMesh.getHoles ( mHoleInfoArray, mHoleVertexArray, &status );
    holeCount = ( status != MStatus::kSuccess ) ? 0 : ( mHoleInfoArray.length() / 3 );

    // Find how many shaders are used by this instance of the mesh.
    // Each instance may apply a number of different materials to different faces.
    // We can use the getConnectedShaders member function of MFnMesh to find out
    // this shader information for each instance.
    mShaders.clear();
    mShaderIndices.clear();
    fnMesh.getConnectedShaders ( 0, mShaders, mShaderIndices );

    // Find the polygons that correspond to each materials and export them.
    uint realShaderCount = ( uint ) mShaders.length();
    uint numShaders = ( uint ) std::max ( ( size_t ) 1, ( size_t ) mShaders.length() );

    for ( uint shaderPosition=0; shaderPosition<numShaders; ++shaderPosition )
    {
        // Set the current shader position
        mShaderPosition = shaderPosition;

        // Export the polygons of the current shader
        exportShaderPolygons ( fnMesh );
    }
}