query world position of objects at time (after changing scene linear units)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
How can I query the world space position at a specific time in the same units as the scene? I do not want to have to switch the currentTime because in heavy scenes that can cause significant slowness because Maya may have lots of other stuff to calculate just by switching frames.
I'm trying to animate a gravity simulation. To obtain the object's initial velocity I need to know an object's world position (regardless of hierarchy or translate values) at time1 and at time2. My method was to do the following:
import pymel.core as pm
thisObject = pm.ls(sl=True)[0]
world_matrix = pm.getAttr(thisObject +'.worldMatrix', t= time1)
p1 = world_matrix[3]
y1 = p1[1]
world_matrix = pm.getAttr(thisObject +'.worldMatrix', t= time2)
p2 = world_matrix[3]
y2 = p2[1]
v = (y2-y1)/(time2-time1)
However: it's not calculating correctly if I change the scene units from cm to meters. This can lead to my velocity calculation being off by a factor of 100, as the world matrix still returns cm values when all the other calculations are done in meters. When things get moved around, it can also lead to incorrect negative values where the object's worldMatrix position is different from its actual position:
p1 = pm.getAttr(thisObject +'.worldMatrix')[3] #-->[347.522, -58.995, 0.0, 1.0]
p0 = pm.xform(thisObject , q=True, rp=True, ws=True, a=True) #--> [-2.158, 0.4704, 0.0]
p1 != p0
I don't really care that these two query methods don't match, but I need a reliable method of querying worldspace positions at different times (which is impossible with xform) that yield results that are consistent with the scene's linear units.
Ideally, everything would be built in the right units, but we all know that usually doesn't always happen in a production environment.