Prompt specification
Build or customize the Three.js 3D scene "Travel organizer personal-items tray" 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: Travel organizer personal-items tray
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/travel-organizer-personal-items-tray-x0635
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts watch straps. Compose a watch, wallet, glasses case, and charging cable in separate organizer pockets; animate packing and unpacking while each object returns to its designated compartment. Stylized solid forms.
Working Three.js Starter (travel-organizer-personal-items-tray-x0635):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Strap Pack — Three.js Organizer</title>
<style>
:root {
color-scheme: light;
--ink: #26323a;
--muted: #68747a;
--panel: rgba(255, 252, 246, 0.82);
--line: rgba(38, 50, 58, 0.12);
--accent: #b35f43;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e1d5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title {
position: fixed;
top: 28px;
left: 30px;
z-index: 2;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
color: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 800;
}
.subtitle {
max-width: 300px;
margin-top: 12px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.controls {
position: fixed;
top: 26px;
right: 26px;
z-index: 3;
display: flex;
gap: 8px;
}
button {
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 15px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 8px 24px rgba(48, 39, 29, 0.08);
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.96);
}
button:active {
transform: translateY(0);
}
.status {
position: fixed;
left: 28px;
bottom: 26px;
z-index: 2;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
box-shadow: 0 8px 24px rgba(48, 39, 29, 0.07);
backdrop-filter: blur(12px);
pointer-events: none;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(179, 95, 67, 0.12);
}
#status-text {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.hint {
position: fixed;
right: 28px;
bottom: 28px;
z-index: 2;
color: rgba(38, 50, 58, 0.6);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 700px) {
.title {
top: 20px;
left: 20px;
}
.subtitle {
display: none;
}
.controls {
top: auto;
right: 16px;
bottom: 18px;
}
.status {
left: 16px;
bottom: 68px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<header class="title">
<div class="eyebrow">Watch straps & everyday carry</div>
<h1>STRAP<br />PACK</h1>
<p class="subtitle">
A four-pocket travel organizer, with every object returning to its
designated place.
</p>
</header>
<div class="controls">
<button id="pause" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
</div>
<div class="status">
<span class="status-dot"></span>
<span id="status-text">Packing organizer</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e1d5);
scene.fog = new THREE.Fog(0xe9e1d5, 19, 35);
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.08;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff7eb, 0x7b8792, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff3df, 4.0);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xaec8d5, 1.8);
fillLight.position.set(8, 6, -8);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe7dfd2,
roughness: 0.95,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
tray: new THREE.MeshStandardMaterial({
color: 0xb88965,
roughness: 0.82
}),
trayEdge: new THREE.MeshStandardMaterial({
color: 0x77503c,
roughness: 0.9
}),
pocket: new THREE.MeshStandardMaterial({
color: 0x4b5559,
roughness: 0.9
}),
pocketInner: new THREE.MeshStandardMaterial({
color: 0x303a40,
roughness: 1
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf0dfc5,
roughness: 0.78
}),
steel: new THREE.MeshStandardMaterial({
color: 0xd8dde0,
roughness: 0.28,
metalness: 0.72
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x68747c,
roughness: 0.35,
metalness: 0.65
}),
watchFace: new THREE.MeshStandardMaterial({
color: 0x18232b,
roughness: 0.22,
metalness: 0.35
}),
watchMark: new THREE.MeshStandardMaterial({
color: 0xf5ead7,
roughness: 0.4
}),
leather: new THREE.MeshStandardMaterial({
color: 0x713d36,
roughness: 0.9
}),
leatherEdge: new THREE.MeshStandardMaterial({
color: 0x4f2927,
roughness: 0.95
}),
wallet: new THREE.MeshStandardMaterial({
color: 0xa65f39,
roughness: 0.84
}),
walletPanel: new THREE.MeshStandardMaterial({
color: 0xc57a4b,
roughness: 0.8
}),
stitch: new THREE.MeshStandardMaterial({
color: 0xe7bd7d,
roughness: 0.95
}),
case: new THREE.MeshStandardMaterial({
color: 0x326b73,
roughness: 0.72
}),
caseLid: new THREE.MeshStandardMaterial({
color: 0x3f8187,
roughness: 0.68
}),
caseSeam: new THREE.MeshStandardMaterial({
color: 0x1f4a50,
roughness: 0.8
}),
cable: new THREE.MeshStandardMaterial({
color: 0xe56f50,
roughness: 0.68
}),
connector: new THREE.MeshStandardMaterial({
color: 0xdce1e4,
roughness: 0.3,
metalness: 0.65
})
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function roundedShape(width, depth, radius) {
const w = width / 2;
const d = depth / 2;
const r = Math.min(radius, w - 0.001, d - 0.001);
const shape = new THREE.Shape();
shape.moveTo(-w + r, -d);
shape.lineTo(w - r, -d);
shape.quadraticCurveTo(w, -d, w, -d + r);
shape.lineTo(w, d - r);
shape.quadraticCurveTo(w, d, w - r, d);
shape.lineTo(-w + r, d);
shape.quadraticCurveTo(-w, d, -w, d - r);
shape.lineTo(-w, -d + r);
shape.quadraticCurveTo(-w, -d, -w + r, -d);
shape.closePath();
return shape;
}
function roundedHole(width, depth, radius) {
const w = width / 2;
const d = depth / 2;
const r = Math.min(radius, w - 0.001, d - 0.001);
const path = new THREE.Path();
path.moveTo(-w + r, -d);
path.quadraticCurveTo(-w, -d, -w, -d + r);
path.lineTo(-w, d - r);
path.quadraticCurveTo(-w, d, -w + r, d);
path.lineTo(w - r, d);
path.quadraticCurveTo(w, d, w, d - r);
path.lineTo(w, -d + r);
path.quadraticCurveTo(w, -d, w - r, -d);
path.lineTo(-w + r, -d);
path.closePath();
return path;
}
function roundedBox(width, height, depth, radius, material) {
const bevel = Math.min(0.035, height * 0.18);
const geometry = new THREE.ExtrudeGeometry(
roundedShape(width, depth, radius),
{
depth: height,
steps: 1,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: bevel,
bevelThickness: bevel,
curveSegments: 16
}
);
geometry.translate(0, 0, -height / 2);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function pocketFrame(width, depth, height, material) {
const shape = roundedShape(width, depth, 0.36);
shape.holes.push(
roundedHole(width - 0.34, depth - 0.34, 0.23)
);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: height,
steps: 1,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.025,
bevelThickness: 0.025,
curveSegments: 18
});
geometry.translate(0, 0, -height / 2);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinder(radius, height, material, radialSegments = 48) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, radialSegments),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function setShadow(group) {
group.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
return group;
}
// ------------------------------------------------------------
// Organizer tray and four labeled pockets
// ------------------------------------------------------------
const organizer = new THREE.Group();
scene.add(organizer);
const lowerBase = roundedBox(
9.35,
0.13,
6.55,
0.48,
materials.trayEdge
);
lowerBase.position.y = 0.055;
organizer.add(lowerBase);
const tray = roundedBox(9.2, 0.42, 6.4, 0.46, materials.tray);
tray.position.y = 0.26;
organizer.add(tray);
const pocketData = [
{ label: "WATCH", x: -2.05, z: -1.32 },
{ label: "WALLET", x: 2.05, z: -1.32 },
{ label: "CASE", x: -2.05, z: 1.32 },
{ label: "CABLE", x: 2.05, z: 1.32 }
];
function createLabel(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(32, 42, 47, 0.88)";
ctx.beginPath();
ctx.roundRect(4, 12, 504, 72, 36);
ctx.fill();
ctx.fillStyle = "#f5ead9";
ctx.font = "700 30px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.letterSpacing = "5px";
ctx.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(1.45, 0.28),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.renderOrder = 2;
return mesh;
}
for (const pocket of pocketData) {
const bottom = roundedBox(
3.55,
0.065,
2.15,
0.25,
materials.pocketInner
);
bottom.position.set(pocket.x, 0.495, pocket.z);
organizer.add(bottom);
const frame = pocketFrame(
3.85,
2.45,
0.23,
materials.cream
);
frame.position.set(pocket.x, 0.58, pocket.z);
organizer.add(frame);
const label = createLabel(pocket.label);
label.position.set(
pocket.x,
0.704,
pocket.z + 2.45 / 2 - 0.17
);
organizer.add(label);
}
// ------------------------------------------------------------
// Watch with upper and lower leather straps
// ------------------------------------------------------------
const watch = new THREE.Group();
const upperStrap = roundedBox(
0.56,
0.105,
0.92,
0.16,
materials.leather
);
upperStrap.position.set(0, 0.075, -0.62);
watch.add(upperStrap);
const lowerStrap = roundedBox(
0.56,
0.105,
0.92,
0.16,
materials.leather
);
lowerStrap.position.set(0, 0.075, 0.62);
watch.add(lowerStrap);
const strapEdgeUpper = roundedBox(
0.43,
0.016,
0.72,
0.12,
materials.leatherEdge
);
strapEdgeUpper.position.set(0, 0.132, -0.62);
watch.add(strapEdgeUpper);
const strapEdgeLower = roundedBox(
0.43,
0.016,
0.72,
0.12,
materials.leatherEdge
);
strapEdgeLower.position.set(0, 0.132, 0.62);
watch.add(strapEdgeLower);
for (const z of [0.72, 0.92]) {
const hole = cylinder(0.045, 0.018, materials.leatherEdge, 16);
hole.position.set(0, 0.14, z);
watch.add(hole);
}
const watchBody = cylinder(0.59, 0.19, materials.steel);
watchBody.position.y = 0.245;
watch.add(watchBody);
const watchFace = cylinder(0.49, 0.035, materials.watchFace);
watchFace.position.y = 0.357;
watch.add(watchFace);
const hourHand = roundedBox(
0.045,
0.025,
0.27,
0.015,
materials.watchMark
);
hourHand.position.set(0, 0.39, 0.095);
watch.add(hourHand);
const minuteHand = roundedBox(
0.04,
0.025,
0.34,
0.015,
materials.watchMark
);
minuteHand.position.set(0.09, 0.392, 0);
minuteHand.rotation.y = -0.42;
watch.add(minuteHand);
const crown = cylinder(0.12, 0.17, materials.steel, 24);
crown.rotation.z = Math.PI / 2;
crown.position.set(0.65, 0.245, 0);
watch.add(crown);
setShadow(watch);
// ------------------------------------------------------------
// Wallet
// ------------------------------------------------------------
const wallet = new THREE.Group();
const walletBody = roundedBox(
2.55,
0.32,
1.52,
0.2,
materials.wallet
);
walletBody.position.y = 0.16;
wallet.add(walletBody);
const walletPanel = roundedBox(
2.38,
0.045,
1.33,
0.16,
materials.walletPanel
);
walletPanel.position.y = 0.34;
wallet.add(walletPanel);
const walletSeam = roundedBox(
1.75,
0.018,
0.028,
0.012,
materials.stitch
);
walletSeam.position.set(0, 0.371, 0.47);
wallet.add(walletSeam);
const walletButton = cylinder(0.085, 0.035, materials.stitch, 24);
walletButton.position.set(0.78, 0.39, 0.12);
wallet.add(walletButton);
setShadow(wallet);
// ------------------------------------------------------------
// Glasses case
// ------------------------------------------------------------
const glassesCase = new THREE.Group();
const caseBase = roundedBox(
2.68,
0.25,
1.38,
0.36,
materials.case
);
caseBase.position.y = 0.125;
glassesCase.add(caseBase);
const caseLid = roundedBox(
2.68,
0.23,
1.38,
0.36,
materials.caseLid
);
caseLid.position.y = 0.36;
glassesCase.add(caseLid);
const caseSeam = roundedBox(
2.18,
0.018,
0.035,
0.014,
materials.caseSeam
);
caseSeam.position.set(0, 0.255, 0.48);
glassesCase.add(caseSeam);
const pullTab = new THREE.Mesh(
new THREE.TorusGeometry(0.11, 0.035, 10, 24),
materials.steel
);
pullTab.rotation.x = Math.PI / 2;
pullTab.position.set(1.12, 0.27, 0.48);
glassesCase.add(pullTab);
setShadow(glassesCase);
// ------------------------------------------------------------
// Coiled charging cable
// ------------------------------------------------------------
const cable = new THREE.Group();
const cablePoints = [];
for (let i = 0; i <= 38; i++) {
const progress = i / 38;
const angle = -0.35 + progress * Math.PI * 1.68;
const radius = 0.52 + progress * 0.13;
cablePoints.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0.11,
Math.sin(angle) * radius
)
);
}
const cableCurve = new THREE.CatmullRomCurve3(cablePoints);
const cableTube = new THREE.Mesh(
new THREE.TubeGeometry(cableCurve, 110, 0.055, 10, false),
materials.cable
);
cable.add(cableTube);
const startPlug = roundedBox(
0.31,
0.14,
0.16,
0.045,
materials.connector
);
startPlug.position.copy(cablePoints[0]);
startPlug.position.x -= 0.14;
cable.add(startPlug);
const startTip = roundedBox(
0.16,
0.09,
0.115,
0.035,
materials.darkSteel
);
startTip.position.copy(startPlug.position);
startTip.position.x -= 0.19;
cable.add(startTip);
const endPlug = roundedBox(
0.31,
0.14,
0.16,
0.045,
materials.connector
);
endPlug.position.copy(cablePoints[cablePoints.length - 1]);
endPlug.position.y += 0.01;
cable.add(endPlug);
const endTip = roundedBox(
0.16,
0.09,
0.115,
0.035,
materials.darkSteel
);
endTip.position.copy(endPlug.position);
endTip.position.z += 0.15;
cable.add(endTip);
setShadow(cable);
// ------------------------------------------------------------
// Animation targets
// ------------------------------------------------------------
const items = [
{
object: watch,
home: new THREE.Vector3(-2.05, 0.51, -1.32),
stage: new THREE.Vector3(-3.75, 3.0, -2.35),
homeRotation: new THREE.Euler(0, 0.1, 0),
stageRotation: new THREE.Euler(-0.08, -0.38, 0.08),
phase: 0.2
},
{
object: wallet,
home: new THREE.Vector3(2.05, 0.51, -1.32),
stage: new THREE.Vector3(3.7, 3.25, -2.3),
homeRotation: new THREE.Euler(0, -0.06, 0),
stageRotation: new THREE.Euler(0.1, 0.27, -0.12),
phase: 1.3
},
{
object: glassesCase,
home: new THREE.Vector3(-2.05, 0.51, 1.32),
stage: new THREE.Vector3(-3.72, 2.72, 2.3),
homeRotation: new THREE.Euler(0, 0.1, 0),
stageRotation: new THREE.Euler(0.06, -0.26, 0.08),
phase: 2.4
},
{
object: cable,
home: new THREE.Vector3(2.05, 0.51, 1.32),
stage: new THREE.Vector3(3.72, 2.62, 2.25),
homeRotation: new THREE.Euler(0, -0.2, 0),
stageRotation: new THREE.Euler(-0.08, 0.38, -0.1),
phase: 3.5
}
];
for (const item of items) {
item.object.position.copy(item.stage);
item.object.rotation.copy(item.stageRotation);
scene.add(item.object);
}
// ------------------------------------------------------------
// Custom camera controls: orbit, pan-free rotation, zoom
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.9, 0),
radius: 15.4,
theta: 0.72,
phi: 0.76,
minRadius: 10.5,
maxRadius: 22,
dragging: false,
pointerX: 0,
pointerY: 0
};
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();
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.34,
1.25
);
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
controls.dragging = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
controls.minRadius,
controls.maxRadius
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Packing / unpacking timeline
// ------------------------------------------------------------
const cycleDuration = 16;
let elapsed = 0;
let paused = false;
const pauseButton = document.getElementById("pause");
const restartButton = document.getElementById("restart");
const statusText = document.getElementById("status-text");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
restartButton.addEventListener("click", () => {
elapsed = 0;
});
function smootherStep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * x * (x * (x * 6 - 15) + 10);
}
function rangeProgress(time, start, end) {
return smootherStep((time - start) / (end - start));
}
function updateItem(item, time) {
const pack = rangeProgress(time, 0, 2.8);
const unpack = rangeProgress(time, 4.5, 7.5);
const returnProgress = rangeProgress(time, 9.5, 13);
let progress;
let from;
let to;
let fromRotation;
let toRotation;
if (time < 4.5) {
progress = pack;
from = item.stage;
to = item.home;
fromRotation = item.stageRotation;
toRotation = item.homeRotation;
} else if (time < 7.5) {
progress = unpack;
from = item.home;
to = item.stage;
fromRotation = item.homeRotation;
toRotation = item.stageRotation;
} else if (time < 9.5) {
progress = 1;
from = item.stage;
to = item.stage;
fromRotation = item.stageRotation;
toRotation = item.stageRotation;
} else {
progress = returnProgress;
from = item.stage;
to = item.home;
fromRotation = item.stageRotation;
toRotation = item.homeRotation;
}
const arc = Math.sin(progress * Math.PI) * 1.15;
item.object.position.lerpVectors(from, to, progress);
item.object.position.y += arc;
item.object.rotation.set(
THREE.MathUtils.lerp(fromRotation.x, toRotation.x, progress) +
Math.sin(progress * Math.PI) * 0.16,
THREE.MathUtils.lerp(fromRotation.y, toRotation.y, progress),
THREE.MathUtils.lerp(fromRotation.z, toRotation.z, progress)
);
const scale = 1 + Math.sin(progress * Math.PI) * 0.045;
item.object.scale.setScalar(scale);
// A subtle floating motion while the item is unpacked.
if (time >= 7.5 && time < 9.5) {
item.object.position.y +=
Math.sin(time * 2.1 + item.phase) * 0.07;
}
}
function updateStatus(time) {
if (time < 2.8) {
statusText.textContent = "Packing organizer";
} else if (time < 4.5) {
statusText.textContent = "All items packed";
} else if (time < 7.5) {
statusText.textContent = "Unpacking objects";
} else if (time < 9.5) {
statusText.textContent = "Objects on display";
} else if (time < 13) {
statusText.textContent = "Returning to pockets";
} else {
statusText.textContent = "All items packed";
}
}
// ------------------------------------------------------------
// Animation loop and resize
// ------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed = (elapsed + delta) % cycleDuration;
}
for (const item of items) {
updateItem(item, elapsed);
}
updateStatus(elapsed);
renderer.render(scene, camera);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```