Maya C++ API custom note plugin ignores world matrix input

Maya C++ API custom note plugin ignores world matrix input

danwwright
Participant Participant
985 Views
2 Replies
Message 1 of 3

Maya C++ API custom note plugin ignores world matrix input

danwwright
Participant
Participant

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:

mayaForumQuestion.PNG

 

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;
}

 

 

0 Likes
Accepted solutions (1)
986 Views
2 Replies
Replies (2)
Message 2 of 3

danwwright
Participant
Participant
Accepted solution

I now find that the compute function will not be called continuously during transform changes UNLESS that compute function actually examines the input world matrix.  I suppose that makes sense as an optimization.  Though oddly the analogous requirement for the input mesh does not seem to hold?

0 Likes
Message 3 of 3

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Maya does use an on demand strategy for optimizing evaluation. I haven't checked about the internal implementation thoroughly but I think the reason here could be outMesh is displayed in Viewport all the time and it could be considered as being demanded all the time. Meanwhile, the world matrix of the shape probably isn't, because of transformation from transform node is used here. 

 

There was some reports about world matrix isn't updating properly during callbacks. That might be related but I think main reason should be the on demanding evaluation policy Maya is using.

 

Yours,

Li

0 Likes