Repository navigation
Expand file tree
/
Copy pathrender_models.py
More file actions
61 lines (54 loc) · 1.97 KB
/
Copy pathrender_models.py
File metadata and controls
61 lines (54 loc) · 1.97 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
"""Render the pinned MuJoCo models used in the experiment for the HTML report."""
import argparse
from pathlib import Path
import mujoco
from PIL import Image
MODEL_FOLDERS = {
"pendulum": "pendulum",
"cart_pole": "cart_pole",
"double_cart_pole": "double_cart_pole",
"push_t": "pusht",
"walker": "walker",
"crane": "crane",
"humanoid": "g1",
}
def render(directory, resolve):
directory.mkdir(parents=True, exist_ok=True)
for name in MODEL_FOLDERS:
model = mujoco.MjModel.from_xml_path(str(resolve(name)))
data = mujoco.MjData(model)
mujoco.mj_forward(model, data)
if name == "push_t":
data.qpos[:3] = [0.045, -0.035, 0.62]
elif name == "double_cart_pole":
data.qpos[1:] = [-0.55, 1.6]
elif name in ("pendulum", "cart_pole"):
data.qpos[-1] = 0.52
elif name == "walker":
data.qpos[3:9] = [0.4, -0.43, -0.08, -0.32, -0.18, 0.12]
mujoco.mj_forward(model, data)
camera = mujoco.MjvCamera()
mujoco.mjv_defaultFreeCamera(model, camera)
if name == "push_t":
camera.distance = 0.32
camera.elevation = -70
camera.lookat[:] = [0.02, 0.02, 0.0]
if name == "double_cart_pole":
camera.distance *= 0.58
camera.lookat[2] = 1.35
if name == "walker":
camera.lookat[0] = 0.0
camera.distance *= 0.78
with mujoco.Renderer(model, height=250, width=360) as renderer:
renderer.update_scene(data, camera=camera)
img = Image.fromarray(renderer.render())
img.save(directory / f"{name}.jpg", quality=88, optimize=True)
if __name__ == "__main__":
from assets import model_path
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--out",
type=Path,
default=Path(__file__).resolve().parent / "results" / "models",
)
render(parser.parse_args().out, model_path)