public static MFnBlendShapeDeformer GetBlendShape(MObject targetObject = null) { if (targetObject == null) { targetObject = BasicFunc.GetSelectedObject(0); } MDagPath dag_target = MDagPath.getAPathTo(targetObject); MFnDependencyNode node_target = new MFnDependencyNode(targetObject); MPlug plug = node_target.findPlug("inMesh"); Debug.Log("node_target:" + node_target.name + " plug:" + plug.name); MItDependencyGraph mit = new MItDependencyGraph(plug, MFn.Type.kBlendShape, MItDependencyGraph.Direction.kUpstream); //MDagPath dagPath = new MDagPath(); //MItDependencyNodes mitnode = new MItDependencyNodes(MFn.Type.kBlendShape); while (!mit.isDone) { MObject mo = mit.currentItem(); MFnDependencyNode dnode = new MFnDependencyNode(mo); Debug.Log("moing:" + dnode.absoluteName); if (mo.hasFn(MFn.Type.kBlendShape)) { Debug.Log("find blendshape"); return(new MFnBlendShapeDeformer(mo)); } mit.next(); } return(null); }
/// <summary> /// Extract a material and its linked texture, if any. /// </summary> private static void ExtractMaterial(MayaM2Mesh mesh, MObject material) { var fnShader = new MFnLambertShader(material); // Get lambert out of the shader var strName = fnShader.name; MGlobal.displayInfo("Detected material : " + strName + " of type " + material.apiTypeStr); //TODO use this type // ReSharper disable once UnusedVariable var clrDiffuse = fnShader.color; // ReSharper disable once UnusedVariable var clrAmbient = fnShader.ambientColor; if (material.hasFn(MFn.Type.kReflect)) { var fnReflectShader = new MFnReflectShader(material); // ReSharper disable once UnusedVariable var clrSpec = fnReflectShader.specularColor; } // Look for textures at the color plug var colorPlug = fnShader.findPlug("color"); var fileTextureIter = new MItDependencyGraph(colorPlug.node, MFn.Type.kFileTexture, MItDependencyGraph.Direction.kUpstream, MItDependencyGraph.Traversal.kDepthFirst, MItDependencyGraph.Level.kNodeLevel); while (!fileTextureIter.isDone) { //TODO hardcoded textures var nodeFn = new MFnDependencyNode(fileTextureIter.thisNode()); var fileNamePlug = nodeFn.findPlug("fileTextureName"); string textureFileName; fileNamePlug.getValue(out textureFileName); MGlobal.displayInfo("\t Texture found : " + textureFileName); var wrapUPlug = nodeFn.findPlug("wrapU"); var wrapU = false; wrapUPlug.getValue(ref wrapU); var wrapVPlug = nodeFn.findPlug("wrapV"); var wrapV = false; wrapVPlug.getValue(ref wrapV); var tex = new MayaM2Texture { WrapU = wrapU, WrapV = wrapV }; mesh.Textures.Add(tex); fileTextureIter.next();//maybe now the loop is fixed } }
public override void doIt(MArgList args) { MSelectionList list = new MSelectionList(); if ( args.length > 0 ) { // Arg list is > 0 so use objects that were passes in // uint last = args.length; for ( uint i = 0; i < last; i++ ) { // Attempt to find all of the objects matched // by the string and add them to the list // string argStr = args.asString(i); list.add(argStr); } } else { // Get arguments from Maya's selection list. MGlobal.getActiveSelectionList(list); } MObject node = new MObject(); MObjectArray nodePath = new MObjectArray(); MFnDependencyNode nodeFn = new MFnDependencyNode(); MFnDependencyNode dgNodeFnSet = new MFnDependencyNode(); for (MItSelectionList iter = new MItSelectionList(list); !iter.isDone; iter.next()) { iter.getDependNode(node); // // The following code shows how to navigate the DG manually without // using an iterator. First, find the attribute that you are // interested. Then connect a plug to it and see where the plug // connected to. Once you get all the connections, you can choose // which route you want to go. // // In here, we wanted to get to the nodes that instObjGroups connected // to since we know that the shadingEngine connects to the instObjGroup // attribute. // nodeFn.setObject( node ); MObject iogAttr = null; try { iogAttr = nodeFn.attribute("instObjGroups"); } catch (Exception) { MGlobal.displayInfo(nodeFn.name + ": is not a renderable object, skipping"); continue; } MPlug iogPlug = new MPlug(node, iogAttr); MPlugArray iogConnections = new MPlugArray(); // // instObjGroups is a multi attribute. In this example, just the // first connection will be tried. // if (!iogPlug.elementByLogicalIndex(0).connectedTo(iogConnections, false, true)) { MGlobal.displayInfo(nodeFn.name + ": is not in a shading group, skipping"); continue; } // // Now we would like to traverse the DG starting from the shadingEngine // since most likely all file texture nodes will be found. Note the // filter used to initialize the DG iterator. There are lots of filter // type available in MF.Type that you can choose to suite your needs. // bool foundATexture = false; for ( int i=0; i < iogConnections.length; i++ ) { MObject currentNode = iogConnections[i].node; // // Note that upon initialization, the current pointer of the // iterator already points to the first valid node. // MItDependencyGraph dgIt = new MItDependencyGraph(currentNode, MFn.Type.kFileTexture, MItDependencyGraph.Direction.kUpstream, MItDependencyGraph.Traversal.kBreadthFirst, MItDependencyGraph.Level.kNodeLevel); if (dgIt == null) { continue; } dgIt.disablePruningOnFilter(); for ( ; !dgIt.isDone; dgIt.next() ) { MObject thisNode = dgIt.thisNode(); dgNodeFnSet.setObject(thisNode); try { dgIt.getNodePath(nodePath); } catch (Exception) { MGlobal.displayInfo("getNodePath"); continue; } // // append the starting node. // nodePath.append(node); dumpInfo( thisNode, dgNodeFnSet, nodePath ); foundATexture = true; } } if ( !foundATexture ) { MGlobal.displayInfo(nodeFn.name + ": is not connected to a file texture"); } } return; }
public override void doIt(MArgList args) { MSelectionList list = new MSelectionList(); if (args.length > 0) { // Arg list is > 0 so use objects that were passes in // uint last = args.length; for (uint i = 0; i < last; i++) { // Attempt to find all of the objects matched // by the string and add them to the list // string argStr = args.asString(i); list.add(argStr); } } else { // Get arguments from Maya's selection list. MGlobal.getActiveSelectionList(list); } MObject node = new MObject(); MObjectArray nodePath = new MObjectArray(); MFnDependencyNode nodeFn = new MFnDependencyNode(); MFnDependencyNode dgNodeFnSet = new MFnDependencyNode(); for (MItSelectionList iter = new MItSelectionList(list); !iter.isDone; iter.next()) { iter.getDependNode(node); // // The following code shows how to navigate the DG manually without // using an iterator. First, find the attribute that you are // interested. Then connect a plug to it and see where the plug // connected to. Once you get all the connections, you can choose // which route you want to go. // // In here, we wanted to get to the nodes that instObjGroups connected // to since we know that the shadingEngine connects to the instObjGroup // attribute. // nodeFn.setObject(node); MObject iogAttr = null; try { iogAttr = nodeFn.attribute("instObjGroups"); } catch (Exception) { MGlobal.displayInfo(nodeFn.name + ": is not a renderable object, skipping"); continue; } MPlug iogPlug = new MPlug(node, iogAttr); MPlugArray iogConnections = new MPlugArray(); // // instObjGroups is a multi attribute. In this example, just the // first connection will be tried. // if (!iogPlug.elementByLogicalIndex(0).connectedTo(iogConnections, false, true)) { MGlobal.displayInfo(nodeFn.name + ": is not in a shading group, skipping"); continue; } // // Now we would like to traverse the DG starting from the shadingEngine // since most likely all file texture nodes will be found. Note the // filter used to initialize the DG iterator. There are lots of filter // type available in MF.Type that you can choose to suite your needs. // bool foundATexture = false; for (int i = 0; i < iogConnections.length; i++) { MObject currentNode = iogConnections[i].node; // // Note that upon initialization, the current pointer of the // iterator already points to the first valid node. // MItDependencyGraph dgIt = new MItDependencyGraph(currentNode, MFn.Type.kFileTexture, MItDependencyGraph.Direction.kUpstream, MItDependencyGraph.Traversal.kBreadthFirst, MItDependencyGraph.Level.kNodeLevel); if (dgIt == null) { continue; } dgIt.disablePruningOnFilter(); for ( ; !dgIt.isDone; dgIt.next()) { MObject thisNode = dgIt.thisNode(); dgNodeFnSet.setObject(thisNode); try { dgIt.getNodePath(nodePath); } catch (Exception) { MGlobal.displayInfo("getNodePath"); continue; } // // append the starting node. // nodePath.append(node); dumpInfo(thisNode, dgNodeFnSet, nodePath); foundATexture = true; } } if (!foundATexture) { MGlobal.displayInfo(nodeFn.name + ": is not connected to a file texture"); } } return; }