I am using scatter_2d inside Script Editor in Isaac Sim. Please use the script below.
# This needs to be run inside Isaac Sim Script Editor not Omniverse Code Script Editor
import omni.replicator.core as rep
from datetime import datetime
from omni.isaac.core.utils.stage import get_current_stage, open_stage
import omni.isaac.core.utils.bounds as bounds_utils
import omni.isaac.core.utils.prims as prims_utils
import numpy as np
# with rep.new_layer():
# Define paths for the character, the props, the environment and the surface where the assets will be scattered in.
FORKLIFT_URL = "omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.1/Isaac/Props/Forklift/forklift.usd"
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)
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"]
print('dir floor_prims: ', dir(floor_prims))
bb_cache = bounds_utils.create_bbox_cache()
combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)
print('combined_range_arr: ', combined_range_arr)
margin = 2
min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr
def randomize_forklift():
forklift = rep.create.from_usd(FORKLIFT_URL, semantics=[('class', 'forklift')])
with forklift:
rep.physics.collider()
rep.modify.pose(
position=rep.distribution.uniform((min_x + margin, min_y + margin, 0), (max_x - margin, max_y - margin, 0)),
rotation=rep.distribution.uniform((0, 0, -90), (0, 0, 90)),
#scale=100
)
return forklift
# Register randomization
rep.randomizer.register(randomize_forklift)
def scatter_pallets(prim):
pallets = rep.create.from_usd(PALLET_URL, semantics=[('class', 'pallet')], count=2)
with pallets:
rep.physics.collider()
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,
# f_stop=0.5,
f_stop=500,
#focal_length=613.634
)
render_product = rep.create.render_product(camera, resolution=(640, 480))
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/forklift_warehouse/" + timestamp , rgb=True, bounding_box_2d_tight=True)
writer.attach([render_product])
with rep.trigger.on_frame(num_frames=50):
forklift = rep.randomizer.randomize_forklift()
pallets = rep.randomizer.scatter_pallets(forklift)
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)
However, it spawns very large pallets. I intend to use scale 0.01 but it seems scatter_2d is not allowing it. How can I fix this problem?
as you can see the pallet is encompassing the warehouse.usd