Randomizing the color of a prim without using a registered function

I am trying to randomize the color of floor (say only once and not triggered every frame). I am following this tutorial:

https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_replicator/randomizer_details.html

def main():
    # Open the environment in a new stage
    print(f"Loading Stage {ENV_URL}")
    open_stage(prefix_with_isaac_asset_server(ENV_URL))

    # Create a custom scope for newly added prims
    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"]
    with floor_prims:
        rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (1, 1, 1)))

Here’s the error I got:

2023-02-21 14:15:41 [16,367ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/NVIDIA/Assets/Characters/Reallusion/Worker/Materials/OmniRL_PBR.mdl?watch=00007f2bf2290410(111,19): C183 unused parameter 'emissive_intensity'
2023-02-21 14:15:41 [16,367ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/NVIDIA/Assets/Characters/Reallusion/Worker/Materials/OmniRL_PBR.mdl?watch=00007f2bf2290410(111,19): C183 unused parameter 'emissive_intensity'
2023-02-21 14:15:42 [16,984ms] [Warning] [omni.isaac.core.simulation_context.simulation_context] A new stage was opened, World or Simulation Object are invalidated and you would need to initialize them again before using them.
2023-02-21 14:15:42 [17,033ms] [Error] [__main__] Exception: __enter__
Traceback (most recent call last):
  File "/home/mona/SDG/omniverse-sdg/offline_generation.py", line 711, in <module>
    main()
  File "/home/mona/SDG/omniverse-sdg/offline_generation.py", line 425, in main
    with floor_prims:
AttributeError: __enter__
[17.177s] Simulation App Shutting Down

I also tried this other version and still same error:

def main():
    # Open the environment in a new stage
    print(f"Loading Stage {ENV_URL}")
    open_stage(prefix_with_isaac_asset_server(ENV_URL))

    # Create a custom scope for newly added prims
    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"]
    
    for floor_prim in floor_prims:
        with floor_prim:
            rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (1, 1, 1)))
            
    
    
    # with floor_prims:
    #     rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (1, 1, 1)))

Error is:

2023-02-21 14:20:12 [15,960ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/NVIDIA/Assets/Characters/Reallusion/Worker/Materials/OmniRLBase.mdl?watch=00007f2212e02bb0(102,32): C302 conversion from 'float' to 'float3' must be explicit
2023-02-21 14:20:12 [15,960ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/NVIDIA/Assets/Characters/Reallusion/Worker/Materials/OmniRL_PBR.mdl?watch=00007f2182355880(111,19): C183 unused parameter 'emissive_intensity'
2023-02-21 14:20:12 [15,960ms] [Warning] [rtx.neuraylib.plugin] Compiler Core: omniverse://localhost/NVIDIA/Assets/Isaac/2022.2.0/NVIDIA/Assets/Characters/Reallusion/Worker/Materials/OmniRL_PBR.mdl?watch=00007f2182355880(111,19): C183 unused parameter 'emissive_intensity'
2023-02-21 14:20:13 [16,575ms] [Warning] [omni.isaac.core.simulation_context.simulation_context] A new stage was opened, World or Simulation Object are invalidated and you would need to initialize them again before using them.
2023-02-21 14:20:13 [16,624ms] [Error] [__main__] Exception: __enter__
Traceback (most recent call last):
  File "/home/mona/SDG/omniverse-sdg/offline_generation.py", line 718, in <module>
    main()
  File "/home/mona/SDG/omniverse-sdg/offline_generation.py", line 427, in main
    with floor_prim:
AttributeError: __enter__
[16.791s] Simulation App Shutting Down

actually I figured it. This is what I need. Thanks a lot for pointers and help @ahaidu and @toni.sm

def register_color_randomizer(prim_path):
    prim = rep.get.prims(semantics=[('class', 'floor')])
    def randomize_color():
        mats = rep.create.material_omnipbr(
            metallic=rep.distribution.uniform(0.0, 1.0),
            roughness=rep.distribution.uniform(0.0, 1.0),
            diffuse=rep.distribution.uniform((0, 0, 0), (1, 1, 1)),
            specular=rep.distribution.uniform(0.0, 1.0), 
            count=1000,
        )
        with prim:
            rep.randomizer.materials(mats)
        return prim.node

    rep.randomizer.register(randomize_color)

^Please let me know if this function has caveats or problems though or could be improved.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.