MeshCat

0.3.2 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

Initializes a MeshCat visualizer, opens it in a web browser, and displays a red box and a blue sphere. The example demonstrates setting objects at the root and at a sub-path, and applying transformations.

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.")

view raw JSON →