Unable to spawn a Rigid object using a USD Path

Isaac Sim Version

4.2.0

Isaac Lab Version

omni-isaac-lab 0.30.1
omni.isaac-lab_assets 0.1.4
omni-isaac-lab_tasks 0.10.17

Operating System

Ubuntu 22.04

Topic Description

Detailed Description

I am trying to create a new scene, with custom USDs.
I want to add a human using a USD file as an object with physics properties (mass, collisions, etc). Thus, I tried loading the human as a RigidBody. However, I cannot load the human using a USD path by using the RigidObjectCfg.

Steps to Reproduce

  1. Setup a scene - Use the Rigid Object tutorial to set up a scene. Instead of loading objects with a predefined configuration, please load any USD from a custom path using UsdFileCfg.
    In my case, I am using the create_scene.py from the standalone tutorial. Apart from the ground and dome_light, I have added the human rigid body code using a USD path.
@configclass
class HumanSceneCfg(InteractiveSceneCfg):

    # ground plane
    ground = AssetBaseCfg(prim_path="/World/defaultGroundPlane", spawn=sim_utils.GroundPlaneCfg())

    # lights
    dome_light = AssetBaseCfg(
        prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75))
    )

    human = RigidObjectCfg(
        prim_path="/World/Human",
        spawn=sim_utils.UsdFileCfg(
            usd_path="/<path_to_usd>/USD/male_adult_police_04.usd",
        ),
        init_state=RigidObjectCfg.InitialStateCfg(),
    )
def run_simulator(sim: sim_utils.SimulationContext, scene: InteractiveScene):
    """Runs the simulation loop."""
    # Extract scene entities
    # note: we only do this here for readability.

    human = scene["human"]
    # Define simulation stepping
    sim_dt = sim.get_physics_dt()
    count = 0
    # Simulation loop
    while simulation_app.is_running():

        sim.step()
        # Increment counter
        count += 1
        # Update buffers
        scene.update(sim_dt)


def main():
    """Main function."""
    # Load kit helper
    sim_cfg = sim_utils.SimulationCfg(device=args_cli.device)
    sim = SimulationContext(sim_cfg)
    # Set main camera
    sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0])
    # Design scene
    scene_cfg = HumanSceneCfg(num_envs=args_cli.num_envs, env_spacing=2.0)
    scene = InteractiveScene(scene_cfg)
    # Play the simulator
    sim.reset()
    # Now we are ready!
    print("[INFO]: Setup complete...")
    # Run the simulator
    run_simulator(sim, scene)


if __name__ == "__main__":
    # run the main function
    main()
    # close sim app
    simulation_app.close()

Error Messages

When I try to run this, I get the following warning.

And then the following error message -
[INFO]: Setup complete…
Traceback (most recent call last):
File “/root/miniconda3/envs/isaacplan/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/root/miniconda3/envs/isaacplan/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
File “/root/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/adapter/…/…/debugpy/launcher/…/…/debugpy/main.py”, line 39, in
cli.main()
File “/root/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/adapter/…/…/debugpy/launcher/…/…/debugpy/…/debugpy/server/cli.py”, line 430, in main
run()
File “/root/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/adapter/…/…/debugpy/launcher/…/…/debugpy/…/debugpy/server/cli.py”, line 284, in run_file
runpy.run_path(target, run_name=“main”)
File “/root/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py”, line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File “/root/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py”, line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File “/root/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py”, line 124, in _run_code
exec(code, run_globals)
File “/viewpoint_autonomy/standalone/human_scene.py”, line 187, in
main()
File “/viewpoint_autonomy/standalone/human_scene.py”, line 182, in main
run_simulator(sim, scene)
File “/viewpoint_autonomy/standalone/human_scene.py”, line 164, in run_simulator
scene.update(sim_dt)
File “/IsaacLab/source/extensions/omni.isaac.lab/omni/isaac/lab/scene/interactive_scene.py”, line 494, in update
rigid_object.update(dt)
File “/IsaacLab/source/extensions/omni.isaac.lab/omni/isaac/lab/assets/rigid_object/rigid_object.py”, line 127, in update
self._data.update(dt)
AttributeError: ‘RigidObject’ object has no attribute ‘_data’. Did you mean: ‘data’?

I was able to fix the issue.

As mentioned in the rigid_object.py file within the IsaacLab directory, for an asset to be considered as a rigid object, the root prim of the asset must have the USD RigidBodyAPI applied to it.

The USD that I was trying to import did not have any Physics API, so I added the following -

  • RigidBodyAPI
  • MassAPI
  • CollisionAPI

After adding these to the root prim, I was able to import the rigid body using the RigidObjectCfg using a USD file.

I am also adding below the code I used to add the Physics API to the USD root prim.

from pxr import Usd, UsdGeom, UsdPhysics, Gf

def analyze_usd_file(file_path):

    # Open the USD stage
    stage = Usd.Stage.Open(file_path)
    if not stage:
        print(f"Could not open USD file: {file_path}")
        return None


    print(f"Opened USD file: {file_path}")


    prim_data = {}
    for prim in stage.Traverse():

        prim_path = str(prim.GetPath())
        prim_type = prim.GetTypeName()
        prim_name = prim.GetName()
        print(f"Analyzing Prim: {prim_name} | Type: {prim_type} | Path: {prim_path}")


        properties = {} #use this section to see the properties of the USD
        for prop in prim.GetProperties():
            prop_name = prop.GetName()
            prop_value = prim.GetAttribute(prop_name).Get()
            print(f"Property: {prop_name} | Value: {prop_value}")

        rigid_body_api = UsdPhysics.RigidBodyAPI.Get(stage, prim_path)

        if rigid_body_api:
            print(f"The prim '{prim_path}' has RigidBodyAPI applied.")
        else:
            print(f"The prim '{prim_path}' does NOT have RigidBodyAPI applied.")
            if prim.CanApplyAPI(UsdPhysics.RigidBodyAPI):
                print("Applying RigidBodyAPI...")
                UsdPhysics.RigidBodyAPI.Apply(prim)
                print("RigidBodyAPI applied.")

        mass_api = UsdPhysics.MassAPI.Get(stage, prim_path)
        if mass_api:
            print(f"The prim '{prim_path}' has MassAPI applied.")
        else:
            print(f"The prim '{prim_path}' does NOT have MassAPI applied.")
            if prim.CanApplyAPI(UsdPhysics.MassAPI):
                print("Applying MassAPI...")
                UsdPhysics.MassAPI.Apply(prim)
                print("MassAPI applied.")


        collision_api = UsdPhysics.CollisionAPI.Get(stage, prim_path)
        if collision_api:
            print(f"The prim '{prim_path}' has CollisionAPI applied.")
        else:
            print(f"The prim '{prim_path}' does NOT have CollisionAPI applied.")
            if prim.CanApplyAPI(UsdPhysics.CollisionAPI):
                print("Applying CollisionAPI...")
                UsdPhysics.CollisionAPI.Apply(prim)
                print("CollisionAPI applied.")
        stage.GetRootLayer().Save()
        break # as we are just doing it for the root


    return prim_data


def main():

    usd_file_path = "<your_path>.usd"

    prim_data = analyze_usd_file(usd_file_path)



if __name__ == "__main__":
    main()

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