Skip to main content

Overview

The useViewer 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
Persisted: Yes
'light' | 'dark'
Visual theme for the viewer.
  • 'light' - Light background (#ffffff)
  • 'dark' - Dark background (#1f2433)
Persisted: Yes

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
Persisted: Yes
'up' | 'cutaway' | 'down'
Wall display mode.
  • 'up' - Walls fully visible (default)
  • 'cutaway' - Walls cut away for interior view
  • 'down' - Walls hidden
Persisted: Yes

Visibility Toggles

boolean
Whether to display scan data/point clouds.Default: true
Persisted: Per-project (in projectPreferences)
boolean
Whether to display construction guides and measurements.Default: true
Persisted: Per-project (in projectPreferences)
boolean
Whether to display the reference grid.Default: true
Persisted: 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 to localStorage under the key 'viewer-preferences':
  • cameraMode
  • theme
  • levelMode
  • wallMode
  • projectPreferences
Other state (like selection, hoveredId) is ephemeral and resets on page reload.

Examples

Selection Management

Display Controls

Theme Switcher

Multi-Select Items