voxolith

makeInstanceLayer()

Draw entities by reference instead of stamping them into the world: one GPU copy of each model, drawn wherever it is placed, at any yaw, mirrored, at fractional positions. Instances use palettes of their own, so a scene of instances has no colour budget, and nothing is written into the world's...

function makeInstanceLayer(target: InstanceTarget, opts?: InstanceLayerOptions): InstanceLayer;

Defined in: engine/src/instances.ts:831

Draw entities by reference instead of stamping them into the world: one GPU copy of each model, drawn wherever it is placed, at any yaw, mirrored, at fractional positions. Instances use palettes of their own, so a scene of instances has no colour budget, and nothing is written into the world's bricks.

Parameters

ParameterTypeDescription
targetInstanceTargetA renderer with instancing (Renderer implements InstanceTarget).
opts?InstanceLayerOptionsload reports uploads and placement into a load tracker; worker encodes the static set's models and bakes it on a scene worker when committed with commitAsync() (placement bakes only).

Returns

InstanceLayer

The layer; pass it to makeCrowd as instances for animated members.

Examples

const layer = makeInstanceLayer(renderer);
const oakBase = layer.palettes.of("oak", oak.model.roles);
layer.setStatic(sites.map((s) => ({ model: oak.model, x: s.x, y: s.y, z: s.z, yaw: s.yaw, base: oakBase })));
layer.commit();
// Off the main thread: encodes and the bake on a scene worker, adds paced over frames.
const worker = makeSceneWorker({ spawn: () => new Worker(new URL("./scene.worker.ts", import.meta.url), { type: "module" }) });
const layer = makeInstanceLayer(renderer, { load, worker });
layer.setStatic(scenery); // returns at once
await layer.commitAsync();
// Coarse first, one swap: placeholders generated at 20 vox/m drawn 5x enlarged in a 100 vox/m
// world, then the fine models. The coarse set draws until the fine one applies, and its models
// are released right after. Which models are coarse and when to swap is the app's choice.
await renderer.prepare({ scaled: true }); // with deferPipelines
layer.setStatic(sites.map((s) => ({ model: coarse[s.kind].model, scale: 5, ...s })));
await layer.commitAsync();
screen.ready();
layer.setStatic(sites.map((s) => ({ model: fine[s.kind].model, ...s })));
await layer.commitAsync();

On this page