Example #1
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(animCube.outputMesh))
            {
                /* Get time */
                MDataHandle timeData = dataBlock.inputValue(animCube.time);
                MTime time = timeData.asTime;

                /* Get output object */

                MDataHandle outputHandle = dataBlock.outputValue(outputMesh);

                MFnMeshData dataCreator = new MFnMeshData();
                MObject newOutputData = dataCreator.create();

                createMesh(time, ref newOutputData);

                outputHandle.set(newOutputData);
                dataBlock.setClean(plug);
            }
            else
                return false;

            return true;
        }
Example #2
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(animCube.outputMesh))
            {
                /* Get time */
                MDataHandle timeData = dataBlock.inputValue(animCube.time);
                MTime       time     = timeData.asTime;

                /* Get output object */

                MDataHandle outputHandle = dataBlock.outputValue(outputMesh);

                MFnMeshData dataCreator   = new MFnMeshData();
                MObject     newOutputData = dataCreator.create();

                createMesh(time, ref newOutputData);

                outputHandle.set(newOutputData);
                dataBlock.setClean(plug);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #3
0
 public override bool getInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
 {
     if (plug.equalEqual(aTransparency))
     {
         dataHandle.set(fTransparency);
         return(true);
     }
     return(base.getInternalValueInContext(plug, dataHandle, ctx));
 }
 public override bool getInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
 {
     if (plug.equalEqual(aTransparency))
     {
         dataHandle.set(fTransparency);
         return true;
     }
     return base.getInternalValueInContext(plug, dataHandle, ctx);
 }
Example #5
0
		public override bool setInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
		{
			if (plug.equalEqual(aTransparency))
			{
				fTransparency = dataHandle.asDouble;
				setImageDirty();
				return true;
			}

			return base.setInternalValueInContext(plug, dataHandle, ctx);
		}
Example #6
0
        public override bool setInternalValueInContext(MPlug plug, MDataHandle dataHandle, MDGContext ctx)
        {
            if (plug.equalEqual(aTransparency))
            {
                fTransparency = dataHandle.asDouble;
                setImageDirty();
                return(true);
            }

            return(base.setInternalValueInContext(plug, dataHandle, ctx));
        }
        public override void validateAndSetValue(MPlug plug, MDataHandle handle, MDGContext context)
        {
            //	Make sure that there is something interesting to process.
            //
            if (plug.isNull)
            {
                throw new ArgumentNullException("plug");
            }

            if (plug.equalEqual(aRockInX))
            {
                MDataBlock  block       = _forceCache(context);
                MDataHandle blockHandle = block.outputValue(plug);

                // Update our new rock in x value
                double rockInX = handle.asDouble;
                blockHandle.set(rockInX);
                rockXValue = rockInX;

                // Update the custom transformation matrix to the
                // right rock value.
                rockingTransformCheckMatrix ltm = getRockingTransformMatrix();
                if (ltm != null)
                {
                    ltm.setRockInX(rockXValue);
                }
                else
                {
                    MGlobal.displayError("Failed to get rock transform matrix");
                }

                blockHandle.setClean();

                // Mark the matrix as dirty so that DG information
                // will update.
                dirtyMatrix();

                return;
            }
            base.validateAndSetValue(plug, handle, context);
        }
        public override bool compute( MPlug plug, MDataBlock block)
        {
            if ( plug.equalEqual(constraintGeometry) )
            {
                //
                block.inputValue(constraintParentInverseMatrix);
                //
                MArrayDataHandle targetArray = block.inputArrayValue( compoundTarget );
                uint targetArrayCount = targetArray.elementCount();
                double weight,selectedWeight = 0;
                if ( weightType == GeometrySurfaceConstraintCommand.ConstraintType.kSmallestWeight )
                    selectedWeight = float.MaxValue;
                MObject selectedMesh = null;
                uint i;
                for ( i = 0; i < targetArrayCount; i++ )
                {
                    MDataHandle targetElement = targetArray.inputValue();
                    weight = targetElement.child(targetWeight).asDouble;
                    if ( !equivalent(weight,0.0))
                    {
                        if ( weightType == GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight )
                        {
                            if ( weight > selectedWeight )
                            {
                                MObject mesh = targetElement.child(targetGeometry).asMesh;
                                if ( !mesh.isNull )
                                {
                                    selectedMesh = mesh;
                                    selectedWeight =  weight;
                                }
                            }
                        }
                        else
                        {
                            if  ( weight < selectedWeight )
                            {
                                MObject mesh = targetElement.child(targetGeometry).asMesh;
                                if ( !mesh.isNull )
                                {
                                    selectedMesh = mesh;
                                    selectedWeight =  weight;
                                }
                            }
                        }
                    }
                    targetArray.next();
                }
                //
                if( selectedMesh == null )
                {
                    block.setClean(plug);
                }
                else
                {
                    // The transform node via the geometry attribute will take care of
                    // updating the location of the constrained geometry.
                    MDataHandle outputConstraintGeometryHandle = block.outputValue(constraintGeometry);
                    outputConstraintGeometryHandle.setMObject(selectedMesh);
                }
            }
            else
            {
                return false;
            }

            return true;
        }
        //
        //    Calls applyRotationLocks && applyRotationLimits
        //    This method verifies that the passed value can be set on the
        //    rotate plugs. In the base class, limits as well as locking are
        //    checked by this method.
        //
        //    The compute, validateAndSetValue, and rotateTo functions
        //    all use this method.
        //
        protected override void checkAndSetRotation(MDataBlock block, MPlug plug, MEulerRotation newRotation, MSpace.Space space)
        {
            MDGContext context = block.context;
            updateMatrixAttrs(context);

            MEulerRotation outRotation = newRotation;
            if (context.isNormal) {
                //	For easy reading.
                //
                MPxTransformationMatrix xformMat = baseTransformationMatrix;

                //	Get the current translation in transform space for
                //	clamping and locking.
                //
                MEulerRotation savedRotation =
                    xformMat.eulerRotation(MSpace.Space.kTransform);

                //	Translate to transform space, since the limit test needs the
                //	values in transform space. The locking test needs the values
                //	in the same space as the savedR value - which is transform
                //	space as well.
                //
                baseTransformationMatrix.rotateTo(newRotation, space);

                outRotation = xformMat.eulerRotation(MSpace.Space.kTransform);

                //	Now that everything is in the same space, apply limits
                //	and change the value to adhere to plug locking.
                //
                outRotation = applyRotationLimits(outRotation, block);
                outRotation = applyRotationLocks(outRotation, savedRotation);

                //	The value that remain is in transform space.
                //
                xformMat.rotateTo(outRotation, MSpace.Space.kTransform);

                //	Get the value that was just set. It needs to be in transform
                //	space since it is used to set the datablock values at the
                //	end of this method. Getting the vaolue right before setting
                //	ensures that the transformation matrix and data block will
                //	be synchronized.
                //
                outRotation = xformMat.eulerRotation(MSpace.Space.kTransform);
            }
            else
            {
                //	Get the rotation for clamping and locking. This will get the
                //	rotate value in transform space.
                //
                double[] s3 = block.inputValue(rotate).Double3;
                MEulerRotation savedRotation = new MEulerRotation(s3[0], s3[1], s3[2]);

                //	Create a local transformation matrix for non-normal context
                //	calculations.
                //
                MPxTransformationMatrix local = createTransformationMatrix();
                if (null == local)
                {
                    throw new InvalidOperationException("rockingTransformCheck::checkAndSetRotation internal error");
                }

                //	Fill the newly created transformation matrix.
                //
                computeLocalTransformation(local, block);

                //	Translate the values to transform space. This will allow the
                //	limit and locking tests to work properly.
                //
                local.rotateTo(newRotation, space);

                outRotation = local.eulerRotation(MSpace.Space.kTransform);

                //	Apply limits
                //
                outRotation = applyRotationLimits(outRotation, block);

                outRotation = applyRotationLocks(outRotation, savedRotation);

                local.rotateTo(outRotation, MSpace.Space.kTransform);

                //	Get the rotate value in transform space for placement in the
                //	data block.
                //
                outRotation = local.eulerRotation(MSpace.Space.kTransform);

                local.Dispose();
            }

            MDataHandle handle = block.outputValue(plug);

            if (plug.equalEqual(rotate)) {
                handle.set(outRotation.x, outRotation.y, outRotation.z);
            } else if (plug.equalEqual(rotateX)) {
                handle.set(outRotation.x);
            } else if (plug.equalEqual(rotateY)) {
                handle.set(outRotation.y);
            } else {
                handle.set(outRotation.z);
            }

            return;
        }
        public override void validateAndSetValue(MPlug plug, MDataHandle handle, MDGContext context)
        {
            //	Make sure that there is something interesting to process.
            //
            if (plug.isNull)
                throw new ArgumentNullException("plug");

            if (plug.equalEqual(aRockInX))
            {
                MDataBlock block = _forceCache(context);
                MDataHandle blockHandle = block.outputValue(plug);

                // Update our new rock in x value
                double rockInX = handle.asDouble;
                blockHandle.set(rockInX);
                rockXValue = rockInX;

                // Update the custom transformation matrix to the
                // right rock value.
                rockingTransformCheckMatrix ltm = getRockingTransformMatrix();
                if (ltm != null)
                {
                    ltm.setRockInX(rockXValue);
                }
                else
                {
                    MGlobal.displayError("Failed to get rock transform matrix");
                }

                blockHandle.setClean();

                // Mark the matrix as dirty so that DG information
                // will update.
                dirtyMatrix();

                return;
            }
            base.validateAndSetValue(plug, handle, context);
        }
        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);
        }
Example #12
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;
		}
        //
        //	Calls applyRotationLocks && applyRotationLimits
        //	This method verifies that the passed value can be set on the
        //	rotate plugs. In the base class, limits as well as locking are
        //	checked by this method.
        //
        //	The compute, validateAndSetValue, and rotateTo functions
        //	all use this method.
        //
        protected override void checkAndSetRotation(MDataBlock block, MPlug plug, MEulerRotation newRotation, MSpace.Space space)
        {
            MDGContext context = block.context;

            updateMatrixAttrs(context);

            MEulerRotation outRotation = newRotation;

            if (context.isNormal)
            {
                //	For easy reading.
                //
                MPxTransformationMatrix xformMat = baseTransformationMatrix;

                //	Get the current translation in transform space for
                //	clamping and locking.
                //
                MEulerRotation savedRotation =
                    xformMat.eulerRotation(MSpace.Space.kTransform);

                //	Translate to transform space, since the limit test needs the
                //	values in transform space. The locking test needs the values
                //	in the same space as the savedR value - which is transform
                //	space as well.
                //
                baseTransformationMatrix.rotateTo(newRotation, space);

                outRotation = xformMat.eulerRotation(MSpace.Space.kTransform);

                //	Now that everything is in the same space, apply limits
                //	and change the value to adhere to plug locking.
                //
                outRotation = applyRotationLimits(outRotation, block);
                outRotation = applyRotationLocks(outRotation, savedRotation);

                //	The value that remain is in transform space.
                //
                xformMat.rotateTo(outRotation, MSpace.Space.kTransform);

                //	Get the value that was just set. It needs to be in transform
                //	space since it is used to set the datablock values at the
                //	end of this method. Getting the vaolue right before setting
                //	ensures that the transformation matrix and data block will
                //	be synchronized.
                //
                outRotation = xformMat.eulerRotation(MSpace.Space.kTransform);
            }
            else
            {
                //	Get the rotation for clamping and locking. This will get the
                //	rotate value in transform space.
                //
                double[]       s3            = block.inputValue(rotate).Double3;
                MEulerRotation savedRotation = new MEulerRotation(s3[0], s3[1], s3[2]);

                //	Create a local transformation matrix for non-normal context
                //	calculations.
                //
                MPxTransformationMatrix local = createTransformationMatrix();
                if (null == local)
                {
                    throw new InvalidOperationException("rockingTransformCheck::checkAndSetRotation internal error");
                }

                //	Fill the newly created transformation matrix.
                //
                computeLocalTransformation(local, block);

                //	Translate the values to transform space. This will allow the
                //	limit and locking tests to work properly.
                //
                local.rotateTo(newRotation, space);

                outRotation = local.eulerRotation(MSpace.Space.kTransform);

                //	Apply limits
                //
                outRotation = applyRotationLimits(outRotation, block);

                outRotation = applyRotationLocks(outRotation, savedRotation);

                local.rotateTo(outRotation, MSpace.Space.kTransform);

                //	Get the rotate value in transform space for placement in the
                //	data block.
                //
                outRotation = local.eulerRotation(MSpace.Space.kTransform);

                local.Dispose();
            }

            MDataHandle handle = block.outputValue(plug);

            if (plug.equalEqual(rotate))
            {
                handle.set(outRotation.x, outRotation.y, outRotation.z);
            }
            else if (plug.equalEqual(rotateX))
            {
                handle.set(outRotation.x);
            }
            else if (plug.equalEqual(rotateY))
            {
                handle.set(outRotation.y);
            }
            else
            {
                handle.set(outRotation.z);
            }

            return;
        }
Example #14
0
        public override bool compute(MPlug plug, MDataBlock block)
        {
            if (plug.equalEqual(constraintGeometry))
            {
                //
                block.inputValue(constraintParentInverseMatrix);
                //
                MArrayDataHandle targetArray = block.inputArrayValue(compoundTarget);
                uint             targetArrayCount = targetArray.elementCount();
                double           weight, selectedWeight = 0;
                if (weightType == GeometrySurfaceConstraintCommand.ConstraintType.kSmallestWeight)
                {
                    selectedWeight = float.MaxValue;
                }
                MObject selectedMesh = null;
                uint    i;
                for (i = 0; i < targetArrayCount; i++)
                {
                    MDataHandle targetElement = targetArray.inputValue();
                    weight = targetElement.child(targetWeight).asDouble;
                    if (!equivalent(weight, 0.0))
                    {
                        if (weightType == GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight)
                        {
                            if (weight > selectedWeight)
                            {
                                MObject mesh = targetElement.child(targetGeometry).asMesh;
                                if (!mesh.isNull)
                                {
                                    selectedMesh   = mesh;
                                    selectedWeight = weight;
                                }
                            }
                        }
                        else
                        {
                            if (weight < selectedWeight)
                            {
                                MObject mesh = targetElement.child(targetGeometry).asMesh;
                                if (!mesh.isNull)
                                {
                                    selectedMesh   = mesh;
                                    selectedWeight = weight;
                                }
                            }
                        }
                    }
                    targetArray.next();
                }
                //
                if (selectedMesh == null)
                {
                    block.setClean(plug);
                }
                else
                {
                    // The transform node via the geometry attribute will take care of
                    // updating the location of the constrained geometry.
                    MDataHandle outputConstraintGeometryHandle = block.outputValue(constraintGeometry);
                    outputConstraintGeometryHandle.setMObject(selectedMesh);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }