Isaac Sim Project Prim onto other

Hi,
I want to project one prim to the transform of another one.
Like in this post: How to set prim location in isaac sim - #3 by joshchiu

However, I receive an error message that says that I need to pass an dynamic control transform instead of an Gf4dMatrix. Did the API change or is there an error on my side?

This is the code

def adapt_transform_to_prim(self, path):
         tracked_prim = self.current_stage.GetPrimAtPath(self.stagepath_tracker)
         matrix = omni.usd.get_world_transform_matrix(tracked_prim)
         prim = self.current_stage.GetPrimAtPath(self.toolPath)
         rigid_body = self.dc.get_rigid_body(path)
         self.dc.set_rigid_body_pose(rigid_body, matrix)

I tried to solve that by getting the dynamic control transform of the rigidboy I want to project, but then I receive an error that the pose is not valid.:

def adapt_transform_to_prim(self, path):
         tracked_prim = self.current_stage.GetPrimAtPath(self.stagepath_tracker)
         matrix = omni.usd.get_world_transform_matrix(tracked_prim)
         prim = self.current_stage.GetPrimAtPath(self.toolPath)
         rigid_body = self.dc.get_rigid_body(path)
         current_pose = self.dc.get_rigid_body_pose(rigid_body)
         # Override Current Post with values of the transformation matrix
         overriden_pose = current_pose
        translation = [matrix[3][0], matrix[3][1], matrix[3][2]]
        rotation = [gfMatrix4d.ExtractRotationQuat().GetReal(), gfMatrix4d.ExtractRotationQuat().GetImaginary()
        overriden_pose.p.x = translation [0]
        overriden_pose.p.y = translation [1]
        overriden_pose.p.z = translation [2]
        overriden_pose.r.w = rotation[0]
        overriden_pose.r.x = rotation[1][0]
        overriden_pose.r.y = rotation[1][1]
        overriden_pose.r.z = rotation[1][2]
        self.dc.set_rigid_body_pose(rigid_body, overriden_pose )

@christian.koenig i am not an expert, but not sure if this snippet is relevant in your use case?

https://docs.omniverse.nvidia.com/isaacsim/latest/how_to_guides/environment_setup.html#align-two-usd-prims

1 Like

Great, thank you, this works at the most parts.
If anyone else has problems with this, omni.usd.utils.get_world_transform_matrix is now under omni.usd.get_world_transform_matrix.
This code below leads to the expected result:

# Get Vive Tracker Data
        tracked_prim = self.current_stage.GetPrimAtPath(self.stagepath_tracker)
        tracked_pose = omni.usd.get_world_transform_matrix(tracked_prim)
        # Get References to Visualization Object
        follower_prim = self.current_stage.GetPrimAtPath(self.toolPath)
        follower_pose = omni.usd.get_world_transform_matrix(follower_prim)
        # Adapt Transformation
        follower_xform = UsdGeom.Xformable(follower_prim)
        follower_xform.ClearXformOpOrder()        
        xformOp = follower_xform.AddXformOp(UsdGeom.XformOp.TypeTransform, UsdGeom.XformOp.PrecisionDouble, "")
        xformOp.Set(tracked_pose)        

Unfortunately I don’t want to apply scale and have oriented my approach to this: https://docs.omniverse.nvidia.com/dev-guide/latest/programmer_ref/usd/transforms/get-local-transforms.html
But by trying to keep the same scale, the follower prim does not moved anymore.

# Get Vive Tracker Data
        tracked_prim = self.current_stage.GetPrimAtPath(self.stagepath_tracker)
        tracked_pose = omni.usd.get_world_transform_matrix(tracked_prim)
        # Get References to Visualization Object
        follower_prim = self.current_stage.GetPrimAtPath(self.toolPath)
        follower_pose = omni.usd.get_world_transform_matrix(follower_prim)
        # Keep Scale
        scale_follower: Gf.Vec3d = Gf.Vec3d(*(v.GetLength() for v in follower_pose.ExtractRotationMatrix()))
        tracked_pose.SetScale(scale_follower)
        # Adapt Transformation
        follower_xform = UsdGeom.Xformable(follower_prim)
        follower_xform.ClearXformOpOrder()        
        xformOp = follower_xform.AddXformOp(UsdGeom.XformOp.TypeTransform, UsdGeom.XformOp.PrecisionDouble, "")
        xformOp.Set(tracked_pose) 

just to confirm, you are extracting rotation matrix?