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 addSelectedButton_Click(object sender, EventArgs e) { if (currentInfo == null) { return; } MDagPath node; MObject component = new MObject(); MFnDagNode nodeFn = new MFnDagNode(); MSelectionList selected = new MSelectionList(); MGlobal.getActiveSelectionList(selected); for (uint index = 0; index < selected.length; index++) { node = selected.getDagPath(index, component); nodeFn.setObject(node); MGlobal.displayInfo($"{nodeFn.name} - {nodeFn.fullPathName} - {component.apiType}"); } }
private void assignShadingGroup(MObject transform, string groupName) { // Get the name of the mesh node. // // We need to use an MFnDagNode rather than an MFnMesh because the mesh // is not fully realized at this point and would be rejected by MFnMesh. MFnDagNode dagFn = new MFnDagNode(transform); dagFn.setObject(dagFn.child(0)); string meshName = dagFn.name; // Use the DAG modifier to put the mesh into a shading group string cmd = "sets -e -fe "; cmd += groupName + " " + meshName; dagMod.commandToExecute(cmd); // Use the DAG modifier to select the new mesh. cmd = "select " + meshName; dagMod.commandToExecute(cmd); }
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 assignShadingGroup(MObject transform, string groupName) { // Get the name of the mesh node. // // We need to use an MFnDagNode rather than an MFnMesh because the mesh // is not fully realized at this point and would be rejected by MFnMesh. MFnDagNode dagFn = new MFnDagNode(transform); dagFn.setObject(dagFn.child(0)); string meshName = dagFn.name; // Use the DAG modifier to put the mesh into a shading group string cmd = "sets -e -fe "; cmd += groupName + " " + meshName; dagMod.commandToExecute(cmd); // Use the DAG modifier to select the new mesh. cmd = "select " + meshName; dagMod.commandToExecute(cmd); }