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
| Name | Type | Description |
|---|---|---|
isLoading | boolean | true until the model has loaded or failed |
isReady | boolean | true after a successful model load |
error | unknown | null | The most recent load/render error, or null |
bounds | SceneBounds | null | Scene bounds: min, max, center, size |
objectCount | number | Number of mesh objects in the loaded scene |
materialVariants | string[] | Names of the model’s glTF material variants; empty when it has none. See showMaterialVariants |
materialVariantGroups | MaterialVariantGroup[] | 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) |
objects | ViewerObjectInfo[] | Every bindable object in the model; filled once handleObjectCatalog is passed to onObjectCatalog |
handleModelLoaded | (model: ViewerModelInfo) => void | Callback to pass to onModelLoaded |
handleObjectCatalog | (objects: ViewerObjectInfo[]) => void | Callback to pass to onObjectCatalog |
handleLoadError | (error: unknown) => void | Callback 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
| Name | Type | Description |
|---|---|---|
models | ModelViewerModelEntry[] | Entries with their current binding edits |
modelUrl | string | Active model URL; initially the first entry’s URL, or "" |
onModelChange | React state setter for string | Changes the active URL; also enables the built-in model switcher |
objectBindings | Record<string, ObjectBinding> | Stable empty record; entry bindings take precedence |
onObjectBindingsChange | (next: Record<string, ObjectBinding>) => void | Replaces 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 .