Publishing gate

Run the WebGL scene health check

Use the checklist to score assets, camera behavior, rendering, mobile performance, loading states, and fallback content before publishing.

Run Scene Check Compare lab tools

Draw calls are the real enemy

A scene with hundreds of identical bolts, trees, cubes, or particles can become slow even when each object is simple. The problem is often draw calls, not raw triangle count. Each separate mesh asks the renderer and GPU to do setup work. InstancedMesh reduces that overhead by drawing many transforms of the same geometry and material together.

The constraint is sameness. Instances share geometry and material. You can vary transform and some per-instance attributes, but if every object needs a unique material setup, instancing may not be the right first tool.

Use a matrix per object

Each instance has a transformation matrix. You can compose that matrix from position, rotation, and scale using a temporary Object3D, then copy it into the InstancedMesh with `setMatrixAt`. After updating matrices, set `instanceMatrix.needsUpdate = true`.

This pattern is predictable and fast enough for setup. For per-frame animation of thousands of instances, you may need more careful batching or shader-based movement, but the basic matrix workflow is the best starting point.

Picking instances needs extra handling

Raycaster can report an instanceId when hitting an InstancedMesh. That gives you a way to select or highlight a specific copy. The UI logic needs to map that instanceId back to your data: product part, point index, building floor, or whatever the instance represents.

If selection is important, keep an array of metadata parallel to the instances. Instancing should not make the scene impossible to inspect.

When instancing is overkill

A dozen repeated objects do not need instancing. The complexity only pays off when draw calls become noticeable. Measure `renderer.info.render.calls` before and after. If the scene is already fast and the code is becoming less clear, keep separate meshes.

Performance work should make the site more reliable, not more mysterious. Use instancing for the repeated-object cases where it clearly reduces render overhead.

When this guide is the right tool

Use this guide when the problem is specific enough that a broad Three.js tutorial would waste time. The focus here is InstancedMesh in a real browser page: what to check first, what to measure, and what to avoid before the scene becomes harder to reason about.

The practical rule is simple: Use InstancedMesh for many copies that share geometry and material. If that sentence describes the scene in front of you, treat the article as a checklist. Read the explanation, copy the smallest useful code pattern, then test the result in a narrow mobile viewport and a wide desktop viewport before adding more polish.

Common mistake to avoid

The common mistake is treating Three.js instancing for many repeated objects as a visual tweak instead of a scene-system decision. Three.js problems often look like one broken line of code, but the actual issue is usually a chain: asset assumptions, renderer settings, camera math, material setup, interaction state, and page layout all meet inside the canvas.

That is why the safest fix is incremental. Start from a known-good scene, change one variable, and keep a visible diagnostic while testing. Update instance matrices deliberately and mark them dirty. When the scene works, remove temporary helpers and leave behind only the checks that make sense for users.

Publishing check

Before publishing, run the scene through three questions. Does the page remain useful if WebGL fails or the asset loads slowly? Does the same scene still read clearly on a phone? Can another developer understand the important settings without reverse-engineering the whole file?

The last pass should be boring on purpose: verify canvas size, console errors, mobile performance, source links, internal links, and the related guide path. Reach for merged geometry or separate meshes when objects need unique materials or topology. If any answer is fuzzy, fix that before introducing a new effect or a larger asset.

Instanced mesh setup

const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
const material = new THREE.MeshStandardMaterial({ color: 0x65d8c2 });
const mesh = new THREE.InstancedMesh(geometry, material, 500);
const dummy = new THREE.Object3D();

for (let i = 0; i < 500; i += 1) {
  dummy.position.set(Math.random() * 8 - 4, Math.random() * 4, Math.random() * 8 - 4);
  dummy.rotation.set(Math.random(), Math.random(), Math.random());
  dummy.updateMatrix();
  mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);

FAQ

When should I use Three.js instancing for many repeated objects?

Use it when your Three.js scene has a focused InstancedMesh problem and you need a practical checklist before adding more visual polish.

Is the code snippet production-ready?

Treat the snippet as a clear starting point. Test it in your scene, adapt naming and paths, and verify behavior on mobile hardware before publishing.

What should I check after applying this guide?

Run the scene through mobile sizing, console errors, loading states, source links, and related guide paths so the page remains useful even when assets or WebGL fail.

Sources and further reading

Related guides