add STL to USD converter and a script that shows how to load an USD file in Isaac Sim
Browse files- min_example.py +70 -0
- stl_to_usd.py +35 -0
- test_all_usd.py +101 -0
min_example.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from omni.isaac.lab.app import AppLauncher
|
| 3 |
+
|
| 4 |
+
parser = argparse.ArgumentParser(description="Test")
|
| 5 |
+
AppLauncher.add_app_launcher_args(parser)
|
| 6 |
+
args_cli = parser.parse_args()
|
| 7 |
+
app_launcher = AppLauncher(headless=False, hide_ui=True, width=640, height=480)
|
| 8 |
+
simulation_app = app_launcher.app
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
import torch
|
| 12 |
+
import os
|
| 13 |
+
import random
|
| 14 |
+
from omni.isaac.core import SimulationContext
|
| 15 |
+
from omni.isaac.core.prims import RigidPrim, GeometryPrim
|
| 16 |
+
from omni.isaac.core.utils import prims
|
| 17 |
+
from omni.isaac.core.world import World
|
| 18 |
+
from omni.isaac.core.objects import FixedCuboid
|
| 19 |
+
|
| 20 |
+
device='cuda'
|
| 21 |
+
backend='torch'
|
| 22 |
+
#device='cpu'
|
| 23 |
+
#backend='numpy'
|
| 24 |
+
|
| 25 |
+
simulation_context = SimulationContext(device=device, backend=backend)
|
| 26 |
+
simulation_context.get_physics_context().enable_gpu_dynamics(True)
|
| 27 |
+
|
| 28 |
+
if World.instance():
|
| 29 |
+
World.instance().clear_instance()
|
| 30 |
+
|
| 31 |
+
world=World(device=device, backend=backend)
|
| 32 |
+
world.scene.add_default_ground_plane()
|
| 33 |
+
|
| 34 |
+
base_dir = os.getcwd()
|
| 35 |
+
usd_file = os.path.join(base_dir,'usd_object','usd','nontextured_proc.usd')
|
| 36 |
+
object_name = '/my_object'
|
| 37 |
+
obj_prim = prims.create_prim(usd_path=usd_file, prim_path=object_name)
|
| 38 |
+
rigid_prim = RigidPrim(prim_path=str(obj_prim.GetPrimPath()), name=object_name, mass=0.5,position=(0,0,0.5))
|
| 39 |
+
geometry_prim = GeometryPrim(prim_path=str(obj_prim.GetPrimPath()), name=object_name, collision=True)
|
| 40 |
+
geometry_prim.set_collision_approximation("convexDecomposition")
|
| 41 |
+
geometry_prim.set_contact_offset(1e-5)
|
| 42 |
+
geometry_prim.set_rest_offset(0)#1e-3)
|
| 43 |
+
rigid_prim.enable_rigid_body_physics()
|
| 44 |
+
world.scene.add(rigid_prim)
|
| 45 |
+
|
| 46 |
+
#cuboid = FixedCuboid(prim_path='/table',name='/table',scale=torch.tensor([10,10,0.4]).to('cuda'), color=np.array([255, 0, 0]))
|
| 47 |
+
cuboid = FixedCuboid(prim_path='/table',name='/table',scale=np.array([10,10,0.4]), color=np.array([255, 0, 0]))
|
| 48 |
+
world.scene.add(cuboid)
|
| 49 |
+
|
| 50 |
+
print('initializing physics...''')
|
| 51 |
+
simulation_context.initialize_physics()
|
| 52 |
+
rigid_prim.initialize()
|
| 53 |
+
simulation_context.play()
|
| 54 |
+
for _ in range(100):
|
| 55 |
+
simulation_context.step(render=True)
|
| 56 |
+
world.reset()
|
| 57 |
+
print("world reset")
|
| 58 |
+
|
| 59 |
+
print('stepping..')
|
| 60 |
+
i = 0
|
| 61 |
+
simulation_context.set_block_on_render(True)
|
| 62 |
+
while simulation_app.is_running():
|
| 63 |
+
simulation_context.step(render=True)
|
| 64 |
+
# this changes after clicking the 'visual'
|
| 65 |
+
print(rigid_prim.get_local_pose())
|
| 66 |
+
i += 1
|
| 67 |
+
if i % 100 == 0:
|
| 68 |
+
print('stepping..')
|
| 69 |
+
|
| 70 |
+
|
stl_to_usd.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
|
| 3 |
+
from omni.isaac.lab.app import AppLauncher
|
| 4 |
+
|
| 5 |
+
# add argparse arguments
|
| 6 |
+
parser = argparse.ArgumentParser(description="Pick and lift state machine for lift environments.")
|
| 7 |
+
parser.add_argument("--num_envs", type=int, default=4, help="Number of environments to simulate.")
|
| 8 |
+
parser.add_argument("--save_path", type=str, default=None, help="Directory to store the data in.")
|
| 9 |
+
# append AppLauncher cli args
|
| 10 |
+
AppLauncher.add_app_launcher_args(parser)
|
| 11 |
+
|
| 12 |
+
# TODO parse the arguments
|
| 13 |
+
args_cli = parser.parse_args()
|
| 14 |
+
batch_size = 32
|
| 15 |
+
device='cuda'
|
| 16 |
+
headless = True
|
| 17 |
+
|
| 18 |
+
# launch omniverse app
|
| 19 |
+
app_launcher = AppLauncher(headless=False, enable_cameras=True)
|
| 20 |
+
simulation_app = app_launcher.app
|
| 21 |
+
|
| 22 |
+
"""Rest everything else."""
|
| 23 |
+
from omni.isaac.lab.sim.converters import MeshConverter, MeshConverterCfg
|
| 24 |
+
from omni.isaac.lab.sim.schemas import CollisionPropertiesCfg
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
#obj_urdf_path = '/home/mmatak/ycb-fixed-meshes/002_master_chef_can/google_16k/nontextured_proc.stl'
|
| 28 |
+
obj_urdf_path = '/home/mmatak/ycb-fixed-meshes/003_cracker_box/google_16k/nontextured_proc.stl'
|
| 29 |
+
collision_cfg = CollisionPropertiesCfg(collision_enabled=True, contact_offset=1e-3, rest_offset=1e-3)
|
| 30 |
+
|
| 31 |
+
cfg = MeshConverterCfg(force_usd_conversion=True, asset_path=obj_urdf_path,\
|
| 32 |
+
usd_dir='/home/mmatak/ycb-fixed-meshes/usd', collision_props=collision_cfg)
|
| 33 |
+
MeshConverter(cfg)
|
| 34 |
+
print('converted')
|
| 35 |
+
|
test_all_usd.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
|
| 3 |
+
from omni.isaac.lab.app import AppLauncher
|
| 4 |
+
|
| 5 |
+
# add argparse arguments
|
| 6 |
+
parser = argparse.ArgumentParser(description="Test")
|
| 7 |
+
# append AppLauncher cli args
|
| 8 |
+
AppLauncher.add_app_launcher_args(parser)
|
| 9 |
+
|
| 10 |
+
# TODO parse the arguments
|
| 11 |
+
args_cli = parser.parse_args()
|
| 12 |
+
|
| 13 |
+
# launch omniverse app
|
| 14 |
+
app_launcher = AppLauncher(headless=False)
|
| 15 |
+
simulation_app = app_launcher.app
|
| 16 |
+
|
| 17 |
+
"""Rest everything else."""
|
| 18 |
+
# 3rd party libs
|
| 19 |
+
import numpy as np
|
| 20 |
+
import torch
|
| 21 |
+
import os
|
| 22 |
+
|
| 23 |
+
import random
|
| 24 |
+
from tqdm import tqdm
|
| 25 |
+
from omni.isaac.core import SimulationContext
|
| 26 |
+
from omni.isaac.core.prims import RigidPrim, GeometryPrim
|
| 27 |
+
from omni.isaac.core.utils import prims
|
| 28 |
+
from omni.isaac.core.utils.stage import add_reference_to_stage
|
| 29 |
+
from omni.isaac.core.world import World
|
| 30 |
+
from omni.isaac.core.objects import FixedCuboid
|
| 31 |
+
|
| 32 |
+
device='cuda'
|
| 33 |
+
backend='torch' if 'cuda' in device else 'numpy'
|
| 34 |
+
|
| 35 |
+
simulation_context = SimulationContext(device=device, backend=backend)
|
| 36 |
+
simulation_context.get_physics_context().enable_gpu_dynamics(True)
|
| 37 |
+
|
| 38 |
+
if World.instance():
|
| 39 |
+
World.instance().clear_instance()
|
| 40 |
+
|
| 41 |
+
world=World(device=device, backend=backend)
|
| 42 |
+
world.scene.add_default_ground_plane()
|
| 43 |
+
|
| 44 |
+
# Directory where subdirectories are located
|
| 45 |
+
base_dir = os.getcwd()
|
| 46 |
+
|
| 47 |
+
# Get all subdirectory names in the base directory
|
| 48 |
+
subdirectories = [name for name in os.listdir(base_dir) if os.path.isdir(os.path.join(base_dir, name))]
|
| 49 |
+
|
| 50 |
+
# Iterate through each subdirectory
|
| 51 |
+
z = 1.0
|
| 52 |
+
obj_id = 0
|
| 53 |
+
for subdir in tqdm(subdirectories[:10]):
|
| 54 |
+
print(subdir)
|
| 55 |
+
# Define the path to the URDF file
|
| 56 |
+
stl_file = os.path.join(base_dir, subdir, 'google_16k', 'nontextured_proc.stl')
|
| 57 |
+
usd_dir = os.path.join(base_dir, subdir, 'usd')
|
| 58 |
+
usd_file = os.path.join(usd_dir, 'nontextured_proc.usd')
|
| 59 |
+
if not os.path.isfile(usd_file):
|
| 60 |
+
usd_file = os.path.join(usd_dir, 'nontextured.usd')
|
| 61 |
+
if not os.path.isfile(usd_file):
|
| 62 |
+
continue
|
| 63 |
+
object_name = '/object_' + str(obj_id) #str(subdir)
|
| 64 |
+
obj_id += 1
|
| 65 |
+
print('object name: ', object_name)
|
| 66 |
+
print('usd filepath: ', usd_file)
|
| 67 |
+
#add_reference_to_stage(usd_path=usd_file, prim_path=object_name)
|
| 68 |
+
obj_prim = prims.create_prim(usd_path=usd_file, prim_path=object_name)
|
| 69 |
+
#add_reference_to_stage(usd_path=object_name, prim_path=usd_file)
|
| 70 |
+
rigid_prim = RigidPrim(prim_path=str(obj_prim.GetPrimPath()), name=object_name, mass=0.5,\
|
| 71 |
+
position=(random.random()*8-4, random.random()*8-4, random.random() + 0.5))
|
| 72 |
+
geometry_prim = GeometryPrim(prim_path=str(obj_prim.GetPrimPath()), name=object_name, collision=True)
|
| 73 |
+
geometry_prim.set_collision_approximation("convexDecomposition")
|
| 74 |
+
geometry_prim.set_contact_offset(0.001)
|
| 75 |
+
geometry_prim.set_rest_offset(1e-3)
|
| 76 |
+
rigid_prim.enable_rigid_body_physics()
|
| 77 |
+
world.scene.add(rigid_prim)
|
| 78 |
+
#world.scene.add(geometry_prim)
|
| 79 |
+
|
| 80 |
+
z += 0.2
|
| 81 |
+
|
| 82 |
+
cuboid = FixedCuboid(prim_path='/table',name='/table',scale=torch.tensor([10,10,0.4]).to('cuda'), color=np.array([255, 0, 0]))
|
| 83 |
+
world.scene.add(cuboid)
|
| 84 |
+
|
| 85 |
+
print('initializing physics...''')
|
| 86 |
+
simulation_context.initialize_physics()
|
| 87 |
+
#prim.initialize()
|
| 88 |
+
simulation_context.play()
|
| 89 |
+
world.reset()
|
| 90 |
+
print("world reset")
|
| 91 |
+
|
| 92 |
+
print('stepping..')
|
| 93 |
+
i = 0
|
| 94 |
+
simulation_context.set_block_on_render(True)
|
| 95 |
+
while simulation_app.is_running():
|
| 96 |
+
simulation_context.step(render=True)
|
| 97 |
+
i += 1
|
| 98 |
+
if i % 100 == 0:
|
| 99 |
+
print('stepping..')
|
| 100 |
+
|
| 101 |
+
|