Beispiel #1
0
        public static bool BindBlendShapeCtl(MFnBlendShapeDeformer bs, MDagPath ctlDagPath = null)
        {
            //MFnDependencyNode ctlNode = new MFnDependencyNode(ctlDagPath.node);
            if (bs == null)
            {
                Debug.Log("null blendShape");
                return(false);
            }
            //Debug.Log("here i am");

            if (ctlDagPath == null)
            {
                ctlDagPath = BasicFunc.CreateCTL_Crystal("ctl_bs_" + bs.name);
            }

            MFnDependencyNode ctlNode = new MFnDependencyNode(ctlDagPath.node);

            MPlug weightPlug = bs.findPlug(ConstantValue.plugName_blendShapeWeight);
            int   count      = (int)weightPlug.numElements;
            //Debug.Log("target count:" + count);

            MDGModifier dGModifier = new MDGModifier();

            for (int i = 0; i < count; i++)
            {
                //Debug.Log("process:" + i);
                MPlug  singleWeightPlug = weightPlug.elementByLogicalIndex((uint)i);
                string weightName       = singleWeightPlug.name.Split('.').Last();
                MPlug  ctlAttrPlug      = AddFloatAttr(ctlDagPath, weightName);
                dGModifier.connect(ctlAttrPlug, singleWeightPlug);
            }
            dGModifier.doIt();

            return(true);
        }
        public static MPlug FindFirstNotConnectedElement(MPlug plug)
        {
            uint  i = 0;
            MPlug returnPlug;

            do
            {
                returnPlug = plug.elementByLogicalIndex(i);
                i++;
            } while (returnPlug.isConnected);

            return(returnPlug);
        }
Beispiel #3
0
 public bool getLayerTypePlug(uint index, out MPlug layerTypePlug)
 {
     try
     {
         MPlug enumPlug = new MPlug(thisMObject(), exCameraSet.layerTypeAttr);
         layerTypePlug = enumPlug.elementByLogicalIndex(index);
         return(true);
     }
     catch (System.Exception)
     {
         layerTypePlug = null;
         return(false);
     }
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
		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 bool getLayerTypePlug(uint index, out MPlug layerTypePlug)
 {
     try
     {
         MPlug enumPlug = new MPlug(thisMObject(), exCameraSet.layerTypeAttr);
         layerTypePlug = enumPlug.elementByLogicalIndex(index);
         return true;
     }
     catch (System.Exception)
     {
         layerTypePlug = null;
         return false;
     }
 }
Beispiel #7
0
        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;
        }