Well, I'm pretty much a newbe with the API, so this solution may be really crappy. What I did was use MPxNode:: thisMObject to access the ramp attribute from within the compute method. It works, but I don't know if it's the "proper" way of doing it, since the docs stress that you should get data from plugs using handles. So maybe it's a really slow method (the node just has one computation per update, so It's hard to see if it's fast or not - for that I'd have to test it on a shading node or make a loop in this testnode which uses the getValueAtPosition method many many times during the compute method). Does anyone have any ideas wether this is the proper way of doing it?
Anyway, here's a modified version of the exampleRampAttrNode where it's used (just exchange the original code in exampleMRampAttribute.cpp with this and compile).
CODE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class exampleRampAttrNode : public MPxNode
{
public:
exampleRampAttrNode() {};
virtual ~exampleRampAttrNode() {};
static void *creator();
static MStatus initialize();
virtual MStatus compute(const MPlug &plug, MDataBlock &dataBlock);
static MObject aRamp;
static MObject aInput; // The input value.
static MObject aOutput; // The output value.
static MTypeId id;
};
MTypeId exampleRampAttrNode::id( 0x81027 );
MObject exampleRampAttrNode::aRamp;
MObject exampleRampAttrNode::aInput;
MObject exampleRampAttrNode::aOutput;
void *exampleRampAttrNode::creator()
{
return((void *) new exampleRampAttrNode);
}
MStatus exampleRampAttrNode::initialize()
{
MFnNumericAttribute nAttr;
MStatus stat;
MString curveRamp("curveRamp");
MString cvr("cvr");
aRamp = MRampAttribute::createCurveRamp(curveRamp, cvr);
aInput = nAttr.create( "input", "in", MFnNumericData::kFloat, 0.0 );
aOutput = nAttr.create( "output", "out", MFnNumericData::kFloat, 0.0 );
nAttr.setWritable(false);
nAttr.setStorable(false);
stat = addAttribute(aRamp);
if(!stat)
{
cout << "ERROR in adding curveRamp Attribute!\n";
}
stat = addAttribute( aInput );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = addAttribute( aOutput );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = attributeAffects( aInput, aOutput );
if (!stat) { stat.perror("attributeAffects"); return stat;}
stat = attributeAffects( aRamp, aOutput );
if (!stat) { stat.perror("attributeAffects"); return stat;}
return stat;
}
MStatus exampleRampAttrNode::compute( const MPlug &plug, MDataBlock &dataBlock )
{
MStatus returnStatus;
if( plug == aOutput )
{
MDataHandle inputData = dataBlock.inputValue( aInput, &returnStatus );
if( returnStatus != MS::kSuccess )
cerr << "ERROR getting data" << endl;
// MDataHandle hRamp = dataBlock.inputValue( aRamp, &returnStatus );
// if( returnStatus != MS::kSuccess )
// cerr << "ERROR getting data" << endl;
MObject thisNode = thisMObject();
MRampAttribute ramp (thisNode, aRamp, &returnStatus);
if( returnStatus != MS::kSuccess )
cerr << "ERROR getting data" << endl;
float rampOut = -1.0;
float position = inputData.asFloat();
ramp.getValueAtPosition(position, rampOut, &returnStatus);
MDataHandle outputHandle = dataBlock.outputValue( exampleRampAttrNode::aOutput );
outputHandle.set( rampOut );
dataBlock.setClean(plug);
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;}
MStatus initializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj, "Alias - Example", "7.0", "Any");
status = plugin.registerNode("exampleRampAttrNode", exampleRampAttrNode::id,
exampleRampAttrNode::creator, exampleRampAttrNode::initialize);
if (!status)
{
status.perror("registerNode");
return status;
}
return status;
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj);
status = plugin.deregisterNode(exampleRampAttrNode::id);
if (!status)
{
status.perror("deregisterNode");
return status;
}
return status;
}