private static void unpackDynMesh(Mesh dynMesh, out MIntArray faceCnx, out MFloatPointArray verticies, out MIntArray faceVtxCt) { MIntArray m_faceCnx = new MIntArray(); MFloatPointArray m_verticies = new MFloatPointArray(); MIntArray m_faceVtxCt = new MIntArray(); MFloatPoint vtxToAdd = new MFloatPoint(); foreach (var vtx in dynMesh.VertexPositions) { if (MGlobal.isZAxisUp) { vtxToAdd.x = (float)vtx.X; vtxToAdd.y = (float)vtx.Y; vtxToAdd.z = (float)vtx.Z; } else { vtxToAdd.x = (float)vtx.X; vtxToAdd.y = (float)vtx.Z; vtxToAdd.z = -(float)vtx.Y; } m_verticies.Add(vtxToAdd); } foreach (var fidx in dynMesh.FaceIndices) { int vtxCt = (int)fidx.Count; m_faceVtxCt.Add(vtxCt); if (vtxCt == 3) { m_faceCnx.Add((int)fidx.A); m_faceCnx.Add((int)fidx.B); m_faceCnx.Add((int)fidx.C); } else { m_faceCnx.Add((int)fidx.A); m_faceCnx.Add((int)fidx.B); m_faceCnx.Add((int)fidx.C); m_faceCnx.Add((int)fidx.D); } } verticies = m_verticies; faceCnx = m_faceCnx; faceVtxCt = m_faceVtxCt; }
private static void unpackTsMesh(TSplineSurface tsMesh, out MIntArray faceCnx, out MFloatPointArray verticies, out MIntArray faceVtxCt) { MIntArray m_faceCnx = new MIntArray(); MFloatPointArray m_verticies = new MFloatPointArray(); MIntArray m_faceVtxCt = new MIntArray(); MFloatPoint vtxToAdd = new MFloatPoint(); var tsMeshCompress = tsMesh.CompressIndexes(); foreach (var vtx in tsMeshCompress.Vertices) { if (MGlobal.isZAxisUp) { vtxToAdd.x = (float)vtx.PointGeometry.X; vtxToAdd.y = (float)vtx.PointGeometry.Y; vtxToAdd.z = (float)vtx.PointGeometry.Z; } else { vtxToAdd.x = (float)vtx.PointGeometry.X; vtxToAdd.y = (float)vtx.PointGeometry.Z; vtxToAdd.z = -(float)vtx.PointGeometry.Y; } m_verticies.Add(vtxToAdd); } foreach (var fidx in tsMeshCompress.Faces) { int vtxCt = fidx.Vertices.Length; m_faceVtxCt.Add(vtxCt); foreach (var fVert in fidx.Vertices) { m_faceCnx.Add(fVert.Index); } } verticies = m_verticies; faceCnx = m_faceCnx; faceVtxCt = m_faceVtxCt; }
public static bool ToMayaOLD(Mesh MeshToSend, string name) { bool nodeExists = false; MDagPath node = null; Task checkNode = null; Task mobjMesh = null; try { checkNode = Task.Factory.StartNew(() => node = DMInterop.getDagNode(name)); checkNode.Wait(500); nodeExists = true; } catch (Exception) { nodeExists = false; } MFnMesh mfnMesh; if (nodeExists) { mfnMesh = new MFnMesh(node); } else { mfnMesh = new MFnMesh(); } //unpack geom int numVert = MeshToSend.VertexPositions.Length; int numPoly = MeshToSend.FaceIndices.Length; MIntArray faceCnx = new MIntArray(); MFloatPointArray verticies = new MFloatPointArray(); MIntArray faceVtxCt = new MIntArray(); MFloatPoint vtxToAdd = new MFloatPoint(); foreach (var vtx in MeshToSend.VertexPositions) { if (MGlobal.isZAxisUp) { vtxToAdd.x = (float)vtx.X; vtxToAdd.y = (float)vtx.Y; vtxToAdd.z = (float)vtx.Z; } else { vtxToAdd.x = (float)vtx.X; vtxToAdd.y = (float)vtx.Z; vtxToAdd.z = -(float)vtx.Y; } verticies.Add(vtxToAdd); } foreach (var fidx in MeshToSend.FaceIndices) { int vtxCt = (int)fidx.Count; faceVtxCt.Add(vtxCt); if (vtxCt == 3) { faceCnx.Add((int)fidx.A); faceCnx.Add((int)fidx.B); faceCnx.Add((int)fidx.C); } else { faceCnx.Add((int)fidx.A); faceCnx.Add((int)fidx.B); faceCnx.Add((int)fidx.C); faceCnx.Add((int)fidx.D); } } //create maya mesh if (nodeExists) { mfnMesh.createInPlace(numVert, numPoly, verticies, faceVtxCt, faceCnx); mfnMesh.Dispose(); } else { using (var obj = mfnMesh.create(numVert, numPoly, verticies, faceVtxCt, faceCnx)) { MFnDependencyNode nodeFn = new MFnDagNode(obj); nodeFn.setName(name); MGlobal.executeCommand("sets -e -forceElement initialShadingGroup " + nodeFn.name); mfnMesh.Dispose(); } } return(true); }