Hello, I am a beginner in Isaac sim. My objective is to simulate objects (boxes) to be simulated in a way they end up skewed or tilted. I got started with a very basic script (given to me by my senior) where I could randomly scatter objects. A simple experiment I tried was to remove the scatter so that objects fall on one another and then end up skewed or tilted over one another. However the objects just seem to sink into one another. I tried playing around with collision parameters but it led me nowhere.
PS I need to modify this base code in order to maintain the stored values (like bbox, depth info etc). I have attached the base code.
# from isaacsim import SimulationApp
from omni.isaac.kit import SimulationApp
# Simple example showing how to start and stop the helper
simulation_app = SimulationApp({"headless": True})
import sys
#from omni.isaac.core.utils.extensions import enable_extension
#enable_extension("omni.replicator.isaac")
import omni.replicator.core as rep
import math, random
output_directory_rgb = "/media/kalyanav/Venkat/skewed_data_isaac"
BOX = "omniverse://localhost/NVIDIA/Assets/ArchVis/Industrial/Containers/Cardboard/Cardbox_A1.usd"
DESK_CLUTTER = [#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Clocks/MantelClock.usd"
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Kitchenware/DecorativeBowl.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Kitchenware/BlackandBrassBowl_Small.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Misc/Supplies/MechanicalPencil.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Entertainment/Games/NewtonsCradle.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Lighting/Table Lamps/BlackLamp.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Storage/Bottles/Plastic/NaturalBostonRound_A/NaturalBostonRoundBottle_A02_PR_NVD_01.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Storage/Bottles/Plastic/NaturalBostonRound_A/NaturalBostonRoundBottle_A02_PR_NVD_01.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Vases/Earthenware02.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Lighting/Floor Lamps/Candice.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Commercial/Seating/Anora.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Commercial/Seating/Petite_Chair.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Furniture/SofaTables/EurekaConsole.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Industrial/Railing/MetalFencing_A2.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Boxed/blue_tin.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Boxed/oil_tin.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Containers/TinCan.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Apple.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Food/Fruit/Pomegranate01.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Lighting/Table Lamps/BlackLamp.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Plants/YuccaCane.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Outdoors/Decor/Pagota.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Electronics/Speakers/Speaker_Outdoor.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Books/BookStack_01.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Books/BookStack_02.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/CandleHolders/BronzeLantern.usd",
#"omniverse://localhost/NVIDIA/Assets/ArchVis/Industrial/Containers/Wooden/WoodenCrate_A2.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/CandleHolders/WoodenCHLarge.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Clocks/AlarmClock_Retro.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Sculptures/GeoSphere_Small.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Plants/Plant_Succulent_02.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Outdoors/Planters/Fluted_Medium.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Misc/PaintRoller/PaintRoller.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Kitchen/KitchenFaucets/faucet_02.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Tchotchkes/DecorativeWoodenBowl.usd",
"omniverse://localhost/NVIDIA/Assets/ArchVis/Residential/Decor/Tchotchkes/ServingTray.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Equipment/Hand_Trucks/Gas_Cylinder_A/GasCylinderHandTruck_A02_PR_V_NVD_01.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Equipment/Hand_Trucks/Convertible_Aluminum_A/ConvertableAlumHandTruck_A01_PR_NVD_01.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Safety/Cones/Colored_Traffic/ColoredTrafficCone_A01_71cm_PR_V_NVD_01.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Shipping/Pallets/Wood/Block_C/BlockPallet_C01_PR_NVD_01.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Storage/Bins/Bin_A_Variants.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Storage/Bins/Bin_B_Variants.usd",
#"omniverse://localhost/NVIDIA/Assets/DigitalTwin/Assets/Warehouse/Facilities/Cleaning/MopBucket_A/MoppingBucket_A01_01.usd",
]
FLOOR_MATS = [ "omniverse://localhost/NVIDIA/Materials/Base/Stone/Ceramic_Tile_18/Ceramic_Tile_18_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Adobe_Octagon_Dots/Adobe_Octagon_Dots_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Adobe_Octagon_Dots/Adobe_Octagon_Dots_N.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Granite_Dark/Granite_Dark_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Granite_Light/Granite_Light_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Gravel/Gravel_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Marble/Marble_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Terracotta/Terracotta_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Stone_Wall/Stone_Wall_H.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Slate/Slate_Tile_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Stone/Fieldstone/Fieldstone_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Natural/Leaves/Leaves_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Wood/Ash_Planks/Ash_Planks_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Wood/Bamboo_Planks/Bamboo_Planks_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Wood/Birch/Birch_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Metals/Aluminum_Cast/Aluminum_Cast_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Metals/RustedMetal/RustedMetal_BaseColor.png",
"omniverse://localhost/NVIDIA/Materials/Base/Masonry/Concrete_Formed/Concrete_Formed_BaseColor.png",
]
rep.settings.carb_settings("/omni/replicator/RTSubframes", 5)
cone_height = 100
def randomize_lights():
count = random.randint(5, 10)
lights = rep.create.light(
light_type="Sphere",
color=rep.distribution.uniform((0.4, 0.4, 0.4), (0.9, 0.9, 0.9)),
intensity=rep.distribution.uniform(100, 500),
exposure=10,
position=rep.distribution.uniform((-200, -200, cone_height + 5), (200, 200, cone_height + 20)),
scale=rep.distribution.uniform(5, 10),
count=count
)
return lights.node
rep.randomizer.register(randomize_lights)
focal_length = 1.93
h_fov = 79.4
v_fov = 65.
h_scale = 2 * math.tan((h_fov / 2.) * math.pi / 180 ) * cone_height * 1.1
v_scale = 2 * math.tan((v_fov / 2.) * math.pi / 180 ) * cone_height * 1.1
# I believe x is vertical, y is horizontal
scatter_volume = rep.create.cone(as_mesh=True, position=(0, 0, 0), scale=(v_scale,h_scale,cone_height), visible=False)
h_aperture = 2 * focal_length * math.tan(h_fov * math.pi / 180 / 2)
print(h_aperture)
cam = rep.create.camera(focal_length=focal_length,
position=(0, 50, cone_height),
look_at=scatter_volume,
f_stop=2,
focus_distance=100,
horizontal_aperture=h_aperture,
name="Camera_RGB",
)
writer = rep.WriterRegistry.get("BasicWriter")
# Visualize 3dbbox https://forums.developer.nvidia.com/t/get-object-center-pose-in-camera-frame-viewport/255358/8
print("Outputting data to ", output_directory_rgb)
writer.initialize(
output_dir=output_directory_rgb,
rgb=True,
distance_to_image_plane=True,
#semantic_types=["class", "box"],
instance_segmentation=True,
instance_id_segmentation=True,
#occlusion=True,
camera_params=True,
bounding_box_3d=True,
bounding_box_2d_tight=True
)
rp = rep.create.render_product(cam, (640, 480))
writer.attach([rp])
plane_scale = 1.5
floor = rep.create.plane(
position=(0, 0, 0),
scale=(1000, 1000, 1),
)
walls = rep.create.cube(
position=(0, 0, 200),
scale=(500, 500, 500)
)
scatter_plane = rep.create.disk(
position=(0, 0, 0),
scale=(h_scale, h_scale, 1),
visible=False
)
with floor:
rep.physics.collider()
with rep.trigger.on_time(interval=0.1, num=10):
rep.randomizer.randomize_lights()
# Randomize the floor texture
with floor:
rep.randomizer.texture(textures=FLOOR_MATS,
texture_scale=rep.distribution.uniform((8, 8), (12, 12)),
texture_rotate=rep.distribution.uniform(-45, 45))
boxes = rep.randomizer.instantiate([BOX], size=rep.distribution.uniform(2,3), mode='scene_instance')
# Randomize the wall texture
with walls:
rep.randomizer.texture(textures=FLOOR_MATS,
texture_scale=rep.distribution.uniform((8, 8), (12, 12)),
texture_rotate=rep.distribution.uniform(-45, 45))
# Put the Camera in a random spot around the room
with cam:
rep.modify.pose_orbit(
barycentre=(0,0,0),
distance=rep.distribution.uniform(100, 200),
azimuth=rep.distribution.uniform(-180, 180),
elevation=rep.distribution.uniform(30, 180),
)
# Change the size and location of boxes
#TODO: Uncomment the below original code
with boxes:
# Base box size 27.4x20.27x19.9 inches
rep.modify.pose(
scale=rep.distribution.uniform((0.4, 0.4, 0.4), (1.1, 1.1, 1.1)),#(0.6022, 1.036, 0.7663)medium#(0.5292, 0.9127, 0.3266)amazon#(0.4744, 0.6413, 0.6784)erica#(0.6076, 0.5469, 0.5589)small box,#(0.4903,0.8773,0.4234)nothing,
)
rep.modify.pose(
rotation_y=rep.distribution.choice([0, 90]),
rotation_z=rep.distribution.uniform(-180, 180)
)
rep.randomizer.scatter_2d(
surface_prims=scatter_plane,
check_for_collisions=True,
offset=5
)
rep.physics.mass(10000)
rep.physics.rigid_body(velocity=(-0, 0, -100), angular_velocity=(0,0,0))
rep.modify.semantics([("class", "box")])
# Spawn and move around distractors
distractors = rep.randomizer.instantiate(DESK_CLUTTER,
size=rep.distribution.uniform(4,5),
mode='scene_instance')
with distractors:
rep.modify.semantics([("class", "distractor")])
rep.physics.collider()
rep.modify.pose(
rotation=rep.distribution.uniform((0, 0, 0), (0, 0, 360)),
#scale=rep.distribution.uniform((0.9, 0.9, 0.9), (1.1, 1.1, 1.1))
)
rep.randomizer.scatter_2d(
surface_prims=scatter_plane,
check_for_collisions=True,
no_coll_prims=boxes
)
rep.orchestrator.run_until_complete()