#include <string.h>
#include <maya/MIOStream.h>
#include <math.h>
#include <maya/MPxNode.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MTime.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MEvaluationNode.h>
#include <maya/MEvaluationManager.h>
#include <maya/MFnPlugin.h>
class simpleEvaluationNode :
public MPxNode
{
public:
simpleEvaluationNode();
virtual ~simpleEvaluationNode();
static void* creator();
public:
private:
bool cachedValueIsValid;
float cachedValue;
float doExpensiveCalculation( float a, float b );
};
MTypeId simpleEvaluationNode::id( 0x0008002B );
MObject simpleEvaluationNode::input;
MObject simpleEvaluationNode::aTimeInput;
MObject simpleEvaluationNode::output;
simpleEvaluationNode::simpleEvaluationNode()
: cachedValueIsValid( false )
, cachedValue( 0.0 )
{
}
simpleEvaluationNode::~simpleEvaluationNode()
{
}
float simpleEvaluationNode::doExpensiveCalculation( float a, float b )
{
return a * b ;
}
{
if( plug == output )
{
{
cerr << "ERROR getting data" << endl;
}
else
{
{
cerr << "ERROR getting data" << endl;
}
else
{
if ( ! cachedValueIsValid )
{
cachedValue = doExpensiveCalculation( inputData.
asFloat() , (float) time.
value() );
cachedValueIsValid = true;
}
outputHandle.
set( cachedValue );
}
}
} else {
}
}
{
if (plug == input || plug == aTimeInput )
{
{
cout << "Evaluation Graph is being constructed" << endl;
}
{
cout << "Evaluation Manager is active, but not in construction" << endl;
}
cachedValueIsValid = false;
}
}
{
#ifdef DO_PRE_EVAL
{
cachedValueIsValid = false;
}
#endif
}
void* simpleEvaluationNode::creator()
{
return new simpleEvaluationNode();
}
MStatus simpleEvaluationNode::initialize()
{
status = addAttribute( input );
if (!status) { status.
perror(
"addAttribute");
return status;}
status = addAttribute( aTimeInput );
if (!status) { status.
perror(
"addAttribute");
return status;}
status = addAttribute( output );
if (!status) { status.
perror(
"addAttribute");
return status;}
status = attributeAffects( input, output );
if (!status) { status.
perror(
"attributeAffects");
return status;}
status = attributeAffects( aTimeInput, output );
if (!status) { status.
perror(
"attributeAffects");
return status;}
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"1.0",
"Any");
status = plugin.registerNode( "simpleEvaluationNode", simpleEvaluationNode::id, simpleEvaluationNode::creator,
simpleEvaluationNode::initialize );
if (!status) {
status.
perror(
"registerNode");
return status;
}
return status;
}
{
status = plugin.deregisterNode( simpleEvaluationNode::id );
if (!status) {
status.
perror(
"deregisterNode");
return status;
}
return status;
}