InstancedModel
InstancedModel draws a registered model once for each placement in a list, in one draw call for each mesh in the model. Use it for a forest, a field of coins or a scree of rocks: things that stand many times and do nothing on their own. It spawns no entity, so a copy has no behaviours and no transform a system moves. In a Landscape each copy is solid by its model’s collider, as Collision says. A thing that moves or is picked up is an <Entity model>.
A placement is a plain transform, so any code can produce the list:
position: the point the model’s lowest point stands on. The model is seated on its own bounds, as the scatter kit is, so a model centred on its origin still stands on the ground. On a hillside,findGroundHeightgives the ground’s height under x and z.turn: radians about y, applied afterrotation. It defaults to 0. InstancedModel draws the file unturned, so at 0 its front faces +z, where an<Entity model>turns it to face -z.rotation: the copy’s own rotation, as an Entity’srotationtakes it: Euler angles in radians or a unit quaternion. It defaults to upright. Lay a copy on its side says how it seats.scale: a multiple of the model’s own size, one number for every axis or one for each. It defaults to 1.tint: a colour the copy is multiplied by. Copies without one keep the model’s own colours.
Its props are in InstancedModelProps and a placement’s fields in InstancePlacement.
Unity’s Graphics.RenderMeshInstanced, Unreal’s Instanced Static Mesh and Godot’s MultiMeshInstance3D take the same input: one mesh and a list of transforms.
Each copy outside a camera’s view costs no draw, as Culling says. A far copy can draw a cheaper model, as Levels of detail says, and cross-fade into it, as Cross-fade says. Low clutter can shrink away before its cull, as Shrink at the cull says. A headless scene draws nothing and loads no model.
Lay a copy on its side
Section titled “Lay a copy on its side”A toppled crate, a boat keel up or a leaning signpost takes a rotation. The rotation turns the copy about its file’s origin in the copy’s own axes, and turn then turns it about world up. A yaw alone goes in turn, which a scatter can hash, and rotation holds the pitch and the roll.
A rotated copy rises until the lowest corner of its model’s hull stands at position’s height, so you never need the model’s height to seat it. The hull is the one its manifest baked, or the corners of its box where the manifest kept none. position’s x and z place the file’s origin, as they do for turn, so a copy laid on its side is not centred on them.
The hull’s lowest corner sits a hair above the mesh where the bake simplified the hull. A model registered as a bare url has no hull, so its draw seats on the loaded file’s box. A solid copy of such a model is refused in development and stands no solid, since the room has no file to measure: register the model from its manifest, or set collider={false}.
Every detail level seats on the nearest model’s hull, so a copy keeps its height as it changes level. An idleMotion pivot is measured from the copy’s foot and turns with it. To animate a pose, use idleMotion or an Entity: a rotation changed in the placements seats the copy again each time.
Unity’s Transform.rotation, Godot’s Node3D.rotation and Unreal’s rotator all give an instance a full rotation, and Unity’s terrain trees take a yaw alone. The engine takes both, so the common case stays one number. Unreal’s editor seats a mesh’s bounds on the floor below as a separate command; here it is how a rotated placement stands.
These crates lie toppled round a stall. The engine’s tests mount this file:
import { InstancedModel, type InstancePlacement } from "@spawnite/engine";
// The wreck of a market stall: one crate upright, one on its side, one// upside down and one leaning back, in one draw. Each stands on the// ground at its position however it is turned.
// At module scope: a new list places every copy again.const crates: InstancePlacement[] = [ { position: [0, 0, 0] }, // On its side, then turned to face the road. { position: [1.5, 0, 0], rotation: [0, 0, Math.PI / 2], turn: 0.4 }, { position: [3, 0, 0], rotation: [Math.PI, 0, 0] }, { position: [0.8, 0, 1.2], rotation: [-0.6, 0, 0] },];
export function ToppledCrates() { return <InstancedModel model="crate" placements={crates} />;}Materials
Section titled “Materials”material changes what every copy wears, as an Entity’s material does: a function handed each of the file’s materials, which returns the one the copies wear in its place, asked once for each of the file’s materials and kept. Left out, the copies wear the material the model registered with, or the file’s own. A mesh drawn with several materials asks the function for each of them. Return a new material, such as a clone, since the original is the loaded file’s; what the function returns is the game’s to dispose. The copies of one batch are drawn as one, so a see-through material draws them in one pass, not sorted one by one. For a colour that differs per copy, give each placement a tint. For leaf and needle cards, use foliage.
These firs turn to autumn. The engine’s tests mount this file:
import { InstancedModel, type InstancePlacement, type ModelMaterial,} from "@spawnite/engine";import { Color, MeshStandardMaterial } from "three";
// A row of firs turned to autumn: every copy wears its file's material// with its colour pulled toward orange.
const orange = new Color("#d9822b");
/** A copy of the file's material, since the original is the loaded * file's, which every other draw of the file wears. Made once, outside the * component: InstancedModel asks it once for each of the file's * materials. */const autumn: ModelMaterial = (original) => { const turned = original.clone(); if (turned instanceof MeshStandardMaterial) turned.color.lerp(orange, 0.6); return turned;};
const firs: InstancePlacement[] = Array.from({ length: 50 }, (_, index) => ({ position: [index * 3, 0, -10], turn: index,}));
export function AutumnTreeline() { return <InstancedModel model="fir" placements={firs} material={autumn} />;}Levels of detail
Section titled “Levels of detail”detailLevels lists cheaper models a copy draws once the camera is far enough away, such as a tree of a few crossed cards past 60 m. Each level names a model and the distance in metres from which a copy draws it. A copy draws the level with the largest distance it is past, and model when it is nearer than all of them. A level takes a material of its own; left out, it wears the one its model registered with, or the file’s own.
cullDistance is where copies stop drawing at all, such as ferns past 40 m. Every level’s distance must be a finite number above 0, shared with no other level and short of the cull distance. In development, a list that breaks this throws when the scene mounts, naming the level and the fix.
Each pass measures a copy’s distance from the camera that draws it. A second camera, such as a screenshot’s, picks the levels from where it stands. The sun’s shadow takes the view camera’s pick, so a shadow matches the copy it falls from. A camera’s distances are measured again once it has moved a metre, so a copy switches within a metre of its distance, and a head’s bob does not flick it from one level to the other.
Each level draws in one batch per mesh, so two levels cost up to twice the draws of one, and a level with no copies in a pass skips its draw. Build the levels to the same height and foot, since a copy swaps from one to the other in place. Set fadeWidth to cross-fade them, as Cross-fade says.
The distance is measured in the world to the copy’s foot, so a scaled parent group scales it too, and ignores the copy’s own scale, so a copy three times the size switches at the same distance. A lens zoomed in divides the distance a level is chosen by, as three’s LOD does, and the cull keeps to the distance itself. Changing the list in a render writes no copy again unless a level’s model or distance changed, so a list written inline costs nothing.
Three’s LOD and drei’s <Detailed> switch one object by its distance. Unity’s LODGroup and Unreal’s static mesh levels switch by the share of the screen a mesh covers, and Godot’s visibility ranges by distance. detailLevels switches by distance, per copy for every copy in the batch.
This forest’s far spruces draw as cards. The engine’s tests mount this file:
import { InstancedModel, type DetailLevel, type InstancePlacement,} from "@spawnite/engine";
// A forest down a valley: each spruce within 60 m of the camera draws the// full model, and past it a few crossed cards of the same size and foot.
const levels: DetailLevel[] = [{ model: "spruce-far", distance: 60 }];
const spruces: InstancePlacement[] = Array.from( { length: 400 }, (_, index) => ({ position: [(index % 20) * 8, 0, -Math.floor(index / 20) * 8], turn: index, }),);
export function FarForest() { return ( <InstancedModel model="spruce" placements={spruces} detailLevels={levels} /> );}Cross-fade
Section titled “Cross-fade”fadeWidth is the metres over which a copy cross-fades from one level into the next, so a tree does not pop as the player walks. The fade ends at the level’s distance: from there on, the level draws whole. A copy also fades out before cullDistance, so nothing draws from the cull on. It fades over the same width unless cullFadeWidth gives the cull a width of its own, and cullFadeWidth={0} culls with no fade. fadeWidth defaults to 0, a switch with no fade, and cullFadeWidth takes its value.
Leave it at 0, and leave out cullDistance, for anything a character can hide behind in a game where players meet. Mid-fade each level draws half its pixels, so a gap opens where the two levels’ outlines differ, and a culled copy hides nobody from a player farther off. Litter, stones and short herbs may fade and cull.
Inside the band both levels draw the copy, and a fixed noise over the screen gives each pixel to one of them, by how far into the band the copy stands. The copy stays opaque, writes depth and casts its shadow, which fades with it. Where the two levels’ silhouettes differ, the edges that only one level covers thin out as it fades, as in any dithered fade. While the camera stands still, a copy inside the band shows the noise’s pattern, so keep the band to a few metres.
The width must fit the room before each switch: no wider than the nearest level’s distance or the gap between two levels, and the cull’s no wider than the cull distance. In development, a width that breaks this throws when the scene mounts, as does a width with no level and no cull to fade. The fade joins the shader at three’s #include <common> and #include <begin_vertex> lines and at its main line. A material function that patches a standard material keeps the fade while it keeps those lines. A material without them, such as your own ShaderMaterial, draws both levels whole inside the band, and the console says so once.
Unity’s LODGroup cross-fades with fadeTransitionWidth, a share of each level’s range just before its switch, as this band sits. Godot’s visibility ranges fade over margins in metres, and Unreal’s dithered LOD transition fades over a moment of time rather than a distance.
These spruces cross-fade to cards and fade out at the far side of the valley. The engine’s tests mount this file:
import { InstancedModel, type DetailLevel, type InstancePlacement,} from "@spawnite/engine";
// A forest down a valley whose spruces turn to crossed cards without a// pop: each copy cross-fades over the 8 m before 60 m, and fades out over// the 8 m before 150 m.
const levels: DetailLevel[] = [{ model: "spruce-far", distance: 60 }];
const spruces: InstancePlacement[] = Array.from( { length: 400 }, (_, index) => ({ position: [(index % 20) * 8, 0, -Math.floor(index / 20) * 8], turn: index, }),);
export function FadingForest() { return ( <InstancedModel model="spruce" placements={spruces} detailLevels={levels} cullDistance={150} fadeWidth={8} /> );}Shrink at the cull
Section titled “Shrink at the cull”cullFadeMode={CullFadeMode.Shrink} ends each copy by shrinking it into the ground over the last cullFadeWidth metres before cullDistance. Each copy shrinks over a quarter of that band, starting at a distance its spot picks, so the copies thin out one by one rather than as a ring round the player. A dither keeps a copy’s size and thins it pixel by pixel, and a still camera shows its pattern. A shrink draws whole pixels, so nothing crawls as the camera moves.
Use it for low clutter that can hide no character: litter, pebbles, chips and low ground cover, lower than a crouched character. A fern a player could crouch in, a bush or a rock keeps fadeWidth 0 and no cullDistance: a player hidden in it from close by must stay hidden from far away.
A shrink needs its own cullFadeWidth, such as a third of cullDistance, and a cullDistance to end at. Without either, the props do not typecheck, and in development a band wider than cullDistance throws when the scene mounts. The levels keep their dither: fadeWidth still cross-fades them, and a shrink of one level into the next would show both at half size.
A copy shrinks evenly toward the middle of its footprint at its lowest point, so it lowers into the ground and narrows at once, as the grass’s blades and the scatter’s bushes do. A copy’s rank comes from its placement’s x and z, so a list made again from the map’s seed shrinks the same copies first, and copies stacked at one spot go together. The band is measured in metres from the camera, as the cull is, so under a zoomed lens every level shrinks at the cull.
These pine chips thin out over the last 12 m before 30 m. The engine’s tests mount this file:
import { CullFadeMode, hashNumbers, InstancedModel, type InstancePlacement,} from "@spawnite/engine";
// Pine chips over a forest floor that thin out round the player rather// than end at a line: over the last 12 m before 30 m, each chip shrinks// into the ground at a distance of its own. A chip hides nobody, so// nothing a player looks for draws differently by distance.
// At module scope: a new list sorts and writes every copy again.const chips: InstancePlacement[] = Array.from({ length: 2500 }, (_, index) => ({ position: [ (index % 50) * 1.6 + hashNumbers(index, 0) * 1.2 - 40, 0, -Math.floor(index / 50) * 1.6 - hashNumbers(index, 1) * 1.2, ], turn: hashNumbers(index, 2) * Math.PI * 2,}));
export function ShrinkingLitter() { return ( <InstancedModel model="pine-chips" placements={chips} collider={false} castShadow={false} cullDistance={30} cullFadeWidth={12} cullFadeMode={CullFadeMode.Shrink} /> );}A shrinking copy’s shadow shrinks with it within the cascades. It casts nothing into the far shadow map, as static={false} does, so no whole shadow stays where a copy has gone. A pick meets a shrinking copy as it draws, and none that has shrunk to nothing.
Unreal’s foliage fades an instance between Start Cull Distance and End Cull Distance through PerInstanceFadeAmount, and leaves the look to a material: a dither, or a world-position offset that shrinks it. Unity’s LODGroup dithers its last level out, and Godot’s visibility ranges fade a whole node by alpha. A MultiMeshInstance3D takes one range for all its instances.
Culling
Section titled “Culling”A copy outside a camera’s view costs no draw. Each pass, the view’s and the sun’s shadow’s alike, tests the copies against its own camera, through a tree over the copies’ bounds, and keeps the list while its camera stands still. A copy behind the player but inside a box of the sun’s cascades still casts its shadow. The test changes no pixel: a copy it leaves out is one the camera could not see.
perInstanceFrustumCulled={false} turns the view’s test off. A model with detailLevels, a cullDistance or a fadeWidth still measures them from the camera that draws, and one without draws as three’s InstancedMesh does. Use it for a material that moves its vertices past the model’s bounds, such as wind sway, which the test would cut short at the screen’s edge. The whole batch is still skipped while all of it is out of view, as three’s InstancedMesh is.
Each culled pass costs some CPU in each pass whose camera moved or turned: a walk of the tree for each mesh of each level, or with the test off, a loop over every copy. Under WebGPURenderer, culling, the cross-fade and the shrink are off, as WebGPU says.
The test is on for every model because the engines built for large worlds cull each instance with no switch a creator sees: Unreal’s hierarchical instanced static meshes and Unity’s GPU Resident Drawer. three culls an Object3D whole with frustumCulled, and Godot’s MultiMeshInstance3D culls the whole multimesh.
Idle motion
Section titled “Idle motion”idleMotion moves every copy as IdleMotion moves what it holds, a float or a sway, in the map’s idleMotion shape, so a row of lanterns or buoys stays one draw. Its pivot is in a copy’s own metres from its foot, before its scale. Each copy starts its cycle from where it stands, unless the motion names a seed, and a float rides the sea it rests on. Only the drawing moves: a copy’s collider stays where it stands.
Every bound a copy is culled by grows by as far as the motion can carry it, so a swinging copy at the screen’s edge never drops out while it shows. Each pass keeps its list as the copies swing. The far shadow map keeps each copy at rest. The engine’s tests mount this file:
import { IdleMotionKind, InstancedModel, type InstancePlacement,} from "@spawnite/engine";
// Twelve lanterns along a quay, each swinging on its hook out of step with// the next, in one draw. Only what is drawn moves.
// At module scope: a new list poses every copy again.const lanterns: InstancePlacement[] = Array.from( { length: 12 }, (_, index) => ({ position: [index * 3, 2.4, 0], }),);
const sway = { kind: IdleMotionKind.Sway, angleRadians: 0.06, periodSeconds: 3.2, // The hook, a metre over the lantern's foot. pivot: [0, 1, 0],} as const;
export function LanternRow() { return ( <InstancedModel model="lantern" placements={lanterns} idleMotion={sway} collider={false} /> );}The motion runs on the CPU: each frame writes every copy’s matrix, seen or not. Juice Island’s lanterns were measured on 2026-10-16 from its core camera, on an RTX 3070 with vsync off, two runs each. At 5,000 copies the motion took 3.0 and 3.6 ms of the main thread a frame, and at 500 and at 50 too little to rank. A frame’s whole time moved less between on and off than between two runs of one count. Keep a moving batch to hundreds of copies; a field of thousands wants a material that moves its vertices, as wind sway does.
Godot’s MultiMesh and Unity’s instancing leave a per-copy motion to a game’s shader or script, and Unreal moves an instance with a material’s world position offset. A vertex shader costs no CPU, but it cannot read the sea a float rides, so the batch poses each copy as IdleMotion does, from the same function.
Shadows
Section titled “Shadows”Every copy receives the sun’s shadow. It casts one too unless castShadow is false, which saves the shadow pass a batch’s triangles. A level takes its own castShadow, such as none for far cards that stand past the sun’s shadow anyway.
Past the cascades, the copies cast into the sun’s far shadow map, which draws them once and keeps them. It draws each copy at the model’s coarsest level that casts, so give a tree’s far level castShadow: true and its impostor cards none. Copies the game moves take static={false}, and cast only within the cascades. Copies past their cullDistance from the camera cast nothing far either, and copies that shrink at the cull cast only within the cascades.
Small plants on a low quality level cast little a player sees, and need not reach far. useActiveQualityLevel reads the level in force, and with QualityGroup.Foliage the player’s Foliage row, which the player may set apart from the rest. It returns a QualityLevel: Minimum, Low, Medium or High, never Auto. These ferns follow it. The engine’s tests mount this file:
import { InstancedModel, QualityGroup, QualityLevel, useActiveQualityLevel, type InstancePlacement,} from "@spawnite/engine";
// Ferns that follow the player's Foliage row: on Low and Minimum they cast// no shadow and stop at 20 m, and above them they cast and reach 35 m.
const lowLevels = [QualityLevel.Minimum, QualityLevel.Low];
// At module scope: a new list sorts and writes every copy again.const ferns: InstancePlacement[] = Array.from({ length: 200 }, (_, index) => ({ position: [(index % 20) * 2, 0, -Math.floor(index / 20) * 2], turn: index,}));
export function QualityFerns() { const low = lowLevels.includes(useActiveQualityLevel(QualityGroup.Foliage)); return ( <InstancedModel model="fern" placements={ferns} castShadow={!low} cullDistance={low ? 20 : 35} /> );}Collision
Section titled “Collision”A batch the scene places in a Landscape, outside <Views>, is solid: the character and every body meet each copy by the collider its model’s manifest baked, as the manifest says. A tree stands as its trunk, so the player walks under its crown, and a rock or a log stands as its convex hull. The copies stand with the Landscape ground’s obstacles, so the room stands them too, and the navmesh cuts them out of the floor. Unreal’s instanced static mesh collides per instance by its mesh’s simple collision by default. Unity’s terrain trees collide by their prefab’s collider. Godot’s MultiMeshInstance3D and PlayCanvas draw only.
collider changes what every copy stands as:
collider={false}stands nothing, for copies a player should not bump: grass, litter, pebbles, a crown’s boughs, or a backdrop past the map’s edge. The floor’s small copies are often tens of thousands, and each solid copy costs the bake and the physics.- A collider of the batch’s own, as a manifest writes one, in the model’s own space, replaces the model’s for every copy, such as
{ shape: { type: "cylinder", radius: 0.3, height: 12 }, offset: [0, 6, 0] }.
cameraCollision is whether the follow camera’s eye stops in front of a copy, by the cards of the nearest model, rather than passing through it. It moves no body. Left out, the copies of a defineFoliage material taller than the knee, 0.5 m, stop the eye and no others do, as The camera stops at plants says.
To change one model everywhere it stands, register it with a collider of your own, as the manifest says.
Keep a solid batch’s placements the same on every end and at every quality level. The room stands what its own render of the scene places, so a list that thins on a low quality level leaves the room a trunk the page does not draw. Thin what a quality level draws with cullDistance and detailLevels instead. A batch inside <Views> is drawn only, as every view is, and asks for no collider: one other than false there is refused. Outside a Landscape no ground stands the copies, so they are drawn only. A solid batch inside an <Entity> is refused, because its copies draw in the entity’s frame and the ground stands them in the world’s: place it in the Landscape outside any Entity, or set collider={false}.
A solid batch inside a moved or turned <group> is refused the same way. Put the offset on each placement instead, or set collider={false}.
Keep the props stable
Section titled “Keep the props stable”Define placements and material once, outside the component or in a useMemo. A new placements list sorts and writes every copy again, and a new material function makes new materials and new batches. A solid batch whose copies stand where they stood bakes nothing again, and one whose copies move bakes the ground’s obstacles again. A detailLevels list written inline costs nothing while its models and distances hold.
Where it runs
Section titled “Where it runs”Both. The page draws the copies, and the room and the page stand their colliders.
import { InstancedModel, registerModel } from "@spawnite/engine";import fir from "./fir.glb?url";
registerModel("fir", fir);
const firs = Array.from({ length: 50 }, (_, index) => ({ position: [index * 3, 0, -10] as [number, number, number], turn: index, scale: 1 + (index % 3) * 0.2,}));
export function Treeline() { return <InstancedModel model="fir" placements={firs} />;}