Prompt specification
Build or customize the Three.js 3D scene "Restroom door sweep and clear area" 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: Restroom door sweep and clear area
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/restroom-door-sweep-and-clear-area-x0449
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Model a simplified restroom cubicle with door arc, basin, and open floor region; compare occupied and unoccupied clearance zones without presenting regulatory design dimensions.
Working Three.js Starter (restroom-door-sweep-and-clear-area-x0449):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Restroom Cubicle — Clearance Study</title>
<style>
:root {
color-scheme: light;
--ink: #173331;
--muted: #617573;
--paper: rgba(249, 252, 250, 0.92);
--line: rgba(23, 51, 49, 0.13);
--cyan: #20a9a4;
--cyan-soft: #d8f4ef;
--amber: #ed9b3f;
--amber-soft: #fff0d8;
--shadow: 0 18px 55px rgba(35, 65, 62, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8efec;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px;
border-radius: 22px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 10px;
color: #43817c;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 13px 0 0 #a8d9d3;
content: "";
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 3vw, 2.15rem);
line-height: 1.03;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 18px;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.5;
}
.mode-switch {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(229, 238, 234, 0.74);
}
.mode-switch button {
min-height: 38px;
padding: 8px 7px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 0.77rem;
font-weight: 750;
transition:
background 160ms ease,
color 160ms ease,
box-shadow 160ms ease;
}
.mode-switch button:hover {
color: var(--ink);
}
.mode-switch button[aria-pressed="true"] {
background: white;
color: var(--ink);
box-shadow: 0 4px 12px rgba(31, 65, 61, 0.11);
}
.insights {
top: 22px;
right: 22px;
width: min(320px, calc(100vw - 44px));
overflow: hidden;
border-radius: 22px;
}
.insights-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 17px 13px;
border-bottom: 1px solid var(--line);
}
.insights-header h2 {
margin: 0;
font-size: 0.93rem;
letter-spacing: -0.02em;
}
.concept-badge {
padding: 5px 8px;
border: 1px solid #beded9;
border-radius: 999px;
background: #eef9f6;
color: #39756f;
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.comparison {
padding: 8px 16px 15px;
}
.comparison-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 11px;
padding: 13px 0;
}
.comparison-row + .comparison-row {
border-top: 1px solid var(--line);
}
.swatch {
width: 10px;
height: 10px;
margin-top: 5px;
border-radius: 3px;
}
.swatch.open {
background: var(--cyan);
box-shadow: 0 0 0 4px var(--cyan-soft);
}
.swatch.occupied {
background: var(--amber);
box-shadow: 0 0 0 4px var(--amber-soft);
}
.comparison-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
font-size: 0.82rem;
font-weight: 800;
}
.comparison-title span:last-child {
color: var(--muted);
font-size: 0.68rem;
font-weight: 750;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.comparison p {
margin: 5px 0 0;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
padding: 12px 16px;
border-top: 1px solid var(--line);
background: rgba(236, 243, 240, 0.58);
color: var(--muted);
font-size: 0.68rem;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 17px;
height: 3px;
border-radius: 4px;
}
.legend-line.door {
background: #7196bd;
}
.legend-line.open {
background: var(--cyan);
}
.legend-line.occupied {
background: var(--amber);
}
.view-controls {
right: 22px;
bottom: 22px;
display: flex;
gap: 5px;
padding: 6px;
border-radius: 14px;
}
.view-controls button {
display: grid;
min-width: 70px;
min-height: 36px;
place-items: center;
padding: 8px 11px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 0.72rem;
font-weight: 800;
}
.view-controls button:hover {
background: #e7efec;
color: var(--ink);
}
.help {
position: fixed;
z-index: 9;
left: 22px;
bottom: 22px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 12px;
background: rgba(249, 252, 250, 0.78);
box-shadow: 0 8px 25px rgba(35, 65, 62, 0.09);
color: var(--muted);
font-size: 0.7rem;
font-weight: 650;
backdrop-filter: blur(12px);
pointer-events: none;
}
.disclaimer {
position: fixed;
z-index: 8;
left: 50%;
bottom: 22px;
width: min(450px, calc(100vw - 460px));
transform: translateX(-50%);
color: rgba(23, 51, 49, 0.62);
font-size: 0.64rem;
line-height: 1.35;
text-align: center;
pointer-events: none;
}
#labels {
position: fixed;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 9px;
background: rgba(255, 255, 255, 0.86);
box-shadow: 0 5px 18px rgba(33, 60, 57, 0.13);
color: #244541;
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.025em;
white-space: nowrap;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.world-label::after {
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: rgba(36, 69, 65, 0.38);
content: "";
}
.world-label .dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: #7196bd;
}
.world-label.basin .dot {
background: #8aa7b8;
}
.world-label.open .dot {
background: var(--cyan);
}
.world-label.occupied .dot {
background: var(--amber);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #e8efec;
color: #39756f;
font-size: 0.78rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.intro {
top: 12px;
left: 12px;
width: min(360px, calc(100vw - 24px));
padding: 16px;
}
.subtitle {
margin-bottom: 13px;
}
.insights {
top: auto;
right: 12px;
bottom: 62px;
width: min(300px, calc(100vw - 24px));
}
.comparison-row {
padding: 9px 0;
}
.view-controls {
right: 12px;
bottom: 12px;
}
.help {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 320px);
}
.disclaimer {
display: none;
}
}
@media (max-width: 540px) {
.insights {
width: calc(100vw - 24px);
}
.insights-header,
.legend,
.comparison-row:nth-child(2) {
display: none;
}
.comparison {
padding: 7px 14px;
}
.comparison-row {
padding: 8px 0;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive voxel restroom cubicle"></canvas>
<section class="panel intro">
<p class="eyebrow">Spatial study</p>
<h1>Restroom cubicle</h1>
<p class="subtitle">
Explore how an occupant changes the usable floor around a basin and
inward-swinging door.
</p>
<div class="mode-switch" role="group" aria-label="Clearance comparison mode">
<button type="button" data-mode="unoccupied" aria-pressed="true">
Unoccupied
</button>
<button type="button" data-mode="occupied" aria-pressed="false">
Occupied
</button>
<button type="button" data-mode="compare" aria-pressed="false">
Compare
</button>
</div>
</section>
<aside class="panel insights">
<div class="insights-header">
<h2>Clearance comparison</h2>
<span class="concept-badge">Conceptual</span>
</div>
<div class="comparison">
<div class="comparison-row">
<span class="swatch open"></span>
<div>
<div class="comparison-title">
<span>Open-floor zone</span>
<span>Connected</span>
</div>
<p>
The center remains visually continuous when the cubicle is not
occupied.
</p>
</div>
</div>
<div class="comparison-row">
<span class="swatch occupied"></span>
<div>
<div class="comparison-title">
<span>Occupied envelope</span>
<span>Localized</span>
</div>
<p>
The occupant creates a local pinch point near the basin approach.
</p>
</div>
</div>
</div>
<div class="legend">
<span class="legend-item">
<i class="legend-line door"></i>
Door sweep
</span>
<span class="legend-item">
<i class="legend-line open"></i>
Open floor
</span>
<span class="legend-item">
<i class="legend-line occupied"></i>
Occupied
</span>
</div>
</aside>
<nav class="panel view-controls" aria-label="Camera views">
<button type="button" data-view="iso">Isometric</button>
<button type="button" data-view="top">Top</button>
<button type="button" data-view="front">Front</button>
</nav>
<div class="help">Drag to orbit · Right-drag to pan · Scroll to zoom</div>
<p class="disclaimer">
Illustrative spatial study only. Zones are qualitative and do not represent
regulatory, accessibility, or construction dimensions.
</p>
<div id="labels" aria-hidden="true"></div>
<div id="loading">Building voxel study…</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8efec);
scene.fog = new THREE.Fog(0xe8efec, 16, 30);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
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;
const hemisphere = new THREE.HemisphereLight(0xf8fffd, 0x8fa7a0, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff8e9, 3.2);
sun.position.set(5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9e3ec, 0.9);
fill.position.set(-7, 5, -4);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
const palette = {
floor: [0xe9eeea, 0xe1e8e3, 0xf1f4ef, 0xdce6df],
wall: [0xf4f3ea, 0xecece2, 0xf8f6ee, 0xe7e8df],
wallShade: [0xdce6df, 0xe4e8df, 0xd8e2da],
trim: 0x5f8881,
dark: 0x315b58,
door: 0x769eb7,
doorLight: 0x91b5c9,
metal: 0x8ea5a5,
mirror: 0xa9d6df
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true,
side: options.side ?? THREE.FrontSide
});
}
function box(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = world
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x486b65, opacity = 0.18) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
// Ground and tiled floor
const ground = box(
34,
0.12,
34,
standard(0xdfe8e3),
0,
-0.19,
0
);
ground.castShadow = false;
const floorBase = box(
8.15,
0.18,
6.15,
standard(0xbed0c8),
0,
-0.07,
0
);
addEdges(floorBase, 0x52756f, 0.2);
const tileGeometry = new THREE.BoxGeometry(0.49, 0.065, 0.49);
const tileMaterial = standard(0xffffff);
const tileCountX = 16;
const tileCountZ = 12;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCountX * tileCountZ
);
tiles.receiveShadow = true;
tiles.castShadow = false;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = 0; z < tileCountZ; z++) {
for (let x = 0; x < tileCountX; x++) {
const px = -3.75 + x * 0.5;
const pz = -2.75 + z * 0.5;
dummy.position.set(px, 0.025, pz);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const shade = (x * 7 + z * 11) % palette.floor.length;
tileColor.setHex(palette.floor[shade]);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
world.add(tiles);
// Voxel wall builder
function voxelWall({
axis,
fixed,
start,
end,
height,
colors = palette.wall,
base = 0.05
}) {
const length = end - start;
const columns = Math.ceil(length / 0.5);
const rows = Math.ceil(height / 0.5);
const geometry = new THREE.BoxGeometry(
axis === "x" ? 0.485 : 0.16,
0.485,
axis === "x" ? 0.16 : 0.485
);
const material = standard(0xffffff);
const mesh = new THREE.InstancedMesh(
geometry,
material,
columns * rows
);
mesh.castShadow = true;
mesh.receiveShadow = true;
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const along = start + (column + 0.5) * (length / columns);
const y = base + 0.2425 + row * 0.5;
dummy.position.set(
axis === "x" ? along : fixed,
y,
axis === "x" ? fixed : along
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const shade = (column * 5 + row * 3) % colors.length;
tileColor.setHex(colors[shade]);
mesh.setColorAt(index, tileColor);
index++;
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
world.add(mesh);
return mesh;
}
// Full back and side walls; front and right walls are cut away.
voxelWall({
axis: "x",
fixed: -3,
start: -4,
end: 4,
height: 2.85,
colors: palette.wall
});
voxelWall({
axis: "z",
fixed: -4,
start: -3,
end: 3,
height: 2.85,
colors: palette.wallShade
});
voxelWall({
axis: "z",
fixed: 4,
start: -3,
end: 3,
height: 1.05,
colors: palette.wall
});
voxelWall({
axis: "x",
fixed: 3,
start: -4,
end: -3.15,
height: 0.72,
colors: palette.wallShade
});
voxelWall({
axis: "x",
fixed: 3,
start: -1.45,
end: 4,
height: 0.72,
colors: palette.wall
});
// Skirting
box(8, 0.16, 0.12, standard(palette.trim), 0, 0.15, -2.89);
box(0.12, 0.16, 6, standard(palette.trim), -3.89, 0.15, 0);
box(0.12, 0.16, 6, standard(palette.trim), 3.89, 0.15, 0);
// Door frame
const frameMaterial = standard(0x668b8a);
box(0.13, 2.3, 0.19, frameMaterial, -3.18, 1.15, 2.96);
box(0.13, 2.3, 0.19, frameMaterial, -1.42, 1.15, 2.96);
box(1.89, 0.13, 0.19, frameMaterial, -2.3, 2.31, 2.96);
// Inward-swinging voxel door
const doorPivot = new THREE.Group();
doorPivot.position.set(-3.1, 0, 2.91);
world.add(doorPivot);
const doorMaterial = standard(palette.door, { roughness: 0.72 });
const doorLightMaterial = standard(palette.doorLight, { roughness: 0.72 });
const doorDarkMaterial = standard(0x557c93, { roughness: 0.75 });
const doorLeaf = box(1.63, 2.14, 0.12, doorMaterial, 0.815, 1.1, 0);
addEdges(doorLeaf, 0x3d647c, 0.26);
doorPivot.add(doorLeaf);
for (let i = 0; i < 4; i++) {
box(
0.25,
1.6,
0.035,
doorLightMaterial,
0.25 + i * 0.36,
1.15,
-0.077
);
}
box(1.5, 0.08, 0.04, doorDarkMaterial, 0.82, 0.35, -0.08);
box(1.5, 0.08, 0.04, doorDarkMaterial, 0.82, 1.88, -0.08);
box(0.13, 0.12, 0.16, standard(palette.metal, { metalness: 0.65 }), 1.39, 1.03, -0.12);
box(0.22, 0.045, 0.08, standard(palette.metal, { metalness: 0.65 }), 1.31, 1.03, -0.18);
doorPivot.rotation.y = THREE.MathUtils.degToRad(68);
// Door swing arc, made from voxel-like tiles.
const arcGroup = new THREE.Group();
world.add(arcGroup);
const arcMaterial = standard(0x7196bd, {
transparent: true,
opacity: 0.82,
depthWrite: false
});
const arcRadius = 1.62;
const hingeX = -3.1;
const hingeZ = 2.91;
const arcAngle = THREE.MathUtils.degToRad(68);
for (let i = 0; i <= 28; i++) {
const a = (i / 28) * arcAngle;
const x = hingeX + Math.cos(a) * arcRadius;
const z = hingeZ - Math.sin(a) * arcRadius;
const marker = box(0.065, 0.025, 0.065, arcMaterial, x, 0.09, z, arcGroup);
marker.castShadow = false;
}
// Basin and mirror
const basinGroup = new THREE.Group();
basinGroup.position.set(2.28, 0, -2.47);
world.add(basinGroup);
const porcelain = standard(0xf5f7f2, { roughness: 0.4 });
const porcelainShade = standard(0xd8e1dc, { roughness: 0.46 });
const basinDark = standard(0x93b5b5, { roughness: 0.3 });
box(0.5, 0.77, 0.46, porcelainShade, 0, 0.43, 0, basinGroup);
box(0.72, 0.12, 0.55, porcelain, 0, 0.84, 0, basinGroup);
box(1.12, 0.2, 0.68, porcelain, 0, 0.94, 0, basinGroup);
// Recessed basin center
box(0.76, 0.035, 0.4, basinDark, 0, 1.052, 0.01, basinGroup);
box(0.42, 0.02, 0.25, standard(0x6f9c9f), 0, 1.075, 0.01, basinGroup);
// Voxel faucet
box(0.12, 0.37, 0.12, standard(palette.metal, { metalness: 0.68 }), 0, 1.25, -0.26, basinGroup);
box(0.12, 0.12, 0.32, standard(palette.metal, { metalness: 0.68 }), 0, 1.42, -0.17, basinGroup);
box(0.1, 0.14, 0.1, standard(palette.metal, { metalness: 0.68 }), 0, 1.36, -0.04, basinGroup);
// Mirror and pixel highlights
const mirrorFrame = box(1.38, 1.42, 0.1, standard(0x789a9c), 2.28, 1.87, -2.88);
addEdges(mirrorFrame, 0x426c6b, 0.28);
box(1.2, 1.24, 0.035, standard(palette.mirror, { roughness: 0.18, metalness: 0.12 }), 2.28, 1.87, -2.815);
box(0.18, 0.72, 0.015, standard(0xdff4f2, { transparent: true, opacity: 0.52, depthWrite: false }), 2.03, 1.91, -2.79);
box(0.08, 0.42, 0.015, standard(0xffffff, { transparent: true, opacity: 0.48, depthWrite: false }), 2.28, 2.0, -2.78);
// Small wall detail above basin
box(0.85, 0.12, 0.1, standard(0xb3c5c1), 2.28, 2.68, -2.88);
// Open-floor zone
const openZone = new THREE.Group();
world.add(openZone);
const openFill = box(
4.35,
0.025,
3.15,
new THREE.MeshBasicMaterial({
color: 0x20a9a4,
transparent: true,
opacity: 0.13,
depthWrite: false
}),
0.15,
0.085,
0.48,
openZone
);
openFill.castShadow = false;
openFill.receiveShadow = false;
openFill.renderOrder = 1;
const openEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(openFill.geometry),
new THREE.LineBasicMaterial({
color: 0x159b96,
transparent: true,
opacity: 0.72
})
);
openFill.add(openEdges);
// Subtle inset grid marks in the open zone
const openGridMaterial = new THREE.MeshBasicMaterial({
color: 0x159b96,
transparent: true,
opacity: 0.13,
depthWrite: false
});
for (let x = -1.55; x <= 1.85; x += 0.7) {
const tick = box(0.025, 0.01, 0.15, openGridMaterial, x, 0.11, 0.48, openZone);
tick.castShadow = false;
}
for (let z = -0.8; z <= 1.75; z += 0.7) {
const tick = box(0.15, 0.01, 0.025, openGridMaterial, 0.15, 0.11, z, openZone);
tick.castShadow = false;
}
// Occupied envelope
const occupiedZone = new THREE.Group();
world.add(occupiedZone);
const occupiedFill = box(
1.95,
0.035,
1.65,
new THREE.MeshBasicMaterial({
color: 0xed9b3f,
transparent: true,
opacity: 0.19,
depthWrite: false
}),
0.05,
0.105,
0.25,
occupiedZone
);
occupiedFill.castShadow = false;
occupiedFill.receiveShadow = false;
occupiedFill.renderOrder = 2;
const occupiedEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(occupiedFill.geometry),
new THREE.LineBasicMaterial({
color: 0xd87e1d,
transparent: true,
opacity: 0.9
})
);
occupiedFill.add(occupiedEdges);
// Corner brackets to make the occupied envelope read as a study overlay.
const cornerMaterial = new THREE.MeshBasicMaterial({
color: 0xd87e1d,
transparent: true,
opacity: 0.9,
depthWrite: false
});
function cornerBracket(x, z, sx, sz) {
box(0.26, 0.018, 0.045, cornerMaterial, x + sx * 0.09, 0.135, z, occupiedZone);
box(0.045, 0.018, 0.26, cornerMaterial, x, 0.135, z + sz * 0.09, occupiedZone);
}
cornerBracket(-0.9, -0.55, 1, 1);
cornerBracket(1.0, -0.55, -1, 1);
cornerBracket(-0.9, 1.05, 1, -1);
cornerBracket(1.0, 1.05, -1, -1);
// Stylized voxel occupant
const occupant = new THREE.Group();
occupant.position.set(0.05, 0.08, 0.25);
world.add(occupant);
const skin = standard(0xdca783, { roughness: 0.9 });
const hair = standard(0x3b403d, { roughness: 1 });
const shirt = standard(0x3c8c88, { roughness: 0.9 });
const shirtLight = standard(0x58aaa3, { roughness: 0.9 });
const pants = standard(0x345461, { roughness: 0.92 });
const shoes = standard(0x273c3e, { roughness: 0.85 });
box(0.2, 0.62, 0.22, pants, -0.15, 0.44, 0, occupant);
box(0.2, 0.62, 0.22, pants, 0.15, 0.44, 0, occupant);
box(0.24, 0.11, 0.36, shoes, -0.15, 0.075, 0.05, occupant);
box(0.24, 0.11, 0.36, shoes, 0.15, 0.075, 0.05, occupant);
const torso = box(0.64, 0.72, 0.34, shirt, 0, 1.08, 0, occupant);
addEdges(torso, 0x286b68, 0.16);
box(0.18, 0.22, 0.36, shirtLight, -0.14, 1.48, 0, occupant);
box(0.19, 0.63, 0.21, shirt, -0.43, 1.08, 0, occupant);
box(0.19, 0.63, 0.21, shirt, 0.43, 1.08, 0, occupant);
box(0.17, 0.17, 0.2, skin, -0.43, 0.68, 0, occupant);
box(0.17, 0.17, 0.2, skin, 0.43, 0.68, 0, occupant);
box(0.43, 0.43, 0.4, skin, 0, 1.69, 0, occupant);
box(0.46, 0.16, 0.42, hair, 0, 1.87, -0.015, occupant);
box(0.12, 0.28, 0.41, hair, -0.19, 1.75, -0.01, occupant);
box(0.12, 0.28, 0.41, hair, 0.19, 1.75, -0.01, occupant);
// Small floor objects for scale and visual interest.
const bin = new THREE.Group();
bin.position.set(-3.18, 0.08, -2.28);
world.add(bin);
box(0.46, 0.62, 0.46, standard(0x839b94), 0, 0.31, 0, bin);
box(0.5, 0.08, 0.5, standard(0x536f6a), 0, 0.64, 0, bin);
box(0.28, 0.03, 0.28, standard(0x2c4543), 0, 0.69, 0, bin);
// World labels
const labels = [];
function addLabel(text, className, anchor, offsetX = 0, offsetY = 0) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = `<span class="dot"></span>${text}`;
labelLayer.appendChild(element);
labels.push({
element,
anchor: new THREE.Vector3(...anchor),
offsetX,
offsetY
});
}
addLabel("Door sweep", "door", [-2.35, 0.22, 2.0], -26, 4);
addLabel("Basin", "basin", [2.28, 1.3, -2.35], 10, -4);
addLabel("Open-floor zone", "open", [-0.2, 0.15, 1.0], -66, 8);
addLabel("Occupied envelope", "occupied", [0.7, 0.16, 0.45], 68, 4);
// Custom camera controller: orbit, pan, zoom, keyboard, and view buttons.
const cameraState = {
target: new THREE.Vector3(0, 0.75, 0),
radius: 12.5,
theta: 0.72,
phi: 0.98
};
const pointerState = {
active: false,
pointerId: null,
button: 0,
x: 0,
y: 0
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function setView(name) {
if (name === "top") {
cameraState.theta = 0;
cameraState.phi = 0.12;
cameraState.radius = 11.4;
cameraState.target.set(0, 0.4, 0);
} else if (name === "front") {
cameraState.theta = 0;
cameraState.phi = 1.22;
cameraState.radius = 11.4;
cameraState.target.set(0, 0.9, 0);
} else {
cameraState.theta = 0.72;
cameraState.phi = 0.98;
cameraState.radius = 12.5;
cameraState.target.set(0, 0.75, 0);
}
updateCamera();
}
function panCamera(dx, dy) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const up = new THREE.Vector3().crossVectors(right, forward).normalize();
const panScale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
cameraState.target.x = clamp(cameraState.target.x, -4, 4);
cameraState.target.y = clamp(cameraState.target.y, -0.2, 3);
cameraState.target.z = clamp(cameraState.target.z, -4, 4);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
pointerState.active = true;
pointerState.pointerId = event.pointerId;
pointerState.button = event.button;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerState.active || event.pointerId !== pointerState.pointerId) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
if (pointerState.button === 0) {
cameraState.theta -= dx * 0.007;
cameraState.phi = clamp(cameraState.phi - dy * 0.006, 0.12, 1.38);
} else {
panCamera(dx, dy);
}
updateCamera();
});
function releasePointer(event) {
if (event.pointerId !== pointerState.pointerId) return;
pointerState.active = false;
pointerState.pointerId = null;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.009,
7.2,
19
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
if (event.key === "ArrowRight") cameraState.theta += 0.08;
if (event.key === "ArrowUp") {
cameraState.phi = clamp(cameraState.phi - 0.06, 0.12, 1.38);
}
if (event.key === "ArrowDown") {
cameraState.phi = clamp(cameraState.phi + 0.06, 0.12, 1.38);
}
if (event.key === "+" || event.key === "=") {
cameraState.radius = clamp(cameraState.radius - 0.6, 7.2, 19);
}
if (event.key === "-" || event.key === "_") {
cameraState.radius = clamp(cameraState.radius + 0.6, 7.2, 19);
}
updateCamera();
});
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
// Occupancy and comparison modes
let currentMode = "unoccupied";
const modeButtons = document.querySelectorAll("[data-mode]");
function setMode(mode) {
currentMode = mode;
occupant.visible = mode !== "unoccupied";
occupiedZone.visible = mode !== "unoccupied";
openZone.visible = mode !== "occupied";
if (mode === "compare") {
openFill.material.opacity = 0.095;
openEdges.material.opacity = 0.42;
} else if (mode === "unoccupied") {
openFill.material.opacity = 0.13;
openEdges.material.opacity = 0.72;
}
modeButtons.forEach(button => {
button.setAttribute("aria-pressed", String(button.dataset.mode === mode));
});
}
modeButtons.forEach(button => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
// Project world-space labels into screen space.
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(label => {
let visible = true;
if (label.element.classList.contains("open")) {
visible = currentMode !== "occupied";
}
if (label.element.classList.contains("occupied")) {
visible = currentMode !== "unoccupied";
}
projected.copy(label.anchor).project(camera);
const inFront = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * width + label.offsetX;
const y = (-projected.y * 0.5 + 0.5) * height + label.offsetY;
visible = visible && inFront && x > -100 && x < width + 100 && y > -50 && y < height + 50;
label.element.style.display = visible ? "flex" : "none";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// Subtle ambient animation, keeping the scene calm and spatial.
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
occupant.position.y = 0.08 + Math.sin(elapsed * 1.5) * 0.008;
occupiedEdges.material.opacity =
currentMode === "compare" ? 0.82 + Math.sin(elapsed * 2.2) * 0.08 : 0.9;
updateCamera();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
setMode("unoccupied");
updateCamera();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
});
</script>
</body>
</html>
```