示例#1
0
        public override void createChildren()
        {
            // Add the rotation manip
            //
            fRotateManip = addRotateManip("RotateManip", "rotation");

            // Add the state manip.  The state manip is used to cycle through the 
            // rotate manipulator modes to demonstrate how they work.
            //
            fStateManip = addStateManip("StateManip", "state");

            // The state manip permits 4 states.  These correspond to:
            // 0 - Rotate manip in objectSpace mode
            // 1 - Rotate manip in worldSpace mode
            // 2 - Rotate manip in gimbal mode
            // 3 - Rotate manip in objectSpace mode with snapping on
            //
            // Note that while the objectSpace and gimbal modes will operator similar 
            // to the built-in Maya rotate manipulator, the worldSpace mode will 
            // produce unusual rotations because the plugin does not convert worldSpace
            // rotations to object space.
            //
            MFnStateManip stateManip = new MFnStateManip(fStateManip);
            stateManip.maxStates = 4;
            stateManip.setInitialState(0);
        }
示例#2
0
        public override void createChildren()
        {
            // Add the rotation manip
            //
            fRotateManip = addRotateManip("RotateManip", "rotation");

            // Add the state manip.  The state manip is used to cycle through the
            // rotate manipulator modes to demonstrate how they work.
            //
            fStateManip = addStateManip("StateManip", "state");

            // The state manip permits 4 states.  These correspond to:
            // 0 - Rotate manip in objectSpace mode
            // 1 - Rotate manip in worldSpace mode
            // 2 - Rotate manip in gimbal mode
            // 3 - Rotate manip in objectSpace mode with snapping on
            //
            // Note that while the objectSpace and gimbal modes will operator similar
            // to the built-in Maya rotate manipulator, the worldSpace mode will
            // produce unusual rotations because the plugin does not convert worldSpace
            // rotations to object space.
            //
            MFnStateManip stateManip = new MFnStateManip(fStateManip);

            stateManip.maxStates = 4;
            stateManip.setInitialState(0);
        }
示例#3
0
        public override void connectToDependNode(MObject node)
        {
            // Find the rotate and rotatePivot plugs on the node.  These plugs will
            // be attached either directly or indirectly to the manip values on the
            // rotate manip.
            //
            MFnDependencyNode nodeFn = new MFnDependencyNode(node);
            MPlug             rPlug  = nodeFn.findPlug("rotate");
            MPlug             rcPlug = nodeFn.findPlug("rotatePivot");

            // If the translate pivot exists, it will be used to move the state manip
            // to a convenient location.
            //
            MPlug tPlug = nodeFn.findPlug("translate");

            // To avoid having the object jump back to the default rotation when the
            // manipulator is first used, extract the existing rotation from the node
            // and set it as the initial rotation on the manipulator.
            //
            MEulerRotation existingRotation    = new MEulerRotation(vectorPlugValue(rPlug));
            MVector        existingTranslation = new MVector(vectorPlugValue(tPlug));

            //
            // The following code configures default settings for the rotate
            // manipulator.
            //

            MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip);

            rotateManip.setInitialRotation(existingRotation);
            rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace);
            rotateManip.displayWithNode(node);

            // Add a callback function to be called when the rotation value changes
            //

            //rotatePlugIndex = addManipToPlugConversionCallback( rPlug, (manipToPlugConversionCallback)&exampleRotateManip::rotationChangedCallback );
            ManipToPlugConverion[rPlug] = rotationChangedCallback;
            // get the index of plug
            rotatePlugIndex = this[rPlug];

            // Create a direct (1-1) connection to the rotation center plug
            //
            rotateManip.connectToRotationCenterPlug(rcPlug);

            // Place the state manip at a distance of 2.0 units away from the object
            // along the X-axis.
            //
            MFnStateManip stateManip = new MFnStateManip(fStateManip);
            MVector       delta      = new MVector(2, 0, 0);

            stateManip.setTranslation(existingTranslation + delta,
                                      MSpace.Space.kTransform);

            finishAddingManips();
            base.connectToDependNode(node);
        }
示例#4
0
        public override void connectToDependNode(MObject node)
        {

            // Find the rotate and rotatePivot plugs on the node.  These plugs will 
            // be attached either directly or indirectly to the manip values on the
            // rotate manip.
            //
            MFnDependencyNode nodeFn = new MFnDependencyNode(node);
            MPlug rPlug = nodeFn.findPlug("rotate");
            MPlug rcPlug = nodeFn.findPlug("rotatePivot");

            // If the translate pivot exists, it will be used to move the state manip
            // to a convenient location.
            //
            MPlug tPlug = nodeFn.findPlug("translate");

            // To avoid having the object jump back to the default rotation when the
            // manipulator is first used, extract the existing rotation from the node
            // and set it as the initial rotation on the manipulator.
            //
            MEulerRotation existingRotation = new MEulerRotation(vectorPlugValue(rPlug));
            MVector existingTranslation = new MVector(vectorPlugValue(tPlug));

            // 
            // The following code configures default settings for the rotate 
            // manipulator.
            //

            MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip);
            rotateManip.setInitialRotation(existingRotation);
            rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace);
            rotateManip.displayWithNode(node);

            // Add a callback function to be called when the rotation value changes
            //

            //rotatePlugIndex = addManipToPlugConversionCallback( rPlug, (manipToPlugConversionCallback)&exampleRotateManip::rotationChangedCallback );
            ManipToPlugConverion[rPlug] = rotationChangedCallback;
            // get the index of plug
            rotatePlugIndex = this[rPlug];

            // Create a direct (1-1) connection to the rotation center plug
            //
            rotateManip.connectToRotationCenterPlug(rcPlug);

            // Place the state manip at a distance of 2.0 units away from the object
            // along the X-axis.
            //
            MFnStateManip stateManip = new MFnStateManip(fStateManip);
            MVector delta = new MVector(2, 0, 0);
            stateManip.setTranslation(existingTranslation + delta,
                MSpace.Space.kTransform);

            finishAddingManips();
            base.connectToDependNode(node);
        }
示例#5
0
        // Callback function
        MManipData rotationChangedCallback(object sender, ManipConversionArgs args)
        {
            MObject obj = MObject.kNullObj;

            // If we entered the callback with an invalid index, print an error and
            // return.  Since we registered the callback only for one plug, all 
            // invocations of the callback should be for that plug.
            //

            MFnNumericData numericData = new MFnNumericData();
            if (args.ManipIndex != rotatePlugIndex)
            {
                MGlobal.displayError("Invalid index in rotation changed callback!");

                // For invalid indices, return vector of 0's
                obj = numericData.create(MFnNumericData.Type.k3Double);
                numericData.setData(0.0, 0.0, 0.0);

                return new MManipData(obj);
            }

            // Assign function sets to the manipulators
            //
            MFnStateManip stateManip = new MFnStateManip(fStateManip);
            MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip);

            // Adjust settings on the rotate manip based on the state of the state 
            // manip.
            //
            uint mode = stateManip.state;
            if (mode != 3)
            {
                rotateManip.setRotateMode((MFnRotateManip.RotateMode)stateManip.state);
                rotateManip.setSnapMode(false);
            }
            else
            {
                // State 3 enables snapping for an object space manip.  In this case,
                // we snap every 15.0 degrees.
                //
                rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace);
                rotateManip.setSnapMode(true);
                rotateManip.snapIncrement = 15.0;
            }

            // The following code creates a data object to be returned in the 
            // MManipData.  In this case, the plug to be computed must be a 3-component
            // vector, so create data as MFnNumericData::k3Double
            //
            obj = numericData.create(MFnNumericData.Type.k3Double);

            // Retrieve the value for the rotation from the manipulator and return it
            // directly without modification.  If the manipulator should eg. slow down
            // rotation, this method would need to do some math with the value before
            // returning it.
            //
            MEulerRotation manipRotation = new MEulerRotation();
            try
            {
                getConverterManipValue(rotateManip.rotationIndex, manipRotation);
                numericData.setData(manipRotation.x, manipRotation.y, manipRotation.z);
            }
            catch (System.Exception)
            {
                MGlobal.displayError("Error retrieving manip value");
                numericData.setData(0.0, 0.0, 0.0);
            }

            return new MManipData(obj);
        }
示例#6
0
        // Callback function
        MManipData rotationChangedCallback(object sender, ManipConversionArgs args)
        {
            MObject obj = MObject.kNullObj;

            // If we entered the callback with an invalid index, print an error and
            // return.  Since we registered the callback only for one plug, all
            // invocations of the callback should be for that plug.
            //

            MFnNumericData numericData = new MFnNumericData();

            if (args.ManipIndex != rotatePlugIndex)
            {
                MGlobal.displayError("Invalid index in rotation changed callback!");

                // For invalid indices, return vector of 0's
                obj = numericData.create(MFnNumericData.Type.k3Double);
                numericData.setData(0.0, 0.0, 0.0);

                return(new MManipData(obj));
            }

            // Assign function sets to the manipulators
            //
            MFnStateManip  stateManip  = new MFnStateManip(fStateManip);
            MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip);

            // Adjust settings on the rotate manip based on the state of the state
            // manip.
            //
            uint mode = stateManip.state;

            if (mode != 3)
            {
                rotateManip.setRotateMode((MFnRotateManip.RotateMode)stateManip.state);
                rotateManip.setSnapMode(false);
            }
            else
            {
                // State 3 enables snapping for an object space manip.  In this case,
                // we snap every 15.0 degrees.
                //
                rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace);
                rotateManip.setSnapMode(true);
                rotateManip.snapIncrement = 15.0;
            }

            // The following code creates a data object to be returned in the
            // MManipData.  In this case, the plug to be computed must be a 3-component
            // vector, so create data as MFnNumericData::k3Double
            //
            obj = numericData.create(MFnNumericData.Type.k3Double);

            // Retrieve the value for the rotation from the manipulator and return it
            // directly without modification.  If the manipulator should eg. slow down
            // rotation, this method would need to do some math with the value before
            // returning it.
            //
            MEulerRotation manipRotation = new MEulerRotation();

            try
            {
                getConverterManipValue(rotateManip.rotationIndex, manipRotation);
                numericData.setData(manipRotation.x, manipRotation.y, manipRotation.z);
            }
            catch (System.Exception)
            {
                MGlobal.displayError("Error retrieving manip value");
                numericData.setData(0.0, 0.0, 0.0);
            }

            return(new MManipData(obj));
        }