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:
bash
pip install vuer
Quick Start
python
import asynciofrom vuer import Vuer, VuerSessionfrom vuer.rtc.scene_store import SceneStorefrom vuer.schemas import Box, Sphere, DefaultSceneapp = Vuer()scene_store = SceneStore()@app.spawn(start=True)async def main(sess: VuerSession): # Subscribe session - auto-unsubscribes when context exits async with scene_store.subscribe(sess): # Set initial scene await scene_store.set_scene( children=[ Box(key="box-1", position=[0, 0, 0], color="red"), ] ) # Main loop - update scene reactively t = 0 while True: # Upsert updates existing nodes or adds new ones await scene_store.upsert @ Sphere( key="sphere-1", position=[2 * math.sin(t), 0, 2 * math.cos(t)], color="blue", ) t += 0.1 await asyncio.sleep(0.05)
API Reference
SceneStore
python
from vuer.rtc.scene_store import SceneStorestore = SceneStore()
Subscribe a session to receive scene updates. Use as an async context manager:
python
async with scene_store.subscribe(sess): # Session receives all updates here await scene_store.set_scene(...)# Session automatically unsubscribed - no memory leaks
scene_store = SceneStore()@app.spawn(start=True)async def handle_session(sess: VuerSession): async with scene_store.subscribe(sess): # New clients automatically receive current scene state # via set_scene or can query snapshot # Send current state to new client snapshot = scene_store.snapshot sess.set @ Scene(**snapshot.to_dict()) # Handle client events async for event in sess: if event.etype == "CLICK": # All subscribed sessions see this update await scene_store.upsert @ Box( key=f"box-{event.value['id']}", position=event.value['position'], )