#include <math.h>
#include <maya/MPxNode.h>
#include <maya/MIOStream.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnLightDataAttribute.h>
#include <maya/MFloatVector.h>
#include <maya/MFnPlugin.h>
{
public:
LightNode();
virtual ~LightNode();
static void * creator();
private
:
static MObject aLightShadowFraction;
static MObject aPreShadowIntensity;
};
MObject LightNode::aInputDirection;
MObject LightNode::aLightDirection;
MObject LightNode::aLightIntensity;
MObject LightNode::aLightShadowFraction;
MObject LightNode::aPreShadowIntensity;
MObject LightNode::aLightBlindData;
void LightNode::postConstructor( )
{
setMPSafe(true);
}
LightNode::LightNode()
{
}
LightNode::~LightNode()
{
}
void * LightNode::creator()
{
return new LightNode();
}
{
aInputDirection = nAttr.
createPoint(
"inputDirection",
"id" );
aLightDirection = nAttr.
createPoint(
"lightDirection",
"ld" );
aLightIntensity = nAttr.
createColor(
"lightIntensity",
"li" );
aLightAmbient = nAttr.
create(
"lightAmbient",
"la",
aLightDiffuse = nAttr.
create(
"lightDiffuse",
"ldf",
aLightSpecular = nAttr.
create(
"lightSpecular",
"ls",
aLightShadowFraction = nAttr.
create(
"lightShadowFraction",
"lsf",
aPreShadowIntensity = nAttr.
create(
"preShadowIntensity",
"psi",
aLightBlindData = nAttr.
createAddr(
"lightBlindData",
"lbld");
aLightData = lAttr.
create(
"lightData",
"ltd",
aLightDirection, aLightIntensity,
aLightAmbient,
aLightDiffuse, aLightSpecular,
aLightShadowFraction,
aPreShadowIntensity, aLightBlindData);
lAttr.
setDefault(-1.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.2f,
true,
true,
true, 0.0f, 1.0f, NULL);
CHECK_MSTATUS ( attributeAffects (aLightIntensity, aLightData) );
CHECK_MSTATUS ( attributeAffects (aLightDirection, aLightData) );
CHECK_MSTATUS ( attributeAffects (aLightShadowFraction, aLightData) );
CHECK_MSTATUS ( attributeAffects (aPreShadowIntensity, aLightData) );
CHECK_MSTATUS ( attributeAffects (aLightBlindData, aLightData) );
CHECK_MSTATUS ( attributeAffects (aInputDirection, aLightData) );
}
{
if ((plug != aLightData) && (plug.
parent() != aLightData))
resultColor = LColor * LIntensity;
outIntensity = resultColor;
outDirection = LDirection;
bool& outAmbient = outLightDataHandle.
child(aLightAmbient).
asBool();
outAmbient = LAmbient;
bool& outDiffuse = outLightDataHandle.
child(aLightDiffuse).
asBool();
outDiffuse = LDiffuse;
bool& outSpecular = outLightDataHandle.
child(aLightSpecular).
asBool();
outSpecular = LSpecular;
float& outSFraction = outLightDataHandle.
child(aLightShadowFraction).
asFloat();
outSFraction = 1.0f;
float& outPSIntensity = outLightDataHandle.
child(aPreShadowIntensity).
asFloat();
outPSIntensity = (resultColor[0] + resultColor[1] + resultColor[2]) / 3.0f;
void*& outBlindData = outLightDataHandle.
child(aLightBlindData).
asAddr();
outBlindData = NULL;
}
{
const MString UserClassify(
"light" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
CHECK_MSTATUS ( plugin.registerNode(
"directLight", LightNode::id,
LightNode::creator, LightNode::initialize,
}
{
}