Frontory

Open code, practice, and notes →

Download source with English comments · for reading

Three.js · 19 Instancing Basics

Series contents · Technology map

Stage: Animation, Instancing, and Render Passes · Editable example · Storage ID: threejs-step-19

Goals and learning outcomes

Prerequisites

Prerequisite concepts: Depth Writes, Sorting Limits. Prepare the result files and observation notes from unit 18.

Key concepts and explanations

Shared Drawing

InstancedMesh draws the same geometry and material with multiple transforms. It can reduce draw calls compared with creating a Mesh for every object.

Instance Buffers

setMatrixAt changes instance data on the CPU. Set instanceMatrix.needsUpdate to upload the changes.

Practice setup

First read the execution-scope guidance on the example screen. The following environment is for extending the assignment in a separate project. Implement it yourself in an HTML and ES module project served by a separate local HTTP development server. Pin three and addons to the same installed version and record it.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. Prepare day-19.js and index.html in the external exercise project. Create 500 identical cubes as a Mesh list and as an InstancedMesh.
  2. Fill setMatrixAt from the same coordinate array and compare renderer.info.render.calls.
  3. Save the output under the Individual Mesh objects input condition, then run again under the InstancedMesh condition. Expected: Under the same material conditions, draw calls decrease. Compare with the actual screen and logs, and record the actual result and reasons for any differences in day-19-notes.md.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
RepresentationIndividual Mesh objectsInstancedMeshUnder the same material conditions, draw calls decrease.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Can the call count decrease without reducing the triangle count?
  2. Can each instance use different geometry?

Official references

Linked example and execution scope

Example source · Runtime environments and limits

This is an editable browser experiment. Measurements vary with the current device and browser.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Transparency and Depth · Next: Instance Selection and Updates

Open code, practice, and notes →