Skip to content

XViewr SDK Documentation

XViewer SDK v3.1.1 is a 3D visualization SDK built on Three.js. It provides a modular, plugin-based architecture for loading, rendering, measuring, annotating, and interacting with CAD-grade 3D scenes in the browser.

Architecture at a Glance

Four layers, talking through an event bus and a service registry:

  • CoreViewerCore owns the lifecycle, the Three.js scene/camera/renderer, and the registries (services, plugins, config, events).
  • Services — long-lived, stateful subsystems registered at startup (camera, loading, materials, measurement, selection, rendering, etc.). Plugins read and write through them.
  • Plugins — feature modules that can be activated and deactivated. They render, handle interaction, and coordinate services.
  • Types — public configuration shapes and shared data types.

Plugins never reach across to each other directly. They communicate via the EventBus and the services they depend on.

ts
import { ViewerCore, LoaderPlugin } from '@optellix/xviewr-sdk';

const viewer = new ViewerCore(document.getElementById('viewer'), {
  viewer: {
    camera: { type: 'perspective', fov: 75, position: { x: 5, y: 5, z: 5 } },
    licensing: { key: 'YOUR_LICENSE_KEY' },
  },
  rendering: { antialias: true },
  plugins: [],
});

await viewer.ready();
await viewer.loadPlugin(new LoaderPlugin());
const loaderPlugin = viewer.pluginManager.getPlugin('loader');
await loaderPlugin.loadFile(myGlbFile);

Getting Started

See the Quick Start guide for a complete walkthrough: install, licensing, loading a model, and common next steps.

For the full config shape see types/configuration.md. Errors thrown by the SDK are in errors.md.

Module Index

Core

ModuleDescription
ViewerCoreMain entry class. Owns the scene, camera, renderer, and registries. Exposes ready(), dispose(), getService, getPlugin.
PluginsIPlugin contract, PluginContext, PluginMetadata, PluginStatus, IPluginManager. How plugins are registered, activated, and torn down.
ServicesIService, ServiceContext, IServiceRegistry, ServiceStatus, ILogger. How to consume and register custom services.
Event BusIEventBus (emit, on, once, off). Cross-module communication.
Config ManagerIConfigManager for dot-path config get/set, validation, and watchers.

Services

ModuleDescription
CameraServiceCamera state, controls (orbit/trackball/arcball), view presets, fit-to-view, projection switching.
LoaderServiceFile loading with pluggable ILoader implementations, chunked manifest loading.
LODServiceStreaming LOD for chunked models. Cache budget, watermarks, eviction.
LicenseServiceXVR1/ES256 license validation, plugin and feature gating, expiry events.
MaterialServiceMaterial modes (default/matcap/random), original tracking, X-ray sets, clipping planes.
MeshServiceMesh registry, deterministic IDs, queries, hide/show/ghost/x-ray/isolate, processing pipeline, edge-line utilities.
MeasurementServiceDescriptor-based 3D measurements (distance, angle, area, multi-point, AABB/OBB, volume, circle, arc).
SelectionServiceObject selection, hover, multi-select, neighbour selection, raycasting, custom highlight strategies.
StorageServiceQueryable scene-hierarchy graph (assemblies, parts, BOM).
RenderingServiceRenderer config, shadow map, tone mapping, exposure, quality presets, screenshot.
PostProcessingServiceEffectComposer pipeline, custom passes, shared color/depth/normal buffers.
CrossSection typesPublic types for the cross-section plugin (SectionCapStyle).
CommandRunnerServiceOptional LLM-friendly command facade. Registry, validation, never-throwing execute, machine-readable catalog.

Plugins

ModuleDescription
CameraPluginAnimated camera transitions, save/restore camera states.
LoaderPluginHigh-level file loading, drag-and-drop, chunked LOD streaming.
AnimationPluginTween/timeline forwarders, scene-state capture, restore, delta animation.
EnvironmentPluginHDRI, lighting, shadows, background.
ExplosionPluginHierarchical mesh explosion with axis/radial/depth modes.
GridPluginReference grid: orientation, auto-fit to scene or object.
LabelPluginHTML overlay labels with per-type renderers, leaders, drag support.
MeasurementPluginInteractive measurement tools and label/leader styling.
CanvasExportPluginPNG/JPEG/WebP export with measurement/label compositing.
RenderingPluginPlugin wrapper for RenderingService and PostProcessingService.
SelectionPluginClick, region, neighbour, focus-on-selection.
ModelTreePluginHierarchical model tree, filtering, search, optional UI panel.
CrossSectionPluginInteractive clipping planes with transform gizmo and IGES export.
TransformControlsPluginTranslate/rotate/scale gizmo.
TechnicalDrawingPluginCAD-style hidden-line drawings with PNG/SVG export.
ViewCubePluginOverlay navigation cube with snap and drag.
ImageViewerPluginStandalone 2D image canvas with zoom and pan.
MarkupPluginPen/eraser overlay synced to image transform.
SlashCommandPluginText-input driver for the command system: parse, autocomplete, chain with &&.

Types and Errors

ModuleDescription
ConfigurationXViewerConfig and all sub-configs (camera, controls, environment, rendering, post-processing, plugins, features).
Common TypesShared types: view presets, load options, screenshot options, chunked manifest types, measurement results.
ErrorsXViewerError hierarchy and when each subclass is thrown.

How the Pieces Fit Together

  1. ViewerCore instantiates the registries and built-in services from your XViewerConfig.
  2. CameraPlugin loads as a core plugin during startup. Other built-in plugins are loaded explicitly with viewer.loadPlugin(new PluginClass()).
  3. Services hold state and expose typed APIs. Example: LoaderService loads a model, MeshService registers its meshes, MaterialService tracks originals, SelectionService listens for input and emits selection events.
  4. Plugins react to events and call into services. Example: MeasurementPlugin listens for clicks via SelectionService, asks MeasurementService to compute the result, and renders the label using LabelPlugin-style overlays.
  5. On viewer.dispose(), plugins deactivate, services dispose GPU resources, and the renderer is torn down.

XViewr SDK and xConvert CLI documentation.