- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've written a very simple DG node that must respond to any changes in and input mesh OR it's location, scale, etc. To this end the node takes in both a mesh AND its world matrix like so:
The initialize and (very simple) compute functions are pasted below. Basically what should happen is as one changes the mesh or transform of sphere1 we should see sphere2 jump up and down along its y axis (see the silly compute function below). I see that sphere2 does jump up and down continuously while I edit sphere1's mesh. However as I attempt to change sphere2's transform in the Maya GUI the sphere2 jumps only once at the beginning of the scale/rotate/translate operation and that's all. Why is the compute function getting called continuously during the scale/rotate/translate operation?
MStatus VtdNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus status;
static float jump = 1.0;
if (plug != aOutValue)
{
cout << "wrong plug" << endl;
return MS::kUnknownParameter;
}
MDataHandle hOutput = data.outputValue(aOutValue, &status);
if (status != MS::kSuccess)
{
cout << "data.outputValue status: " << status << "\n" << endl;
}
CHECK_MSTATUS_AND_RETURN_IT(status);
jump = -jump;
hOutput.setFloat(jump);
hOutput.setClean();
data.setClean(plug);
return MS::kSuccess;
}
MStatus VtdNode::initialize()
{
MStatus status;
MFnNumericAttribute nAttr;
MFnTypedAttribute tAttr;
MFnMatrixAttribute mAttr;
MFnCompoundAttribute cAttr;
aOutValue = nAttr.create("outValue", "outValue", MFnNumericData::kFloat);
if (status != MS::kSuccess)
{
cout << "create outValue status: " << status << "\n" << endl;
}
CHECK_MSTATUS_AND_RETURN_IT(status);
nAttr.setWritable(false);
nAttr.setStorable(false);
addAttribute(aOutValue);
aInput = cAttr.create("input", "input", &status);
if (status != MS::kSuccess)
{
cout << "create input status: " << status << "\n" << endl;
}
cAttr.setArray(true);
//cAttr.setDisconnectBehavior(MFnAttribute::kDelete);
aInputMesh = tAttr.create("inputMesh", "inputMesh", MFnData::kMesh, MObject::kNullObj, &status);
if (status != MS::kSuccess)
{
cout << "create inputMesh status: " << status << "\n" << endl;
}
CHECK_MSTATUS_AND_RETURN_IT(status);
tAttr.setWritable(true);
tAttr.setKeyable(true);
addAttribute(aInputMesh);
attributeAffects(aInputMesh, aOutValue);
cAttr.addChild(aInputMesh);
aInputMatrix = mAttr.create("inputMatrix", "inputMatrix", MFnMatrixAttribute::kDouble, &status);
if (status != MS::kSuccess)
{
cout << "create inputMatrix status: " << status << "\n" << endl;
}
CHECK_MSTATUS_AND_RETURN_IT(status);
mAttr.setWritable(true);
//mAttr.setHidden(true);
mAttr.setKeyable(true);
//mAttr.setDisconnectBehavior(MFnAttribute::kDelete);
addAttribute(aInputMatrix);
attributeAffects(aInputMatrix, aOutValue);
cAttr.addChild(aInputMatrix);
addAttribute(aInput);
attributeAffects(aInput, aOutValue);
return MS::kSuccess;
}
Solved! Go to Solution.