Skip to content

Instantly share code, notes, and snippets.

@davidtjones
Last active Mar 26, 2022
Embed
What would you like to do?
Incompatibe xform ops for USD file for online data generation
import torch
import random
import numpy as np
import carb
from omni.isaac.kit import SimulationApp
RANDOM_TRANSLATION_X = (-230.0, 230.0)
RANDOM_TRANSLATION_Z = (-230.0, 230.0)
RANDOM_ROTATION_Y = (0.0, 360.0)
SCALE = 1
CAMERA_DISTANCE = 300
BBOX_AREA_THRESH = 16
# Default rendering parameters
RENDER_CONFIG = {"renderer": "PathTracing", "samples_per_pixel_per_frame": 12, "headless": False}
class RandomObjects(torch.utils.data.IterableDataset):
def __init__(self):
self.kit = SimulationApp(RENDER_CONFIG)
self.stage = self.kit.context.get_stage()
self._setup_world()
def _setup_world(self):
from pxr import UsdGeom
from omni.isaac.core.utils.prims import create_prim
from omni.isaac.core.utils.rotations import euler_angles_to_quat
import omni
create_prim("/World/Room", "Sphere", attributes={"radius": 1e3, "primvars:displayColor": [(1.0, 1.0, 1.0)]})
create_prim("/World/Ground", "Cylinder", position=np.array([0.0, -0.5, 0.0]),
orientation=euler_angles_to_quat(np.array([90.0, 0.0, 0.0]), degrees=True),
attributes={"height": 1, "radius": 1e4, "primvars:displayColor": [(1.0, 1.0, 1.0)]},
)
create_prim("/World/Light1", "SphereLight", position=np.array([-450, 350, 350]),
attributes={"radius": 100, "intensity": 30000.0, "color": (0.0, 0.365, 0.848)}
)
create_prim("/World/Light2", "SphereLight", position=np.array([450, 350, 350]),
attributes={"radius": 100, "intensity": 30000.0, "color": (1.0, 0.278, 0.0)},
)
create_prim("/World/Asset", "Xform")
self.kit.update()
def __iter__(self):
return self
def __next__(self):
asset = self.load_single_asset("omniverse://localhost/Isaac/Props/Dolly/dolly.usd", "0")
while True:
self.kit.update()
return asset
def load_single_asset(self, ref, semantic_label, suffix=""):
from pxr import UsdGeom, Usd
from omni.isaac.core.utils.prims import create_prim, get_prim_path
from omni.isaac.core.utils.rotations import euler_angles_to_quat
x = random.uniform(*RANDOM_TRANSLATION_X)
z = random.uniform(*RANDOM_TRANSLATION_Z)
rot_y = random.uniform(*RANDOM_ROTATION_Y)
asset = create_prim(
f"/World/Asset/mesh{suffix}",
"Xform",
scale=np.array([1, 1, 1]),
orientation=euler_angles_to_quat(np.array([0.0, rot_y, 0.0])),
usd_path=ref,
semantic_label=semantic_label)
usd_mesh = UsdGeom.Mesh(asset)
bound = usd_mesh.ComputeWorldBound(0.0, "default")
box_min_y = bound.GetBox().GetMin()[1]
print(f"Box Min Y: {box_min_y}")
UsdGeom.XformCommonAPI(asset).SetTranslate((x, -box_min_y, z))
return asset
if __name__ == "__main__":
for asset in RandomObjects():
continue
dataset.kit.close()
@davidtjones
Copy link
Author

davidtjones commented Mar 26, 2022

Note that I've used

while True:
    self.kit.update()

on line 48 to stop the iterator and just run the simulator. This enables me (the user) to use the simulator and poke around and see what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment