Prompt specification
Build or customize the Three.js 3D scene "Weekend suitcase packing" 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: Weekend suitcase packing
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/weekend-suitcase-packing-x0575
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows clothing folds and packing. Compose an open suitcase, folded clothes, shoes, and toiletries; place items in separate regions and show the lid closing only after all contents fit below its plane. Stylized solid forms.
Working Three.js Starter (weekend-suitcase-packing-x0575):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fold / Pack — Suitcase Study</title>
<style>
:root {
--ink: #183534;
--muted: #617370;
--paper: rgba(250, 247, 239, 0.88);
--line: rgba(24, 53, 52, 0.14);
--coral: #e8785f;
--sage: #8eb9a7;
--gold: #e2b956;
--cyan: #50cfc3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel,
.status,
.controls {
pointer-events: auto;
}
.panel {
position: absolute;
top: 24px;
left: 24px;
width: min(350px, calc(100vw - 48px));
padding: 24px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 24px;
background: var(--paper);
box-shadow:
0 20px 60px rgba(40, 61, 57, 0.12),
inset 0 0 0 1px rgba(24, 53, 52, 0.03);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 19px;
height: 2px;
border-radius: 2px;
background: var(--coral);
content: "";
}
h1 {
margin: 0;
font-size: clamp(31px, 4vw, 46px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.description {
margin: 15px 0 19px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #52625f;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
}
.swatch.fold {
background: var(--coral);
}
.swatch.shoes {
background: var(--sage);
}
.swatch.care {
background: var(--gold);
}
.status {
position: absolute;
top: 24px;
right: 24px;
width: min(285px, calc(100vw - 48px));
padding: 17px 18px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 19px;
background: rgba(250, 247, 239, 0.82);
box-shadow: 0 16px 45px rgba(40, 61, 57, 0.10);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.status-top {
display: flex;
align-items: center;
gap: 9px;
}
#statusDot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: #8e9d98;
box-shadow: 0 0 0 4px rgba(142, 157, 152, 0.12);
transition: background 180ms ease, box-shadow 180ms ease;
}
#statusDot.work {
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(80, 207, 195, 0.16);
}
#statusDot.good {
background: #4a9e79;
box-shadow: 0 0 0 4px rgba(74, 158, 121, 0.15);
}
#statusDot.bad {
background: #d66054;
box-shadow: 0 0 0 4px rgba(214, 96, 84, 0.15);
}
#statusText {
font-size: 12px;
font-weight: 780;
}
#statusDetail {
min-height: 31px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.meter {
height: 3px;
margin-top: 12px;
overflow: hidden;
border-radius: 4px;
background: rgba(24, 53, 52, 0.09);
}
#progress {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--coral);
transition: width 100ms linear;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 9px;
}
button {
border: 0;
border-radius: 14px;
padding: 13px 18px;
color: white;
background: var(--ink);
box-shadow: 0 9px 24px rgba(24, 53, 52, 0.17);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, opacity 150ms ease,
background 150ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
background: #244845;
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: default;
opacity: 0.55;
}
button.secondary {
color: var(--ink);
background: rgba(250, 247, 239, 0.88);
box-shadow: 0 9px 24px rgba(40, 61, 57, 0.08);
}
.hint {
position: absolute;
bottom: 28px;
left: 50%;
transform: translateX(-50%);
padding: 9px 13px;
border-radius: 999px;
color: rgba(24, 53, 52, 0.67);
background: rgba(250, 247, 239, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
white-space: nowrap;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--ink);
background: #e9e4da;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease, visibility 350ms ease;
}
#loading.hidden {
visibility: hidden;
opacity: 0;
}
@media (max-width: 700px) {
.panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 18px;
border-radius: 20px;
}
h1 {
font-size: 31px;
}
.description {
max-width: 90%;
margin: 10px 0 13px;
font-size: 11px;
}
.legend {
padding-top: 12px;
}
.status {
top: auto;
right: 14px;
bottom: 74px;
width: calc(100vw - 28px);
padding: 13px 15px;
}
#statusDetail {
min-height: 0;
}
.controls {
right: 14px;
bottom: 14px;
}
button {
padding: 12px 15px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="hud">
<section class="panel">
<div class="eyebrow">Suitcase study 01</div>
<h1>Fold, fit,<br>close.</h1>
<p class="description">
Each group has its own compartment. The cyan plane is the lid’s
clearance limit; the suitcase stays open until every item fits below it.
</p>
<div class="legend">
<div class="legend-item">
<span class="swatch fold"></span>
Folded
</div>
<div class="legend-item">
<span class="swatch shoes"></span>
Shoes
</div>
<div class="legend-item">
<span class="swatch care"></span>
Care
</div>
</div>
</section>
<aside class="status" aria-live="polite">
<div class="status-top">
<span id="statusDot"></span>
<strong id="statusText">Ready to pack</strong>
</div>
<div id="statusDetail">
Three folds, one pair of shoes, and three care items are staged.
</div>
<div class="meter"><i id="progress"></i></div>
</aside>
<div class="controls">
<button id="resetButton" class="secondary">Reset</button>
<button id="packButton">Pack all</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to rotate</div>
</div>
<div id="loading">Preparing suitcase</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const packButton = document.getElementById("packButton");
const resetButton = document.getElementById("resetButton");
const statusText = document.getElementById("statusText");
const statusDetail = document.getElementById("statusDetail");
const statusDot = document.getElementById("statusDot");
const progress = document.getElementById("progress");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4da);
scene.fog = new THREE.Fog(0xe9e4da, 20, 38);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.9, 0.1);
let cameraTheta = 0.78;
let cameraPhi = 0.73;
let cameraRadius = 15.5;
let cameraWasAdjusted = false;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff9e9, 0x78928d, 2.35);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff4dc, 3.2);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e4df, 1.2);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffb58f, 0.7);
rimLight.position.set(-7, 4, -4);
scene.add(rimLight);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.02,
...options
});
}
const materials = {
shell: standard(0x2d6970),
shellDark: standard(0x17484f),
shellLight: standard(0x4d8587),
lining: standard(0xeee1c9),
liningShade: standard(0xd8c8ac),
pocket: standard(0xb9cbc0, {
transparent: true,
opacity: 0.83,
roughness: 0.85
}),
strap: standard(0x8e7562),
handle: standard(0x233b3d),
cream: standard(0xf2ead9),
sole: standard(0xf3eee0),
coral: standard(0xe8785f),
yellow: standard(0xe2b956),
blue: standard(0x638ca7),
sage: standard(0x8eb9a7),
teal: standard(0x428c87),
dark: standard(0x253f43)
};
function roundedSlabGeometry(width, depth, height, radius = 0.12) {
const w = width;
const d = depth;
const r = Math.min(radius, w / 2, d / 2);
const shape = new THREE.Shape();
shape.moveTo(-w / 2 + r, -d / 2);
shape.lineTo(w / 2 - r, -d / 2);
shape.quadraticCurveTo(w / 2, -d / 2, w / 2, -d / 2 + r);
shape.lineTo(w / 2, d / 2 - r);
shape.quadraticCurveTo(w / 2, d / 2, w / 2 - r, d / 2);
shape.lineTo(-w / 2 + r, d / 2);
shape.quadraticCurveTo(-w / 2, d / 2, -w / 2, d / 2 - r);
shape.lineTo(-w / 2, -d / 2 + r);
shape.quadraticCurveTo(-w / 2, -d / 2, -w / 2 + r, -d / 2);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: height,
bevelEnabled: false,
curveSegments: 8,
steps: 1
});
geometry.rotateX(-Math.PI / 2);
geometry.translate(0, -height / 2, 0);
geometry.computeVertexNormals();
return geometry;
}
function slab(width, depth, height, radius, material) {
const mesh = new THREE.Mesh(
roundedSlabGeometry(width, depth, height, radius),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinder(radiusTop, radiusBottom, height, material, segments = 24) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function labelTexture(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(255,255,255,0.58)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#294845";
ctx.font = "800 40px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function floorLabel(text, x, z, width = 1.1) {
const material = new THREE.MeshBasicMaterial({
map: labelTexture(text),
transparent: true,
depthWrite: false,
toneMapped: false
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 96 / 512),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.617, z);
mesh.renderOrder = 2;
scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground and suitcase base
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.CircleGeometry(18, 96),
standard(0xe9e4da, { roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.012;
floor.receiveShadow = true;
scene.add(floor);
const baseShell = slab(6.4, 4.6, 0.3, 0.3, materials.shell);
baseShell.position.y = 0.25;
scene.add(baseShell);
const baseTrim = slab(6.18, 4.38, 0.09, 0.25, materials.shellDark);
baseTrim.position.y = 0.43;
scene.add(baseTrim);
const interiorFloor = slab(5.78, 3.96, 0.14, 0.22, materials.lining);
interiorFloor.position.y = 0.49;
scene.add(interiorFloor);
const railHeight = 0.56;
const railY = 0.72;
const leftRail = slab(0.34, 4.34, railHeight, 0.15, materials.shell);
leftRail.position.set(-3.02, railY, 0);
scene.add(leftRail);
const rightRail = leftRail.clone();
rightRail.position.x = 3.02;
scene.add(rightRail);
const frontRail = slab(6.05, 0.34, railHeight, 0.15, materials.shell);
frontRail.position.set(0, railY, 2.12);
scene.add(frontRail);
const backRail = frontRail.clone();
backRail.position.z = -2.12;
scene.add(backRail);
// A subtle front grip and two latches.
const grip = slab(1.55, 0.2, 0.16, 0.09, materials.handle);
grip.position.set(0, 0.58, 2.43);
scene.add(grip);
for (const x of [-1.9, 1.9]) {
const latch = slab(0.32, 0.16, 0.3, 0.06, materials.shellDark);
latch.position.set(x, 0.91, 2.3);
scene.add(latch);
const latchFace = slab(0.2, 0.04, 0.1, 0.025, materials.cream);
latchFace.position.set(x, 0.97, 2.395);
scene.add(latchFace);
}
// ------------------------------------------------------------
// Dedicated packing regions
// ------------------------------------------------------------
function createRegion(name, color, x, z, width, depth) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
emissive: new THREE.Color(color).multiplyScalar(0.11),
emissiveIntensity: 0.2
});
const mesh = slab(width, depth, 0.045, 0.16, material);
mesh.position.set(x, 0.585, z);
scene.add(mesh);
return {
name,
mesh,
material,
baseGlow: 0.2,
activeUntil: 0
};
}
const regions = {
fold: createRegion(
"Folded",
0xe9b4a7,
-1.55,
0,
2.35,
3.45
),
shoes: createRegion(
"Shoes",
0x9dc5b6,
1.42,
-0.77,
2.35,
1.78
),
care: createRegion(
"Care",
0xe6c982,
1.42,
1.3,
2.35,
1.0
)
};
floorLabel("FOLDED", -1.55, -1.48, 1.2);
floorLabel("SHOES", 1.42, -1.43, 1.05);
floorLabel("CARE", 1.42, 1.63, 0.86);
// ------------------------------------------------------------
// Hinged lid
// ------------------------------------------------------------
const LID_OPEN_ANGLE = -1.95;
const lid = new THREE.Group();
lid.position.set(0, 1.1, -2.3);
lid.rotation.x = LID_OPEN_ANGLE;
scene.add(lid);
const lidShell = slab(6.4, 4.6, 0.18, 0.3, materials.shell);
lidShell.position.set(0, 0.09, 2.3);
lid.add(lidShell);
const lidLiner = slab(5.86, 4.06, 0.06, 0.22, materials.lining);
lidLiner.position.set(0, -0.03, 2.3);
lid.add(lidLiner);
// Gasket around the inside of the lid.
const gasketMaterial = standard(0x587477);
const gasketLeft = slab(0.14, 3.9, 0.04, 0.05, gasketMaterial);
gasketLeft.position.set(-2.83, -0.075, 2.3);
lid.add(gasketLeft);
const gasketRight = gasketLeft.clone();
gasketRight.position.x = 2.83;
lid.add(gasketRight);
const gasketFront = slab(5.58, 0.14, 0.04, 0.05, gasketMaterial);
gasketFront.position.set(0, -0.075, 4.22);
lid.add(gasketFront);
const gasketBack = gasketFront.clone();
gasketBack.position.z = 0.38;
lid.add(gasketBack);
// Flat mesh pocket and straps on the inner face.
const pocket = slab(4.82, 2.36, 0.025, 0.16, materials.pocket);
pocket.position.set(0, -0.082, 2.4);
lid.add(pocket);
const pocketBorder = slab(4.96, 2.5, 0.018, 0.17, materials.liningShade);
pocketBorder.position.set(0, -0.069, 2.4);
lid.add(pocketBorder);
for (const x of [-1.42, 1.42]) {
const strap = slab(0.085, 3.38, 0.025, 0.03, materials.strap);
strap.position.set(x, -0.104, 2.3);
lid.add(strap);
const buckle = slab(0.18, 0.23, 0.03, 0.035, materials.cream);
buckle.position.set(x, -0.12, 1.72);
lid.add(buckle);
}
const pocketZip = slab(4.38, 0.045, 0.018, 0.015, materials.shellDark);
pocketZip.position.set(0, -0.112, 3.48);
lid.add(pocketZip);
// Hinge barrels.
for (const x of [-1.85, 1.85]) {
const barrel = cylinder(
0.13,
0.13,
0.68,
materials.shellDark,
24
);
barrel.rotation.z = Math.PI / 2;
barrel.position.set(x, 1.1, -2.3);
scene.add(barrel);
}
// ------------------------------------------------------------
// Lid clearance plane
// ------------------------------------------------------------
const CLEARANCE_Y = 1.01;
const clearanceMaterial = new THREE.MeshBasicMaterial({
color: 0x50cfc3,
transparent: true,
opacity: 0.11,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
});
const clearancePlane = new THREE.Mesh(
new THREE.PlaneGeometry(5.52, 3.72),
clearanceMaterial
);
clearancePlane.rotation.x = -Math.PI / 2;
clearancePlane.position.y = CLEARANCE_Y;
clearancePlane.visible = false;
clearancePlane.renderOrder = 3;
scene.add(clearancePlane);
const clearanceLineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.76, 0, -1.86),
new THREE.Vector3(2.76, 0, -1.86),
new THREE.Vector3(2.76, 0, 1.86),
new THREE.Vector3(-2.76, 0, 1.86)
]);
const clearanceLine = new THREE.LineLoop(
clearanceLineGeometry,
new THREE.LineBasicMaterial({
color: 0x38bfb5,
transparent: true,
opacity: 0.72,
toneMapped: false
})
);
clearanceLine.position.y = CLEARANCE_Y + 0.004;
clearanceLine.visible = false;
clearanceLine.renderOrder = 4;
scene.add(clearanceLine);
// ------------------------------------------------------------
// Stylized packed objects
// ------------------------------------------------------------
function createFoldedGarment(color, accentColor) {
const group = new THREE.Group();
const baseMaterial = standard(color);
const middleMaterial = baseMaterial.clone();
middleMaterial.color.offsetHSL(0, -0.03, -0.055);
const topMaterial = baseMaterial.clone();
topMaterial.color.offsetHSL(0, 0.02, 0.035);
const layerHeight = 0.052;
for (let i = 0; i < 3; i++) {
const layer = slab(
1.7 - i * 0.045,
1.02 - i * 0.025,
layerHeight,
0.14,
i === 0 ? middleMaterial : i === 1 ? baseMaterial : topMaterial
);
layer.position.set(i * 0.012, i * 0.056 + layerHeight / 2, i * 0.008);
group.add(layer);
}
// The folded-over upper panel creates a readable garment crease.
const flap = slab(0.68, 0.76, 0.035, 0.12, topMaterial);
flap.position.set(0.46, 0.177, -0.04);
group.add(flap);
const crease = slab(1.27, 0.035, 0.012, 0.014, standard(accentColor));
crease.position.set(-0.08, 0.193, 0.25);
group.add(crease);
const edgeFold = slab(1.45, 0.045, 0.015, 0.015, standard(accentColor));
edgeFold.position.set(0, 0.126, 0.502);
group.add(edgeFold);
return group;
}
function createShoe(upperColor) {
const group = new THREE.Group();
const upperMaterial = standard(upperColor);
const sole = slab(0.69, 1.48, 0.1, 0.22, materials.sole);
sole.position.y = 0.05;
group.add(sole);
const upper = new THREE.Mesh(
new THREE.SphereGeometry(1, 28, 18),
upperMaterial
);
upper.scale.set(0.3, 0.18, 0.55);
upper.position.set(0, 0.18, 0.09);
upper.castShadow = true;
upper.receiveShadow = true;
group.add(upper);
const opening = new THREE.Mesh(
new THREE.CircleGeometry(1, 28),
materials.dark
);
opening.rotation.x = -Math.PI / 2;
opening.scale.set(0.13, 0.23, 1);
opening.position.set(0, 0.356, -0.31);
group.add(opening);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.038, 10, 28),
standard(upperColor).clone()
);
collar.material.color.offsetHSL(0, 0, -0.08);
collar.rotation.x = Math.PI / 2;
collar.scale.set(0.78, 1.3, 1);
collar.position.set(0, 0.361, -0.31);
collar.castShadow = true;
group.add(collar);
for (let i = 0; i < 3; i++) {
const lace = slab(0.31 - i * 0.025, 0.035, 0.015, 0.014, materials.cream);
lace.position.set(0, 0.365 - i * 0.012, 0.02 + i * 0.12);
group.add(lace);
}
const heel = slab(0.48, 0.18, 0.06, 0.06, upperMaterial);
heel.position.set(0, 0.26, -0.54);
group.add(heel);
return group;
}
function createShoePair() {
const group = new THREE.Group();
const left = createShoe(0xd96f55);
left.position.set(-0.42, 0, 0.04);
left.rotation.y = 0.08;
group.add(left);
const right = createShoe(0x4f7379);
right.position.set(0.42, 0, -0.06);
right.rotation.y = -0.08;
group.add(right);
return group;
}
function createToiletries() {
const group = new THREE.Group();
const bottleMaterial = standard(0x438f87);
const bottle = cylinder(0.15, 0.165, 0.23, bottleMaterial, 24);
bottle.position.set(-0.48, 0.115, -0.18);
group.add(bottle);
const shoulder = new THREE.Mesh(
new THREE.SphereGeometry(1, 24, 12),
bottleMaterial
);
shoulder.scale.set(0.15, 0.055, 0.15);
shoulder.position.set(-0.48, 0.245, -0.18);
shoulder.castShadow = true;
group.add(shoulder);
const cap = cylinder(0.085, 0.085, 0.06, materials.cream, 20);
cap.position.set(-0.48, 0.3, -0.18);
group.add(cap);
const pump = slab(0.2, 0.07, 0.035, 0.025, materials.cream);
pump.position.set(-0.44, 0.342, -0.18);
group.add(pump);
const jarMaterial = standard(0xf0d9ac);
const jar = cylinder(0.2, 0.19, 0.18, jarMaterial, 24);
jar.position.set(0.15, 0.09, 0.16);
group.add(jar);
const jarLid = cylinder(0.205, 0.205, 0.04, materials.cream, 24);
jarLid.position.set(0.15, 0.2, 0.16);
group.add(jarLid);
const tube = slab(0.27, 0.34, 0.25, 0.1, materials.coral);
tube.position.set(0.68, 0.125, -0.04);
group.add(tube);
const tubeCap = slab(0.16, 0.12, 0.045, 0.025, materials.cream);
tubeCap.position.set(0.68, 0.267, -0.04);
group.add(tubeCap);
const label = slab(0.18, 0.012, 0.11, 0.02, materials.cream);
label.position.set(0.68, 0.135, 0.134);
group.add(label);
return group;
}
// ------------------------------------------------------------
// Staged and target transforms
// ------------------------------------------------------------
const itemDefinitions = [
{
name: "Coral folded shirt",
region: "fold",
object: createFoldedGarment(0xe8785f, 0xb94d40),
from: new THREE.Vector3(-4.95, 0.025, 1.2),
to: new THREE.Vector3(-1.95, 0.61, -1.02),
fromRotation: -0.22,
toRotation: -0.04,
arc: 1.2
},
{
name: "Golden folded shirt",
region: "fold",
object: createFoldedGarment(0xe2b956, 0xa97828),
from: new THREE.Vector3(-4.85, 0.025, 2.42),
to: new THREE.Vector3(-1.95, 0.61, 0.04),
fromRotation: 0.2,
toRotation: 0.03,
arc: 1.35
},
{
name: "Blue folded shirt",
region: "fold",
object: createFoldedGarment(0x638ca7, 0x3e667f),
from: new THREE.Vector3(-3.7, 0.025, 3.28),
to: new THREE.Vector3(-1.53, 0.61, 1.14),
fromRotation: -0.13,
toRotation: 0.08,
arc: 1.1
},
{
name: "Pair of shoes",
region: "shoes",
object: createShoePair(),
from: new THREE.Vector3(4.7, 0.025, 1.75),
to: new THREE.Vector3(1.42, 0.61, -0.75),
fromRotation: -0.28,
toRotation: 0,
arc: 1.45
},
{
name: "Toiletries",
region: "care",
object: createToiletries(),
from: new THREE.Vector3(5.15, 0.025, -0.32),
to: new THREE.Vector3(1.42, 0.61, 1.28),
fromRotation: 0.26,
toRotation: 0,
arc: 1.55
}
];
const items = itemDefinitions.map((definition) => {
definition.object.position.copy(definition.from);
definition.object.rotation.y = definition.fromRotation;
scene.add(definition.object);
return {
...definition,
packed: false,
startTime: 0,
duration: 1200
};
});
// ------------------------------------------------------------
// Packing state machine
// ------------------------------------------------------------
let phase = "ready";
let packStartTime = 0;
let packEndTime = 0;
let lidAnimation = null;
let autoTimer = 0;
function setStatus(title, detail, state = "idle") {
statusText.textContent = title;
statusDetail.textContent = detail;
statusDot.className = state;
}
function resetScene() {
window.clearTimeout(autoTimer);
phase = "ready";
lidAnimation = null;
lid.rotation.x = LID_OPEN_ANGLE;
clearancePlane.visible = false;
clearanceLine.visible = false;
clearanceMaterial.color.setHex(0x50cfc3);
for (const item of items) {
item.object.position.copy(item.from);
item.object.rotation.y = item.fromRotation;
item.packed = false;
}
for (const region of Object.values(regions)) {
region.activeUntil = 0;
}
progress.style.width = "0%";
packButton.disabled = false;
packButton.textContent = "Pack all";
setStatus(
"Ready to pack",
"Three folds, one pair of shoes, and three care items are staged.",
"idle"
);
}
function beginPack() {
window.clearTimeout(autoTimer);
if (phase === "done") {
resetScene();
}
phase = "packing";
packButton.disabled = true;
packButton.textContent = "Packing…";
clearancePlane.visible = true;
clearanceLine.visible = true;
const now = performance.now();
packStartTime = now + 300;
items.forEach((item, index) => {
item.startTime = packStartTime + index * 1450;
item.packed = false;
item.object.position.copy(item.from);
item.object.rotation.y = item.fromRotation;
});
packEndTime = items[items.length - 1].startTime + 1200;
setStatus(
"Packing compartments",
"Each item is checked only after it settles into its zone.",
"work"
);
}
function verifyFit() {
phase = "checking";
scene.updateMatrixWorld(true);
let highestPoint = -Infinity;
let tallestName = "";
let blocked = false;
for (const item of items) {
const bounds = new THREE.Box3().setFromObject(item.object, true);
const top = bounds.max.y;
if (top > highestPoint) {
highestPoint = top;
tallestName = item.name;
}
if (top > CLEARANCE_Y + 0.006) {
blocked = true;
item.object.traverse((child) => {
if (child.isMesh && child.material?.emissive) {
child.material.emissive.setHex(0xd66054);
child.material.emissiveIntensity = 0.32;
}
});
}
}
const clearance = Math.max(
0,
CLEARANCE_Y - highestPoint
).toFixed(3);
progress.style.width = "100%";
if (!blocked) {
phase = "closing";
setStatus(
"All contents clear",
`Tallest point: ${highestPoint.toFixed(3)} m · ` +
`${clearance} m below the lid plane. Closing now.`,
"good"
);
lidAnimation = {
start: performance.now() + 260,
from: lid.rotation.x,
to: 0,
duration: 1750
};
} else {
phase = "blocked";
clearanceMaterial.color.setHex(0xd66054);
clearanceLine.material.color.setHex(0xd66054);
setStatus(
"Lid blocked",
`${tallestName} exceeds the clearance plane. ` +
"The lid will remain open.",
"bad"
);
packButton.disabled = false;
packButton.textContent = "Try again";
}
}
function smoothstep(value) {
return value * value * (3 - 2 * value);
}
function updatePacking(now) {
if (phase === "packing") {
let movingItem = null;
for (const item of items) {
if (now < item.startTime) continue;
const rawT = Math.min(
1,
Math.max(0, (now - item.startTime) / item.duration)
);
if (rawT < 1) {
movingItem = item;
}
const t = smoothstep(rawT);
item.object.position.lerpVectors(item.from, item.to, t);
item.object.position.y += Math.sin(rawT * Math.PI) * item.arc;
item.object.rotation.y = THREE.MathUtils.lerp(
item.fromRotation,
item.toRotation,
t
);
if (rawT >= 1 && !item.packed) {
item.packed = true;
item.object.position.copy(item.to);
item.object.rotation.y = item.toRotation;
}
}
const totalDuration = Math.max(1, packEndTime - packStartTime);
progress.style.width =
`${Math.min(100, ((now - packStartTime) / totalDuration) * 100)}%`;
if (movingItem) {
regions[movingItem.region].activeUntil = now + 500;
setStatus(
`Fitting ${movingItem.name.toLowerCase()}`,
"The cyan plane remains active until every object is at rest.",
"work"
);
}
if (now >= packEndTime) {
verifyFit();
}
}
if (phase === "closing" && lidAnimation) {
const rawT = Math.min(
1,
Math.max(
0,
(now - lidAnimation.start) / lidAnimation.duration
)
);
const t = smoothstep(rawT);
lid.rotation.x = THREE.MathUtils.lerp(
lidAnimation.from,
lidAnimation.to,
t
);
clearanceMaterial.opacity = 0.11 * (1 - rawT);
clearanceLine.material.opacity = 0.72 * (1 - rawT);
if (rawT >= 1) {
phase = "done";
lid.rotation.x = 0;
clearancePlane.visible = false;
clearanceLine.visible = false;
packButton.disabled = false;
packButton.textContent = "Replay packing";
setStatus(
"Packed and closed",
"Every item settled below the clearance plane before the lid closed.",
"good"
);
}
}
}
// ------------------------------------------------------------
// Direct camera controls — no external control addons
// ------------------------------------------------------------
let dragging = false;
let dragDistance = 0;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
dragDistance += Math.abs(dx) + Math.abs(dy);
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.36,
1.28
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraWasAdjusted = true;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
9.5,
27
);
cameraWasAdjusted = true;
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraTheta += 0.12;
break;
case "ArrowRight":
cameraTheta -= 0.12;
break;
case "ArrowUp":
cameraPhi = Math.max(0.36, cameraPhi - 0.08);
break;
case "ArrowDown":
cameraPhi = Math.min(1.28, cameraPhi + 0.08);
break;
case "+":
case "=":
cameraRadius = Math.max(9.5, cameraRadius - 1);
break;
case "-":
cameraRadius = Math.min(27, cameraRadius + 1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
cameraWasAdjusted = true;
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
if (!cameraWasAdjusted) {
cameraRadius = camera.aspect < 0.8
? 24
: camera.aspect < 1.2
? 19
: 15.5;
updateCamera();
}
});
packButton.addEventListener("click", beginPack);
resetButton.addEventListener("click", resetScene);
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const now = performance.now();
updatePacking(now);
for (const region of Object.values(regions)) {
const target = now < region.activeUntil ? 0.68 : region.baseGlow;
region.material.emissiveIntensity = THREE.MathUtils.lerp(
region.material.emissiveIntensity,
target,
0.08
);
}
// A very small breathing motion keeps the still composition alive.
const elapsed = clock.getElapsedTime();
clearanceMaterial.opacity = phase === "packing" || phase === "checking"
? 0.095 + Math.sin(elapsed * 2.8) * 0.025
: clearanceMaterial.opacity;
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
// Begin the demonstration shortly after the scene is visible.
autoTimer = window.setTimeout(beginPack, 1300);
</script>
</body>
</html>
```