public static void RemoveUnusedTextures(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } List <MObject> deleteList = new List <MObject>(); for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); MFnDependencyNode imageNode = new MFnDependencyNode(mo); MPlug texOutputPlug = imageNode.findPlug(ConstantValue.plugName_fileTexOutputColor); MPlugArray destPlugs = new MPlugArray(); texOutputPlug.destinations(destPlugs); if (destPlugs.Count == 0) { deleteList.Add(mo); Debug.Log("remove no use:" + imageNode.absoluteName); } else { Debug.Log("still used:" + imageNode.absoluteName); for (int j = 0; j < destPlugs.length; j++) { Debug.Log(" by:" + destPlugs[0].partialName(true)); } } } BasicFunc.DeleteObjects(deleteList); }
public static void DeleteUnusedShadingNode(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } List <MFnDependencyNode> deleteList = new List <MFnDependencyNode>(); for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); if (mo.hasFn(MFn.Type.kShadingEngine)) { MFnDependencyNode sgNode = new MFnDependencyNode(mo); MPlug plug_dagSetMemebers = sgNode.findPlug(ConstantValue.plugName_dagSetMembers); Debug.Log("numelements:" + plug_dagSetMemebers.numElements); if (plug_dagSetMemebers.numElements == 0) { deleteList.Add(sgNode); } } //Debug.Log(sgNode.name); } BasicFunc.DeleteObjects(deleteList); }
// // Takes the nodes that are on the active selection list and adds an // attribute changed callback to each one. // public override void doIt(MArgList args) { MObject node = new MObject(); MSelectionList list = new MSelectionList(); // Register node callbacks for all nodes on the active list. // MGlobal.getActiveSelectionList( list ); for ( uint i=0; i<list.length; i++ ) { list.getDependNode( i, node ); try { node.AttributeChanged += userCB; } catch (Exception) { MGlobal.displayInfo("MNodeMessage.addCallback failed\n"); continue; } // C# SDK will cleanup events, when this plugin is unloaded // callbacks.append(node); } return; }
public override void doIt(MArgList args) // // Takes the nodes that are on the active selection list and adds an // attribute changed callback to each one. // { MObject node = new MObject(); MSelectionList list = new MSelectionList(); // Register node callbacks for all nodes on the active list. // MGlobal.getActiveSelectionList(list); for (uint i = 0; i < list.length; i++) { list.getDependNode(i, node); try { node.AttributeChanged += userCB; } catch (Exception) { MGlobal.displayInfo("MNodeMessage.addCallback failed\n"); continue; } // C# SDK will cleanup events, when this plugin is unloaded // callbacks.append(node); } return; }
/// <summary> /// well, this action is truely dangerous /// </summary> /// <param name="list"></param> /// <returns></returns> public static bool CombineMaterials(MSelectionList list, bool deleteRepeated = true) { if (!BasicFunc.CheckSelectionList(list, 2)) { Debug.Log("please choose at least 2 materials"); return(false); } string firstMatName = ""; List <MObject> deleteList = new List <MObject>(); List <MSelectionList> waitForAssign = new List <MSelectionList>(); MDGModifier dGModifier = new MDGModifier(); for (uint i = 0; i < list.length; i++) { //Debug.Log(i + " mat test"); MObject matObject = new MObject(); list.getDependNode(i, matObject); MFnDependencyNode dnode = new MFnDependencyNode(matObject); if (i == 0) { firstMatName = dnode.absoluteName; continue; } else { deleteList.Add(matObject); } //Debug.Log(i + " node:" + dnode.absoluteName); if (matObject.hasFn(MFn.Type.kLambert) || matObject.hasFn(MFn.Type.kBlinn) || matObject.hasFn(MFn.Type.kPhong)) { //Debug.Log("has mat fn"); //MMaterial mat = new MMaterial(matObject); //MColor color = new MColor(); //mat.getDiffuse(color); //Debug.Log("mat:" + dnode.absoluteName + " ,color:" + BasicFunc.MToString(color)); SelectObjectsWithMat(dnode); //Debug.Log("finish select"); //waitForAssign.Add(BasicFunc.GetSelectedList()); AssignMat(firstMatName); //Debug.Log("finish assign"); BasicFunc.DeleteByCMD(dnode.absoluteName); //Debug.Log("finish delete"); } else { Debug.Log("no mat fn"); } } dGModifier.doIt(); //MGlobal.executeCommandOnIdle("hyperShade -objects " + matNode.absoluteName); return(true); }
// get the dependency node private MObject getDependNode(string node_name) { var sl = new MSelectionList(); sl.add(node_name, true); var o = new MObject(); sl.getDependNode(0, o); return(o); }
public static void PrintObjects(MSelectionList list) { for (int i = 0; i < list.length; i++) { uint index = (uint)i; MObject mo = new MObject(); list.getDependNode(index, mo); Debug.Log(index + ":typeof:" + mo.apiTypeStr); } }
// get the dependency node MObject getDependNode(string node_name) { MSelectionList sl = new MSelectionList(); sl.add(node_name, true); MObject o = new MObject(); sl.getDependNode(0, o); return(o); }
public static MObject GetObjectByName(string name, int index = 0) { MSelectionList matched = GetObjectsByName(name); MObject mObject = new MObject(); if (index < matched.length) { matched.getDependNode((uint)index, mObject); } return(mObject); }
public static List <MObject> GetSelectedObjectList() { MSelectionList list = GetSelectedList(); List <MObject> nodes = new List <MObject>(); for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); nodes.Add(mo); } return(nodes); }
public static MObject GetSelectedObject(int index) { MSelectionList selected = new MSelectionList(); MGlobal.getActiveSelectionList(selected); MObject mObject = new MObject(); if (index < selected.length) { selected.getDependNode((uint)index, mObject); } return(mObject); }
public static MFnDependencyNode CreateLayeredTextureNode(List <MFnDependencyNode> imageNodes) { //MFnDependencyNode layeredTextureNode = new MFnDependencyNode(); //layeredTextureNode.create("layeredTexture"); MFnDependencyNode layeredTextureNode = CreateShadingNode(ShadingNodeType.Utility, "layeredTexture"); MPlug layeredTexInputsPlug = layeredTextureNode.findPlug(ConstantValue.plugName_layeredTextureInputs); //check place2DTextures MDGModifier dGModifier = new MDGModifier(); for (int i = 0; i < imageNodes.Count; i++) { //place2dTexture setting MFnDependencyNode p2dNode = GetPlace2dTextureForTex(imageNodes[i]); p2dNode.findPlug("wrapU").setBool(false); p2dNode.findPlug("translateFrameU").setFloat(i); //set tex default color to 0 imageNodes[i].findPlug(ConstantValue.plugName_fileTexDefaultColorR).setFloat(0); imageNodes[i].findPlug(ConstantValue.plugName_fileTexDefaultColorG).setFloat(0); imageNodes[i].findPlug(ConstantValue.plugName_fileTexDefaultColorB).setFloat(0); //move uv MSelectionList matList = GetMaterialsWithTex(imageNodes[i]); for (int j = 0; j < matList.length; j++) { MObject matObj = new MObject(); matList.getDependNode((uint)j, matObj); string matName = new MFnDependencyNode(matObj).absoluteName; Debug.Log("move uv for mat:" + matName); MoveUV(i, 0, matName); } MPlug layeredTexInputPlug = layeredTexInputsPlug.elementByLogicalIndex((uint)i); MPlug texOutColorPlug = imageNodes[i].findPlug(ConstantValue.plugName_fileTexOutputColor); MPlug layeredTexInputColor = layeredTexInputPlug.child((int)ConstantValue.LayeredTextureInputDataIndex.Color); dGModifier.connect(texOutColorPlug, layeredTexInputColor); //set blendMode to add MPlug blendMode = layeredTexInputPlug.child((int)ConstantValue.LayeredTextureInputDataIndex.BlendMode); if (i < imageNodes.Count - 1) { blendMode.setInt((int)ConstantValue.LayeredTextureBlendMode.Add); } else { blendMode.setInt((int)ConstantValue.LayeredTextureBlendMode.None); } } dGModifier.doIt(); return(layeredTextureNode); }
public static void ChangeTexturesPrefix(MSelectionList list, string newFolderPath) { if (list == null) { Debug.Log("list null"); return; } for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); MFnDependencyNode imageNode = new MFnDependencyNode(mo); MPlug plug = imageNode.findPlug(ConstantValue.plugName_fileTexPath); string filePath = plug.asString(); Debug.Log("filePath:" + filePath); string fileName = Path.GetFileName(filePath); plug.setString(Path.Combine(newFolderPath, fileName)); } }
public static void RenameTextures(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); MFnDependencyNode imageNode = new MFnDependencyNode(mo); MPlug plug = imageNode.findPlug(ConstantValue.plugName_fileTexPath); string filePath = plug.asString(); Debug.Log("filePath:" + filePath); string fileName = BasicFunc.GetFileName(filePath); Debug.Log("fileName:" + fileName); imageNode.setName(fileName); } }
public static MSelectionList GetSelectedList(MFn.Type type = MFn.Type.kInvalid) { MSelectionList selected = new MSelectionList(); MGlobal.getActiveSelectionList(selected); if (type != MFn.Type.kInvalid) { for (int i = (int)(selected.length - 1); i >= 0; i--) { MObject mo = new MObject(); selected.getDependNode((uint)i, mo); if (!mo.hasFn(type)) { selected.remove((uint)i); } } } return(selected); }
public static void RenameMaterials(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); MFnDependencyNode matNode = new MFnDependencyNode(mo); MPlug plug = matNode.findPlug(ConstantValue.plugName_matColorInput); MPlug sourcePlug = plug.source; if (sourcePlug != null) { MFnDependencyNode sourceNode = new MFnDependencyNode(sourcePlug.node); matNode.setName("mat_" + sourceNode.name); } } }
public static void DeleteUnusedMats(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } List <MFnDependencyNode> deleteList = new List <MFnDependencyNode>(); for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); MFnDependencyNode matNode = new MFnDependencyNode(mo); MPlug plug = matNode.findPlug(ConstantValue.plugName_matColorOutput); MPlugArray plugArr = new MPlugArray(); plug.destinations(plugArr); if (plugArr.Count > 0) { MFnDependencyNode sgNode = new MFnDependencyNode(plugArr[0].node); Debug.Log(sgNode.name); MPlug plug_dagSetMemebers = sgNode.findPlug(ConstantValue.plugName_dagSetMembers); Debug.Log("numelements:" + plug_dagSetMemebers.numElements); if (plug_dagSetMemebers.numElements == 0) { deleteList.Add(matNode); deleteList.Add(sgNode); } } else { deleteList.Add(matNode); } } BasicFunc.DeleteObjects(deleteList); }
public bool getExCameraSetNode(MObject dirObj) { // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; list.getDependNode(0, dirNode); if (dirNode == MObject.kNullObj) { return(false); } MFnDependencyNode nodeFn = new MFnDependencyNode(dirNode); if (nodeFn.typeId.id != exCameraSet.type_id.id) { return(false); } dirObj = dirNode; return(true); }
public static void IterateSelectedObjects(Action <MObject> dealMethod, MFn.Type typeFilter = MFn.Type.kInvalid, MSelectionList list = null) { if (list == null) { list = GetSelectedList(); } int count = (int)list.length; for (int i = 0; i < count; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); if (typeFilter != MFn.Type.kInvalid) { if (!mo.hasFn(typeFilter)) { continue; } } dealMethod(mo); } }
// get the dependency node MObject getDependNode(string node_name) { MSelectionList sl = new MSelectionList(); sl.add(node_name, true); MObject o = new MObject(); sl.getDependNode(0, o); return o; }
override public void doIt(MArgList args) // Parses the given command line arguments and executes them. // { parseArgs(args); bool nothingSet = (!createdUsed && !appendCameraUsed && !appendCameraAndSetUsed && !deleteLayerUsed && !cameraUsed && !layerUsed && !helpUsed && !setUsed && !layerTypeUsed && !numLayersUsed); if (nothingSet) { throw new ArgumentException("A flag must be used. testCameraSet -help for available flags", "args"); } if (helpUsed) { MGlobal.displayInfo("testExCameraSet -help"); MGlobal.displayInfo("\ttestExCameraSet tests the functionality of the exCameraSet node."); MGlobal.displayInfo(""); MGlobal.displayInfo("\t-h -help : This message is printed"); MGlobal.displayInfo("\t-a -active [true/false]: Set/get whether a particular layer is active"); MGlobal.displayInfo("\t-ac -appendCamera <cameraName>: Append a new camera layer to the cameraSet using the specified camera"); MGlobal.displayInfo("\t-acs -appendCameraAndSet <cameraName> <setName>: Append a new camera layer to the cameraSet using the specified camera and set"); MGlobal.displayInfo("\t-cam -camera [<cameraName>]: Set/get the camera for a particular layer"); MGlobal.displayInfo("\t-c -create : Create a new cameraSet node"); MGlobal.displayInfo("\t-d -deleteLayer <layerIndex>: Delete the layer at the given index"); MGlobal.displayInfo("\t-nl -numLayers: Returns the number of layers defined in the specified cameraSet"); MGlobal.displayInfo("\t-l -layer <layerIndex>: Specifies the layer index to be used when accessing layer information"); MGlobal.displayInfo("\t-lt -layerType [<layerTypeName>]: Set/get the layer type for a particular layer. Possible values are Mono, Left, and Right."); MGlobal.displayInfo("\t-s -set [<setName>]: Set/get the set for a particular layer"); MGlobal.displayInfo("\t-e -edit : Perform an edit operation"); MGlobal.displayInfo("\t-q -query : Perform a query operation"); MGlobal.displayInfo(""); } uint nObjs = list.length; if (nObjs == 0) { if (createdUsed) { // Create a new cameraSet node. // MFnDependencyNode dirFn = new MFnDependencyNode(); string noName = ""; try { MObject dirObj = dirFn.create(exCameraSet.type_id, noName); MGlobal.select(dirObj, MGlobal.ListAdjustment.kReplaceList); } catch (System.Exception ex) { throw new ApplicationException("Could not create a cameraSet node", ex); } return; } if (appendCameraUsed || appendCameraAndSetUsed || deleteLayerUsed || editUsed || cameraUsed || setUsed || layerTypeUsed || activeUsed || numLayersUsed) { throw new ArgumentException("Must specify a cameraSet node", "args"); } } else { if (createdUsed) { throw new ArgumentException("-create cannot have any object specified", "args"); } if (appendCameraUsed) { if (nObjs != 1) { throw new ArgumentException("-appendCamera must have a single cameraSet node specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-appendCamera must have a valid exCameraSet node specified", "args"); } // Get a dag path to the specified camera. // MSelectionList camList = new MSelectionList(); camList.add(camName); MDagPath camPath = new MDagPath(); camList.getDagPath(0, camPath); if (!camPath.isValid) { throw new ArgumentException("-appendCamera must have a valid camera node specified", "args"); } // Call the MFnCameraSet method to append the layer. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.appendLayer(camPath, MObject.kNullObj); return; } if (appendCameraAndSetUsed) { if (nObjs != 1) { throw new ArgumentException("-appendCameraAndSet must have a single cameraSet node specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-appendCameraAndSet must have a valid exCameraSet node specified", "args"); } // Get a dag path to the specified camera. // MSelectionList camList = new MSelectionList(); camList.add(camName); MDagPath camPath = new MDagPath(); camList.getDagPath(0, camPath); if (!camPath.isValid) { throw new ArgumentException("-appendCameraAndSet must have a valid camera node specified", "args"); } // Get the specified set node. // MSelectionList setList = new MSelectionList(); setList.add(setName); MObject setObj = MObject.kNullObj; setList.getDependNode(0, setObj); if (setObj == MObject.kNullObj) { throw new ArgumentException("-appendCameraAndSet must have a valid set node specified", "args"); } // Call the MFnCameraSet method to append the layer. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.appendLayer(camPath, setObj); return; } if (deleteLayerUsed) { if (nObjs != 1) { throw new ArgumentException("-deleteLayer must have a single cameraSet node specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-deleteLayer must have a valid exCameraSet node specified", "args"); } // Call the MFnCameraSet method to delete the layer. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.deleteLayer((uint)cameraLayer); return; } if (numLayersUsed) { if (queryUsed) { // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-numLayers must have a valid exCameraSet node specified", "args"); } // Call the MFnCameraSet method to get the number of layers. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); uint numLayers = dirFn.numLayers; setResult((int)numLayers); } else { throw new ArgumentException("-numLayers requires the query flag to be used", "args"); } return; } if (cameraUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-camera must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-camera must have a valid exCameraSet node specified", "args"); } if (editUsed) { // Get a dag path to the specified camera. // MSelectionList camList = new MSelectionList(); camList.add(camName); MDagPath camPath = new MDagPath(); camList.getDagPath(0, camPath); if (!camPath.isValid) { throw new ArgumentException("-camera must have a valid camera node specified", "args"); } // Call the MFnCameraSet method to set the camera. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.setLayerCamera((uint)cameraLayer, camPath); } else if (queryUsed) { // Call the MFnCameraSet method to get the camera. // MDagPath camPath = new MDagPath(); MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.getLayerCamera((uint)cameraLayer, camPath); MObject camNode = camPath.node; MFnDependencyNode nodeFn = new MFnDependencyNode(camNode); setResult(nodeFn.name); } } if (setUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-set must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-set must have a valid exCameraSet node specified", "args"); } if (editUsed) { // Get the specified set node. // MObject setObj = MObject.kNullObj; if (setName != "") { MSelectionList setList = new MSelectionList(); setList.add(setName); setList.getDependNode(0, setObj); if (setObj == MObject.kNullObj) { throw new ArgumentException("-set must have a valid set node specified", "args"); } } // Call the MFnCameraSet method to set the set node. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.setLayerSceneData((uint)cameraLayer, setObj); } else if (queryUsed) { // Call the MFnCameraSet method to get the set node. // MObject setObj = new MObject(); MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.getLayerSceneData((uint)cameraLayer, setObj); MFnDependencyNode nodeFn = new MFnDependencyNode(setObj); setResult(nodeFn.name); } } if (layerTypeUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-layerType must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-layerType must have a valid exCameraSet node specified", "args"); } MFnDependencyNode nodeFn = new MFnDependencyNode(dirNode); exCameraSet exDir = nodeFn.userNode as exCameraSet; if (editUsed) { // Get the specified layer type. // int pt = -1; if (layerTypeVal == "Mono") { pt = 0; } else if (layerTypeVal == "Left") { pt = 1; } else if (layerTypeVal == "Right") { pt = 2; } else { throw new ArgumentException("-layerType must have a valid type specified", "args"); } // Call the exCameraSet method to set the layer type. // exDir.setLayerType((uint)cameraLayer, pt); } else if (queryUsed) { // Call the exCameraSet method to get the layer type. // try { int lt = exDir.getLayerType((uint)cameraLayer); if (lt == 0) { setResult("Mono"); } else if (lt == 1) { setResult("Left"); } else if (lt == 2) { setResult("Right"); } } catch (System.Exception ex) { throw new ApplicationException("exCameraSet node does not have a valid layer type", ex); } } } if (activeUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-active must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-active must have a valid exCameraSet node specified", "args"); } if (editUsed) { // Call the MFnCameraSet method to set the set node. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.setLayerActive((uint)cameraLayer, activeVal); } else if (queryUsed) { // Call the MFnCameraSet method to get the active value. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); activeVal = dirFn.isLayerActive((uint)cameraLayer); setResult(activeVal); } } } return; }
public static MFnDependencyNode CombineToUDIM(List <MFnDependencyNode> imageNodes, string prename, string newFolder = "UDIM", int maxUCount = 5) { if (imageNodes.Count < 2) { return(null); } MFnDependencyNode udimImgNode = CreateShadingNode(ShadingNodeType.Texture, ConstantValue.nodeName_fileTex); //MFnDependencyNode udimImgNode = new MFnDependencyNode(); //udimImgNode.create("file"); MPlug texOutColorPlug = udimImgNode.findPlug(ConstantValue.plugName_fileTexOutputColor); MPlug texOutTransparencyPlug = udimImgNode.findPlug(ConstantValue.plugName_fileTexOutputTransparency); udimImgNode.findPlug(ConstantValue.plugName_fileTexUVTilingMode).setInt((int)ConstantValue.UVTilingMode.UDIM); MDGModifier dGModifier = new MDGModifier(); for (int i = 0; i < imageNodes.Count; i++) { MPlug plug_fileTexPath = imageNodes[i].findPlug(ConstantValue.plugName_fileTexPath); string originFullPath = plug_fileTexPath.asString(); int uIndex = i % maxUCount; int vIndex = i / maxUCount; string mariIndexStr = string.Format("{0}.10{1}{2}", prename, vIndex, uIndex + 1); string newFullPath = RenameTexFile(imageNodes[i], mariIndexStr, newFolder); if (i == 0) { udimImgNode.findPlug(ConstantValue.plugName_fileTexPath).setString(newFullPath); } //move uv and reconnect link MPlugArray plugArr_transparencyDest, plugArr_colorDest; MSelectionList matList = GetMaterialsWithTex(imageNodes[i], out plugArr_colorDest, out plugArr_transparencyDest); //move uv for every material for (int j = 0; j < matList.length; j++) { MObject matObj = new MObject(); matList.getDependNode((uint)j, matObj); MFnDependencyNode matNode = new MFnDependencyNode(matObj); string matName = matNode.absoluteName; //Debug.Log("move uv for mat:" + matName); MoveUV(uIndex, vIndex, matName); //MPlug plug_matColorInput = matNode.findPlug(ConstantValue.plugName_matColorInput); //if (plug_matColorInput != null) //{ // dGModifier.disconnect(plug_matColorInput.source, plug_matColorInput); // dGModifier.connect(texOutColorPlug, plug_matColorInput); // dGModifier.doIt(); //} } //reconnect alpha for (int j = 0; j < plugArr_transparencyDest.length; j++) { dGModifier.disconnect(plugArr_transparencyDest[j].source, plugArr_transparencyDest[j]); dGModifier.connect(texOutTransparencyPlug, plugArr_transparencyDest[j]); } //reconnect color for (int j = 0; j < plugArr_colorDest.length; j++) { dGModifier.disconnect(plugArr_colorDest[j].source, plugArr_colorDest[j]); dGModifier.connect(texOutColorPlug, plugArr_colorDest[j]); } } dGModifier.doIt(); return(udimImgNode); }
// Parses the given command line arguments and executes them. // public override void doIt(MArgList args) { parseArgs(args); bool nothingSet = (!createdUsed && !appendCameraUsed && !appendCameraAndSetUsed && !deleteLayerUsed && !cameraUsed && !layerUsed && !helpUsed && !setUsed && !layerTypeUsed && !numLayersUsed); if (nothingSet) { throw new ArgumentException("A flag must be used. testCameraSet -help for available flags", "args"); } if (helpUsed) { MGlobal.displayInfo("testExCameraSet -help"); MGlobal.displayInfo("\ttestExCameraSet tests the functionality of the exCameraSet node."); MGlobal.displayInfo(""); MGlobal.displayInfo("\t-h -help : This message is printed"); MGlobal.displayInfo("\t-a -active [true/false]: Set/get whether a particular layer is active"); MGlobal.displayInfo("\t-ac -appendCamera <cameraName>: Append a new camera layer to the cameraSet using the specified camera"); MGlobal.displayInfo("\t-acs -appendCameraAndSet <cameraName> <setName>: Append a new camera layer to the cameraSet using the specified camera and set"); MGlobal.displayInfo("\t-cam -camera [<cameraName>]: Set/get the camera for a particular layer"); MGlobal.displayInfo("\t-c -create : Create a new cameraSet node"); MGlobal.displayInfo("\t-d -deleteLayer <layerIndex>: Delete the layer at the given index"); MGlobal.displayInfo("\t-nl -numLayers: Returns the number of layers defined in the specified cameraSet"); MGlobal.displayInfo("\t-l -layer <layerIndex>: Specifies the layer index to be used when accessing layer information"); MGlobal.displayInfo("\t-lt -layerType [<layerTypeName>]: Set/get the layer type for a particular layer. Possible values are Mono, Left, and Right."); MGlobal.displayInfo("\t-s -set [<setName>]: Set/get the set for a particular layer"); MGlobal.displayInfo("\t-e -edit : Perform an edit operation"); MGlobal.displayInfo("\t-q -query : Perform a query operation"); MGlobal.displayInfo(""); } uint nObjs = list.length; if (nObjs == 0) { if (createdUsed) { // Create a new cameraSet node. // MFnDependencyNode dirFn = new MFnDependencyNode(); string noName = ""; try { MObject dirObj = dirFn.create(exCameraSet.type_id, noName); MGlobal.select(dirObj, MGlobal.ListAdjustment.kReplaceList); } catch (System.Exception ex) { throw new ApplicationException("Could not create a cameraSet node", ex); } return; } if (appendCameraUsed || appendCameraAndSetUsed || deleteLayerUsed || editUsed || cameraUsed || setUsed || layerTypeUsed || activeUsed || numLayersUsed) { throw new ArgumentException("Must specify a cameraSet node", "args"); } } else { if (createdUsed) { throw new ArgumentException("-create cannot have any object specified", "args"); } if (appendCameraUsed) { if (nObjs != 1) { throw new ArgumentException("-appendCamera must have a single cameraSet node specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-appendCamera must have a valid exCameraSet node specified", "args"); } // Get a dag path to the specified camera. // MSelectionList camList = new MSelectionList(); camList.add(camName); MDagPath camPath = new MDagPath(); camList.getDagPath(0, camPath); if (!camPath.isValid) { throw new ArgumentException("-appendCamera must have a valid camera node specified", "args"); } // Call the MFnCameraSet method to append the layer. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.appendLayer(camPath, MObject.kNullObj); return; } if (appendCameraAndSetUsed) { if (nObjs != 1) { throw new ArgumentException("-appendCameraAndSet must have a single cameraSet node specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-appendCameraAndSet must have a valid exCameraSet node specified", "args"); } // Get a dag path to the specified camera. // MSelectionList camList = new MSelectionList(); camList.add(camName); MDagPath camPath = new MDagPath(); camList.getDagPath(0, camPath); if (!camPath.isValid) { throw new ArgumentException("-appendCameraAndSet must have a valid camera node specified", "args"); } // Get the specified set node. // MSelectionList setList = new MSelectionList(); setList.add(setName); MObject setObj = MObject.kNullObj; setList.getDependNode(0, setObj); if (setObj == MObject.kNullObj) { throw new ArgumentException("-appendCameraAndSet must have a valid set node specified", "args"); } // Call the MFnCameraSet method to append the layer. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.appendLayer(camPath, setObj); return; } if (deleteLayerUsed) { if (nObjs != 1) { throw new ArgumentException("-deleteLayer must have a single cameraSet node specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-deleteLayer must have a valid exCameraSet node specified", "args"); } // Call the MFnCameraSet method to delete the layer. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.deleteLayer((uint)cameraLayer); return; } if (numLayersUsed) { if (queryUsed) { // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-numLayers must have a valid exCameraSet node specified", "args"); } // Call the MFnCameraSet method to get the number of layers. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); uint numLayers = dirFn.numLayers; setResult((int)numLayers); } else { throw new ArgumentException("-numLayers requires the query flag to be used", "args"); } return; } if (cameraUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-camera must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-camera must have a valid exCameraSet node specified", "args"); } if (editUsed) { // Get a dag path to the specified camera. // MSelectionList camList = new MSelectionList(); camList.add(camName); MDagPath camPath = new MDagPath(); camList.getDagPath(0, camPath); if (!camPath.isValid) { throw new ArgumentException("-camera must have a valid camera node specified", "args"); } // Call the MFnCameraSet method to set the camera. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.setLayerCamera((uint)cameraLayer, camPath); } else if (queryUsed) { // Call the MFnCameraSet method to get the camera. // MDagPath camPath = new MDagPath(); MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.getLayerCamera((uint)cameraLayer, camPath); MObject camNode = camPath.node; MFnDependencyNode nodeFn = new MFnDependencyNode(camNode); setResult(nodeFn.name); } } if (setUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-set must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-set must have a valid exCameraSet node specified", "args"); } if (editUsed) { // Get the specified set node. // MObject setObj = MObject.kNullObj; if (setName != "") { MSelectionList setList = new MSelectionList(); setList.add(setName); setList.getDependNode(0, setObj); if (setObj == MObject.kNullObj) { throw new ArgumentException("-set must have a valid set node specified", "args"); } } // Call the MFnCameraSet method to set the set node. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.setLayerSceneData((uint)cameraLayer, setObj); } else if (queryUsed) { // Call the MFnCameraSet method to get the set node. // MObject setObj = new MObject(); MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.getLayerSceneData((uint)cameraLayer, setObj); MFnDependencyNode nodeFn = new MFnDependencyNode(setObj); setResult(nodeFn.name); } } if (layerTypeUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-layerType must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-layerType must have a valid exCameraSet node specified", "args"); } MFnDependencyNode nodeFn = new MFnDependencyNode(dirNode); exCameraSet exDir = nodeFn.userNode as exCameraSet; if (editUsed) { // Get the specified layer type. // int pt = -1; if (layerTypeVal == "Mono") pt = 0; else if (layerTypeVal == "Left") pt = 1; else if (layerTypeVal == "Right") pt = 2; else { throw new ArgumentException("-layerType must have a valid type specified", "args"); } // Call the exCameraSet method to set the layer type. // exDir.setLayerType((uint)cameraLayer, pt); } else if (queryUsed) { // Call the exCameraSet method to get the layer type. // try { int lt = exDir.getLayerType((uint)cameraLayer); if (lt == 0) setResult("Mono"); else if (lt == 1) setResult("Left"); else if (lt == 2) setResult("Right"); } catch (System.Exception ex) { throw new ApplicationException("exCameraSet node does not have a valid layer type", ex); } } } if (activeUsed) { if ((nObjs != 1) || (!layerUsed)) { throw new ArgumentException("-active must have a cameraSet node and layer specified", "args"); } // Get the specified cameraSet node. // MObject dirNode = MObject.kNullObj; if (!getExCameraSetNode(dirNode)) { throw new ArgumentException("-active must have a valid exCameraSet node specified", "args"); } if (editUsed) { // Call the MFnCameraSet method to set the set node. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); dirFn.setLayerActive((uint)cameraLayer, activeVal); } else if (queryUsed) { // Call the MFnCameraSet method to get the active value. // MFnCameraSet dirFn = new MFnCameraSet(dirNode); activeVal = dirFn.isLayerActive((uint)cameraLayer); setResult(activeVal); } } } return; }
public static bool CombineSameTextures(MSelectionList list, bool deleteRepeated = true) { if (!BasicFunc.CheckSelectionList(list, 2)) { Debug.Log("please choose at least 2 materials"); return(false); } //string texFilePath = ""; //List<string> texFilePaths = new List<string>(); Dictionary <string, int> combineDic = new Dictionary <string, int>(); List <MPlug> texOutputPlugs = new List <MPlug>(); MDGModifier dGModifier = new MDGModifier(); List <MObject> deleteList = new List <MObject>(); for (int i = 0; i < list.length; i++) { MObject texObject = new MObject(); list.getDependNode((uint)i, texObject); //MImage img = new MImage(); //img.readFromTextureNode(texObject, MImage.MPixelType.kUnknown); MFnDependencyNode texDN = new MFnDependencyNode(texObject); MPlug texPlug = texDN.findPlug(ConstantValue.plugName_fileTexPath); MPlug texOutputPlug = texDN.findPlug(ConstantValue.plugName_fileTexOutputColor); //Debug.Log("texplug name:" + texPlug.name); texOutputPlugs.Add(texOutputPlug); string filePath = texPlug.asString(); //Debug.Log("path:" + filePath); if (combineDic.ContainsKey(filePath)) { //combine int targetIndex = combineDic[filePath]; //Debug.Log("combine " + i + " to " + targetIndex); MPlugArray destPlugs = new MPlugArray(); texOutputPlug.destinations(destPlugs); for (int j = 0; j < destPlugs.Count; j++) { //Debug.Log("texPlugs[targetIndex]:" + texOutputPlugs[targetIndex].name + " , destPlugs[j]" + destPlugs[j].name); dGModifier.disconnect(texOutputPlug, destPlugs[j]); dGModifier.connect(texOutputPlugs[targetIndex], destPlugs[j]); } deleteList.Add(texObject); } else { combineDic.Add(filePath, i); } } dGModifier.doIt(); if (deleteRepeated) { for (int i = 0; i < deleteList.Count; i++) { dGModifier.deleteNode(deleteList[i]); } } dGModifier.doIt(); return(true); }