Showcase: 3D Portfolio — Creative Web

3D is an extra, not a requirement. Count the budget: draw calls (1 per mesh per material group, cut with merging, InstancedMesh, an atlas), triangles, texture…

What does a buyer see if their phone can't run WebGL, or the signal is slow and the 3D model hasn't arrived yet? If the answer is "an empty box", the page isn't done. A good 3D page still works when its 3D is slow, heavy, or can't show at all. A stunning scene alone isn't enough.

Picture Raka's shop window with a spotlight: the light makes the mug look amazing, but if it goes out, the mug, the price tag and the till are all still there. On the web, 3D is that spotlight: an extra, not a requirement.

The last lesson of this track brings everything together on Raka's product page: the 3D display (the mug and the shirt box), with a performance budget, staged loading, a fallback without WebGL, and accessibility.

The performance budget

Count before adding anything. For Raka's display (numbers from renderer.info in three.js 0.186):

What is counted Raka's display How
Draw calls 10 1 per mesh per material group: mug body 3 + handle 1 + shirt box 6
Triangles 1,228 192 (48-segment body) + 1,024 (handle) + 12 (box)
Texture memory 2.28 MB (942 × 300 + 480 × 300) × 4 bytes × 4/3 for mipmaps
Canvas pixels 307,200 640 × 480 at DPR 2, with setPixelRatio(Math.min(devicePixelRatio, 2))

GPU limits on phones

Loading: GLB, compression, placeholders

Say Raka puts import * as THREE from 'three' straight into the product page's main bundle. three.js for this scene, bundled and minified, is 538 KB, 134.6 KB after gzip (measured with three 0.186.1). Lighthouse's mobile setting is 1.6 Mbps with a 150 ms RTT and a CPU 4 times slower: the download takes about 0.81 seconds, then running three.js plus the first render makes one long task of about 130 ms (measured in Chrome), adding about 80 to 110 ms of TBT. So three.js is split off with import() and only loaded when needed:

// index.js: the product page, without three.js
import WebGL from 'three/addons/capabilities/WebGL.js'; // just a small checker

async function load3D() {
  const { buildDisplay } = await import('./display-3d.js'); // a separate chunk: three.js
  await buildDisplay(document.getElementById('shop-3d'));
}
if (WebGL.isWebGL2Available()) load3D(); // or when the "View in 3D" button is clicked

3D models usually come as glTF, in one binary file as .glb. Raka's display exports to 66.4 KB (38.6 KB of geometry, the rest PNG textures). A scanned model or one made in Blender can be several MB, and there are two ways to shrink its geometry:

For a 66 KB model, the Draco decoder is bigger than what it saves; for a 5 MB scan, compression makes a real difference. Both can be produced with npx @gltf-transform/cli draco or meshopt.

const loader = new GLTFLoader().setMeshoptDecoder(MeshoptDecoder);
const gltf = await loader.loadAsync('/model/display.glb', (e) => {
  container.dataset.percent = Math.round((e.loaded / e.total) * 100); // "Loading 42%"
});
scene.add(gltf.scene);

Meanwhile visitors must see something: a model can be large, and an empty canvas looks like a broken page. The best placeholder is a poster image of the products in a box whose size is already reserved (aspect-ratio: 4 / 3), plus a percentage from onProgress. When the 3D is ready, the poster is swapped for the canvas in the same place: nothing moves. In R3F, wrap the model in <Suspense fallback={...}>; drei's useProgress gives the percentage.

Without WebGL: progressive enhancement

Progressive enhancement means the basic page (images, text, prices, the buy button) works in every browser, and the 3D is only added when it can be. three.js needs WebGL 2 since r163; without it new THREE.WebGLRenderer() throws THREE.WebGLRenderer: Error creating WebGL context. So check first:

<a class="skip" href="#detail">Skip the 3D, go to the product details</a>
<div id="shop-3d" style="aspect-ratio: 4 / 3; max-width: 320px">
  <img id="poster" src="/img/display.webp" width="320" height="240"
       alt="A black Coffee Print Mug with the coffee-cup print, next to the Coffee Print Tee box">
</div>
<h2 id="detail" tabindex="-1">Product details</h2>

If WebGL.isWebGL2Available() is false, load3D is never called: the poster and the prices stay, and the 134.6 KB of three.js is never downloaded.

Accessibility

The effect on Lighthouse

Lighthouse 13's performance score weighs TBT 30%, LCP 25%, CLS 25%, FCP 10% and Speed Index 10%. For a 3D page:

Plain three.js or R3F

If Raka's shop is already built with React, React Three Fiber is the right choice: the scene is written as components, the cart state and the chosen colour become props directly, and drei provides helpers. If the page is static with no React, plain three.js is lighter. On the GPU both draw the same thing; what decides is the draw calls, the triangles, the textures and how it loads.

Other options, including one with no 3D code for a single .glb model that can be turned:

Way When to pick it
Plain three.js (the code in this lesson) a page with no React, or a scene with behaviour of its own: clicking products, changing colours, animation
React Three Fiber the site already uses React
<model-viewer> 4.4.0 (a web component) one model without writing 3D code. alt becomes the label for screen readers, poster shows while it waits, the model loads only when it comes near the screen, and camera-controls lets people turn it with the mouse, touch and the arrow keys. The file is about 290 KB gzip, twice the three.js of this scene, because three.js is inside it

One page from twelve lessons

Part of the page From the lesson
The coffee print on the texture and the poster Canvas API Basics
Coffee steam, time deltas Canvas Animation
Pointer, drag Interactive Canvas
The moving shop logo SVG Animation
The Bean Pattern motif for the next shirt Generative Art
Shaders, DPR, resizing WebGL Concepts, Three.js Setup
The mug, the box, lights, dispose() Three.js Geometry & Material
The loop, Timer, autoRotate with a delta Three.js Animation
Orbit, raycaster, keyboard buttons Interactive Three.js
The React version React Three Fiber
Budget, loading, fallback, accessibility this lesson

⚠️ Check these before the 3D display goes live

TL;DR: 3D is an extra, not a requirement. Count the budget: draw calls (1 per mesh per material group, cut with merging, InstancedMesh, an atlas), triangles, texture memory (width × height × 4 × 4/3; Raka's display: 10 draw calls, 1,228 triangles, 2.28 MB), DPR at most 2, textures at most 2048 on phones, handle webglcontextlost. Split three.js (134.6 KB gzip) off with import() and load it when visible or clicked; .glb models with GLTFLoader, Draco (KHR_draco_mesh_compression) or Meshopt (EXT_meshopt_compression) compression. A poster <img> with alt text in an aspect-ratio box as the placeholder, and as the fallback when WebGL.isWebGL2Available() is false. Canvas role="img" + aria-label, a "Skip the 3D" link, prefers-reduced-motion. Lighthouse: TBT 30%, LCP 25% (a canvas is never a candidate), CLS 25%. Already React? R3F; not? Plain three.js.

⚡ 3D is an extra, not a requirement

Meaning: A good page still works when its 3D is slow, heavy, or can't show at all. The price, the buy button, and a poster <img> with alt text in an aspect-ratio: 4 / 3 box are there before three.js arrives.

⚡ Count the budget

Guess first: the mug's print PNG is only 14 KB. How big is it on the GPU?

About 1.5 MB. Texture memory comes from the pixel size, not the file size.

Meaning: A draw call is 1 per mesh per material group, and a texture takes width × height × 4 × 4/3 bytes. Raka's display: 10 draw calls, 1,228 triangles, 2.28 MB. For phones, textures are 2048 at most.

⚡ Load three.js later

Write:

async function load3D() {
  const { buildDisplay } = await import('./display-3d.js'); // a separate chunk: three.js
  await buildDisplay(document.getElementById('shop-3d'));
}
if (WebGL.isWebGL2Available()) load3D();

Meaning: three.js (134.6 KB gzip) is split off with import() and only downloaded when needed. Without WebGL 2, the poster and the prices stay, and three.js is never downloaded.

⚡ Plain three.js or R3F?

Meaning: If the site already uses React, React Three Fiber is the right choice: the scene becomes components, and state becomes props directly. A static page with no React is lighter with plain three.js. On the GPU, both draw the same thing.

What you will learn