public static Dictionary <string, object> getSmoothMesh(MFnMesh mayaMesh)
        {
            MObject     tempMesh = new MObject();
            MFnMeshData meshData = new MFnMeshData();
            MObject     dataObject;
            MObject     smoothedObj = new MObject();

            dataObject  = meshData.create();
            smoothedObj = mayaMesh.generateSmoothMesh(dataObject);
            MFnMesh meshFn = new MFnMesh(smoothedObj);


            // var smoothMeshObj = mayaMesh.generateSmoothMesh();


            // MFnDependencyNode mfnDn = new MFnDependencyNode(smoothedObj);
            // var meshDag = DMInterop.getDagNode(mfnDn.name);
            Mesh dynamoMesh = DMMesh.MTDMeshFromMayaMesh(meshFn, MSpace.Space.kObject);

            //MGlobal.displayInfo(smoothedObj.apiTypeStr);

            //MGlobal.deleteNode(smoothedObj);


            return(new Dictionary <string, object>
            {
                { "mesh", dynamoMesh },
                { "mayaMesh", meshFn }
            });
        }
Example #2
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(animCube.outputMesh))
            {
                /* Get time */
                MDataHandle timeData = dataBlock.inputValue(animCube.time);
                MTime time = timeData.asTime;

                /* Get output object */

                MDataHandle outputHandle = dataBlock.outputValue(outputMesh);

                MFnMeshData dataCreator = new MFnMeshData();
                MObject newOutputData = dataCreator.create();

                createMesh(time, ref newOutputData);

                outputHandle.set(newOutputData);
                dataBlock.setClean(plug);
            }
            else
                return false;

            return true;
        }
Example #3
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(animCube.outputMesh))
            {
                /* Get time */
                MDataHandle timeData = dataBlock.inputValue(animCube.time);
                MTime       time     = timeData.asTime;

                /* Get output object */

                MDataHandle outputHandle = dataBlock.outputValue(outputMesh);

                MFnMeshData dataCreator   = new MFnMeshData();
                MObject     newOutputData = dataCreator.create();

                createMesh(time, ref newOutputData);

                outputHandle.set(newOutputData);
                dataBlock.setClean(plug);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        private void createNodes()
        {
            // Generate the raw data for the requested primitive.
            generatePrimitiveData();

            // Create a mesh data wrapper to hold the new geometry.
            MFnMeshData dataFn      = new MFnMeshData();
            MObject     dataWrapper = dataFn.create();

            // Create the mesh geometry and put it into the wrapper.
            MFnMesh meshFn  = new MFnMesh();
            MObject dataObj = meshFn.create(
                num_verts,
                num_faces,
                pa,
                faceCounts,
                faceConnects,
                dataWrapper
                );

            // Use the DAG modifier to create an empty mesh node and its parent
            // transform.
            MObject transform = dagMod.createNode("mesh", MObject.kNullObj);

            // Commit the creation so that the transform and its child will be
            // valid below.
            dagMod.doIt();

            // At the moment we have a transform named something like 'transform1'
            // and a mesh named something like 'polySurfaceShape1'. Let's tidy that
            // up by renaming them as 'pPrimitive#' and 'pPrimitiveShape#', where
            // '#' is a number to ensure uniqueness.
            renameNodes(transform, "pPrimitive");
            // Commit the rename so that assignShadingGroup() can get the new name.
            dagMod.doIt();

            // Assign the mesh to a shading group.
            assignShadingGroup(transform, "initialShadingGroup");

            // Commit the changes.
            dagMod.doIt();

            // Set the mesh node to use the geometry we created for it.
            setMeshData(transform, dataWrapper);
        }
Example #5
0
		private void createNodes()
		{
			// Generate the raw data for the requested primitive.
			generatePrimitiveData();

			// Create a mesh data wrapper to hold the new geometry.
			MFnMeshData    dataFn = new MFnMeshData();
			MObject        dataWrapper = dataFn.create();

			// Create the mesh geometry and put it into the wrapper.
			MFnMesh        meshFn = new MFnMesh();
			MObject        dataObj = meshFn.create(
										num_verts,
										num_faces,
										pa,
										faceCounts,
										faceConnects,
										dataWrapper
									);

			// Use the DAG modifier to create an empty mesh node and its parent
			// transform.
			MObject transform = dagMod.createNode("mesh", MObject.kNullObj);

			// Commit the creation so that the transform and its child will be
			// valid below.
			dagMod.doIt();

			// At the moment we have a transform named something like 'transform1'
			// and a mesh named something like 'polySurfaceShape1'. Let's tidy that
			// up by renaming them as 'pPrimitive#' and 'pPrimitiveShape#', where
			// '#' is a number to ensure uniqueness.
			renameNodes(transform, "pPrimitive");
			// Commit the rename so that assignShadingGroup() can get the new name.
			dagMod.doIt();

			// Assign the mesh to a shading group.
			assignShadingGroup(transform, "initialShadingGroup");

			// Commit the changes.
			dagMod.doIt();

			// Set the mesh node to use the geometry we created for it.
			setMeshData(transform, dataWrapper);
		}
Example #6
0
        private void dynMeshToMayaMesh(string name, Mesh dynMesh = null, TSplineSurface tsMesh = null)
        {
            bool     nodeExists = false;
            MDagPath node       = null;
            Task     unpackTask = null;
            Task     mobjTask   = null;

            try
            {
                node       = DMInterop.getDagNode(name);
                nodeExists = true;
            }
            catch (Exception)
            {
                nodeExists = false;
            }

            MIntArray        faceCnx   = new MIntArray();
            MFloatPointArray verticies = new MFloatPointArray();
            MIntArray        faceVtxCt = new MIntArray();
            int numVert = 0;
            int numPoly = 0;

            if (dynMesh != null)
            {
                numVert    = dynMesh.VertexPositions.Length;
                numPoly    = dynMesh.FaceIndices.Length;
                unpackTask = Task.Factory.StartNew(() => unpackDynMesh(dynMesh, out faceCnx, out verticies, out faceVtxCt));
                unpackTask.Wait(4000);
            }

            if (tsMesh != null)
            {
                numVert    = tsMesh.VerticesCount;
                numPoly    = tsMesh.FacesCount;
                unpackTask = Task.Factory.StartNew(() => unpackTsMesh(tsMesh, out faceCnx, out verticies, out faceVtxCt));
                unpackTask.Wait(4000);
            }



            if (nodeExists)
            {
                try
                {
                    meshFn = new MFnMesh(node);
                    meshFn.createInPlace(numVert, numPoly, verticies, faceVtxCt, faceCnx);
                }
                catch (Exception e)
                {
                    MGlobal.displayWarning(e.Message);
                }
            }
            else
            {
                try
                {
                    dagMod = new MDagModifier();
                    // Create a mesh data wrapper to hold the new geometry.
                    MFnMeshData dataFn      = new MFnMeshData();
                    MObject     dataWrapper = dataFn.create();

                    // Create the mesh geometry and put it into the wrapper.
                    meshFn = new MFnMesh();
                    MObject dataObj   = meshFn.create(numVert, numPoly, verticies, faceVtxCt, faceCnx, dataWrapper);
                    MObject transform = dagMod.createNode("mesh", MObject.kNullObj);

                    dagMod.doIt();

                    renameNodes(transform, name);
                    dagMod.doIt();
                    assignShadingGroup(transform, "initialShadingGroup");
                    dagMod.doIt();
                    setMeshData(transform, dataWrapper);
                }
                catch (Exception e)
                {
                    MGlobal.displayWarning(e.Message);
                }
            }

            //GC.Collect();
            //GC.WaitForPendingFinalizers();
        }