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
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
pending | readonly | number | Jobs (bakes, and on a scene worker encodes) asked for and not yet settled. | PlacementWorker.pending | engine/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
| Parameter | Type |
|---|---|
input | PlacementInput |
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
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
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
| Parameter | Type |
|---|---|
key | number |
Returns
void
Inherited from
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
| Parameter | Type | Description |
|---|---|---|
src | ModelSource | The model, as Renderer.addModel takes it. |
opts? | SceneEncodeOptions | Abort, 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
| Parameter | Type |
|---|---|
encoded | EncodedModel |
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
| Parameter | Type |
|---|---|
result | PlacementBake | EncodedModel |
Returns
boolean
Inherited from
has()
has(key: number): boolean;Defined in: engine/src/worker/scene.ts:484
Whether a model key has been sent (and not dropped).
Parameters
| Parameter | Type |
|---|---|
key | number |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
model | PlacementModel |
Returns
void
Inherited from
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
| Parameter | Type |
|---|---|
encoded | EncodedModel |
keys | PlacementKeys | readonly PlacementKeys[] |
Returns
void