Prompt specification
Build or customize the Three.js 3D scene "Small bedroom organization" 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: Small bedroom organization
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-bedroom-organization-x0031
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: small bedroom organization. Arrange a bed, wardrobe, hamper, and narrow walking route; allow the hamper to fold so the newly opened floor area becomes immediately visible. Return one self-contained HTML file.
Working Three.js Starter (small-bedroom-organization-x0031):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fold-Away Bedroom — Voxel Organizer</title>
<style>
:root {
--ink: #26322f;
--muted: #6e7772;
--paper: #f5f0e8;
--card: rgba(255, 253, 248, 0.86);
--line: rgba(38, 50, 47, 0.13);
--green: #4f9d78;
--amber: #d6914c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee7dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 30px;
max-width: 390px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 2px;
background: var(--amber);
content: "";
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 45px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.96;
}
.brand p {
max-width: 340px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.status-card {
position: absolute;
top: 28px;
right: 28px;
width: 252px;
padding: 17px 18px 16px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 18px;
background: var(--card);
box-shadow: 0 18px 48px rgba(53, 48, 38, 0.1);
backdrop-filter: blur(14px);
}
.status-heading {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-main {
display: flex;
align-items: center;
gap: 9px;
margin-top: 11px;
font-size: 13px;
font-weight: 780;
letter-spacing: -0.01em;
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 5px rgba(214, 145, 76, 0.13);
transition: 0.35s ease;
}
.status-card.clear .status-dot {
background: var(--green);
box-shadow: 0 0 0 5px rgba(79, 157, 120, 0.14);
}
.status-track {
height: 4px;
margin-top: 14px;
overflow: hidden;
border-radius: 99px;
background: rgba(38, 50, 47, 0.09);
}
.status-track span {
display: block;
width: 44%;
height: 100%;
border-radius: inherit;
background: var(--amber);
transition: width 0.65s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.35s ease;
}
.status-card.clear .status-track span {
width: 100%;
background: var(--green);
}
.status-detail {
display: block;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
}
.controls {
position: absolute;
right: 28px;
bottom: 26px;
display: flex;
align-items: flex-end;
gap: 10px;
pointer-events: auto;
}
.fold-button,
.reset-button {
border: 0;
color: var(--ink);
font: inherit;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.fold-button {
display: flex;
min-width: 226px;
align-items: center;
gap: 13px;
padding: 12px 17px 12px 12px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 18px;
background: rgba(255, 253, 248, 0.92);
box-shadow: 0 17px 45px rgba(53, 48, 38, 0.15);
text-align: left;
backdrop-filter: blur(14px);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.fold-button:hover {
transform: translateY(-2px);
box-shadow: 0 21px 52px rgba(53, 48, 38, 0.19);
}
.fold-button:active {
transform: translateY(0);
}
.fold-button:focus-visible,
.reset-button:focus-visible {
outline: 3px solid rgba(79, 157, 120, 0.4);
outline-offset: 3px;
}
.fold-icon {
display: grid;
width: 43px;
height: 43px;
flex: 0 0 auto;
place-items: center;
border-radius: 13px;
background: #e9e0d3;
transition: background 0.35s ease, transform 0.5s ease;
}
.fold-button[aria-pressed="true"] .fold-icon {
background: #d8ecdf;
transform: rotate(180deg);
}
.fold-icon svg {
width: 23px;
height: 23px;
}
.button-copy {
display: flex;
flex-direction: column;
gap: 3px;
}
.button-copy small {
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.button-copy strong {
font-size: 13px;
letter-spacing: -0.01em;
}
.reset-button {
display: grid;
width: 48px;
height: 48px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 16px;
background: rgba(255, 253, 248, 0.9);
box-shadow: 0 14px 35px rgba(53, 48, 38, 0.12);
backdrop-filter: blur(14px);
transition: transform 0.2s ease;
}
.reset-button:hover {
transform: translateY(-2px) rotate(-4deg);
}
.reset-button svg {
width: 19px;
height: 19px;
}
.instructions {
position: absolute;
bottom: 29px;
left: 30px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(38, 50, 47, 0.62);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
}
.mouse-icon {
position: relative;
width: 17px;
height: 24px;
border: 1.5px solid currentColor;
border-radius: 9px;
}
.mouse-icon::before {
position: absolute;
top: 4px;
left: 6px;
width: 2px;
height: 5px;
border-radius: 2px;
background: currentColor;
content: "";
}
.world-label {
position: absolute;
z-index: 4;
min-width: 148px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 12px;
background: rgba(255, 253, 248, 0.92);
box-shadow: 0 12px 28px rgba(53, 48, 38, 0.12);
pointer-events: none;
opacity: 0;
transform: translate(-50%, -115%);
transition: opacity 0.25s ease, background 0.35s ease;
}
.world-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 10px;
height: 10px;
background: inherit;
content: "";
transform: translateX(-50%) rotate(45deg);
}
.world-label.visible {
opacity: 1;
}
.world-label.clear {
background: rgba(235, 248, 238, 0.94);
}
.world-label span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.world-label strong {
font-size: 11px;
letter-spacing: -0.01em;
}
.toast {
position: absolute;
bottom: 98px;
left: 50%;
padding: 10px 15px;
border-radius: 999px;
background: rgba(38, 50, 47, 0.9);
color: white;
font-size: 11px;
font-weight: 700;
opacity: 0;
transform: translate(-50%, 8px);
transition: 0.3s ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eee7dc;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 20px;
left: 19px;
max-width: 235px;
}
.brand p {
display: none;
}
h1 {
font-size: 28px;
}
.status-card {
top: 18px;
right: 17px;
width: 174px;
padding: 13px;
border-radius: 15px;
}
.status-main {
font-size: 10px;
}
.status-detail {
font-size: 8px;
}
.controls {
right: 17px;
bottom: 18px;
}
.fold-button {
min-width: 194px;
padding: 9px 14px 9px 9px;
}
.fold-icon {
width: 39px;
height: 39px;
}
.instructions {
display: none;
}
.toast {
bottom: 84px;
max-width: 85vw;
white-space: nowrap;
}
}
@media (max-width: 470px) {
.brand {
max-width: 180px;
}
.eyebrow {
font-size: 7px;
}
h1 {
font-size: 23px;
}
.status-card {
top: 102px;
left: 18px;
right: auto;
width: 156px;
}
}
</style>
</head>
<body>
<div id="loading">Building the room…</div>
<div class="hud">
<header class="brand">
<div class="eyebrow">Voxel room study / 01</div>
<h1>Small space,<br />clearly sorted.</h1>
<p>
A compact bedroom organized around a 0.9 m walking route.
Fold the hamper and watch the floor return.
</p>
</header>
<aside id="statusCard" class="status-card" aria-live="polite">
<div class="status-heading">Walking route</div>
<div class="status-main">
<span class="status-dot"></span>
<span id="statusText">AISLE OBSTRUCTED</span>
</div>
<div class="status-track"><span id="statusFill"></span></div>
<small id="statusDetail" class="status-detail">0.9 m clear when folded</small>
</aside>
<div id="worldLabel" class="world-label">
<span id="worldLabelKicker">Hamper</span>
<strong id="worldLabelText">Pinches the walking route</strong>
</div>
<div id="toast" class="toast">Floor area released</div>
<div class="instructions">
<span class="mouse-icon"></span>
Drag to orbit · Scroll to zoom · Right-drag to pan
</div>
<div class="controls">
<button id="toggleButton" class="fold-button" type="button" aria-pressed="false">
<span class="fold-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M4 8.5 12 4l8 4.5v7L12 20l-8-4.5v-7Z" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
<path d="m4.4 8.7 7.6 4.4 7.6-4.4M12 13v6.7M8 6.2l8 4.5" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
</svg>
</span>
<span class="button-copy">
<small>One-tap change</small>
<strong id="toggleText">Fold hamper</strong>
</span>
</button>
<button id="resetButton" class="reset-button" type="button" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" fill="none">
<path d="M4.7 9A8 8 0 1 1 5 15.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<path d="M4.7 4.8V9h4.2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color("#eee7dc");
scene.fog = new THREE.Fog("#eee7dc", 28, 50);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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;
renderer.domElement.setAttribute("aria-label", "Interactive voxel bedroom");
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.25, -0.1);
let cameraAzimuth = 0.72;
let cameraPolar = 0.88;
let cameraRadius = 18;
let cameraZoom = 1;
const hemi = new THREE.HemisphereLight("#fff8eb", "#a99b87", 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff3d8", 3.15);
sun.position.set(-3, 11, 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 = 30;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#d9e8ff", 0.85);
fill.position.set(8, 6, -4);
scene.add(fill);
const materialCache = new Map();
function getMaterial(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function box(w, h, d, color, x = 0, y = 0, z = 0, parent = scene, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), getMaterial(color));
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(x = 0, y = 0, z = 0, parent = scene) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
function smoothstep(min, max, value) {
const t = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
// ---------------------------------------------------------------------
// Room shell: a warm voxel floor, two cutaway walls, and simple trim.
// ---------------------------------------------------------------------
box(11.35, 0.22, 9.35, "#bba98f", 0, -0.23, 0);
const plankColors = ["#d9c9ae", "#d5c4a8", "#ddcdb3", "#d2c0a4", "#d8c7ab"];
for (let i = 0; i < 22; i++) {
box(
0.495,
0.12,
9.0,
plankColors[i % plankColors.length],
-5.25 + i * 0.5,
-0.06,
0,
scene,
false
);
}
box(11.4, 4.7, 0.24, "#e8dfd1", 0, 2.35, -4.66);
box(0.24, 4.7, 9.3, "#e3d9ca", -5.66, 2.35, 0);
box(11.45, 0.12, 0.3, "#f3ebdf", 0, 4.72, -4.66);
box(0.3, 0.12, 9.32, "#f3ebdf", -5.66, 4.72, 0);
box(11.15, 0.18, 0.08, "#b69a78", 0, 0.09, -4.49);
box(0.08, 0.18, 9.0, "#b69a78", -5.49, 0.09, 0);
// Window on the left wall.
const windowGroup = group(-5.47, 2.82, -0.95);
box(0.05, 1.46, 1.94, "#a9d3dc", 0, 0, 0, windowGroup, false);
box(0.11, 1.7, 0.13, "#f8f1e6", 0.04, 0, -1.0, windowGroup);
box(0.11, 1.7, 0.13, "#f8f1e6", 0.04, 0, 1.0, windowGroup);
box(0.11, 0.13, 2.13, "#f8f1e6", 0.04, 0.85, 0, windowGroup);
box(0.11, 0.13, 2.13, "#f8f1e6", 0.04, -0.85, 0, windowGroup);
box(0.12, 1.58, 0.09, "#f8f1e6", 0.08, 0, 0, windowGroup);
box(0.12, 0.09, 1.98, "#f8f1e6", 0.08, 0, 0, windowGroup);
box(0.24, 0.12, 2.22, "#b49a78", 0.06, -0.88, 0, windowGroup);
// Voxel artwork and a narrow floating shelf.
box(1.58, 1.0, 0.09, "#a37c54", -3.08, 3.18, -4.48);
box(1.38, 0.8, 0.06, "#f6efe3", -3.08, 3.18, -4.42);
box(0.52, 0.52, 0.05, "#6f9d8b", -3.29, 3.13, -4.36);
box(0.32, 0.28, 0.05, "#d59059", -2.91, 3.29, -4.35);
box(1.48, 0.12, 0.48, "#b79268", -0.68, 2.65, -4.32);
box(0.16, 0.45, 0.18, "#658f82", -1.12, 2.92, -4.28);
box(0.14, 0.36, 0.17, "#d5955b", -0.89, 2.88, -4.27);
box(0.13, 0.51, 0.17, "#d9cbb3", -0.68, 2.95, -4.27);
// ---------------------------------------------------------------------
// The narrow walking route.
// ---------------------------------------------------------------------
const routeFillMaterial = new THREE.MeshStandardMaterial({
color: "#d9cdb8",
transparent: true,
opacity: 0.43,
roughness: 1,
depthWrite: false
});
const routeFill = box(1.02, 0.025, 5.85, routeFillMaterial, -0.26, 0.022, 0.66, scene, false);
routeFill.renderOrder = 1;
const routeDashMaterial = new THREE.MeshStandardMaterial({
color: "#a99a83",
transparent: true,
opacity: 0.72,
roughness: 1,
depthWrite: false
});
for (const x of [-0.82, 0.3]) {
for (let z = -2.1; z < 3.75; z += 0.53) {
box(0.075, 0.027, 0.26, routeDashMaterial, x, 0.049, z, scene, false);
}
}
const arrowMaterial = new THREE.MeshStandardMaterial({
color: "#a99a83",
transparent: true,
opacity: 0.8,
roughness: 1,
depthWrite: false
});
box(0.08, 0.028, 0.42, arrowMaterial, -0.26, 0.051, 3.18, scene, false);
const arrowLeft = box(0.065, 0.028, 0.32, arrowMaterial, -0.37, 0.052, 2.91, scene, false);
const arrowRight = box(0.065, 0.028, 0.32, arrowMaterial, -0.15, 0.052, 2.91, scene, false);
arrowLeft.rotation.y = -Math.PI / 4;
arrowRight.rotation.y = Math.PI / 4;
// Mint patch marking the floor area released by the hamper.
const releasedGroup = group(-0.26, 0, 0.35);
const patchMaterial = new THREE.MeshStandardMaterial({
color: "#78c49b",
transparent: true,
opacity: 0,
roughness: 1,
depthWrite: false
});
const outlineMaterial = new THREE.MeshStandardMaterial({
color: "#4e9b76",
transparent: true,
opacity: 0,
roughness: 1,
depthWrite: false
});
box(1.46, 0.028, 1.42, patchMaterial, 0, 0.062, 0, releasedGroup, false);
box(1.46, 0.035, 0.055, outlineMaterial, 0, 0.075, -0.71, releasedGroup, false);
box(1.46, 0.035, 0.055, outlineMaterial, 0, 0.075, 0.71, releasedGroup, false);
box(0.055, 0.035, 1.42, outlineMaterial, -0.73, 0.075, 0, releasedGroup, false);
box(0.055, 0.035, 1.42, outlineMaterial, 0.73, 0.075, 0, releasedGroup, false);
// ---------------------------------------------------------------------
// Bed: raised platform leaves enough clearance for the folded hamper.
// ---------------------------------------------------------------------
const bedGroup = group(-3.2, 0, -0.9);
for (const x of [-1.58, 1.58]) {
for (const z of [-2.35, 2.28]) {
box(0.24, 0.58, 0.24, "#8d6847", x, 0.29, z, bedGroup);
}
}
box(3.55, 0.22, 0.18, "#8d6847", 0, 0.48, -2.42, bedGroup);
box(3.55, 0.22, 0.18, "#8d6847", 0, 0.48, 2.42, bedGroup);
box(0.18, 0.22, 4.95, "#8d6847", -1.68, 0.48, 0, bedGroup);
box(0.18, 0.22, 4.95, "#8d6847", 1.68, 0.48, 0, bedGroup);
for (let z = -2.1; z <= 2.1; z += 0.52) {
box(3.25, 0.11, 0.16, "#a27c54", 0, 0.43, z, bedGroup);
}
box(3.38, 0.44, 4.9, "#f1ece2", 0, 0.79, 0, bedGroup);
box(3.4, 0.18, 2.75, "#709b91", 0, 1.06, 1.05, bedGroup);
box(3.43, 0.1, 0.58, "#d59159", 0, 1.17, -0.26, bedGroup);
box(3.42, 0.1, 0.18, "#537c75", 0, 1.19, 0.1, bedGroup);
box(1.42, 0.28, 0.78, "#faf5ec", -0.72, 1.12, -1.78, bedGroup);
box(1.42, 0.28, 0.78, "#faf5ec", 0.72, 1.12, -1.78, bedGroup);
box(2.72, 0.13, 0.62, "#eee4d4", 0, 1.04, -1.73, bedGroup);
box(3.65, 1.75, 0.18, "#9b744e", 0, 1.0, -2.56, bedGroup);
box(3.85, 0.16, 0.25, "#b28b60", 0, 1.94, -2.56, bedGroup);
box(0.18, 1.94, 0.22, "#b28b60", -1.74, 1.02, -2.56, bedGroup);
box(0.18, 1.94, 0.22, "#b28b60", 1.74, 1.02, -2.56, bedGroup);
// A tiny bedside book stack on the headboard.
box(0.66, 0.09, 0.48, "#d88e57", -1.4, 2.08, -2.5, bedGroup);
box(0.56, 0.07, 0.43, "#527a73", -1.42, 2.16, -2.5, bedGroup);
// ---------------------------------------------------------------------
// Wardrobe at the back of the room.
// ---------------------------------------------------------------------
const wardrobeGroup = group(2.25, 0, -3.57);
box(4.35, 0.18, 1.55, "#9b7651", 0, 0.1, 0, wardrobeGroup);
box(4.22, 3.7, 1.52, "#cbb18d", 0, 1.98, 0, wardrobeGroup);
box(4.43, 0.18, 1.68, "#ad865d", 0, 3.89, 0, wardrobeGroup);
for (const x of [-1.39, 0, 1.39]) {
box(1.28, 3.34, 0.12, "#e7dac4", x, 1.96, 0.79, wardrobeGroup);
box(0.055, 0.52, 0.09, "#6d6252", x + 0.43, 1.82, 0.89, wardrobeGroup);
}
box(4.02, 0.09, 0.08, "#b18a61", 0, 0.29, 0.87, wardrobeGroup);
box(4.02, 0.09, 0.08, "#b18a61", 0, 3.61, 0.87, wardrobeGroup);
// Voxel plant and a small case on top.
box(0.38, 0.34, 0.38, "#c87851", -1.47, 4.14, 0, wardrobeGroup);
box(0.16, 0.45, 0.17, "#4f7e62", -1.58, 4.45, 0, wardrobeGroup);
box(0.17, 0.36, 0.16, "#679573", -1.33, 4.39, 0.02, wardrobeGroup);
box(0.16, 0.31, 0.16, "#3f6f57", -1.46, 4.6, 0, wardrobeGroup);
box(0.88, 0.34, 0.55, "#607a79", 1.35, 4.15, 0, wardrobeGroup);
box(0.58, 0.08, 0.08, "#91aaa6", 1.35, 4.18, 0.31, wardrobeGroup);
// ---------------------------------------------------------------------
// Collapsible slatted hamper.
// ---------------------------------------------------------------------
const hamperStart = new THREE.Vector3(-0.26, 0, 0.35);
const hamperTarget = new THREE.Vector3(-2.78, 0, -0.35);
const hamper = group(hamperStart.x, hamperStart.y, hamperStart.z);
const hamperWidth = 1.3;
const hamperDepth = 1.16;
const hamperHeight = 1.46;
const rattan = "#bd8f58";
const rattanLight = "#d5aa72";
box(hamperWidth, 0.14, hamperDepth, "#a87949", 0, 0.13, 0, hamper);
box(hamperWidth - 0.14, 0.09, hamperDepth - 0.14, "#c99a63", 0, 0.22, 0, hamper);
function makeFrontPanel() {
const panel = new THREE.Group();
box(hamperWidth, 0.1, 0.11, rattan, 0, 0.05, 0, panel);
box(hamperWidth, 0.12, 0.13, rattanLight, 0, hamperHeight - 0.06, 0, panel);
for (let i = 0; i < 9; i++) {
const x = -0.58 + i * (1.16 / 8);
box(0.065, hamperHeight - 0.17, 0.075, rattan, x, hamperHeight / 2, 0, panel);
}
return panel;
}
function makeSidePanel() {
const panel = new THREE.Group();
box(0.11, 0.1, hamperDepth, rattan, 0, 0.05, 0, panel);
box(0.13, 0.12, hamperDepth, rattanLight, 0, hamperHeight - 0.06, 0, panel);
for (let i = 0; i < 7; i++) {
const z = -0.5 + i * (1.0 / 6);
box(0.075, hamperHeight - 0.17, 0.065, rattan, 0, hamperHeight / 2, z, panel);
}
return panel;
}
const frontPanel = makeFrontPanel();
frontPanel.position.set(0, 0.2, hamperDepth / 2);
hamper.add(frontPanel);
const backPanel = makeFrontPanel();
backPanel.position.set(0, 0.2, -hamperDepth / 2);
hamper.add(backPanel);
const leftPanel = makeSidePanel();
leftPanel.position.set(-hamperWidth / 2, 0.2, 0);
hamper.add(leftPanel);
const rightPanel = makeSidePanel();
rightPanel.position.set(hamperWidth / 2, 0.2, 0);
hamper.add(rightPanel);
const clothes = group(0, 0, 0, hamper);
box(0.62, 0.22, 0.48, "#6f9b91", -0.22, 0.48, 0.05, clothes);
box(0.52, 0.19, 0.45, "#d58b58", 0.26, 0.47, -0.12, clothes);
box(0.55, 0.17, 0.43, "#d9cfb9", -0.04, 0.65, 0.1, clothes);
// Small folded handle on the front rim.
box(0.48, 0.11, 0.09, "#8d633d", 0, 1.53, hamperDepth / 2 + 0.04, hamper);
// ---------------------------------------------------------------------
// Interaction and animation.
// ---------------------------------------------------------------------
const toggleButton = document.getElementById("toggleButton");
const toggleText = document.getElementById("toggleText");
const statusCard = document.getElementById("statusCard");
const statusText = document.getElementById("statusText");
const statusDetail = document.getElementById("statusDetail");
const statusFill = document.getElementById("statusFill");
const worldLabel = document.getElementById("worldLabel");
const worldLabelKicker = document.getElementById("worldLabelKicker");
const worldLabelText = document.getElementById("worldLabelText");
const toast = document.getElementById("toast");
let foldTarget = 0;
let foldProgress = 0;
let toastTimer;
function setFoldState(isFolded) {
foldTarget = isFolded ? 1 : 0;
toggleButton.setAttribute("aria-pressed", String(isFolded));
toggleText.textContent = isFolded ? "Unfold hamper" : "Fold hamper";
statusText.textContent = isFolded ? "AISLE RESTORED" : "AISLE OBSTRUCTED";
statusDetail.textContent = isFolded ? "0.9 m route fully clear" : "0.9 m clear when folded";
statusCard.classList.toggle("clear", isFolded);
worldLabelKicker.textContent = isFolded ? "Floor released" : "Hamper";
worldLabelText.textContent = isFolded ? "1.6 m² clear again" : "Pinches the walking route";
worldLabel.classList.toggle("clear", isFolded);
toast.textContent = isFolded ? "Hamper folded and tucked away" : "Hamper returned to the aisle";
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2300);
}
toggleButton.addEventListener("click", () => {
setFoldState(foldTarget < 0.5);
});
// ---------------------------------------------------------------------
// Camera controls implemented directly, without external add-ons.
// ---------------------------------------------------------------------
const canvas = renderer.domElement;
const activePointers = new Map();
let dragMode = null;
let previousX = 0;
let previousY = 0;
let pinchDistance = 0;
function updateCamera() {
camera.position.setFromSpherical(
new THREE.Spherical(cameraRadius, cameraPolar, cameraAzimuth)
).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraAzimuth = 0.72;
cameraPolar = 0.88;
cameraRadius = 18;
cameraZoom = 1;
cameraTarget.set(0, 1.25, -0.1);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.setPointerCapture(event.pointerId);
previousX = event.clientX;
previousY = event.clientY;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
dragMode = "pinch";
}
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (pinchDistance > 0) {
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (distance / pinchDistance),
0.65,
1.75
);
camera.updateProjectionMatrix();
}
pinchDistance = distance;
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragMode === "orbit") {
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(cameraPolar + dy * 0.005, 0.55, 1.18);
updateCamera();
} else if (dragMode === "pan") {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const groundUp = new THREE.Vector3(up.x, 0, up.z).normalize();
const worldPerPixel =
(camera.top - camera.bottom) / camera.zoom / canvas.clientHeight;
cameraTarget.addScaledVector(right, -dx * worldPerPixel);
cameraTarget.addScaledVector(groundUp, dy * worldPerPixel);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -5, 5);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -5, 5);
updateCamera();
}
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 0) {
dragMode = null;
pinchDistance = 0;
} else if (activePointers.size === 1) {
dragMode = "orbit";
const point = [...activePointers.values()][0];
previousX = point.x;
previousY = point.y;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.75
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("resetButton").addEventListener("click", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(12.5, 15.2 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// ---------------------------------------------------------------------
// Render loop.
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const labelAnchor = new THREE.Vector3();
const projected = new THREE.Vector3();
const routeBaseColor = new THREE.Color("#d9cdb8");
const routeClearColor = new THREE.Color("#b9dec4");
const routeDashBaseColor = new THREE.Color("#a99a83");
const routeDashClearColor = new THREE.Color("#4f9d78");
const arrowBaseColor = new THREE.Color("#a99a83");
const arrowClearColor = new THREE.Color("#4f9d78");
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-dt * 5.8);
foldProgress += (foldTarget - foldProgress) * easing;
if (Math.abs(foldTarget - foldProgress) < 0.0005) {
foldProgress = foldTarget;
}
const panelFold = smoothstep(0.0, 0.56, foldProgress);
const compaction = smoothstep(0.0, 0.72, foldProgress);
const slide = smoothstep(0.42, 1.0, foldProgress);
const clearAmount = smoothstep(0.56, 0.94, foldProgress);
frontPanel.rotation.x = -Math.PI * 0.5 * panelFold;
backPanel.rotation.x = Math.PI * 0.5 * panelFold;
leftPanel.rotation.z = -Math.PI * 0.5 * panelFold;
rightPanel.rotation.z = Math.PI * 0.5 * panelFold;
const clothesScale = Math.max(0.001, 1 - smoothstep(0.0, 0.47, foldProgress));
clothes.scale.setScalar(clothesScale);
hamper.position.x = lerp(hamperStart.x, hamperTarget.x, slide);
hamper.position.z = lerp(hamperStart.z, hamperTarget.z, slide);
hamper.scale.set(
1 - 0.16 * compaction,
1 - 0.78 * compaction,
1 - 0.16 * compaction
);
patchMaterial.opacity = 0.7 * clearAmount;
outlineMaterial.opacity = 0.95 * clearAmount;
routeFillMaterial.color.lerpColors(routeBaseColor, routeClearColor, clearAmount);
routeDashMaterial.color.lerpColors(routeDashBaseColor, routeDashClearColor, clearAmount);
arrowMaterial.color.lerpColors(arrowBaseColor, arrowClearColor, clearAmount);
// Move the annotation from the hamper to the released floor patch.
labelAnchor.set(
hamper.position.x,
hamper.position.y + 1.95 * (1 - compaction),
hamper.position.z
);
labelAnchor.lerp(
new THREE.Vector3(releasedGroup.position.x, 0.36, releasedGroup.position.z),
smoothstep(0.5, 0.86, foldProgress)
);
projected.copy(labelAnchor).project(camera);
const labelX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const labelY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
worldLabel.style.left = `${labelX}px`;
worldLabel.style.top = `${labelY}px`;
worldLabel.classList.toggle(
"visible",
projected.z > -1 && projected.z < 1 && labelX > 65 && labelX < window.innerWidth - 65
);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```