SceneStore - Reactive Scene Graph Management
The SceneStore class provides a reactive store for managing 3D scene graph state and synchronizing it across multiple connected VuerSession clients.
Overview
SceneStore solves a common problem in multi-client visualization: maintaining consistent scene state across all connected browsers while allowing the Python backend to track and modify the scene.
Key features:
- Reactive updates: Changes automatically propagate to all subscribed sessions
- Snapshot access: Get the current scene state at any time
- Auto-cleanup: Context manager pattern prevents memory leaks from disconnected sessions
- Familiar API: Uses the same
@operator pattern as VuerSession
Installation
SceneStore is included in the vuer package:
Quick Start
API Reference
SceneStore
Properties
| Property | Type | Description |
|---|---|---|
snapshot | SceneState | Returns a deep copy of the current scene state |
upsert | _UpsertProxy | Proxy for upsert operations with @ operator |
add | _AddProxy | Proxy for add operations with @ operator |
update | _UpdateProxy | Proxy for update operations with @ operator |
remove | _RemoveProxy | Proxy for remove operations with @ operator |
Methods
subscribe(session: VuerSession) -> SubscriptionContext
Subscribe a session to receive scene updates. Use as an async context manager:
async set_scene(...)
Set the entire scene state:
async upsert_async(*nodes, to=None)
Update existing nodes or add new ones:
async add_async(*nodes, to=None)
Add new nodes to the scene:
async update_async(*updates)
Update properties of existing nodes:
async remove_async(*keys)
Remove nodes by key:
get_node(key: str) -> Optional[SceneNode]
Find a node by key:
has_node(key: str) -> bool
Check if a node exists:
Using the @ Operator
SceneStore supports the same @ operator pattern as VuerSession:
Usage Patterns
Multi-Session Synchronization
Conditional Updates
Cleanup Pattern
The context manager ensures sessions are properly unsubscribed even if errors occur: