API Documentation v0.1.0

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.

Back to Live Studio
Zero Runtime UI Dependencies
svelte-brush ships self-contained components bundled via @sveltejs/package into dist/ with full TypeScript declarations and optional engine peer dependencies.

Installation

Terminal
bash
pnpm add svelte-brush
# Optional native 3D / 2D engines (bring your own peer dependencies)
pnpm add -D @babylonjs/core pixi.js three

Package Entry Points

svelte-brush
Full bundle: Layer 2 primitives, Layer 1 proxies, PhysicsWorld, WebGPU compute, & Kit helpers.
svelte-brush/core
RenderAdapter, StageController, ResourceRegistry, FrameScheduler, PhysicsWorld, PhysicsBackend interface, WebGPUComputeRunner.
svelte-brush/babylon
createBabylonAdapter(), injectBabylonScene(), <Babylon.*> dynamic proxy namespace.
svelte-brush/pixi
createPixiAdapter(), createPixiDualShader() (WGSL+GLSL), <Pixi.*> dynamic proxy namespace.
svelte-brush/three
createThreeAdapter(), createThreeTslBinding(), migrateThrelteCode(), <Three.*> proxy namespace.
svelte-brush/kit
preloadSceneAssets(), createAssetStore(), parseAssetPayload(), detectWebGPUCapability(), serializeSceneForSSR().

Native Engine Bridge + Physics Example

NativeScene.svelte
svelte
<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

+page.ts
typescript
// src/routes/+page.ts
import { 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

<Stage>
adapter, backend, forceFallback, sharedDevice, interactiveOrbit, physics, onready, onnodeclick

Manages async WebGPU/WebGL2 initialization, ResizeObserver, offscreen auto-pause, and PhysicsWorld stepping.

<Mesh> & <Group>
geometry, position, rotation, scale, shader, autoRotate, rotationSpeed, physics

Cross-engine hierarchical 3D transforms with deterministic HMR ResourceRegistry disposal.

<RigidBody>
bodyType, collider ("sphere" | "box" | "cylinder"), velocity, angularVelocity, restitution, friction, buoyancy, tetherTarget, tetherStiffness, oncollide

2-substep solver with shape-specific narrowphase collisions, rotational inertia, Coulomb friction spin, Hookean springs, and Archimedes wave tank buoyancy.

<Joint>
bodyA, bodyB, type ("distance" | "ball-socket" | "hinge"), anchorA, anchorB, restLength, stiffness, damping, axis

Connects two RigidBody nodes by ID or name with impulse-damped distance, ball-socket, or angular hinge constraints and live canvas connector overlays.

<Text> & <Asset>
text, subtext, fontSize, align, key, url, kind (gltf | hdri | spritesheet | texture | wgsl)

Billboards 3D scene labels and renders preloaded/streamed binary GLB, HDRI, WGSL, and spritesheet assets.

<Layer> & <Sprite>
adapter, mode ("2d-hud" | "3d-overlay"), blockPointerEvents, text, subtext, badge

Multi-pass hybrid composition (e.g. Pixi v8 HUD over Babylon/Three 3D world) blocking 3D raycasts behind 2D HUD hits.

<Compute> & <Inspector>
mode ("galaxy" | "boids" | "vortex" | "wave"), particles, workgroups, wgsl, bind:open

Hardware GPUComputePipeline dispatcher when WebGPU is active + zero-dependency Scene Tree & telemetry Inspector overlay.

Runes & Hooks

useStage()

Returns the reactive StageController instance (`sceneReady`, `backend`, `telemetry`, `nodes`, `physics`, `registry`).

useTick(cb, priority)

Registers a priority-ordered per-frame callback tied to Svelte 5 $effect teardown.

useTransform(init)

Runes-backed `{ position, rotation, scale }` state synchronized cleanly with render loops.

useSpring(target, opts)

Frame-accurate spring interpolation running at priority -100 inside FrameScheduler.

usePhysics()

Accesses the reactive PhysicsWorld (`restitution`, `fluidDensity`, `fluidLevel`, `joints`, `setBackend(PhysicsBackend)`, `applyImpulseAll`).

useCompute(opts)

Adapts particle & workgroup counts dynamically across WebGPU and WebGL2 fallback.

Native Engine Bridge Hooks

Custom WGSL / GLSL Shaders

Passes shader descriptors on <Mesh shader={...} /> to Babylon ShaderMaterial, Three ShaderMaterial, and Pixi dual WGSL/GLSL shaders.

Live GLTF & Asset Loading

Routes <Asset kind="gltf" /> into Babylon SceneLoader.ImportMeshAsync, Three GLTFLoader, and Pixi Assets.load with fallback placeholders until hydrated.

Native Raycast & PhysicsBackend

Delegates pointer picking via adapter.raycast() to Babylon scene.pick and Three Raycaster, and swaps TS physics for WASM engines via physics.setBackend(PhysicsBackend).