voxolith

SceneWorker

A worker that encodes models for the GPU and bakes static placements, from makeSceneWorker. Give it to makeInstanceLayer(target, { worker }), which does both for its static set; the methods are there for hosts that drive encodeModel / Renderer.addEncodedModel and the placement bake themselves.

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

Extends

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
pendingreadonlynumberJobs (bakes, and on a scene worker encodes) asked for and not yet settled.PlacementWorker.pendingengine/src/worker/scene.ts:506

Methods

bake()

bake(input: PlacementInput, opts?: object): Promise<PlacementBake>;

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

Bake a static set on the worker. Every model the input names must have been registered. Rejects when the bake fails, the worker dies, the worker is destroyed, or signal aborts (with signal.reason, an AbortError unless given another). Aborting skips the bake if the worker has not started it; one that has started runs to the end and its result is dropped.

onProgress hears the bake's progress from the worker while it runs: done of total opaque work units (use done / total as a fraction), first (0, total), last (total, total), about every 50 ms, never decreasing. It stops once the bake settles, is aborted or the worker is destroyed.

A worker with a cache (serveScene({ cache })) answers from it when it holds this bake (by a digest of the input and of the models' placement data): no progress then, and PlacementWorker.fromCache is true for the result. cache: false skips it both ways.

Parameters

ParameterType
inputPlacementInput
opts?{ cache?: boolean; onProgress?: (done: number, total: number) => void; signal?: AbortSignal; }
opts.cache?boolean
opts.onProgress?(done: number, total: number) => void
opts.signal?AbortSignal

Returns

Promise<PlacementBake>

Inherited from

PlacementWorker.bake


destroy()

destroy(): Promise<void>;

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

Stop the worker: pending jobs reject at once and the worker is unusable afterwards. A worker still running a job is terminated at once; an idle one first finishes its cache writes (up to closeTimeoutMs), so what it just made is there next visit. Resolves when the worker has been terminated; callers need not wait (and should not make a first frame wait for it).

Returns

Promise<void>

Inherited from

PlacementWorker.destroy


drop()

drop(key: number): void;

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

Forget a model key on the worker, after its model was removed. Unknown keys are ignored.

Parameters

ParameterType
keynumber

Returns

void

Inherited from

PlacementWorker.drop


encode()

encode(src: ModelSource, opts?: SceneEncodeOptions): Promise<EncodedModel>;

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

Encode a model on the worker (encodeModel), for Renderer.addEncodedModel. The call returns at once: a sparse model's bricks are packed and sent in chunks, one task each, and a dense model's arrays are copied as postMessage copies them. Don't change the model until the promise settles. Rejects when the encode fails (more than 32 parts, parts without dense data), the worker dies or is destroyed, or signal aborts.

A source's partBoxes object is put back on the result in place of the worker's copy, so models added with the same boxes object still share poses (ModelSource.partBoxes).

Parameters

ParameterTypeDescription
srcModelSourceThe model, as Renderer.addModel takes it.
opts?SceneEncodeOptionsAbort, progress, and whether the worker keeps the placement data.

Returns

Promise<EncodedModel>

The encoded model, its arrays transferred from the worker.


forget()

forget(encoded: EncodedModel): void;

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

Let the worker drop what it kept of an encoding that will not be registered. Harmless otherwise.

Parameters

ParameterType
encodedEncodedModel

Returns

void


fromCache()

fromCache(result: PlacementBake | EncodedModel): boolean;

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

Whether a bake (or an encoding, on a scene worker) this worker returned came from its cache.

Parameters

ParameterType
resultPlacementBake | EncodedModel

Returns

boolean

Inherited from

PlacementWorker.fromCache


has()

has(key: number): boolean;

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

Whether a model key has been sent (and not dropped).

Parameters

ParameterType
keynumber

Returns

boolean

Inherited from

PlacementWorker.has


register()

register(model: PlacementModel): void;

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

Send a model to the worker (Renderer.placementModel), once per key: a known key is not sent again.

Parameters

ParameterType
modelPlacementModel

Returns

void

Inherited from

PlacementWorker.register


registerEncoded()

registerEncoded(encoded: EncodedModel, keys: PlacementKeys | readonly PlacementKeys[]): void;

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

Register a model for placement once the renderer has added it (key, poseKey and scale from Renderer.placementModel(id) after addEncodedModel; pass scale too, or the worker bakes a scaled model at scale 1). An encoding this worker kept (keepPlacement) is registered from the worker's own copy, so only the keys travel; any other is sent whole (placementModelOf, as PlacementWorker.register). Once per key.

One encoding added at several scales (addEncodedModel(e, { scale }) once per scale) is several renderer models: pass all their keys in one call, so a kept encoding still sends only keys. The worker forgets its copy after this call, so a scale added later is sent whole.

Parameters

ParameterType
encodedEncodedModel
keysPlacementKeys | readonly PlacementKeys[]

Returns

void

On this page