Create Viewer.
The Display object.
configuration parameters.
The callback to receive changes of viewer parameters.
Optional callback for PNG pinning.
enforce to redraw orientation marker after every ui activity
Get ambientLight property. Throws if not rendered.
Get axesHelper property. Throws if not rendered.
Get the current CAD view width.
Get camera property. Throws if not rendered.
Get clipping property. Throws if not rendered.
Get controls property. Throws if not rendered.
Get directLight property. Throws if not rendered.
Environment manager — proxied from StudioManager for display.ts access.
Get the current glass mode state.
Get gridHelper property. Throws if not rendered.
Get the current view height.
Returns whether Studio mode is currently active.
True if Studio mode is active and the viewer has rendered content.
Get nestedGroup property. Throws if not rendered.
Get orientationMarker property. Throws if not rendered.
Get ortho value as property (for ViewerLike interface compatibility).
Get rendered state, throwing if not yet rendered.
Get scene property. Throws if not rendered.
Get treeview property. Returns null if not rendered.
Get the current tree width.
Activate or deactivate a measurement/selection tool. This is the single entry point for tool state changes - Display should call this rather than mutating state directly.
Tool name ("distance", "properties", "select")
Whether to activate (true) or deactivate (false) the tool
Add a part (leaf or subtree) to the scene under an existing parent.
For a leaf, pass a Shapes object with shape set and name
as a plain name (no leading slash). The absolute path is built as
parentPath + "/" + partData.name.
For a subtree, pass a Shapes object with parts set and id
as a slash-prefixed relative tree (e.g. "/shelf"). All id
fields in the tree are prefixed with parentPath before rendering.
When adding many parts in a batch, pass { skipBounds: true } to
defer the expensive bounds/clipping/treeview recomputation, then call
updateBounds() once after the loop.
Absolute path of the parent group (e.g. "/assembly"). Must already exist as a CompoundGroup.
A Shapes object describing the part to add.
Optional settings.
OptionalskipBounds?: booleanWhen true, skip bounds/clipping/treeview
update and re-render. Caller must call updateBounds() afterwards.
The absolute path of the added root element.
Add a position animation track (full 3D translation).
path/id of group to be animated.
array of keyframe times.
array of [x, y, z] position offsets.
Add a quaternion rotation animation track.
path/id of group to be animated.
array of keyframe times.
array of [x, y, z, w] quaternion values.
Add a single-axis rotation animation track.
path/id of group to be animated.
which axis to rotate around ("x", "y", or "z").
array of keyframe times.
array of rotation angles in degrees.
Add a single-axis translation animation track.
path/id of group to be animated.
which axis to translate along ("x", "y", or "z").
array of keyframe times.
array of translation values along the axis.
Start the animation loop
Backup animation (for switch to explode animation)
Centers the camera view on all visible objects in the scene. Calculates a bounding box that encompasses all visible ObjectGroup instances and sets the camera target to the center of that bounding box.
Whether to notify listeners of the camera update
Creates ChangeNotification object if new value != old value and sends change notifications via viewer.notifyCallback.
change information.
whether to send notification or not.
Clear the current CAD view without disposing the renderer.
Use this to remove shapes before rendering new ones. The viewer remains usable after clear().
Clear the animation object and dispose dependent objects
Collapse or expand tree nodes.
CollapseState enum value
whether to send notification or not.
Handler for the animation control
the pressed button as string: "play", "pause", "stop"
Remove all assets and event handlers. Call when done with the viewer.
This disposes:
After calling dispose(), the viewer instance should not be used.
Pre-size the clipping stencil region so that all future updatePart /
updateBounds calls whose geometry stays within bb will never trigger
an expensive rebuildStencils.
Call this once before a series of updates when the maximum extent of the geometry is known upfront (e.g. the parameter range of a slider).
The maximum bounding box that geometry will ever occupy.
InternalEnter Studio mode. Called by display.ts switchToTab().
Calculate explode trajectories and initiate the animation.
duration of animation.
speed of animation.
multiplier for length of trajectories.
Get intensity of ambient light.
ambientLight value.
Get whether axes helpers are visible.
true if axes are shown
Get location of axes.
axes0 value, true means at origin (0,0,0)
Get blackEdges value.
blackEdges value.
Get the current camera position.
camera position as 3 dim array [x,y,z].
Get the current camera rotation as quaternion.
camera rotation as 4 dim quaternion array [x,y,z,w].
Get camera type.
"ortho" or "perspective".
Get zoom value.
zoom value.
Get the canvas DOM element.
The canvas element
Get intersection mode.
clip intersection value.
Get clipping plane state.
index of the normal: 0, 1 ,2
clip plane visibility value.
Get clipping plane state.
clip plane visibility value.
Get clipping slider value.
index of the normal: 0, 1 ,2
clip slider value.
Get intensity of direct light.
directLight value.
Get default color of the edges.
edgeColor value.
Get visibility of grids.
grids value.
Get holroyd (non-tumbling) trackball mode.
holroyd flag.
Get the current canvas as png data.
an id to identify the screenshot
Promise resolving to task ID and data URL Note: Only the canvas will be shown, no tools and orientation marker
Retrieves the metalness value.
The current metalness value.
Get the color of a node from its path
path of the CAD object
Get whether the clipping caps color status
color caps value (object color (true) or RGB (false)).
Get default opacity.
opacity value.
Get ortho value.
ortho value.
Get panning speed.
pan speed value.
Get the current relative animation time (0-1).
relative time between 0 and 1.
Get reset location value.
target, position, quaternion, zoom as object.
Get rotation speed.
rotation speed value.
Retrieves the roughness value.
The current roughness value.
Get the ObjectGroup and path for the currently selected object in Studio mode. Returns null if nothing is selected, Studio mode is inactive, or the selection is a CompoundGroup (assembly node) rather than a leaf object.
Get state of a treeview leaf for a path. separator can be / or |
path of the object
state value in the form of [mesh, edges] = [0/1, 0/1]
Get states of all treeview leaves.
object mapping paths to visibility states.
Gets whether 4K environment maps are enabled.
True for 4K, false for 2K.
Gets the current ambient occlusion intensity in Studio mode.
The AO intensity value (0.5-3.0).
Gets the current background mode for Studio mode.
The background mode ("grey", "white", "gradient", "environment", or "transparent").
Gets the current studio environment intensity.
The environment intensity (0-3).
Gets the current studio environment preset.
The environment name ("studio", "neutral", "outdoor", "none", or custom HDR URL).
Gets the current environment rotation for Studio mode.
The rotation in degrees (0-360).
Gets the current exposure value for Studio mode.
The exposure value (0-3).
Gets the current shadow intensity in Studio mode.
The shadow intensity (0-1). 0 means shadows are off.
Gets the current shadow softness in Studio mode.
The shadow softness (0-1).
Gets the current texture mapping mode for Studio mode.
The texture mapping mode ("triplanar" or "parametric").
Gets the current tone mapping mode for Studio mode.
The tone mapping mode ("neutral", "ACES", or "none").
Get whether tools are shown/hidden.
tools value.
Get transparency state of CAD objects.
transparent value.
Gets the current stripe color scheme.
The color scheme ("blackwhite", "colorful", "grayscale").
Gets the current stripe count value.
The stripe count (2-50).
Gets the current stripe direction value.
The stripe direction in degrees (0-90).
Gets the current stripe mapping mode.
The mapping mode ("reflection", "normal").
Gets the current stripe opacity value.
The stripe opacity (0-1).
Get zoom speed.
zoomSpeed value.
Enable/disable glass mode (transparent overlay UI).
whether to enable glass mode
whether to send notification or not.
Handle a backend response sent by the backend The response is a JSON object sent by the Python backend through VSCode
Handle bounding box and notifications for picked elements
path of object
name of object (id = path/name)
meta key pressed
shift key pressed
alt key pressed
picked point
node type
whether from tree
Check whether animation object exists
Initialize the animation.
overall duration of the animation.
speed of the animation.
animation label.
whether to repeat the animation.
InternalLeave Studio mode. Called by display.ts switchToTab().
Notifies the states by checking for changes and passing the states to the checkChanges method.
Find the shape that was double clicked and send notification
a DOM PointerEvent or MouseEvent
Replace CadView with an inline png image of the canvas.
Note: Only the canvas will be shown, no tools and orientation marker
Move the camera to one of the preset locations.
can be "iso", "top", "bottom", "front", "rear", "left", "right"
zoom value
whether to send notification or not.
Recenter camera on the bounding box center of all objects.
whether to send notification or not.
Refresh clipping plane
index of the plane: 0,1,2
distance on the clipping normal from the center
Remove a part (leaf or subtree) from the scene by path.
When removing many parts in a batch, pass { skipBounds: true } to
defer the expensive bounds/clipping/treeview recomputation, then call
updateBounds() once after the loop.
The absolute path of the part to remove (e.g., "/assembly/shelf_5").
Optional settings.
OptionalskipBounds?: booleanWhen true, skip bounds/clipping/treeview
update and re-render. Caller must call updateBounds() afterwards.
Render a CAD object and build the navigation tree.
This is the main entry point for displaying CAD geometry. It:
the Shapes object representing the tessellated CAD object
the render options (edge color, opacity, etc.)
the viewer options (camera position, clipping, etc.)
Render the shapes of the CAD object.
Whether to render the compact or exploded version
The Shapes object.
A nested THREE.Group object and navigation tree.
Reset the view to the initial camera and controls settings.
Resets clip planes to default normals and slider positions. Normals reset to -X, -Y, -Z; sliders to gridSize/2; checkboxes unchecked.
Resets the material settings of the viewer to their default values. Updates the metalness, roughness, ambient light intensity, and direct light intensity based on the current material settings.
Reset Studio settings to defaults.
Resets zebra tool settings to defaults: count=9, opacity=1, direction=0, colorScheme=blackwhite, mappingMode=reflection.
Reset zoom to 1.0.
Resize UI and renderer.
new width of CAD View
new width of navigation tree
new height of CAD View
Whether to use glass mode or not
Restore animation (for switch back from explode animation)
Set the active sidebar tab.
Tab name: "tree", "clip", "material", "zebra", or "studio"
whether to send notification or not.
Set the intensity of ambient light.
the new ambient light intensity (0-4)
whether to send notification or not.
Show or hide the axes helper (X/Y/Z indicators).
true to show axes, false to hide
whether to send notification to callback
Set whether grids and axes center at the origin or the object's boundary box center
whether grids and axes center at the origin (0,0,0)
whether to send notification or not.
Show edges in black or the default edge color.
whether to show edges in black
whether to send notification or not.
Sets the bounding box for a given ID.
The ID of the group.
Move the camera to a given location.
flag whether the position is a relative (e.g. [1,1,1] for iso) or absolute point.
the camera position as THREE.Vector3
the camera rotation expressed by a quaternion.
zoom value.
whether to send notification or not.
Set camera position.
camera position as 3 dim Array [x,y,z].
flag whether the position is a relative (e.g. [1,1,1] for iso) or absolute point.
whether to send notification or not.
Set camera rotation via quaternion.
camera rotation as 4 dim quaternion array [x,y,z,w].
whether to send notification or not.
Set camera target.
camera target as THREE.Vector3 or [x, y, z] tuple.
whether to send notification or not.
Set zoom value.
float zoom value.
whether to send notification or not.
Set the clipping mode to intersection mode
whether to use intersection mode
whether to send notification or not.
Set the normal at index to a given normal
index of the normal: 0, 1 ,2
3 dim array representing the normal
value of the slider, if given
whether to send notification or not.
Set the normal at index to the current viewing direction
index of the normal: 0, 1 ,2
whether to send notification or not.
Toggle the clipping caps color between object color and RGB
whether to use intersection mode
whether to send notification or not.
Show/hide clip plane helpers
whether to show clip plane helpers
whether to send notification or not.
Set clipping slider value and update the clipping plane.
index of the normal: 0, 1 ,2
value for the clipping slider
whether to send notification or not.
Set the intensity of directional light.
the new direct light intensity (0-4)
whether to send notification or not.
Set the default edge color
edge color (0xrrggbb)
whether to send notification or not.
Toggle explode mode on/off.
whether to enable or disable explode mode
whether to send notification or not.
Enable or disable glass mode (overlay navigation)
whether to enable glass mode
whether to send notification or not.
Show/hide grids
one of "grid" (all grids), "grid-xy","grid-xz", "grid-yz"
visibility flag
whether to send notification or not.
Set grid center
true for centering grid at (0,0,0)
whether to send notification or not.
Toggle grid visibility
3 dim grid visibility (xy, xz, yz)
whether to send notification or not.
Set holroyd (non-tumbling) trackball mode. When false, uses standard Three.js TrackballControls behavior.
whether to enable holroyd mode.
whether to send notification or not.
Set modifiers and action shortcuts for keymap
keymap e.g. {"shift": "shiftKey", "ctrl": "ctrlKey", "meta": "altKey", "axes": "a", ...}
Enable/disable local clipping
whether to enable local clipping
Sets the metalness value for the viewer and updates related properties.
The metalness value to set (0-1).
Whether to notify about the changes.
Sets the visibility state of an object in the viewer.
The path of the object.
The visibility state (0 or 1).
The icon number.
Whether to notify the changes.
Whether to update the view.
Set the default opacity
opacity (between 0.0 and 1.0)
whether to send notification or not.
Set/unset camera's orthographic mode.
whether to set orthographic mode or not.
whether to send notification or not.
Set pan speed.
the new pan speed
whether to send notification or not.
Set raycast mode
turn raycast mode on or off
Set the animation to a specific relative time (0-1). Pauses the animation at that point.
relative time between 0 and 1.
Apply render options and build materialSettings object. Called by render() after state is populated with render options.
The provided options object for rendering.
Set reset location value.
camera target as 3 dim Array [x,y,z].
camera position as 3 dim Array [x,y,z].
camera rotation as 4 dim quaternion array [x,y,z,w].
camera zoom value.
whether to send notification or not.
Set rotation speed.
the new rotation speed.
whether to send notification or not.
Sets the roughness value for the viewer and updates related components.
The roughness value to set (0-1).
Whether to notify about the changes.
Set state of one entry of a treeview leaf given by an id
object id
2 dim array [mesh, edges] = [0/1, 0/1]
node type (unused)
whether to send notification or not.
Set states of treeview leaves.
states object mapping paths to visibility states.
Sets whether 4K environment maps are used (default: 2K).
True for 4K, false for 2K.
Whether to notify about the changes.
Sets the ambient occlusion intensity in Studio mode. A value of 0 disables AO; values > 0 enable it at that intensity.
The AO intensity (0-3.0).
Whether to notify about the changes.
Sets the background mode for Studio mode.
The background mode ("grey", "white", "gradient", "environment", or "transparent").
Whether to notify about the changes.
Sets the studio environment intensity.
The environment intensity (0-3).
Whether to notify about the changes.
Sets the studio environment preset.
The environment name ("studio", "neutral", "outdoor", "none", or custom HDR URL).
Whether to notify about the changes.
Sets the environment rotation for Studio mode.
The rotation in degrees (0-360).
Whether to notify about the changes.
Sets the exposure value for Studio mode.
The exposure value (0-2).
Whether to notify about the changes.
Sets the shadow intensity in Studio mode. A value of 0 disables shadows; values > 0 enable them at that darkness.
The shadow intensity (0-1).
Whether to notify about the changes.
Sets the shadow softness in Studio mode. Controls PCSS penumbra width (virtual light source size).
The shadow softness (0-1).
Whether to notify about the changes.
Sets the texture mapping mode for Studio mode.
The texture mapping mode ("triplanar" or "parametric").
Whether to notify about the changes.
Sets the tone mapping mode for Studio mode.
The tone mapping mode ("neutral", "ACES", or "none").
Whether to notify about the changes.
Set the UI theme.
"light", "dark", or "browser" for auto-detection
The resolved theme ("light" or "dark")
Show or hide the CAD tools panel
whether to show tools
whether to send notification or not.
Set CAD objects transparency.
whether to show the CAD object in transparent mode
whether to send notification or not.
Set camera to a predefined view direction.
"iso", "front", "rear", "left", "right", "top", or "bottom"
whether to focus/center on visible objects
Apply view options to state. Called by render() after state is populated.
The provided options object for the view.
Sets the stripe color scheme for the viewer and updates related components.
The color scheme ("blackwhite", "colorful", "grayscale").
Sets the stripe count value for the viewer and updates related components.
The stripe count value to set.
Sets the stripe direction value for the viewer and updates related components.
The stripe direction value to set.
Sets the stripe mapping mode for the viewer and updates related components.
The mapping mode ("reflection", "normal").
Sets the stripe opacity value for the viewer and updates related components.
The stripe opacity value to set.
Set zoom speed.
the new zoom speed
whether to send notification or not.
Set zscaling value.
scale factor.
Show/hide the explode tool.
whether to show the explode tool
Show/hide the help dialog.
whether to show the help dialog
Collapse or expand the info panel in glass mode.
true to show, false to collapse
Show/hide the measure tools.
whether to show the measure tools
Show/hide the pinning button.
whether to show the pinning button
Show/hide the select tool.
whether to show the select tool
Show/hide the CAD tools
visibility flag
whether to send notification or not.
Collapse or expand the tools panel (tabs + content) in glass mode.
true to show, false to collapse
Show/hide the z-scale tool.
whether to show the z-scale tool
Set camera mode to OrthographicCamera or PerspectiveCamera.
true for orthographic, false for perspective
whether to send notification or not.
Synchronizes the states of two tree structures recursively.
The compact tree structure.
The expanded tree structure.
Whether rendering in exploded mode.
The current path in the tree structure.
Toggle the two version of the NestedGroup. Must only be called after render() has completed.
whether to render the exploded or compact version
Render scene and update orientation marker If no animation loop exists, this needs to be called manually after every camera/scene change
whether to update the orientation marker
whether to send notification or not.
Recompute scene bounds, camera far plane, clipping stencils, and
re-render. Call this once after a batch of
addPart, removePart, or updatePart calls that used
{ skipBounds: true }.
If parts were added or removed in the batch, the navigation treeview is also rebuilt automatically.
Update an existing part's geometry.
When the mesh topology is unchanged (same number of vertices, triangles,
and edge segments), buffers are updated in-place — no Three.js objects
are disposed or recreated. When topology differs the method
automatically falls back to a batched removePart + addPart.
Only leaf parts (ObjectGroups with shapeGeometry) are supported.
The part must already exist in the scene.
When updating many parts in a batch, pass { skipBounds: true } to
defer the expensive bounds/clipping recomputation, then call
updateBounds() once after the loop:
for (const p of parts) {
viewer.updatePart(path, data, { skipBounds: true });
}
viewer.updateBounds();
The absolute path of the part to update (e.g., "/assembly/part").
A Shapes object with the new shape data.
The shape.vertices, shape.normals, shape.triangles, and
shape.edges fields are used to update the geometry.
Optionally color, alpha, and loc are synced into this.shapes.
Optional settings.
OptionalskipBounds?: booleanWhen true, skip bounds/clipping/explode-cache
update and re-render. Caller must call updateBounds() afterwards.
Return three-cad-viewer version as semver string.
semver version
Main CAD viewer class that manages the 3D scene, rendering, and user interaction.
The Viewer is created by Display and handles:
Lifecycle
render()called to display CAD shapesclear()to remove shapes (optional)dispose()for cleanupState Management
All state is centralized in
ViewerState. Use getter/setter methods rather than accessing state directly.Example