Skip to Content
HooksuseViewerModel

useViewerModel

Provides model lifecycle state and scene metadata: loading status, errors, scene bounds, object count, and the list of bindable objects.

This reports one model’s metadata. For the model array, active URL, and per-model binding edits, use useViewerModels.

Usage

import { useViewerModel } from "@liveroom-tech/react-immersive"; const { isLoading, isReady, error, bounds, objectCount, materialVariants, materialVariantGroups, objects, handleModelLoaded, handleObjectCatalog, handleLoadError, } = useViewerModel(); <ModelViewer onModelLoaded={handleModelLoaded} onObjectCatalog={handleObjectCatalog} onLoadError={handleLoadError} ... />

Returns

NameTypeDescription
isLoadingbooleantrue until the model has loaded or failed
isReadybooleantrue after a successful model load
errorunknown | nullThe most recent load/render error, or null
boundsSceneBounds | nullScene bounds: min, max, center, size
objectCountnumberNumber of mesh objects in the loaded scene
materialVariantsstring[]Names of the model’s glTF material variants; empty when it has none. See showMaterialVariants
materialVariantGroupsMaterialVariantGroup[]The same variants as option groups, each with a name (or null) and its variants (name, display label, and a swatch colour when the material is a plain colour)
objectsViewerObjectInfo[]Every bindable object in the model; filled once handleObjectCatalog is passed to onObjectCatalog
handleModelLoaded(model: ViewerModelInfo) => voidCallback to pass to onModelLoaded
handleObjectCatalog(objects: ViewerObjectInfo[]) => voidCallback to pass to onObjectCatalog
handleLoadError(error: unknown) => voidCallback to pass to onLoadError

Example: Loading States

const { isLoading, isReady, error } = useViewerModel(); if (isLoading) return <p>Loading model…</p>; if (error) return <p>Failed to load: {String(error)}</p>; if (isReady) return <p>Model ready with {objectCount} objects</p>;

Example: Listing the model’s objects

const { objects, handleObjectCatalog } = useViewerModel(); <ModelViewer modelUrl="/model.glb" licenseKey={licenseKey} onObjectCatalog={handleObjectCatalog} />; <ul> {objects.map((object) => ( <li key={object.name}> {object.name} ({object.triangles} triangles) </li> ))} </ul>;

useViewerModels

Owns the models array, active URL, and write-back of binding edits to the active entry. Spread its return value onto ModelViewer:

import { ModelViewer, useViewerModels } from "@liveroom-tech/react-immersive"; const viewer = useViewerModels(initialModels); <ModelViewer {...viewer} licenseKey={licenseKey} />;

Parameter

initialModels: ModelViewerModelEntry[] initializes state on mount. Each entry requires a unique url and an explicit objectBindings record. The first URL is initially active. Later changes to initialModels do not replace state. The hook does not expose upload, add/remove, or scene-config setters; own that state yourself when you need a dynamic model list.

Returns

NameTypeDescription
modelsModelViewerModelEntry[]Entries with their current binding edits
modelUrlstringActive model URL; initially the first entry’s URL, or ""
onModelChangeReact state setter for stringChanges the active URL; also enables the built-in model switcher
objectBindingsRecord<string, ObjectBinding>Stable empty record; entry bindings take precedence
onObjectBindingsChange(next: Record<string, ObjectBinding>) => voidReplaces bindings on the active URL only

The hook does not manage selection or animation controls. Clear your selection when changing the active model and use onModelAnimationsReady for playback across entries. See the complete export-to-viewer example .