Exemplo n.º 1
0
        protected override bool connectObjectAndConstraint(MDGModifier modifier)
        {
            MObject transform = transformObject();

            if (transform.isNull)
            {
                throw new InvalidOperationException("Failed to get transformObject()");
            }

            MFnTransform transformFn   = new MFnTransform(transform);
            MVector      translate     = transformFn.getTranslation(MSpace.Space.kTransform);
            MPlug        translatePlug = transformFn.findPlug("translate");

            if (MPlug.FreeToChangeState.kFreeToChange == translatePlug.isFreeToChange())
            {
                MFnNumericData nd = new MFnNumericData();

                MObject translateData = nd.create(MFnNumericData.Type.k3Double);
                nd.setData3Double(translate.x, translate.y, translate.z);
                modifier.newPlugValue(translatePlug, translateData);
                connectObjectAttribute(MPxTransform.geometry, GeometrySurfaceConstraint.constraintGeometry, false);
            }

            connectObjectAttribute(MPxTransform.parentInverseMatrix, GeometrySurfaceConstraint.constraintParentInverseMatrix, true, true);

            return(true);
        }
Exemplo n.º 2
0
        //
        // Description
        //
        //    Returns the bounding box for this object.
        //    It is a good idea not to recompute here as this funcion is called often.
        //
        public override MBoundingBox boundingBox()
        {
            MObject thisNode = thisMObject();
            MPlug c1Plug = new MPlug( thisNode, bboxCorner1 );
            MPlug c2Plug = new MPlug( thisNode, bboxCorner2 );
            MObject corner1Object = new MObject();
            MObject corner2Object = new MObject();
            c1Plug.getValue( corner1Object );
            c2Plug.getValue( corner2Object );

            double[] corner1 = new double[3];
            double[] corner2 = new double[3];

            MFnNumericData fnData = new MFnNumericData();
            fnData.setObject( corner1Object );
            fnData.getData(out corner1[0], out corner1[1], out corner1[2]);
            fnData.setObject( corner2Object );
            fnData.getData(out corner2[0], out corner2[1], out corner2[2]);

            MPoint corner1Point = new MPoint( corner1[0], corner1[1], corner1[2] );
            MPoint corner2Point = new MPoint( corner2[0], corner2[1], corner2[2] );

            return new MBoundingBox( corner1Point, corner2Point );
        }
        protected override bool connectObjectAndConstraint(MDGModifier modifier)
        {
            MObject transform = transformObject();
            if ( transform.isNull )
            {
                throw new InvalidOperationException("Failed to get transformObject()");
            }

            MFnTransform transformFn = new MFnTransform(transform);
            MVector translate = transformFn.getTranslation(MSpace.Space.kTransform);
            MPlug translatePlug = transformFn.findPlug("translate");

            if (MPlug.FreeToChangeState.kFreeToChange == translatePlug.isFreeToChange())
            {
                MFnNumericData nd = new MFnNumericData();

                MObject translateData = nd.create(MFnNumericData.Type.k3Double);
                nd.setData3Double(translate.x, translate.y, translate.z);
                modifier.newPlugValue(translatePlug, translateData);
                connectObjectAttribute(MPxTransform.geometry, GeometrySurfaceConstraint.constraintGeometry, false);
            }

            connectObjectAttribute(MPxTransform.parentInverseMatrix, GeometrySurfaceConstraint.constraintParentInverseMatrix, true, true);

            return true;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(gOutputFloat_2Float_3Float))
            {
                // attribute affecting generic attribute case.  Based on the
                // input attribute, we modify the output generic attribute
                MDataHandle inputDataInt = dataBlock.inputValue(gInputInt);
                int         inputInt     = inputDataInt.asInt;

                // Get the output handle
                MDataHandle outputData       = dataBlock.outputValue(plug);
                bool        isGenericNumeric = false;
                bool        isGenericNull    = false;

                // Is the output handle generic data
                if (outputData.isGeneric(ref isGenericNumeric, ref isGenericNull))
                {
                    // Based on the inputHandle, update the generic
                    // output handle
                    if (inputInt == 1)
                    {
                        outputData.setGenericBool(false, true);
                    }
                    else if (inputInt == 2)
                    {
                        outputData.setGenericBool(true, true);
                    }
                    else if (inputInt == 3)
                    {
                        outputData.setGenericChar(127, true);
                    }
                    else if (inputInt == 4)
                    {
                        outputData.setGenericDouble(3.145, true);
                    }
                    else if (inputInt == 5)
                    {
                        outputData.setGenericFloat((float)9.98, true);
                    }
                    else if (inputInt == 6)
                    {
                        outputData.setGenericShort(3245, true);
                    }
                    else if (inputInt == 7)
                    {
                        outputData.setGenericInt(32768, true);
                    }
                    else if (inputInt == 8)
                    {
                        MFnNumericData numericData = new MFnNumericData();
                        MObject        obj         = numericData.create(MFnNumericData.Type.k2Float);
                        numericData.setData((float)1.5, (float)6.7);
                        outputData.set(obj);
                    }
                    else if (inputInt == 9)
                    {
                        MFnNumericData numericData = new MFnNumericData();
                        MObject        obj         = numericData.create(MFnNumericData.Type.k3Float);
                        numericData.setData((float)2.5, (float)8.7, (float)2.3345);
                        outputData.set(obj);
                    }
                    else if (inputInt == 10)
                    {
                        outputData.setGenericInt(909, true);
                    }

                    // Mark the data clean
                    outputData.setClean();
                    dataBlock.setClean(gOutputFloat_2Float_3Float);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
		public override bool compute(MPlug plug, MDataBlock dataBlock)
		{
			if ( plug.equalEqual(gOutputFloat_2Float_3Float) )
			{
				// attribute affecting generic attribute case.  Based on the
				// input attribute, we modify the output generic attribute
				MDataHandle inputDataInt = dataBlock.inputValue( gInputInt );
				int inputInt = inputDataInt.asInt;
		
				// Get the output handle
				MDataHandle outputData = dataBlock.outputValue( plug );	
				bool isGenericNumeric = false;
				bool isGenericNull = false;
		
				// Is the output handle generic data
				if ( outputData.isGeneric( ref isGenericNumeric, ref isGenericNull ) )
				{
					// Based on the inputHandle, update the generic
					// output handle
					if ( inputInt == 1 )
						outputData.setGenericBool( false, true );
					else if ( inputInt == 2 )
						outputData.setGenericBool( true, true );
					else if ( inputInt == 3 )
						outputData.setGenericChar( 127, true );
					else if ( inputInt == 4 )
						outputData.setGenericDouble( 3.145, true );
					else if ( inputInt == 5 )
						outputData.setGenericFloat( (float)9.98, true );	
					else if ( inputInt == 6 )
						outputData.setGenericShort( 3245, true );
					else if ( inputInt == 7 )
						outputData.setGenericInt( 32768, true );
					else if ( inputInt == 8 )
					{
						MFnNumericData numericData = new MFnNumericData();
						MObject obj = numericData.create( MFnNumericData.Type.k2Float);
						numericData.setData( (float)1.5, (float)6.7 );
						outputData.set( obj );
					}
					else if ( inputInt == 9 )
					{
						MFnNumericData numericData = new MFnNumericData();
						MObject obj = numericData.create( MFnNumericData.Type.k3Float);
						numericData.setData( (float)2.5, (float)8.7, (float)2.3345 );
						outputData.set( obj );
					}
					else if ( inputInt == 10 )
					{
						outputData.setGenericInt( 909, true );
					}							

					// Mark the data clean
					outputData.setClean();
					dataBlock.setClean( gOutputFloat_2Float_3Float );
				}
			} 
			else 
			{
				return false;
			}

			return true;
		}
Exemplo n.º 7
0
		public override MBoundingBox boundingBox()
		//
		// Description
		//
		//    Returns the bounding box for this object.
		//    It is a good idea not to recompute here as this funcion is called often.
		//
		{
			MObject thisNode = thisMObject();
			MPlug c1Plug = new MPlug( thisNode, bboxCorner1 );
			MPlug c2Plug = new MPlug( thisNode, bboxCorner2 );
			MObject corner1Object = new MObject();
			MObject corner2Object = new MObject();
			c1Plug.getValue( corner1Object );
			c2Plug.getValue( corner2Object );

			double[] corner1 = new double[3];
			double[] corner2 = new double[3];

			MFnNumericData fnData = new MFnNumericData();
			fnData.setObject( corner1Object );
			fnData.getData(out corner1[0], out corner1[1], out corner1[2]);
			fnData.setObject( corner2Object );
			fnData.getData(out corner2[0], out corner2[1], out corner2[2]);

			MPoint corner1Point = new MPoint( corner1[0], corner1[1], corner1[2] );
			MPoint corner2Point = new MPoint( corner2[0], corner2[1], corner2[2] );

			return new MBoundingBox( corner1Point, corner2Point );
		}
Exemplo n.º 8
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));
        }