Prompt specification
Build or customize the Three.js 3D scene "Mobile wardrobe packing game" 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: Mobile wardrobe packing game
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mobile-wardrobe-packing-game-x0032
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: mobile wardrobe packing game. Create a small moving-day scene with collapsible furniture and a cart; users fold the hamper and arrange items while preserving a clear exit doorway. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (mobile-wardrobe-packing-game-x0032):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Pack & Go — Moving Day</title>
<style>
:root {
--ink: #173d3a;
--muted: #607b76;
--paper: rgba(255, 255, 255, 0.9);
--coral: #f27c68;
--gold: #efb84e;
--mint: #69b9a7;
--purple: #9b83cf;
--shadow: 0 12px 32px rgba(26, 66, 61, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe9e5;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
position: fixed;
inset: 0;
isolation: isolate;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 5;
}
.brand {
position: absolute;
top: max(16px, env(safe-area-inset-top));
left: max(16px, env(safe-area-inset-left));
padding: 13px 16px 12px;
border: 1px solid rgba(255,255,255,.8);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.brand-row {
display: flex;
align-items: center;
gap: 10px;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border-radius: 11px;
background: var(--ink);
color: #fff;
font-size: 19px;
transform: rotate(-3deg);
}
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1;
letter-spacing: -.5px;
}
.brand p {
margin: 6px 0 0 44px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 1.2px;
text-transform: uppercase;
}
.stats {
position: absolute;
top: max(16px, env(safe-area-inset-top));
right: max(16px, env(safe-area-inset-right));
display: flex;
gap: 8px;
pointer-events: auto;
}
.stat {
min-width: 104px;
padding: 10px 12px;
border: 1px solid rgba(255,255,255,.8);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 8px 22px rgba(26,66,61,.1);
backdrop-filter: blur(12px);
}
.stat small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 1px;
text-transform: uppercase;
}
.stat strong {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
white-space: nowrap;
}
.stat strong::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 3px rgba(239,184,78,.18);
}
.stat.complete strong::before {
background: var(--mint);
box-shadow: 0 0 0 3px rgba(105,185,167,.18);
}
.stat.danger strong::before {
background: var(--coral);
box-shadow: 0 0 0 3px rgba(242,124,104,.18);
}
.controls {
position: absolute;
left: max(16px, env(safe-area-inset-left));
bottom: 126px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.action {
min-height: 44px;
padding: 0 15px;
border: 0;
border-radius: 13px;
background: var(--ink);
color: white;
font-size: 13px;
font-weight: 800;
cursor: pointer;
box-shadow: 0 8px 18px rgba(23,61,58,.22);
transition: transform .16s ease, background .16s ease;
}
.action:hover { transform: translateY(-2px); }
.action:active { transform: translateY(0) scale(.98); }
.action.secondary {
background: rgba(255,255,255,.92);
color: var(--ink);
border: 1px solid rgba(23,61,58,.1);
}
.instruction {
position: absolute;
right: max(16px, env(safe-area-inset-right));
bottom: 132px;
max-width: 295px;
padding: 10px 13px;
border-radius: 13px;
background: rgba(255,255,255,.78);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
box-shadow: 0 6px 20px rgba(26,66,61,.08);
backdrop-filter: blur(10px);
}
.instruction b { color: var(--ink); }
.inventory-wrap {
position: absolute;
left: 50%;
bottom: max(12px, env(safe-area-inset-bottom));
width: min(760px, calc(100% - 24px));
transform: translateX(-50%);
pointer-events: auto;
}
.inventory-title {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 4px 7px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 1.2px;
text-transform: uppercase;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.inventory {
display: flex;
gap: 8px;
overflow-x: auto;
padding: 9px;
border: 1px solid rgba(255,255,255,.85);
border-radius: 19px;
background: rgba(255,255,255,.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: none;
}
.inventory::-webkit-scrollbar { display: none; }
.item-card {
position: relative;
flex: 1 0 112px;
min-width: 112px;
min-height: 64px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
border: 2px solid transparent;
border-radius: 13px;
background: #f5f7f5;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.item-card:hover { transform: translateY(-2px); }
.item-card.selected {
border-color: var(--gold);
background: #fffaf0;
}
.item-card.packed {
opacity: .62;
cursor: default;
background: #e9f4ef;
}
.swatch {
flex: 0 0 auto;
width: 27px;
height: 34px;
border-radius: 9px 9px 12px 12px;
box-shadow: inset 0 -7px 0 rgba(0,0,0,.08);
}
.item-copy { min-width: 0; }
.item-copy strong {
display: block;
overflow: hidden;
font-size: 11px;
line-height: 1.15;
text-overflow: ellipsis;
white-space: nowrap;
}
.item-copy small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: .8px;
text-transform: uppercase;
}
.check {
position: absolute;
top: 6px;
right: 7px;
display: none;
color: #328d78;
font-size: 12px;
font-weight: 900;
}
.packed .check { display: block; }
#toast {
position: absolute;
top: 92px;
left: 50%;
max-width: min(440px, calc(100% - 28px));
padding: 10px 15px;
border-radius: 999px;
background: rgba(23,61,58,.94);
color: #fff;
font-size: 12px;
font-weight: 750;
text-align: center;
box-shadow: var(--shadow);
opacity: 0;
transform: translate(-50%, -8px);
transition: opacity .2s ease, transform .2s ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#success {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
padding: 20px;
background: rgba(20,55,52,.28);
opacity: 0;
visibility: hidden;
pointer-events: none;
transition: opacity .3s ease, visibility .3s;
backdrop-filter: blur(5px);
}
#success.show {
opacity: 1;
visibility: visible;
pointer-events: auto;
}
.success-card {
width: min(430px, 100%);
padding: 30px;
border: 1px solid rgba(255,255,255,.8);
border-radius: 28px;
background: rgba(255,255,255,.95);
box-shadow: 0 24px 70px rgba(17,55,51,.25);
text-align: center;
}
.success-icon {
width: 76px;
height: 76px;
display: grid;
place-items: center;
margin: 0 auto 15px;
border-radius: 24px;
background: var(--mint);
color: white;
font-size: 40px;
transform: rotate(-4deg);
}
.success-card h2 {
margin: 0;
font-size: 29px;
letter-spacing: -.8px;
}
.success-card p {
margin: 10px auto 20px;
max-width: 300px;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.success-card .action { min-width: 150px; }
.confetti {
position: absolute;
top: -20px;
width: 9px;
height: 15px;
border-radius: 2px;
pointer-events: none;
animation: fall 2.8s ease-in forwards;
}
@keyframes fall {
0% { transform: translate3d(0,-20px,0) rotate(0deg); opacity: 1; }
100% { transform: translate3d(var(--drift),105vh,0) rotate(720deg); opacity: .8; }
}
#loading {
position: absolute;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dbe9e5;
color: var(--ink);
font-weight: 850;
letter-spacing: 1px;
transition: opacity .3s ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.brand {
top: max(9px, env(safe-area-inset-top));
left: 10px;
padding: 9px 11px;
border-radius: 14px;
}
.brand-mark { width: 29px; height: 29px; font-size: 16px; }
.brand h1 { font-size: 15px; }
.brand p { display: none; }
.stats {
top: max(9px, env(safe-area-inset-top));
right: 10px;
gap: 5px;
}
.stat {
min-width: 0;
padding: 7px 8px;
border-radius: 11px;
}
.stat small { display: none; }
.stat strong { font-size: 10px; gap: 4px; }
.stat strong::before { width: 6px; height: 6px; }
.controls {
left: 10px;
bottom: 108px;
}
.action {
min-height: 40px;
padding: 0 12px;
border-radius: 11px;
font-size: 11px;
}
.instruction { display: none; }
.inventory-wrap {
bottom: max(7px, env(safe-area-inset-bottom));
width: calc(100% - 14px);
}
.inventory {
gap: 6px;
padding: 7px;
border-radius: 15px;
}
.item-card {
flex-basis: 108px;
min-width: 108px;
min-height: 59px;
padding: 7px;
}
.swatch { width: 24px; height: 30px; }
.item-copy strong { font-size: 10px; }
.item-copy small { font-size: 7px; }
.inventory-title { font-size: 8px; }
#toast { top: 64px; font-size: 11px; }
}
@media (max-height: 580px) and (orientation: landscape) {
.brand p, .instruction { display: none; }
.controls { bottom: 92px; }
.inventory-wrap { width: min(680px, calc(100% - 20px)); }
.inventory-title { display: none; }
.item-card { min-height: 50px; }
.stats { top: 8px; }
}
</style>
</head>
<body>
<main id="app">
<div id="loading">BUILDING YOUR MOVING DAY…</div>
<div class="hud">
<header class="brand">
<div class="brand-row">
<div class="brand-mark">↗</div>
<h1>Pack & Go</h1>
</div>
<p>A little moving-day puzzle</p>
</header>
<section class="stats" aria-label="Puzzle status">
<div class="stat" id="packStat">
<small>Packed</small>
<strong id="packStatus">0 / 5</strong>
</div>
<div class="stat" id="hamperStat">
<small>Hamper</small>
<strong id="hamperStatus">Open</strong>
</div>
<div class="stat" id="exitStat">
<small>Exit</small>
<strong id="exitStatus">Clear</strong>
</div>
</section>
<div class="controls">
<button class="action" id="foldButton" type="button">▱ Fold hamper</button>
<button class="action secondary" id="resetButton" type="button">Reset</button>
</div>
<div class="instruction">
<b>Drag</b> each item to its matching destination, or tap an item and then a destination.
Keep the amber exit lane empty.
</div>
<section class="inventory-wrap" aria-label="Items to pack">
<div class="inventory-title">
<span>Your moving-day items</span>
<span id="objective">Pack 5 items · Fold hamper · Keep exit clear</span>
</div>
<div class="inventory" id="inventory"></div>
</section>
<div id="toast" role="status" aria-live="polite"></div>
</div>
<section id="success" aria-hidden="true">
<div class="success-card">
<div class="success-icon">✓</div>
<h2>Ready to roll!</h2>
<p>Everything is packed, the hamper is folded, and your exit is clear. Great moving-day work!</p>
<button class="action" id="playAgain" type="button">Pack it again</button>
</div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const loading = document.getElementById("loading");
const inventoryEl = document.getElementById("inventory");
const foldButton = document.getElementById("foldButton");
const resetButton = document.getElementById("resetButton");
const playAgain = document.getElementById("playAgain");
const toastEl = document.getElementById("toast");
const successEl = document.getElementById("success");
const palette = {
ink: 0x173d3a,
cream: 0xf4ead7,
mintWall: 0xd9e7df,
floor: 0xd8b98f,
rug: 0xe9dfcc,
coral: 0xf27c68,
gold: 0xefb84e,
mint: 0x69b9a7,
teal: 0x3f8f86,
purple: 0x9b83cf,
navy: 0x315a79,
white: 0xfffdf7,
wood: 0xb98252,
woodLight: 0xd4a16c,
metal: 0x486563,
cardboard: 0xc9955f
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe9e5);
scene.fog = new THREE.Fog(0xdbe9e5, 22, 42);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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;
renderer.domElement.setAttribute("aria-label", "Interactive low-poly moving-day packing scene");
app.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
camera.position.set(12.5, 11.5, 14.5);
camera.lookAt(0, 1.05, -0.65);
const hemi = new THREE.HemisphereLight(0xf7fffb, 0x7f8b78, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.2);
sun.position.set(7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dfff, 1.1);
fill.position.set(-8, 6, -4);
scene.add(fill);
const material = (color, options = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
const mats = {
floor: material(palette.floor),
cream: material(palette.cream),
mintWall: material(palette.mintWall),
ink: material(palette.ink),
white: material(palette.white),
wood: material(palette.wood),
woodLight: material(palette.woodLight),
metal: material(palette.metal, { metalness: 0.38, roughness: 0.5 }),
cardboard: material(palette.cardboard),
tape: material(0xe7c98e),
coral: material(palette.coral),
gold: material(palette.gold),
teal: material(palette.teal),
purple: material(palette.purple),
navy: material(palette.navy),
mint: material(palette.mint),
plant: material(0x5a9b67),
plantLight: material(0x77b879),
pot: material(0xc87558)
};
function box(parent, w, h, d, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, rTop, rBottom, h, x, y, z, mat, segments = 8) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(rTop, rBottom, h, segments), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, width, depth, mat) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, direction.length(), depth), mat);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function labelSprite(text, width = 1.7, bg = "rgba(255,255,255,.92)", fg = "#173d3a") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = bg;
ctx.beginPath();
ctx.roundRect(8, 12, 496, 104, 26);
ctx.fill();
ctx.fillStyle = fg;
ctx.font = "800 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 30;
return sprite;
}
function register(group, data, list) {
group.traverse(object => {
Object.assign(object.userData, data);
list.push(object);
});
}
const pickables = [];
// Room
const room = new THREE.Group();
scene.add(room);
box(room, 12.8, 0.3, 9.8, 0, -0.18, 0, mats.floor, false);
const plankMat = material(0xc69f77);
for (let z = -4.35; z <= 4.4; z += 0.9) {
box(room, 12.5, 0.012, 0.025, 0, 0.005, z, plankMat, false);
}
box(room, 9.45, 4.15, 0.22, -1.37, 2.04, -4.72, mats.cream);
box(room, 0.85, 4.15, 0.22, 5.78, 2.04, -4.72, mats.cream);
box(room, 0.22, 4.15, 9.4, -6.18, 2.04, 0, mats.mintWall);
box(room, 9.4, 0.17, 0.27, -1.35, 0.09, -4.56, mats.woodLight);
box(room, 0.82, 0.17, 0.27, 5.77, 0.09, -4.56, mats.woodLight);
box(room, 0.27, 0.17, 9.35, -6.03, 0.09, 0, mats.woodLight);
// Open exit doorway
const doorway = new THREE.Group();
doorway.position.set(4.42, 0, -4.72);
scene.add(doorway);
box(doorway, 2.05, 3.95, 0.12, 0, 1.98, -0.15, material(0xb9d9d5), false);
box(doorway, 0.18, 4.16, 0.34, -1.08, 2.08, 0.03, mats.coral);
box(doorway, 0.18, 4.16, 0.34, 1.08, 2.08, 0.03, mats.coral);
box(doorway, 2.34, 0.18, 0.34, 0, 4.08, 0.03, mats.coral);
box(doorway, 2.05, 0.08, 0.48, 0, 0.035, 0.12, mats.woodLight);
const exitLabel = labelSprite("EXIT", 1.15, "rgba(242,124,104,.94)", "#ffffff");
exitLabel.position.set(4.42, 3.05, -4.38);
scene.add(exitLabel);
// Rug and exit lane
box(scene, 7.3, 0.025, 5.7, -0.1, 0.025, 0.75, material(palette.rug), false);
const laneMat = new THREE.MeshStandardMaterial({
color: palette.gold,
emissive: palette.gold,
emissiveIntensity: 0.22,
roughness: 0.8,
transparent: true,
opacity: 0.72
});
const lane = new THREE.Group();
for (let i = 0; i < 10; i++) {
box(lane, 0.65, 0.025, 0.24, 4.45, 0.045, 3.25 - i * 0.73, laneMat, false);
}
scene.add(lane);
// Wardrobe
const wardrobe = new THREE.Group();
wardrobe.position.set(-3.7, 0, -3.78);
scene.add(wardrobe);
box(wardrobe, 3.35, 3.75, 0.18, 0, 1.93, -0.56, mats.wood);
box(wardrobe, 0.18, 3.95, 1.22, -1.58, 1.98, 0, mats.woodLight);
box(wardrobe, 0.18, 3.95, 1.22, 1.58, 1.98, 0, mats.woodLight);
box(wardrobe, 3.35, 0.18, 1.22, 0, 3.88, 0, mats.woodLight);
box(wardrobe, 3.35, 0.18, 1.22, 0, 0.13, 0, mats.wood);
box(wardrobe, 3.05, 0.12, 1.08, 0, 1.25, 0, mats.woodLight);
box(wardrobe, 3.05, 0.12, 1.08, 0, 2.45, 0, mats.woodLight);
const rail = cylinder(wardrobe, 0.055, 0.055, 2.65, 0, 3.15, 0.03, mats.metal, 8);
rail.rotation.z = Math.PI / 2;
// Existing folded linens in the wardrobe
box(wardrobe, 0.85, 0.28, 0.7, -0.9, 0.43, 0, mats.mint);
box(wardrobe, 0.8, 0.25, 0.66, 0.85, 0.42, 0, mats.purple);
box(wardrobe, 0.72, 0.48, 0.22, -0.78, 1.83, 0.15, mats.coral);
box(wardrobe, 0.42, 0.62, 0.2, -1.16, 2.62, 0.13, mats.coral);
box(wardrobe, 0.42, 0.62, 0.2, -0.4, 2.62, 0.13, mats.coral);
const wardrobeLabel = labelSprite("WARDROBE", 1.85, "rgba(23,61,58,.93)", "#ffffff");
wardrobeLabel.position.set(0, 4.35, 0.1);
wardrobe.add(wardrobeLabel);
const wardrobeRing = new THREE.Mesh(
new THREE.RingGeometry(1.25, 1.48, 32),
new THREE.MeshBasicMaterial({
color: palette.gold,
transparent: true,
opacity: 0.35,
side: THREE.DoubleSide,
depthWrite: false
})
);
wardrobeRing.rotation.x = -Math.PI / 2;
wardrobeRing.position.set(-3.7, 0.055, -2.85);
scene.add(wardrobeRing);
const wardrobeZone = new THREE.Mesh(
new THREE.BoxGeometry(3.0, 2.5, 1.45),
new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })
);
wardrobeZone.position.set(-3.7, 1.25, -3.02);
scene.add(wardrobeZone);
// Folding table
const table = new THREE.Group();
table.position.set(-3.35, 0, 0.55);
scene.add(table);
box(table, 2.55, 0.15, 1.55, 0, 1.02, 0, mats.woodLight);
beamBetween(table, [-1.02, 0.08, -0.58], [1.02, 0.94, 0.52], 0.13, 0.13, mats.metal);
beamBetween(table, [1.02, 0.08, -0.58], [-1.02, 0.94, 0.52], 0.13, 0.13, mats.metal);
beamBetween(table, [-1.02, 0.08, 0.58], [1.02, 0.94, -0.52], 0.13, 0.13, mats.metal);
beamBetween(table, [1.02, 0.08, 0.58], [-1.02, 0.94, -0.52], 0.13, 0.13, mats.metal);
// Open, collapsible hamper
const hamper = new THREE.Group();
hamper.position.set(-0.65, 0, 0.2);
scene.add(hamper);
const hamperBody = new THREE.Group();
hamper.add(hamperBody);
box(hamperBody, 1.36, 0.13, 1.08, 0, 0.13, 0, mats.purple);
box(hamperBody, 1.26, 0.8, 0.11, 0, 0.58, -0.49, material(0xb4a1dc));
box(hamperBody, 1.26, 0.8, 0.11, 0, 0.58, 0.49, material(0xb4a1dc));
box(hamperBody, 0.11, 0.8, 0.98, -0.63, 0.58, 0, material(0xb4a1dc));
box(hamperBody, 0.11, 0.8, 0.98, 0.63, 0.58, 0, material(0xb4a1dc));
for (const x of [-0.61, 0.61]) {
for (const z of [-0.46, 0.46]) {
box(hamperBody, 0.12, 1.16, 0.12, x, 0.58, z, mats.ink);
}
}
box(hamperBody, 1.38, 0.11, 0.12, 0, 1.14, -0.48, mats.ink);
box(hamperBody, 1.38, 0.11, 0.12, 0, 1.14, 0.48, mats.ink);
box(hamperBody, 0.12, 0.11, 1.08, -0.64, 1.14, 0, mats.ink);
box(hamperBody, 0.12, 0.11, 1.08, 0.64, 1.14, 0, mats.ink);
const laundry = new THREE.Group();
box(laundry, 0.7, 0.3, 0.52, -0.18, 0.88, 0, mats.coral);
box(laundry, 0.62, 0.24, 0.46, 0.3, 0.83, 0.08, mats.mint);
hamperBody.add(laundry);
const hamperLabel = labelSprite("HAMPER", 1.38, "rgba(155,131,207,.94)", "#ffffff");
hamperLabel.position.set(0, 1.72, 0);
hamper.add(hamperLabel);
// Packing cart
const cart = new THREE.Group();
cart.position.set(2.75, 0, 2.45);
scene.add(cart);
box(cart, 2.0, 0.15, 1.25, 0, 0.43, 0, mats.teal);
box(cart, 0.12, 1.12, 0.12, -0.87, 0.96, -0.5, mats.metal);
box(cart, 0.12, 1.12, 0.12, 0.87, 0.96, -0.5, mats.metal);
box(cart, 0.12, 1.12, 0.12, -0.87, 0.96, 0.5, mats.metal);
box(cart, 0.12, 1.12, 0.12, 0.87, 0.96, 0.5, mats.metal);
box(cart, 1.86, 0.11, 0.11, 0, 1.48, -0.5, mats.ink);
box(cart, 1.86, 0.11, 0.11, 0, 1.48, 0.5, mats.ink);
for (const x of [-0.83, 0.83]) {
for (const z of [-0.48, 0.48]) {
const wheel = cylinder(cart, 0.19, 0.19, 0.13, x, 0.18, z, mats.ink, 10);
wheel.rotation.z = Math.PI / 2;
}
}
const cartLabel = labelSprite("PACK CART", 1.62, "rgba(63,143,134,.95)", "#ffffff");
cartLabel.position.set(0, 1.95, 0);
cart.add(cartLabel);
const cartRing = new THREE.Mesh(
new THREE.RingGeometry(1.13, 1.34, 32),
new THREE.MeshBasicMaterial({
color: palette.gold,
transparent: true,
opacity: 0.35,
side: THREE.DoubleSide,
depthWrite: false
})
);
cartRing.rotation.x = -Math.PI / 2;
cartRing.position.set(2.75, 0.055, 2.05);
scene.add(cartRing);
const cartZone = new THREE.Mesh(
new THREE.BoxGeometry(2.35, 2.0, 1.75),
new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })
);
cartZone.position.set(2.75, 1, 2.1);
scene.add(cartZone);
// Moving boxes and a low-poly plant
function movingBox(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, 0.95, 0.72, 0.9, 0, 0.36, 0, mats.cardboard);
box(group, 0.16, 0.735, 0.92, 0, 0.36, 0, mats.tape);
box(group, 0.18, 0.018, 0.34, 0, 0.735, 0, mats.tape);
return group;
}
movingBox(0.1, 0, -3.85, 1);
movingBox(0.2, 0.73, -3.85, 0.72);
const plant = new THREE.Group();
plant.position.set(-5.45, 0, -2.35);
scene.add(plant);
cylinder(plant, 0.42, 0.32, 0.62, 0, 0.31, 0, mats.pot, 7);
cylinder(plant, 0.05, 0.07, 1.35, 0, 1.15, 0, material(0x567657), 6);
const leafGeometry = new THREE.ConeGeometry(0.32, 0.9, 5);
for (let i = 0; i < 7; i++) {
const leaf = new THREE.Mesh(leafGeometry, i % 2 ? mats.plant : mats.plantLight);
const angle = (i / 7) * Math.PI * 2;
leaf.position.set(Math.cos(angle) * 0.27, 1.45 + (i % 3) * 0.24, Math.sin(angle) * 0.27);
leaf.rotation.z = Math.cos(angle) * 0.55;
leaf.rotation.x = Math.sin(angle) * 0.55;
leaf.castShadow = true;
plant.add(leaf);
}
// Moving-day poster
const posterCanvas = document.createElement("canvas");
posterCanvas.width = 512;
posterCanvas.height = 384;
const posterCtx = posterCanvas.getContext("2d");
posterCtx.fillStyle = "#f4ead7";
posterCtx.fillRect(0, 0, 512, 384);
posterCtx.fillStyle = "#173d3a";
posterCtx.fillRect(34, 34, 444, 316);
posterCtx.fillStyle = "#efb84e";
posterCtx.beginPath();
posterCtx.arc(256, 130, 55, 0, Math.PI * 2);
posterCtx.fill();
posterCtx.fillStyle = "#ffffff";
posterCtx.textAlign = "center";
posterCtx.font = "900 49px system-ui";
posterCtx.fillText("MOVE DAY", 256, 228);
posterCtx.font = "700 24px system-ui";
posterCtx.fillStyle = "#9b83cf";
posterCtx.fillText("PACK • FOLD • GO", 256, 286);
const posterTexture = new THREE.CanvasTexture(posterCanvas);
posterTexture.colorSpace = THREE.SRGBColorSpace;
const poster = new THREE.Mesh(
new THREE.PlaneGeometry(1.55, 1.16),
new THREE.MeshStandardMaterial({ map: posterTexture, roughness: 0.9 })
);
poster.position.set(-0.65, 2.55, -4.57);
scene.add(poster);
// Item factory
const items = [];
function makeItem(id, name, target, color, home, builder) {
const group = new THREE.Group();
group.position.set(...home);
scene.add(group);
builder(group, color);
const label = labelSprite(name.toUpperCase(), 1.28, "rgba(255,255,255,.9)", "#173d3a");
label.position.y = group.userData.labelHeight || 1.3;
group.add(label);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.57, 0.045, 6, 28),
new THREE.MeshBasicMaterial({ color: palette.gold, transparent: true, opacity: 0.95 })
);
halo.rotation.x = Math.PI / 2;
halo.position.y = 0.035;
halo.visible = false;
group.add(halo);
const item = {
id,
name,
target,
color,
group,
label,
halo,
home: new THREE.Vector3(...home),
packed: false,
packing: null
};
group.userData.labelHeight = group.userData.labelHeight || 1.3;
label.position.y = group.userData.labelHeight;
items.push(item);
return item;
}
function shirtBuilder(group) {
const mat = material(palette.coral);
box(group, 0.72, 0.78, 0.27, 0, 0.55, 0, mat);
const left = box(group, 0.32, 0.62, 0.25, -0.49, 0.69, 0, mat);
const right = box(group, 0.32, 0.62, 0.25, 0.49, 0.69, 0, mat);
left.rotation.z = 0.34;
right.rotation.z = -0.34;
box(group, 0.28, 0.12, 0.3, 0, 0.93, 0, material(0xd45f54));
group.userData.labelHeight = 1.38;
}
function coatBuilder(group) {
const mat = material(palette.gold);
box(group, 0.72, 1.05, 0.3, 0, 0.65, 0, mat);
const left = box(group, 0.34, 0.76, 0.28, -0.49, 0.81, 0, mat);
const right = box(group, 0.34, 0.76, 0.28, 0.49, 0.81, 0, mat);
left.rotation.z = 0.24;
right.rotation.z = -0.24;
box(group, 0.12, 0.82, 0.33, 0, 0.77, 0, material(0xd79d31));
group.userData.labelHeight = 1.68;
}
function shoesBuilder(group) {
const mat = material(palette.mint);
for (const x of [-0.23, 0.23]) {
box(group, 0.38, 0.22, 0.67, x, 0.17, 0, mat);
box(group, 0.34, 0.18, 0.3, x, 0.29, -0.15, material(0xf1fff9));
box(group, 0.39, 0.055, 0.68, x, 0.055, 0, mats.ink);
}
group.userData.labelHeight = 0.75;
}
function booksBuilder(group) {
box(group, 0.82, 0.16, 0.58, 0, 0.13, 0, mats.navy);
box(group, 0.73, 0.15, 0.52, 0.05, 0.28, 0.02, mats.coral);
box(group, 0.8, 0.14, 0.55, -0.02, 0.42, -0.02, mats.mint);
box(group, 0.18, 0.1, 0.6, -0.23, 0.54, -0.02, mats.gold);
group.userData.labelHeight = 0.95;
}
function lampBuilder(group) {
cylinder(group, 0.38, 0.42, 0.13, 0, 0.1, 0, mats.navy, 8);
cylinder(group, 0.055, 0.07, 0.94, 0, 0.62, 0, mats.metal, 8);
const shade = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.52, 0.58, 8, 1, true),
material(palette.gold, { side: THREE.DoubleSide })
);
shade.position.y = 1.25;
shade.castShadow = true;
group.add(shade);
cylinder(group, 0.48, 0.48, 0.045, 0, 1.55, 0, mats.gold, 8);
group.userData.labelHeight = 1.95;
}
makeItem("shirt", "Coral shirt", "wardrobe", "#f27c68", [-3.3, 1.12, 0.45], shirtBuilder);
makeItem("coat", "Sun coat", "wardrobe", "#efb84e", [-1.55, 0.04, 2.25], coatBuilder);
makeItem("shoes", "Sneakers", "wardrobe", "#69b9a7", [-4.55, 0.04, -1.55], shoesBuilder);
makeItem("books", "Books", "cart", "#315a79", [0.65, 0.04, 2.55], booksBuilder);
makeItem("lamp", "Table lamp", "cart", "#efb84e", [0.75, 0.04, -1.15], lampBuilder);
// Register interactive objects
items.forEach(item => register(item.group, { itemId: item.id }, pickables));
register(wardrobe, { target: "wardrobe" }, pickables);
register(cart, { target: "cart" }, pickables);
register(hamper, { action: "hamper" }, pickables);
register(wardrobeZone, { target: "wardrobe" }, pickables);
register(cartZone, { target: "cart" }, pickables);
// Inventory cards
const itemButtons = new Map();
items.forEach(item => {
const button = document.createElement("button");
button.className = "item-card";
button.type = "button";
button.innerHTML = `
<span class="swatch" style="background:${item.color}"></span>
<span class="item-copy">
<strong>${item.name}</strong>
<small>${item.target === "wardrobe" ? "Wardrobe" : "Pack cart"}</small>
</span>
<span class="check">✓</span>
`;
button.addEventListener("click", () => {
if (item.packed) {
showToast(`${item.name} is already packed.`);
return;
}
selectItem(item.id);
showToast(`${item.name} selected. Drag it to the ${item.target === "wardrobe" ? "wardrobe" : "pack cart"}.`);
});
inventoryEl.appendChild(button);
itemButtons.set(item.id, button);
});
let selectedId = null;
let hamperFolded = false;
let hamperScale = 1;
let won = false;
let exitBlocked = false;
let toastTimer;
function selectedItem() {
return items.find(item => item.id === selectedId) || null;
}
function selectItem(id) {
selectedId = id;
items.forEach(item => {
const selected = item.id === id && !item.packed;
item.halo.visible = selected;
itemButtons.get(item.id).classList.toggle("selected", selected);
});
}
function clearSelection() {
selectedId = null;
items.forEach(item => {
item.halo.visible = false;
itemButtons.get(item.id).classList.remove("selected");
});
}
function showToast(message) {
toastEl.textContent = message;
toastEl.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastEl.classList.remove("show"), 2200);
}
function toggleHamper() {
hamperFolded = !hamperFolded;
foldButton.textContent = hamperFolded ? "▱ Unfold hamper" : "▱ Fold hamper";
showToast(hamperFolded ? "Hamper folded — nice and flat!" : "Hamper unfolded.");
updateStatus();
}
foldButton.addEventListener("click", toggleHamper);
function targetPosition(target) {
return target === "wardrobe"
? new THREE.Vector3(-3.7, 1.55, -3.0)
: new THREE.Vector3(2.75, 0.8, 2.2);
}
function destinationFor(item) {
if (item.target === "wardrobe") {
const slots = {
shirt: new THREE.Vector3(-4.35, 2.0, -3.1),
coat: new THREE.Vector3(-3.65, 1.95, -3.05),
shoes: new THREE.Vector3(-2.9, 0.68, -3.05)
};
return slots[item.id];
}
return item.id === "books"
? new THREE.Vector3(2.35, 0.78, 2.2)
: new THREE.Vector3(3.15, 1.05, 2.2);
}
function packItem(item, target) {
if (item.packed) return;
if (item.target !== target) {
showToast(`${item.name} belongs in the ${item.target === "wardrobe" ? "wardrobe" : "pack cart"}.`);
return;
}
item.packed = true;
item.label.visible = false;
item.halo.visible = false;
item.packing = {
start: item.group.position.clone(),
end: destinationFor(item),
startTime: performance.now(),
duration: 520
};
itemButtons.get(item.id).classList.add("packed");
itemButtons.get(item.id).classList.remove("selected");
clearSelection();
showToast(`${item.name} packed in the ${target === "wardrobe" ? "wardrobe" : "cart"}.`);
updateStatus();
}
function resetGame() {
items.forEach(item => {
item.packed = false;
item.packing = null;
item.group.visible = true;
item.group.position.copy(item.home);
item.group.scale.setScalar(1);
item.label.visible = true;
item.halo.visible = false;
itemButtons.get(item.id).classList.remove("packed", "selected");
});
hamperFolded = false;
hamperScale = 1;
hamperBody.scale.y = 1;
foldButton.textContent = "▱ Fold hamper";
clearSelection();
won = false;
successEl.classList.remove("show");
successEl.setAttribute("aria-hidden", "true");
updateStatus();
showToast("Puzzle reset. Let’s pack this place up!");
}
resetButton.addEventListener("click", resetGame);
playAgain.addEventListener("click", resetGame);
function isExitBlocked() {
return items.some(item => {
if (item.packed) return false;
const p = item.group.position;
return Math.abs(p.x - 4.45) < 0.76 && p.z > -4.38 && p.z < 3.48;
});
}
function updateStatus() {
const packedCount = items.filter(item => item.packed).length;
exitBlocked = isExitBlocked();
document.getElementById("packStatus").textContent = `${packedCount} / ${items.length}`;
document.getElementById("hamperStatus").textContent = hamperFolded ? "Folded" : "Open";
document.getElementById("exitStatus").textContent = exitBlocked ? "Blocked" : "Clear";
document.getElementById("packStat").classList.toggle("complete", packedCount === items.length);
document.getElementById("hamperStat").classList.toggle("complete", hamperFolded);
document.getElementById("exitStat").classList.toggle("complete", !exitBlocked);
document.getElementById("exitStat").classList.toggle("danger", exitBlocked);
laneMat.color.setHex(exitBlocked ? palette.coral : palette.gold);
laneMat.emissive.setHex(exitBlocked ? palette.coral : palette.gold);
const objective = document.getElementById("objective");
if (exitBlocked) {
objective.textContent = "Move the item out of the amber exit lane";
} else if (packedCount < items.length) {
objective.textContent = hamperFolded ? "Pack the remaining items" : "Pack 5 items · Fold hamper";
} else if (!hamperFolded) {
objective.textContent = "Everything packed — now fold the hamper";
} else {
objective.textContent = "All done — the exit is clear!";
}
const done = packedCount === items.length && hamperFolded && !exitBlocked;
if (done && !won) {
won = true;
successEl.classList.add("show");
successEl.setAttribute("aria-hidden", "false");
spawnConfetti();
} else if (!done && won) {
won = false;
successEl.classList.remove("show");
successEl.setAttribute("aria-hidden", "true");
}
}
function spawnConfetti() {
const colors = ["#f27c68", "#efb84e", "#69b9a7", "#9b83cf", "#315a79"];
for (let i = 0; i < 36; i++) {
const bit = document.createElement("i");
bit.className = "confetti";
bit.style.left = `${Math.random() * 100}%`;
bit.style.background = colors[i % colors.length];
bit.style.setProperty("--drift", `${(Math.random() - 0.5) * 240}px`);
bit.style.animationDelay = `${Math.random() * 0.55}s`;
bit.style.animationDuration = `${2.3 + Math.random() * 1.2}s`;
successEl.appendChild(bit);
setTimeout(() => bit.remove(), 4200);
}
}
// Pointer interaction and direct dragging
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.08);
const floorPoint = new THREE.Vector3();
let drag = null;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pick(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (!hits.length) return null;
const itemHit = hits.find(hit => hit.object.userData.itemId);
if (itemHit) return itemHit;
return hits.find(hit =>
hit.object.userData.target ||
hit.object.userData.action === "hamper"
) || null;
}
function nearestMatchingTarget(position, target) {
const destinations = {
wardrobe: new THREE.Vector3(-3.7, 0, -3.0),
cart: new THREE.Vector3(2.75, 0, 2.05)
};
const dest = destinations[target];
const dx = position.x - dest.x;
const dz = position.z - dest.z;
return Math.hypot(dx, dz) < 1.48;
}
renderer.domElement.addEventListener("pointerdown", event => {
const hit = pick(event);
if (!hit) return;
const data = hit.object.userData;
if (data.itemId) {
const item = items.find(candidate => candidate.id === data.itemId);
if (!item || item.packed) return;
event.preventDefault();
renderer.domElement.setPointerCapture(event.pointerId);
selectItem(item.id);
raycaster.setFromCamera(pointer, camera);
const point = raycaster.ray.intersectPlane(dragPlane, floorPoint);
if (!point) return;
drag = {
item,
pointerId: event.pointerId,
startX: event.clientX,
startY: event.clientY,
moved: false,
offset: item.group.position.clone().sub(floorPoint)
};
} else if (data.target) {
event.preventDefault();
const item = selectedItem();
if (item) packItem(item, data.target);
else showToast("Select an item first, then tap a destination.");
} else if (data.action === "hamper") {
event.preventDefault();
toggleHamper();
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (drag && event.pointerId === drag.pointerId) {
const distance = Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY);
if (distance > 4) drag.moved = true;
if (!drag.moved) return;
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(dragPlane, floorPoint)) {
const p = floorPoint.clone().add(drag.offset);
p.x = THREE.MathUtils.clamp(p.x, -5.65, 5.65);
p.z = THREE.MathUtils.clamp(p.z, -4.25, 4.2);
drag.item.group.position.set(p.x, 0.28, p.z);
const nearWardrobe = nearestMatchingTarget(p, "wardrobe");
const nearCart = nearestMatchingTarget(p, "cart");
wardrobeRing.material.opacity = nearWardrobe ? 0.9 : 0.28;
cartRing.material.opacity = nearCart ? 0.9 : 0.28;
}
return;
}
const hit = pick(event);
renderer.domElement.style.cursor = hit ? "grab" : "default";
});
function endDrag(event, cancelled = false) {
if (!drag || event.pointerId !== drag.pointerId) return;
const activeDrag = drag;
drag = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
wardrobeRing.material.opacity = 0.35;
cartRing.material.opacity = 0.35;
if (cancelled || !activeDrag.moved) return;
const item = activeDrag.item;
const position = item.group.position;
const nearWardrobe = nearestMatchingTarget(position, "wardrobe");
const nearCart = nearestMatchingTarget(position, "cart");
if (nearWardrobe || nearCart) {
const target = nearWardrobe ? "wardrobe" : "cart";
if (target === item.target) {
packItem(item, target);
return;
}
}
item.group.position.y = 0.04;
if (isExitBlocked()) {
showToast("That blocks the exit. Move the item out of the amber lane.");
} else {
showToast(`${item.name} moved. Drop it on its matching destination to pack it.`);
}
updateStatus();
}
renderer.domElement.addEventListener("pointerup", event => endDrag(event));
renderer.domElement.addEventListener("pointercancel", event => endDrag(event, true));
// Responsive camera
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const vertical = Math.max(9.2, 12.8 / aspect);
camera.left = -vertical * aspect / 2;
camera.right = vertical * aspect / 2;
camera.top = vertical / 2;
camera.bottom = -vertical / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
}
window.addEventListener("resize", resize);
resize();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
const hamperTarget = hamperFolded ? 0.15 : 1;
hamperScale = THREE.MathUtils.lerp(hamperScale, hamperTarget, Math.min(1, dt * 10));
hamperBody.scale.y = hamperScale;
hamperLabel.position.y = 0.35 + hamperScale * 1.28;
const pulse = 1 + Math.sin(now * 0.003) * 0.045;
wardrobeRing.scale.setScalar(pulse);
cartRing.scale.setScalar(pulse);
for (const item of items) {
if (item.halo.visible) {
item.halo.rotation.z += dt * 0.8;
item.halo.material.opacity = 0.72 + Math.sin(now * 0.006) * 0.22;
}
if (item.packing) {
const t = Math.min(1, (now - item.packing.startTime) / item.packing.duration);
const ease = 1 - Math.pow(1 - t, 3);
item.group.position.lerpVectors(item.packing.start, item.packing.end, ease);
item.group.scale.setScalar(1 - ease * 0.72);
if (t >= 1) {
item.group.visible = false;
item.packing = null;
}
}
}
renderer.render(scene, camera);
}
updateStatus();
requestAnimationFrame(animate);
requestAnimationFrame(() => loading.classList.add("hide"));
</script>
</body>
</html>
```