How Can I tell if a plug is dirty during "prepareForDraw"?

How Can I tell if a plug is dirty during "prepareForDraw"?

jmreinhart
Advisor Advisor
864 Views
3 Replies
Message 1 of 4

How Can I tell if a plug is dirty during "prepareForDraw"?

jmreinhart
Advisor
Advisor

So I have a custom locator that draws a subset of faces to make a deformable control using two inputs (a mesh, and a intArray of faces IDs). Like this https://vimeo.com/311008901 

 

Ultimately I'm using this method to draw it:

 

drawManager.mesh(MHWRender::MUIDrawManager::kTriangles, draw_trianglePoints, NULL,NULL, &triangleIds);

 

Because I have to convert from facesIDs to triangle and vertex ids, I have stuff set up so that I cache the vertex ids I need to requery the positions of on each redraw, and I also put those positions into a non-repeating array and the "triangleIds" attribute contains the indices within that short list of positions that define each triangle I draw.

 

So "draw_trianglePoints" updates every time the mesh deforms, but "triangleIds" only updates if the topology changes or I change the value of the faceIds inputs. However during the "prepareForDraw" step I can't think of a way to avoid always re-querying "triangleIds" in case the value has changed, since I only have access to the DAG node being drawn. Does anyone have experience with optimizing custom locators for stuff like this?

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

muir.j
Contributor
Contributor

Not sure if this helps, but might be worth checking out the source for footPrintNode_GeometryOverride - it implements a variable called 'geometryChanging' that is updated in the compute node and then propagated through to the draw override class.

 

On a related note, if you are doing manipulators, the draw method also has limited access to variables so you have to pass the parent deformer class as a variable so you can get things while in the manip class.

Message 3 of 4

jmreinhart
Advisor
Advisor

Unfortunately that's different than what I'm looking for. I found workaround where the user can manually reset a seprate attribute to tell the prepareForDraw method that the list of points I'm passing has changed. Unfortunately the speed increase was basically nothing, so I think I'm gonna have to shelf this MPxLocator and try a different approach entirely.

0 Likes
Message 4 of 4

jmreinhart
Advisor
Advisor
Accepted solution

Thanks to Matt Lefevre's method of using a forced compute and MObject.userNode to access the custom locators internal data I came up with a solution using setDependentsDirty. I've attached the .cpp with the solution. To summarize:

 

when the input to the MPxLocator changes it triggers setDependentsDirty which sets an internal attribute_dirty variable to true. During the prepareForDraw method we use MObject.userNode to access that attribute_dirty value to determine if we need to requery the MPlug or if the value already in the MUserData is still valid.

0 Likes