from pxr import Usd, UsdGeom
from pathlib import Path
import omni.usd
import omni.replicator.core as rep
# Axis and unitscale can also be set optionally
# rep.settings.set_stage_up_axis("Z")
# rep.settings.set_stage_meters_per_unit(1.0)
# Create Camera
camera = rep.create.camera(position=(0, 280, 310), rotation=(-45, 0, 0))
stage = omni.usd.get_context().get_stage()
# Retrieve a reference to a plane using rep.get.prims
plane = rep.get.prims(path_pattern="table_low", prim_types="mesh")
# Create a cube with specified properties
cube = rep.create.cube(visible=False, semantics=[('class', 'cube')], position=(50, 100, 0), rotation=(0, 0, 90), scale=(0.2, 0.2, 0.2))
sem = [('class', 'shape')]
# Randomizer for scattering
def get_shapes():
shapes = rep.get.prims(semantics=[('class', 'cube')])
with shapes:
rep.randomizer.scatter_2d(plane)
return shapes.node
rep.randomizer.register(get_shapes)
# Create the projection with the plane as the target
with plane:
proj1 = rep.create.projection_material(cube, sem)
# Modify the cube position, and update the projection
with rep.trigger.on_frame(num_frames=30):
rep.randomizer.get_shapes()
with proj1:
rep.modify.projection_material(diffuse=Path(rep.example.TEXTURES_DIR).joinpath("smiley_albedo.png").as_posix())
I want to perform projection mapping on “table_low” in simpleroom, but it is not functioning correctly. Could you please point out any improvements in the following code?
I am executing the code after opening the spatial asset of simpleroom initially.
simpleroom URL: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.1/Isaac/Environments/Simple_Room/simple_room.usd