Overview
TheuseViewer hook provides centralized state management for the 3D viewer. It’s built with Zustand and includes persistence for user preferences like camera mode, theme, and display settings.
Import
Usage
State Properties
Selection
SelectionPath
Current selection state in the scene hierarchy.
string | null
ID of the currently hovered node or zone.
Camera & Rendering
'perspective' | 'orthographic'
Current camera projection mode.
'perspective'- Standard perspective camera (default)'orthographic'- Orthographic camera for technical drawings
'light' | 'dark'
Visual theme for the viewer.
'light'- Light background (#ffffff)'dark'- Dark background (#1f2433)
Display Modes
'stacked' | 'exploded' | 'solo' | 'manual'
How levels are displayed vertically.
'stacked'- Levels stacked normally (default)'exploded'- Levels separated with gaps for clarity'solo'- Only selected level visible'manual'- Custom positioning
'up' | 'cutaway' | 'down'
Wall display mode.
'up'- Walls fully visible (default)'cutaway'- Walls cut away for interior view'down'- Walls hidden
Visibility Toggles
boolean
Whether to display scan data/point clouds.Default:
Persisted: Per-project (in
truePersisted: Per-project (in
projectPreferences)boolean
Whether to display construction guides and measurements.Default:
Persisted: Per-project (in
truePersisted: Per-project (in
projectPreferences)boolean
Whether to display the reference grid.Default:
Persisted: Per-project (in
truePersisted: Per-project (in
projectPreferences)Project Settings
string | null
Currently active project ID. Used to load project-specific preferences.
Record<string, ProjectPrefs>
Per-project settings for scans, guides, and grid visibility.Persisted: Yes
Advanced State
Outliner
Direct references to selected and hovered Three.js Object3D instances. Used by the outline post-processing effect.Note: This is manipulated directly (no setter) for performance.
(() => Promise<void>) | null
Export function reference. Set by export utilities.
boolean
Whether the camera is currently being dragged. Used to disable certain interactions during camera movement.
Methods
Selection Methods
(updates: Partial<SelectionPath>) => void
Update the selection state. Automatically resets child selections when parent changes.Hierarchy Guard: When selecting a parent node, child selections are automatically cleared unless explicitly provided in the update.
() => void
Clear all selections.
(id: string | null) => void
Set the currently hovered node ID.
Camera & Display Methods
(mode: 'perspective' | 'orthographic') => void
Switch between perspective and orthographic camera modes.
(theme: 'light' | 'dark') => void
Change the viewer theme.
(mode: 'stacked' | 'exploded' | 'solo' | 'manual') => void
Change how levels are displayed.
(mode: 'up' | 'cutaway' | 'down') => void
Change wall display mode.
Visibility Methods
(show: boolean) => void
Toggle scan visibility. Automatically saves to project preferences.
(show: boolean) => void
Toggle guide visibility. Automatically saves to project preferences.
(show: boolean) => void
Toggle grid visibility. Automatically saves to project preferences.
Project Methods
(id: string | null) => void
Set the active project ID and load its preferences.Note: When a new project is loaded, the hook automatically restores that project’s scan/guide/grid visibility settings.
Advanced Methods
(fn: (() => Promise<void>) | null) => void
Set the scene export function reference.
(dragging: boolean) => void
Set camera dragging state.
TypeScript Signatures
Persistence
The following state is automatically persisted tolocalStorage under the key 'viewer-preferences':
cameraModethemelevelModewallModeprojectPreferences
selection, hoveredId) is ephemeral and resets on page reload.
Examples
Selection Management
Display Controls
Theme Switcher
Multi-Select Items
Related
- Viewer Component - Main 3D viewer component
- @pascal-app/core - Core scene graph and node types