Hey all,
Having troubles iterating over a maya scene quickly to get all lights.
So we have a maya 2011 scene with a largeish number of objects (5000+).
Say we have 3 or 4 point lights in that scene that we want to get in our API.
MItDag iter( MItDag::kBreadthFirst, MFn::kPointLight);
for ( ; !iter.isDone(); iter.next() )
{
MDagPath lightPath;
iter.getPath(lightPath);
potentialLights.append(lightPath);
}
Now, the iteration loop above is fast, as it only iterates over 4 objects.
However, the creation of the MItDag object (the first line of code above) is very very slow, as (im guessing) it interally iterates over each DAG object and checks if its a point light, adding it to the list of objects to iterate over if it is.
If i change the search type to kDepthFirst, things are much faster, but still not as fast as I’d like (its still taking about 5-6 seconds to execute that first line of code).
Some questions:
- Why is the creation of this iterator so slow in large scenes?
- Why does changing kBreadthFirst to kDepthFirst speed it up so much? Aren’t they both (internally) checking every single DAG node vs kPointLight?
- How come the mel command
maya.cmds.ls(type="light")
executes instantly, whereas these API calls are much slower?
Most important question
- What is the fastest way to get a list of lights from the API then?
A really easy way to do some tests is to compile the scanDagSyntax plugin from the maya devkit (for some reason, it only runs in Release mode though for me), then call it with the following:
maya.cmds.scanDagSyntax(depthFirst=True, lights=True);