How should I fix this error? I want to throw the pallets using scatter_2d onto the floor_prims
Error:
import omni.usd
import omni.replicator.core as rep
from pxr import Usd, UsdGeom, Gf
from datetime import datetime
import numpy as np
PALLET_URL = "omniverse://localhost/NVIDIA/Assets/ArchVis/Industrial/Pallets/Pallet_B1.usd"
ENV_URL ="omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/Isaac/Samples/Replicator/Stage/full_warehouse_worker_and_anim_cameras.usd"
#open_stage(ENV_URL)
#result, error = omni.usd.get_context().open_stage(ENV_URL, load_set=omni.usd.UsdContextInitialLoadSet.LOAD_NONE)
omni.usd.get_context().open_stage(ENV_URL)
stage = omni.usd.get_context().get_stage()
#stage = get_current_stage()
#floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]
floor_prims_paths = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() ]
floor_prims = []
for floor_prim_path in floor_prims_paths:
floor_prims.append(omni.usd.get_prim_at_path(floor_prim_path))
#bb_cache = bounds_utils.create_bbox_cache()
#combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)
#min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr
# bbox = omni.usd.get_context().compute_path_world_bounding_box(floor_prims[0])
# min_x, min_y, min_z, max_x, max_y, max_z = bbox
# print("bbox is: ", bbox)
def compute_bbox_with_cache(cache: UsdGeom.BBoxCache, prim: Usd.Prim) -> Gf.Range3d:
"""
Compute Bounding Box using ComputeWorldBound at UsdGeom.BBoxCache. More efficient if used multiple times.
See https://graphics.pixar.com/usd/dev/api/class_usd_geom_b_box_cache.html
Args:
cache: A cached, i.e. `UsdGeom.BBoxCache(Usd.TimeCode.Default(), ['default', 'render'])`
prim: A prim to compute the bounding box.
Returns:
A range (i.e. bounding box), see more at: https://graphics.pixar.com/usd/release/api/class_gf_range3d.html
"""
bound = cache.ComputeWorldBound(prim)
bound_range = bound.ComputeAlignedBox()
return bound_range
bbcache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), ["default", "render"])
bb = compute_bbox_with_cache(bbcache, floor_prims[0])
max_x, max_y, max_z = bb.GetMax()
min_x_arr = []
min_y_arr = []
min_z_arr = []
max_x_arr = []
max_y_arr = []
max_z_arr = []
for floor_prim in floor_prims:
tmp_bb = compute_bbox_with_cache(bbcache, floor_prim)
tmp_min_x, tmp_min_y, tmp_min_z = tmp_bb.GetMin()
tmp_max_x, tmp_max_y, tmp_max_z = tmp_bb.GetMax()
min_x_arr.append(tmp_min_x)
min_y_arr.append(tmp_min_y)
min_z_arr.append(tmp_min_z)
max_x_arr.append(tmp_max_x)
max_y_arr.append(tmp_max_y)
max_z_arr.append(tmp_max_z)
min_x = min(min_x_arr)
min_y = min(min_y_arr)
min_z = min(min_z_arr)
max_x = max(max_x_arr)
max_y = max(max_y_arr)
max_z = max(max_z_arr)
margin = 3
def scatter_pallets(prim):
pallets = rep.create.from_usd(PALLET_URL, semantics=[('class', 'pallet')], count=50)
with pallets:
rep.physics.collider()
rep.modify.pose(scale=0.001)
rep.randomizer.scatter_2d(surface_prims=prim, check_for_collisions=True),
return pallets
# Register randomization
rep.randomizer.register(scatter_pallets)
# Setup camera and attach it to render product
camera = rep.create.camera(
focus_distance=800,
focal_length=40
# f_stop=0.5,
# f_stop=500,
#focal_length=613.634
)
render_product = rep.create.render_product(camera, resolution=(1024, 1024))
timestamp = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")
# Initialize and attach writer
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(output_dir="/home/mona/Desktop/Isaac_Sim_Dummy_Out/scattered_pallets_warehouse/" + timestamp , rgb=True, bounding_box_2d_tight=True)
writer.attach([render_product])
with rep.trigger.on_frame(num_frames=50):
pallets = rep.randomizer.scatter_pallets(floor_prims)
print('pallets is: ', pallets)
print('pallets type is: ', type(pallets))
# pallets = rep.randomizer.randomize_pallet()
with camera:
rep.modify.pose(position=rep.distribution.uniform((min_x + margin, min_y + margin, 4), (max_x - margin, max_y - margin, 7)),
look_at=pallets)