override public void redoIt() { _dagModifier.doIt(); var dagFn = new MFnDagNode(_transform); _shape = dagFn.child(0); _dagModifier.renameNode(_shape, "motionCameraShape"); _dagModifier.doIt(); }
private void setMeshData(MObject transform, MObject dataWrapper) { // Get the mesh node. MFnDagNode dagFn = new MFnDagNode(transform); MObject mesh = dagFn.child(0); // The mesh node has two geometry inputs: 'inMesh' and 'cachedInMesh'. // 'inMesh' is only used when it has an incoming connection, otherwise // 'cachedInMesh' is used. Unfortunately, the docs say that 'cachedInMesh' // is for internal use only and that changing it may render Maya // unstable. // // To get around that, we do the little dance below... // Use a temporary MDagModifier to create a temporary mesh attribute on // the node. MFnTypedAttribute tAttr = new MFnTypedAttribute(); MObject tempAttr = tAttr.create("tempMesh", "tmpm", MFnData.Type.kMesh); MDagModifier tempMod = new MDagModifier(); tempMod.addAttribute(mesh, tempAttr); tempMod.doIt(); // Set the geometry data onto the temp attribute. dagFn.setObject(mesh); MPlug tempPlug = dagFn.findPlug(tempAttr); tempPlug.setValue(dataWrapper); // Use the temporary MDagModifier to connect the temp attribute to the // node's 'inMesh'. MPlug inMeshPlug = dagFn.findPlug("inMesh"); tempMod.connect(tempPlug, inMeshPlug); tempMod.doIt(); // Force the mesh to update by grabbing its output geometry. dagFn.findPlug("outMesh").asMObject(); // Undo the temporary modifier. tempMod.undoIt(); }
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); }
public static void RenameDagList(MDagPath[] dagList, string formatStr) { MDagModifier dagModifier = new MDagModifier(); for (int i = 0; i < dagList.Length; i++) { dagModifier.renameNode(dagList[i].node, string.Format(formatStr, i)); } dagModifier.doIt(); }
public void sendCurveToMaya(string node_name, Point3DCollection controlVertices, List <double> knots, int degree, MFnNurbsCurveForm form) { var dn = new MFnDagNode(getDagNode(node_name)); var plCreate = dn.findPlug("create"); var plDynamoCreate = new MPlug(); try { plDynamoCreate = dn.findPlug("dynamoCreate"); } catch { var tAttr = new MFnTypedAttribute(); var ldaDynamoCreate = tAttr.create("dynamoCreate", "dc", MFnData.Type.kNurbsCurve, MObject.kNullObj); try { dn.addAttribute(ldaDynamoCreate, MFnDependencyNode.MAttrClass.kLocalDynamicAttr); plDynamoCreate = dn.findPlug(ldaDynamoCreate); var dagm = new MDagModifier(); dagm.connect(plDynamoCreate, plCreate); dagm.doIt(); } catch { return; } } var ncd = new MFnNurbsCurveData(); var oOwner = ncd.create(); var nc = new MFnNurbsCurve(); var p_aControlVertices = new MPointArray(); foreach (var p in controlVertices) { p_aControlVertices.Add(new MPoint(p.X, p.Y, p.Z)); } var d_aKnots = new MDoubleArray(); for (var i = 1; i < knots.Count - 1; ++i) { d_aKnots.Add(knots[i]); } nc.create(p_aControlVertices, d_aKnots, (uint)degree, (MFnNurbsCurve.Form)form, false, true, oOwner); plDynamoCreate.setMObject(oOwner); MGlobal.executeCommandOnIdle(string.Format("dgdirty {0}.create;", node_name)); }
public void sendCurveToMaya(string node_name, Point3DCollection controlVertices, List<double> knots, int degree, MFnNurbsCurveForm form) { MFnDagNode dn = new MFnDagNode(getDagNode(node_name)); MPlug plCreate = dn.findPlug("create"); MPlug plDynamoCreate = new MPlug(); try { plDynamoCreate = dn.findPlug("dynamoCreate"); } catch { MFnTypedAttribute tAttr = new MFnTypedAttribute(); MObject ldaDynamoCreate = tAttr.create("dynamoCreate", "dc", MFnData.Type.kNurbsCurve, MObject.kNullObj); try { dn.addAttribute(ldaDynamoCreate, MFnDependencyNode.MAttrClass.kLocalDynamicAttr); plDynamoCreate = dn.findPlug(ldaDynamoCreate); MDagModifier dagm = new MDagModifier(); dagm.connect(plDynamoCreate, plCreate); dagm.doIt(); } catch { return; } } MFnNurbsCurveData ncd = new MFnNurbsCurveData(); MObject oOwner = ncd.create(); MFnNurbsCurve nc = new MFnNurbsCurve(); MPointArray p_aControlVertices = new MPointArray(); foreach (Point3D p in controlVertices) { p_aControlVertices.Add(new MPoint(p.X, p.Y, p.Z)); } MDoubleArray d_aKnots = new MDoubleArray(); for (int i = 1; i < knots.Count - 1; ++i ) { d_aKnots.Add(knots[i]); } nc.create(p_aControlVertices, d_aKnots, (uint)degree, (MFnNurbsCurve.Form)form, false, true, oOwner); plDynamoCreate.setMObject(oOwner); MGlobal.executeCommandOnIdle(String.Format("dgdirty {0}.create;", node_name)); }
public override void redoIt() { modifier.doIt(); return; }
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(); }