• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WebGL-based 3D visualizer for Python

meshcat-python: Python Bindings to the MeshCat WebGL viewer

https://github.com/rdeits/meshcat-python/workflows/CI/badge.svg?branch=master

MeshCat is a remotely-controllable 3D viewer, built on top of three.js. The viewer contains a tree of objects and transformations (i.e. a scene graph) and allows those objects and transformations to be added and manipulated with simple commands. This makes it easy to create 3D visualizations of geometries, mechanisms, and robots.

The MeshCat architecture is based on the model used by Jupyter:

  • The viewer itself runs entirely in the browser, with no external dependencies
  • The MeshCat server communicates with the viewer via WebSockets
  • Your code can use the meshcat python libraries or communicate directly with the server through its ZeroMQ socket.

Installation

The latest version of MeshCat requires Python 3.6 or above.

Using pip:

pip install meshcat

From source:

git clone https://github.com/rdeits/meshcat-python
git submodule update --init --recursive
cd meshcat-python
python setup.py install

You will need the ZeroMQ libraries installed on your system:

Ubuntu/Debian:

apt install libzmq3-dev

Homebrew:

brew install zmq

Windows:

Download the official installer from zeromq.org.

Usage

For examples of interactive usage, see demo.ipynb

Under the Hood

Starting a Server

If you want to run your own meshcat server (for example, to communicate with the viewer over ZeroMQ from another language), all you need to do is run:

meshcat-server

The server will choose an available ZeroMQ URL and print that URL over stdout. If you want to specify a URL, just do:

meshcat-server --zmq-url=<your URL>

You can also instruct the server to open a browser window with:

meshcat-server --open

Protocol

All communication with the meshcat server happens over the ZMQ socket. Some commands consist of multiple ZMQ frames.

ZMQ frames:["url"]
Action:Request URL
Response:The web URL for the server. Open this URL in your browser to see the 3D scene.

ZMQ frames:["wait"]
Action:Wait for a browser to connect
Response:"ok" when a brower has connected to the server. This is useful in scripts to block execution until geometry can actually be displayed.

ZMQ frames:["set_object", "/slash/separated/path", data]
Action:Set the object at the given path. data is a MsgPack-encoded dictionary, described below.
Response:"ok"

ZMQ frames:["set_transform", "/slash/separated/path", data]
Action:Set the transform of the object at the given path. There does not need to be any geometry at that path yet, so set_transform and set_object can happen in any order. data is a MsgPack-encoded dictionary, described below.
Response:"ok"

ZMQ frames:["delete", "/slash/separated/path", data]
Action:Delete the object at the given path. data is a MsgPack-encoded dictionary, described below.
Response:"ok"

set_object data format

{
    "type": "set_object",
    "path": "/slash/separated/path",  // the path of the object
    "object": <three.js JSON>
}

The format of the object field is exactly the built-in JSON serialization format from three.js (note that we use the JSON structure, but actually use msgpack for the encoding due to its much better performance). For examples of the JSON structure, see the three.js wiki .

Note on redundancy
The type and path fields are duplicated: they are sent once in the first two ZeroMQ frames and once inside the MsgPack-encoded data. This is intentional and makes it easier for the server to handle messages without unpacking them fully.

set_transform data format

{
    "type": "set_transform",
    "path": "/slash/separated/path",
    "matrix": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
}

The format of the matrix in a set_transform command is a column-major homogeneous transformation matrix.

delete data format

{
    "type": "delete",
    "path", "/slash/separated/path"
}

Examples

Creating a box at path /meshcat/box

{
    "type": "set_object",
    "path": "/meshcat/box",
    "object": {
        "metadata": {"type": "Object", "version": 4.5},
        "geometries": [{"depth": 0.5,
                        "height": 0.5,
                        "type": "BoxGeometry",
                        "uuid": "fbafc3d6-18f8-11e8-b16e-f8b156fe4628",
                        "width": 0.5}],
        "materials": [{"color": 16777215,
                       "reflectivity": 0.5,
                       "type": "MeshPhongMaterial",
                       "uuid": "e3c21698-18f8-11e8-b16e-f8b156fe4628"}],
        "object": {"geometry": "fbafc3d6-18f8-11e8-b16e-f8b156fe4628",
                   "material": "e3c21698-18f8-11e8-b16e-f8b156fe4628",
                   "matrix": [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0],
                   "type": "Mesh",
                   "uuid": "fbafc3d7-18f8-11e8-b16e-f8b156fe4628"}},
}

Translating that box by the vector [2, 3, 4]:

{
    "type": "set_transform",
    "path": "/meshcat/box",
    "matrix": [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 3.0, 4.0, 1.0]
}

Packing Arrays

Msgpack's default behavior is not ideal for packing large contiguous arrays (it inserts a type code before every element). For faster transfer of large pointclouds and meshes, msgpack Ext codes are available for several types of arrays. For the full list, see https://github.com/kawanet/msgpack-lite#extension-types . The meshcat Python bindings will automatically use these Ext types for numpy array inputs.

More Repositories

1

MeshCat.jl

WebGL-based 3D visualizer in Julia
Julia
232
star
2

meshcat

Remotely-controllable 3D viewer, built on top of three.js
HTML
178
star
3

iris-distro

Iterative Regional Inflation by SDP
MATLAB
119
star
4

swig-eigen-numpy

A demonstration of a SWIG wrapper for a C++ library containing Eigen matrix types for use with Python and NumPy
C
53
star
5

CommonSubexpressions.jl

NaΓ―ve combined subexpression elimination in Julia
Julia
35
star
6

cryptics

Cryptic crossword solver
HTML
35
star
7

DynamicWalking2018.jl

Julia Robotics tutorial presented at Dynamic Walking 2018
Jupyter Notebook
30
star
8

ConditionalJuMP.jl

Automatic transformation of implications and complementarity into mixed-integer models in Julia
Julia
29
star
9

AdaptiveDistanceFields.jl

Adaptively sampled distance fields in Julia
Jupyter Notebook
28
star
10

NNLS.jl

Non-Negative Least Squares and Quadratic Program solver in Julia
Julia
27
star
11

ScratchHolograms

A set of tools to make abrasion (scratch) holography easier to do by hand
Ruby
25
star
12

StrandbeestRobot.jl

Simulation of a 12-legged parallel walking mechanism in Julia, inspired by Theo Jansen's Strandbeest
Jupyter Notebook
19
star
13

DrakeVisualizer.jl

Interface to the RobotLocomotion Drake Visualizer tool from Julia
Julia
18
star
14

ConcreteInterfaces.jl

Julia
15
star
15

RigidBodyTreeInspector.jl

Simple visualization for the RigidBodyDynamics.jl library
Julia
13
star
16

DetroitTechWatch2020.jl

Jupyter Notebook
11
star
17

Flatten.jl

Flatten Julia types to tuples or vectors, and un-flatten them later
Julia
11
star
18

LoewnerJohnEllipsoids.jl

Loewner-John inner and outer ellipsoids
Julia
10
star
19

SublimeLinter-contrib-mlint

A SublimeLinter3 interface to MATLAB mlint
Python
9
star
20

Ev3dev.jl

Julia bindings for ev3dev
Jupyter Notebook
9
star
21

WPepub

Convert a wordpress blog into an epub book
Python
9
star
22

CrypticCrosswords.jl

Cryptic crossword clue solver written in Julia
Julia
8
star
23

phd-thesis-defense

Slides from my PhD thesis defense at MIT CSAIL, October 2018
Shell
8
star
24

Mayday.jl

Sums-of-Squares optimization in Julia, powered by JuMP
Julia
7
star
25

LocalScopeBenchmarks.jl

A slightly friendlier interface to BenchmarkTools.jl
Julia
6
star
26

MatlabOptimizationTools

Some helpful scripts for running optimizations in Matlab
MATLAB
6
star
27

LVIS-dev

Experimental implementation of LVIS in Julia
Shell
6
star
28

CouenneNL.jl

Julia
5
star
29

ChartParsers.jl

Basic top-down and bottom-up chart parsing for context-free grammars in Julia
Julia
5
star
30

PyLCM.jl

Julia bindings for LCM, the Lightweight Communications and Marshalling library, via PyCall
Python
5
star
31

PyAnalogInt

Analog integers in python
Python
4
star
32

quadruped-walking-exploration

MATLAB
4
star
33

LCPSim.jl

Julia
4
star
34

pydrake-julia

Use Drake from Julia by way of Python
Jupyter Notebook
4
star
35

EdgeCameras.jl

Julia implementation of Bouman et al.'s edge camera algorithm
Jupyter Notebook
4
star
36

drake-mpc

Jupyter Notebook
3
star
37

en

fork of https://www.nodebox.net/code/index.php/Linguistics
Python
3
star
38

BeatTrack

Predictive beat tracking, eventually to be used with Bemis100
Python
3
star
39

juliet

More powerful package installation for Julia
Julia
3
star
40

StateMachineIterators.jl

Iterable finite state machines in Julia
Julia
3
star
41

Collective.jl

Your enigmatological distinctiveness will be added to our own
Julia
3
star
42

CrypticServer.jl

Julia
2
star
43

StaticPolynomials.jl

Jupyter Notebook
2
star
44

Trivia.jl

OpenTDB trivia interface in Julia
Julia
2
star
45

oscilloscope-music

Decoding oscilloscope music in Julia
Jupyter Notebook
2
star
46

convex-segmentation

Find convex regions in a binary image
MATLAB
2
star
47

SpatialFields.jl

Scalar and vector fields, including Hermite Radial Basis Function fields
Jupyter Notebook
2
star
48

DygraphsOverviewMode

An overview mode for dygraphs that makes it easy to navigate through a dataset
JavaScript
2
star
49

interval-inverse-kinematics

Jupyter Notebook
2
star
50

rdeits-vim

An ongoing attempt to turn vim into a nice editing environment for myself.
Vim Script
2
star
51

julia-ev3-report

TeX
2
star
52

Identify-Polygons

Identify 2D polygons from a point cloud using a genetic algorithm
Python
2
star
53

adaptive-PIV

An FPGA implementation of Particle Image Velocimetry for 6.375 at MIT
MATLAB
2
star
54

FluxExtensions.jl

Julia
1
star
55

swigmake

Helpful swig interface files
C
1
star
56

threshold-qp

1
star
57

Puzzle-Anagrams

Anagram tools for an MIT puzzle
Python
1
star
58

julia-matlab-fortran-fem-benchmark

Julia, Matlab, and Fortan Finite Element FEM benchmark and direct comparison
Fortran
1
star
59

gaited-footstep-planner-exploration

MATLAB
1
star
60

sublime-config

Sublime Text 2 Configuration
1
star
61

6.438-formula-sheet

1
star
62

Noticer.jl

Julia
1
star
63

LearningMPC.jl

Julia
1
star
64

ImplicitSkinning.jl

Implementation of implicit surface reconstruction with HRBF by Vaillant et al.
Jupyter Notebook
1
star
65

dotfiles

My various *nix configuration files`
Vim Script
1
star
66

julia-metaprogramming

Jupyter Notebook
1
star
67

crazytags

Python
1
star
68

coasters

Cedar Point roller coaster analysis
Python
1
star
69

SCOWL-mirror

Mirror of SCOWL from https://sourceforge.net/projects/wordlist/files/SCOWL/2018.04.16/
Shell
1
star
70

MultiprecisionLP.jl

Julia
1
star
71

action-sequence

Convert a set of images into a multiple-exposure action sequence
Python
1
star
72

pypolyhedron

Mirror of PyPolyhedron by Pearu Peterson from http://cens.ioc.ee/projects/polyhedron/
C
1
star
73

juggling

MATLAB
1
star
74

rrt-explorations

Playing around with Rapidly Expanding Random Trees
1
star
75

rdeits.github.com

HTML
1
star
76

Behaviors.jl

Finite-state-machine behaviors
Julia
1
star
77

TiddlyWiki-Project-Journal

A modification of Jeremy Ruston's TiddlyWiki for my own project and research tracking.
1
star
78

iris

IRIS algorithm for finding large convex volumes of free space
MATLAB
1
star
79

icra-2019-lvis

Slides for my talk at ICRA 2019
Shell
1
star