-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplay.py
78 lines (56 loc) · 2.04 KB
/
replay.py
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
import mujoco as mj
import mujoco.viewer as viewer
import utils
from move import Movement
def load_model(file_path: str) -> tuple[mj.MjModel, mj.MjData]:
""" Loads the .xml model into mj.MjModel and mj.MjData structs """
m = mj.MjModel.from_xml_path(file_path)
d = mj.MjData(m)
return m, d
def simulate_move(m: mj.MjModel, d: mj.MjData, move: Movement, view: viewer.Handle = None,
debug: bool = False) -> None:
# disables ALL contact forces
# m.opt.disableflags |= 1
while move.step(m, d):
if view and view.is_running():
view.sync()
time.sleep(model.opt.timestep)
if debug:
utils.debug_capture(model, data)
# re-enables contact forces for future (physics) simulations
# m.opt.disableflags -= 1
if __name__ == '__main__':
import time
data_files = [
'data/ACCAD/Female1Running_c3d/C5 - walk to run_poses.npz',
'data/ACCAD/Female1Walking_c3d/B18 - walk to leap to walk_poses.npz',
'data/ACCAD/Female1Gestures_c3d/D6- CartWheel_poses.npz',
'data/ACCAD/Male2MartialArtsKicks_c3d/G19- reverse spin cresent left t2_poses.npz',
]
model, data = load_model('assets/humanoid.xml')
move = Movement(data_files[0], model)
# move = Movement(data_files[1], model, end=360)
# move = Movement(data_files[2], model, end=270, offset=[0., 0., 0.1])
model.opt.timestep = move.timestep
try:
view = viewer.launch_passive(model, data)
debug = False
time.sleep(1)
except RuntimeError:
view = None
debug = True
move.set_movement(model, data)
move.curr += 1
simulate_move(model, data, move, view, debug)
start = time.time()
while time.time() - start < 2.0:
mj.mj_step(model, data)
if view and view.is_running():
view.sync()
time.sleep(model.opt.timestep)
if debug:
utils.debug_capture(model, data)
if view and view.is_running():
view.close()
if debug:
utils.debug_plot()