Download chess-sim/code/sim/view_scene.py from Machanize/playful: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/Machanize/playful/resolve/main/chess-sim/code/sim/view_scene.py
- Command line
-
hf download hf://datasets/Machanize/playful/chess-sim/code/sim/view_scene.py
-
curl -L -o view_scene.py https://huggingface.co/datasets/Machanize/playful/resolve/main/chess-sim/code/sim/view_scene.py
1.23 kB
| """Open the chess scene in the interactive MuJoCo viewer, arm at home, window brought to front. | |
| Run with plain python (mjpython crashes the blocking viewer on macOS): | |
| .venv/bin/python sim/view_scene.py | |
| """ | |
| from __future__ import annotations | |
| import subprocess | |
| import sys | |
| import threading | |
| import time | |
| from pathlib import Path | |
| import mujoco | |
| import mujoco.viewer | |
| HERE = Path(__file__).resolve().parent | |
| def bring_to_front(): | |
| time.sleep(2.5) | |
| if sys.platform == "darwin": | |
| subprocess.run(["osascript", "-e", 'tell application "System Events" to set frontmost of first process whose name is "Python" to true'], | |
| capture_output=True) | |
| def main(): | |
| m = mujoco.MjModel.from_xml_path(str(HERE / "chess_scene.xml")) | |
| d = mujoco.MjData(m) | |
| mujoco.mj_resetDataKeyframe(m, d, m.key("home").id) | |
| print(f"scene loaded: {m.nbody} bodies, {m.ncam} cameras. Opening viewer window titled 'MuJoCo'...", flush=True) | |
| print("If you don't see it, check Mission Control (F3) or the Dock for a Python icon.", flush=True) | |
| threading.Thread(target=bring_to_front, daemon=True).start() | |
| mujoco.viewer.launch(m, d) | |
| print("viewer closed", flush=True) | |
| if __name__ == "__main__": | |
| main() | |