I don't understand how to apply gravity to objects in replicator yaml language

I’m new to the code and not familiar with it. Did I add gravity Settings correctly in the yaml file or did I miss some steps? The data set object generated after I added it with reference to some materials is still floating.The reference function path is D:\Omniverse\library\isaac_sim-2023.1.1\extscache\ omni.replicater.core-1.10.20 +105.1.wx64.r.cp310\omni\replicato r\core\scripts\physics.py
Do you have relevant case reference?
In addition,I ran the script headlessly. The yaml file I wrote is as follows:
stage_unit_setting:
settings.set_stage_meters_per_unit:
meters_per_unit: 1

IsaacSim default is “Z”", Code is “Y”

stage_up_axis_setting:
settings.set_stage_up_axis:
up_axis: “Z”

_setup_physics_scene:
physics._setup_physics_scene:
gravity_magnitude: 9.807
timesteps_per_second: 240

gravity_obj:
physics.collider:
input_prims: shapes

set v,a
obj_v_and_a:
physics.rigid_body:
velocity: [1, 1, 1]
angular_velocity: [1, 1, 1]
input_prims: shapes

time:
modify.timeline:
value: 3
modify_type: “time”

This YAML script example demonstrates:

Moving a group of objects to varied positions using a distribution

Create the camera and render product

camera:
create.camera:
position: [5, -1, 4]
rotation: [0, -30, -27]

render_product:
create.render_product:
camera: camera
resolution: [1024, 1024]

Create the objects in the scene

light:
create.light:
light_type: “distant”

torus:
create.torus:
semantics: [[“class”, “torus”]]
position: [1, 0, -2]

sphere:
create.sphere:
semantics: [[“class”, “sphere”]]
position: [1, 0, 1]

cube:
create.cube:
semantics: [[“class”, “cube”]]
position: [1, 1, -2]

plane:
create.plane:
semantics: [[“class”, “plane”]]
visible: true
scale: 10

group:
create.group:
items: [torus, sphere, cube]

Create a group of objects with these semantic labels

shapes:
get.prims:
semantics: [[‘class’, ‘cube’], [‘class’, ‘sphere’], [‘class’, ‘tours’]]

Create the writer and initialize

writer:
writers.get:
name: “BasicWriter”
init_params:
output_dir: “D:/Omniverse/datatry/_output_yaml/TutorialBasicFunctionality/”
rgb: True
normals: True
distance_to_camera: True
instance_segmentation: False
bounding_box_2d_tight: True

writer_attach:
writer.attach:
render_products: render_product

Set the trigger as on_frame

trigger:
trigger.on_frame:
max_execs: 7
rt_subframes: 30

When the trigger executes, modify the poses of the group

with_trigger:
with.trigger:
with.group:
modify.pose:
position:
distribution.uniform:
lower: [-1, -1, -1]
upper: [2, 2, 2]
scale:
distribution.uniform:
lower: 0.1
upper: 2

Thank you very much!

Hi @1208054946 , all the prims needs to be a physics object. You can do something like this:

with.torus:
    physics.collider: null
    physics.rigid_body: null
1 Like

Hello, I have modified the yaml file according to your suggestion but still failed. My purpose is to let the objects in the scene fall to the ground by gravity after randomizing the size, quantity and material. Finally, I use the camera to capture the picture of the fallen scene. Could you please give me a yaml code demonstration? Thank you very much.

Can you attach your complete yaml, including the part where you use a writer to save the result? And also make sure to click Replicator -> Run in the menu bar after you finish parsing the yaml.

Here is a full example of a YAML with physics, randomizing fruits that drop into a crate. The size and position of the fruits are randomized.

# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: BSD-3-Clause
# Fruit Drop YAML

# IsaacSim default is 1, Omniverse Code is 0.01
stage_unit_setting:
  settings.set_stage_meters_per_unit:
    meters_per_unit: 0.01

# IsaacSim default is "Z"", Omniverse Code is "Y"
stage_up_axis_setting:
  settings.set_stage_up_axis:
    up_axis: "Z"

# Randomization setup
# Instantiate 300 of each object in random positions, rotations, and scale
register_create_props:
  randomizer.register:
    create_props:
      fruits:
        randomizer.instantiate:
          size: 1
          paths:
            distribution.choice:
              num_samples: 300
              choices:
                distribution.sequence:
                  items:
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Apple.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Avocado01.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Kiwi01.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Lime01.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Lychee01.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Pomegranate01.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Vegetables/RedOnion.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Berries/strawberry.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Tchotchkes/Lemon_01.usd'
                    - 'omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Tchotchkes/Orange_01.usd'
      with.fruits:
        modify.pose:
          position:
            distribution.uniform:
              lower: [-8, 5,100]
              upper: [8, 30, 300]
          rotation:
            distribution.uniform:
              lower: [-180, -180, -180]
              upper: [180, 180, 180]
          scale:
            distribution.normal:
              mean: 1.0
              std: 0.25
        physics.rigid_body: null # if you don't want any initial speed to the obj

table:
  create.from_usd:
    usd: "omniverse://localhost/NVIDIA/Assets/Scenes/Templates/Basic/display_riser.usd"

table_physics:
  with.table:
    physics.collider: null
    modify.pose:
      rotation: [90, 0, 0]

crate:
  create.from_usd:
    usd: "omniverse://localhost/NVIDIA/Samples/Marbles/assets/standalone/SM_room_crate_3/SM_room_crate_3.usd"

crate_physics:
  with.crate:
    physics.collider: 
      approximation_shape: "none"
    physics.mass:
      mass: 10000

crate_pose:
  with.crate:
    modify.pose:
      position: [0, 0, 20.5]
      rotation: [0, -90, 0]
      scale: [1, 3, 2]

# Create the camera and render product
camera:
  create.camera:
    position: [120, 160, 200]
    look_at: [0, 0, 0]

render_product:
  create.render_product:
    camera: camera
    resolution: [640, 480]

# Create the writer and initialize
writer:
  writers.get:
    name: "BasicWriter"
    init_params:
      output_dir: "Fruit_Drop_Yaml"
      rgb: True

on_time_trigger:
  trigger.on_time:
    interval: 3
    max_execs: 11 # change this to your desired number
    reset_physics: True

on_frame_trigger:
  trigger.on_frame:
    interval: 89
    max_execs: 11

writer_attach:
  writer.attach:
    render_products: render_product
    trigger: on_frame_trigger

with_trigger:
  with.on_time_trigger:
    randomizer.create_props: null

Note, that there are 2 triggers in this example.

The first trigger with on_time is the one that activates physics and randomizes the fruits every 3 seconds (interval: 3).

The second trigger with on_frame triggers a render every 89 frames (3 seconds * 30 frames-per-second = 90) which should mean the fruits have dropped and mostly settled in the crate. The writer is attached only to this trigger. If you wish to render every frame of the physics simulation you would remove this on_frame trigger.

Example image:
rgb_0_0001

1 Like