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
| Parameter | Type | Description |
|---|---|---|
target | InstanceTarget | A renderer with instancing (Renderer implements InstanceTarget). |
opts? | InstanceLayerOptions | load 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
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();makeChunkedWorld()
Build a world a chunk at a time around a focus point and free chunks that fall out of range, so load time and memory scale with the view rather than the world. Chunks are square columns over the full height, built nearest-first within a time budget.
makeLoadTracker()
Make a load tracker: loaders report phases into it, and the app reads it to draw its own loading screen and to time the load.