Domain Randomization

Domain Randomization varies the parameters that define a scene in the simulation environment. Some of the parameters include the pose, scale of various objects in a scene, the lighting of the simulated environment, the appearance of simulated objects via their color and texture properties and so on. One of the main objectives of domain randomization is to enhance the training of deep learning applications by exposing the neural network to wide variety of domain parameters in simulation which will help to generalize well to real world applications. For example, in order to train a deep network to detect a cup, a huge data set is needed for training purpose with randomized color, texture, pose, size of the cup and different lighting conditions. This huge data set is made possible by generating synthetic data in Omniverse Isaac Sim instead of real images.

Here is a glimpse of domain randomization applied on a warehouse scene in Isaac Sim.

Domain Randomizer Plugin

Here, we explain the usage of Domain Randomizer(DR) plugin in Omniverse Isaac Sim and elaborate on the various parameters that can be randomized in the simulation environment.

To enable DR plugin, go to Window -> Extensions menu and enable omni.isaac.dr plugin.

DR Components

In order to randomize various parameters in the scene, DR components need to be created. To deep dive into various components that the plugin supports, open Synthetic Data->Domain Randomization->Samples->Component Randomizer.

Comp Sample Menu

Color Component

The color component enables randomization of the appearance of objects in the simulation environment via color property. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Color and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR color component.

  4. On clicking Play, the color of the cube randomizes.

Color Comp Sample

Here are some parameters in the color component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • firstColor: Specify the minimum R, G, B values. The scale is from 0 to 1.

  • secondColor: Specify the maximum R, G, B values. The scale is from 0 to 1.

  • roughness: Specify the range for roughness property. The scale is from 0 to 1.

  • metallic: Specify the range for metallic property. The scale is from 0 to 1.

  • includeChildren: Enable if the child prims also need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Color Comp UI

Please refer here to create color component via UI. To deep dive into the Python code used to create the sample, please refer here.

Movement Component

The movement component enables randomization of the position of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Movement and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR movement component.

  4. On clicking Play, the position of the cube randomizes.

Mov Comp Sample

Here are some parameters in the movement component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • xRange: Specify the range of X for movement along X-axis.

  • yRange: Specify the range of Y for movement along Y-axis.

  • zRange: Specify the range of Z for movement along Z-axis.

  • polygonPoints: Specify the set of points in world coordinates to define a polygon area for randomization. Currently, it only supports 2D polygon.

  • drawPolygon: Enable to visualize the polygon area as defined by polygonPoints.

  • targetPoints: Specify the set of points in world coordinates to enable randomization along those points randomly.

  • enableSequentialBehavior: Enable to randomize in a sequential order instead of randomly as defined by targetPoints.

  • enableLookAtTarget: Enable to look at a target location during randomization.

  • lookAtTargetPaths: Specify the USD prim path of assets to look at. In case of multiple assets, it looks at an average location specified by the assets.

  • lookAtTargetPoints: Specify the set of points in world coordinates to look at.

  • lookAtTargetOffset: Specify an offset location in world coordinates in addition to lookAtTargetPaths or lookAtTargetPoints.

  • includeChildren: Enable if the child prims also need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Mov Comp UI

Please refer here to create movement component via UI.

Rotation Component

The rotation component enables randomization of the orientation of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Rotation and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR rotation component.

  4. On clicking Play, the orientation of the cube randomizes.

Rot Comp Sample

Here are some parameters in the rotation component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • xRange: Specify the range of X for rotation along X-axis.

  • yRange: Specify the range of Y for rotation along Y-axis.

  • zRange: Specify the range of Z for rotation along Z-axis.

  • includeChildren: Enable if only the child prims of type Xform need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Rot Comp UI

Please refer here to create rotation component via UI.

Scale Component

The scale component enables randomization of the scale of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Scale and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR scale component.

  4. On clicking Play, the scale of the cube randomizes.

Scale Comp Sample

Here are some parameters in the scale component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • xRange: Specify the range of X for scale along X-axis.

  • yRange: Specify the range of Y for scale along Y-axis.

  • zRange: Specify the range of Z for scale along Z-axis.

  • enableUniform: Enable it to scale uniformly along all three axes.

  • includeChildren: Enable if the child prims also need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Scale Comp UI

Please refer here to create scale component via UI.

Transform Component

The transform component enables randomization of the position, orientation and scale of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Transform and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR transform component.

  4. On clicking Play, the position, orientation and scale of the cube randomizes.

Trans Comp Sample

Here are some parameters in the transform component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • translateMin: Specify the minimum X, Y, Z values for translation.

  • translateMax: Specify the maximum X, Y, Z values for translation.

  • rotateMin: Specify the minimum X, Y, Z values for rotation.

  • rotateMax: Specify the maximum X, Y, Z values for rotation.

  • scaleMin: Specify the minimum X, Y, Z values for scale.

  • scaleMax: Specify the maximum X, Y, Z values for scale.

  • polygonPoints: Specify the set of points in world coordinates to define a polygon area for randomization. Currently, it only supports 2D polygon.

  • drawPolygon: Enable to visualize the polygon area as defined by polygonPoints.

  • targetPoints: Specify the set of points in world coordinates to enable randomization along those points randomly.

  • enableSequentialBehavior: Enable to randomize in a sequential order instead of randomly as defined by targetPoints.

  • enableLookAtTarget: Enable to look at a target location during randomization.

  • lookAtTargetPaths: Specify the USD prim path of assets to look at. In case of multiple assets, it looks at an average location specified by the assets.

  • lookAtTargetPoints: Specify the set of points in world coordinates to look at.

  • lookAtTargetOffset: Specify an offset location in world coordinates in addition to lookAtTargetPaths or lookAtTargetPoints.

  • targetPointInstancers: Specify the set of point instancers used to select points in world coordinates to enable randomization along those points in a random order.

  • combineRandomRange: Enable to combine range based randomization with point or point instancer based randomization for translation.

  • excludedTargetPaths: Specify the USD prim path of assets to avoid overlap with.

  • excludedTargetOffset: Specify an offset value along X, Y, Z axis that defines a bounding cube around the random point. This bounding cube is used to check overlap with excluded target assets.

  • includeChildren: Enable if the child prims also need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Trans Comp UI

Light Component

The light component enables randomization of various properties of lights in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Light and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube with a light directly above it.

  3. Press Load DR Component that adds a DR light component.

  4. On clicking Play, light properties like intensity, temperature and color randomizes.

Below is the expected behavior.

Light Comp Sample

Here are some parameters in the light component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • firstColor: Specify the minimum R, G, B values of light color. The scale is from 0 to 1.

  • secondColor: Specify the maximum R, G, B values of light color. The scale is from 0 to 1.

  • intensityRange: Specify the range of light intensity.

  • enableTemperature: Enable if temperature of light needs to be randomized.

  • temperatureRange: Specify the range of light temperature. This is applied only when enableTemperature is enabled.

  • includeChildren: Enable if the child prims also need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Light Comp UI

Please refer here to create light component via UI.

Texture Component

The texture component enables randomization of the appearance of objects in the simulation environment via texture property. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Texture and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR texture component.

  4. On clicking Play, the texture of the cube randomizes.

Texture Comp Sample

Here are some parameters in the texture component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • textureList: List of texture files. Specified as comma separated list of strings.

  • ignoredClass: Prims contains class labels that need to be ignored during randomization. Specified as comma separated list of strings.

  • groupedClass: Prims contains class labels that need to be grouped with similar textures during randomization. Specified as comma separated list of strings.

  • enableProjectUVW: Enable it to allow UVW texture mapping.

  • includeChildren: Enable if only the child prims of type Mesh need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Texture Comp UI

Please refer here to create texture component via UI.

Material Component

The material component enables randomization of the appearance of objects in the simulation environment by applying different materials. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Material and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a cube.

  3. Press Load DR Component that adds a DR material component.

  4. On clicking Play, the material of the cube randomizes.

Material Comp Sample

Here are some parameters in the material component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • materialList: List of material files(.mdl). Specified as comma separated list of strings.

  • ignoredClass: Prims contains class labels that need to be ignored during randomization. Specified as comma separated list of strings.

  • groupedClass: Prims contains class labels that need to be grouped with similar materials during randomization. Specified as comma separated list of strings.

  • loadedMaterialPrimPaths: Specify the USD prim path of pre-loaded material assets to use for randomization.

  • includeChildren: Enable if only the child prims of type Mesh need to included for randomization.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Material Comp UI

Please refer here to create material component via UI.

Mesh Component

The mesh component enables spawning of multiple copies of an asset in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Mesh and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing a light.

  3. Press Load DR Component that adds a DR mesh component along with prims will be spawned under /World/Meshes/mesh_component.

Here are some parameters in the mesh component that can be set.

  • meshList: List of mesh files(.usd). Specified as comma separated list of strings.

  • numMeshRange: Specify the range of number of mesh copies to spawn.

Mesh Comp UI

Visibility Component

The visibility component enables randomization of visibility property of assets in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Visibility and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing multiple cubes.

  3. Press Load DR Component that adds a DR visibility component.

  4. On clicking Play, visibility property randomizes.

Below is the expected behavior.

Visibility Comp Sample

Here are some parameters in the visibility component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • numVisibleRange: Specify the range of number of assets that needs to be visible.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Visibility Comp UI

Please refer here to create visibility component via UI.

Attribute Component

The attribute component enables randomization of various properties (referred as USD attributes) of asset in the simulation environment. In the Domain Randomizer Component Samples UI,

  1. Set the dropdown to Attribute and then press, Clear Stage to open a new empty scene.

  2. Press Load Stage to load a stage containing multiple cubes.

  3. Press Load DR Component that adds a DR attribute component.

  4. On clicking Play, attributes specified in the custom data json (in this case, translation and rotation) randomizes.

Below is the expected behavior.

Attribute Comp Sample

Here are some parameters in the attribute component that can be set.

  • primPaths: Specify the USD prim path of assets to randomize.

  • customData: Specify the randomization parameters for each USD attribute.

  • duration: Time interval in seconds between subsequent randomization.

  • seed: Value to initialize the pseudorandom number generator.

Attribute Comp UI

Create DR Components via UI

One way to enable randomization in a scene is by creating DR components via UI. Below is a workflow to achieve that.

  1. Go to Synthetic Data->Domain Randomization->Components to create a DR component.

  2. For the newly created component, add the path of the assets for the randomization to be applied.

  3. Update the various parameters of the component.

Color Component

In the below scenario, a color component is created. Then, the asset path for the box and floor is added. For example, Xform at path /World/props/box represented the box which was added to the color component. This caused the color of the objects to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the color component in it.

Movement Component

In the below scenario, a movement component is created. Then, the asset path for the cube is added. For example, Xform at path /World/props/nvidia_cube_1 represented the cube which was added to the movement component. This caused the position of the object to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. The parameters that control the range of motion along x, y and z-axis was also updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the movement component in it.

Rotation Component

In the below scenario, a rotation component is created. Then, the asset path for the cube is added. For example, Xform at path /World/props/nvidia_cube_2 represented the cube which was added to the rotation component. This caused the orientation of the object to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. The parameters that control the range of orientation along x, y and z-axis was also updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the rotation component in it.

Scale Component

In the below scenario, a scale component is created. Then, the asset path for the box is added. For example, Xform at path /World/props/box represented the box which was added to the scale component. This caused the scale of the object to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. The parameters that control the range of scale along x, y and z-axis was also updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the scale component in it.

Light Component

In the below scenario, a light component is created. Then, the asset path for the light is added. For example, the scene has a light at path /World/props/DiskLight which was added to the light component. This caused the various properties of the light to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. Other light parameters that includes color, intensity and temperature can be updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the light component in it.

Texture Component

In the below scenario, a texture component is created. Then, a list of texture files from server are added to the textureList parameter.

1
Isaac/Samples/DR/Materials/Textures/checkered.png,Isaac/Samples/DR/Materials/Textures/marble_tile.png,Isaac/Samples/DR/Materials/Textures/picture_a.png,Isaac/Samples/DR/Materials/Textures/picture_b.png,Isaac/Samples/DR/Materials/Textures/textured_wall.png

The asset path is added. For example, the Mesh at path /World/simple_room/table_low_327/table_low represented the table mesh which was added to the texture component. This caused the texture of the table to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the texture component in it.

Material Component

In the below scenario, a material component is created. Then, a list of material files from server are added to the materialList parameter.

1
Isaac/Samples/DR/Materials/checkered.mdl,Isaac/Samples/DR/Materials/checkered_color.mdl,Isaac/Samples/DR/Materials/marble_tile.mdl,Isaac/Samples/DR/Materials/picture_a.mdl,Isaac/Samples/DR/Materials/picture_b.mdl,Isaac/Samples/DR/Materials/textured_wall.mdl

The asset path is added. For example, the Mesh at path /World/simple_room/table_low_327/table_low represented the table mesh which was added to the material component. This caused the material of the table to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the material component in it.

Visibility Component

In the below scenario, a visibility component is created. Then, the asset path for the cubes are added. For example, Xform at paths /World/props/box, /World/props/nvidia_cube_1, /World/props/nvidia_cube_2 represented the cubes which were added to the visibility component. Next, the numVisibleRange is set to (1,2). This caused the visibility of the cubes to randomize such that each randomized scene contains 1 to 2 cubes which are visible. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the visibility component in it.

Domain Randomizer Usage Example

Load DR Samples

Here are two samples that bring together the various DR components and randomizes a scene.

Simple Room Sample

Open Synthetic Data->Domain Randomization->Samples->Simple Room and click Play.

Warehouse Sample

Open Synthetic Data->Domain Randomization->Samples->Warehouse and click Play.

Add DR to an environment

Here are two approaches that loads an environment and adds various DR components to randomize the scene.

Via UI

Open Synthetic Data->Domain Randomization->Samples->Simple Room (Python). In the Simple Room Python Sample UI,

  1. Open the simple room environment by pressing Load Stage.

  2. Add DR components to the environment by pressing Load DR Component and click Play.

Via Python Code

Open Synthetic Data->Domain Randomization->Samples->Simple Room (Python). In the Simple Room Python Sample UI,

  1. Open the simple room environment by pressing Load Stage.

  2. Open Window->Script Editor, paste the below code and click Run to execute python code.

  3. Press Play

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import omni
import omni.isaac.dr

# Enter server name
asset_path = "omniverse://<server-name>/Isaac"

# List of textures to randomize from
texture_list = [
    asset_path + "/Samples/DR/Materials/Textures/checkered.png",
    asset_path + "/Samples/DR/Materials/Textures/marble_tile.png",
    asset_path + "/Samples/DR/Materials/Textures/picture_a.png",
    asset_path + "/Samples/DR/Materials/Textures/picture_b.png",
    asset_path + "/Samples/DR/Materials/Textures/textured_wall.png",
    asset_path + "/Samples/DR/Materials/Textures/checkered_color.png",
]

# Some prim paths to used for randomization
simple_room_prim_path = "/Root"
light_prim_path = "/Root/RectLight"
table_prim_path = "/Root/table_low_327"
floor_prim_path = "/Root/Towel_Room01_floor_bottom_218"

# Create DR texture component
result, prim = omni.kit.commands.execute(
    "CreateTextureComponentCommand",
    prim_paths=[simple_room_prim_path],
    enable_project_uvw=False,
    texture_list=texture_list,
    ignored_class_list=["floor_bottom"],
    grouped_class_list=[],
    duration=1.0,
    include_children=True,
)
# Create DR color component
result, prim = omni.kit.commands.execute(
    "CreateColorComponentCommand",
    prim_paths=[floor_prim_path],
    first_color_range=(0.0, 0.0, 0.0),
    second_color_range=(1.0, 1.0, 1.0),
    roughness_range=(0.0, 1.0),
    metallic_range=(0.0, 1.0),
    duration=1.0,
    include_children=False,
)
# Create DR movement component
result, prim = omni.kit.commands.execute(
    "CreateMovementComponentCommand",
    prim_paths=[table_prim_path],
    min_range=(-50.0, -50.0, -77),
    max_range=(50.0, 50.0, -77),
    target_position=None,
    target_paths=None,
    duration=1.0,
    include_children=False,
)
# Create DR rotation component
result, prim = omni.kit.commands.execute(
    "CreateRotationComponentCommand",
    prim_paths=[table_prim_path],
    min_range=(0.0, 0.0, 0.0),
    max_range=(0.0, 0.0, 360.0),
    duration=1.0,
    include_children=False,
)
# Create DR scale component
result, prim = omni.kit.commands.execute(
    "CreateScaleComponentCommand",
    prim_paths=[table_prim_path],
    min_range=(0.4, 0.4, 0.4),
    max_range=(1.3, 1.3, 1.3),
    uniform_scaling=True,
    duration=1.0,
    include_children=False,
)
# Create DR light component
result, prim = omni.kit.commands.execute(
    "CreateLightComponentCommand",
    light_paths=[light_prim_path],
    first_color_range=(0.9, 0.9, 0.9),
    second_color_range=(1.0, 1.0, 1.0),
    intensity_range=(40000.0, 70000.0),
    temperature_range=(1500.0, 6500.0),
    enable_temperature=True,
    duration=1.0,
    include_children=False,
)

To deep dive into the Python code used to create the sample, please refer here.

Python API Documentation

See the API Documentation for usage information.

Code deep dive

Each DR component sample is created using Python APIs. We will deep dive into the Python code in this section.

Color Component

The code snippets below can be found in the color component sample’s script. This can also be run within Windows->Script Editor inside Omniverse Isaac Sim UI after loading Isaac/Samples/DR/Props/simple_cube_with_light.usd stage.

First, we import some libraries.

1
2
3
4
import omni.kit
import omni.usd
import omni.isaac.dr
from pxr import Sdf

Next, we create DR color component and set its attributes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
stage = omni.usd.get_context().get_stage()
default_prim_path = str(stage.GetDefaultPrim().GetPath())
cube_path = default_prim_path + "/Cube"

# Create DR color component
result, prim = omni.kit.commands.execute(
    "CreateColorComponentCommand",
    prim_paths=[cube_path],
    first_color_range=(0.0, 0.0, 0.0),
    second_color_range=(1.0, 1.0, 1.0),
    roughness_range=(0.0, 1.0),
    metallic_range=(0.0, 1.0),
    duration=0.3,
    include_children=False,
)

Remember, the editor must be playing for the randomization to happen. This can also be done via Python.

1
2
3
editor = omni.kit.editor.get_editor_interface()
if not editor.is_playing():
    editor.play()

To update an attribute of the color component, we need to first access the attribute corresponding to the color component prim that was created earlier and then set it to the new value. For example, we will update the duration attribute of color_component prim to 0 which means color randomization happens every frame.

1
2
3
4
5
6
7
8
9
stage = omni.usd.get_context().get_stage()
default_prim_path = str(stage.GetDefaultPrim().GetPath())
color_component_path = default_prim_path + "/color_component"

# Get DR color component prim
prim = stage.GetPrimAtPath(color_component_path)

# Update duration to 0
prim.GetAttribute("duration").Set(float(0))

Simple Room Python Sample

In this section, we do a deep dive into the code snippet provided here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import omni
import omni.isaac.dr

# Enter server name
asset_path = "omniverse://<server-name>/Isaac"

# List of textures to randomize from
texture_list = [
    asset_path + "/Samples/DR/Materials/Textures/checkered.png",
    asset_path + "/Samples/DR/Materials/Textures/marble_tile.png",
    asset_path + "/Samples/DR/Materials/Textures/picture_a.png",
    asset_path + "/Samples/DR/Materials/Textures/picture_b.png",
    asset_path + "/Samples/DR/Materials/Textures/textured_wall.png",
    asset_path + "/Samples/DR/Materials/Textures/checkered_color.png",
]

# Some prim paths to use for randomization
simple_room_prim_path = "/Root"
light_prim_path = "/Root/RectLight"
table_prim_path = "/Root/table_low_327"
floor_prim_path = "/Root/Towel_Room01_floor_bottom_218"

First, we import some libraries including DR. Then, we specify the Omniverse server name in Line 5 which will be used to find assets. A list of texture assets that will be used to randomize assets in the room is provided in texture_list. In lines 18-21, we store prim paths for assets that will be part of the randomization process.

Finally, we create multiple DR components using omni.kit.commands.execute.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Create DR texture component
result, prim = omni.kit.commands.execute(
    "CreateTextureComponentCommand",
    prim_paths=[simple_room_prim_path],
    enable_project_uvw=False,
    texture_list=texture_list,
    ignored_class_list=["floor_bottom"],
    grouped_class_list=[],
    duration=1.0,
    include_children=True,
)

For example, the above one-liner creates a DR texture component that randomizes the texture of all assets in the room except ones whose prim path contains floor_bottom. As a result, every 1 second, a random texture from texture_list will be applied to those assets.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Create DR color component
result, prim = omni.kit.commands.execute(
    "CreateColorComponentCommand",
    prim_paths=[floor_prim_path],
    first_color_range=(0.0, 0.0, 0.0),
    second_color_range=(1.0, 1.0, 1.0),
    roughness_range=(0.0, 1.0),
    metallic_range=(0.0, 1.0),
    duration=1.0,
    include_children=False,
)

The above one-liner creates a DR color component that randomizes the color, roughness and metallic property of the floor asset referred by floor_prim_path. As a result, every 1 second, the floor asset will have a random color specified within first_color_range and second_color_range along with random roughness, metallic property value specified by roughness_range and metallic_range respectively.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Create DR movement component
result, prim = omni.kit.commands.execute(
    "CreateMovementComponentCommand",
    prim_paths=[table_prim_path],
    min_range=(-50.0, -50.0, -77),
    max_range=(50.0, 50.0, -77),
    target_position=None,
    target_paths=None,
    duration=1.0,
    include_children=False,
)

The above one-liner creates a DR movement component that randomizes the location of the table asset referred by table_prim_path. As a result, every 1 second, the table asset will be randomly placed at a location specified within min_range and max_range.

1
2
3
4
5
6
7
8
9
# Create DR rotation component
result, prim = omni.kit.commands.execute(
    "CreateRotationComponentCommand",
    prim_paths=[table_prim_path],
    min_range=(0.0, 0.0, 0.0),
    max_range=(0.0, 0.0, 360.0),
    duration=1.0,
    include_children=False,
)

The above one-liner creates a DR rotation component that randomizes the orientation of the table asset referred by table_prim_path. As a result, every 1 second, the table asset will be randomly oriented by a value specified within min_range and max_range.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Create DR scale component
result, prim = omni.kit.commands.execute(
    "CreateScaleComponentCommand",
    prim_paths=[table_prim_path],
    min_range=(0.4, 0.4, 0.4),
    max_range=(1.3, 1.3, 1.3),
    uniform_scaling=True,
    duration=1.0,
    include_children=False,
)

The above one-liner creates a DR scale component that randomizes the scale of the table asset referred by table_prim_path. As a result, every 1 second, the table asset will be randomly scaled by a value specified within min_range and max_range.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Create DR light component
result, prim = omni.kit.commands.execute(
    "CreateLightComponentCommand",
    light_paths=[light_prim_path],
    first_color_range=(0.9, 0.9, 0.9),
    second_color_range=(1.0, 1.0, 1.0),
    intensity_range=(40000.0, 70000.0),
    temperature_range=(1500.0, 6500.0),
    enable_temperature=True,
    duration=1.0,
    include_children=False,
)

The above one-liner creates a DR light component that randomizes the properties of light asset referred by light_prim_path. As a result, every 1 second, the light color will be a random value specified within first_color_range and second_color_range along with random intensity, temperature property value specified by intensity_range and temperature_range respectively.

Sample Use Cases

Random movement behavior within polygon area

This example presents a movement behavior where an asset is placed randomly within a polygon area.

  1. Open the simple room environment from /Isaac/Environments/Simple_Room/simple_room.usd.

  2. Open Window->Script Editor, paste the below code and click Run to execute python code.

  3. Press Play

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import omni

# Create a cube and scale it
stage = omni.usd.get_context().get_stage()
prim = stage.DefinePrim("/Root/Cube", "Cube")
UsdGeom.XformCommonAPI(prim).SetScale((10, 10, 10))

# Specify the points that define the polygon
polygon_points = [
    (250, 90, -65),
    (0, 250, -65),
    (-200, 200, -65),
    (-200, 100, -65),
    (175, 100, -65)
]

# Create DR transform component
result, prim = omni.kit.commands.execute(
    "CreateTransformComponentCommand",
    prim_paths=["/Root/Cube"],
    translate_min_range=(0.0, 0.0, -65.0),
    translate_max_range=(0.0, 0.0, -65.0),
    polygon_points=polygon_points,
    draw_polygon=True,
    duration=0.3
)

The above code first creates a cube and scales it. Then, we specify a list of points via polygon_points that define the polygon. Finally, we create a transform component with that list of points. Currently, only 2D polygon is supported which means the X, Y coordinates of polygon_points are used to determine the X, Y coordinates of random cube position. The Z coordinate in polygon_points are ignored and instead the Z coordinate in translate_min_range and translate_max_range is used to determine the Z coordinate of random cube position.

Sequential movement behavior along a path

This example presents a sequential movement behavior along a path defined by a set of points.

  1. Open the simple room environment from /Isaac/Environments/Simple_Room/simple_room.usd.

  2. Open Window->Script Editor, paste the below code and click Run to execute python code.

  3. Press Play

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import omni
import numpy as np

# Create a camera
stage = omni.usd.get_context().get_stage()
prim = stage.DefinePrim("/Root/Camera", "Camera")

# Specify a set of target points along a circle
center_point = (0, 0, 0)
radius = 150
target_points_list = []
for theta in range(0, 360):
    th = theta * np.pi / 180
    x = radius * np.cos(th) + center_point[0]
    y = radius * np.sin(th) + center_point[1]
    target_points_list.append(Gf.Vec3f(x, y, center_point[2]))

# Specify a set of points to look at, in this case its the next point
lookat_target_points_list = [a for a in target_points_list[1:]]
lookat_target_points_list.append(target_points_list[0])

# Create DR transform component
result, prim = omni.kit.commands.execute(
    "CreateTransformComponentCommand",
    prim_paths=["/Root/Camera"],
    target_points=target_points_list,
    lookat_target_points=lookat_target_points_list,
    enable_sequential_behavior=True,
)

The above code first creates a camera. Then, we define a circular path via a list of points in target_points_list. At each target point, the asset will look at the next point as defined in lookat_target_points_list. Finally, we create a transform component with both lists. We also enable sequential behavior that allows the camera to traverse the circular path in a sequential manner i.e. move from one point to its neighboring point.

Specify distribution per attribute

This example present a way to specify distribution for each attribute.

  1. Open the simple room environment from /Isaac/Environments/Simple_Room/simple_room.usd.

  2. Open Window->Script Editor, paste the below code and click Run to execute python code.

  3. Press Play

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import omni

# Dictionary with attribute name and distribution details
attribute_dict = {
    "attribute_1": {"name": "xformOp:scale", "mean": "1.0", "stddev": "0.3", "distribution": "normal"},
    "attribute_2": {"name": "xformOp:translate", "min": "0", "max": "10", "distribution": "uniform"},
}

# Create DR attribute component
result, prim = omni.kit.commands.execute(
    "CreateAttributeComponentCommand",
    prim_paths=["/Root/table_low_327"],
    custom_data=attribute_dict,
    duration=0.5
)

The above code first defines a dictionary that contains name of attribute to be randomized and details about the distribution. In this example, we will randomize two attributes - xformOp:scale and xformOp:translate. The attribute values will follow a normal distribution with specified mean and standard deviation for xformOp:scale whereas it will follow an uniform distribution with specified minimum and maximum values for xformOp:translate. Finally, we create an attribute component that randomizes the scale and position of the table based on attribute_dict dictionary.