Pivot Tool Not Working from Script

Hello, I am currently using Isaac Sim 4.2 and trying to use the pivot tool from a Python script. I followed the documentation for the pivot tool and attempted to perform pivoting with the code below.
However, when I visualize the USDA file, it appears that the pivot has not been applied. Additionally, when I load the USD file saved through the GUI, the pivoting also doesn’t seem to have been applied. Could you please advise on how to resolve this issue?

import argparse

from omni.isaac.lab.app import AppLauncher

parser = argparse.ArgumentParser(description="Utility to convert a mesh file into USD format.")
parser.add_argument("input", type=str, nargs="+", help="The path to the input mesh file.")
AppLauncher.add_app_launcher_args(parser)
args_cli = parser.parse_args()

app_launcher = AppLauncher(args_cli)
simulation_app = app_launcher.app

"""Rest everything follows."""
import os
import carb
import omni
import omni.usd
import omni.kit.commands
import omni.kit.app as app
from pxr import Sdf, Gf, UsdPhysics, UsdLux, PhysxSchema, Usd, UsdGeom
from omni.isaac.lab.utils.assets import check_file_path


def main():
    # check valid file path
    usd_paths = args_cli.input
    if usd_paths is None:
        raise ValueError("USD paths does not exist.")
    else:
        print("USD paths:", usd_paths)

    manager = omni.kit.app.get_app().get_extension_manager()
    # enable immediately
    manager.set_extension_enabled_immediate("omni.tools.pivot", True)

    for usd_path in usd_paths:
        if not os.path.isabs(usd_path):
            usd_path = os.path.abspath(usd_path)
        if not check_file_path(usd_path):
            raise ValueError(f"Invalid usd file path: {usd_path}")

        stage = Usd.Stage.Open(usd_path)
        omni.kit.commands.execute("PivotToolAddPivot", prim_paths=["/model_0/geometry"])
        omni.kit.commands.execute("PivotToolSetPivotToBoundingBoxCenter", prim_paths=["/model_0/geometry"])

        prim = UsdGeom.Xform.Get(stage, "/model_0/geometry")
        print(stage.ExportToString())
        
        # Save usd
        stage.GetRootLayer().Save()
        
        print(f"[INFO] Usd path is {usd_path}")
        print("[INFO] Pivotting is done!")
    
    simulation_app.close()
    

if __name__ == "__main__":
    main()

usda output

def Xform "model_0" (
    apiSchemas = ["PhysicsMassAPI", "PhysicsRigidBodyAPI", "PhysxRigidBodyAPI"]
)
{
    float physics:mass = 0.25

    def Xform "geometry" (
        instanceable = true
        kind = "component"
        add references = </Flattened_Prototype_1>
    )
    {
        quatd xformOp:orient = (1, 0, 0, 0)
        double xformOp:rotateX:unitsResolve = 90
        double3 xformOp:scale = (1, 1, 1)
        double3 xformOp:scale:unitsResolve = (0.01, 0.01, 0.01)
        double3 xformOp:translate = (0, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale", "xformOp:rotateX:unitsResolve", "xformOp:scale:unitsResolve"]
    }
}

The issue has been resolved!
The cause was that the mesh had been made instanceable, but I was able to fix it by directly setting the xform:transformOp on the geometry mesh in the instanceable_meshes.usd.

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