voxolith

serveScene()

Serve model encodes and placement bakes on this worker until it is terminated: the worker side of makeSceneWorker. Encodes run the renderer's encodeModel; bakes run a PlacementBaker holding the registered models. Each job is answered with its result, buffers transferred, after progress messages...

function serveScene(opts?: ServeSceneOptions): void;

Defined in: engine/src/worker/scene.ts:193

Serve model encodes and placement bakes on this worker until it is terminated: the worker side of makeSceneWorker. Encodes run the renderer's encodeModel; bakes run a PlacementBaker holding the registered models. Each job is answered with its result, buffers transferred, after progress messages posted while it runs (so the main thread hears them before it returns).

Jobs run one at a time in the order asked, and the worker yields between them, so a cancel for a job that has not started skips it. A job that has started runs to the end: it is one synchronous call. A stale result costs worker time only; the main thread drops it.

With cache, results are kept in IndexedDB and served from there next time (see ServeSceneOptions.cache), salted with this worker's URL, so a production build (which hashes the URL) never serves what older renderer code made. Writes finish after the result is posted; the main side's destroy() asks the worker to finish them (close) first.

Parameters

ParameterType
opts?ServeSceneOptions

Returns

void

Example

// scene.worker.ts
import { serveScene } from "@voxolith/engine/worker";
serveScene({ cache: import.meta.env.DEV ? undefined : "voxolith-scene" });

On this page