private void computeMeshData() { foreach (MayaMesh mesh in allMeshes) { // Get the Maya mesh MFnMesh mayaMesh = new MFnMesh(mesh.mayaObjectPath); // Does the maya mesh have UVs? MStringArray uvSetNames = new MStringArray(); mayaMesh.getUVSetNames(uvSetNames); bool hasUvs = (uvSetNames.length > 0) && (mayaMesh.numUVs(uvSetNames[0]) > 0); // Iterate through all of the vertices and build the data. MItMeshFaceVertex it = new MItMeshFaceVertex(mesh.mayaObjectPath); while (!it.isDone) { // Create a new vertex and populate its data. Vertex vert = new Vertex(); // Get the local position relative to the world origin. MPoint mayaPos = it.position(MSpace.Space.kObject); vert.position = new Vector3((float)mayaPos.x, (float)mayaPos.y, (float)mayaPos.z); //vert.position = new Vector3((float)mayaPos.x - mesh.sourceXForm.mayaWorldPosition.x, //(float)mayaPos.y - mesh.sourceXForm.mayaWorldPosition.y, //(float)mayaPos.z - mesh.sourceXForm.mayaWorldPosition.z); // Get the normal. MVector mayaNrm = new MVector(); it.getNormal(mayaNrm, MSpace.Space.kObject); vert.normal = new Vector3((float)mayaNrm.x, (float)mayaNrm.y, (float)mayaNrm.z); // Texcoords. if (hasUvs && it.hasUVsProperty) { float[] mayaUvs = new float[2]; it.getUV(mayaUvs, uvSetNames[0]); vert.texcoord = new Vector2(mayaUvs[0], mayaUvs[1]); } // Append the vertex. mesh.vertices.Add(vert); it.next(); } // Get all index data. MIntArray mia1 = new MIntArray(); MIntArray mia2 = new MIntArray(); mayaMesh.getTriangleOffsets(mia1, mia2); foreach (int idx in mia2) { mesh.indices.Add((uint)idx); } } }
private void computeMeshData() { foreach( MayaMesh mesh in allMeshes ) { // Get the Maya mesh MFnMesh mayaMesh = new MFnMesh(mesh.mayaObjectPath); // Does the maya mesh have UVs? MStringArray uvSetNames = new MStringArray(); mayaMesh.getUVSetNames(uvSetNames); bool hasUvs = (uvSetNames.length > 0) && (mayaMesh.numUVs(uvSetNames[0]) > 0); // Iterate through all of the vertices and build the data. MItMeshFaceVertex it = new MItMeshFaceVertex(mesh.mayaObjectPath); while( !it.isDone ) { // Create a new vertex and populate its data. Vertex vert = new Vertex(); // Get the local position relative to the world origin. MPoint mayaPos = it.position(MSpace.Space.kObject); vert.position = new Vector3((float)mayaPos.x, (float)mayaPos.y, (float)mayaPos.z); //vert.position = new Vector3((float)mayaPos.x - mesh.sourceXForm.mayaWorldPosition.x, //(float)mayaPos.y - mesh.sourceXForm.mayaWorldPosition.y, //(float)mayaPos.z - mesh.sourceXForm.mayaWorldPosition.z); // Get the normal. MVector mayaNrm = new MVector(); it.getNormal(mayaNrm, MSpace.Space.kObject); vert.normal = new Vector3((float)mayaNrm.x, (float)mayaNrm.y, (float)mayaNrm.z); // Texcoords. if( hasUvs && it.hasUVsProperty ) { float[] mayaUvs = new float[2]; it.getUV(mayaUvs, uvSetNames[0]); vert.texcoord = new Vector2(mayaUvs[0], mayaUvs[1]); } // Append the vertex. mesh.vertices.Add(vert); it.next(); } // Get all index data. MIntArray mia1 = new MIntArray(); MIntArray mia2 = new MIntArray(); mayaMesh.getTriangleOffsets(mia1, mia2); foreach( int idx in mia2 ) { mesh.indices.Add((uint)idx); } } }