THE THREE.JS
DONUT PICNIC
CUBES, SHAPES, MATERIALS & GROUPS

By Shane Brumback · · Updated · Free Three.js tutorial · Cube Series Part 3

To build a Three.js scene from many shapes, make one Mesh per geometry, give each a material, collect related meshes in a THREE.Group, and move them every frame in the render loop. Here a glossy iced donut sits on a picnic table in a low-poly meadow while a teal cube, torus knot, sphere, icosahedron, cone and cylinder bob and spin around it.

You will use TorusGeometry, TorusKnotGeometry, metal and clearcoat materials, and THREE.Group. The scene behind this page is the live demo, and the full copy-paste source is below.

✓ FREE Part 3 · Beginner+ 7 geometries PBR materials THREE.Group

PART 3 OF THE BEGINNER SERIES

Prerequisite: finish Parts 1 and 2 first. This step assumes you can already make a scene, camera, renderer and spinning mesh (Part 1) and add lights, shadows, a ground and OrbitControls (Part 2). Now we put many shapes and materials together into one real scene.

See it live

LIVE DEMO

The donut picnic behind this page is a live Three.js scene. Launch the full-screen demo to drag to orbit and scroll to zoom around the donut and its floating shapes. Launch asks for a free Google sign-in first. Press Esc or Exit to return.

Free Google sign-in · Orbit: drag · Zoom: scroll · Esc to exit

What You Will Learn

In Part 1 you spun one cube. In Part 2 you lit it and gave it a floor. A real scene is many objects working together, so this step teaches the three ideas you need for that:

  • More geometries: TorusGeometry (the donut), BoxGeometry (the teal cube), TorusKnotGeometry, SphereGeometry, IcosahedronGeometry, ConeGeometry and CylinderGeometry, plus BoxGeometry and CapsuleGeometry for the table and sprinkles.
  • Mixing materials: MeshStandardMaterial with metalness and roughness for dough, gold and chrome; MeshPhysicalMaterial with clearcoat for icing and a candy-shell knot.
  • Grouping and animation: THREE.Group to build trees, a table and a donut from parts, and a simple bob-and-spin loop that gives every object its own rhythm.

The meadow, sky, pine trees and rocks match Level 1 and Level 2 of the Cube Series — same hills and trees, with the picnic table and shapes added on top.

How It Works

  1. Set up the scene, camera and renderer. We make an empty 3D world, a camera to look at it, and a renderer that draws it with soft shadows and warm filmic color.
  2. Paint the sky and float clouds. The sky is the same soft blue as Levels 1 and 2.
  3. Light it with a soft sun. A sky light fills everything softly and one strong sun throws the shadows — the same HemisphereLight and DirectionalLight setup as Level 2.
  4. Build the meadow: grass, hills and trees. This is the same meadow as Levels 1 and 2.
  5. Set the picnic table. A table is just boxes: one flat box for the top and four thin boxes for legs.
  6. Make the hero donut. The donut is two rings stacked: a matte dough ring and a slightly fatter, flattened, glossy pink icing ring, sprinkled with tiny capsules.
  7. Add a floating geometry gallery. Around the donut float six more shapes, each with a different material: a glossy torus knot, a gold sphere, a faceted icosahedron, a cone, a chrome cylinder and the teal cube from Level 2.
  8. Bob and spin every object. Every frame, each shape moves up and down on its own sine wave and turns a little, so the whole scene feels alive without any two shapes moving in step.

The detailed code breakdown and the full copy-paste file are below. Every step is an exact excerpt of the full file, and the full file is the same code as the live demo.

Try it yourself: change the icing color, swap the gold sphere's metalness to 0, or add your own shape with one more addFloater() call. Want shapes you can click? Try raycaster selection.

Frequently Asked Questions

How do I make a donut in Three.js?

Use new THREE.TorusGeometry(radius, tube, radialSegments, tubularSegments), for example TorusGeometry(0.62, 0.3, 24, 64), with a MeshStandardMaterial and add the Mesh to the scene. For icing, add a second, slightly fatter torus with a glossy MeshPhysicalMaterial, flatten it with scale.z and lift it a little.

What is the difference between TorusGeometry and TorusKnotGeometry?

TorusGeometry is a plain ring, like a donut. TorusKnotGeometry is a tube that winds around the ring several times to form a knot, controlled by its p and q parameters. Both take a radius and a tube thickness.

When should I use MeshPhysicalMaterial instead of MeshStandardMaterial?

MeshStandardMaterial covers most surfaces with color, metalness and roughness. Use MeshPhysicalMaterial when you need extra layers such as clearcoat, which adds a thin glossy coat like icing, candy or car paint. It costs a little more to render, so use it only on the hero objects.

What does THREE.Group do?

A Group is an empty container. Anything you add to it moves, rotates and scales with it. In this scene the donut, its icing and sprinkles share one group, so one rotation spins the whole donut, and each tree and the picnic table are groups of simple parts.

How do I make objects bob and spin?

In the render loop set position.y to a base height plus Math.sin(time * speed + phase) times a small amount, and add a little to rotation each frame scaled by the frame delta. Giving each object its own phase and speed keeps them from moving in step.

Do I need Part 1 and Part 2 first?

It helps. Part 1 builds your first spinning cube and Part 2 adds lights, shadows, a ground and OrbitControls. This Part 3 reuses all of that, brings back the teal Level 2 cube, and focuses on combining 7 geometries and mixed materials into one scene.

Why do I need to sign in to launch the live demo?

The tutorial and its full code are free to read. The full-screen Live Demo asks for a free Google sign-in first, the same gate used across the site, so I know who is learning from these tutorials.

Play It and Keep Learning

Low-poly scenes like this power Super Soldier Battle, free in your browser. Browse every Three.js tutorial or play more 3D games.

Need Three.js or WebGL work? I take freelance and contract work: contact me.