Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Drei | 4,902 | 81 | a day ago | 469 | September 25, 2022 | 203 | mit | JavaScript | ||
🥉 useful helpers for react-three-fiber | ||||||||||
Three Mesh Bvh | 1,662 | 8 | 7 | 4 days ago | 36 | June 20, 2022 | 65 | mit | JavaScript | |
A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes. | ||||||||||
3dtilesrendererjs | 973 | 3 months ago | 30 | July 02, 2022 | 33 | apache-2.0 | JavaScript | |||
Renderer for 3D Tiles in Javascript using three.js | ||||||||||
Three Gpu Pathtracer | 904 | 4 days ago | 5 | July 16, 2022 | 101 | mit | JavaScript | |||
Path tracing renderer and utilities for three.js built on top of three-mesh-bvh. | ||||||||||
Three Geo | 797 | 4 days ago | 16 | June 18, 2022 | 26 | mit | JavaScript | |||
3D geographic visualization library | ||||||||||
Web Ifc Viewer | 756 | 22 days ago | 172 | July 05, 2022 | 29 | mit | JavaScript | |||
Graphics engine and toolkit for client applications. | ||||||||||
Threejs Ballooning | 514 | 4 years ago | mit | JavaScript | ||||||
Buffer geometry merging, procedural terrains and shadow mapper research with Three.js | ||||||||||
Threejs Sandbox | 499 | 15 days ago | 7 | mit | Roff | |||||
Set of experiments and extensions to THREE.js. | ||||||||||
Three Projected Material | 492 | 8 days ago | 12 | May 18, 2022 | 1 | mit | JavaScript | |||
📽 Three.js Material which lets you do Texture Projection on a 3d Model | ||||||||||
Geo Three | 427 | 3 | a month ago | 19 | September 08, 2022 | 21 | mit | TypeScript | ||
Tile based geographic world map visualization library for threejs |
MeshCat is a remotely-controllable 3D viewer, built on top of three.js. The MeshCat viewer runs in a browser and listens for geometry commands over WebSockets. This makes it easy to create a tree of objects and transformations by sending the appropriate commands over the websocket.
The MeshCat viewer is meant to be combined with an interface in the language of your choice. Current interfaces are:
MeshCat can be used programmatically from JS or over a WebSocket connection.
To create a new MeshCat viewer, use the Viewer
constructor:
let viewer = new MeshCat.Viewer(dom_element);
where dom_element
is the div
in which the viewer should live. The primary interface to the viewer is the handle_command
function, which maps directly to the behaviors available over the WebSocket.
Viewer.handle_command(cmd)
cmd
should be a JS object with at least the field type
. Available command types are:
set_object
delete
command first (see below).
Internally, we append a final path segment, <object>
, to the provided path before creating the object. This is done because clients may disagree about what the "intrinsic" transform of a particular geometry is (for example, is a "Box" centered on the origin, or does it have one corner at the origin?). Clients can use the matrix
field of the JSON object to store that intrinsic transform, and that matrix will be preserved by attaching it to the <object>
path. Generally, you shouldn't need to worry about this: if you set an object at the path /meshcat/foo
, then you can set the transform at /meshcat/foo
and everything will just work.
Additional fields:
path
"/"
-separated string indicating the object's path in the scene tree. An object at path "/foo/bar"
is a child of an object at path "/foo"
, so setting the transform of (or deleting) "/foo"
will also affect its children.
object
toJSON()
method of a Three.js Object3D.
{ type: "set_object", path: "/meshcat/boxes/box1", object: { metadata: {version: 4.5, type: "Object"}, geometries: [ { uuid: "cef79e52-526d-4263-b595-04fa2705974e", type: "BoxGeometry", width: 1, height: 1, depth:1 } ], materials: [ { uuid: "0767ae32-eb34-450c-b65f-3ae57a1102c3", type: "MeshLambertMaterial", color: 16777215, emissive: 0, side: 2, depthFunc: 3, depthTest: true, depthWrite: true } ], object: { uuid: "00c2baef-9600-4c6b-b88d-7e82c40e004f", type: "Mesh", geometry: "cef79e52-526d-4263-b595-04fa2705974e", material: "0767ae32-eb34-450c-b65f-3ae57a1102c3" } } }Note the somewhat indirect way in which geometries and materials are specified. Each Three.js serialized object has a list of geometries and a list of materials, each with a UUID. The actual geometry and material for a given object are simply references to those existing UUIDs. This enables easy re-use of geometries between objects in Three.js, although we don't really rely on that in MeshCat. Some information about the JSON object format can be found on the Three.js wiki.
set_transform
"/foo"
will move the objects at "/foo/box1"
and "/foo/robots/HAL9000"
.
Additional fields:
path
"/"
-separated string indicating the object's path in the scene tree. An object at path "/foo/bar"
is a child of an object at path "/foo"
, so setting the transform of (or deleting) "/foo"
will also affect its children.
matrix
Float32Array
in column-major order.
{ type: "set_transform", path: "/meshcat/boxes", matrix: new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5, 0.0, 0.5, 1]) }
delete
Additional fields:
path
"/"
-separated string indicating the object's path in the scene tree. An object at path "/foo/bar"
is a child of an object at path "/foo"
, so setting the transform of (or deleting) "/foo"
will also affect its children.
{ type: "delete", path: "/meshcat/boxes" }
set_property
Note: as we append an extra path element with the name <object>
to every item created with set_object
, if you want to modify a property of the object itself, rather than the group containing it, you should ensure that your path is of the form /meshcat/foo/<object>
Additional fields:
property
value
{ type: "set_property", path: "/Cameras/default/rotated/<object>", property: "zoom", value: 2.0 }Example 2:
{ type: "set_property", path: "/Lights/DirectionalLight/<object>", property: "intensity", value: 1.0 }
set_animation
Additional fields:
animations
path
set_property
above, you will need to append <object>
to the path to set an object's intrinsic property.
clip
AnimationClip
in JSON form. The clip in turn has the following fields:
fps
name
tracks
name
field, with a single "."
before that property name to signify that it applies to exactly the object given by the path
above.
Each track has the following fields:
name
"."
(e.g. ".position"
)
type
"vector3"
for the position
property)
keys
time
(in frames) and value
indicating the value of the animated property at that time.
options
play
repetitions
{ type: "set_animation", animations: [{ path: "/Cameras/default", clip: { fps: 30, name: "default", tracks: [{ name: ".position" type: "vector3", keys: [{ time: 0, value: [0, 1, .3] },{ time: 80, value: [0, 1, 2] }], }] } },{ path: "/meshcat/boxes", clip: { fps: 30, name: "default", tracks: [{ name: ".position" type: "vector3", keys: [{ time: 0, value: [0, 1, 0] },{ time: 80, value: [0, -1, 0] }], }] } }], options: { play: true, repetitions: 1 } }
set_target
Example:
{ "type": "set_target", value: [0., 1., 0.] }This sets the camera target to `(0, 1, 0)`
capture_image
{ "type": "capture_image", "xres": 1920, "yres": 1080 }This sets the camera target to `(0, 1, 0)`
Viewer.connect(url)
msgpack.decode()
from msgpack-javascript and the resulting object will be passed directly to Viewer.handle_command()
as documented above.
Note that we do support the MsgPack extension types listed in msgpack-javascript#extension-types, with additional support for the Float32Array
type which is particularly useful for efficiently sending point data and for Uint32Array
.
The default MeshCat scene comes with a few objects at pre-set paths. You can replace, delete, or transform these objects just like anything else in the scene.
/Lights/DirectionalLight
/Lights/AmbientLight
/Grid
/Axes
/Cameras
/Background
The camera is just another object in the MeshCat scene, so you can move it around with set_transform
commands like any other object. You can also use set_target
to change the camera's target. Please note that replacing the camera with set_object
is not currently supported (but we expect to implement this in the future).
Controlling the camera is slightly more complicated than moving a single object because the camera actually has two important poses: the origin about which the camera orbits when you click-and-drag with the mouse, and the position of the camera itself. In addition, cameras and controls in Three.js assume a coordinate system in which the Y axis is upward. In robotics, we typically have the Z axis pointing up, and that's what's done in MeshCat. To account for this, the actual camera lives inside a few path elements:
/Cameras/default/rotated/<object>
The /rotated
path element exists to remind users that its transform has been rotated to a Y-up coordinate system for the camera inside.
There is one additional complication: the built-in orbit and pan controls (which allow the user to move the view with their mouse) use the translation of only the intrinsic transform of the camera object itself to determine the radius of the orbit. That means that, in practice, you can allow the user to orbit by setting the position
property at the path /Cameras/default/rotated/<object>
to a nonzero value like [2, 0, 0]
, or you can lock the orbit controls by setting the position
property at that path to [0, 0, 0]
. Remember that whatever translation you choose is in the rotated, Y-up coordinate system that the Three.js camera expects. We're sorry.
To move the camera's center of attention to the point [1, 2, 3]
, while still allowing the user to orbit and pan manually, we suggest setting the transform of the /Cameras/default
path to whatever center point you want and setting the position
property of /Cameras/default/rotated/<object>
to [2, 0, 0]
. That means sending two commands:
{
type: "set_transform",
path: "/Cameras/default",
matrix: new Float32Array([1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
1, 2, 3, 1]) // the translation here is the camera's
// center of attention
},
{
type: "set_property",
path: "/Cameras/default/rotated/<object>",
property: "position",
value: [2, 0, 0] // the offset of the camera about its point of rotation
}
To move the camera itself to the point [1, 2, 3]
and lock its controls, we suggest setting the transform of /Cameras/default
to the exact camera pose and setting the position
property of /Cameras/default/rotated/<object>
to [0, 0, 0]
:
{
type: "set_transform",
path: "/Cameras/default",
matrix: new Float32Array([1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
1, 2, 3, 1]) // the translation here is now the camera's
// exact pose
},
{
type: "set_property",
path: "/Cameras/default/rotated/<object>",
property: "position",
value: [0, 0, 0] // set to zero to lock the camera controls
}
The MeshCat javascript sources live in src/index.js
. We use webpack to bundle up MeshCat with its Three.js dependencies into a single javascript bundle. If you want to edit the MeshCat source, you'll need to regenerate that bundle. Fortunately, it's pretty easy:
node
and npm
. Try running yarn -v
and npm -v
to make sure those programs are installed.yarn
project.json
file and install all the necessary javascript dependencies.npm run build
dist/main.min.js
. The build script will also watch for changes to the MeshCat source files and regenerate the bundle whenever those source files change.main.min.js
in your own application, or you can open up dist/index.html
in your browser.Note that due to caching, you may need to do a hard refresh (shift+F5 or ctrl+shift+R) in your browser to reload the updated javascript bundle.