Prompt specification
Build or customize the Three.js 3D scene "Backpack closure comparison" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Backpack closure comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/backpack-closure-comparison-x0595
Scene Description Prompt:
A voxel backpack display with operable hook-and-loop, buckle, and zipper closures. Use Three.js from cdnjs and deliver one HTML file.
Working Three.js Starter (backpack-closure-comparison-x0595):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Pack — Interactive Closure Display</title>
<style>
:root {
--ink: #14282b;
--paper: #e5eee8;
--panel: rgba(15, 37, 40, 0.95);
--mint: #79d8bd;
--orange: #ff7552;
--gold: #f4bd52;
--cream: #fff4dc;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 20;
top: 28px;
left: 32px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 30px;
height: 3px;
background: var(--orange);
box-shadow: 9px 0 0 var(--gold);
}
.brand h1 {
margin: 0;
font-size: clamp(36px, 5vw, 72px);
line-height: 0.88;
letter-spacing: -0.065em;
text-transform: uppercase;
}
.brand h1 span {
display: block;
color: transparent;
-webkit-text-stroke: 1.5px var(--ink);
}
.brand p {
max-width: 360px;
margin: 16px 0 0;
font-size: 13px;
font-weight: 600;
line-height: 1.55;
opacity: 0.68;
}
.panel {
position: fixed;
z-index: 30;
top: 24px;
right: 24px;
bottom: 24px;
width: 330px;
padding: 24px;
overflow: auto;
color: #f6f3e9;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 22px;
box-shadow: 0 24px 70px rgba(20, 40, 43, 0.25);
backdrop-filter: blur(16px);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
padding-bottom: 20px;
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.panel-heading h2 {
margin: 0 0 5px;
font-size: 18px;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 0;
color: rgba(255, 255, 255, 0.52);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 7px;
color: var(--mint);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 5px rgba(121, 216, 189, 0.12);
animation: pulse 2s infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 9px rgba(121, 216, 189, 0);
}
}
.closures {
display: grid;
gap: 10px;
margin: 20px 0;
}
.closure {
position: relative;
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 12px;
width: 100%;
padding: 13px;
text-align: left;
background: rgba(255, 255, 255, 0.045);
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 13px;
cursor: pointer;
transition: 180ms ease;
}
.closure:hover {
background: rgba(255, 255, 255, 0.09);
transform: translateX(-3px);
}
.closure:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 2px;
}
.closure.active {
background: rgba(121, 216, 189, 0.1);
border-color: rgba(121, 216, 189, 0.45);
}
.number {
display: grid;
place-items: center;
width: 38px;
height: 38px;
color: var(--ink);
background: var(--cream);
border-radius: 10px;
font-size: 11px;
font-weight: 900;
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.closure:nth-child(2) .number {
background: var(--gold);
}
.closure:nth-child(3) .number {
background: var(--orange);
color: white;
}
.closure strong,
.closure small {
display: block;
}
.closure strong {
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.closure small {
color: rgba(255, 255, 255, 0.47);
font-size: 10px;
line-height: 1.3;
}
.state {
min-width: 42px;
color: var(--mint);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-align: right;
text-transform: uppercase;
}
.zip-control {
margin: 2px 0 22px;
padding: 14px;
background: rgba(0, 0, 0, 0.15);
border-radius: 13px;
}
.zip-control label {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: rgba(255, 255, 255, 0.58);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 5px;
appearance: none;
background: linear-gradient(
to right,
var(--orange) 0%,
var(--orange) var(--zip, 0%),
rgba(255, 255, 255, 0.14) var(--zip, 0%)
);
border-radius: 99px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
background: var(--cream);
border: 3px solid var(--orange);
border-radius: 4px;
cursor: ew-resize;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
background: var(--cream);
border: 3px solid var(--orange);
border-radius: 4px;
cursor: ew-resize;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.action {
padding: 11px 10px;
color: var(--ink);
background: var(--cream);
border: 0;
border-radius: 10px;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.action:hover {
background: var(--mint);
transform: translateY(-2px);
}
.action.secondary {
color: white;
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.12);
}
.panel-footer {
display: flex;
gap: 9px;
margin-top: 20px;
padding-top: 18px;
color: rgba(255, 255, 255, 0.43);
border-top: 1px solid rgba(255, 255, 255, 0.1);
font-size: 10px;
line-height: 1.5;
}
.panel-footer b {
color: var(--cream);
}
#markers {
position: fixed;
z-index: 15;
inset: 0;
pointer-events: none;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 0;
background: transparent;
border: 0;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.hotspot.visible {
opacity: 1;
pointer-events: auto;
}
.hotspot .dot {
position: relative;
display: grid;
place-items: center;
width: 30px;
height: 30px;
color: var(--ink);
background: var(--cream);
border: 3px solid rgba(255, 255, 255, 0.72);
border-radius: 50%;
box-shadow: 0 6px 20px rgba(20, 40, 43, 0.25);
font-size: 9px;
font-weight: 950;
}
.hotspot .dot::after {
content: "";
position: absolute;
inset: -8px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 50%;
animation: ring 2.2s infinite;
}
@keyframes ring {
70%,
100% {
opacity: 0;
transform: scale(1.35);
}
}
.hotspot .label {
padding: 7px 10px;
color: var(--ink);
background: rgba(255, 244, 220, 0.92);
border-radius: 7px;
box-shadow: 0 6px 20px rgba(20, 40, 43, 0.15);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
white-space: nowrap;
}
.hotspot:hover .dot {
color: white;
background: var(--orange);
}
.hint {
position: fixed;
z-index: 12;
left: 32px;
bottom: 28px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 14px;
color: var(--ink);
background: rgba(255, 244, 220, 0.76);
border: 1px solid rgba(20, 40, 43, 0.08);
border-radius: 12px;
box-shadow: 0 12px 30px rgba(20, 40, 43, 0.09);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.mouse {
position: relative;
width: 16px;
height: 24px;
border: 2px solid currentColor;
border-radius: 9px;
}
.mouse::before {
content: "";
position: absolute;
top: 4px;
left: 5px;
width: 2px;
height: 5px;
background: currentColor;
border-radius: 2px;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: var(--paper);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.brand {
top: 18px;
left: 18px;
}
.brand h1 {
font-size: 38px;
}
.brand p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 16px;
border-radius: 17px;
}
.panel-heading {
padding-bottom: 12px;
}
.panel-heading p,
.panel-footer {
display: none;
}
.closures {
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 12px 0;
}
.closure {
grid-template-columns: 28px 1fr;
gap: 7px;
padding: 9px;
}
.number {
width: 28px;
height: 28px;
border-radius: 7px;
}
.closure small,
.state {
display: none;
}
.closure strong {
font-size: 8px;
}
.zip-control {
display: none;
}
.actions {
grid-template-columns: 1fr 1fr;
}
.hint {
display: none;
}
.hotspot .label {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive voxel backpack display"></canvas>
<header class="brand">
<div class="eyebrow">Field Series / No. 08</div>
<h1>Voxel <span>Pack</span></h1>
<p>
A modular utility pack built from 3D blocks. Explore every fastening
system: peel the hook-and-loop, release the buckle, and pull the zipper.
</p>
</header>
<aside class="panel">
<div class="panel-heading">
<div>
<h2>Closure Systems</h2>
<p>Interactive hardware</p>
</div>
<div class="live">Live model</div>
</div>
<div class="closures">
<button class="closure" data-toggle="velcro" aria-pressed="false">
<span class="number">01</span>
<span>
<strong>Hook & Loop</strong>
<small>Peel the tab and lift the lid</small>
</span>
<span class="state" id="velcro-state">Closed</span>
</button>
<button class="closure" data-toggle="buckle" aria-pressed="false">
<span class="number">02</span>
<span>
<strong>Buckle</strong>
<small>Release the compression clasp</small>
</span>
<span class="state" id="buckle-state">Closed</span>
</button>
<button class="closure" data-toggle="zipper" aria-pressed="false">
<span class="number">03</span>
<span>
<strong>Zipper</strong>
<small>Drag the gold pull along the track</small>
</span>
<span class="state" id="zipper-state">Closed</span>
</button>
</div>
<div class="zip-control">
<label for="zip-range">
<span>Zipper travel</span>
<span id="zip-value">0%</span>
</label>
<input id="zip-range" type="range" min="0" max="100" value="0" />
</div>
<div class="actions">
<button class="action" id="open-all">Open all</button>
<button class="action secondary" id="reset-all">Reset pack</button>
</div>
<div class="panel-footer">
<span>↔</span>
<span>
<b>Drag</b> to orbit<br />
<b>Scroll</b> to zoom<br />
<b>Click</b> numbered markers to operate
</span>
</div>
</aside>
<div id="markers">
<button class="hotspot" data-action="velcro" aria-label="Operate hook-and-loop closure">
<span class="dot">01</span>
<span class="label">Hook & Loop</span>
</button>
<button class="hotspot" data-action="buckle" aria-label="Operate buckle closure">
<span class="dot">02</span>
<span class="label">Buckle</span>
</button>
<button class="hotspot" data-action="zipper" aria-label="Operate zipper">
<span class="dot">03</span>
<span class="label">Zipper</span>
</button>
</div>
<div class="hint">
<span class="mouse"></span>
<span>DRAG TO ORBIT · SCROLL TO ZOOM</span>
</div>
<div id="loading">Building voxel pack…</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9e3);
scene.fog = new THREE.Fog(0xdfe9e3, 12, 24);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const controls = {
target: new THREE.Vector3(0, 2.65, 0),
radius: 8.8,
theta: 0.49,
phi: 1.12
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf8fff3, 0x61706d, 2.2);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff2d5, 3.5);
key.position.set(-5, 10, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 1;
key.shadow.camera.far = 25;
key.shadow.bias = -0.00035;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9bd9ef, 1.35);
fill.position.set(7, 4, -5);
scene.add(fill);
const rim = new THREE.PointLight(0xff8c61, 22, 13, 2);
rim.position.set(-4, 5, 3);
scene.add(rim);
const world = new THREE.Group();
scene.add(world);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function material(color, roughness = 0.82) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0.02
});
}
const mat = {
teal: material(0x217c75),
tealDark: material(0x145c5d),
tealLight: material(0x319487),
tealPale: material(0x55aa94),
coral: material(0xf06e50),
coralDark: material(0xbd4d3d),
coralLight: material(0xff8a5e),
gold: material(0xf2b642, 0.55),
goldDark: material(0xb87b24, 0.6),
cream: material(0xffefd0),
dark: material(0x183438),
black: material(0x102629),
shoulder: material(0x164f52)
};
function box(parent, size, position, meshMaterial, castShadow = true) {
const mesh = new THREE.Mesh(cubeGeometry, meshMaterial);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hashColor(i, j, k, seed, frontBoost = false) {
let h =
(Math.imul(i + seed, 73856093) ^
Math.imul(j + 17, 19349663) ^
Math.imul(k + 31, 83492791)) >>>
0;
h = Math.imul(h ^ (h >>> 13), 1274126177) >>> 0;
return (h + (frontBoost ? 1 : 0)) % 4;
}
function addVoxels(parent, options) {
const {
nx,
ny,
nz,
cell,
center = [0, 0, 0],
palette,
materials,
shape = null,
seed = 1,
gap = 0.025,
surfaceOnly = false
} = options;
const buckets = materials.map(() => []);
const dummy = new THREE.Object3D();
const occupied = (i, j, k) => {
if (i < 0 || j < 0 || k < 0 || i >= nx || j >= ny || k >= nz) {
return false;
}
return shape ? shape(i, j, k) : true;
};
for (let k = 0; k < nz; k++) {
for (let j = 0; j < ny; j++) {
for (let i = 0; i < nx; i++) {
if (!occupied(i, j, k)) continue;
if (
surfaceOnly &&
occupied(i - 1, j, k) &&
occupied(i + 1, j, k) &&
occupied(i, j - 1, k) &&
occupied(i, j + 1, k) &&
occupied(i, j, k - 1) &&
occupied(i, j, k + 1)
) {
continue;
}
const index = hashColor(i, j, k, seed, k === nz - 1) % materials.length;
buckets[index].push([i, j, k]);
}
}
}
buckets.forEach((positions, index) => {
if (!positions.length) return;
const mesh = new THREE.InstancedMesh(
cubeGeometry,
materials[index],
positions.length
);
positions.forEach(([i, j, k], instanceIndex) => {
dummy.position.set(
center[0] + (i - (nx - 1) / 2) * cell,
center[1] + (j - (ny - 1) / 2) * cell,
center[2] + (k - (nz - 1) / 2) * cell
);
dummy.scale.set(cell - gap, cell - gap, cell - gap);
dummy.updateMatrix();
mesh.setMatrixAt(instanceIndex, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
});
}
// Display plinth
const plinth = new THREE.Group();
world.add(plinth);
box(plinth, [6.2, 0.38, 4.8], [0, 0.19, 0.05], material(0xb7c8c0));
box(plinth, [5.45, 0.22, 4.2], [0, 0.49, 0.05], material(0xd6dfd7));
box(plinth, [4.8, 0.24, 3.6], [0, 0.71, 0.05], material(0xf1ead9));
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
material(0xdfe9e3)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
// Main backpack shell
const backpack = new THREE.Group();
world.add(backpack);
const bodyShape = (i, j, k) => {
const x = i - 5.5;
const y = j;
if (y === 13 && Math.abs(x) > 4.5) return false;
if (y === 12 && Math.abs(x) > 5.5) return false;
if (y === 0 && Math.abs(x) > 5.5) return false;
return true;
};
addVoxels(backpack, {
nx: 12,
ny: 14,
nz: 6,
cell: 0.3,
center: [0, 2.92, 0],
palette: [0, 1, 2, 3],
materials: [mat.teal, mat.tealDark, mat.tealLight, mat.tealPale],
shape: bodyShape,
surfaceOnly: true,
seed: 11,
gap: 0.027
});
// Dark inner compartment revealed by the lid
const compartment = new THREE.Group();
backpack.add(compartment);
addVoxels(compartment, {
nx: 9,
ny: 7,
nz: 1,
cell: 0.28,
center: [0, 3.77, 1.0],
palette: [0, 1],
materials: [mat.dark, mat.black],
seed: 31,
gap: 0.018
});
box(compartment, [1.2, 0.62, 0.13], [-0.45, 3.42, 1.17], mat.coralDark);
box(compartment, [0.58, 0.26, 0.14], [0.58, 3.8, 1.18], mat.gold);
// Front pocket
const pocket = new THREE.Group();
backpack.add(pocket);
addVoxels(pocket, {
nx: 10,
ny: 6,
nz: 2,
cell: 0.25,
center: [0, 1.64, 1.125],
palette: [0, 1, 2],
materials: [mat.coral, mat.coralDark, mat.coralLight],
surfaceOnly: true,
seed: 22,
gap: 0.022
});
// Side pockets
for (const side of [-1, 1]) {
const sidePocket = new THREE.Group();
sidePocket.position.set(side * 1.89, 1.65, -0.12);
backpack.add(sidePocket);
addVoxels(sidePocket, {
nx: 3,
ny: 5,
nz: 4,
cell: 0.22,
center: [0, 0, 0],
palette: [0, 1],
materials: [mat.coralDark, mat.coral],
shape: (i, j, k) => !(j === 4 && (i === 0 || i === 2)),
surfaceOnly: true,
seed: side > 0 ? 40 : 41,
gap: 0.02
});
box(
sidePocket,
[0.7, 0.12, 0.12],
[0, 0.62, 0.5],
mat.gold
);
}
// Shoulder straps visible from the sides
for (const side of [-1, 1]) {
const strap = new THREE.Group();
strap.position.set(side * 0.94, 3.05, -1.02);
strap.rotation.z = side * 0.07;
backpack.add(strap);
box(strap, [0.36, 2.7, 0.22], [0, 0, 0], mat.shoulder);
box(strap, [0.46, 0.35, 0.28], [0, -1.4, 0.02], mat.dark);
box(strap, [0.5, 0.14, 0.3], [0, -0.55, 0], mat.gold);
}
// Top carry handle
const handle = new THREE.Group();
handle.position.set(0, 5.02, -0.1);
backpack.add(handle);
box(handle, [0.25, 0.58, 0.28], [-0.58, 0.18, 0], mat.dark);
box(handle, [0.25, 0.58, 0.28], [0.58, 0.18, 0], mat.dark);
box(handle, [1.4, 0.24, 0.28], [0, 0.48, 0], mat.dark);
box(handle, [0.45, 0.18, 0.31], [0, 0.48, 0], mat.gold);
// Hinged top lid
const lid = new THREE.Group();
lid.position.set(0, 4.95, 0.93);
backpack.add(lid);
addVoxels(lid, {
nx: 12,
ny: 7,
nz: 2,
cell: 0.3,
center: [0, -1.05, 0],
palette: [0, 1, 2, 3],
materials: [mat.tealLight, mat.teal, mat.tealDark, mat.tealPale],
shape: (i, j, k) => {
const x = i - 5.5;
if (j === 6 && Math.abs(x) > 4.5) return false;
return true;
},
seed: 51,
gap: 0.027
});
// Small pixel-style brand badge
const badgeCells = [
[-1, -1],
[0, -1],
[1, -1],
[-1, 0],
[1, 0],
[-1, 1],
[0, 1],
[1, 1]
];
badgeCells.forEach(([x, y]) => {
box(
lid,
[0.15, 0.15, 0.07],
[0.72 + x * 0.16, -0.72 + y * 0.16, 0.33],
mat.cream
);
});
// Hook-and-loop patch and peel tab
const hookPatch = box(
lid,
[1.05, 0.52, 0.09],
[-0.75, -1.58, 0.34],
mat.gold
);
const hookTab = new THREE.Group();
hookTab.position.set(-0.75, -1.38, 0.4);
lid.add(hookTab);
box(hookTab, [0.43, 0.62, 0.1], [0, -0.27, 0.03], mat.coral);
box(hookTab, [0.34, 0.13, 0.11], [0, -0.54, 0.03], mat.cream);
hookTab.userData.action = "velcro";
hookPatch.userData.action = "velcro";
// Buckle strap and buckle
const buckleStrap = box(
backpack,
[0.3, 1.4, 0.1],
[0.83, 1.73, 1.43],
mat.gold
);
buckleStrap.userData.action = "buckle";
const buckle = new THREE.Group();
buckle.position.set(0.83, 2.57, 1.49);
backpack.add(buckle);
buckle.userData.action = "buckle";
box(buckle, [0.76, 0.12, 0.14], [0, 0.22, 0], mat.goldDark);
box(buckle, [0.76, 0.12, 0.14], [0, -0.22, 0], mat.goldDark);
const leftProng = new THREE.Group();
leftProng.position.set(-0.32, 0, 0);
buckle.add(leftProng);
box(leftProng, [0.12, 0.46, 0.14], [-0.05, 0, 0], mat.gold);
const rightProng = new THREE.Group();
rightProng.position.set(0.32, 0, 0);
buckle.add(rightProng);
box(rightProng, [0.12, 0.46, 0.14], [0.05, 0, 0], mat.gold);
const tongue = new THREE.Group();
tongue.position.set(0, -0.19, 0.09);
buckle.add(tongue);
box(tongue, [0.25, 0.43, 0.12], [0, 0.17, 0], mat.cream);
box(tongue, [0.35, 0.1, 0.13], [0, -0.02, 0], mat.gold);
// Zipper track and individual voxel teeth
const zipperTrack = box(
backpack,
[2.55, 0.09, 0.07],
[0, 2.31, 1.43],
mat.black,
false
);
zipperTrack.userData.action = "zipper";
for (let i = 0; i < 18; i++) {
const tooth = box(
backpack,
[0.075, 0.12, 0.09],
[-1.16 + i * 0.135, 2.31, 1.48],
mat.gold,
false
);
tooth.userData.action = "zipper";
}
// The fabric edge peels away as the zipper travels
const zipPeel = new THREE.Group();
zipPeel.position.set(-1.17, 2.245, 1.43);
backpack.add(zipPeel);
const zipPeelMesh = box(
zipPeel,
[1, 0.055, 0.045],
[0.5, 0, 0],
mat.coralDark,
false
);
zipPeelMesh.scale.set(0.001, 0.055, 0.045);
// Gold slider and pull
const zipperSlider = new THREE.Group();
zipperSlider.position.set(-1.16, 2.32, 1.53);
backpack.add(zipperSlider);
zipperSlider.userData.action = "zipper";
box(zipperSlider, [0.3, 0.24, 0.16], [0, 0, 0], mat.gold);
box(zipperSlider, [0.08, 0.36, 0.08], [0, -0.25, 0.01], mat.goldDark);
box(zipperSlider, [0.25, 0.08, 0.08], [0, -0.42, 0.01], mat.gold);
box(zipperSlider, [0.08, 0.27, 0.08], [-0.11, -0.56, 0.01], mat.gold);
box(zipperSlider, [0.08, 0.27, 0.08], [0.11, -0.56, 0.01], mat.gold);
box(zipperSlider, [0.25, 0.08, 0.08], [0, -0.68, 0.01], mat.gold);
// Marker anchors
const markerAnchors = {
velcro: new THREE.Object3D(),
buckle: new THREE.Object3D(),
zipper: new THREE.Object3D()
};
markerAnchors.velcro.position.set(-0.75, -1.55, 0.62);
lid.add(markerAnchors.velcro);
markerAnchors.buckle.position.set(0.83, 2.57, 1.72);
backpack.add(markerAnchors.buckle);
markerAnchors.zipper.position.set(0, 0, 0.3);
zipperSlider.add(markerAnchors.zipper);
// A few floating display voxels
const floating = [];
const floatingColors = [mat.coral, mat.gold, mat.tealLight, mat.cream];
[
[-3.3, 4.7, -1.3, 0.22],
[3.1, 5.6, -1.8, 0.18],
[-3.6, 2.2, -2.1, 0.15],
[3.5, 3.2, -2.6, 0.21]
].forEach(([x, y, z, s], i) => {
const mesh = box(world, [s, s, s], [x, y, z], floatingColors[i], false);
floating.push({
mesh,
baseY: y,
phase: i * 1.7
});
});
// State
const state = {
velcro: false,
buckle: false,
zipper: 0
};
const animated = {
velcro: 0,
buckle: 0,
zipper: 0
};
const closureButtons = [...document.querySelectorAll("[data-toggle]")];
const markerButtons = [...document.querySelectorAll("[data-action]")];
const velcroState = document.querySelector("#velcro-state");
const buckleState = document.querySelector("#buckle-state");
const zipperState = document.querySelector("#zipper-state");
const zipRange = document.querySelector("#zip-range");
const zipValue = document.querySelector("#zip-value");
function toggleClosure(action) {
if (action === "velcro") state.velcro = !state.velcro;
if (action === "buckle") state.buckle = !state.buckle;
if (action === "zipper") state.zipper = state.zipper > 0.5 ? 0 : 1;
syncUI();
}
closureButtons.forEach((button) => {
button.addEventListener("click", () => toggleClosure(button.dataset.toggle));
});
markerButtons.forEach((button) => {
button.addEventListener("click", (event) => {
event.stopPropagation();
toggleClosure(button.dataset.action);
});
});
zipRange.addEventListener("input", () => {
state.zipper = Number(zipRange.value) / 100;
syncUI();
});
document.querySelector("#open-all").addEventListener("click", () => {
state.velcro = true;
state.buckle = true;
state.zipper = 1;
syncUI();
});
document.querySelector("#reset-all").addEventListener("click", () => {
state.velcro = false;
state.buckle = false;
state.zipper = 0;
syncUI();
});
function syncUI() {
velcroState.textContent = state.velcro ? "Open" : "Closed";
buckleState.textContent = state.buckle ? "Open" : "Closed";
zipperState.textContent =
state.zipper >= 0.99 ? "Open" : `${Math.round(state.zipper * 100)}%`;
closureButtons.forEach((button) => {
const action = button.dataset.toggle;
const active =
action === "zipper" ? state.zipper > 0.02 : state[action];
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
const percent = Math.round(state.zipper * 100);
zipRange.value = percent;
zipRange.style.setProperty("--zip", `${percent}%`);
zipValue.textContent = `${percent}%`;
}
syncUI();
// Direct camera controls
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const interactables = [hookTab, hookPatch, buckle, zipperSlider, zipperTrack];
let pointerDown = false;
let moved = false;
let draggingZipper = false;
let pointerX = 0;
let pointerY = 0;
let startX = 0;
let startY = 0;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickAction(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactables, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object) {
if (object.userData.action) return object.userData.action;
object = object.parent;
}
return null;
}
function zipperFromPointer(event) {
const rect = canvas.getBoundingClientRect();
const a = new THREE.Vector3(-1.16, 2.32, 1.53).project(camera);
const b = new THREE.Vector3(1.16, 2.32, 1.53).project(camera);
const ax = rect.left + ((a.x + 1) / 2) * rect.width;
const ay = rect.top + ((-a.y + 1) / 2) * rect.height;
const bx = rect.left + ((b.x + 1) / 2) * rect.width;
const by = rect.top + ((-b.y + 1) / 2) * rect.height;
const dx = bx - ax;
const dy = by - ay;
const px = event.clientX - ax;
const py = event.clientY - ay;
const lengthSquared = dx * dx + dy * dy;
const t = lengthSquared
? THREE.MathUtils.clamp((px * dx + py * dy) / lengthSquared, 0, 1)
: 0;
state.zipper = t;
syncUI();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
moved = false;
pointerX = event.clientX;
pointerY = event.clientY;
startX = event.clientX;
startY = event.clientY;
const action = pickAction(event);
draggingZipper = action === "zipper";
if (draggingZipper) {
canvas.setPointerCapture(event.pointerId);
zipperFromPointer(event);
}
});
canvas.addEventListener("pointermove", (event) => {
if (draggingZipper) {
zipperFromPointer(event);
return;
}
if (pointerDown) {
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
if (
Math.abs(event.clientX - startX) +
Math.abs(event.clientY - startY) >
4
) {
moved = true;
}
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.58,
1.43
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
} else {
const action = pickAction(event);
canvas.style.cursor = action ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && !moved && !draggingZipper) {
const action = pickAction(event);
if (action) toggleClosure(action);
}
pointerDown = false;
draggingZipper = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
draggingZipper = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.008,
5.7,
13
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
controls.radius = 8.8;
controls.theta = 0.49;
controls.phi = 1.12;
updateCamera();
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// Marker projection
const hotspotElements = {
velcro: document.querySelector('[data-action="velcro"]'),
buckle: document.querySelector('[data-action="buckle"]'),
zipper: document.querySelector('[data-action="zipper"]')
};
const projected = new THREE.Vector3();
function updateMarkers() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const key of Object.keys(markerAnchors)) {
markerAnchors[key].getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
const element = hotspotElements[key];
element.classList.toggle("visible", visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
}
}
function damp(current, target, speed, dt) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-speed * dt)
);
}
function smoothstep01(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
animated.velcro = damp(
animated.velcro,
state.velcro ? 1 : 0,
5.5,
dt
);
animated.buckle = damp(
animated.buckle,
state.buckle ? 1 : 0,
7,
dt
);
animated.zipper = damp(
animated.zipper,
state.zipper,
9,
dt
);
// Peel the hook-and-loop tab, then lift the lid.
hookTab.rotation.x = -1.48 * animated.velcro;
const lidAmount = smoothstep01((animated.velcro - 0.28) / 0.72);
lid.rotation.x = -1.86 * lidAmount;
// Buckle prongs release and the tongue lifts free.
leftProng.rotation.z = -0.55 * animated.buckle;
rightProng.rotation.z = 0.55 * animated.buckle;
tongue.position.y = -0.19 + animated.buckle * 0.19;
tongue.position.z = 0.09 + animated.buckle * 0.08;
tongue.rotation.z = -0.13 * animated.buckle;
// Zipper pull and peeled fabric edge.
const zipX = THREE.MathUtils.lerp(
-1.16,
1.16,
animated.zipper
);
zipperSlider.position.x = zipX;
const peelWidth = 2.32 * animated.zipper;
zipPeelMesh.scale.x = Math.max(0.001, peelWidth);
zipPeelMesh.position.x = Math.max(0.001, peelWidth) / 2;
zipPeelMesh.visible = animated.zipper > 0.005;
// Gentle floating display cubes.
floating.forEach((item) => {
item.mesh.position.y =
item.baseY + Math.sin(performance.now() * 0.0007 + item.phase) * 0.12;
item.mesh.rotation.x += dt * 0.25;
item.mesh.rotation.y += dt * 0.32;
});
updateMarkers();
renderer.render(scene, camera);
}
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
animate();
</script>
</body>
</html>
```