Hi, I have two folder paths: one for “dolls” and one for “hose”. I need to instantiate the two groups seperatly in order to assign semantics but then I need to group them together in order to proparly scatter all objects on the same plane. This is my code:
import omni.replicator.core as rep
HOSE_ON_GROUND_ASSETS_DIR = "C:/Users/dsiss/Desktop/Synthia-LFS/Omniverse/randomization_assets/water_hose/rolled_on_ground"
DOLLS_ASSETS_DIR = "C:/Users/dsiss/Desktop/Synthia-LFS/Omniverse/randomization_assets/toys/dolls"
plane_path = "/World/Plane"
with rep.new_layer():
traversable_plane = rep.get.prim_at_path(plane_path)
hoses_usd = rep.utils.get_usd_files(HOSE_ON_GROUND_ASSETS_DIR)
hoses_prims = rep.randomizer.instantiate(hoses_usd, size=5, use_cache = False)
with rep.utils.sequential():
with hoses_prims:
rep.modify.semantics(semantics = [("class", "hose")])
dolls_usd = rep.utils.get_usd_files(DOLLS_ASSETS_DIR)
dolls_prims = rep.randomizer.instantiate(dolls_usd, size=5, use_cache = False)
with rep.utils.sequential():
with dolls_prims:
rep.modify.semantics(semantics = [("class", "toy")])
group = rep.create.group(semantics=[("class", "hose"), ("class", "toy")])
with rep.utils.sequential():
with group:
rep.randomizer.scatter_2d(traversable_plane, check_for_collisions=True)
the line
group = rep.create.group(semantics=[("class", "hose"), ("class", "toy")])
does not work.
get.prims does not work eaither.
How can I group these prims after instantiating (or before) while still assigning different semantics?
group = rep.create.group([hoses_prims, dolls_prims])
I believe what is happening in your original script is that rep.modify.semantics and rep.create.group are essentially evaluated at the same time (since there is no clear dependency on other objects in the code). So when rep.create.group is being evaluated, there are no prims with semantics=[("class", "hose"), ("class", "toy")].
By writing it as group = rep.create.group([hoses_prims, dolls_prims])
You are using the exact prims you instantiated earlier
By using variables from earlier in the script, a dependency is created and those are evaluated first
@dennis.lynch Hi, I tried this too but it does not work.
So this is my code:
import omni.replicator.core as rep
plane_path = "/World/Plane"
HOSE_ON_GROUND_ASSETS_DIR = "C:/Users/dsiss/Desktop/synthia-LFS/Omniverse/randomization_assets/water_hose/rolled_on_ground"
DOLLS_ASSETS_DIR = "C:/Users/dsiss/Desktop/synthia-LFS/Omniverse/randomization_assets/toys/dolls"
with rep.new_layer():
traversable_plane = rep.get.prim_at_path(plane_path)
hoses_usd = rep.utils.get_usd_files(HOSE_ON_GROUND_ASSETS_DIR)
hoses_prims = rep.randomizer.instantiate(hoses_usd, size=4, with_replacements = False, use_cache = False)
with rep.utils.sequential():
with hoses_prims:
rep.modify.semantics(semantics = [("class", "hose")])
dolls_usd = rep.utils.get_usd_files(DOLLS_ASSETS_DIR)
dolls_prims = rep.randomizer.instantiate(dolls_usd, size=4, with_replacements = False, use_cache = False)
with rep.utils.sequential():
with dolls_prims:
rep.modify.semantics(semantics = [("class", "toy")])
group = rep.create.group(items=[hoses_prims, dolls_prims])
with rep.utils.sequential():
with group:
rep.randomizer.scatter_2d(traversable_plane, check_for_collisions=True)
But it seems that only the hose prims are properly scattered, meaning that the group only consists of hoses_prims. If i switch the order of the items list:
group = rep.create.group(items=[dolls_prims, hoses_prims])
Then same is still true, only the hose prims are scattered.
@dennis.lynch Thank you for this work around but it wont work since create.from_usd expects a path to a single usd but my path is a path to a directory.
I tried using choice:
with rep.new_layer():
traversable_plane = rep.get.prim_at_path(plane_path)
hoses_usds = rep.utils.get_usd_files(HOSE_ON_GROUND_ASSETS_DIR)
hose = rep.distribution.choice(hoses_usds)
with hose:
rep.create.from_usd(semantics=[("class", "hose")])
But this does not work either. Using create.from_dir is also not an option as it selects all the usds in that directory.
this code works (i can segment the different prims and scatter them). But I need to randomly select files from the directory (and not all the usd files)