Ejemplo n.º 1
0
        // The compute() method does the actual work of the node using the inputs
        // of the node to generate its output.
        //
        // Compute takes two parameters: plug and data.
        // - Plug is the the data value that needs to be recomputed
        // - Data provides handles to all of the nodes attributes, only these
        //   handles should be used when performing computations.
        //
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            MObject           thisNode   = thisMObject();
            MFnDependencyNode fnThisNode = new MFnDependencyNode(thisNode);

            MGlobal.displayInfo("affects::compute(), plug being computed is \"" + plug.name + "\"");

            if (plug.partialName() == "B")
            {
                // Plug "B" is being computed. Assign it the value on plug "A"
                // if "A" exists.
                //
                MPlug pA = fnThisNode.findPlug("A");

                MGlobal.displayInfo("\t\t... found dynamic attribute \"A\", copying its value to \"B\"");
                MDataHandle inputData = dataBlock.inputValue(pA);

                int value = inputData.asInt;

                MDataHandle outputHandle = dataBlock.outputValue(plug);

                outputHandle.set(value);
                dataBlock.setClean(plug);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 public override bool compute(MPlug plug, MDataBlock dataBlock)
 {
     factor = springFactor(dataBlock);
     // Note: return "kUnknownParameter" so that Maya spring node can
     // compute spring force for this plug-in simple spring node.
     return(false);
 }
Ejemplo n.º 4
0
 public override bool compute(MPlug plug, MDataBlock dataBlock)
 {
     factor = springFactor(dataBlock);
     // Note: return "kUnknownParameter" so that Maya spring node can
     // compute spring force for this plug-in simple spring node.
     return false;
 }
Ejemplo n.º 5
0
        override public void deform(MDataBlock block, MItGeometry iter, MMatrix m, uint multiIndex)
        {
            MDataHandle angleData = block.inputValue(angle);
            MDataHandle envData   = block.inputValue(envelope);
            double      magnitude = angleData.asDouble;

            float env = envData.asFloat;

            for (; !iter.isDone; iter.next())
            {
                MPoint pt = iter.position();

                // do the twist
                //

                double ff = magnitude * pt.y * env;
                if (ff != 0.0)
                {
                    double cct = Math.Cos(ff);
                    double cst = Math.Sin(ff);
                    double tt  = pt.x * cct - pt.z * cst;
                    pt.z = pt.x * cst + pt.z * cct;
                    pt.x = tt;;
                }

                iter.setPosition(pt);
            }
        }
Ejemplo n.º 6
0
 double springFactor( MDataBlock block )
 {
     MDataHandle handle = block.inputValue(aSpringFactor);
     double value = 0.0;
     value = handle.asDouble;
     return value;
 }
Ejemplo n.º 7
0
        public override void deform(MDataBlock block, MItGeometry iter, MMatrix m, uint multiIndex)
        {
            MDataHandle angleData = block.inputValue(angle);
            MDataHandle envData = block.inputValue(envelope);
            double magnitude = angleData.asDouble;

            float env = envData.asFloat;

            for (; !iter.isDone; iter.next())
            {
                MPoint pt = iter.position();

                // do the twist
                //

                double ff = magnitude * pt.y * env;
                if (ff != 0.0)
                {
                    double cct = Math.Cos(ff);
                    double cst = Math.Sin(ff);
                    double tt = pt.x * cct - pt.z * cst;
                    pt.z = pt.x * cst + pt.z * cct;
                    pt.x = tt; ;
                }

                iter.setPosition(pt);
            }
        }
Ejemplo n.º 8
0
 public override bool compute(MPlug plug, MDataBlock datablock)
 // Since there are no output attributes this is not necessary but
 // if we wanted to compute an output mesh for rendering it would
 // be done here base on the inputs.
 {
     return(false);
 }
Ejemplo n.º 9
0
		// The compute() method does the actual work of the node using the inputs
		// of the node to generate its output.
		//
		// Compute takes two parameters: plug and data.
		// - Plug is the the data value that needs to be recomputed
		// - Data provides handles to all of the nodes attributes, only these
		//   handles should be used when performing computations.
		//
		public override bool compute(MPlug plug, MDataBlock dataBlock)
		{
			MObject thisNode = thisMObject();
			MFnDependencyNode fnThisNode = new MFnDependencyNode(thisNode);
			MGlobal.displayInfo("affects::compute(), plug being computed is \"" + plug.name + "\"");
 
			if (plug.partialName() == "B") {
				// Plug "B" is being computed. Assign it the value on plug "A"
				// if "A" exists.
				//
				MPlug pA  = fnThisNode.findPlug("A");
			  
				MGlobal.displayInfo("\t\t... found dynamic attribute \"A\", copying its value to \"B\"");
				MDataHandle inputData = dataBlock.inputValue(pA);
				
				int value = inputData.asInt;

				MDataHandle outputHandle = dataBlock.outputValue( plug );

				outputHandle.set(value);
				dataBlock.setClean(plug);

			} else {
				return false;
			}
			return true;
		}
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        double end2WeightValue( MDataBlock block )
        {
            MDataHandle hValue = block.inputValue( mEnd2Weight );

            double value = 0.0;
            value = hValue.asDouble;
            return value;
        }
Ejemplo n.º 12
0
        double springFactor(MDataBlock block)
        {
            MDataHandle handle = block.inputValue(aSpringFactor);
            double      value  = 0.0;

            value = handle.asDouble;
            return(value);
        }
Ejemplo n.º 13
0
        double end2WeightValue(MDataBlock block)
        {
            MDataHandle hValue = block.inputValue(mEnd2Weight);

            double value = 0.0;

            value = hValue.asDouble;
            return(value);
        }
Ejemplo n.º 14
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        //
        //	Description:
        //		Computes a color value
        //	from a surface noraml angle.
        //
        {
            if ((plug.notEqual(aOutColor)) && (plug.parent.notEqual(aOutColor)))
            {
                return(false);
            }

            MFloatVector resultColor;

            MFloatVector walkable      = dataBlock.inputValue(aColor1).asFloatVector;
            MFloatVector nonWalkable   = dataBlock.inputValue(aColor2).asFloatVector;
            MFloatVector surfaceNormal = dataBlock.inputValue(aTriangleNormalCamera).asFloatVector;
            MFloatMatrix viewMatrix    = dataBlock.inputValue(aMatrixEyeToWorld).asFloatMatrix;
            float        angle         = dataBlock.inputValue(aAngle).asFloat;

            // Normalize the view vector
            //
            surfaceNormal.normalize();
            MFloatVector WSVector = surfaceNormal.multiply(viewMatrix);

            // find dot product
            //
            float scalarNormal = WSVector.multiply(new MFloatVector(0, 1, 0));

            // take the absolute value
            //
            if (scalarNormal < 0.0)
            {
                scalarNormal *= -1.0f;
            }

            if (Math.Cos(angle * AWdegreesToRadians) < scalarNormal)
            {
                resultColor = walkable;
            }
            else
            {
                resultColor = nonWalkable;
            }

            // set ouput color attribute
            //
            MDataHandle  outColorHandle = dataBlock.outputValue(aOutColor);
            MFloatVector outColor       = outColorHandle.asFloatVector;

            outColor = resultColor;
            outColorHandle.setClean();

            return(true);
        }
Ejemplo n.º 15
0
        private double magnitude(MDataBlock block)
        {
            MDataHandle hValue;
            double      value = 0.0;

            try
            {
                hValue = block.inputValue(mMagnitude);
                value  = hValue.asDouble;
            }
            catch
            {
            }

            return(value);
        }
Ejemplo n.º 16
0
        override public bool compute(MPlug plug, MDataBlock dataBlock)
        {
            bool res = plug.attribute.equalEqual(output);

            if (res)
            {
                MDataHandle inputData;
                inputData = dataBlock.inputValue(input);

                MDataHandle outputHandle = dataBlock.outputValue(output);
                outputHandle.asFloat = 10 * (float)Math.Sin((double)inputData.asFloat);
                dataBlock.setClean(plug);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        override public bool compute(MPlug plug, MDataBlock dataBlock)
        {
            bool res = plug.attribute.equalEqual(output);

            if (res)
            {
                MDataHandle inputData;
                inputData = dataBlock.inputValue(input);

                MDataHandle outputHandle = dataBlock.outputValue(output);
                outputHandle.asFloat = 10 * (float)Math.Sin((double)inputData.asFloat);
                dataBlock.setClean(plug);
                return true;
            }

            return false;
        }
Ejemplo n.º 18
0
        override public void deform(MDataBlock block, MItGeometry iter, MMatrix m, uint multiIndex)
        {
            MDataHandle angleData = block.inputValue(angle);
            MDataHandle envData   = block.inputValue(envelope);
            double      magnitude = angleData.asDouble;

            float env = envData.asFloat;

            var startTime = DateTime.Now;

            var poses = new MPointArray();

            iter.allPositions(poses);

            //var newPos = VulankCompute.ComputeData(poses, (float)magnitude, env);
            VulankCompute.ComputeData(poses, (float)magnitude, env);

            iter.setAllPositions(poses);

            var timeSpand = DateTime.Now - startTime;

            MGlobal.displayInfo(string.Format("---------- total time : {0}", timeSpand.TotalSeconds));
            //for (; !iter.isDone; iter.next())
            //{
            //MPoint pt = iter.position();

            //// do the twist
            ////

            //double ff = magnitude * pt.y * env;
            //if (ff != 0.0)
            //{
            //    double cct = Math.Cos(ff);
            //    double cst = Math.Sin(ff);
            //    double tt = pt.x * cct - pt.z * cst;
            //    pt.z = pt.x * cst + pt.z * cct;
            //    pt.x = tt; ;
            //}

            //iter.setPosition(pt);
            //}
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
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;
		}
Ejemplo n.º 21
0
 public override bool compute(MPlug plug, MDataBlock dataBlock)
 {
     return(true);
 }
        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;
        }
Ejemplo n.º 23
0
 protected override MEulerRotation applyRotationLimits(MEulerRotation unlimitedRotation, MDataBlock block)
 {
     //
     // For demonstration purposes we limit the rotation to 60
     // degrees and bypass the rotation limit attributes
     //
     DegreeRadianConverter conv = new DegreeRadianConverter();
     double degrees = conv.radiansToDegrees( unlimitedRotation.x );
     if ( degrees < 60 )
         return unlimitedRotation;
     MEulerRotation euler = new MEulerRotation();
     euler.x = conv.degreesToRadians( 60.0 );
     return euler;
 }
Ejemplo n.º 24
0
		private unsafe void apply(
		MDataBlock block,
		uint receptorSize,
		MDoubleArray magnitudeArray,
		MDoubleArray magnitudeOwnerArray,
		MVectorArray directionArray,
		MVectorArray directionOwnerArray,
		MVectorArray outputForce
		)
		//
		//      Compute output force for each particle.  If there exists the 
		//      corresponding per particle attribute, use the data passed from
		//      particle shape (stored in magnitudeArray and directionArray).  
		//      Otherwise, use the attribute value from the field.
		//
		{
			// get the default values
			MVector defaultDir = direction(block);
			double defaultMag = magnitude(block);
			uint magArraySize = magnitudeArray.length;
			uint dirArraySize = directionArray.length;
			uint magOwnerArraySize = magnitudeOwnerArray.length;
			uint dirOwnerArraySize = directionOwnerArray.length;
			uint numOfOwner = magOwnerArraySize;
			if (dirOwnerArraySize > numOfOwner)
				numOfOwner = dirOwnerArraySize;

			double m_magnitude = defaultMag;
			MVector m_direction = defaultDir;

			for (int ptIndex = 0; ptIndex < receptorSize; ptIndex++)
			{
				if (receptorSize == magArraySize)
					m_magnitude = magnitudeArray[ptIndex];
				if (receptorSize == dirArraySize)
					m_direction = directionArray[ptIndex];
				if (numOfOwner > 0)
				{
					for (int nthOwner = 0; nthOwner < numOfOwner; nthOwner++)
					{
						if (magOwnerArraySize == numOfOwner)
							m_magnitude = magnitudeOwnerArray[nthOwner];
						if (dirOwnerArraySize == numOfOwner)
							m_direction = directionOwnerArray[nthOwner];
						outputForce.append(m_direction * m_magnitude);
					}
				}
				else
				{
					outputForce.append(m_direction * m_magnitude);
				}
			}
		}
Ejemplo n.º 25
0
		private double magnitude(MDataBlock block)
		{
			MDataHandle hValue;
			double value = 0.0;
			try
			{
				hValue = block.inputValue(mMagnitude);
				value = hValue.asDouble;
			}
			catch
			{

			}

			return (value);
		}
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        //
        // Description
        //
        //    Compute the outputSurface attribute.
        //
        //    If there is no history, use cachedSurface as the
        //    input surface. All tweaks will get written directly
        //    to it. Output is just a copy of the cached surface
        //    that can be connected etc.
        //
        public void computeOutputSurface( MPlug plug, MDataBlock datablock )
        {
            // Check for an input surface. The input surface, if it
            // exists, is copied to the cached surface.
            //
            computeInputSurface( plug, datablock );

            // Get a handle to the cached data
            //
            MDataHandle cachedHandle = datablock.outputValue( cachedSurface );
            apiMeshData cached = cachedHandle.asPluginData as apiMeshData;
            if ( null == cached ) {
                MGlobal.displayInfo( "NULL cachedSurface data found" );
            }

            datablock.setClean( plug );

            // Apply any vertex offsets.
            //
            if ( hasHistory() ) {
                applyTweaks( datablock, cached.fGeometry );
            }
            else {
                MArrayDataHandle cpHandle = datablock.inputArrayValue( mControlPoints );
                cpHandle.setAllClean();
            }

            // Create some output data
            //
            MFnPluginData fnDataCreator = new MFnPluginData();
            fnDataCreator.create(new MTypeId(apiMeshData.id));
            apiMeshData newData = (apiMeshData)fnDataCreator.data();

            // Copy the data
            //
            if ( null != cached ) {
                newData.fGeometry = cached.fGeometry;
            }
            else {
                MGlobal.displayInfo( "computeOutputSurface: NULL cachedSurface data" );
            }

            // Assign the new data to the outputSurface handle
            //
            MDataHandle outHandle = datablock.outputValue( outputSurface );
            outHandle.set( newData );

            // Update the bounding box attributes
            //
            computeBoundingBox( datablock );
        }
Ejemplo n.º 28
0
        private unsafe void apply(
            MDataBlock block,
            uint receptorSize,
            MDoubleArray magnitudeArray,
            MDoubleArray magnitudeOwnerArray,
            MVectorArray directionArray,
            MVectorArray directionOwnerArray,
            MVectorArray outputForce
            )
        //
        //      Compute output force for each particle.  If there exists the
        //      corresponding per particle attribute, use the data passed from
        //      particle shape (stored in magnitudeArray and directionArray).
        //      Otherwise, use the attribute value from the field.
        //
        {
            // get the default values
            MVector defaultDir        = direction(block);
            double  defaultMag        = magnitude(block);
            uint    magArraySize      = magnitudeArray.length;
            uint    dirArraySize      = directionArray.length;
            uint    magOwnerArraySize = magnitudeOwnerArray.length;
            uint    dirOwnerArraySize = directionOwnerArray.length;
            uint    numOfOwner        = magOwnerArraySize;

            if (dirOwnerArraySize > numOfOwner)
            {
                numOfOwner = dirOwnerArraySize;
            }

            double  m_magnitude = defaultMag;
            MVector m_direction = defaultDir;

            for (int ptIndex = 0; ptIndex < receptorSize; ptIndex++)
            {
                if (receptorSize == magArraySize)
                {
                    m_magnitude = magnitudeArray[ptIndex];
                }
                if (receptorSize == dirArraySize)
                {
                    m_direction = directionArray[ptIndex];
                }
                if (numOfOwner > 0)
                {
                    for (int nthOwner = 0; nthOwner < numOfOwner; nthOwner++)
                    {
                        if (magOwnerArraySize == numOfOwner)
                        {
                            m_magnitude = magnitudeOwnerArray[nthOwner];
                        }
                        if (dirOwnerArraySize == numOfOwner)
                        {
                            m_direction = directionOwnerArray[nthOwner];
                        }
                        outputForce.append(m_direction * m_magnitude);
                    }
                }
                else
                {
                    outputForce.append(m_direction * m_magnitude);
                }
            }
        }
Ejemplo n.º 29
0
        //
        //	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;
        }
Ejemplo n.º 30
0
        protected override MEulerRotation applyRotationLimits(MEulerRotation unlimitedRotation, MDataBlock block)
        {
            //
            // For demonstration purposes we limit the rotation to 60
            // degrees and bypass the rotation limit attributes
            //
            DegreeRadianConverter conv = new DegreeRadianConverter();
            double degrees             = conv.radiansToDegrees(unlimitedRotation.x);

            if (degrees < 60)
            {
                return(unlimitedRotation);
            }
            MEulerRotation euler = new MEulerRotation();

            euler.x = conv.degreesToRadians(60.0);
            return(euler);
        }
Ejemplo n.º 31
0
        private MVector direction(MDataBlock block)
        {
            MFloatVector fV = block.inputValue(mDirection).asFloatVector;

            return(new MVector(fV.x, fV.y, fV.z));
        }
Ejemplo n.º 32
0
 public override bool compute(MPlug plug, MDataBlock datablock)
 // Since there are no output attributes this is not necessary but
 // if we wanted to compute an output mesh for rendering it would
 // be done here base on the inputs.
 {
     return false;
 }
Ejemplo n.º 33
0
        //
        // Description
        //
        //     This function takes an input surface of type kMeshData and converts
        //     the geometry into this nodes attributes.
        //     Returns false if nothing is connected.
        //
        public bool computeInputMesh(MPlug plug,
                                     MDataBlock datablock,
                                     MPointArray vertices,
                                     MIntArray counts,
                                     MIntArray connects,
                                     MVectorArray normals,
                                     apiMeshGeomUV uvs)
        {
            // Get the input subdiv
            //
            MDataHandle inputData = datablock.inputValue(inputMesh);
            MObject     surf      = inputData.asMesh;

            // Check if anything is connected
            //
            MObject thisObj  = thisMObject();
            MPlug   surfPlug = new MPlug(thisObj, inputMesh);

            if (!surfPlug.isConnected)
            {
                datablock.setClean(plug);
                return(false);
            }

            // Extract the mesh data
            //
            MFnMesh surfFn = new MFnMesh(surf);

            surfFn.getPoints(vertices, MSpace.Space.kObject);

            // Check to see if we have UVs to copy.
            //
            bool hasUVs = surfFn.numUVsProperty > 0;

            surfFn.getUVs(uvs.ucoord, uvs.vcoord);

            for (int i = 0; i < surfFn.numPolygons; i++)
            {
                MIntArray polyVerts = new MIntArray();
                surfFn.getPolygonVertices(i, polyVerts);
                int pvc = (int)polyVerts.length;
                counts.append(pvc);
                int uvId;
                for (int v = 0; v < pvc; v++)
                {
                    if (hasUVs)
                    {
                        surfFn.getPolygonUVid(i, v, out uvId);
                        uvs.faceVertexIndex.append(uvId);
                    }
                    connects.append(polyVerts[v]);
                }
            }

            for (int n = 0; n < (int)vertices.length; n++)
            {
                MVector normal = new MVector();
                surfFn.getVertexNormal(n, normal);
                normals.append(normal);
            }

            return(true);
        }
Ejemplo n.º 34
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);
        }
Ejemplo n.º 35
0
        //
        //    Description:
        //        Computes a color value
        //    from a surface noraml angle.
        //
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if ((plug.notEqual(aOutColor)) && (plug.parent.notEqual(aOutColor)))
                return false;

            MFloatVector resultColor;

            MFloatVector  walkable = dataBlock.inputValue( aColor1 ).asFloatVector;
            MFloatVector  nonWalkable = dataBlock.inputValue( aColor2 ).asFloatVector;
            MFloatVector  surfaceNormal = dataBlock.inputValue( aTriangleNormalCamera ).asFloatVector;
            MFloatMatrix  viewMatrix = dataBlock.inputValue( aMatrixEyeToWorld ).asFloatMatrix;
            float angle = dataBlock.inputValue( aAngle ).asFloat;

            // Normalize the view vector
            //
            surfaceNormal.normalize();
            MFloatVector WSVector = surfaceNormal.multiply(viewMatrix);

            // find dot product
            //
            float scalarNormal = WSVector.multiply(new MFloatVector(0, 1, 0));

            // take the absolute value
            //
            if (scalarNormal < 0.0)
                scalarNormal *= -1.0f;

            if(Math.Cos(angle*AWdegreesToRadians) < scalarNormal)
                resultColor = walkable;
            else
                resultColor = nonWalkable;

            // set ouput color attribute
            //
            MDataHandle outColorHandle = dataBlock.outputValue( aOutColor );
            MFloatVector outColor = outColorHandle.asFloatVector;
            outColor = resultColor;
            outColorHandle.setClean();

            return true;
        }
Ejemplo n.º 36
0
 // Since there are no output attributes this is not necessary but
 // if we wanted to compute an output mesh for rendering it would
 // be done here base on the inputs.
 public override bool compute(MPlug plug, MDataBlock datablock)
 {
     return false;
 }
Ejemplo n.º 37
0
        public override bool compute(MPlug plug, MDataBlock datablock)
        //
        // Description
        //
        //    When input attributes are dirty this method will be called to
        //    recompute the output attributes.
        //
        {
            if (plug.attribute.equalEqual(outputSurface))
            {
                // Create some user-defined geometry data and access the
                // geometry so that we can set it
                //
                MFnPluginData fnDataCreator = new MFnPluginData();
                fnDataCreator.create(new MTypeId(apiMeshData.id));
                apiMeshData meshData = (apiMeshData)fnDataCreator.data();
                apiMeshGeom meshGeom = meshData.fGeometry;

                // If there is an input mesh then copy it's values
                // and construct some apiMeshGeom for it.
                //
                bool hasHistory = computeInputMesh(plug,
                                                   datablock,
                                                   meshGeom.vertices,
                                                   meshGeom.face_counts,
                                                   meshGeom.face_connects,
                                                   meshGeom.normals,
                                                   meshGeom.uvcoords);

                // There is no input mesh so check the shapeType attribute
                // and create either a cube or a sphere.
                //
                if (!hasHistory)
                {
                    MDataHandle sizeHandle = datablock.inputValue(size);
                    double      shape_size = sizeHandle.asDouble;
                    MDataHandle typeHandle = datablock.inputValue(shapeType);
                    short       shape_type = typeHandle.asShort;

                    switch (shape_type)
                    {
                    case 0:                              // build a cube
                        buildCube(shape_size,
                                  meshGeom.vertices,
                                  meshGeom.face_counts,
                                  meshGeom.face_connects,
                                  meshGeom.normals,
                                  meshGeom.uvcoords
                                  );
                        break;

                    case 1:                              // build a sphere
                        buildSphere(shape_size,
                                    32,
                                    meshGeom.vertices,
                                    meshGeom.face_counts,
                                    meshGeom.face_connects,
                                    meshGeom.normals,
                                    meshGeom.uvcoords
                                    );
                        break;
                    }                     // end switch
                }

                meshGeom.faceCount = meshGeom.face_counts.length;

                // Assign the new data to the outputSurface handle
                //
                MDataHandle outHandle = datablock.outputValue(outputSurface);
                outHandle.set(meshData);

                datablock.setClean(plug);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 38
0
		private MVector direction(MDataBlock block)
		{
			MFloatVector fV = block.inputValue(mDirection).asFloatVector;
			return new MVector(fV.x, fV.y, fV.z);
		}
Ejemplo n.º 39
0
        //
        // Description
        //
        //    Check the controlPoints array. If there is input history
        //    then we will use this array to store tweaks (vertex movements).
        //
        public void buildControlPoints(MDataBlock datablock, int count)
        {
            MArrayDataHandle cpH = datablock.outputArrayValue( mControlPoints );

            MArrayDataBuilder oldBuilder = cpH.builder();
            if ( count != (int)oldBuilder.elementCount )
            {
                // Make and set the new builder based on the
                // info from the old builder.
                MArrayDataBuilder builder = new MArrayDataBuilder( oldBuilder );
                cpH.set( builder );
            }

            cpH.setAllClean();
        }
Ejemplo n.º 40
0
		public override bool compute(MPlug plug, MDataBlock dataBlock)
		//
		//	Descriptions:
		//		compute output force.
		//
		{
			if (plug.notEqual(mOutputForce))
                return false;

			// get the logical index of the element this plug refers to.
			//
			uint multiIndex = plug.logicalIndex;

			// Get input data handle, use outputArrayValue since we do not
			// want to evaluate both inputs, only the one related to the
			// requested multiIndex. Evaluating both inputs at once would cause
			// a dependency graph loop.

			MArrayDataHandle hInputArray = dataBlock.outputArrayValue(mInputData);
			hInputArray.jumpToElement(multiIndex);

			// get children of aInputData.

			MDataHandle hCompond = hInputArray.inputValue();

			MDataHandle hPosition = hCompond.child(mInputPositions);
			MObject dPosition = hPosition.data();
			MFnVectorArrayData fnPosition = new MFnVectorArrayData(dPosition);
			MVectorArray points = fnPosition.array();

			// The attribute mInputPPData contains the attribute in an array form 
			// prepared by the particleShape if the particleShape has per particle 
			// attribute fieldName_attrName.  
			//
			// Suppose a field with the name dynExprField1 is connecting to 
			// particleShape1, and the particleShape1 has per particle float attribute
			// dynExprField1_magnitude and vector attribute dynExprField1_direction,
			// then hInputPPArray will contains a MdoubleArray with the corresponding
			// name "magnitude" and a MvectorArray with the name "direction".  This 
			// is a mechanism to allow the field attributes being driven by dynamic 
			// expression.
			MArrayDataHandle mhInputPPData = dataBlock.inputArrayValue(mInputPPData);
			mhInputPPData.jumpToElement(multiIndex);
			
			MDataHandle hInputPPData = mhInputPPData.inputValue();
			MObject dInputPPData = hInputPPData.data();
			MFnArrayAttrsData inputPPArray = new MFnArrayAttrsData(dInputPPData);

			MDataHandle hOwnerPPData = dataBlock.inputValue(mOwnerPPData);
			MObject dOwnerPPData = hOwnerPPData.data();
			MFnArrayAttrsData ownerPPArray = new MFnArrayAttrsData(dOwnerPPData);

			string magString = "magnitude";
			MFnArrayAttrsData.Type doubleType = MFnArrayAttrsData.Type.kDoubleArray;

			bool arrayExist;
			MDoubleArray magnitudeArray;
			arrayExist = inputPPArray.checkArrayExist(magString, out doubleType);
            if (arrayExist)
            {
                magnitudeArray = inputPPArray.getDoubleData(magString);
            }
            else
            {
                magnitudeArray = new MDoubleArray();
            }
		   
			MDoubleArray magnitudeOwnerArray;
			arrayExist = ownerPPArray.checkArrayExist(magString, out doubleType);
			if (arrayExist)
			{
				magnitudeOwnerArray = ownerPPArray.getDoubleData(magString);
            }
            else
            {
                magnitudeOwnerArray = new MDoubleArray();
            }

			string dirString = "direction";
			MFnArrayAttrsData.Type vectorType = MFnArrayAttrsData.Type.kVectorArray;
			MVectorArray directionArray;
			arrayExist = inputPPArray.checkArrayExist(dirString, out vectorType);
            if (arrayExist)
            {
                directionArray = inputPPArray.getVectorData(dirString);
            }
            else
            {
                directionArray = new MVectorArray();
            }
		 
			MVectorArray directionOwnerArray;
			arrayExist = ownerPPArray.checkArrayExist(dirString, out vectorType);
            if (arrayExist)
            {
                directionOwnerArray = ownerPPArray.getVectorData(dirString);
            }
            else
            {
                directionOwnerArray = new MVectorArray();
            }

			// Compute the output force.
			//
			MVectorArray forceArray = new MVectorArray();

			apply(dataBlock, points.length, magnitudeArray, magnitudeOwnerArray,
				   directionArray, directionOwnerArray, forceArray);

			// get output data handle
			//
			MArrayDataHandle hOutArray = dataBlock.outputArrayValue(mOutputForce);
			MArrayDataBuilder bOutArray = hOutArray.builder();

			// get output force array from block.
			//
			MDataHandle hOut = bOutArray.addElement(multiIndex);
			MFnVectorArrayData fnOutputForce = new MFnVectorArrayData();
			MObject dOutputForce = fnOutputForce.create(forceArray);

			// update data block with new output force data.
			//
			hOut.set(dOutputForce);
			dataBlock.setClean(plug);

			return true;
		}
Ejemplo n.º 41
0
        //
        // Description
        //
        //    Use the larges/smallest vertex positions to set the corners
        //    of the bounding box.
        //
        public void computeBoundingBox( MDataBlock datablock )
        {
            // Update bounding box
            //
            MDataHandle lowerHandle = datablock.outputValue( bboxCorner1 );
            MDataHandle upperHandle = datablock.outputValue( bboxCorner2 );

            double[] lower = lowerHandle.Double3;
            double[] upper = upperHandle.Double3;

            apiMeshGeom geomPtr = meshGeom();
            uint cnt = geomPtr.vertices.length;
            if ( cnt == 0 ) return;

            // This clears any old bbox values
            //
            MPoint tmppnt = geomPtr.vertices[0];
            lower[0] = tmppnt[0]; lower[1] = tmppnt[1]; lower[2] = tmppnt[2];
            upper[0] = tmppnt[0]; upper[1] = tmppnt[1]; upper[2] = tmppnt[2];

            for ( int i=0; i<cnt; i++ )
            {
                MPoint pnt = geomPtr.vertices[i];

                if ( pnt[0] < lower[0] ) lower[0] = pnt[0];
                if ( pnt[1] < lower[1] ) lower[1] = pnt[1];
                if ( pnt[2] > lower[2] ) lower[2] = pnt[2];
                if ( pnt[0] > upper[0] ) upper[0] = pnt[0];
                if ( pnt[1] > upper[1] ) upper[1] = pnt[1];
                if ( pnt[2] < upper[2] ) upper[2] = pnt[2];
            }

            lowerHandle.Double3 = lower;
            lowerHandle.setClean();

            upperHandle.Double3 = upper;
            upperHandle.setClean();

            // Signal that the bounding box has changed.
            //
            childChanged(MPxSurfaceShape.MChildChanged.kBoundingBoxChanged);
        }
Ejemplo n.º 42
0
        //
        //    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;
        }
Ejemplo n.º 43
0
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        //
        //	Descriptions:
        //		compute output force.
        //
        {
            if (plug.notEqual(mOutputForce))
            {
                return(false);
            }

            // get the logical index of the element this plug refers to.
            //
            uint multiIndex = plug.logicalIndex;

            // Get input data handle, use outputArrayValue since we do not
            // want to evaluate both inputs, only the one related to the
            // requested multiIndex. Evaluating both inputs at once would cause
            // a dependency graph loop.

            MArrayDataHandle hInputArray = dataBlock.outputArrayValue(mInputData);

            hInputArray.jumpToElement(multiIndex);

            // get children of aInputData.

            MDataHandle hCompond = hInputArray.inputValue();

            MDataHandle        hPosition  = hCompond.child(mInputPositions);
            MObject            dPosition  = hPosition.data();
            MFnVectorArrayData fnPosition = new MFnVectorArrayData(dPosition);
            MVectorArray       points     = fnPosition.array();

            // The attribute mInputPPData contains the attribute in an array form
            // prepared by the particleShape if the particleShape has per particle
            // attribute fieldName_attrName.
            //
            // Suppose a field with the name dynExprField1 is connecting to
            // particleShape1, and the particleShape1 has per particle float attribute
            // dynExprField1_magnitude and vector attribute dynExprField1_direction,
            // then hInputPPArray will contains a MdoubleArray with the corresponding
            // name "magnitude" and a MvectorArray with the name "direction".  This
            // is a mechanism to allow the field attributes being driven by dynamic
            // expression.
            MArrayDataHandle mhInputPPData = dataBlock.inputArrayValue(mInputPPData);

            mhInputPPData.jumpToElement(multiIndex);

            MDataHandle       hInputPPData = mhInputPPData.inputValue();
            MObject           dInputPPData = hInputPPData.data();
            MFnArrayAttrsData inputPPArray = new MFnArrayAttrsData(dInputPPData);

            MDataHandle       hOwnerPPData = dataBlock.inputValue(mOwnerPPData);
            MObject           dOwnerPPData = hOwnerPPData.data();
            MFnArrayAttrsData ownerPPArray = new MFnArrayAttrsData(dOwnerPPData);

            string magString = "magnitude";

            MFnArrayAttrsData.Type doubleType = MFnArrayAttrsData.Type.kDoubleArray;

            bool         arrayExist;
            MDoubleArray magnitudeArray;

            arrayExist = inputPPArray.checkArrayExist(magString, out doubleType);
            if (arrayExist)
            {
                magnitudeArray = inputPPArray.getDoubleData(magString);
            }
            else
            {
                magnitudeArray = new MDoubleArray();
            }

            MDoubleArray magnitudeOwnerArray;

            arrayExist = ownerPPArray.checkArrayExist(magString, out doubleType);
            if (arrayExist)
            {
                magnitudeOwnerArray = ownerPPArray.getDoubleData(magString);
            }
            else
            {
                magnitudeOwnerArray = new MDoubleArray();
            }

            string dirString = "direction";

            MFnArrayAttrsData.Type vectorType = MFnArrayAttrsData.Type.kVectorArray;
            MVectorArray           directionArray;

            arrayExist = inputPPArray.checkArrayExist(dirString, out vectorType);
            if (arrayExist)
            {
                directionArray = inputPPArray.getVectorData(dirString);
            }
            else
            {
                directionArray = new MVectorArray();
            }

            MVectorArray directionOwnerArray;

            arrayExist = ownerPPArray.checkArrayExist(dirString, out vectorType);
            if (arrayExist)
            {
                directionOwnerArray = ownerPPArray.getVectorData(dirString);
            }
            else
            {
                directionOwnerArray = new MVectorArray();
            }

            // Compute the output force.
            //
            MVectorArray forceArray = new MVectorArray();

            apply(dataBlock, points.length, magnitudeArray, magnitudeOwnerArray,
                  directionArray, directionOwnerArray, forceArray);

            // get output data handle
            //
            MArrayDataHandle  hOutArray = dataBlock.outputArrayValue(mOutputForce);
            MArrayDataBuilder bOutArray = hOutArray.builder();

            // get output force array from block.
            //
            MDataHandle        hOut          = bOutArray.addElement(multiIndex);
            MFnVectorArrayData fnOutputForce = new MFnVectorArrayData();
            MObject            dOutputForce  = fnOutputForce.create(forceArray);

            // update data block with new output force data.
            //
            hOut.set(dOutputForce);
            dataBlock.setClean(plug);

            return(true);
        }
Ejemplo n.º 44
0
		public void buildControlPoints(MDataBlock datablock, int count)
		//
		// Description
		//
		//    Check the controlPoints array. If there is input history
		//    then we will use this array to store tweaks (vertex movements).
		//
		{
			MArrayDataHandle cpH = datablock.outputArrayValue( mControlPoints );

			MArrayDataBuilder oldBuilder = cpH.builder();
			if ( count != (int)oldBuilder.elementCount )
			{
				// Make and set the new builder based on the
				// info from the old builder.
				MArrayDataBuilder builder = new MArrayDataBuilder( oldBuilder );
				cpH.set( builder );
			}

			cpH.setAllClean();
		}
Ejemplo n.º 45
0
 override public bool compute(MPlug plug, MDataBlock block)
 {
     return(true);
 }
Ejemplo n.º 46
0
        //
        // Description
        //
        //    If the shape has history, apply any tweaks (offsets) made
        //    to the control points.
        //
        public void applyTweaks(MDataBlock datablock, apiMeshGeom meshGeom)
        {
            MArrayDataHandle cpHandle = datablock.inputArrayValue( mControlPoints );

            // Loop through the component list and transform each vertex.
            //
            uint elemCount = cpHandle.elementCount();
            for ( uint idx=0; idx<elemCount; idx++ )
            {
                int elemIndex = (int)cpHandle.elementIndex();
                MDataHandle pntHandle = cpHandle.outputValue();
                double[] pnt = pntHandle.Double3;
                MVector offset = new MVector(pnt[0], pnt[1], pnt[2]);

                // Apply the tweaks to the output surface
                //
                MPoint oldPnt = meshGeom.vertices[elemIndex];
                oldPnt = oldPnt.plus( offset );

                cpHandle.next();
            }

            return;
        }
Ejemplo n.º 47
0
		public override bool compute(MPlug plug, MDataBlock datablock)
		//
		// Description
		//
		//    When input attributes are dirty this method will be called to
		//    recompute the output attributes.
		//
		// Arguments
		//
		//    plug      - the attribute that triggered the compute
		//    datablock - the nodes data
		//
		// Returns
		//
		//    kSuccess          - this method could compute the dirty attribute,
		//    kUnknownParameter - the dirty attribute can not be handled at this level
		//
		{
			if ( plug.attribute.equalEqual(outputSurface) ) {
				computeOutputSurface( plug, datablock );
				return true;
			}
			else if ( plug.attribute.equalEqual(cachedSurface) ) {
				computeOutputSurface( plug, datablock );
				return true;
			}
			else if ( plug.attribute.equalEqual(worldSurface) ) {
				computeWorldSurface( plug, datablock );
				return true;
			}
			else {
				return false;
			}
		}
Ejemplo n.º 48
0
 //
 // Description
 //
 //    When input attributes are dirty this method will be called to
 //    recompute the output attributes.
 //
 // Arguments
 //
 //    plug      - the attribute that triggered the compute
 //    datablock - the nodes data
 //
 // Returns
 //
 //    kSuccess          - this method could compute the dirty attribute,
 //    kUnknownParameter - the dirty attribute can not be handled at this level
 //
 public override bool compute(MPlug plug, MDataBlock datablock)
 {
     if ( plug.attribute.equalEqual(outputSurface) ) {
         computeOutputSurface( plug, datablock );
         return true;
     }
     else if ( plug.attribute.equalEqual(cachedSurface) ) {
         computeOutputSurface( plug, datablock );
         return true;
     }
     else if ( plug.attribute.equalEqual(worldSurface) ) {
         computeWorldSurface( plug, datablock );
         return true;
     }
     else {
         return false;
     }
 }
Ejemplo n.º 49
0
        //
        //      Compute output force for each particle.  If there exists the
        //      corresponding per particle attribute, use the data passed from
        //      particle shape (stored in magnitudeArray and directionArray).
        //      Otherwise, use the attribute value from the field.
        //
        private unsafe void apply(
            MDataBlock block,
            uint receptorSize,
            MDoubleArray magnitudeArray,
            MDoubleArray magnitudeOwnerArray,
            MVectorArray directionArray,
            MVectorArray directionOwnerArray,
            MVectorArray outputForce
            )
        {
            // get the default values
            MVector defaultDir = direction(block);
            double defaultMag = magnitude(block);
            uint magArraySize = magnitudeArray.length;
            uint dirArraySize = directionArray.length;
            uint magOwnerArraySize = magnitudeOwnerArray.length;
            uint dirOwnerArraySize = directionOwnerArray.length;
            uint numOfOwner = magOwnerArraySize;
            if (dirOwnerArraySize > numOfOwner)
                numOfOwner = dirOwnerArraySize;

            double m_magnitude = defaultMag;
            MVector m_direction = defaultDir;

            for (int ptIndex = 0; ptIndex < receptorSize; ptIndex++)
            {
                if (receptorSize == magArraySize)
                    m_magnitude = magnitudeArray[ptIndex];
                if (receptorSize == dirArraySize)
                    m_direction = directionArray[ptIndex];
                if (numOfOwner > 0)
                {
                    for (int nthOwner = 0; nthOwner < numOfOwner; nthOwner++)
                    {
                        if (magOwnerArraySize == numOfOwner)
                            m_magnitude = magnitudeOwnerArray[nthOwner];
                        if (dirOwnerArraySize == numOfOwner)
                            m_direction = directionOwnerArray[nthOwner];
                        outputForce.append(m_direction * m_magnitude);
                    }
                }
                else
                {
                    outputForce.append(m_direction * m_magnitude);
                }
            }
        }
Ejemplo n.º 50
0
        //
        // Description
        //
        //    If there is input history, evaluate the input attribute
        //
        public void computeInputSurface( MPlug plug, MDataBlock datablock )
        {
            // Get the input surface if there is history
            //
            if ( hasHistory() ) {
                MDataHandle inputHandle = datablock.inputValue( inputSurface );
                apiMeshData surf = inputHandle.asPluginData as apiMeshData;
                if ( null == surf ) {
                    throw new ArgumentException("NULL inputSurface data found", "datablock");
                }

                apiMeshGeom geomPtr = surf.fGeometry;

                // Create the cachedSurface and copy the input surface into it
                //
                MFnPluginData fnDataCreator = new MFnPluginData();
                fnDataCreator.create(new MTypeId(apiMeshData.id));
                apiMeshData newCachedData = (apiMeshData)fnDataCreator.data();
                newCachedData.fGeometry = geomPtr;

                MDataHandle cachedHandle = datablock.outputValue( cachedSurface );
                cachedHandle.set( newCachedData );
            }
        }
Ejemplo n.º 51
0
		public override bool compute(MPlug plug, MDataBlock datablock)
		//
		// Description
		//
		//    When input attributes are dirty this method will be called to
		//    recompute the output attributes.
		//
		{
			if (plug.attribute.equalEqual(outputSurface))
			{
				// Create some user-defined geometry data and access the
				// geometry so that we can set it
				//
				MFnPluginData fnDataCreator = new MFnPluginData();
				fnDataCreator.create(new MTypeId(apiMeshData.id));
				apiMeshData meshData = (apiMeshData)fnDataCreator.data();
				apiMeshGeom meshGeom = meshData.fGeometry;

				// If there is an input mesh then copy it's values
				// and construct some apiMeshGeom for it.
				//
				bool hasHistory = computeInputMesh(plug,
												   datablock,
												   meshGeom.vertices,
												   meshGeom.face_counts,
												   meshGeom.face_connects,
												   meshGeom.normals,
												   meshGeom.uvcoords);

				// There is no input mesh so check the shapeType attribute
				// and create either a cube or a sphere.
				//
				if ( !hasHistory )
				{
					MDataHandle sizeHandle = datablock.inputValue(size);
					double shape_size = sizeHandle.asDouble;
					MDataHandle typeHandle = datablock.inputValue(shapeType);
					short shape_type = typeHandle.asShort;

					switch( shape_type )
					{
						case 0 : // build a cube
							buildCube(shape_size,
									  meshGeom.vertices,
									  meshGeom.face_counts,
									  meshGeom.face_connects,
									  meshGeom.normals,
									  meshGeom.uvcoords
								);
							break;
			
						case 1 : // build a sphere
							buildSphere(shape_size,
										32,
										meshGeom.vertices,
										meshGeom.face_counts,
										meshGeom.face_connects,
										meshGeom.normals,
										meshGeom.uvcoords
								);
							break;
					} // end switch
				}

				meshGeom.faceCount = meshGeom.face_counts.length;

				// Assign the new data to the outputSurface handle
				//
				MDataHandle outHandle = datablock.outputValue(outputSurface);
				outHandle.set(meshData);

				datablock.setClean(plug);
                return true;
			}

			return false;
		}
Ejemplo n.º 52
0
        //
        // Description
        //
        //    Compute the worldSurface attribute.
        //
        public void computeWorldSurface( MPlug plug, MDataBlock datablock )
        {
            computeOutputSurface( plug, datablock );
            MDataHandle inHandle = datablock.outputValue( outputSurface );
            apiMeshData outSurf = inHandle.asPluginData as apiMeshData;
            if ( null == outSurf ) {
                throw new ArgumentException("computeWorldSurface: outSurf NULL", "datablock");
            }

            // Create some output data
            //
            MFnPluginData fnDataCreator = new MFnPluginData();
            fnDataCreator.create(new MTypeId(apiMeshData.id));
            apiMeshData newData = (apiMeshData)fnDataCreator.data();

            // Get worldMatrix from MPxSurfaceShape and set it to MPxGeometryData
            MMatrix worldMat = getWorldMatrix(datablock, 0);
            newData.matrix(worldMat);

            // Copy the data
            //
            newData.fGeometry = outSurf.fGeometry;

            // Assign the new data to the outputSurface handle
            //
            uint arrayIndex = plug.logicalIndex;

            MArrayDataHandle worldHandle = datablock.outputArrayValue( worldSurface );
            MArrayDataBuilder builder = worldHandle.builder();
            MDataHandle outHandle = builder.addElement( arrayIndex );
            outHandle.set( newData );
        }
Ejemplo n.º 53
0
 public override bool compute(MPlug plug, MDataBlock dataBlock)
 {
     return true;
 }