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
| Parameter | Type |
|---|---|
opts? | ServeSceneOptions |
Returns
void
Example
// scene.worker.ts
import { serveScene } from "@voxolith/engine/worker";
serveScene({ cache: import.meta.env.DEV ? undefined : "voxolith-scene" });~~servePlacement()~~
Serve placement bakes on this worker: serveScene under its older name (the worker then encodes models too, when asked).
unpackEntity()
Rebuild an entity from packEntity's output. Every array is copied out of bytes, unless opts.views: then a sparse model's bricks are views into bytes (which the entity then owns; one allocation per brick rather than one copy each, which is what the generator pool does with the packed entities its...