#include <maya/MIOStream.h>
#include <maya/MPxNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MArrayDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnLightDataAttribute.h>
#include <maya/MFloatVector.h>
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
class lambert : public MPxNode
{
public:
lambert();
virtual ~lambert();
static void * creator();
virtual MStatus compute( const MPlug&, MDataBlock& );
static MStatus initialize();
virtual void postConstructor();
static MTypeId id;
protected:
static MObject aTranslucenceCoeff;
static MObject aDiffuseReflectivity;
static MObject aColorR;
static MObject aColorG;
static MObject aColorB;
static MObject aColor;
static MObject aIncandescenceR;
static MObject aIncandescenceG;
static MObject aIncandescenceB;
static MObject aIncandescence;
static MObject aInTransR;
static MObject aInTransG;
static MObject aInTransB;
static MObject aInTransparency;
static MObject aOutColorR;
static MObject aOutColorG;
static MObject aOutColorB;
static MObject aOutColor;
static MObject aOutTransR;
static MObject aOutTransG;
static MObject aOutTransB;
static MObject aOutTransparency;
static MObject aNormalCameraX;
static MObject aNormalCameraY;
static MObject aNormalCameraZ;
static MObject aNormalCamera;
static MObject aLightDirectionX;
static MObject aLightDirectionY;
static MObject aLightDirectionZ;
static MObject aLightDirection;
static MObject aLightIntensityR;
static MObject aLightIntensityG;
static MObject aLightIntensityB;
static MObject aLightIntensity;
static MObject aLightAmbient;
static MObject aLightDiffuse;
static MObject aLightSpecular;
static MObject aLightShadowFraction;
static MObject aPreShadowIntensity;
static MObject aLightBlindData;
static MObject aLightData;
};
MTypeId lambert::id( 0x81000 );
void lambert::postConstructor( )
{
setMPSafe( true );
}
MObject lambert::aTranslucenceCoeff;
MObject lambert::aDiffuseReflectivity;
MObject lambert::aInTransparency;
MObject lambert::aInTransR;
MObject lambert::aInTransG;
MObject lambert::aInTransB;
MObject lambert::aColor;
MObject lambert::aColorR;
MObject lambert::aColorG;
MObject lambert::aColorB;
MObject lambert::aIncandescence;
MObject lambert::aIncandescenceR;
MObject lambert::aIncandescenceG;
MObject lambert::aIncandescenceB;
MObject lambert::aOutColor;
MObject lambert::aOutColorR;
MObject lambert::aOutColorG;
MObject lambert::aOutColorB;
MObject lambert::aOutTransparency;
MObject lambert::aOutTransR;
MObject lambert::aOutTransG;
MObject lambert::aOutTransB;
MObject lambert::aNormalCamera;
MObject lambert::aNormalCameraX;
MObject lambert::aNormalCameraY;
MObject lambert::aNormalCameraZ;
MObject lambert::aLightData;
MObject lambert::aLightDirection;
MObject lambert::aLightDirectionX;
MObject lambert::aLightDirectionY;
MObject lambert::aLightDirectionZ;
MObject lambert::aLightIntensity;
MObject lambert::aLightIntensityR;
MObject lambert::aLightIntensityG;
MObject lambert::aLightIntensityB;
MObject lambert::aLightAmbient;
MObject lambert::aLightDiffuse;
MObject lambert::aLightSpecular;
MObject lambert::aLightShadowFraction;
MObject lambert::aPreShadowIntensity;
MObject lambert::aLightBlindData;
lambert::lambert() { }
lambert::~lambert() { }
void* lambert::creator()
{
return new lambert();
}
MStatus lambert::initialize()
{
MFnNumericAttribute nAttr;
MFnLightDataAttribute lAttr;
MStatus status;
aTranslucenceCoeff = nAttr.create( "translucenceCoeff", "tc",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f ) );
aDiffuseReflectivity = nAttr.create( "diffuseReflectivity", "drfl",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.8f ) );
aColorR = nAttr.create( "colorR", "cr",MFnNumericData::kFloat, 0,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f ) );
aColorG = nAttr.create( "colorG", "cg", MFnNumericData::kFloat, 0,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.58824f ) );
aColorB = nAttr.create( "colorB", "cb",MFnNumericData::kFloat, 0,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.644f ) );
aColor = nAttr.create( "color", "c", aColorR, aColorG, aColorB,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.58824f, 0.644f ) );
CHECK_MSTATUS( nAttr.setUsedAsColor( true ) );
aIncandescenceR = nAttr.create( "incandescenceR", "ir",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f ) );
aIncandescenceG = nAttr.create( "incandescenceG", "ig",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f ) );
aIncandescenceB = nAttr.create( "incandescenceB", "ib",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status);
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f ) );
aIncandescence = nAttr.create( "incandescence", "ic", aIncandescenceR,
aIncandescenceG, aIncandescenceB, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) );
CHECK_MSTATUS( nAttr.setUsedAsColor( true ) );
aInTransR = nAttr.create( "transparencyR", "itr",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
aInTransG = nAttr.create( "transparencyG", "itg",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
aInTransB = nAttr.create( "transparencyB", "itb",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status);
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
aInTransparency = nAttr.create( "transparency", "it", aInTransR,
aInTransG, aInTransB, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setKeyable( true ) );
CHECK_MSTATUS( nAttr.setStorable( true ) );
CHECK_MSTATUS( nAttr.setDefault( 0.0f, 0.0f, 0.0f ) );
CHECK_MSTATUS( nAttr.setUsedAsColor( true ) );
aOutColorR = nAttr.create( "outColorR", "ocr", MFnNumericData::kFloat,
0, &status );
CHECK_MSTATUS( status );
aOutColorG = nAttr.create( "outColorG", "ocg", MFnNumericData::kFloat,
0, &status );
CHECK_MSTATUS( status );
aOutColorB = nAttr.create( "outColorB", "ocb", MFnNumericData::kFloat,
0, &status );
CHECK_MSTATUS( status );
aOutColor = nAttr.create( "outColor", "oc", aOutColorR, aOutColorG,
aOutColorB, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setHidden( false ) );
CHECK_MSTATUS( nAttr.setReadable( true ) );
CHECK_MSTATUS( nAttr.setWritable( false ) );
aOutTransR = nAttr.create( "outTransparencyR", "otr",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
aOutTransG = nAttr.create( "outTransparencyG", "otg",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
aOutTransB = nAttr.create( "outTransparencyB", "otb",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
aOutTransparency = nAttr.create( "outTransparency", "ot",
aOutTransR,aOutTransG,aOutTransB, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setHidden( false ) );
CHECK_MSTATUS( nAttr.setReadable( true ) );
CHECK_MSTATUS( nAttr.setWritable( false ) );
aNormalCameraX = nAttr.create( "normalCameraX", "nx",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setStorable( false ) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aNormalCameraY = nAttr.create( "normalCameraY", "ny",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setStorable( false ) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aNormalCameraZ = nAttr.create( "normalCameraZ", "nz",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setStorable( false ) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aNormalCamera = nAttr.create( "normalCamera","n", aNormalCameraX,
aNormalCameraY, aNormalCameraZ, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( nAttr.setStorable( false ) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) );
CHECK_MSTATUS( nAttr.setHidden( true ) );
aLightDirectionX = nAttr.create( "lightDirectionX", "ldx",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightDirectionY = nAttr.create( "lightDirectionY", "ldy",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightDirectionZ = nAttr.create( "lightDirectionZ", "ldz",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightDirection = nAttr.create( "lightDirection", "ld",
aLightDirectionX, aLightDirectionY, aLightDirectionZ,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) );
aLightIntensityR = nAttr.create( "lightIntensityR", "lir",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightIntensityG = nAttr.create( "lightIntensityG", "lig",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightIntensityB = nAttr.create( "lightIntensityB", "lib",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightIntensity = nAttr.create( "lightIntensity", "li",
aLightIntensityR, aLightIntensityG, aLightIntensityB,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f, 1.0f, 1.0f ) );
aLightAmbient = nAttr.create( "lightAmbient", "la",
MFnNumericData::kBoolean, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( true ) );
aLightDiffuse = nAttr.create( "lightDiffuse", "ldf",
MFnNumericData::kBoolean, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( true ) );
aLightSpecular = nAttr.create( "lightSpecular", "ls",
MFnNumericData::kBoolean, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( false ) );
aLightShadowFraction = nAttr.create( "lightShadowFraction", "lsf",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aPreShadowIntensity = nAttr.create( "preShadowIntensity", "psi",
MFnNumericData::kFloat, 0, &status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
CHECK_MSTATUS( nAttr.setDefault( 1.0f ) );
aLightBlindData = nAttr.createAddr( "lightBlindData", "lbld",
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS ( nAttr.setStorable(false) );
CHECK_MSTATUS ( nAttr.setHidden(true) );
CHECK_MSTATUS ( nAttr.setReadable(true) );
CHECK_MSTATUS ( nAttr.setWritable(false) );
aLightData = lAttr.create( "lightDataArray", "ltd", aLightDirection,
aLightIntensity, aLightAmbient, aLightDiffuse, aLightSpecular,
aLightShadowFraction, aPreShadowIntensity, aLightBlindData,
&status );
CHECK_MSTATUS( status );
CHECK_MSTATUS( lAttr.setArray( true ) );
CHECK_MSTATUS( lAttr.setStorable( false ) );
CHECK_MSTATUS( lAttr.setHidden( true ) );
CHECK_MSTATUS( lAttr.setDefault( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
true, true, false, 1.0f, 1.0f, NULL ) );
CHECK_MSTATUS( addAttribute( aTranslucenceCoeff ) );
CHECK_MSTATUS( addAttribute( aDiffuseReflectivity ) );
CHECK_MSTATUS( addAttribute( aColor ) );
CHECK_MSTATUS( addAttribute( aIncandescence ) );
CHECK_MSTATUS( addAttribute( aInTransparency ) );
CHECK_MSTATUS( addAttribute( aOutColor ) );
CHECK_MSTATUS( addAttribute( aOutTransparency ) );
CHECK_MSTATUS( addAttribute( aNormalCamera ) );
CHECK_MSTATUS( addAttribute( aLightData ) );
CHECK_MSTATUS( attributeAffects( aTranslucenceCoeff, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aDiffuseReflectivity, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aColorR, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aColorG, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aColorB, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aColor, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aInTransR, aOutTransparency ) );
CHECK_MSTATUS( attributeAffects( aInTransG, aOutTransparency ) );
CHECK_MSTATUS( attributeAffects( aInTransB, aOutTransparency ) );
CHECK_MSTATUS( attributeAffects( aInTransparency, aOutTransparency ) );
CHECK_MSTATUS( attributeAffects( aInTransparency, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aIncandescenceR, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aIncandescenceG, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aIncandescenceB, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aIncandescence, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightIntensityR, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightIntensityB, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightIntensityG, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightIntensity, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aNormalCameraX, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aNormalCameraY, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aNormalCameraZ, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aNormalCamera, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightDirectionX, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightDirectionY, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightDirectionZ, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightDirection, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightAmbient, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightSpecular, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightDiffuse, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightShadowFraction, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aPreShadowIntensity, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightBlindData, aOutColor ) );
CHECK_MSTATUS( attributeAffects( aLightData, aOutColor ) );
return( MS::kSuccess );
}
MStatus lambert::compute( const MPlug& plug, MDataBlock& block )
{
if( plug == aOutColor
|| plug == aOutColorR
|| plug == aOutColorG
|| plug == aOutColorB
|| plug == aOutTransparency
|| plug == aOutTransR
|| plug == aOutTransG
|| plug == aOutTransB )
{
MStatus status;
MFloatVector resultColor( 0.0, 0.0, 0.0 );
MFloatVector& surfaceNormal = block.inputValue( aNormalCamera,
&status ).asFloatVector();
CHECK_MSTATUS( status );
MFloatVector& surfaceColor = block.inputValue( aColor,
&status ).asFloatVector();
CHECK_MSTATUS( status );
MFloatVector& incandescence = block.inputValue( aIncandescence,
&status ).asFloatVector();
CHECK_MSTATUS( status );
float diffuseReflectivity = block.inputValue(
aDiffuseReflectivity, &status ).asFloat();
CHECK_MSTATUS( status );
MArrayDataHandle lightData = block.inputArrayValue( aLightData,
&status );
CHECK_MSTATUS( status );
int numLights = lightData.elementCount( &status );
CHECK_MSTATUS( status );
for( int count=1; count <= numLights; count++ )
{
MDataHandle currentLight = lightData.inputValue( &status );
CHECK_MSTATUS( status );
MFloatVector& lightIntensity = currentLight.child(
aLightIntensity ).asFloatVector();
if ( currentLight.child( aLightAmbient ).asBool() )
{
resultColor += lightIntensity;
}
if ( currentLight.child( aLightDiffuse ).asBool() )
{
MFloatVector& lightDirection = currentLight.child(
aLightDirection ).asFloatVector();
float cosln = lightDirection * surfaceNormal;
if ( cosln > 0.0f ) {
resultColor += lightIntensity
* ( cosln * diffuseReflectivity );
}
}
if ( count < numLights ) {
status = lightData.next();
CHECK_MSTATUS( status );
}
}
resultColor[0] = resultColor[0] * surfaceColor[0] + incandescence[0];
resultColor[1] = resultColor[1] * surfaceColor[1] + incandescence[1];
resultColor[2] = resultColor[2] * surfaceColor[2] + incandescence[2];
if ( plug == aOutColor || plug == aOutColorR || plug == aOutColorG
|| plug == aOutColorB)
{
MDataHandle outColorHandle = block.outputValue( aOutColor,
&status );
CHECK_MSTATUS( status );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
}
if ( plug == aOutTransparency || plug == aOutTransR
|| plug == aOutTransG || plug == aOutTransB )
{
MFloatVector& transparency = block.inputValue(
aInTransparency, &status ).asFloatVector();
CHECK_MSTATUS( status );
MDataHandle outTransHandle = block.outputValue(
aOutTransparency, &status );
CHECK_MSTATUS( status );
MFloatVector& outTrans = outTransHandle.asFloatVector();
outTrans = transparency;
outTransHandle.setClean();
}
}
else
{
return( MS::kUnknownParameter );
}
return( MS::kSuccess );
}
MStatus initializePlugin( MObject obj )
{
const MString UserClassify( "shader/surface" );
MString command( "if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\"" );
MFnPlugin plugin( obj, PLUGIN_COMPANY, "4.5", "Any" );
CHECK_MSTATUS( plugin.registerNode( "lambertShader", lambert::id,
lambert::creator, lambert::initialize, MPxNode::kDependNode,
&UserClassify ) );
command += UserClassify;
command += "\");}\n";
CHECK_MSTATUS( MGlobal::executeCommand( command ) );
return( MS::kSuccess );
}
MStatus uninitializePlugin( MObject obj )
{
const MString UserClassify( "shader/surface" );
MString command( "if( `window -exists createRenderNodeWindow` ) {refreshCreateRenderNodeWindow(\"" );
MFnPlugin plugin( obj );
CHECK_MSTATUS( plugin.deregisterNode( lambert::id ) );
command += UserClassify;
command += "\");}\n";
CHECK_MSTATUS( MGlobal::executeCommand( command ) );
return MS::kSuccess;
}