Force evaluation of MPxSurfaceShape with MPxGeometryOverride

Force evaluation of MPxSurfaceShape with MPxGeometryOverride

alex.vJ8Q98
Explorer Explorer
433 Views
2 Replies
Message 1 of 3

Force evaluation of MPxSurfaceShape with MPxGeometryOverride

alex.vJ8Q98
Explorer
Explorer

Hi !

I have a custom MPxSurfaceShape node. This node does not output any relevant plugs to Maya. Instead it has a MPxGeometryOverride that draws from internal data stored on the node.

My main questions are :
1 - How do I make MPxSurfaceShape compute() trigger when any of the input attributes change, even though there is no output attribute to "affect".
2 - How do I correctly notify MPxGeometryOverride that the shape node has changed, and needs to be redrawn ?

This may be trivial but I have looked in every SDK example i can find and they all have different and half explained methods that sometime work, sometime don't. I am looking for the modern way to do this, it has to support DG, Serial and Parallel.
Surely this must be possible in a clean manner ?

PS : I have seen examples using a dummy output attribute, that is pulled from the MPxGeometryOverride to trigger the compute, this sort of works, but unreliably it seems ? The SDK "footPrintNode_GeometryOverride" mentions a "Technique 1.1" but this technique is no where to be found, only technique 1 is implemented, and comments in the code seem to indicate it is not ideal ?

Thanks !
Alex.

0 Likes
434 Views
2 Replies
Replies (2)
Message 2 of 3

maxime.robinot
Participant
Participant

Hey,

This is a good question! I'm also interested in having an answer about that.

I figured that we can use the setInternalValue function to get data from a plug whenever it's value changes, but this is quite limited since the function is called individually for every plugs of your shape.. so it's hard to not do some compute multiple times when multiple plugs are changed at the same time.

 

If maybe you found an answer, could you share it please ?

 

Thanks!

Message 3 of 3

maxime.robinot
Participant
Participant

Hello again!

 

I finally found a clean (mostly) way to force the compute() of an MPxSurfaceShape to be called whenever an input attribute is modified, even though there is no real output.

 

The trick is to call MHWRender::MRenderer::setGeometryDrawDirty(thisMObject()) in the function setDependentsDirty.

Then this will cause draw override to have its prepareForDraw function called, where you need to access a dummy output plug.

MPlug out_plug(your_shape_node->thisMObject(), Your_shape_node_class::dummy_output);
MDataHandle handle =out_plug.asMDataHandle();

This will then cause the compute of the shape node to be called, to satisfy the attributeAffect relation to this output.

In short: you trick Maya to think you have an ouput attribute that's needed ! So you still need to have a dummy ouput attribute, but you don't need to actually connect it 🙂

 

Still, would be great to have an official answer from Autodesk for a really clean way, without having a dummy ouput attribute.

 

Hope this will help others that struggle with that !