//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ #include #include #include #include #include #include #include #include #include #define AWdegreesToRadians 0.0174532925199432957692369076848f MTypeId slopeShaderNode::id( 0x81005 ); //Input values // MObject slopeShaderNode::aAngle; MObject slopeShaderNode::aColor1; MObject slopeShaderNode::aColor2; //Rendering attributes // MObject slopeShaderNode::aTriangleNormalCamera; MObject slopeShaderNode::aMatrixEyeToWorld; //Output color // MObject slopeShaderNode::aOutColor; //Dummy plug for forcing //an evaluation of this node // MObject slopeShaderNode::aDirtyShaderAttr; slopeShaderNode::slopeShaderNode() // // Description: // Constructor // { } void slopeShaderNode::postConstructor( ) // // Description: // postConstructor // { setMPSafe(true); } slopeShaderNode::~slopeShaderNode() // // Description: // Descructor // { } void* slopeShaderNode::creator() // // Description: // Returns a new instance of this class // { return new slopeShaderNode(); } MStatus slopeShaderNode::initialize() // // Description: // Initializes the attributes for this node. // { MFnNumericAttribute nAttr; MFnMatrixAttribute nMAttr; MFnTypedAttribute nTAttr; MFnGenericAttribute nGAttr; // Input Attributes // aAngle = nAttr.create( "angle", "ang", MFnNumericData::kFloat); nAttr.setDefault(30.0f); nAttr.setMin(0.0f); nAttr.setMax(100.0f); nAttr.setKeyable(true); nAttr.setStorable(true); nAttr.setReadable(true); nAttr.setWritable(true); aColor1 = nAttr.createColor( "walkableColor", "w" ); nAttr.setDefault(0.0f, 1.0f, 0.0f); nAttr.setKeyable(true); nAttr.setStorable(true); nAttr.setUsedAsColor(true); nAttr.setReadable(true); nAttr.setWritable(true); aColor2 = nAttr.createColor( "nonWalkableColor", "nw" ); nAttr.setDefault(1.0f, 0.0f, 0.0f); nAttr.setKeyable(true); nAttr.setStorable(true); nAttr.setUsedAsColor(true); nAttr.setReadable(true); nAttr.setWritable(true); // Surface Normal supplied by the render sampler // aTriangleNormalCamera = nAttr.createPoint( "triangleNormalCamera", "n" ); nAttr.setStorable(false); nAttr.setHidden(true); nAttr.setReadable(true); nAttr.setWritable(true); //View matrix from the camera into world space // aMatrixEyeToWorld = nMAttr.create( "matrixEyeToWorld", "mew", MFnMatrixAttribute::kFloat ); nAttr.setHidden(true); nMAttr.setWritable(true); // Output Attributes // aOutColor = nAttr.createColor( "outColor", "oc" ); nAttr.setStorable(false); nAttr.setHidden(false); nAttr.setReadable(true); nAttr.setWritable(false); //dummy plug for forcing evaluation // aDirtyShaderAttr = nGAttr.create( "dirtyShaderPlug", "dsp"); nGAttr.setArray(true); nGAttr.setHidden(false); nGAttr.setUsesArrayDataBuilder(true); nGAttr.setReadable(false); nGAttr.setStorable(true); nGAttr.setIndexMatters(false); nGAttr.addAccept(MFnData::kMesh); //Add attribues addAttribute(aAngle); addAttribute(aColor1); addAttribute(aColor2); addAttribute(aTriangleNormalCamera); addAttribute(aOutColor); addAttribute(aMatrixEyeToWorld); addAttribute(aDirtyShaderAttr); attributeAffects (aAngle, aOutColor); attributeAffects (aColor1, aOutColor); attributeAffects (aColor2, aOutColor); attributeAffects (aTriangleNormalCamera, aOutColor); attributeAffects (aDirtyShaderAttr, aOutColor); return MS::kSuccess; } MStatus slopeShaderNode::compute(const MPlug & plug, MDataBlock & block ) // // Description: // Computes a color value // from a surface noraml angle. // { if ((plug != aOutColor) && (plug.parent() != aOutColor)) return MS::kUnknownParameter; MFloatVector resultColor; MFloatVector& walkable = block.inputValue( aColor1 ).asFloatVector(); MFloatVector& nonWalkable = block.inputValue( aColor2 ).asFloatVector(); MFloatVector& surfaceNormal = block.inputValue( aTriangleNormalCamera ).asFloatVector(); MFloatMatrix& viewMatrix = block.inputValue( aMatrixEyeToWorld ).asFloatMatrix(); float angle = block.inputValue( aAngle ).asFloat(); // Normalize the view vector // surfaceNormal.normalize(); MFloatVector WSVector = surfaceNormal * viewMatrix; // find dot product // float scalarNormal = WSVector * MFloatVector(0, 1, 0); // take the absolute value // if (scalarNormal < 0.0) scalarNormal *= -1.0; if(cos(angle*AWdegreesToRadians) < scalarNormal) resultColor = walkable; else resultColor = nonWalkable; // set ouput color attribute // MDataHandle outColorHandle = block.outputValue( aOutColor ); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; outColorHandle.setClean(); return MS::kSuccess; }