Пример #1
0
        public override bool getSourceIndexing(MObject obj, MComponentDataIndexing sourceIndexing)
        {
            // get the mesh from the current path, if it is not a mesh we do nothing.
            MFnMesh mesh = null;

            try {
                mesh = new MFnMesh(obj);
            } catch (System.Exception) {
                return(false);
            }

            // if it is an empty mesh we do nothing.
            int numPolys = mesh.numPolygons;

            if (numPolys <= 0)
            {
                return(false);
            }

            // for each face
            MUintArray vertToFaceVertIDs = sourceIndexing.indicesProperty;
            uint       faceNum           = 0;

            for (int i = 0; i < numPolys; i++)
            {
                // assign a color ID to all vertices in this face.
                uint faceColorID = faceNum % 3;

                int vertexCount = mesh.polygonVertexCount(i);
                for (int j = 0; j < vertexCount; j++)
                {
                    // set each face vertex to the face color
                    vertToFaceVertIDs.append(faceColorID);
                }

                faceNum++;
            }

            // assign the source indexing
            sourceIndexing.setComponentType(MComponentDataIndexing.MComponentType.kFaceVertex);

            return(true);
        }
Пример #2
0
        public override void createVertexStream(MObject objPath,
                                                MVertexBuffer vertexBuffer,
                                                MComponentDataIndexing targetIndexing,
                                                MComponentDataIndexing sharedIndexing,
                                                MVertexBufferArray sourceStreams)
        {
            // get the descriptor from the vertex buffer.
            // It describes the format and layout of the stream.
            MVertexBufferDescriptor descriptor = vertexBuffer.descriptor;

            // we are expecting a float stream.
            if (descriptor.dataType != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.DataType.kFloat)
            {
                return;
            }

            // we are expecting a float2
            if (descriptor.dimension != 2)
            {
                return;
            }

            // we are expecting a texture channel
            if (descriptor.semantic != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.Semantic.kTexture)
            {
                return;
            }

            // get the mesh from the current path, if it is not a mesh we do nothing.
            MFnMesh mesh = null;

            try {
                mesh = new MFnMesh(objPath);
            } catch (System.Exception) {
                return;                 // failed
            }

            MUintArray indices     = targetIndexing.indicesProperty;
            uint       vertexCount = indices.length;

            if (vertexCount <= 0)
            {
                return;
            }

            unsafe {
                // acquire the buffer to fill with data.
                float *buffer = (float *)vertexBuffer.acquire(vertexCount);

                for (int i = 0; i < vertexCount; i++)
                {
                    // Here we are embedding some custom data into the stream.
                    // The included effects (vertexBufferGeneratorGL.cgfx and
                    // vertexBufferGeneratorDX11.fx) will alternate
                    // red, green, and blue vertex colored triangles based on this input.
                    *(buffer++) = 1.0f;
                    *(buffer++) = (float)indices[i];                 // color index
                }

                // commit the buffer to signal completion.
                vertexBuffer.commit((byte *)buffer);
            }
        }
Пример #3
0
        public static List <Surface> meshToNurbs(MFnMesh mayaMesh)
        {
            MFnSubd subDmesh = new MFnSubd();

            subDmesh.isIntermediateObject = true;
            MPointArray mayaVerts = new MPointArray();

            mayaMesh.getPoints(mayaVerts, MSpace.Space.kWorld);

            MIntArray polyVertct = new MIntArray();


            MIntArray ids    = new MIntArray();
            MIntArray idList = new MIntArray();

            for (int i = 0; i < mayaMesh.numPolygons; i++)
            {
                mayaMesh.getPolygonVertices(i, ids);
                foreach (var id in ids)
                {
                    idList.Add(id);
                }
                polyVertct.Add(ids.Count);
            }
            subDmesh.createBaseMesh(false, mayaMesh.numVertices, mayaMesh.numPolygons, mayaVerts, polyVertct, idList);

            try
            {
                MUintArray   creaseEdgId   = new MUintArray();
                MDoubleArray creaseEdgeVal = new MDoubleArray();
                mayaMesh.getCreaseEdges(creaseEdgId, creaseEdgeVal);

                foreach (var edgId in creaseEdgId)
                {
                    subDmesh.edgeSetCrease(edgId, true);
                }
            }
            catch {}

            try
            {
                MUintArray   creaseVertId  = new MUintArray();
                MDoubleArray creaseVertVal = new MDoubleArray();
                mayaMesh.getCreaseVertices(creaseVertId, creaseVertVal);

                foreach (var vertId in creaseVertId)
                {
                    subDmesh.vertexSetCrease(vertId, true);
                }
            }
            catch { }


            subDmesh.updateAllEditsAndCreases();

            MObjectArray nurbsSurfs = new MObjectArray();

            subDmesh.convertToNurbs(nurbsSurfs);

            List <MFnNurbsSurface> mfnSurfaceList = new List <MFnNurbsSurface>(nurbsSurfs.Count);

            foreach (var surf in nurbsSurfs)
            {
                mfnSurfaceList.Add(new MFnNurbsSurface(surf));
            }

            List <Surface> dynSurfaceList = new List <Surface>(mfnSurfaceList.Count);

            foreach (var mfnNS in mfnSurfaceList)
            {
                dynSurfaceList.Add(DMSurface.mNurbsSurfaceToDynamoSurface(mfnNS, MSpace.Space.kObject));
            }

            MGlobal.deleteNode(subDmesh.model);
            return(dynSurfaceList);
        }