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.

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>;