1- import numpy as np
2- import genesis as gs
31import argparse
42
3+ import genesis as gs
4+
55
66def main ():
77 parser = argparse .ArgumentParser ()
8- parser .add_argument (
9- "--object" ,
10- type = str ,
11- default = "cylinder" ,
12- choices = ["sphere" , "cylinder" , "duck" ],
13- )
8+ parser .add_argument ("--object" , type = str , default = "cylinder" , choices = ("sphere" , "cylinder" , "duck" ))
149 parser .add_argument ("-v" , "--vis" , action = "store_true" , default = False )
1510 args = parser .parse_args ()
1611 object_type = args .object
@@ -22,46 +17,37 @@ def main():
2217 dt = 0.005 ,
2318 ),
2419 rigid_options = gs .options .RigidOptions (
25- box_box_detection = False ,
26- max_collision_pairs = 2000 ,
27- use_gjk_collision = True ,
28- enable_mujoco_compatibility = False ,
20+ max_collision_pairs = 200 ,
2921 ),
3022 viewer_options = gs .options .ViewerOptions (
3123 camera_pos = (20 , - 20 , 20 ),
3224 camera_lookat = (0.0 , 0.0 , 5.0 ),
33- camera_fov = 30 ,
3425 max_FPS = 60 ,
3526 ),
3627 show_viewer = args .vis ,
3728 )
3829
39- plane = scene .add_entity (gs .morphs .Plane (pos = ( 0 , 0 , 0 ) ))
30+ plane = scene .add_entity (gs .morphs .Plane ())
4031
4132 # create pyramid of boxes
42- box_width = 0.25
43- box_length = 2.0
44- box_height = 0.1
33+ box_width , box_length , box_height = 0.25 , 2.0 , 0.1
4534 num_stacks = 50
46- height_offset = 0.0
4735 for i in range (num_stacks ):
48- horizontal = i % 2 == 0
49-
50- if horizontal :
51- box_size = np .array ([box_width , box_length , box_height ])
52- box_pos_0 = (- 0.4 * box_length , 0 , i * (height_offset + box_size [2 ]) + 0.5 * box_size [2 ])
53- box_pos_1 = (+ 0.4 * box_length , 0 , i * (height_offset + box_size [2 ]) + 0.5 * box_size [2 ])
54- else :
55- box_size = np .array ([box_length , box_width , box_height ])
56- box_pos_0 = (0 , - 0.4 * box_length , i * (height_offset + box_size [2 ]) + 0.5 * box_size [2 ])
57- box_pos_1 = (0 , + 0.4 * box_length , i * (height_offset + box_size [2 ]) + 0.5 * box_size [2 ])
58-
59- scene .add_entity (
60- gs .morphs .Box (size = box_size , pos = box_pos_0 ),
61- )
62- scene .add_entity (
63- gs .morphs .Box (size = box_size , pos = box_pos_1 ),
64- )
36+ if i % 2 == 0 : # horizontal stack
37+ box_size = (box_width , box_length , box_height )
38+ box_pos_0 = (- 0.4 * box_length , 0 , i * (box_height - 1e-3 ) + 0.5 * box_height )
39+ box_pos_1 = (+ 0.4 * box_length , 0 , i * (box_height - 1e-3 ) + 0.5 * box_height )
40+ else : # vertical stack
41+ box_size = (box_length , box_width , box_height )
42+ box_pos_0 = (0 , - 0.4 * box_length , i * (box_height - 1e-3 ) + 0.5 * box_height )
43+ box_pos_1 = (0 , + 0.4 * box_length , i * (box_height - 1e-3 ) + 0.5 * box_height )
44+ for box_pos in (box_pos_0 , box_pos_1 ):
45+ scene .add_entity (
46+ gs .morphs .Box (
47+ size = box_size ,
48+ pos = box_pos ,
49+ ),
50+ )
6551
6652 # Drop a huge mesh
6753 if object_type == "duck" :
@@ -70,29 +56,29 @@ def main():
7056 morph = gs .morphs .Mesh (
7157 file = "meshes/duck.obj" ,
7258 scale = duck_scale ,
73- pos = (0 , 0 , num_stacks * ( height_offset + box_height ) + 10 * duck_scale ),
59+ pos = (0 , 0 , num_stacks * box_height + 10 * duck_scale ),
7460 ),
7561 )
7662 elif object_type == "sphere" :
7763 sphere_radius = 2.0
7864 scene .add_entity (
7965 morph = gs .morphs .Sphere (
80- radius = sphere_radius , pos = (0.0 , 0.0 , num_stacks * (height_offset + box_height ) + 5 * sphere_radius )
66+ radius = sphere_radius ,
67+ pos = (0.0 , 0.0 , num_stacks * box_height + 5 * sphere_radius ),
8168 ),
8269 )
8370 elif object_type == "cylinder" :
84- cylinder_radius = 2.0
85- cylinder_height = 1.0
71+ cylinder_radius , cylinder_height = 2.0 , 1.0
8672 scene .add_entity (
8773 morph = gs .morphs .Cylinder (
8874 radius = cylinder_radius ,
8975 height = cylinder_height ,
90- pos = (0.0 , 0.0 , num_stacks * ( height_offset + box_height ) + 5 * cylinder_height ),
76+ pos = (0.0 , 0.0 , num_stacks * box_height + 5 * cylinder_height ),
9177 ),
9278 )
9379
9480 scene .build ()
95- for i in range (500 ):
81+ for i in range (600 ):
9682 scene .step ()
9783
9884
0 commit comments