Skip to Content
API ReferenceCompareViewer

CompareViewer

Shows two configurations next to each other with one camera: a before and after of a renovation, two paint options, the current part against its replacement. Each side is a full ModelViewer, so a side can differ in anything a viewer takes: objectBindings, sceneConfig, material variants, even a different modelUrl.

import "@liveroom-tech/react-immersive/styles.css"; import { CompareViewer } from "@liveroom-tech/react-immersive"; <div style={{ height: 600 }}> <CompareViewer modelUrl="/kitchen.glb" licenseKey="your-license-key" before={{ label: "Current", objectBindings: currentBindings }} after={{ label: "Proposed", objectBindings: proposedBindings }} /> </div>;

Layouts

  • layout="slider" (default) lays the two views over each other. A divider splits them: the left of it shows before, the right shows after. Drag the divider, or focus it and use the arrow keys, Page Up/Down, Home, and End. It is a slider to screen readers, with each side’s label and share.
  • layout="side-by-side" shows the two views next to each other, each half the width.

Changing layout keeps both viewers loaded and keeps the camera where the visitor left it, so a layout toggle doesn’t reset their view.

<CompareViewer modelUrl="/car.glb" licenseKey="your-license-key" layout="side-by-side" before={{ sceneConfig: { ...config, model: { ...config.model, activeVariants: ["Paint: Red"] }, }, }} after={{ sceneConfig: { ...config, model: { ...config.model, activeVariants: ["Paint: Blue"] }, }, }} />

One camera

Orbiting, panning, or zooming either side moves both. The side you last grabbed leads and the other copies it every frame, so a fly-in, a zoom to a selected object, or a refit on one side shows on both. With two different models, the views line up on the same point in space, so the models should share a coordinate system.

Props

type CompareViewerProps = Partial<ModelViewerProps> & { licenseKey: string; before: CompareViewerSide; // the left side after: CompareViewerSide; // the right side layout?: "slider" | "side-by-side"; // default "slider" split?: number; // the divider, 0 (left edge) to 1; default 0.5 onSplitChange?: (split: number) => void; semanticComparison?: boolean | SemanticComparisonOptions; showComparisonOutlines?: boolean; // default true; controlled when supplied onComparisonOutlinesChange?: (enabled: boolean) => void; linkSections?: boolean; // default true when semanticComparison is enabled onComparisonChange?: (report: ConfigurationComparisonReport) => void; }; type CompareViewerSide = Partial<ModelViewerProps> & { label?: string; // shown over the side; default "Before" / "After" };

Every other prop is shared by both sides, and a side’s own props win. Callbacks run per side: give before.onObjectSelect and after.onObjectSelect to tell the sides apart. Both sides start from the minimal preset , with no panels or buttons, so their interfaces don’t overlap; pass preset or ui to change that. Pass split to control the divider yourself; without it, CompareViewer keeps the position.

refitOnResize defaults to false here, unlike on ModelViewer: when the panes change size (a layout switch or a window resize) the camera keeps its view instead of reframing the model. Pass refitOnResize to reframe instead.

Each side has its own WebGL (or WebGPU ) canvas. The two share one download and parse of the model file, but the GPU holds two copies of its geometry and textures.

poster, loading and reveal work as on ModelViewer. With reveal="interaction", one View in 3D button starts both sides.

BindingBuilder has the same slider over its preview (Compare), to check edits against the project as it was opened.

The divider and the default side labels use the labels keys compareBefore, compareAfter, compareDivider, and compareDividerValue.

Semantic comparison

Enable semanticComparison to see added, removed, modified, unchanged, and ambiguous binding records, alongside the original slider or side-by-side views. The panel filters by status and category, searches objects, shows old and new field values, and downloads a JSON report. Green bounds mark additions, red bounds removals, amber bounds modifications, and cyan bounds the focused row. Uncheck Show outlines in the Changes panel to hide the colored comparison bounds on both sides while keeping the change list and matched selection active. The editor remembers this choice when you close and reopen Compare during the same session. CompareViewer also accepts showComparisonOutlines={false}; pair that prop with onComparisonOutlinesChange to control the panel switch from your application. The regular viewer selection highlight is independent.

The outlines are temporary helpers: they do not change materials or appear in model exports. Selecting a row focuses its object and selects the matched object on both sides. Removed objects are focused in the before view.

<CompareViewer licenseKey="your-license-key" modelUrl="/assembly.glb" semanticComparison={{ matchBy: { metadataKey: "partId" }, tolerance: 0.00001, }} before={{ objectBindings: currentBindings }} after={{ objectBindings: proposedBindings }} />

Matching defaults to modelObjectId. Use matchBy: "id" for binding IDs or { metadataKey: "partId" } for an exact string/number metadata value. Duplicate or missing identities are reported as ambiguous rather than paired by guesswork. An explicit one-to-one mapping: { beforeBindingKey: "afterBindingKey" } resolves renamed nodes or duplicate identities. Invalid mappings throw an error.

Comparison categories cover identity, appearance (material overrides and decals), transforms, visibility/status, metadata/metrics, and behavior (actions, selectability, hoverability, and camera overrides). Missing visibility and interaction flags use their viewer defaults; tags are compared as sets. Missing transform fields inherit the source model pose and are not assumed to be zero. ignoreMetadataKeys excludes volatile top-level metadata keys. removed: true counts as absence; visible: false is a visibility change. Scene settings have a separate change list.

The data API works without React or a renderer:

import { compareViewerConfigurations } from "@liveroom-tech/react-immersive/utils"; const report = compareViewerConfigurations( { objectBindings: currentBindings, sceneConfig: currentScene }, { objectBindings: proposedBindings, sceneConfig: proposedScene }, { matchBy: "modelObjectId", ignoreMetadataKeys: ["lastUpdated"] }, ); // report.objects: keys, model object IDs, status, and field changes // report.counts: added / removed / modified / unchanged / ambiguous // report.sceneChanges: authored scene setting changes

Inputs must contain finite, acyclic JSON data. Reports detach changed values from the input. Numeric comparisons use an absolute tolerance of 0.000001 by default. onComparisonChange receives a new report when its contents change.

linkSections defaults to true with semantic comparison: both views use the after view’s cut, and toolbar adjustments inspect both views together. Set linkSections={false} to view each side’s own section settings. The report still compares the original authored settings. Programmatic focus also synchronizes camera field of view.

This compares the active asset’s authored configuration. It does not inspect mesh topology, compare pixels, infer changes inside a model URL, or combine all assets in a composition into one revision report. Use stable object identities across revisions and provide bindings for the objects you want to compare. Unbound geometry is not classified as added or removed.

BindingBuilder’s Compare includes this panel automatically. Object matching chooses model ID, binding ID, or a metadata key. Pin keeps the current configuration as the before baseline for subsequent edits. Both sides use the current section cut while you inspect the active asset.

Starter

The before/after starter  compares two aligned kitchen models with both layouts, a keyboard-operable divider and camera buttons wired through useViewerCamera().

Programmatic camera control

Connect a useViewerCamera() hook to a pane’s onViewerReady and onCameraChange callbacks (or use that pane’s useViewer().props). Explicit hook commands such as lookAt, setCameraTarget, dollyTo, fitScene and goToPreset make that pane the leader for the command, so both cameras move. Dragging either pane transfers leadership to it again. Automatic follower refits continue to follow the current leader. Direct calls on viewer.raw.controls bypass this ownership behavior; prefer the hook commands for linked views.