Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 39 ยท Projects and Practice

Project: A 3D Product Configurator

Build a 3D product configurator in Three.js: parametric chair model, material swapping, view presets, exploded view, soft shadows, price calculation, saved config and a screenshot button.

Product configurators are one of the most common commercial uses of Three.js: choose a color, a material or a size, and see the product update live from every angle. Furniture, sneakers, cars, jewelry and phone cases all work this way, and the techniques are the same ones you already know, combined into an app with a clear structure.

In this project you will build a chair from primitives (so there is nothing to download), define the product's options as plain state, apply that state to the 3D model without rebuilding it, add camera presets and an exploded view, calculate a price, save the configuration as JSON and take a screenshot.

Design the data first

A configurator is easiest to build when the 3D scene is a function of a small state object. The UI edits the state, one apply(state) function updates the scene, and the same state can be saved, shared or sent to a shopping cart.

JavaScript
const state = {
  fabric: 'ocean',      // seat and back color
  legs: 'oak',          // wood or metal finish
  width: 1.0,           // size multiplier
  exploded: false
};

Options and prices live in plain tables, which also makes them easy to load from a server later:

JavaScript
const FABRICS = { ocean: '#2563eb', sand: '#d6c3a1', moss: '#4d7c0f', rose: '#e11d48' };
const LEGS = {
  oak:   { color: '#a16207', metalness: 0,   roughness: 0.7, price: 0 },
  steel: { color: '#cbd5e1', metalness: 1,   roughness: 0.25, price: 40 },
  black: { color: '#111827', metalness: 0.6, roughness: 0.4, price: 25 }
};

Configurator architecture

State One plain object describes the choice
UI Buttons edit the state
apply(state) Updates materials, scale, positions
Output Price, JSON, screenshot

Never rebuild the model for a color change; update the existing materials.

1 / 2

Step 1: a parametric model

The chair is built by a function that returns a group and a dictionary of named parts. Keeping parts in a dictionary lets apply find the seat or the legs without traversing the scene. Each part remembers its assembled position (userData.home) and an exploded position (userData.away) for later.

Step 1: the model and state

Two materials drive the whole look: fabricMat (shared by seat and back) and legMat (shared by all four legs). Changing one material changes every part that uses it, which is exactly what we want for "change the fabric".

Step 2: apply the state

apply(state) pushes the state into the scene. Colors and PBR values are assigned to the existing materials; the size option scales the chair on x; the exploded view moves each part between its home and away positions. For a smooth explode, store a target in exploded and ease toward it each frame using MathUtils.damp.

Add also:

  • Shadows: a directional light with castShadow, plus a large ShadowMaterial plane (transparent except where shadows fall), so the chair seems to sit on the page. Use renderer.shadowMap.type = THREE.PCFSoftShadowMap.
  • Camera presets: store a position and target per view ("front", "side", "top", "detail") and move to them with damping, using camera.position.x = damp(...).
  • Price: base price plus option surcharges and a size factor. Compute it from the state, never from the scene.
  • Persistence: JSON.stringify(state) gives you something to put in a URL, localStorage (on your own site) or an order.
  • Screenshot: render, then canvas.toBlob. This works only if you read the canvas immediately after rendering (or create the renderer with preserveDrawingBuffer: true).
Step 2: the complete configurator

Try every control: the fabric swatches and leg finishes only edit material values (no new objects), the width slider scales the group, the explode button animates parts with damping, the preset buttons fly the camera and release as soon as you drag, and the price and JSON update from the state alone.

From toy to real product

The structure scales to real products:

  • Real models: export your chair from Blender as GLB, name the meshes (Seat, Legs), load with GLTFLoader (glTF lesson), and look up materials by name: gltf.scene.getObjectByName('Seat').material. Clone materials you plan to modify if several meshes share them.
  • Textures: replace flat colors with fabric normal and roughness maps (PBR textures); swap material.map per option and set the right color spaces.
  • Hotspots: HTML buttons that follow 3D points. Project each anchor with vector.project(camera) and position the element from the normalized coordinates; hide it when it faces away.
  • Performance: cap pixel ratio, render on demand (only when state, controls or the fly-to animation change) and compress textures with KTX2 (performance).
  • AR: export USDZ for iOS Quick Look or GLB for Android Scene Viewer from the same configuration.
  • Commerce: send the state JSON with the add-to-cart request, and rebuild the same 3D configuration in the cart page from it.
  • Accessibility: keep real HTML controls with labels and keyboard support next to the canvas; the 3D view is a visualization, not the only way to choose.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why model the configurator as 'scene = function of a state object'?

    A plain state is easy to serialize, validate and price, and one apply function keeps the scene consistent with it.
  2. 2. How should a fabric color change be applied?

    Materials are shared by the parts that use them, so changing material.color updates all of them with no new objects.
  3. 3. What does a ShadowMaterial plane provide?

    ShadowMaterial renders nothing but received shadows, so the product seems to sit on the page background.
  4. 4. Why does the screenshot button call renderer.render before canvas.toBlob?

    Without preserveDrawingBuffer, the canvas contents are only guaranteed immediately after rendering in the same task.

Summary

  • Keep the configuration in a small state object; one apply(state) function updates materials, scale and positions.
  • Share materials between parts so one change affects all of them, and never rebuild the model for a color swap.
  • Add presentation: environment lighting, soft shadows on a ShadowMaterial floor, camera presets with damping and an exploded view.
  • Compute price and export JSON from the state; take screenshots right after rendering.
  • Replace the primitives with a named-mesh GLB, add textures and hotspots, and keep accessible HTML controls.

Next: Project: A Particle Galaxy