Currently I am using “GetAttribute(“xformOp:translate”).Get()” to get Translate. However, with this method, I can only get the Translate of the child object, which is local to the parent object.
I would like to know if there is a better way to get the world Translate.
Example
World
ObjectA (Translate X:1.0, Y:1.0, Z:1.0) (child of World)
ObjectB (Translate X: 1.0, Y:0.0, Z:0.0) (child of ObjectA)
I want to get Translate of ObjectB as (X:2.0, 1.0, 1.0) but I can only get (X: 1.0, Y:0.0, Z:0.0).
It is difficult to get the coordinates considering the object’s rotation…
A possible solution would be to calculate the transformation with respect to the world using the ComputeLocalToWorldTransform method as shown in the following snippet
import omni
from pxr import Usd, UsdGeom, Gf
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/ObjectA/ObjectB")
transform = Gf.Transform()
transform.SetMatrix(UsdGeom.Xformable(prim).ComputeLocalToWorldTransform(Usd.TimeCode.Default()))
position = transform.GetTranslation()
orientation = transform.GetRotation().GetQuat()
print(position)
print(orientation)