Ejemplo n.º 1
0
        //======================================================================
        //
        // Look through the arg database and verify that the arguments are
        // valid. Only checks the common flags so derived classes should call
        // this parent method first before checking their own flags.
        //
        public virtual void checkArgs(MArgDatabase argsDb)
        {
            String formatType = "raw";

            fSerialize = AssociationsSerializer.formatByName(formatType);
            if (fSerialize == null)
            {
                String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kMetadataFormatNotFound);
                String msg = String.Format(fmt, formatType);
                displayError(msg);
                throw new System.ArgumentException(msg);
            }

            //----------------------------------------
            // (selection list)
            //
            // Commands need at least one mesh object on which to operate so gather up
            // the list of meshes specified and/or selected.
            //

            // Empty out the list of meshes on which to operate so that it can be
            // populated from the selection or specified lists.
            fMeshes.clear();

            MSelectionList objects = new MSelectionList();

            argsDb.getObjects(objects);
            for (int i = 0; i < objects.length; ++i)
            {
                MDagPath dagPath = new MDagPath();
                objects.getDagPath((uint)i, dagPath);

                MFnDagNode dagNode = new MFnDagNode(dagPath.node);
                MObject    obj     = dagNode.child(0);
                if (obj.apiTypeStr == "kMesh")
                {
                    MFnMesh mesh = new MFnMesh(obj);
                    if (mesh != null)
                    {
                        fMeshes.append(obj);
                    }
                }
                else
                {
                    String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError);
                    String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]");
                    displayError(msg);
                    throw new System.InvalidOperationException(msg);
                }
            }

            if (fMeshes.length == 0)
            {
                String msg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError);
                displayError(msg);
                throw new System.InvalidOperationException(msg);
            }
        }
Ejemplo n.º 2
0
        //======================================================================
        //
        // Check the parsed arguments and do/undo/redo the command as appropriate
        //
        void checkArgs(ref MArgDatabase argsDb)
        {
            //----------------------------------------
            // (selection list)
            //
            // Commands need at least one node on which to operate so gather up
            // the list of nodes specified and/or selected.
            //

            // Empty out the list of nodes on which to operate so that it can be
            // populated from the selection or specified lists.
            fNodes.clear();
            MSelectionList objects = new MSelectionList();

            argsDb.getObjects(objects);

            for (uint i = 0; i < objects.length; ++i)
            {
                MDagPath dagPath = new MDagPath();
                objects.getDagPath((uint)i, dagPath);
                MFnDagNode dagNode = new MFnDagNode(dagPath.node);
                MObject    obj     = dagNode.child(0);
                if (obj.apiTypeStr == "kMesh")
                {
                    if (obj == MObject.kNullObj)
                    {
                        throw new ApplicationException("Error: objects.getDependNode() ");
                    }
                    fNodes.append(dagPath.node);
                }
                else
                {
                    String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError);
                    String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]");
                    displayError(msg);
                    throw new System.InvalidOperationException(msg);
                }
            }

            if (fNodes.length == 0)
            {
                string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError);
                throw new ArgumentException(errMsg, "argsDb");
            }
        }
 protected override void getOutputAttributes(MObjectArray attributeArray)
 {
     attributeArray.clear();
     attributeArray.append(GeometrySurfaceConstraint.constraintGeometry);
 }
Ejemplo n.º 4
0
        public override void doIt(MArgList args)
        {
            // parse the command arguments
            //
            parseArgs(args);

            uint count = 0;
            // if the character flag was used, create the clip on the specified
            // character, otherwise, create a character
            //
            MFnCharacter fnCharacter = new MFnCharacter();

            if (fCharacter.isNull)
            {
                MSelectionList activeList = new MSelectionList();
                MGlobal.getActiveSelectionList(activeList);
                if (0 == activeList.length)
                {
                    throw new ApplicationException("Empty Active Selection List.");
                }

                // create a character using the selection list
                //
                fCharacter = fnCharacter.create(activeList, MFnSet.Restriction.kNone);
            }
            else
            {
                fnCharacter.setObject(fCharacter);
            }

            // Get the array of members of the character. We will create a clip
            // for them.
            //
            MPlugArray plugs = new MPlugArray();

            fnCharacter.getMemberPlugs(plugs);

            // Now create a animCurves to use as a clip for the character.
            // The curves will be set up between frames 0 and 10;
            //
            MTime        start      = new MTime(0.0);
            MTime        duration   = new MTime(10.0);
            MObjectArray clipCurves = new MObjectArray();

            for (count = 0; count < plugs.length; ++count)
            {
                // Now create a bunch of animCurves to use as a clip for the
                // character
                //
                MFnAnimCurve fnCurve = new MFnAnimCurve();
                MObject      curve   = fnCurve.create(MFnAnimCurve.AnimCurveType.kAnimCurveTL);          // plugType);
                fnCurve.addKeyframe(start, 5.0);
                fnCurve.addKeyframe(duration, 15.0);
                clipCurves.append(curve);
            }

            // Create a source clip node and add the animation to it
            //
            MFnClip fnClipCreate = new MFnClip();
            MObject sourceClip   = fnClipCreate.createSourceClip(start, duration, fMod);

            fnCharacter.attachSourceToCharacter(sourceClip, fMod);
            for (count = 0; count < plugs.length; ++count)
            {
                MPlug animPlug = plugs[(int)count];
                fnCharacter.addCurveToClip(clipCurves[(int)count], sourceClip, animPlug, fMod);
            }


            // instance the clip
            //
            MTime   schedStart    = new MTime(15.0);
            MObject instancedClip = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);

            fnCharacter.attachInstanceToCharacter(instancedClip, fMod);

            // instance the clip a second time, at time 30
            //
            schedStart.value = 30.0;
            MObject instancedClip2 = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);

            fnCharacter.attachInstanceToCharacter(instancedClip2, fMod);

            return;
        }
Ejemplo n.º 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;
		}
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        //
        //    Description:
        //        Overloaded function from MPxDragAndDropBehavior
        //    this method will handle the connection between the slopeShaderNodeCSharp and the shader it is
        //    assigned to as well as any meshes that it is assigned to.
        //
        public override void connectNodeToNode(MObject sourceNode, MObject destinationNode, bool force)
        {
            MFnDependencyNode src = new MFnDependencyNode(sourceNode);

            //if we are dragging from a lambert
            //we want to check what we are dragging
            //onto.
            if(sourceNode.hasFn(MFn.Type.kLambert))
            {
                //MObject shaderNode;
                MPlugArray connections = new MPlugArray();
                MObjectArray shaderNodes = new MObjectArray();
                shaderNodes.clear();

                //if the source node was a lambert
                //than we will check the downstream connections to see
                //if a slope shader is assigned to it.
                //
                src.getConnections(connections);
                int i;
                for(i = 0; i < connections.length; i++)
                {
                    //check the incoming connections to this plug
                    //
                    MPlugArray connectedPlugs = new MPlugArray();
                    connections[i].connectedTo(connectedPlugs, true, false);
                    for(uint j = 0; j < connectedPlugs.length; j++)
                    {
                        //if the incoming node is a slope shader than
                        //append the node to the shaderNodes array
                        //
                        MObject currentnode = connectedPlugs[i].node;
                        if (new MFnDependencyNode(currentnode).typeName == "slopeShaderNodeCSharp")
                        {
                            shaderNodes.append(currentnode);
                        }
                    }
                }

                //if we found a shading node
                //than check the destination node
                //type to see if it is a mesh
                //
                if(shaderNodes.length > 0)
                {
                    MFnDependencyNode dest = new MFnDependencyNode(destinationNode);
                    if(destinationNode.hasFn(MFn.Type.kMesh))
                    {
                        //if the node is a mesh than for each slopeShaderNodeCSharp
                        //connect the worldMesh attribute to the dirtyShaderPlug
                        //attribute to force an evaluation of the node when the mesh
                        //changes
                        //
                        for(i = 0; i < shaderNodes.length; i++)
                        {
                            MPlug srcPlug = dest.findPlug("worldMesh");
                            MPlug destPlug = new MFnDependencyNode(shaderNodes[i]).findPlug("dirtyShaderPlug");

                            if(!srcPlug.isNull && !destPlug.isNull)
                            {
                                string cmd = "connectAttr -na ";
                                cmd += srcPlug.name + " ";
                                cmd += destPlug.name;

                                try
                                {
                                    // in slopeShaderBehavior.cpp, this may excute failed but continue on the following code, so we catch it.
                                    MGlobal.executeCommand(cmd);
                                }
                                catch (System.Exception)
                                {
                                    MGlobal.displayError("ExcuteCommand (" + cmd + ") failed.");
                                }
                            }
                        }

                        //get the shading engine so we can assign the shader
                        //to the mesh after doing the connection
                        //
                        MObject shadingEngine = findShadingEngine(sourceNode);

                        //if there is a valid shading engine than make
                        //the connection
                        //
                        if(!shadingEngine.isNull)
                        {
                            string cmd = "sets -edit -forceElement ";
                            cmd += new MFnDependencyNode(shadingEngine).name + " ";
                            cmd += new MFnDagNode(destinationNode).partialPathName;
                            MGlobal.executeCommand(cmd);
                        }
                    }
                }
            }
            else if (src.typeName == "slopeShaderNodeCSharp")
            //if we are dragging from a slope shader
            //than we want to see what we are dragging onto
            //
            {
                if(destinationNode.hasFn(MFn.Type.kMesh))
                {
                    //if the user is dragging onto a mesh
                    //than make the connection from the worldMesh
                    //to the dirtyShader plug on the slopeShaderNodeCSharp
                    //
                    MFnDependencyNode dest = new MFnDependencyNode(destinationNode);
                    MPlug srcPlug = dest.findPlug("worldMesh");
                    MPlug destPlug = src.findPlug("dirtyShaderPlug");
                    if(!srcPlug.isNull && !destPlug.isNull)
                    {
                        string cmd = "connectAttr -na ";
                        cmd += srcPlug.name + " ";
                        cmd += destPlug.name;
                        MGlobal.executeCommand(cmd);
                    }
                }
            }

            return;
        }
Ejemplo n.º 8
0
        //======================================================================
        //
        // Check the parsed arguments and do/undo/redo the command as appropriate
        //
        void checkArgs(ref MArgDatabase argsDb)
        {
            //----------------------------------------
            // -structure flag
            //
            fStructureFlag.parse(ref argsDb, flagStructure);
            if (fStructureFlag.isSet())
            {
                if (!fStructureFlag.isArgValid())
                {
                    string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString);
                    throw new ArgumentException(errMsg, "argsDb");
                }

                string structureName = fStructureFlag.arg();
                try
                {
                    fStructure = Structure.structureByName(structureName);
                }
                catch (System.Exception)
                {
                    string msgFmt = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataStructureNotFound);
                    throw new ArgumentException(String.Format(msgFmt, structureName), "argsDb");
                }
            }
            else
            {
                string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName);
                throw new ArgumentException(errMsg, "argsDb");
            }

            //----------------------------------------
            // -streamName flag
            //
            fStreamNameFlag.parse(ref argsDb, flagStreamName);
            if (fStreamNameFlag.isSet())
            {
                if (!fStreamNameFlag.isArgValid())
                {
                    string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString);
                    throw new ArgumentException(errMsg, "argsDb");
                }
                fStreamName = fStreamNameFlag.arg();
            }
            else
            {
                string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName);
                throw new ArgumentException(errMsg, "argsDb");
            }

            //----------------------------------------
            // -channelType flag
            //
            fChannelTypeFlag.parse(ref argsDb, flagChannelType);
            if (fChannelTypeFlag.isSet())
            {
                if (!fChannelTypeFlag.isArgValid())
                {
                    string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString);
                    throw new ArgumentException(errMsg, "argsDb");
                }
                fChannelType = fChannelTypeFlag.arg();
            }
            else
            {
                string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName);
                throw new ArgumentException(errMsg, "argsDb");
            }

            //----------------------------------------
            // (selection list)
            //
            // Commands need at least one node on which to operate so gather up
            // the list of nodes specified and/or selected.
            //

            // Empty out the list of nodes on which to operate so that it can be
            // populated from the selection or specified lists.
            fNodes.clear();
            MSelectionList objects = new MSelectionList();

            argsDb.getObjects(objects);

            for (uint i = 0; i < objects.length; ++i)
            {
                MDagPath dagPath = new MDagPath();
                objects.getDagPath((uint)i, dagPath);
                MFnDagNode dagNode = new MFnDagNode(dagPath.node);
                MObject    obj     = dagNode.child(0);
                if (obj.apiTypeStr == "kMesh")
                {
                    if (obj == MObject.kNullObj)
                    {
                        throw new ApplicationException("Error: objects.getDependNode() ");
                    }
                    fNodes.append(dagPath.node);
                }
                else
                {
                    String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError);
                    String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]");
                    displayError(msg);
                    throw new System.InvalidOperationException(msg);
                }
            }

            if (fNodes.length == 0)
            {
                string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError);
                throw new ArgumentException(errMsg, "argsDb");
            }
        }
Ejemplo n.º 9
0
		public override void doIt(MArgList args)
		{
			// parse the command arguments
			//
			parseArgs(args);

			uint count = 0;
			// if the character flag was used, create the clip on the specified
			// character, otherwise, create a character
			//
			MFnCharacter fnCharacter = new MFnCharacter();
			if (fCharacter.isNull)
			{
				MSelectionList activeList = new MSelectionList();
				MGlobal.getActiveSelectionList(activeList);
				if (0 == activeList.length)
				{
					throw new ApplicationException("Empty Active Selection List.");
				}

				// create a character using the selection list
				//
				fCharacter = fnCharacter.create(activeList, MFnSet.Restriction.kNone);
			}
			else
				fnCharacter.setObject(fCharacter);

			// Get the array of members of the character. We will create a clip
			// for them.
			//
			MPlugArray plugs = new MPlugArray();
			fnCharacter.getMemberPlugs(plugs);

			// Now create a animCurves to use as a clip for the character.
			// The curves will be set up between frames 0 and 10;
			//
			MTime start = new MTime(0.0);
			MTime duration = new MTime(10.0);
			MObjectArray clipCurves = new MObjectArray();

			for (count = 0; count < plugs.length; ++count)
			{
				// Now create a bunch of animCurves to use as a clip for the
				// character
				//
				MFnAnimCurve fnCurve = new MFnAnimCurve();
				MObject curve = fnCurve.create(MFnAnimCurve.AnimCurveType.kAnimCurveTL); // plugType);
				fnCurve.addKeyframe(start, 5.0);
				fnCurve.addKeyframe(duration, 15.0);
				clipCurves.append(curve);
			}

			// Create a source clip node and add the animation to it
			//
			MFnClip fnClipCreate = new MFnClip();
			MObject sourceClip = fnClipCreate.createSourceClip(start, duration, fMod);
			fnCharacter.attachSourceToCharacter(sourceClip, fMod);
			for (count = 0; count < plugs.length; ++count)
			{
				MPlug animPlug = plugs[(int)count];
				fnCharacter.addCurveToClip(clipCurves[(int)count], sourceClip, animPlug, fMod);
			}


			// instance the clip
			//
			MTime schedStart = new MTime(15.0);
			MObject instancedClip = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);
			fnCharacter.attachInstanceToCharacter(instancedClip, fMod);

			// instance the clip a second time, at time 30
			//
			schedStart.value = 30.0;
			MObject instancedClip2 = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);
			fnCharacter.attachInstanceToCharacter(instancedClip2, fMod);

			return;
		}
Ejemplo n.º 10
0
        //
        //	Description:
        //		Overloaded function from MPxDragAndDropBehavior
        //	this method will handle the connection between the slopeShaderNodeCSharp and the shader it is
        //	assigned to as well as any meshes that it is assigned to.
        //
        public override void connectNodeToNode(MObject sourceNode, MObject destinationNode, bool force)
        {
            MFnDependencyNode src = new MFnDependencyNode(sourceNode);

            //if we are dragging from a lambert
            //we want to check what we are dragging
            //onto.
            if (sourceNode.hasFn(MFn.Type.kLambert))
            {
                //MObject shaderNode;
                MPlugArray   connections = new MPlugArray();
                MObjectArray shaderNodes = new MObjectArray();
                shaderNodes.clear();

                //if the source node was a lambert
                //than we will check the downstream connections to see
                //if a slope shader is assigned to it.
                //
                src.getConnections(connections);
                int i;
                for (i = 0; i < connections.length; i++)
                {
                    //check the incoming connections to this plug
                    //
                    MPlugArray connectedPlugs = new MPlugArray();
                    connections[i].connectedTo(connectedPlugs, true, false);
                    for (uint j = 0; j < connectedPlugs.length; j++)
                    {
                        //if the incoming node is a slope shader than
                        //append the node to the shaderNodes array
                        //
                        MObject currentnode = connectedPlugs[i].node;
                        if (new MFnDependencyNode(currentnode).typeName == "slopeShaderNodeCSharp")
                        {
                            shaderNodes.append(currentnode);
                        }
                    }
                }

                //if we found a shading node
                //than check the destination node
                //type to see if it is a mesh
                //
                if (shaderNodes.length > 0)
                {
                    MFnDependencyNode dest = new MFnDependencyNode(destinationNode);
                    if (destinationNode.hasFn(MFn.Type.kMesh))
                    {
                        //if the node is a mesh than for each slopeShaderNodeCSharp
                        //connect the worldMesh attribute to the dirtyShaderPlug
                        //attribute to force an evaluation of the node when the mesh
                        //changes
                        //
                        for (i = 0; i < shaderNodes.length; i++)
                        {
                            MPlug srcPlug  = dest.findPlug("worldMesh");
                            MPlug destPlug = new MFnDependencyNode(shaderNodes[i]).findPlug("dirtyShaderPlug");

                            if (!srcPlug.isNull && !destPlug.isNull)
                            {
                                string cmd = "connectAttr -na ";
                                cmd += srcPlug.name + " ";
                                cmd += destPlug.name;

                                try
                                {
                                    // in slopeShaderBehavior.cpp, this may excute failed but continue on the following code, so we catch it.
                                    MGlobal.executeCommand(cmd);
                                }
                                catch (System.Exception)
                                {
                                    MGlobal.displayError("ExcuteCommand (" + cmd + ") failed.");
                                }
                            }
                        }

                        //get the shading engine so we can assign the shader
                        //to the mesh after doing the connection
                        //
                        MObject shadingEngine = findShadingEngine(sourceNode);

                        //if there is a valid shading engine than make
                        //the connection
                        //
                        if (!shadingEngine.isNull)
                        {
                            string cmd = "sets -edit -forceElement ";
                            cmd += new MFnDependencyNode(shadingEngine).name + " ";
                            cmd += new MFnDagNode(destinationNode).partialPathName;
                            MGlobal.executeCommand(cmd);
                        }
                    }
                }
            }
            else if (src.typeName == "slopeShaderNodeCSharp")
            //if we are dragging from a slope shader
            //than we want to see what we are dragging onto
            //
            {
                if (destinationNode.hasFn(MFn.Type.kMesh))
                {
                    //if the user is dragging onto a mesh
                    //than make the connection from the worldMesh
                    //to the dirtyShader plug on the slopeShaderNodeCSharp
                    //
                    MFnDependencyNode dest     = new MFnDependencyNode(destinationNode);
                    MPlug             srcPlug  = dest.findPlug("worldMesh");
                    MPlug             destPlug = src.findPlug("dirtyShaderPlug");
                    if (!srcPlug.isNull && !destPlug.isNull)
                    {
                        string cmd = "connectAttr -na ";
                        cmd += srcPlug.name + " ";
                        cmd += destPlug.name;
                        MGlobal.executeCommand(cmd);
                    }
                }
            }

            return;
        }
Ejemplo n.º 11
0
 protected override void getOutputAttributes(MObjectArray attributeArray)
 {
     attributeArray.clear();
     attributeArray.append(GeometrySurfaceConstraint.constraintGeometry);
 }