示例#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);
        }
示例#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;
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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;
        }
示例#6
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);
        }
        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;
        }
示例#10
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);
        }
示例#11
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;
		}
示例#12
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);
        }
示例#13
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 );
        }
示例#14
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);
        }
示例#15
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);
        }
示例#16
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;
		}
示例#17
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;
		}
示例#18
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 );
            }
        }
        //
        //	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;
        }
示例#20
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 );
        }
示例#21
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;
        }