-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathmouse_interaction.py
More file actions
76 lines (63 loc) · 1.99 KB
/
mouse_interaction.py
File metadata and controls
76 lines (63 loc) · 1.99 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
import argparse
import math
import os
import genesis as gs
import genesis.vis.keybindings as kb
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Mouse interaction viewer plugin example.")
parser.add_argument(
"--use_force", "-f", action="store_true", help="Apply spring forces instead of setting position"
)
parser.add_argument("--num_envs", "-b", type=int, default=1, help="Number of environments to create")
args = parser.parse_args()
gs.init(backend=gs.cpu)
scene = gs.Scene(
viewer_options=gs.options.ViewerOptions(
camera_pos=(3.5, 0.0, 2.5),
camera_lookat=(0.0, 0.0, 0.5),
camera_fov=40,
),
profiling_options=gs.options.ProfilingOptions(
show_FPS=False,
),
show_viewer=True,
)
scene.add_entity(gs.morphs.Plane())
sphere = scene.add_entity(
morph=gs.morphs.Sphere(
pos=(-0.3, -0.3, 0),
radius=0.1,
),
)
for i in range(6):
angle = i * (2 * math.pi / 6)
radius = 0.5 + i * 0.1
cube = scene.add_entity(
morph=gs.morphs.Box(
pos=(radius * math.cos(angle), radius * math.sin(angle), 0.1 + i * 0.1),
size=(0.2, 0.2, 0.2),
),
)
scene.viewer.add_plugin(
gs.vis.viewer_plugins.MouseInteractionPlugin(
use_force=args.use_force,
color=(0.1, 0.6, 0.8, 0.6),
)
)
scene.build(n_envs=args.num_envs)
is_running = True
def stop():
global is_running
is_running = False
scene.viewer.register_keybinds(
kb.Keybind("quit", kb.Key.ESCAPE, kb.KeyAction.RELEASE, callback=stop),
)
try:
while is_running:
scene.step()
if "PYTEST_VERSION" in os.environ:
break
except KeyboardInterrupt:
gs.logger.info("Simulation interrupted, exiting.")
finally:
gs.logger.info("Simulation finished.")