Prompt specification
Build or customize the Three.js 3D scene "Multipurpose classroom reset" 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: Multipurpose classroom reset
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/multipurpose-classroom-reset-x0179
Scene Description Prompt:
Build a classroom changing from discussion circle to open floor activity; chairs move into compact stacks and a continuous movement area appears between storage and entrance. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (multipurpose-classroom-reset-x0179):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Classroom — Circle to Open Floor</title>
<style>
:root {
--ink: #173b37;
--muted: #657874;
--paper: #f4f1e8;
--teal: #29a98f;
--yellow: #f2bd45;
--coral: #e8795f;
--line: rgba(23, 59, 55, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e5da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.intro {
top: 30px;
left: 32px;
max-width: 490px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(244, 241, 232, 0.84);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--teal);
content: "";
box-shadow: 10px 0 0 var(--yellow);
margin-right: 10px;
}
h1 {
margin: 0;
font-size: clamp(30px, 4.4vw, 62px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.96;
}
.intro p {
max-width: 430px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.state-card {
top: 30px;
right: 30px;
display: flex;
align-items: center;
gap: 12px;
min-width: 224px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(244, 241, 232, 0.88);
box-shadow: 0 10px 35px rgba(48, 60, 52, 0.08);
backdrop-filter: blur(14px);
}
.state-dot {
position: relative;
width: 12px;
height: 12px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--yellow);
transition: background 250ms ease, transform 250ms ease;
}
body[data-mode="open"] .state-dot {
background: var(--teal);
transform: rotate(45deg);
}
.state-card small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
}
.state-card strong {
display: block;
font-size: 13px;
letter-spacing: -0.01em;
}
.controls {
bottom: 24px;
left: 50%;
display: flex;
align-items: center;
gap: 10px;
width: min(760px, calc(100vw - 32px));
padding: 10px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(244, 241, 232, 0.92);
box-shadow: 0 18px 50px rgba(48, 60, 52, 0.14);
backdrop-filter: blur(16px);
transform: translateX(-50%);
pointer-events: auto;
}
.phase-track {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
padding: 0 8px;
}
.phase {
display: flex;
align-items: center;
gap: 8px;
color: #8a9792;
white-space: nowrap;
transition: color 220ms ease;
}
.phase b {
display: grid;
width: 28px;
height: 28px;
place-items: center;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.55);
font-size: 9px;
transition: all 220ms ease;
}
.phase span {
font-size: 11px;
font-weight: 750;
}
.phase.active {
color: var(--ink);
}
.phase.active b {
border-color: var(--ink);
background: var(--ink);
color: var(--paper);
}
.phase-line {
width: 24px;
height: 1px;
margin: 0 8px;
background: var(--line);
}
button {
border: 0;
font: inherit;
cursor: pointer;
}
.primary {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
min-height: 46px;
padding: 0 17px;
border-radius: 10px;
background: var(--ink);
color: white;
font-size: 12px;
font-weight: 750;
white-space: nowrap;
transition: transform 160ms ease, background 160ms ease;
}
.primary:hover {
background: #21524c;
transform: translateY(-1px);
}
.primary:active {
transform: translateY(1px);
}
.primary .arrow {
font-size: 17px;
line-height: 1;
}
.icon-button {
display: grid;
width: 46px;
height: 46px;
flex: 0 0 auto;
place-items: center;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
font-size: 19px;
transition: background 160ms ease, transform 160ms ease;
}
.icon-button:hover {
background: white;
transform: translateY(-1px);
}
.camera-hint {
position: fixed;
right: 31px;
bottom: 102px;
z-index: 4;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(244, 241, 232, 0.72);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(10px);
}
.room-label {
position: fixed;
z-index: 4;
padding: 7px 9px;
border: 1px solid rgba(23, 59, 55, 0.16);
border-radius: 7px;
background: rgba(248, 246, 238, 0.88);
box-shadow: 0 5px 18px rgba(36, 53, 47, 0.08);
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(8px);
transition: opacity 200ms ease;
}
.room-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 8px;
height: 8px;
border-right: 1px solid rgba(23, 59, 55, 0.16);
border-bottom: 1px solid rgba(23, 59, 55, 0.16);
background: rgba(248, 246, 238, 0.88);
content: "";
transform: translateX(-50%) rotate(45deg);
}
#movement-label {
border-color: rgba(41, 169, 143, 0.45);
background: rgba(226, 248, 241, 0.92);
color: #176e60;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8e5da;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
.intro p {
display: none;
}
h1 {
max-width: 310px;
font-size: 36px;
}
.state-card {
top: 132px;
right: 18px;
min-width: 190px;
padding: 10px 12px;
}
.controls {
bottom: 14px;
width: calc(100vw - 24px);
flex-wrap: wrap;
}
.phase-track {
order: 2;
width: 100%;
flex-basis: 100%;
justify-content: center;
padding-top: 5px;
}
.phase-line {
width: 14px;
}
.primary {
flex: 1;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body data-mode="circle">
<div id="loading">Building voxel classroom…</div>
<header class="hud intro">
<div class="eyebrow">Spatial planning study</div>
<h1>From circle<br />to clear floor.</h1>
<p id="scene-description">
Twelve chairs begin in a discussion circle. Reconfigure the room to
reveal an open activity floor and a continuous route from storage to
the entrance.
</p>
</header>
<div class="hud state-card" aria-live="polite">
<div class="state-dot"></div>
<div>
<small>ROOM STATE</small>
<strong id="status-text">Discussion circle</strong>
</div>
</div>
<div class="room-label" id="storage-label">Storage</div>
<div class="room-label" id="entrance-label">Entrance</div>
<div class="room-label" id="circle-label">Discussion circle</div>
<div class="room-label" id="movement-label">Continuous movement area</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom · R to reset</div>
<nav class="controls" aria-label="Classroom configuration controls">
<div class="phase-track">
<div class="phase active" data-phase="0">
<b>01</b><span>Discuss</span>
</div>
<div class="phase-line"></div>
<div class="phase" data-phase="1">
<b>02</b><span>Clear</span>
</div>
<div class="phase-line"></div>
<div class="phase" data-phase="2">
<b>03</b><span>Move</span>
</div>
</div>
<button class="icon-button" id="reset-view" title="Reset camera" aria-label="Reset camera">
↺
</button>
<button class="primary" id="toggle-room">
<span>Reconfigure to open floor</span>
<span class="arrow">→</span>
</button>
</nav>
<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 body = document.body;
const loading = document.getElementById("loading");
const toggleButton = document.getElementById("toggle-room");
const resetButton = document.getElementById("reset-view");
const statusText = document.getElementById("status-text");
const sceneDescription = document.getElementById("scene-description");
const phaseElements = [...document.querySelectorAll(".phase")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e5da);
scene.fog = new THREE.Fog(0xe8e5da, 29, 52);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel classroom changing between a discussion circle and an open activity floor"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const clock = new THREE.Clock();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const ambient = new THREE.HemisphereLight(0xfffbef, 0x87968d, 2.25);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff0d3, 3.5);
sun.position.set(-8, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc6e8df, 1.15);
fill.position.set(9, 7, -8);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
const materials = {
ground: material(0xe8e5da, { roughness: 1 }),
base: material(0xcbbda3),
floorA: material(0xe8dfc9, { roughness: 0.96 }),
floorB: material(0xdfd3b8, { roughness: 0.96 }),
floorC: material(0xeee6d3, { roughness: 0.96 }),
wall: material(0xf1eee3),
wallAlt: material(0xe9e5d8),
trim: material(0x244b45),
wood: material(0xb98252),
woodLight: material(0xd1a26e),
storageBack: material(0x44665d),
storageFrame: material(0x36534c),
binTeal: material(0x4ba99a),
binYellow: material(0xe7b84d),
binCoral: material(0xd8755d),
binBlue: material(0x6d93a6),
board: material(0x28564d),
boardFrame: material(0xd6c6a3),
chalk: material(0xf6edcf),
door: material(0xe77d61),
doorEdge: material(0xb95743),
gold: material(0xf2c75a, { metalness: 0.16, roughness: 0.45 }),
chairTeal: material(0x3ca995),
chairYellow: material(0xe8b947),
chairCoral: material(0xdc745d),
chairFrame: material(0x31534d),
pathA: material(0x45bea4, {
emissive: 0x12695d,
emissiveIntensity: 0.22,
roughness: 0.72
}),
pathB: material(0xf0c75c, {
emissive: 0x725514,
emissiveIntensity: 0.12,
roughness: 0.78
})
};
function box(
width,
height,
depth,
mat,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Room shell and voxel floor
// -------------------------------------------------------------------------
box(60, 0.12, 60, materials.ground, 0, -0.42, 0, scene, false);
box(14.55, 0.28, 10.55, materials.base, 0, -0.23, 0, scene, false);
for (let x = 0; x < 14; x++) {
for (let z = 0; z < 10; z++) {
const floorMaterial =
(x + z) % 7 === 0
? materials.floorC
: (x + z) % 2 === 0
? materials.floorA
: materials.floorB;
box(
0.97,
0.14,
0.97,
floorMaterial,
-6.5 + x,
-0.07,
-4.5 + z,
scene,
false
);
}
}
// Back wall: staggered voxel blocks.
for (let row = 0; row < 5; row++) {
for (let x = 0; x < 14; x++) {
box(
0.98,
0.62,
0.32,
(x + row) % 5 === 0 ? materials.wallAlt : materials.wall,
-6.5 + x,
0.31 + row * 0.65,
-5.13
);
}
}
// Left wall.
for (let row = 0; row < 5; row++) {
for (let z = 0; z < 10; z++) {
box(
0.32,
0.62,
0.98,
(z + row) % 4 === 0 ? materials.wallAlt : materials.wall,
-7.13,
0.31 + row * 0.65,
-4.5 + z
);
}
}
// Low right-side wall leaves the entrance and camera view open.
for (let row = 0; row < 2; row++) {
for (let z = 0; z < 10; z++) {
if (z > 5 && z < 9) continue;
box(
0.32,
0.62,
0.98,
(z + row) % 3 === 0 ? materials.wallAlt : materials.wall,
7.13,
0.31 + row * 0.65,
-4.5 + z
);
}
}
// Wall trim.
box(14, 0.16, 0.18, materials.trim, 0, 0.08, -4.91);
box(0.18, 0.16, 10, materials.trim, -6.91, 0.08, 0);
// -------------------------------------------------------------------------
// Storage wall
// -------------------------------------------------------------------------
box(5.15, 0.14, 0.8, materials.storageFrame, -4, 0.1, -4.34);
box(5.15, 0.14, 0.8, materials.storageFrame, -4, 1.76, -4.34);
box(5.15, 0.12, 0.8, materials.storageFrame, -4, 0.94, -4.34);
box(5.15, 1.74, 0.12, materials.storageBack, -4, 0.94, -4.72);
[-6.5, -4.83, -3.16, -1.5].forEach((x) => {
box(0.13, 1.78, 0.8, materials.storageFrame, x, 0.94, -4.34);
});
const binMaterials = [
materials.binTeal,
materials.binYellow,
materials.binCoral,
materials.binBlue
];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
if (row === 1 && col === 1) continue;
const x = -5.665 + col * 1.665;
const y = row === 0 ? 0.51 : 1.34;
const mat = binMaterials[(row * 3 + col) % binMaterials.length];
box(0.94, 0.53, 0.49, mat, x, y, -4.27);
box(0.34, 0.08, 0.04, materials.boardFrame, x, y + 0.08, -4.01);
}
}
box(5.4, 0.16, 0.95, materials.woodLight, -4, 1.91, -4.31);
// -------------------------------------------------------------------------
// Classroom board and small voxel details
// -------------------------------------------------------------------------
box(4.85, 1.94, 0.16, materials.boardFrame, 0.72, 2.38, -4.86);
box(4.55, 1.64, 0.1, materials.board, 0.72, 2.38, -4.74);
// Pixel-style writing on the board.
const boardPixels = [
[-1.28, 2.63, 0.36, 0.12],
[-0.86, 2.46, 0.12, 0.42],
[-0.43, 2.59, 0.36, 0.12],
[-0.43, 2.37, 0.12, 0.28],
[0.1, 2.62, 0.12, 0.33],
[0.33, 2.46, 0.12, 0.33],
[0.56, 2.62, 0.12, 0.33],
[0.96, 2.65, 0.7, 0.12],
[0.96, 2.4, 0.12, 0.3],
[1.63, 2.58, 0.12, 0.42],
[1.86, 2.37, 0.12, 0.28]
];
boardPixels.forEach(([x, y, w, h]) => {
box(w, h, 0.035, materials.chalk, x, y, -4.665);
});
// A pixel clock.
box(0.74, 0.74, 0.12, materials.trim, 4.72, 2.58, -4.82);
box(0.54, 0.54, 0.08, materials.chalk, 4.72, 2.58, -4.72);
box(0.07, 0.21, 0.04, materials.trim, 4.72, 2.66, -4.65);
box(0.18, 0.07, 0.04, materials.trim, 4.79, 2.58, -4.65);
// -------------------------------------------------------------------------
// Entrance and open door
// -------------------------------------------------------------------------
box(0.34, 3.25, 0.2, materials.trim, 7.05, 1.62, 1.0);
box(0.34, 3.25, 0.2, materials.trim, 7.05, 1.62, 3.47);
box(0.34, 0.24, 2.68, materials.trim, 7.05, 3.18, 2.235);
box(0.64, 0.07, 2.44, materials.gold, 6.78, 0.035, 2.235, scene, false);
const doorPivot = new THREE.Group();
doorPivot.position.set(7.02, 0, 1.03);
doorPivot.rotation.y = -1.03;
scene.add(doorPivot);
box(0.14, 2.75, 2.1, materials.door, 0, 1.43, 1.05, doorPivot);
box(0.16, 0.22, 2.12, materials.doorEdge, 0, 0.59, 1.05, doorPivot);
box(0.16, 0.22, 2.12, materials.doorEdge, 0, 2.25, 1.05, doorPivot);
box(0.2, 0.1, 0.34, materials.gold, -0.12, 1.35, 1.72, doorPivot);
// -------------------------------------------------------------------------
// Discussion rug made from visible square voxels
// -------------------------------------------------------------------------
const rugGroup = new THREE.Group();
rugGroup.position.set(-0.75, 0, 0.45);
scene.add(rugGroup);
const rugMaterials = [
material(0xe7b947, {
transparent: true,
opacity: 0.9,
depthWrite: false,
roughness: 0.94
}),
material(0xf1cc6d, {
transparent: true,
opacity: 0.9,
depthWrite: false,
roughness: 0.94
})
];
for (let ix = -7; ix <= 7; ix++) {
for (let iz = -7; iz <= 7; iz++) {
const x = ix * 0.37;
const z = iz * 0.37;
if (x * x + z * z > 6.7) continue;
box(
0.345,
0.05,
0.345,
rugMaterials[(ix + iz + 20) % 2],
x,
0.027,
z,
rugGroup,
false
);
}
}
// -------------------------------------------------------------------------
// Voxel chairs
// -------------------------------------------------------------------------
const chairMaterials = [
materials.chairTeal,
materials.chairYellow,
materials.chairCoral
];
function createChair(index) {
const group = new THREE.Group();
const seatMaterial = chairMaterials[Math.floor(index / 4)];
// Seat, back, support rail, and four block legs.
box(0.7, 0.14, 0.7, seatMaterial, 0, 0.53, 0, group);
box(0.7, 0.61, 0.13, seatMaterial, 0, 0.88, -0.285, group);
box(0.58, 0.1, 0.12, materials.chairFrame, 0, 0.4, 0, group);
[-0.25, 0.25].forEach((x) => {
[-0.25, 0.25].forEach((z) => {
box(0.09, 0.48, 0.09, materials.chairFrame, x, 0.24, z, group);
});
});
group.scale.setScalar(0.96);
scene.add(group);
const angle = (index / 12) * Math.PI * 2 + Math.PI / 12;
const radius = 2.28;
const centerX = -0.75;
const centerZ = 0.45;
const circlePosition = new THREE.Vector3(
centerX + Math.cos(angle) * radius,
0,
centerZ + Math.sin(angle) * radius
);
const directionX = centerX - circlePosition.x;
const directionZ = centerZ - circlePosition.z;
const circleRotation = Math.atan2(directionX, directionZ);
const stack = Math.floor(index / 4);
const level = index % 4;
const stackPosition = new THREE.Vector3(
-6.23 + (level % 2) * 0.045,
level * 0.255,
-2.86 + stack * 1.07
);
const stackRotation = Math.PI / 2 + (level % 2 === 0 ? -0.07 : 0.07);
group.position.copy(circlePosition);
group.rotation.y = circleRotation;
return {
group,
circlePosition,
circleRotation,
stackPosition,
stackRotation,
active: false
};
}
const chairs = Array.from({ length: 12 }, (_, index) => createChair(index));
// Small pads underneath the future chair stacks.
const stackPads = [];
for (let stack = 0; stack < 3; stack++) {
const padMaterial = material(0xb7a77e, {
transparent: true,
opacity: 0,
depthWrite: false
});
const pad = box(
0.92,
0.055,
0.96,
padMaterial,
-6.21,
0.028,
-2.86 + stack * 1.07,
scene,
false
);
stackPads.push(pad);
}
// -------------------------------------------------------------------------
// Continuous movement area from storage to entrance
// -------------------------------------------------------------------------
const pathTiles = [];
const pathKeys = new Set();
function addPathTile(ix, iz, order) {
const key = `${ix},${iz}`;
if (pathKeys.has(key)) return;
pathKeys.add(key);
const mat = order % 3 === 0 ? materials.pathB : materials.pathA;
const tile = box(
0.525,
0.075,
0.525,
mat,
ix * 0.56,
0.043,
iz * 0.56,
scene,
false
);
tile.scale.y = 0.001;
pathTiles.push({
mesh: tile,
reveal: 0,
from: 0,
to: 0,
start: 0,
duration: 1,
delay: 0,
active: false
});
}
// Route: storage → across the back → toward the entrance → through the door.
let pathOrder = 0;
for (const iz of [-7, -6]) {
for (let ix = -7; ix <= 8; ix++) {
addPathTile(ix, iz, pathOrder++);
}
}
for (let iz = -6; iz <= 4; iz++) {
for (const ix of [8, 9]) {
addPathTile(ix, iz, pathOrder++);
}
}
for (let ix = 8; ix <= 12; ix++) {
for (const iz of [3, 4]) {
addPathTile(ix, iz, pathOrder++);
}
}
pathTiles.forEach((tile, index) => {
tile.delay = index / Math.max(1, pathTiles.length - 1);
});
// Pixel arrows reinforce the direction of travel.
const arrows = [];
function createArrow(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.095, z);
group.rotation.y = rotation;
const pixels = [
[0, 0.19],
[-0.09, 0.08],
[0.09, 0.08],
[-0.18, -0.03],
[0.18, -0.03],
[0, -0.23]
];
pixels.forEach(([px, pz]) => {
box(
0.085,
0.035,
0.085,
materials.chalk,
px,
0,
pz,
group,
false
);
});
group.scale.setScalar(0.001);
scene.add(group);
arrows.push(group);
}
createArrow(-2.15, -3.64, Math.PI / 2);
createArrow(1.65, -3.64, Math.PI / 2);
createArrow(4.76, -0.45, 0);
createArrow(5.95, 1.96, Math.PI / 2);
// -------------------------------------------------------------------------
// State changes and animation
// -------------------------------------------------------------------------
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let roomMode = "circle";
let rugAnimation = null;
let padAnimation = null;
const clamp01 = (value) => Math.min(1, Math.max(0, value));
const easeInOutCubic = (value) =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
const easeOutCubic = (value) => 1 - Math.pow(1 - value, 3);
function updateInterface() {
const isOpen = roomMode === "open";
body.dataset.mode = roomMode;
statusText.textContent = isOpen
? "Open floor activity"
: "Discussion circle";
sceneDescription.textContent = isOpen
? "Chairs are nested in three compact stacks, opening an uninterrupted route from storage to the entrance."
: "Twelve chairs begin in a discussion circle. Reconfigure the room to reveal an open activity floor and a continuous route from storage to the entrance.";
toggleButton.querySelector("span:first-child").textContent = isOpen
? "Return to discussion circle"
: "Reconfigure to open floor";
toggleButton.querySelector(".arrow").textContent = isOpen ? "←" : "→";
phaseElements.forEach((phase, index) => {
phase.classList.toggle("active", index === (isOpen ? 2 : 0));
});
}
function setRoomMode(nextMode) {
if (nextMode === roomMode) return;
const now = clock.getElapsedTime();
const speed = reducedMotion ? 0.28 : 1;
const targetIsOpen = nextMode === "open";
chairs.forEach((chair, index) => {
chair.fromPosition = chair.group.position.clone();
chair.fromRotation = chair.group.rotation.y;
chair.toPosition = (
targetIsOpen ? chair.stackPosition : chair.circlePosition
).clone();
chair.toRotation = targetIsOpen
? chair.stackRotation
: chair.circleRotation;
chair.start = now + index * 0.047 * speed;
chair.duration = 1.75 * speed;
chair.active = true;
});
rugAnimation = {
fromScale: rugGroup.scale.x,
toScale: targetIsOpen ? 0.025 : 1,
fromOpacity: rugMaterials[0].opacity,
toOpacity: targetIsOpen ? 0 : 0.9,
start: now,
duration: 1.18 * speed,
active: true
};
pathTiles.forEach((tile) => {
tile.from = tile.reveal;
tile.to = targetIsOpen ? 1 : 0;
tile.start = now + tile.delay * 0.78 * speed;
tile.duration = 0.72 * speed;
tile.active = true;
});
padAnimation = {
from: stackPads[0].material.opacity,
to: targetIsOpen ? 0.85 : 0,
start: now + 0.2 * speed,
duration: 0.7 * speed,
active: true
};
roomMode = nextMode;
updateInterface();
}
toggleButton.addEventListener("click", () => {
setRoomMode(roomMode === "circle" ? "open" : "circle");
});
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.68,
pitch: 0.73,
radius: 20,
target: new THREE.Vector3(0, 0.65, 0)
};
let userZoomed = false;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const sinPitch = Math.sin(cameraState.pitch);
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPitch * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.radius * cosPitch,
cameraState.target.z +
cameraState.radius * sinPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.yaw = 0.68;
cameraState.pitch = 0.73;
cameraState.radius = window.innerWidth / window.innerHeight < 0.8 ? 29 : 20;
cameraState.target.set(0, 0.65, 0);
userZoomed = false;
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.005,
0.36,
1.25
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
12,
34
);
userZoomed = true;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setRoomMode(roomMode === "circle" ? "open" : "circle");
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Projected room labels
// -------------------------------------------------------------------------
const labels = {
storage: {
element: document.getElementById("storage-label"),
position: new THREE.Vector3(-4.1, 2.38, -4.05)
},
entrance: {
element: document.getElementById("entrance-label"),
position: new THREE.Vector3(7.08, 3.55, 2.25)
},
circle: {
element: document.getElementById("circle-label"),
position: new THREE.Vector3(-0.75, 1.48, 0.45)
},
movement: {
element: document.getElementById("movement-label"),
position: new THREE.Vector3(2.9, 0.42, -3.25)
}
};
const projectedPosition = new THREE.Vector3();
function positionLabel(label, opacity) {
projectedPosition.copy(label.position).project(camera);
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1 &&
opacity > 0.01;
label.element.style.left = `${(projectedPosition.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projectedPosition.y * 0.5 + 0.5) * window.innerHeight}px`;
label.element.style.opacity = visible ? opacity : 0;
}
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
function animate() {
const now = clock.getElapsedTime();
// Chairs.
chairs.forEach((chair) => {
if (!chair.active) return;
const progress = clamp01((now - chair.start) / chair.duration);
if (progress >= 1) {
chair.group.position.copy(chair.toPosition);
chair.group.rotation.y = chair.toRotation;
chair.active = false;
return;
}
const eased = easeInOutCubic(progress);
chair.group.position.lerpVectors(
chair.fromPosition,
chair.toPosition,
eased
);
// Lift each chair into a visible travel arc.
chair.group.position.y += Math.sin(progress * Math.PI) * 1.08;
const angleDifference = Math.atan2(
Math.sin(chair.toRotation - chair.fromRotation),
Math.cos(chair.toRotation - chair.fromRotation)
);
chair.group.rotation.y =
chair.fromRotation + angleDifference * eased;
});
// Discussion rug.
if (rugAnimation?.active) {
const progress = clamp01(
(now - rugAnimation.start) / rugAnimation.duration
);
const eased = easeInOutCubic(progress);
const scale = THREE.MathUtils.lerp(
rugAnimation.fromScale,
rugAnimation.toScale,
eased
);
const opacity = THREE.MathUtils.lerp(
rugAnimation.fromOpacity,
rugAnimation.toOpacity,
eased
);
rugGroup.scale.setScalar(scale);
rugMaterials.forEach((mat) => {
mat.opacity = opacity;
});
if (progress >= 1) {
rugAnimation.active = false;
}
}
// Movement tiles reveal sequentially.
pathTiles.forEach((tile) => {
if (!tile.active) return;
const progress = clamp01((now - tile.start) / tile.duration);
const eased = easeOutCubic(progress);
tile.reveal = THREE.MathUtils.lerp(tile.from, tile.to, eased);
tile.mesh.scale.y = Math.max(0.001, tile.reveal);
if (progress >= 1) {
tile.active = false;
}
});
// Stack pads.
if (padAnimation?.active) {
const progress = clamp01(
(now - padAnimation.start) / padAnimation.duration
);
const opacity = THREE.MathUtils.lerp(
padAnimation.from,
padAnimation.to,
easeOutCubic(progress)
);
stackPads.forEach((pad) => {
pad.material.opacity = opacity;
});
if (progress >= 1) {
padAnimation.active = false;
}
}
// Directional arrows follow the revealed route.
const averageReveal =
pathTiles.reduce((sum, tile) => sum + tile.reveal, 0) /
pathTiles.length;
arrows.forEach((arrow, index) => {
const localReveal = clamp01(
averageReveal * 1.4 - index * 0.08
);
const scale = Math.max(0.001, easeOutCubic(localReveal));
arrow.scale.setScalar(scale);
});
positionLabel(labels.storage, 1);
positionLabel(labels.entrance, 1);
positionLabel(labels.circle, roomMode === "circle" ? 1 : 0);
positionLabel(labels.movement, roomMode === "open" ? 1 : 0);
renderer.render(scene, camera);
}
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
function onResize() {
const aspect = window.innerWidth / window.innerHeight;
camera.aspect = aspect;
camera.fov = aspect < 0.8 ? 50 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (!userZoomed) {
cameraState.radius = aspect < 0.8 ? 29 : aspect < 1.2 ? 23 : 20;
}
updateCamera();
}
window.addEventListener("resize", onResize);
onResize();
updateInterface();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```