How to programmatically rotate the prim correctly with the new pivot position?

Hello everyone,

I have encountered a challenge while automating the manipulation of a Primitive object. The Primitive has a noticeable difference in pivot position compared to its parent object’s xform. To ensure correct scaling, I utilized a pivot tool to adjust the pivot position of the parent object accordingly. With the help of Omniverse’s rotation tool, I have successfully achieved accurate rotation, translation, and scaling of the Primitive using the new pivot point.

However, as I attempted to replicate these transformations programmatically using a Python script and a 4x4 transformation matrix for a -90 degree rotation around the Y-axis, I encountered unexpected stretching effects. Despite the Primitive rotating correctly, the resulting appearance is not as intended.

I would greatly appreciate any guidance or insights on how to address this issue and achieve the desired transformation accurately without the presence of stretching effects. Thank you in advance for your assistance.



import omni.usd
import math
from pxr import Gf, UsdGeom

def get_rotation_matrix(angle):
rotation = Gf.Rotation(Gf.Vec3d(0, 1, 0), angle)
matrix = Gf.Matrix4d(1.0)
matrix.SetRotate(rotation)
return matrix

rotation_matrix = get_rotation_matrix(-90)

stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath(“/scene/Meshes/Sketchfab_model/root/GLTF_SceneRootNode/Box_28”)
transform_matrix = prim.GetAttribute(“xformOp:transform”).Get()

prim.GetAttribute(“xformOp:transform”).Set(rotation_matrix * transform_matrix)

Hi @renton.hsu.vfx. Have you seen this tutorial? Transformations, Time-sampled Animation, and Layer Offsets — Universal Scene Description 23.05 documentation I think this should give you an idea of how you could programmatically recreate the xformOps that you created manually using the pivot tool and transform manipulators.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.