Optimizing Mesh Normals Access

Optimizing Mesh Normals Access

jmreinhart
Advisor Advisor
618 Views
6 Replies
Message 1 of 7

Optimizing Mesh Normals Access

jmreinhart
Advisor
Advisor

I have a custom node that requires me to access the vertex normals of the input mesh.

I switched from getVertexNormals to using getRawNormals (with some extra stuff to go from vertex-face to per-vertex normals), and expected to see a big jump in performance but there was almost no change. I did some profiling to compare the two and it seems like no matter which method you choose, Maya has to update the surface normals which is a heavy calculation. Is there a faster way to do this?

0 Likes
619 Views
6 Replies
Replies (6)
Message 2 of 7

stuzzz
Collaborator
Collaborator

hi,,

I've already got such issue already. 

I found a workaround by creating a Mvector array attribute to the custom node storing the normals. It acts like a cache.

Then anytime I need to retrieve the normals of the mesh, I get the plug values of my custom attribute if it's not empty.

 

 

0 Likes
Message 3 of 7

jmreinhart
Advisor
Advisor

I use that "caching" method a lot, but I usually use internal node data instead of actual attributes to avoid weird attribute dependency. Unfortunately that won't work for me in this particular case because the mesh has deformations being applied before this node that queries the normals. 

Message 4 of 7

stuzzz
Collaborator
Collaborator

what's that internal thing?

do you have some details?

0 Likes
Message 5 of 7

jmreinhart
Advisor
Advisor

If you have variable on your MPxDeformer class (like an MFloatVectorArray) you can set and get that variable during the deformation loop. If you've seen Chad Vernons maya API tutorial he talks about it in his section on "performance considerations". It's a really good technique especially when dealing with weights because pulling weights out of the dataBlock every time is slow compared to pulling them once, putting then in a c++ vector, and then pulling from the vector.

0 Likes
Message 6 of 7

stuzzz
Collaborator
Collaborator

So you talk about class variables?

0 Likes
Message 7 of 7

jmreinhart
Advisor
Advisor

Yes.

0 Likes