Prompt specification
Build or customize the Three.js 3D scene "Community hall capacity planner" 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: Community hall capacity planner
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-hall-capacity-planner-x0180
Scene Description Prompt:
Rearrange low-poly chairs and tables between meeting and workshop layouts in a community hall while preserving connected circulation. Three.js from cdnjs, one HTML file.
Working Three.js Starter (community-hall-capacity-planner-x0180):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#ece9df" />
<title>Community Hall — Layout Planner</title>
<style>
:root {
--ink: #24312e;
--muted: #71807b;
--panel: rgba(251, 250, 245, 0.92);
--line: rgba(36, 49, 46, 0.13);
--green: #287f70;
--green-dark: #1f665a;
--green-soft: #dceee8;
--orange: #cf704f;
--shadow: 0 18px 50px rgba(43, 54, 49, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ece9df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.topbar {
position: fixed;
top: 24px;
left: 28px;
z-index: 10;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
color: var(--green-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.brand-mark {
display: grid;
width: 26px;
height: 26px;
grid-template-columns: repeat(2, 1fr);
gap: 3px;
padding: 4px;
border: 1px solid rgba(40, 127, 112, 0.35);
border-radius: 8px;
background: rgba(255, 255, 255, 0.48);
}
.brand-mark span {
border-radius: 2px;
background: var(--green);
}
.brand-mark span:nth-child(2),
.brand-mark span:nth-child(4) {
opacity: 0.4;
}
h1 {
margin: 0;
max-width: 470px;
font-size: clamp(30px, 4vw, 56px);
font-weight: 650;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.panel {
position: fixed;
top: 24px;
right: 24px;
z-index: 20;
width: min(340px, calc(100vw - 32px));
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 15px;
}
.eyebrow {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 19px;
font-weight: 700;
letter-spacing: -0.025em;
}
.live-dot {
display: flex;
flex: 0 0 auto;
align-items: center;
gap: 6px;
padding-top: 5px;
color: var(--green-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #46a88f;
box-shadow: 0 0 0 4px rgba(70, 168, 143, 0.12);
content: "";
}
.layout-options {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.layout-button {
position: relative;
min-height: 92px;
padding: 13px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
cursor: pointer;
text-align: left;
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease,
box-shadow 180ms ease;
}
.layout-button:hover {
transform: translateY(-2px);
border-color: rgba(40, 127, 112, 0.42);
}
.layout-button[aria-pressed="true"] {
border-color: var(--green);
background: var(--green-soft);
box-shadow: inset 0 0 0 1px rgba(40, 127, 112, 0.13);
}
.layout-name {
display: block;
margin-top: 9px;
font-size: 13px;
font-weight: 750;
}
.layout-meta {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.mini-layout {
position: relative;
display: block;
width: 66px;
height: 30px;
}
.mini-table {
position: absolute;
border-radius: 2px;
background: #b47c54;
}
.mini-chair {
position: absolute;
width: 7px;
height: 5px;
border-radius: 1px;
background: #638e87;
}
.mini-meeting .mini-table {
top: 11px;
left: 19px;
width: 31px;
height: 9px;
}
.mini-meeting .mini-chair:nth-child(2) { top: 3px; left: 21px; }
.mini-meeting .mini-chair:nth-child(3) { top: 3px; left: 30px; }
.mini-meeting .mini-chair:nth-child(4) { top: 3px; left: 39px; }
.mini-meeting .mini-chair:nth-child(5) { top: 23px; left: 21px; }
.mini-meeting .mini-chair:nth-child(6) { top: 23px; left: 30px; }
.mini-meeting .mini-chair:nth-child(7) { top: 23px; left: 39px; }
.mini-workshop .mini-table {
width: 17px;
height: 9px;
}
.mini-workshop .mini-table:nth-child(1) { top: 2px; left: 7px; }
.mini-workshop .mini-table:nth-child(2) { top: 2px; left: 41px; }
.mini-workshop .mini-table:nth-child(3) { top: 20px; left: 7px; }
.mini-workshop .mini-table:nth-child(4) { top: 20px; left: 41px; }
.mini-workshop .mini-chair {
width: 5px;
height: 4px;
}
.mini-workshop .mini-chair:nth-child(5) { top: 10px; left: 13px; }
.mini-workshop .mini-chair:nth-child(6) { top: 10px; left: 47px; }
.mini-workshop .mini-chair:nth-child(7) { top: 12px; left: 30px; }
.divider {
height: 1px;
margin: 16px 0;
background: var(--line);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.status-label {
color: var(--muted);
font-size: 11px;
}
.status-value {
color: var(--green-dark);
font-size: 11px;
font-weight: 800;
text-align: right;
}
.toggle-row {
display: flex;
gap: 8px;
}
.soft-button {
flex: 1;
min-height: 40px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.soft-button:hover {
transform: translateY(-1px);
border-color: rgba(40, 127, 112, 0.4);
background: white;
}
.soft-button.active {
border-color: rgba(40, 127, 112, 0.25);
background: var(--green-soft);
color: var(--green-dark);
}
.legend {
position: fixed;
bottom: 25px;
left: 28px;
z-index: 10;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 12px;
background: rgba(251, 250, 245, 0.78);
color: var(--muted);
box-shadow: 0 10px 30px rgba(43, 54, 49, 0.08);
backdrop-filter: blur(12px);
font-size: 10px;
}
.legend-swatch {
width: 24px;
height: 8px;
border: 1px dashed rgba(40, 127, 112, 0.7);
border-radius: 3px;
background: rgba(71, 166, 144, 0.16);
}
.controls-help {
position: fixed;
right: 28px;
bottom: 27px;
z-index: 10;
color: rgba(36, 49, 46, 0.57);
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #ece9df;
color: var(--green-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 780px) {
.topbar {
top: 18px;
left: 18px;
}
h1 {
font-size: 34px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 13px;
border-radius: 18px;
}
.panel-heading {
margin-bottom: 10px;
}
.layout-button {
min-height: 70px;
padding: 10px;
}
.mini-layout {
transform: scale(0.8);
transform-origin: left top;
}
.divider {
margin: 11px 0;
}
.legend,
.controls-help {
display: none;
}
}
@media (max-height: 700px) and (min-width: 781px) {
.topbar {
top: 18px;
}
.panel {
top: 16px;
right: 16px;
}
.layout-button {
min-height: 76px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D community hall layout"></div>
<header class="topbar">
<div class="brand">
<span class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</span>
Common Ground / Hall Planner
</div>
<h1>One hall.<br />Two ways to gather.</h1>
<p class="subtitle">
Reconfigure the room for conversation or collaboration while keeping every route connected.
</p>
</header>
<aside class="panel" aria-label="Layout controls">
<div class="panel-heading">
<div>
<span class="eyebrow">Room arrangement</span>
<h2 id="layoutName">Meeting layout</h2>
</div>
<span class="live-dot">Connected</span>
</div>
<div class="layout-options">
<button
class="layout-button"
type="button"
data-layout="meeting"
aria-pressed="true"
>
<span class="mini-layout mini-meeting" aria-hidden="true">
<span class="mini-table"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
</span>
<span class="layout-name">Meeting</span>
<span class="layout-meta">12 seats · 4 modules</span>
</button>
<button
class="layout-button"
type="button"
data-layout="workshop"
aria-pressed="false"
>
<span class="mini-layout mini-workshop" aria-hidden="true">
<span class="mini-table"></span>
<span class="mini-table"></span>
<span class="mini-table"></span>
<span class="mini-table"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
<span class="mini-chair"></span>
</span>
<span class="layout-name">Workshop</span>
<span class="layout-meta">4 groups · shared aisles</span>
</button>
</div>
<div class="divider"></div>
<div class="status-row">
<span class="status-label">Circulation check</span>
<span class="status-value" id="clearance">1.2 m minimum clear</span>
</div>
<div class="toggle-row">
<button class="soft-button active" id="routeButton" type="button" aria-pressed="true">
Show route
</button>
<button class="soft-button" id="planButton" type="button" aria-pressed="false">
Plan view
</button>
<button class="soft-button" id="resetButton" type="button">
Reset view
</button>
</div>
</aside>
<div class="legend">
<span class="legend-swatch"></span>
<span>Mint band = connected circulation</span>
</div>
<div class="controls-help">
Drag to orbit · Shift-drag to pan · Scroll to zoom · M / W to switch layout
</div>
<div class="loading" id="loading">Preparing the hall…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xece9df);
scene.fog = new THREE.Fog(0xece9df, 32, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "3D community hall");
renderer.domElement.tabIndex = 0;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x8da69b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.15);
sun.position.set(-7, 16, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xc9e6e1, 1.2);
fillLight.position.set(12, 9, -8);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.78, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
const mats = {
floor: material(0xd8d0bd, 0.94),
floorInset: material(0xe2dac8, 0.93),
wall: material(0xf1eee4, 0.92),
wallLower: material(0x8caea4, 0.85),
trim: material(0xf8f4e9, 0.8),
wood: material(0xc98c5e, 0.72),
woodDark: material(0x9d6542, 0.78),
metal: material(0x43514e, 0.55, 0.28),
metalLight: material(0x68736f, 0.5, 0.3),
glass: new THREE.MeshStandardMaterial({
color: 0x9fc9c7,
roughness: 0.25,
metalness: 0.05,
transparent: true,
opacity: 0.88
}),
board: material(0x6d857b, 0.88),
paperA: material(0xf1c66f, 0.92),
paperB: material(0xe58a67, 0.92),
paperC: material(0xc9d8c8, 0.92),
plant: material(0x557b5c, 0.9),
plantLight: material(0x78916c, 0.9),
pot: material(0xb87955, 0.9)
};
const chairPalette = [
material(0x3e7f78, 0.72),
material(0xd07b5e, 0.76),
material(0xd4ad58, 0.76)
];
function box(width, height, depth, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(radiusTop, radiusBottom, height, segments, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Community hall shell
// -------------------------------------------------------------------------
box(18, 0.24, 24, mats.floor, 0, -0.12, 0);
box(17.65, 0.025, 23.65, mats.floorInset, 0, 0.002, 0);
const floorLinePositions = [];
for (let x = -8; x <= 8; x += 2) {
floorLinePositions.push(x, 0.022, -11.75, x, 0.022, 11.75);
}
for (let z = -10; z <= 10; z += 2) {
floorLinePositions.push(-8.75, 0.022, z, 8.75, 0.022, z);
}
const floorLineGeometry = new THREE.BufferGeometry();
floorLineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(floorLinePositions, 3)
);
const floorLines = new THREE.LineSegments(
floorLineGeometry,
new THREE.LineBasicMaterial({
color: 0xaa9e86,
transparent: true,
opacity: 0.2
})
);
scene.add(floorLines);
// Back wall with a centered doorway.
const wallHeight = 4.2;
const doorWidth = 2.4;
const doorHeight = 2.8;
const sideWallWidth = (18 - doorWidth) / 2;
box(sideWallWidth, wallHeight, 0.25, mats.wall, -5.1, wallHeight / 2, -12);
box(sideWallWidth, wallHeight, 0.25, mats.wall, 5.1, wallHeight / 2, -12);
box(
doorWidth,
wallHeight - doorHeight,
0.25,
mats.wall,
0,
doorHeight + (wallHeight - doorHeight) / 2,
-12
);
// Lower wainscoting.
box(sideWallWidth, 1.05, 0.08, mats.wallLower, -5.1, 0.525, -11.84);
box(sideWallWidth, 1.05, 0.08, mats.wallLower, 5.1, 0.525, -11.84);
box(0.22, 4.2, 24, mats.wall, -9, 2.1, 0);
box(0.08, 1.05, 23.8, mats.wallLower, -8.84, 0.525, 0);
box(0.08, 0.1, 23.8, mats.trim, -8.79, 1.06, 0);
box(15, 0.1, 0.08, mats.trim, 0, 1.06, -11.78);
// Doorway and frame.
box(2.28, 2.74, 0.04, material(0x38514b, 0.9), 0, 1.37, -11.89);
box(0.12, 2.9, 0.16, mats.trim, -1.22, 1.45, -11.76);
box(0.12, 2.9, 0.16, mats.trim, 1.22, 1.45, -11.76);
box(2.56, 0.12, 0.16, mats.trim, 0, 2.88, -11.76);
// Front entrance threshold.
box(2.5, 0.025, 0.45, mats.trim, 0, 0.018, 11.72);
box(0.12, 1.0, 0.12, mats.trim, -1.3, 0.5, 11.78);
box(0.12, 1.0, 0.12, mats.trim, 1.3, 0.5, 11.78);
// Left-wall windows.
for (const z of [-7, -1.5, 4]) {
box(0.06, 1.55, 2.5, mats.glass, -8.84, 2.45, z);
box(0.12, 1.75, 0.09, mats.trim, -8.75, 2.45, z - 1.3);
box(0.12, 1.75, 0.09, mats.trim, -8.75, 2.45, z + 1.3);
box(0.12, 0.09, 2.65, mats.trim, -8.75, 1.62, z);
box(0.12, 0.09, 2.65, mats.trim, -8.75, 3.28, z);
box(0.14, 1.58, 0.06, mats.trim, -8.73, 2.45, z);
}
// Community notice board.
box(3.35, 1.65, 0.12, mats.woodDark, -5.3, 2.35, -11.79);
box(3.08, 1.38, 0.08, mats.board, -5.3, 2.35, -11.71);
box(0.67, 0.48, 0.025, mats.paperA, -6.18, 2.48, -11.65);
box(0.67, 0.48, 0.025, mats.paperB, -5.35, 2.48, -11.65);
box(0.67, 0.48, 0.025, mats.paperC, -4.52, 2.48, -11.65);
box(0.67, 0.48, 0.025, mats.paperC, -6.18, 1.91, -11.65);
box(0.67, 0.48, 0.025, mats.paperA, -5.35, 1.91, -11.65);
box(0.67, 0.48, 0.025, mats.paperB, -4.52, 1.91, -11.65);
// Low-poly planters.
function createPlanter(x, z) {
cylinder(0.38, 0.28, 0.72, 7, mats.pot, x, 0.36, z);
cylinder(0.32, 0.32, 0.07, 7, mats.woodDark, x, 0.72, z);
const leafA = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.58, 0),
mats.plant
);
leafA.position.set(x, 1.22, z);
leafA.scale.set(0.9, 1.35, 0.9);
leafA.rotation.set(0.15, 0.4, 0.15);
leafA.castShadow = true;
scene.add(leafA);
const leafB = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.42, 0),
mats.plantLight
);
leafB.position.set(x + 0.15, 1.62, z - 0.06);
leafB.rotation.set(-0.15, 0.8, -0.12);
leafB.castShadow = true;
scene.add(leafB);
}
createPlanter(-7.55, 10.55);
createPlanter(7.55, 10.55);
// -------------------------------------------------------------------------
// Circulation network
// -------------------------------------------------------------------------
const commonRouteGroup = new THREE.Group();
const workshopRouteGroup = new THREE.Group();
scene.add(commonRouteGroup, workshopRouteGroup);
const commonRouteMaterials = [];
const workshopRouteMaterials = [];
function routeMaterial(extra = false) {
const mat = new THREE.MeshBasicMaterial({
color: 0x54b59d,
transparent: true,
opacity: 0.115,
depthWrite: false,
side: THREE.DoubleSide
});
mat.userData.baseOpacity = mat.opacity;
(extra ? workshopRouteMaterials : commonRouteMaterials).push(mat);
return mat;
}
function routeLineMaterial(extra = false) {
const mat = new THREE.LineDashedMaterial({
color: 0x287f70,
dashSize: 0.28,
gapSize: 0.18,
transparent: true,
opacity: 0.72,
depthWrite: false
});
mat.userData.baseOpacity = mat.opacity;
(extra ? workshopRouteMaterials : commonRouteMaterials).push(mat);
return mat;
}
function routeStrip(x, z, width, depth, parent, extra = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.014, depth),
routeMaterial(extra)
);
mesh.position.set(x, 0.035, z);
mesh.receiveShadow = false;
parent.add(mesh);
return mesh;
}
function dashedLine(points, parent, extra = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(point[0], 0.052, point[1]))
);
const line = new THREE.Line(geometry, routeLineMaterial(extra));
line.computeLineDistances();
parent.add(line);
return line;
}
// Connected perimeter and entrance/exit branches.
routeStrip(-7, 0, 1, 18.5, commonRouteGroup);
routeStrip(7, 0, 1, 18.5, commonRouteGroup);
routeStrip(0, 9.25, 14, 1, commonRouteGroup);
routeStrip(0, -9.25, 14, 1, commonRouteGroup);
routeStrip(0, 10.4, 1.2, 2.7, commonRouteGroup);
routeStrip(0, -10.4, 1.2, 2.7, commonRouteGroup);
dashedLine(
[
[-7, 9.25],
[7, 9.25],
[7, -9.25],
[-7, -9.25],
[-7, 9.25]
],
commonRouteGroup
);
dashedLine([[0, 9.25], [0, 11.75]], commonRouteGroup);
dashedLine([[0, -9.25], [0, -11.7]], commonRouteGroup);
// Workshop-only central cross-aisles.
routeStrip(0, 0, 1.2, 18.5, workshopRouteGroup, true);
routeStrip(0, 0, 14, 1.2, workshopRouteGroup, true);
dashedLine([[0, -9.25], [0, 9.25]], workshopRouteGroup, true);
dashedLine([[-7, 0], [7, 0]], workshopRouteGroup, true);
// -------------------------------------------------------------------------
// Modular tables and low-poly chairs
// -------------------------------------------------------------------------
const tables = [];
const chairs = [];
function createTable(index) {
const group = new THREE.Group();
// Shared modular table: 2.15 × 1.4.
box(2.15, 0.13, 1.4, mats.wood, 0, 0.86, 0, group);
box(1.92, 0.08, 0.09, mats.woodDark, 0, 0.74, 0, group);
for (const x of [-0.87, 0.87]) {
for (const z of [-0.49, 0.49]) {
box(0.065, 0.8, 0.065, mats.metal, x, 0.4, z, group);
}
}
// Small workshop materials remain attached to each table module.
box(0.4, 0.035, 0.31, index % 2 ? mats.paperB : mats.paperA, -0.54, 0.946, 0.12, group);
box(0.37, 0.035, 0.28, mats.paperC, 0.51, 0.946, -0.15, group);
cylinder(0.07, 0.055, 0.17, 8, mats.trim, 0.73, 1.02, 0.26, group);
group.userData.target = { x: 0, z: 0, rotation: 0 };
scene.add(group);
tables.push(group);
return group;
}
function createChair(index) {
const group = new THREE.Group();
const chairMat = chairPalette[index % chairPalette.length];
box(0.62, 0.11, 0.58, chairMat, 0, 0.5, 0, group);
const back = box(0.62, 0.5, 0.08, chairMat, 0, 0.84, -0.255, group);
back.rotation.x = -0.12;
for (const x of [-0.235, 0.235]) {
for (const z of [-0.205, 0.205]) {
box(0.055, 0.46, 0.055, mats.metal, x, 0.23, z, group);
}
}
box(0.48, 0.055, 0.05, mats.metal, 0, 0.19, 0, group);
group.userData.target = { x: 0, z: 0, rotation: 0 };
scene.add(group);
chairs.push(group);
return group;
}
for (let i = 0; i < 4; i++) createTable(i);
for (let i = 0; i < 12; i++) createChair(i);
// Four modules align to form one long meeting table.
const meetingTableSpecs = [
{ x: -3.345, z: 0, rotation: 0 },
{ x: -1.115, z: 0, rotation: 0 },
{ x: 1.115, z: 0, rotation: 0 },
{ x: 3.345, z: 0, rotation: 0 }
];
const meetingChairSpecs = [];
for (let i = 0; i < 5; i++) {
meetingChairSpecs.push({
x: -3.6 + i * 1.8,
z: 1.15,
rotation: Math.PI
});
}
for (let i = 0; i < 5; i++) {
meetingChairSpecs.push({
x: -3.6 + i * 1.8,
z: -1.15,
rotation: 0
});
}
meetingChairSpecs.push({ x: -4.95, z: 0, rotation: Math.PI / 2 });
meetingChairSpecs.push({ x: 4.95, z: 0, rotation: -Math.PI / 2 });
// Four islands leave a connected cross-aisle through the center.
const workshopTableSpecs = [
{ x: -4.2, z: -4.1, rotation: 0 },
{ x: 4.2, z: -4.1, rotation: 0 },
{ x: -4.2, z: 4.1, rotation: 0 },
{ x: 4.2, z: 4.1, rotation: 0 }
];
const workshopChairSpecs = [];
for (const tableSpec of workshopTableSpecs) {
if (tableSpec.z < 0) {
workshopChairSpecs.push(
{ x: tableSpec.x - 0.62, z: tableSpec.z + 1.35, rotation: Math.PI },
{ x: tableSpec.x + 0.62, z: tableSpec.z + 1.35, rotation: Math.PI },
{ x: tableSpec.x, z: tableSpec.z - 1.35, rotation: 0 }
);
} else {
workshopChairSpecs.push(
{ x: tableSpec.x - 0.62, z: tableSpec.z - 1.35, rotation: 0 },
{ x: tableSpec.x + 0.62, z: tableSpec.z - 1.35, rotation: 0 },
{ x: tableSpec.x, z: tableSpec.z + 1.35, rotation: Math.PI }
);
}
}
function applySpec(object, spec, immediate = false) {
object.userData.target = {
x: spec.x,
z: spec.z,
rotation: spec.rotation
};
if (immediate) {
object.position.set(spec.x, 0, spec.z);
object.rotation.y = spec.rotation;
}
}
tables.forEach((table, index) => applySpec(table, meetingTableSpecs[index], true));
chairs.forEach((chair, index) => applySpec(chair, meetingChairSpecs[index], true));
// -------------------------------------------------------------------------
// Layout transitions
// -------------------------------------------------------------------------
let currentLayout = "meeting";
let transitioning = false;
let transitionStart = 0;
const transitionDuration = 1650;
const layoutButtons = [...document.querySelectorAll("[data-layout]")];
const layoutName = document.getElementById("layoutName");
const clearance = document.getElementById("clearance");
function shortestAngleDifference(from, to) {
return Math.atan2(Math.sin(to - from), Math.cos(to - from));
}
function beginTransition(layout) {
if (layout === currentLayout) return;
currentLayout = layout;
const tableSpecs = layout === "meeting" ? meetingTableSpecs : workshopTableSpecs;
const chairSpecs = layout === "meeting" ? meetingChairSpecs : workshopChairSpecs;
tables.forEach((table, index) => {
table.userData.fromPosition = table.position.clone();
table.userData.fromRotation = table.rotation.y;
applySpec(table, tableSpecs[index]);
});
chairs.forEach((chair, index) => {
chair.userData.fromPosition = chair.position.clone();
chair.userData.fromRotation = chair.rotation.y;
applySpec(chair, chairSpecs[index]);
});
transitionStart = performance.now();
transitioning = true;
layoutButtons.forEach((button) => {
button.setAttribute("aria-pressed", String(button.dataset.layout === layout));
});
if (layout === "meeting") {
layoutName.textContent = "Meeting layout";
clearance.textContent = "1.2 m minimum clear";
} else {
layoutName.textContent = "Workshop layout";
clearance.textContent = "2.1 m minimum clear";
}
}
layoutButtons.forEach((button) => {
button.addEventListener("click", () => beginTransition(button.dataset.layout));
});
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
// -------------------------------------------------------------------------
// Route visibility
// -------------------------------------------------------------------------
const routeButton = document.getElementById("routeButton");
let routeVisible = true;
let routeAlpha = 1;
let workshopRouteAlpha = 0;
routeButton.addEventListener("click", () => {
routeVisible = !routeVisible;
routeButton.textContent = routeVisible ? "Show route" : "Hide route";
routeButton.classList.toggle("active", routeVisible);
routeButton.setAttribute("aria-pressed", String(routeVisible));
});
function updateRouteMaterials(delta) {
const commonTarget = routeVisible ? 1 : 0;
const workshopTarget = routeVisible && currentLayout === "workshop" ? 1 : 0;
const smoothing = 1 - Math.exp(-delta * 5.5);
routeAlpha += (commonTarget - routeAlpha) * smoothing;
workshopRouteAlpha += (workshopTarget - workshopRouteAlpha) * smoothing;
for (const mat of commonRouteMaterials) {
mat.opacity = mat.userData.baseOpacity * routeAlpha;
}
for (const mat of workshopRouteMaterials) {
mat.opacity = mat.userData.baseOpacity * routeAlpha * workshopRouteAlpha;
}
commonRouteGroup.visible = routeAlpha > 0.01;
workshopRouteGroup.visible = routeAlpha * workshopRouteAlpha > 0.01;
}
// -------------------------------------------------------------------------
// Custom orbit/pan/zoom camera controls
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.63,
phi: 0.98,
radius: 30,
target: new THREE.Vector3(0, 0.35, 0)
};
const desiredCamera = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
const pointers = new Map();
let activePointerId = null;
let panning = false;
let lastGesture = { x: 0, y: 0 };
let lastCentroid = { x: 0, y: 0 };
let lastSpread = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function pointerPosition(event) {
const rect = renderer.domElement.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top
};
}
function updateGestureBaseline() {
const values = [...pointers.values()];
if (values.length === 0) return;
const centroidX = values.reduce((sum, p) => sum + p.x, 0) / values.length;
const centroidY = values.reduce((sum, p) => sum + p.y, 0) / values.length;
lastCentroid = { x: centroidX, y: centroidY };
if (values.length === 2) {
lastSpread = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
}
function panCamera(deltaX, deltaY) {
const scale = desiredCamera.radius * 0.00115;
const rightX = Math.cos(desiredCamera.theta);
const rightZ = -Math.sin(desiredCamera.theta);
const forwardX = -Math.sin(desiredCamera.theta);
const forwardZ = -Math.cos(desiredCamera.theta);
desiredCamera.target.x +=
(-deltaX * rightX + deltaY * forwardX) * scale;
desiredCamera.target.z +=
(-deltaX * rightZ + deltaY * forwardZ) * scale;
desiredCamera.target.x = clamp(desiredCamera.target.x, -4.5, 4.5);
desiredCamera.target.z = clamp(desiredCamera.target.z, -6, 6);
}
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
const position = pointerPosition(event);
pointers.set(event.pointerId, position);
if (pointers.size === 1) {
activePointerId = event.pointerId;
panning = event.button === 2 || event.shiftKey;
lastGesture = position;
} else {
updateGestureBaseline();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const position = pointerPosition(event);
pointers.set(event.pointerId, position);
if (pointers.size === 2) {
const values = [...pointers.values()];
const centroidX = (values[0].x + values[1].x) / 2;
const centroidY = (values[0].y + values[1].y) / 2;
const spread = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (lastSpread > 0 && spread > 0) {
desiredCamera.radius = clamp(
desiredCamera.radius * (lastSpread / spread),
16,
43
);
}
desiredCamera.theta -= (centroidX - lastCentroid.x) * 0.004;
desiredCamera.phi = clamp(
desiredCamera.phi - (centroidY - lastCentroid.y) * 0.004,
0.12,
1.36
);
lastCentroid = { x: centroidX, y: centroidY };
lastSpread = spread;
return;
}
if (event.pointerId !== activePointerId) return;
const deltaX = position.x - lastGesture.x;
const deltaY = position.y - lastGesture.y;
lastGesture = position;
if (panning || event.shiftKey) {
panCamera(deltaX, deltaY);
} else {
desiredCamera.theta -= deltaX * 0.006;
desiredCamera.phi = clamp(
desiredCamera.phi - deltaY * 0.005,
0.12,
1.36
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (activePointerId === event.pointerId) {
activePointerId = null;
}
if (pointers.size === 1) {
const [id, position] = pointers.entries().next().value;
activePointerId = id;
lastGesture = position;
}
updateGestureBaseline();
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
16,
43
);
},
{ passive: false }
);
const planButton = document.getElementById("planButton");
let planView = false;
function setPlanView(enabled) {
planView = enabled;
planButton.classList.toggle("active", enabled);
planButton.setAttribute("aria-pressed", String(enabled));
if (enabled) {
desiredCamera.theta = 0;
desiredCamera.phi = 0.12;
desiredCamera.radius = 29;
desiredCamera.target.set(0, 0, 0);
} else {
desiredCamera.theta = 0.63;
desiredCamera.phi = 0.98;
desiredCamera.radius = 30;
desiredCamera.target.set(0, 0.35, 0);
}
}
planButton.addEventListener("click", () => setPlanView(!planView));
document.getElementById("resetButton").addEventListener("click", () => {
setPlanView(false);
desiredCamera.theta = 0.63;
desiredCamera.phi = 0.98;
desiredCamera.radius = 30;
desiredCamera.target.set(0, 0.35, 0);
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
const key = event.key.toLowerCase();
if (key === "m") beginTransition("meeting");
if (key === "w") beginTransition("workshop");
if (key === "c") routeButton.click();
if (key === "p") setPlanView(!planView);
if (key === "r") document.getElementById("resetButton").click();
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (transitioning) {
const rawProgress = clamp(
(now - transitionStart) / transitionDuration,
0,
1
);
const progress = easeInOutCubic(rawProgress);
tables.forEach((table) => {
const from = table.userData.fromPosition;
const target = table.userData.target;
const rotationDelta = shortestAngleDifference(
table.userData.fromRotation,
target.rotation
);
table.position.x = THREE.MathUtils.lerp(from.x, target.x, progress);
table.position.z = THREE.MathUtils.lerp(from.z, target.z, progress);
table.position.y = Math.sin(rawProgress * Math.PI) * 0.035;
table.rotation.y =
table.userData.fromRotation + rotationDelta * progress;
});
chairs.forEach((chair) => {
const from = chair.userData.fromPosition;
const target = chair.userData.target;
const rotationDelta = shortestAngleDifference(
chair.userData.fromRotation,
target.rotation
);
chair.position.x = THREE.MathUtils.lerp(from.x, target.x, progress);
chair.position.z = THREE.MathUtils.lerp(from.z, target.z, progress);
chair.position.y =
THREE.MathUtils.lerp(from.y, 0, progress) +
Math.sin(rawProgress * Math.PI) * 0.22;
chair.rotation.y =
chair.userData.fromRotation + rotationDelta * progress;
});
if (rawProgress >= 1) {
transitioning = false;
tables.forEach((table) => {
const target = table.userData.target;
table.position.set(target.x, 0, target.z);
table.rotation.y = target.rotation;
});
chairs.forEach((chair) => {
const target = chair.userData.target;
chair.position.set(target.x, 0, target.z);
chair.rotation.y = target.rotation;
});
}
}
updateRouteMaterials(delta);
const cameraSmoothing = 1 - Math.exp(-delta * 10);
cameraState.theta +=
(desiredCamera.theta - cameraState.theta) * cameraSmoothing;
cameraState.phi +=
(desiredCamera.phi - cameraState.phi) * cameraSmoothing;
cameraState.radius +=
(desiredCamera.radius - cameraState.radius) * cameraSmoothing;
cameraState.target.lerp(desiredCamera.target, cameraSmoothing);
const horizontalRadius =
cameraState.radius * Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
horizontalRadius * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
horizontalRadius * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```