MeshCat
MeshCat is a remotely-controllable WebGL-based 3D visualizer for Python, built on top of three.js. It allows users to create 3D visualizations of geometries, mechanisms, and robots with a scene graph approach, communicating with a browser-based viewer via WebSockets. The current version is 0.3.2.
Warnings
- deprecated The `zmq.eventloop.ioloop` module used internally by older `meshcat` versions is deprecated in `pyzmq` 17+. While `meshcat` typically handles this gracefully, direct usage or older environments might show warnings.
- gotcha MeshCat has known limitations with DAE (Collada) files, particularly regarding scaling and display. They may not appear or scale correctly in the viewer.
- gotcha When integrating with simulation environments (e.g., Drake), the default visualization update frequency of MeshCat might cause initial conditions or very fast state changes to be visually missed or incorrectly displayed. The visualization might lag behind the simulation's true initial state.
- gotcha Converting MeshCat animations to video files requires `ffmpeg` to be installed on your system. If `ffmpeg` is not found, the video conversion functions will fail silently or with an error about `ffmpeg` not being callable.
Install
-
pip install meshcat
Imports
- Visualizer
import meshcat vis = meshcat.Visualizer()
- geometry
import meshcat.geometry as g
- transformations
import meshcat.transformations as tf
Quickstart
import meshcat
import meshcat.geometry as g
import meshcat.transformations as tf
# Create a new visualizer. This will launch a local server
# and typically open a browser window with the visualization.
vis = meshcat.Visualizer().open()
# You can also get the URL to open it manually:
# print(f"MeshCat URL: {vis.url()}")
# Set a red box at the root of the scene
vis.set_object(g.Box([0.2, 0.2, 0.2]), g.MeshPhongMaterial(color=0xff0000))
# Move the box slightly along the x-axis
vis.set_transform(tf.translation_matrix([0.5, 0, 0]))
# Add a blue sphere at a sub-path within the scene tree
vis["sphere"].set_object(g.Sphere(0.1), g.MeshPhongMaterial(color=0x0000ff))
vis["sphere"].set_transform(tf.translation_matrix([0, 0.5, 0]))
print("Visualization created. Check your browser window or the URL printed above.")