Hi all,
I want to change the material and texture of an object by defining a probability for each frame. In 80% of the frames I want the texture/material to remain the default value. In the remaining 20% I want to set a random material/texture. My code to set random materials/textures already works, but how can I define a probability that the materials/textures will not be changed and the default value will be kept?
If I would be able to extract the materials and textures from the usd files that I use (e.g. /Isaac/Props/YCB/Axis_Aligned/002_master_chef_can.usd), I could use rep.distribution.choice and add the default material/texture with a 80% probability. But how can I extract the default values as a path of the material (e.g. /NVIDIA/Materials/Base/Architecture/Roof_Tiles.mdl)?
Code to spawn and simulate the objects:
# Spawn distractors falling
for i in range(number_distractors):
distractor_usd_path = distractor_usds[i]
distractor_prim_name = f"distractor_{i}"
distractor_prim = prims.create_prim(
prim_path=f"/World/distractors/{distractor_prim_name}",
usd_path=prefix_with_isaac_asset_server(distractor_usd_path),
)
# Get the next spawn height for the box
spawn_height += bb_cache.ComputeLocalBound(distractor_prim).GetRange().GetSize()[2] * 1.1
# Wrap the distractor prim into a rigid prim to be able to simulate it
distractor_rigid_prim = RigidPrim(
prim_path=str(distractor_prim.GetPrimPath()),
name=distractor_prim_name,
position=(Gf.Vec3d(random.uniform(spawn_location[0] + CONFIG_DIST_spawn_displacement[0][0], spawn_location[0] + CONFIG_DIST_spawn_displacement[1][0]),
random.uniform(spawn_location[1] + CONFIG_DIST_spawn_displacement[0][1], spawn_location[1] + CONFIG_DIST_spawn_displacement[1][1]),
random.uniform(spawn_location[2] + CONFIG_DIST_spawn_displacement[0][2], spawn_location[2] + CONFIG_DIST_spawn_displacement[1][2]))),
orientation=euler_angles_to_quat([random.uniform(-math.pi, math.pi), random.uniform(-math.pi, math.pi), random.uniform(-math.pi, math.pi)]),
scale=np.array(distractor_scales[i]),
)
# Make sure physics are enabled on the rigid prim
distractor_rigid_prim.enable_rigid_body_physics()
# Enable colission
distractor=GeometryPrim(
prim_path=str(distractor_prim.GetPrimPath()),
name=f"distractor_geom_prim_{i}",
collision=True,
)
distractor.set_collision_approximation("convexHull")
# Register rigid prim with the scene
world.scene.add(distractor)
# Reset the world to handle the physics of the newly created rigid prims
world.reset()
# Simulate the world for the given number of steps
for i in range(max_sim_steps):
world.step(render=False)
Code to randomize the materials/textures:
# Randomization of material and texture of distractor objects
def randomize_distractor_obj():
distractors = rep.get.prims(path_pattern="/World/distractors/")
def rand_distractor_obj():
with distractors:
rep.randomizer.texture(rep.distribution.choice([prefix_with_isaac_asset_server(item) for item in textures]))
rep.randomizer.materials(rep.distribution.choice([prefix_with_isaac_asset_server(item) for item in materials]))
rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (1, 1, 1)))
return distractors.node
rep.randomizer.register(rand_distractor_obj)
Any help is appreciated!
Lukas