Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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);
        }