Why and When to use MDGContext
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I've been using MDGContext to evaluate some transforms at a given time thinking that it would be faster than updating the whole scene with "oma.MAnimControl.setCurrentTime(time)". Unfortunately, it seems that updating the whole scene is faster. I'm I using the MDGContext wrong ? When should it be used ? Should I avoid using custom MDGContext?
from maya.api import OpenMaya as om
sel = om.MSelectionList()
sel.add(node + '.worldMatrix[0]')
worldMatplug = sel.getPlug(0)
time = oma.MAnimControl.currentTime()
for f in range(100):
time.value = float(f)
context = om.MDGContext(time)
matObj = worldMatplug.asMObject(context)
wm = om.MFnMatrixData(matObj).matrix()
Looks like I should use MContextGuard instead, but it isn't available in python. I suppose it just set the context as current than switch back to the previous context as the guard goes out of scope?
Edit:
I did some more test and figured out that in most of the times its faster or approximately the same. It is just slower in a particular scene in which there is animations layers. Once I bake the layers, using MDGContext is faster. Any idea why ?
Thanks for your help.
Jonathan