This Viewer module focuses on the interactive layer: Views, Cameras, picking, emphasis effects (highlight/selection/x-ray),
section planes, lighting, and rendering modes.
Installation
npminstall@xeokit/sdk
Tutorial
This tutorial walks through a minimal setup and then adds common interaction features step by step.
Start by creating a Scene. The Scene is the SDK’s in-memory scene graph: it owns the model
representation (SceneModels, objects, meshes, geometries, textures) and is where model content is created, updated,
imported, and exported. For a deeper introduction to Scene content and building/importing models, see
@xeokit/sdk/scene.
Next, create a Viewer. The Viewer is the browser-facing facade for interactive viewing: it manages one or more
Views (canvases), user interaction state (camera control, picking, emphasis effects, section planes,
render modes, etc), and it provides a Viewer-centric event stream that reflects interactions and viewer-side changes.
Finally, attach a WebGLRenderer. The WebGLRenderer is the rendering backend that
listens to changes and draws the Scene into the View canvases using the browser’s WebGL API.
The runtime event flow is:
The Scene emits events when its content changes (models loaded, objects created/destroyed, transforms updated, etc).
The Viewer receives those Scene changes (via the attached Scene) and emits Viewer events as user interaction and
view configuration changes occur (camera moves, section planes added, objects highlighted/selected/x-rayed, etc).
The WebGLRenderer listens to both streams to keep GPU resources in sync and re-render Views whenever something changes.
constscene = newScene();
constviewer = newViewer({ scene });
constrenderer = newWebGLRenderer({ viewer });
3) Create a View (canvas) and enable camera controls
A Viewer renders into one or more Views. Each View has its own canvas, camera, and per-object visual state.
Configure Camera.worldAxis | worldAxis to match your domain’s coordinate system. This affects navigation behavior when using CameraControl.
+Y up (+X right, -Z forward):
view1.camera.worldAxis = [ 1, 0, 0, // Right 0, 1, 0, // Up 0, 0, -1// Forward ];
+Z up (+X right, -Y forward):
view1.camera.worldAxis = [ 1, 0, 0, // Right 0, 0, 1, // Up 0, -1, 0// Forward ];
7) Add some content
For a full walkthrough on creating and importing geometry, see @xeokit/sdk/scene.
Below is a tiny example that creates a model with a few objects so you can try interactions immediately:
ViewLayers let you apply operations to groups of objects (visibility, selection, clipping, etc).
ViewLayers are created in a View and are populated based on the layerId
of the underlying SceneObjects.
xeokit Viewer
The SDK's browser-based 3D/2D Viewer for xeokit Scenes
This module allows you to display and interact with a Scene in the browser.
If you’re new to xeokit’s model representation, start with:
This Viewer module focuses on the interactive layer: Views, Cameras, picking, emphasis effects (highlight/selection/x-ray), section planes, lighting, and rendering modes.
Installation
Tutorial
This tutorial walks through a minimal setup and then adds common interaction features step by step.
1) Import modules
2) Create a Scene, Viewer and WebGLRenderer
Start by creating a Scene. The Scene is the SDK’s in-memory scene graph: it owns the model representation (SceneModels, objects, meshes, geometries, textures) and is where model content is created, updated, imported, and exported. For a deeper introduction to Scene content and building/importing models, see @xeokit/sdk/scene.
Next, create a Viewer. The Viewer is the browser-facing facade for interactive viewing: it manages one or more Views (canvases), user interaction state (camera control, picking, emphasis effects, section planes, render modes, etc), and it provides a Viewer-centric event stream that reflects interactions and viewer-side changes.
Finally, attach a WebGLRenderer. The WebGLRenderer is the rendering backend that listens to changes and draws the Scene into the View canvases using the browser’s WebGL API.
The runtime event flow is:
3) Create a View (canvas) and enable camera controls
A Viewer renders into one or more Views. Each View has its own canvas, camera, and per-object visual state.
4) Position the camera
5) Choose a projection (orthographic or perspective)
6) Align navigation to a world axis convention
Configure Camera.worldAxis | worldAxis to match your domain’s coordinate system. This affects navigation behavior when using CameraControl.
+Y up (+X right, -Z forward):
+Z up (+X right, -Y forward):
7) Add some content
For a full walkthrough on creating and importing geometry, see @xeokit/sdk/scene. Below is a tiny example that creates a model with a few objects so you can try interactions immediately:
8) Emphasis effects: highlight, select, x-ray, and colorize
Toggle effects in batches:
Or set state directly on a ViewObject:
9) Slice the scene with SectionPlanes
Create a SectionPlane:
Animate it:
Keep specific objects unaffected:
10) Customize lighting
11) Add a second View
Multiple Views can render the same Scene with different camera positions and visual states.
12) Organize objects with ViewLayers
ViewLayers let you apply operations to groups of objects (visibility, selection, clipping, etc). ViewLayers are created in a View and are populated based on the layerId of the underlying SceneObjects.
Hide everything in a layer:
13) Save and load BCF viewpoints
Use BCF to exchange viewpoints with other BIM tools. For background and semantic context, see @xeokit/sdk/data.
14) Switch rendering modes
Rendering modes let you enable/disable effects as a group (eg. quality vs performance).
15) Serialize and restore Viewer configuration
Use Viewer.toParams and Viewer.fromParams to copy Viewer configuration between instances (Views, Cameras, SectionPlanes, Lights, materials, and more).