MPxLocatorNode updating values on transform

Hi All,

I have a custom locator node derived off MPxLocatorNode.

I want to re-compute my output value when the locator’s rotation changes in world space (I would also settle for local space).

I have tried adding:

attributeAffects(worldMatrix, aOutForce);

To the initialize() method, where aOutForce is the output value I need to calculate.

Has any one managed to get this working in your own plugins?
Anyone got a work around or a better way of achieving the same result?

I am now thinking about adding a ‘attribute changed’ event to the parent transforms rotation channels and using DGDirty! There must be a better way.

Cheers,

Keir

That should work as far as I know, if the “worldMatrix” is the name of a variable that is an MObject for an input plug like MfnNumericData and you are connecting out of the rotation of the object that you are rotating to that input plug.

The worldMatrix is an attribute in the form of an MObject. It comes ‘for free’ when using the MPxLocatorNode as a base, as shown in the docs.

I have not made any connections from the transforms rotation to my shape. I was hoping to avoid doing that.

I have been thinking some more about this issue and was thinking that my approach relaying on the world matrix would break down if my shape was ever instanced…

Your right I should try the connection approach next.

WIN!

So it turns out my that using:

attributeAffects(worldMatrix, aOutForce);

Is the wrong approach.
Making connections from the parent transform to the shape is also wrong.

The solution is to add the use the setWorldSpace function on the attribute that you need to affect.

In the static initialize:


// Final force
MFnNumericAttribute mNumAttr;
aOutForce = mNumAttr.create("forceOutput", "fout", MFnNumericData::k3Double);
mNumAttr.setWorldSpace(true);
mNumAttr.setArray(true);
status = addAttribute(aOutForce);
CHECK_MSTATUS(status);

This code is much more reliable than making connections to the parent transform. It updates faster, runs more smoothly and animates nicely.

From the docs:

Sets whether this attribute should be treated as worldspace. Being worldspace indicates the attribute is dependent on the worldSpace transformation of this node, and will be marked dirty by any attribute changes in the hierarchy that affects the worldSpace transformation. The attribute needs to be an array since during instancing there are multiple worldSpace paths to the node & Maya requires one array element per path for worldSpace attributes.

NOTES: 1. Can only be used on array attributes. 2. This property is ignored on non-dag nodes.

So any time you need the translation, rotation, scale or a change to the transform matrix of your custom shape/locator to affect one of your attributes you now know what to do.

Keir Rice