#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();
~simpleEvaluationNode() override;
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 )
{
if( returnStatus != MS::kSuccess )
{
cerr << "ERROR getting data" << endl;
return returnStatus;
}
if( returnStatus != MS::kSuccess )
{
cerr << "ERROR getting data" << endl;
return returnStatus;
}
float outputValue;
{
if( !cachedValueIsValid )
{
cachedValue = doExpensiveCalculation( inputData.
asFloat() , (float) time.
value() );
cachedValueIsValid = true;
}
outputValue = cachedValue;
}
else
{
outputValue = doExpensiveCalculation( inputData.
asFloat() , (float) time.
value() );
}
outputHandle.
set( outputValue );
}
else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
{
if (plug == input || plug == aTimeInput )
{
{
cout << "Evaluation Graph is being constructed" << endl;
}
{
cout << "Evaluation Manager is active, but not in construction" << endl;
}
cachedValueIsValid = false;
}
}
#define DO_PRE_EVAL
{
#ifdef DO_PRE_EVAL
{
{
cachedValueIsValid = false;
}
}
#endif
return MS::kSuccess;
}
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;}
return MS::kSuccess;
}
{
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;
}