Skip to Content
HooksuseObjectVisibility

useObjectVisibility

A stateless utility hook for controlling object visibility outside the viewer.

useObjectVisibility does not own its own copy of objectBindings — the consumer owns the state and passes both the current value and its setter. The hook’s methods call the setter directly, so the hook and the viewer stay in sync automatically.

Usage

import { useObjectVisibility } from "@liveroom/react-immersive"; const [objectBindings, setObjectBindings] = useState(initialBindings); const { hiddenObjects, hiddenObjectIds, hideObject, showObject, toggleObjectVisibility, isObjectHidden, clearHiddenObjects, } = useObjectVisibility(objectBindings, setObjectBindings); <ModelViewer objectBindings={objectBindings} onObjectBindingsChange={setObjectBindings} ... />

Parameters

NameTypeDescription
objectBindingsRecord<string, ObjectBinding>The current bindings map (owned by consumer)
setObjectBindings(next: Record<string, ObjectBinding>) => voidState setter from useState

Returns

NameTypeDescription
hiddenObjectsRecord<string, ObjectBinding>Derived map of hidden bindings
hiddenObjectIdsstring[]IDs of currently hidden bindings
hideObject(id: string) => voidHide a binding by key, binding.id, or binding.modelObjectId
showObject(id: string) => voidShow a binding
toggleObjectVisibility(id: string) => voidToggle visibility of a binding
isObjectHidden(id: string) => booleanCheck if a binding is currently hidden
clearHiddenObjects() => voidShow all objects

Example

<button onClick={() => toggleObjectVisibility("some-object-id")}> Toggle Visibility </button> <button onClick={() => clearHiddenObjects()}> Show All </button> <p>Hidden: {hiddenObjectIds.join(", ")}</p>