svelte-brush (USSG) Reference
Universal Svelte Scene Graph (USSG) for Svelte 5 & SvelteKit 3 — supporting Babylon.js 9.0+, PixiJS v8.23+, and Three.js with optional native runtime bindings, zero runtime UI dependencies, and streaming asset preloading.
svelte-brush ships self-contained components bundled via @sveltejs/package into dist/ with full TypeScript declarations and optional
engine peer dependencies.Installation
pnpm add svelte-brush# Optional native 3D / 2D engines (bring your own peer dependencies)pnpm add -D @babylonjs/core pixi.js threePackage Entry Points
Native Engine Bridge + Physics Example
<script lang="ts"> import * as BABYLON from '@babylonjs/core'; import { Stage, Group, Mesh, RigidBody, Joint, Text, Asset, createBabylonAdapter } from 'svelte-brush'; const babylon = createBabylonAdapter({ runtime: BABYLON });</script><Stage adapter={babylon} backend="auto" physics={{ fluidEnabled: true, restitution: 0.85 }}> <Text text="Quantum Reactor" subtext="Babylon WebGPU + Pixi HUD" position={[0, 2.2, 0]} /> <Asset key="core-reactor" url="/assets/models/core-reactor.glb" kind="gltf" position={[2, 0.5, 0]} /> <Group autoRotate> <Mesh geometry="icosahedron" color="#ff6b35" /> </Group> <RigidBody id="buoy-a" bodyType="dynamic" collider="sphere" buoyancy={1.4} restitution={0.88} position={[-1.1, 0.6, 0]} /> <RigidBody id="buoy-b" bodyType="dynamic" collider="box" position={[1.1, 0.9, 0]} /> <Joint bodyA="buoy-a" bodyB="buoy-b" type="distance" restLength={2.1} stiffness={24} /></Stage>SvelteKit Streaming Asset Loader
// src/routes/+page.tsimport { preloadSceneAssets, serializeSceneForSSR } from 'svelte-brush/kit';import type { PageLoad } from './$types';export const load: PageLoad = async ({ fetch }) => { const preloadedBundle = await preloadSceneAssets( [ { key: 'core', url: '/assets/models/core-reactor.glb', kind: 'gltf' }, { key: 'env', url: '/assets/env/nebula-2k.hdr', kind: 'hdri' }, { key: 'atlas', url: '/assets/hud/controls-v8.json', kind: 'spritesheet' }, { key: 'boids', url: '/assets/shaders/boids-field.wgsl', kind: 'wgsl' } ], { bundleId: 'main-scene', fetchFn: fetch } ); return { preloadedBundle };};Layer 2 Semantic Primitives
Manages async WebGPU/WebGL2 initialization, ResizeObserver, offscreen auto-pause, and PhysicsWorld stepping.
Cross-engine hierarchical 3D transforms with deterministic HMR ResourceRegistry disposal.
2-substep solver with shape-specific narrowphase collisions, rotational inertia, Coulomb friction spin, Hookean springs, and Archimedes wave tank buoyancy.
Connects two RigidBody nodes by ID or name with impulse-damped distance, ball-socket, or angular hinge constraints and live canvas connector overlays.
Billboards 3D scene labels and renders preloaded/streamed binary GLB, HDRI, WGSL, and spritesheet assets.
Multi-pass hybrid composition (e.g. Pixi v8 HUD over Babylon/Three 3D world) blocking 3D raycasts behind 2D HUD hits.
Hardware GPUComputePipeline dispatcher when WebGPU is active + zero-dependency Scene Tree & telemetry Inspector overlay.
Runes & Hooks
Returns the reactive StageController instance (`sceneReady`, `backend`, `telemetry`, `nodes`, `physics`, `registry`).
Registers a priority-ordered per-frame callback tied to Svelte 5 $effect teardown.
Runes-backed `{ position, rotation, scale }` state synchronized cleanly with render loops.
Frame-accurate spring interpolation running at priority -100 inside FrameScheduler.
Accesses the reactive PhysicsWorld (`restitution`, `fluidDensity`, `fluidLevel`, `joints`, `setBackend(PhysicsBackend)`, `applyImpulseAll`).
Adapts particle & workgroup counts dynamically across WebGPU and WebGL2 fallback.
Native Engine Bridge Hooks
Passes shader descriptors on <Mesh shader={...} /> to Babylon ShaderMaterial, Three ShaderMaterial, and Pixi dual
WGSL/GLSL shaders.
Routes <Asset kind="gltf" /> into Babylon SceneLoader.ImportMeshAsync, Three GLTFLoader, and Pixi Assets.load with fallback placeholders until hydrated.
Delegates pointer picking via adapter.raycast() to Babylon scene.pick and Three Raycaster, and swaps TS physics for WASM engines via physics.setBackend(PhysicsBackend).