Recursively creating thousands of MObjects

Recursively creating thousands of MObjects

Anonymous
Not applicable
443 Views
1 Reply
Message 1 of 2

Recursively creating thousands of MObjects

Anonymous
Not applicable

Hi,

I'm leveraging the instancing behavior of importing multiple GPU caches of the same object.

Say I have 100000 alembic spheres each with a different transform. I wan't to create these in the fastest way possible. some pseudocode for what I'm doing with OpenMaya is:

 

mdm = OpenMaya.MDagModifier()

for each instance:

    create gpucache node

    set the alembic filename

    apply a transform

mdm.doIt()

 

now, over very many objects(with varying complexity) this is painfully slow to build, with doIt() adding roughly 1/2 the time of the instance creation section to the total time. Here's a profiling example:

 

this instance took 0.00145 seconds.
this instance took 0.00066 seconds.
this instance took 0.00066 seconds.
doIt() took 0.00125 seconds.

 

This is also not multithreaded. How can I multithread something like this?

0 Likes
444 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Many MDGModifier and MDagModifier operations defer portions of their processing until doIt() is called. For example I believe that MDagModifier::createNode() doesn't add the created node to the DAG until doIt() is called. So the time for doIt() isn't overhead, if that's what you're thinking. To get a truer idea of where the time is being spent you should call doIt() after each operation and include the doIt() time with that of the operation. (Don't worry, calling doIt() multiple times won't redo the operations which have already been done.) However, in terms of performance you should stick with a single call to doIt() at the end, if you can.

 

The pseudo-code you give shows you creating the transform after the cache node. If you're using MDagModifier to create the GPU cache node then it may be faster to create the transform first and then pass it to MDagModifier::createNode() as the parent for the GPU cache node. You may have to call doIt() in-between.

0 Likes