-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathtower.py
More file actions
88 lines (77 loc) · 2.85 KB
/
tower.py
File metadata and controls
88 lines (77 loc) · 2.85 KB
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
87
88
import argparse
import os
import genesis as gs
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--object", type=str, default="cylinder", choices=("sphere", "cylinder", "duck"))
parser.add_argument("-v", "--vis", action="store_true", default=False)
args = parser.parse_args()
object_type = args.object
horizon = 20 if "PYTEST_VERSION" in os.environ else 600
gs.init(backend=gs.cpu, precision="32", performance_mode=True)
scene = gs.Scene(
sim_options=gs.options.SimOptions(
dt=0.02,
substeps=6,
),
rigid_options=gs.options.RigidOptions(
max_collision_pairs=200,
),
viewer_options=gs.options.ViewerOptions(
camera_pos=(20, -20, 20),
camera_lookat=(0.0, 0.0, 5.0),
),
show_viewer=args.vis,
)
scene.add_entity(gs.morphs.Plane())
# create pyramid of boxes
box_width, box_length, box_height = 0.25, 2.0, 0.1
num_stacks = 50
for i in range(num_stacks):
if i % 2 == 0: # horizontal stack
box_size = (box_width, box_length, box_height)
box_pos_0 = (-0.4 * box_length, 0, i * (box_height - 1e-3) + 0.5 * box_height)
box_pos_1 = (+0.4 * box_length, 0, i * (box_height - 1e-3) + 0.5 * box_height)
else: # vertical stack
box_size = (box_length, box_width, box_height)
box_pos_0 = (0, -0.4 * box_length, i * (box_height - 1e-3) + 0.5 * box_height)
box_pos_1 = (0, +0.4 * box_length, i * (box_height - 1e-3) + 0.5 * box_height)
for box_pos in (box_pos_0, box_pos_1):
scene.add_entity(
gs.morphs.Box(
size=box_size,
pos=box_pos,
),
)
# Drop a huge mesh
if object_type == "duck":
duck_scale = 0.8
scene.add_entity(
morph=gs.morphs.Mesh(
file="meshes/duck.obj",
scale=duck_scale,
pos=(0, -0.1, num_stacks * box_height + 10 * duck_scale),
),
)
elif object_type == "sphere":
sphere_radius = 2.0
scene.add_entity(
morph=gs.morphs.Sphere(
radius=sphere_radius,
pos=(0.0, 0.0, num_stacks * box_height + 5 * sphere_radius),
),
)
elif object_type == "cylinder":
cylinder_radius, cylinder_height = 2.0, 1.0
scene.add_entity(
morph=gs.morphs.Cylinder(
radius=cylinder_radius,
height=cylinder_height,
pos=(0.0, 0.0, num_stacks * box_height + 5 * cylinder_height),
),
)
scene.build()
for i in range(horizon):
scene.step()
if __name__ == "__main__":
main()