#include <math.h>
#include "slopeShaderNode.h"
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFloatVector.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnGenericAttribute.h>
#define AWdegreesToRadians 0.0174532925199432957692369076848f
MTypeId slopeShaderNode::id( 0x81005 );
 
MObject slopeShaderNode::aTriangleNormalCamera;
 
MObject slopeShaderNode::aMatrixEyeToWorld;
 
MObject slopeShaderNode::aOutColor;
 
MObject slopeShaderNode::aDirtyShaderAttr;
 
slopeShaderNode::slopeShaderNode()
{
}
void slopeShaderNode::postConstructor( )
{
    setMPSafe(true);
}
slopeShaderNode::~slopeShaderNode()
{
}
void* slopeShaderNode::creator()
{
    return new slopeShaderNode();
}
MStatus slopeShaderNode::initialize()
 
{
    
    
    aColor2 = nAttr.
createColor( 
"nonWalkableColor", 
"nw" );
    
    
    aTriangleNormalCamera = nAttr.
createPoint( 
"triangleNormalCamera", 
"n" );
    
    
    aMatrixEyeToWorld = nMAttr.
create( 
"matrixEyeToWorld", 
"mew",
    
    
    
    
    aDirtyShaderAttr = nGAttr.
create( 
"dirtyShaderPlug", 
"dsp");
    
    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);
}
{ 
    if ((plug != aOutColor) && (plug.
parent() != aOutColor))
 
    
    
    
    
    
    
    
    if (scalarNormal < 0.0) scalarNormal *= -1.0;
    if(cos(angle*AWdegreesToRadians) < scalarNormal)
        resultColor = walkable;
    else
        resultColor = nonWalkable;
    
    
    outColor = resultColor;
}