Beispiel #1
0
        public override bool doRelease(M3dView view)
        {
            // Scale nodes on the selection list.
            // Simple implementation that does not
            // support undo.
            MSelectionList list = new MSelectionList();

            MGlobal.getActiveSelectionList(list);
            MObject node = new MObject();

            for (MItSelectionList iter = new MItSelectionList(list); !iter.isDone; iter.next())
            {
                iter.getDependNode(node);
                MFnTransform xform;
                try
                {
                    xform = new MFnTransform(node);
                }
                catch (System.Exception)
                {
                    continue;
                }

                double[] newScale = new double[3];
                newScale[0] = mousePointGlName.x + 1;
                newScale[1] = mousePointGlName.y + 1;
                newScale[2] = mousePointGlName.z + 1;
                xform.setScale(newScale);
            }
            return(true);
        }
Beispiel #2
0
        void parseArgs(MArgList args)
        {
            string         arg          = "";
            MSelectionList list         = new MSelectionList();
            bool           charNameUsed = false;
            string         charName;
            const string   charFlag     = "-c";
            const string   charFlagLong = "-char";

            for (uint i = 0; i < args.length; i++)
            {
                arg = args.asString(i);
                if (arg == charFlag || arg == charFlagLong)
                {
                    // get the char name
                    //
                    if (i == args.length - 1)
                    {
                        arg += ": must specify a character name";
                        throw new ArgumentException(arg, "args");
                    }
                    i++;
                    charName = args.asString(i);
                    list.add(charName);

                    charNameUsed = true;
                }
                else
                {
                    arg += ": unknown argument";
                    throw new ArgumentException(arg, "args");
                }
            }

            if (charNameUsed)
            {
                // get the character corresponding to the node name
                //
                MItSelectionList iter = new MItSelectionList(list);
                for (; iter.isDone; iter.next())
                {
                    MObject node = new MObject();
                    iter.getDependNode(node);
                    if (node.apiType == MFn.Type.kCharacter)
                    {
                        fCharacter = node;
                        break;
                    }
                }

                if (fCharacter.isNull)
                {
                    throw new ApplicationException("Unable to get the character corresponding to the node name.");
                }
            }
        }
Beispiel #3
0
        /*!
         * Callback that creates the manipulator if valid geometry is
         * selected. Also removes the manipulator if no geometry is
         * selected. Handles connecting the manipulator to multiply
         * selected nodes.
         *
         * \param[in] data Pointer to the current context class.
         */
        void updateManipulators()
        {
            deleteManipulators();

            if (!validGeometrySelected())
            {
                return;
            }

            // Clear info
            owner = null;
            firstObjectSelected = MObject.kNullObj;

            MSelectionList list = new MSelectionList();

            MGlobal.getActiveSelectionList(list);
            MItSelectionList iter = new MItSelectionList(list, MFn.Type.kInvalid);

            string             manipName   = "lineManipContainerCSharp";
            MObject            manipObject = new MObject();
            lineManipContainer manipulator = MPxManipContainer.newManipulator(manipName, manipObject) as lineManipContainer;

            if (null != manipulator)
            {
                // Save state
                owner = manipulator;
                // Add the manipulator
                addManipulator(manipObject);
                //
                for (; !iter.isDone; iter.next())
                {
                    MObject dependNode = new MObject();
                    iter.getDependNode(dependNode);
                    MFnDependencyNode dependNodeFn = new MFnDependencyNode(dependNode);
                    // Connect the manipulator to the object in the selection list.
                    manipulator.connectToDependNode(dependNode);
                    //
                    if (MObject.kNullObj == firstObjectSelected)
                    {
                        firstObjectSelected = dependNode;
                    }
                }

                // Allow the manipulator to set initial state
                setInitialState();
            }
        }
Beispiel #4
0
        //! Ensure that valid geometry is selected
        bool validGeometrySelected()
        {
            MSelectionList list = new MSelectionList();

            MGlobal.getActiveSelectionList(list);
            MItSelectionList iter = new MItSelectionList(list, MFn.Type.kInvalid);

            for (; !iter.isDone; iter.next())
            {
                MObject dependNode = new MObject();
                iter.getDependNode(dependNode);
                if (dependNode.isNull || !dependNode.hasFn(MFn.Type.kTransform))
                {
                    MGlobal.displayWarning("Object in selection list is not right type of node");
                    return(false);
                }

                MFnDependencyNode dependNodeFn   = new MFnDependencyNode(dependNode);
                MStringArray      attributeNames = new MStringArray();
                attributeNames.append("scaleX");
                attributeNames.append("translateX");

                int i;
                for (i = 0; i < attributeNames.length; i++)
                {
                    MPlug plug = dependNodeFn.findPlug(attributeNames[i]);
                    if (plug.isNull)
                    {
                        MGlobal.displayWarning("Object cannot be manipulated: " +
                                               dependNodeFn.name);
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #5
0
        public static void updateManipulators(RotateManipContext ctx)
        {
            if (ctx == null)
                return;

            ctx.deleteManipulators();

            // Add the rotate manipulator to each selected object.  This produces 
            // behavior different from the default rotate manipulator behavior.  Here,
            // a distinct rotate manipulator is attached to every object.
            // 
            try
            {
                MSelectionList list = MGlobal.activeSelectionList;

                MItSelectionList iter = new MItSelectionList(list, MFn.Type.kInvalid);
                for (; !iter.isDone; iter.next())
                {

                    // Make sure the selection list item is a depend node and has the
                    // required plugs before manipulating it.
                    //
                    MObject dependNode = new MObject();
                    iter.getDependNode(dependNode);
                    if (dependNode.isNull || !dependNode.hasFn(MFn.Type.kDependencyNode))
                    {
                        MGlobal.displayWarning("Object in selection list is not a depend node.");
                        continue;
                    }

                    MFnDependencyNode dependNodeFn = new MFnDependencyNode(dependNode);
                    try
                    {
                        /* MPlug rPlug = */
                        dependNodeFn.findPlug("rotate");
                    }
                    catch (System.Exception)
                    {
                        MGlobal.displayWarning("Object cannot be manipulated: " + dependNodeFn.name);
                        continue;
                    }

                    // Add manipulator to the selected object
                    //
                    MObject manipObject = new MObject();

                    exampleRotateManip manipulator;
                    try
                    {
                        manipulator = exampleRotateManip.newManipulator("exampleRotateManipCSharp", manipObject) as exampleRotateManip;

                        // Add the manipulator
                        //
                        ctx.addManipulator(manipObject);

                        // Connect the manipulator to the object in the selection list.
                        //
                        try
                        {
                            manipulator.connectToDependNode(dependNode);
                        }
                        catch (System.Exception)
                        {
                            MGlobal.displayWarning("Error connecting manipulator to object: " + dependNodeFn.name);
                        }
                    }
                    catch (System.Exception)
                    {

                    }
                }
            }
            catch (System.Exception)
            {

            }

        }
Beispiel #6
0
		/*!
		  Callback that creates the manipulator if valid geometry is
		  selected. Also removes the manipulator if no geometry is
		  selected. Handles connecting the manipulator to multiply
		  selected nodes.

		  \param[in] data Pointer to the current context class.
		*/
		void updateManipulators()
		{
			deleteManipulators();

			if ( ! validGeometrySelected() )
			{
				return;
			}

			// Clear info
			owner = null;
			firstObjectSelected = MObject.kNullObj;

			MSelectionList list = new MSelectionList();
			MGlobal.getActiveSelectionList(list);
			MItSelectionList iter = new MItSelectionList(list, MFn.Type.kInvalid);

			string manipName = "lineManipContainerCSharp";
			MObject manipObject = new MObject();
			lineManipContainer manipulator = MPxManipContainer.newManipulator(manipName, manipObject) as lineManipContainer;

			if (null != manipulator)
			{
				// Save state
				owner = manipulator;
				// Add the manipulator
				addManipulator(manipObject);
				//
				for (; !iter.isDone; iter.next())
				{
					MObject dependNode = new MObject();
					iter.getDependNode(dependNode);
					MFnDependencyNode dependNodeFn = new MFnDependencyNode(dependNode);
					// Connect the manipulator to the object in the selection list.
					manipulator.connectToDependNode(dependNode);
					//
					if (MObject.kNullObj == firstObjectSelected)
					{
						firstObjectSelected = dependNode;
					}
				}

				// Allow the manipulator to set initial state
				setInitialState();
			}
		}
Beispiel #7
0
		//! Ensure that valid geometry is selected
		bool validGeometrySelected()
		{
			MSelectionList list = new MSelectionList();
			MGlobal.getActiveSelectionList(list);
			MItSelectionList iter = new MItSelectionList(list, MFn.Type.kInvalid);

			for (; !iter.isDone; iter.next())
			{
				MObject dependNode = new MObject();
				iter.getDependNode(dependNode);
				if (dependNode.isNull || !dependNode.hasFn(MFn.Type.kTransform))
				{
					MGlobal.displayWarning("Object in selection list is not right type of node");
					return false;
				}

				MFnDependencyNode dependNodeFn = new MFnDependencyNode(dependNode);
				MStringArray attributeNames = new MStringArray();
				attributeNames.append("scaleX");
				attributeNames.append("translateX");

				int i;
				for ( i = 0; i < attributeNames.length; i++ )
				{
					MPlug plug = dependNodeFn.findPlug(attributeNames[i]);
					if ( plug.isNull )
					{
						MGlobal.displayWarning("Object cannot be manipulated: " +
							dependNodeFn.name);
						return false;
					}
				}
			}
			return true;
		}
Beispiel #8
0
		public override bool doRelease(M3dView view)
		{
			// Scale nodes on the selection list.
			// Simple implementation that does not
			// support undo.
			MSelectionList list = new MSelectionList();
			MGlobal.getActiveSelectionList(list);
			MObject node = new MObject();
			for (MItSelectionList iter = new MItSelectionList(list); !iter.isDone; iter.next())
			{
				iter.getDependNode(node);
				MFnTransform xform;
				try
				{
					xform = new MFnTransform(node);
				}
				catch (System.Exception)
				{
					continue;
				}

				double[] newScale = new double[3];
				newScale[0] = mousePointGlName.x + 1;
				newScale[1] = mousePointGlName.y + 1;
				newScale[2] = mousePointGlName.z + 1;
				xform.setScale(newScale);
			}
			return true;
		}
Beispiel #9
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;
		}
Beispiel #10
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;
        }
Beispiel #11
0
		void parseArgs(MArgList args)
		{
			string arg = "";
			MSelectionList list = new MSelectionList();
			bool charNameUsed = false;
			string charName;
			const string charFlag = "-c";
			const string charFlagLong = "-char";

			for (uint i = 0; i < args.length; i++)
			{
				arg = args.asString(i);
				if (arg == charFlag || arg == charFlagLong)
				{
					// get the char name
					//
					if (i == args.length - 1)
					{
						arg += ": must specify a character name";
						throw new ArgumentException(arg, "args"); 
					}
					i++;
					charName = args.asString(i);
					list.add(charName);

					charNameUsed = true;
				}
				else
				{
					arg += ": unknown argument";
					throw new ArgumentException(arg, "args"); 
				}
			}

			if (charNameUsed)
			{
				// get the character corresponding to the node name
				//
				MItSelectionList iter = new MItSelectionList(list);
				for (; iter.isDone; iter.next())
				{
					MObject node = new MObject();
					iter.getDependNode(node);
					if (node.apiType == MFn.Type.kCharacter)
					{
						fCharacter = node;
						break;
					}
				}

				if (fCharacter.isNull)
				{
					throw new ApplicationException("Unable to get the character corresponding to the node name.");
				}
			}
		}
Beispiel #12
0
        public static void updateManipulators(RotateManipContext ctx)
        {
            if (ctx == null)
            {
                return;
            }

            ctx.deleteManipulators();

            // Add the rotate manipulator to each selected object.  This produces
            // behavior different from the default rotate manipulator behavior.  Here,
            // a distinct rotate manipulator is attached to every object.
            //
            try
            {
                MSelectionList list = MGlobal.activeSelectionList;

                MItSelectionList iter = new MItSelectionList(list, MFn.Type.kInvalid);
                for (; !iter.isDone; iter.next())
                {
                    // Make sure the selection list item is a depend node and has the
                    // required plugs before manipulating it.
                    //
                    MObject dependNode = new MObject();
                    iter.getDependNode(dependNode);
                    if (dependNode.isNull || !dependNode.hasFn(MFn.Type.kDependencyNode))
                    {
                        MGlobal.displayWarning("Object in selection list is not a depend node.");
                        continue;
                    }

                    MFnDependencyNode dependNodeFn = new MFnDependencyNode(dependNode);
                    try
                    {
                        /* MPlug rPlug = */
                        dependNodeFn.findPlug("rotate");
                    }
                    catch (System.Exception)
                    {
                        MGlobal.displayWarning("Object cannot be manipulated: " + dependNodeFn.name);
                        continue;
                    }

                    // Add manipulator to the selected object
                    //
                    MObject manipObject = new MObject();

                    exampleRotateManip manipulator;
                    try
                    {
                        manipulator = exampleRotateManip.newManipulator("exampleRotateManipCSharp", manipObject) as exampleRotateManip;

                        // Add the manipulator
                        //
                        ctx.addManipulator(manipObject);

                        // Connect the manipulator to the object in the selection list.
                        //
                        try
                        {
                            manipulator.connectToDependNode(dependNode);
                        }
                        catch (System.Exception)
                        {
                            MGlobal.displayWarning("Error connecting manipulator to object: " + dependNodeFn.name);
                        }
                    }
                    catch (System.Exception)
                    {
                    }
                }
            }
            catch (System.Exception)
            {
            }
        }