Hi!
I'm writing a custom deformer using the C++ API (I hope it's okay to post that here!) that operates on many individual meshes. I've found that one of my biggest bottlenecks is simply reading the data from my inputs.
As an example, if I create a deformer that does nothing but get the value of a single plug:
MStatus MyDeformer::deform(MDataBlock& data, MItGeometry& itGeo,
const MMatrix& localToWorldMatrix, unsigned int geomIndex)
{
MStatus status;
MMatrix inputMatrix = data.inputValue(aInputMatrix).asMatrix();
return MS::kSuccess;
}
and then in my Maya scene, if I plug 20 meshes into this deformer, or plug 20 meshes into 20 of these deformers (the performance seems to be equivalent) and constantly change the input matrix (locators world matrix in my tests) I get an increase in CPU usage
of around 19% compared to if these deformers were not present.
To test, I created 20 DistanceDimension nodes, which at the very least have to read the two inputs from the data block for the start and end positions, do a calculation and finally do some drawing in the viewport for the display, and I only get an increase of 6%, compared to my 19%! :(
(I've also tried changing the matrix attribute to a double3 in case getting matrices were just particularly slow)
Is there a way to optimize this? How do these in-built nodes read the data so efficiently? My node has several attributes that is has to get and just reading these inputs is destroying my CPU..
Thanks!
Kaine