Beispiel #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);
        }
        public override void validateAndSetValue(MPlug plug, MDataHandle handle, MDGContext context)
        {
            //	Make sure that there is something interesting to process.
            //
            if (plug.isNull)
            {
                throw new ArgumentNullException("plug");
            }

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

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

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

                blockHandle.setClean();

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

                return;
            }
            base.validateAndSetValue(plug, handle, context);
        }
        public override bool compute(MPlug plug, MDataBlock dataBlock)
        {
            if (plug.equalEqual(gOutputFloat_2Float_3Float))
            {
                // attribute affecting generic attribute case.  Based on the
                // input attribute, we modify the output generic attribute
                MDataHandle inputDataInt = dataBlock.inputValue(gInputInt);
                int         inputInt     = inputDataInt.asInt;

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

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

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

            return(true);
        }