forked from LitchiCheng/mujoco-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmujoco_viewer.py
More file actions
40 lines (31 loc) · 1016 Bytes
/
mujoco_viewer.py
File metadata and controls
40 lines (31 loc) · 1016 Bytes
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
import mujoco
import mujoco.viewer
class CustomViewer:
def __init__(self, model_path, distance=3, azimuth=0, elevation=-30):
self.model = mujoco.MjModel.from_xml_path(model_path)
self.data = mujoco.MjData(self.model)
self.handle = mujoco.viewer.launch_passive(self.model, self.data)
self.handle.cam.distance = distance
self.handle.cam.azimuth = azimuth
self.handle.cam.elevation = elevation
def is_running(self):
return self.handle.is_running()
def sync(self):
self.handle.sync()
@property
def cam(self):
return self.handle.cam
@property
def viewport(self):
return self.handle.viewport
def run_loop(self):
self.runBefore()
while self.is_running():
mujoco.mj_forward(self.model, self.data)
self.runFunc()
mujoco.mj_step(self.model, self.data)
self.sync()
def runBefore(self):
pass
def runFunc(self):
pass