Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 39 ยท Projects and Practice

Three.js Practice Challenges and Debugging Checklist

Test your Three.js skills with graded challenges, a reusable scene diagnostic helper for black screens and missing objects, a physics bounce solution, a mini-game and a learning roadmap.

Reading a tutorial gives you recognition; building things gives you skill. This closing lesson is a workout: a debugging toolkit for the problems you will hit on every project, a set of graded challenges with clear goals, two worked solutions you can run and take apart, and a roadmap for what to learn next.

Treat the challenges like a gym plan. Pick one per sitting, write it from a blank file, and only look at the hints if you are stuck for more than fifteen minutes.

Part 1: The "nothing shows up" checklist

Most Three.js bugs are not exotic. A black canvas almost always has one of a handful of causes. Walk through them in order:

  1. Console errors: failed module import, CORS-blocked texture, shader compile error. Read them first.
  2. Did you render? renderer.render(scene, camera) must be called after the objects exist (and every frame if anything moves).
  3. Is the object in the scene? scene.add(mesh) (or added to a parent that is in the scene).
  4. Is the camera looking at it? Position, lookAt, and the object not being behind the camera or inside near/far limits.
  5. Is the size sane? Units are arbitrary: a model 0.01 or 5000 units wide will vanish. Measure with Box3.
  6. Is there light? MeshStandardMaterial, Lambert, Phong, Physical are black without lights or an environment. MeshBasicMaterial ignores lights.
  7. Is the material visible? transparent with opacity: 0, side: FrontSide seen from behind, visible = false, an alpha-test discarding everything.
  8. Is the canvas sized? A 0 x 0 canvas (CSS height of 0, hidden parent) renders nothing.
  9. Is the texture loaded and valid? CORS, wrong path, colorSpace.

Because these checks are mechanical, you can write a helper that does them for you. Here is one you can paste into any project. It inspects a scene and prints a plain-language diagnosis. Run it and notice that the "broken" scene triggers several messages, and the fixed one is clean.

A scene diagnostic helper

Keep this function in your toolbox; extend it each time a new bug bites you. Also remember the visual helpers: AxesHelper, GridHelper, BoxHelper, CameraHelper and SkeletonHelper, plus renderer.info for counts, and the browser extension "Three.js Developer Tools" that lets you inspect the scene graph.

Part 2: Challenges

Each challenge lists a goal and acceptance criteria you can check yourself. Levels roughly follow the chapters of this tutorial.

Level 1: foundations

  1. Orbiting cubes clock. Twelve small cubes in a ring with one rotating "hand". The hand should make one turn per minute using real elapsed time. Check: it stays correct if you throttle the frame rate in DevTools.
  2. Responsive canvas. A scene that fills its container and keeps the correct aspect ratio when the window is resized, with setPixelRatio capped at 2. Check: spheres stay round at every size.
  3. Light show. Three colored point lights circling a white sphere on a white floor with shadows. Check: the shadow of the sphere moves smoothly and no light leaves the scene.

Level 2: materials, models, interaction

  1. Material gallery. A grid of 12 spheres demonstrating different materials (basic, lambert, standard with metal and rough values, physical with clearcoat, wireframe, toon, normal). Add labels with HTML overlays that follow each sphere. Check: labels stay attached when you orbit.
  2. Click-to-paint cube. Clicking a face of a cube paints a dot at the clicked texture position, using the raycast uv and a CanvasTexture. Hint: draw a circle on the canvas at uv.x * width, (1 - uv.y) * height, then set texture.needsUpdate = true.
  3. Model inspector. Load a glTF file the user drops onto the page (FileReader plus GLTFLoader.parse), center and scale it, show its triangle count and list its animations with play buttons. Check: a second drop replaces the first without leaking memory (renderer.info.memory.geometries returns to the correct count).

Level 3: shaders, effects, performance

  1. Dissolve effect. A mesh that dissolves away with a noise threshold uniform and a glowing edge, using onBeforeCompile on MeshStandardMaterial and discard. Check: lighting still works while it dissolves.
  2. Cinematic scene. Any scene with bloom, a vignette, and an outline on hover, at a stable 60 fps on a mid-range laptop. Check: renderer.info.render.calls under 50.
  3. A million cubes. An InstancedMesh city with 100,000 buildings, LOD-by-instance (hide far instances with per-instance scale 0 or BatchedMesh visibility) and frustum culling. Check: stays smooth, memory stable.
  4. GPU Game of Life in 3D layers. Extend the ping-pong example from the render targets lesson: display the last 16 generations stacked as translucent layers.

Choose challenges that scare you a little. When one works, change a requirement (a new color scheme, a different input device) and make it work again; that is when the knowledge becomes yours.

Part 3: A solved challenge, bouncing balls

Challenge: Click to drop a ball from the click position. Balls fall with gravity, bounce on the floor, lose a bit of energy on each bounce, and stop when nearly at rest. Balls beyond 40 are recycled. Below is a full solution with a deterministic physics step (fixed timestep, so results do not depend on the frame rate). The console proves it by simulating a ball for 3 simulated seconds.

Solution: click to drop bouncing balls

Points worth studying in this solution: the physics lives in a plain function that knows nothing about Three.js; the loop uses a fixed timestep with an accumulator so behaviour is identical on 30 Hz and 144 Hz screens; one geometry is shared by all balls; and recycled balls have their material disposed. For real physics (rotation, stacking, friction) you would reach for a library such as Rapier or cannon-es, but the structure (fixed step, sync meshes from bodies) stays the same.

Part 4: A solved challenge, catch the stars

Challenge: Build a tiny game: move a paddle with the pointer; stars fall from above; catching them scores a point, missing three ends the game. Again the rules are separate from the rendering, and an automated "bot" proves the scoring in the console.

Solution: a catch-the-stars mini-game

Move the pointer across the canvas to steer the paddle. The test at the top makes a point you should adopt in your own projects: when the rules of your game or tool are separate from Three.js, you can run them without a GPU, in a unit test, and trust them.

Part 5: Where to go next

  • Physics: Rapier (WASM, fast) or cannon-es, then collision shapes, constraints and character controllers.
  • Rendering craft: baked lighting (lightmaps), light probes, screen-space effects, custom depth materials, MeshPhysicalMaterial features (transmission, iridescence, sheen), clipping planes and stencil tricks.
  • Assets: Blender to glTF pipeline, gltf-transform optimization, KTX2 textures, animation retargeting.
  • Frameworks and tooling: React Three Fiber, Vite, TypeScript, a real deployment with caching.
  • WebGPU and TSL: compute shaders, huge particle counts (WebGPU and TSL).
  • XR: renderer.xr.enabled = true, VR and AR sessions, hand tracking.
  • Study: read the official examples' source, the Three.js manual, and the shader book "The Book of Shaders" for the math behind effects.

Build one real thing you care about: a portfolio scene, a data visualization, a small game. Finishing a project teaches you more than any chapter.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A MeshStandardMaterial cube renders pure black. What is the most likely cause?

    Standard materials need light to be visible. Add a light or an environment, or use MeshBasicMaterial.
  2. 2. Why does the bouncing-ball solution use a fixed timestep with an accumulator?

    Stepping the simulation by the same small dt every time gives identical results on slow and fast screens.
  3. 3. What is the benefit of keeping game rules in a function with no Three.js code?

    Pure logic can be run in a console or unit test, as the bot test shows.
  4. 4. Which camera problem makes an object invisible even though it is in the scene and lit?

    Objects outside the view frustum, behind the camera, or nearer than the near plane are not drawn.

Summary

  • Debug black screens methodically: errors, render call, scene membership, camera, size, light, material, canvas size, textures.
  • A small diagnostic helper turns that checklist into code you can reuse.
  • Practise with graded challenges, and extend each one after it works.
  • Separate rules (physics, game logic) from rendering so they are deterministic and testable; use fixed timesteps.
  • Keep growing with physics, asset pipelines, frameworks, WebGPU and XR, and finish real projects.

Next: back to the Three.js track overview