public static List <Curve> getSmothMeshEdges(MFnMesh mayaMesh, bool createInMaya = false)
        {
            //MCommandResult result = new MCommandResult();
            int          ne           = mayaMesh.numEdges;
            MFnTransform group        = new MFnTransform();
            List <Curve> curveObjects = new List <Curve>(ne);
            MStringArray resultStr    = new MStringArray();

            var    fullName      = mayaMesh.fullPathName.Split('|');
            string transformName = fullName[fullName.Length - 2];


            if (createInMaya)
            {
                for (int i = 0; i < ne; i++)
                {
                    using (MCommandResult result = new MCommandResult())
                    {
                        MGlobal.executeCommand(
                            $"polyToCurve -name {transformName}Curves -form 2 -degree 3 -conformToSmoothMeshPreview 1 {transformName}.e[{i}]",
                            result);
                        result.getResult(resultStr);
                        curveObjects.Add(
                            DMCurve.CurveFromMfnNurbsCurveFromName(resultStr[0],
                                                                   MSpace.Space.kPostTransform.ToString()));
                    }
                }
            }
            else
            {
                //Parallel.For(0, ne, i => {
                for (int i = 0; i < ne; i++)
                {
                    using (MCommandResult result = new MCommandResult())
                    {
                        MGlobal.executeCommand(
                            $"polyToCurve -name deleteMe11232204332AA -form 2 -degree 3 -conformToSmoothMeshPreview 1 {transformName}.e[{i}]",
                            result);
                        result.getResult(resultStr);
                        curveObjects.Add(
                            DMCurve.CurveFromMfnNurbsCurveFromName(resultStr[0],
                                                                   MSpace.Space.kPostTransform.ToString()));
                        try
                        {
                            MGlobal.deleteNode(DMInterop.getDependNode(resultStr[0]));
                        }
                        catch
                        {
                            MGlobal.displayWarning("getSmothMeshEdges: unable to delete temp object");
                        }
                    }
                }

                // });
            }


            return(curveObjects);
        }
        public static List <List <Curve> > getSmothMeshEdgesPerFace(MFnMesh mayaMesh, bool createInMaya = false)
        {
            MCommandResult ptcResult = new MCommandResult();
            MCommandResult teResult  = new MCommandResult();

            int numPoly = mayaMesh.numPolygons;

            List <List <Curve> > curveObjects    = new  List <List <Curve> >(numPoly);
            MStringArray         ptcResultStr    = new MStringArray();
            MStringArray         teResultStr     = new MStringArray();
            MStringArray         teResultStrFlat = new MStringArray();

            List <Curve> tempCurveArray = null;

            if (createInMaya)
            {
            }
            else
            {
                for (int i = 0; i < numPoly; i++)
                {
                    MGlobal.executeCommand($"polyListComponentConversion -te {mayaMesh.name}.f[{i}]", teResult);
                    teResult.getResult(teResultStr);
                    MGlobal.clearSelectionList();

                    foreach (var ters in teResultStr)
                    {
                        MGlobal.selectByName(ters, MGlobal.ListAdjustment.kAddToList);
                    }
                    MGlobal.executeCommand($"ls -sl -fl", teResult);
                    teResult.getResult(teResultStrFlat);

                    tempCurveArray = new List <Curve>((int)teResultStrFlat.length);

                    foreach (var e in teResultStrFlat)
                    {
                        MGlobal.executeCommand($"polyToCurve -name deleteMe11232204332AA -form 2 -degree 3 -conformToSmoothMeshPreview 1 {e}", ptcResult);
                        ptcResult.getResult(ptcResultStr);
                        tempCurveArray.Add(DMCurve.CurveFromMfnNurbsCurveFromName(ptcResultStr[0], MSpace.Space.kPostTransform.ToString()));
                        try
                        {
                            MGlobal.deleteNode(DMInterop.getDependNode(ptcResultStr[0]));
                        }
                        catch
                        {
                            MGlobal.displayWarning("getSmothMeshEdges: unable to delete temp object");
                        }
                    }

                    curveObjects.Add(tempCurveArray);
                }
            }


            return(curveObjects);
        }
        protected void clearResults(MPx3dModelView view)
        {
            MObject cstObj = MObject.kNullObj;

            try
            {
                view.getCameraSet(cstObj);
                view.setCameraSet(MObject.kNullObj);
                MGlobal.deleteNode(cstObj);
            }
            catch (Exception)
            {
            }
            fCameraList.clear();
        }
        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);
        }
Example #5
0
        public void DeleteSelection()
        {
            MObject sel = GetFirstSelectedObject();

            MGlobal.deleteNode(sel);
        }