Dear @jlafleche and @pcallender
I am trying to spawn crates with watertight volumes inside of them. The volumes are not rendered but they are there. After the crates are scattered2d on the surface, I want to scatter3d boxes inside those volumes.
Unfortunately the boxes always appear where the volumes (crates) have been in the previous randomization.
Code:
from box_spawner import BOXES
from base_spawner import BaseSpawner
from scenes.base_scene_config import SceneConfig
from omni.replicator.core.scripts.utils.utils import ReplicatorItem
import omni.replicator.core as rep
CRATE = "file:///home/wojtek/Workspace/Surveily.Omniverse/Library/envs/warehouse_props/crates_inpost.usd"
class CrateSpawner(BaseSpawner):
def __init__(self):
super().__init__()
self.box_pool : list[ReplicatorItem] = []
self.box_poolGroup : ReplicatorItem
self.crate_pool : list[ReplicatorItem] = []
self.crate_poolGroup : ReplicatorItem
async def load(self, config : SceneConfig):
while len(self.box_pool) < config.boxCount*config.crateCount:
for box_url in BOXES:
if len(self.box_pool) < config.boxCount*config.crateCount:
self.box_pool.append(rep.create.from_usd(usd=box_url))
while len(self.crate_pool) < config.crateCount:
self.crate_pool.append(rep.create.from_usd(usd=CRATE))
self.box_poolGroup = rep.create.group(items=self.box_pool)
self.crate_poolGroup = rep.create.group(items=self.crate_pool)
def on_trigger(self, seed : int, floor : lambda : ReplicatorItem, config):
if config.crateCount > 0:
# Randomize cages
with self.crate_poolGroup:
rep.modify.pose(scale=rep.distribution.uniform(0.8,1.2),rotation=rep.distribution.uniform([0, 0, -180],[0, 0, 180]))
rep.modify.variant(name="fill_type",value="full")
rep.modify.variant(name="crate_type",value=rep.distribution.choice(choices=["wheeled","pallet"]))
rep.randomizer.scatter_2d(seed=seed,surface_prims=[floor()],check_for_collisions=True,min_samp=config.scatterRange[0],max_samp=config.scatterRange[1])
# Randomize boxes in cages
with self.box_poolGroup:
rep.modify.pose(scale=rep.distribution.uniform(0.8,1.2),rotation=rep.distribution.uniform([0, 0, -180],[0, 0, 180]))
rep.randomizer.scatter_3d(volume_prims=rep.get.mesh(path_pattern="\/volume_full",cache_result=True),check_for_collisions=True)
Video: