Prompt specification
Build or customize the Three.js 3D scene "Elevator Cabin With Occupancy Footprints" 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: Elevator Cabin With Occupancy Footprints
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/elevator-cabin-with-occupancy-footprints-x2093
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Model a transparent elevator cabin with several floor footprint markers and a doorway. Show capacity geometrically under stated schematic dimensions rather than a certified person limit.
Working Three.js Starter (elevator-cabin-with-occupancy-footprints-x2093):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Elevator — Geometric Capacity Study</title>
<style>
:root {
color-scheme: dark;
--cyan: #55e5ff;
--green: #65f0ae;
--amber: #ffd166;
--ink: #07131f;
--panel: rgba(8, 20, 32, 0.82);
--line: rgba(111, 226, 255, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 25%, #173248 0%, #091722 46%, #050b12 100%);
color: #eaf8ff;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: min(470px, calc(100vw - 52px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-left: 3px solid var(--cyan);
background: linear-gradient(135deg, rgba(8, 22, 35, 0.92), rgba(8, 22, 35, 0.56));
box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
background: var(--green);
box-shadow: 0 0 12px var(--green);
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.04;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: #a7becd;
font-size: 12px;
line-height: 1.5;
}
.status {
position: absolute;
top: 24px;
right: 26px;
display: grid;
grid-template-columns: auto auto;
gap: 4px 14px;
align-items: center;
padding: 12px 15px;
border: 1px solid rgba(101, 240, 174, 0.35);
background: rgba(5, 18, 27, 0.75);
color: #bfd0da;
font: 600 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.status strong {
color: var(--green);
text-align: right;
}
.status .door-state {
color: var(--amber);
}
.readout {
position: absolute;
left: 26px;
bottom: 26px;
width: min(530px, calc(100vw - 52px));
padding: 17px 18px;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
.readout-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 18px;
margin-bottom: 13px;
}
.readout h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.big-number {
color: var(--green);
font: 800 26px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.big-number small {
color: #a8c0cd;
font-size: 10px;
font-weight: 600;
letter-spacing: 0.08em;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 11px;
}
.metric {
min-width: 0;
padding: 9px 10px;
border: 1px solid rgba(126, 203, 231, 0.15);
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
color: #829baa;
font: 600 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric b {
display: block;
margin-top: 4px;
color: #edfaff;
font: 700 13px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.formula {
margin: 0;
color: #b6cad5;
font: 500 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.formula strong {
color: var(--cyan);
}
.warning {
margin: 10px 0 0;
padding-top: 10px;
border-top: 1px solid rgba(255, 209, 102, 0.24);
color: #dfcba1;
font-size: 10px;
line-height: 1.5;
}
.warning strong {
color: var(--amber);
}
.tools {
position: absolute;
right: 26px;
bottom: 26px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.button-row {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
}
button {
min-height: 36px;
padding: 0 12px;
border: 1px solid rgba(85, 229, 255, 0.3);
border-radius: 0;
background: rgba(8, 23, 35, 0.88);
color: #d9f7ff;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
}
button:hover,
button:focus-visible {
border-color: var(--cyan);
background: rgba(19, 53, 70, 0.92);
outline: none;
}
button.active {
border-color: rgba(101, 240, 174, 0.7);
color: var(--green);
}
.hint {
color: #78909f;
font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
padding: 13px 14px;
}
.subtitle {
display: none;
}
.status {
top: 14px;
right: 14px;
padding: 9px 10px;
font-size: 8px;
}
.readout {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 13px;
}
.metrics {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.metric {
padding: 7px;
}
.metric b {
font-size: 11px;
}
.tools {
right: 14px;
bottom: 245px;
}
.button-row {
max-width: 290px;
}
.hint {
display: none;
}
}
@media (max-width: 480px) {
.status {
display: none;
}
.brand {
max-width: calc(100vw - 28px);
}
h1 {
font-size: 22px;
}
.readout-head {
align-items: center;
}
.readout h2 {
font-size: 10px;
}
.big-number {
font-size: 21px;
}
.formula,
.warning {
font-size: 9px;
}
.tools {
bottom: 254px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="hud">
<section class="brand">
<div class="eyebrow">Voxel schematic / study 03</div>
<h1>Transparent Elevator</h1>
<p class="subtitle">
A dimensioned cabin study with twelve illuminated floor-footprint cells.
Drag to orbit, scroll or pinch to zoom.
</p>
</section>
<aside class="status">
<span>Geometry</span><strong>Validated</strong>
<span>Doorway</span><strong class="door-state" id="doorStatus">Open</strong>
</aside>
<section class="readout">
<div class="readout-head">
<h2>Geometric floor-cell readout</h2>
<div class="big-number">12 <small>cells</small></div>
</div>
<div class="metrics">
<div class="metric">
<span>Clear floor</span>
<b>2.20 × 1.60 m</b>
</div>
<div class="metric">
<span>Cell pitch</span>
<b>0.50 × 0.50 m</b>
</div>
<div class="metric">
<span>Door opening</span>
<b>1.00 m</b>
</div>
</div>
<p class="formula">
Floor area <strong>3.52 m²</strong> ÷ cell area
<strong>0.25 m²</strong> = <strong>14.08</strong> by raw area;
regular layout fits <strong>4 × 3 = 12</strong> complete cells.
</p>
<p class="warning">
<strong>Schematic geometry only — not a certified person limit.</strong>
The count excludes doorway circulation, egress, accessibility, comfort,
occupant behavior, structural loads, ventilation, and local code factors.
</p>
</section>
<nav class="tools" aria-label="Scene controls">
<div class="button-row">
<button id="toggleMarkers" class="active" aria-pressed="true">Footprint cells</button>
<button id="toggleDimensions" class="active" aria-pressed="true">Dimensions</button>
<button id="toggleDoor">Close door</button>
<button id="resetCamera">Reset view</button>
</div>
<div class="hint">Drag: orbit · Wheel / pinch: zoom · R: reset</div>
</nav>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131f);
scene.fog = new THREE.FogExp2(0x07131f, 0.027);
const renderer = new THREE.WebGLRenderer({
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.15;
renderer.domElement.setAttribute("aria-label", "Interactive 3D voxel elevator cabin");
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
let cameraTheta = 0.72;
let cameraPhi = 1.14;
let cameraRadius = 7.15;
let desiredTheta = cameraTheta;
let desiredPhi = cameraPhi;
let desiredRadius = cameraRadius;
const hemisphere = new THREE.HemisphereLight(0xbcecff, 0x16202b, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x35dfff, 16, 9, 2);
cyanLight.position.set(-3.3, 2.8, 2.8);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffbf57, 12, 7, 2);
amberLight.position.set(3.2, 1.2, -2.5);
scene.add(amberLight);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x294253,
metalness: 0.76,
roughness: 0.27
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x102330,
metalness: 0.7,
roughness: 0.38
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x142a36,
metalness: 0.28,
roughness: 0.68
});
const yellowMaterial = new THREE.MeshStandardMaterial({
color: 0xf4bd43,
emissive: 0x6f4300,
emissiveIntensity: 0.35,
metalness: 0.42,
roughness: 0.35
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x75ddff,
metalness: 0,
roughness: 0.08,
transparent: true,
opacity: 0.18,
transmission: 0.12,
thickness: 0.045,
side: THREE.DoubleSide,
depthWrite: false
});
const doorGlassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8be7ff,
metalness: 0,
roughness: 0.06,
transparent: true,
opacity: 0.28,
transmission: 0.1,
thickness: 0.04,
side: THREE.DoubleSide,
depthWrite: false
});
function addBox(parent, width, height, depth, x, y, z, material, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x79e8ff, opacity = 0.45) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
edges.renderOrder = 3;
mesh.add(edges);
return edges;
}
function makeLabel(text, accent = "#55e5ff", worldWidth = 2.1) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(5, 17, 27, 0.88)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = accent;
context.lineWidth = 4;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = accent;
context.fillRect(18, 23, 7, 82);
context.font = "700 31px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#e9f9ff";
context.fillText(text, canvas.width / 2 + 8, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 128 / 640, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeDimensionLine(points, color = 0xffd166) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map(point => new THREE.Vector3(...point))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 12;
return line;
}
// Voxel-tiled ground.
const groundGroup = new THREE.Group();
scene.add(groundGroup);
const tileGeometry = new THREE.BoxGeometry(0.48, 0.08, 0.48);
const tileMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
metalness: 0.12,
roughness: 0.82
});
const tileCount = 21 * 21;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < 21; row++) {
for (let column = 0; column < 21; column++) {
const x = (column - 10) * 0.5;
const z = (row - 10) * 0.5;
const underCabin = Math.abs(x) < 1.3 && Math.abs(z) < 1.1;
dummy.position.set(x, -0.17, z);
dummy.scale.setScalar(underCabin ? 0 : 1);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const variation = 0.5 + 0.5 * Math.sin(column * 1.71 + row * 0.83);
color.setHSL(0.55, 0.28, 0.085 + variation * 0.035);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) {
tiles.instanceColor.needsUpdate = true;
}
groundGroup.add(tiles);
addBox(
groundGroup,
2.95, 0.14, 2.35,
0, -0.205, 0,
darkMetalMaterial
);
addBox(
groundGroup,
2.55, 0.08, 1.95,
0, -0.11, 0,
frameMaterial
);
// Front landing and threshold.
addBox(
groundGroup,
2.35, 0.12, 0.7,
0, -0.12, 1.35,
floorMaterial
);
for (let i = 0; i < 8; i++) {
addBox(
groundGroup,
0.18, 0.025, 0.18,
-0.875 + i * 0.25, -0.045, 1.61,
i % 2 ? yellowMaterial : darkMetalMaterial,
false
);
}
// Main transparent cabin.
const cabin = new THREE.Group();
scene.add(cabin);
// Structural outer dimensions: 2.40 m × 1.80 m × 2.50 m.
// Clear floor dimensions: 2.20 m × 1.60 m.
// Clear height below ceiling: 2.40 m.
addBox(cabin, 2.4, 0.14, 1.8, 0, -0.07, 0, floorMaterial);
addBox(cabin, 2.4, 0.1, 1.8, 0, 2.45, 0, frameMaterial);
const backGlass = addBox(
cabin, 2.2, 2.3, 0.045,
0, 1.15, -0.85,
glassMaterial,
false
);
backGlass.renderOrder = 2;
addEdges(backGlass);
const leftGlass = addBox(
cabin, 0.045, 2.3, 1.6,
-1.15, 1.15, 0,
glassMaterial,
false
);
leftGlass.renderOrder = 2;
addEdges(leftGlass);
const rightGlass = addBox(
cabin, 0.045, 2.3, 1.6,
1.15, 1.15, 0,
glassMaterial,
false
);
rightGlass.renderOrder = 2;
addEdges(rightGlass);
// Front side glazing leaves a 1.00 m central doorway.
const frontLeftGlass = addBox(
cabin, 0.6, 2.3, 0.045,
-0.8, 1.15, 0.85,
glassMaterial,
false
);
frontLeftGlass.renderOrder = 2;
addEdges(frontLeftGlass);
const frontRightGlass = addBox(
cabin, 0.6, 2.3, 0.045,
0.8, 1.15, 0.85,
glassMaterial,
false
);
frontRightGlass.renderOrder = 2;
addEdges(frontRightGlass);
// Corner posts and perimeter frame.
for (const x of [-1.16, 1.16]) {
for (const z of [-0.86, 0.86]) {
addBox(cabin, 0.08, 2.5, 0.08, x, 1.25, z, frameMaterial);
}
}
for (const z of [-0.86, 0.86]) {
addBox(cabin, 2.4, 0.1, 0.1, 0, 2.45, z, frameMaterial);
addBox(cabin, 2.4, 0.08, 0.1, 0, 0.02, z, frameMaterial);
}
for (const x of [-1.16, 1.16]) {
addBox(cabin, 0.1, 0.1, 1.8, x, 2.45, 0, frameMaterial);
addBox(cabin, 0.08, 0.08, 1.72, x, 0.02, 0, frameMaterial);
}
// Door frame.
addBox(cabin, 0.075, 2.22, 0.1, -0.535, 1.11, 0.9, yellowMaterial);
addBox(cabin, 0.075, 2.22, 0.1, 0.535, 1.11, 0.9, yellowMaterial);
addBox(cabin, 1.145, 0.09, 0.1, 0, 2.2, 0.9, yellowMaterial);
// Sliding transparent door leaves.
const leftDoor = addBox(
cabin, 0.49, 2.13, 0.04,
-0.78, 1.065, 0.92,
doorGlassMaterial,
false
);
addEdges(leftDoor, 0xb8f3ff, 0.72);
leftDoor.renderOrder = 4;
const rightDoor = addBox(
cabin, 0.49, 2.13, 0.04,
0.78, 1.065, 0.92,
doorGlassMaterial,
false
);
addEdges(rightDoor, 0xb8f3ff, 0.72);
rightDoor.renderOrder = 4;
// Safety threshold.
for (let i = 0; i < 5; i++) {
addBox(
cabin,
0.16, 0.025, 0.11,
-0.4 + i * 0.2, 0.025, 0.83,
i % 2 ? yellowMaterial : darkMetalMaterial,
false
);
}
// Interior control panel.
addBox(cabin, 0.09, 0.55, 0.26, 1.055, 1.25, 0.48, darkMetalMaterial);
const buttonMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xffa500,
emissiveIntensity: 0.8,
metalness: 0.15,
roughness: 0.35
});
for (let i = 0; i < 3; i++) {
addBox(
cabin,
0.025, 0.075, 0.075,
1.108, 1.42 - i * 0.14, 0.48,
buttonMaterial,
false
);
}
// Overhead indicator housing.
addBox(cabin, 0.62, 0.19, 0.12, 0, 2.61, 0.91, darkMetalMaterial);
const indicator = makeLabel("▲ 03", "#65f0ae", 0.52);
indicator.position.set(0, 2.61, 0.985);
cabin.add(indicator);
// Twelve 0.50 m × 0.50 m floor-footprint cells: 4 columns × 3 rows.
const markerGroup = new THREE.Group();
cabin.add(markerGroup);
const markerGeometry = new THREE.BoxGeometry(0.43, 0.018, 0.43);
const markerEdgeGeometry = new THREE.EdgesGeometry(markerGeometry);
const markerMaterials = [
new THREE.MeshStandardMaterial({
color: 0x4fe2a0,
emissive: 0x0d6f49,
emissiveIntensity: 0.4,
metalness: 0.05,
roughness: 0.55,
transparent: true,
opacity: 0.32,
depthWrite: false
}),
new THREE.MeshStandardMaterial({
color: 0x4edfff,
emissive: 0x08677a,
emissiveIntensity: 0.36,
metalness: 0.05,
roughness: 0.55,
transparent: true,
opacity: 0.28,
depthWrite: false
})
];
const markerEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x8affd0,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const centerMarkerMaterial = new THREE.MeshBasicMaterial({
color: 0xa7ffda,
transparent: true,
opacity: 0.9
});
const markerCenters = [];
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 4; column++) {
const x = (column - 1.5) * 0.5;
const z = (row - 1) * 0.5;
markerCenters.push(new THREE.Vector3(x, 0.035, z));
const plate = new THREE.Mesh(
markerGeometry,
markerMaterials[(row + column) % markerMaterials.length]
);
plate.position.set(x, 0.035, z);
plate.renderOrder = 6;
markerGroup.add(plate);
const outline = new THREE.LineSegments(
markerEdgeGeometry,
markerEdgeMaterial
);
outline.renderOrder = 7;
plate.add(outline);
const center = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.022, 0.075),
centerMarkerMaterial
);
center.position.y = 0.012;
center.renderOrder = 8;
plate.add(center);
}
}
// Floating geometric result label.
const resultLabel = makeLabel("12 / SCHEMATIC FLOOR CELLS", "#65f0ae", 2.75);
resultLabel.position.set(0, 3.08, 0);
cabin.add(resultLabel);
addBox(cabin, 0.025, 0.42, 0.025, 0, 2.8, 0, frameMaterial);
// Dimension group.
const dimensionGroup = new THREE.Group();
scene.add(dimensionGroup);
// Clear width.
dimensionGroup.add(makeDimensionLine([
[-1.1, 0.055, 1.22],
[1.1, 0.055, 1.22]
]));
dimensionGroup.add(makeDimensionLine([
[-1.1, 0.055, 1.12],
[-1.1, 0.055, 1.32]
]));
dimensionGroup.add(makeDimensionLine([
[1.1, 0.055, 1.12],
[1.1, 0.055, 1.32]
]));
const widthLabel = makeLabel("2.20 m CLEAR WIDTH", "#ffd166", 1.85);
widthLabel.position.set(0, 0.19, 1.27);
dimensionGroup.add(widthLabel);
// Clear depth.
dimensionGroup.add(makeDimensionLine([
[1.4, 0.055, -0.8],
[1.4, 0.055, 0.8]
]));
dimensionGroup.add(makeDimensionLine([
[1.3, 0.055, -0.8],
[1.5, 0.055, -0.8]
]));
dimensionGroup.add(makeDimensionLine([
[1.3, 0.055, 0.8],
[1.5, 0.055, 0.8]
]));
const depthLabel = makeLabel("1.60 m CLEAR DEPTH", "#ffd166", 1.85);
depthLabel.position.set(1.58, 0.19, 0);
dimensionGroup.add(depthLabel);
// Clear height.
dimensionGroup.add(makeDimensionLine([
[-1.4, 0, -0.85],
[-1.4, 2.4, -0.85]
]));
dimensionGroup.add(makeDimensionLine([
[-1.5, 0, -0.85],
[-1.3, 0, -0.85]
]));
dimensionGroup.add(makeDimensionLine([
[-1.5, 2.4, -0.85],
[-1.3, 2.4, -0.85]
]));
const heightLabel = makeLabel("2.40 m CLEAR HEIGHT", "#ffd166", 1.95);
heightLabel.position.set(-1.58, 1.22, -0.83);
dimensionGroup.add(heightLabel);
// Door opening.
dimensionGroup.add(makeDimensionLine([
[-0.5, 2.16, 1.06],
[0.5, 2.16, 1.06]
]));
dimensionGroup.add(makeDimensionLine([
[-0.5, 2.08, 1.06],
[-0.5, 2.24, 1.06]
]));
dimensionGroup.add(makeDimensionLine([
[0.5, 2.08, 1.06],
[0.5, 2.24, 1.06]
]));
const doorLabel = makeLabel("1.00 m DOOR", "#ffd166", 1.45);
doorLabel.position.set(0, 2.35, 1.11);
dimensionGroup.add(doorLabel);
// Cell pitch.
dimensionGroup.add(makeDimensionLine([
[-0.75, 0.065, -0.24],
[-0.25, 0.065, -0.24]
]));
dimensionGroup.add(makeDimensionLine([
[-0.75, 0.065, -0.32],
[-0.75, 0.065, -0.16]
]));
dimensionGroup.add(makeDimensionLine([
[-0.25, 0.065, -0.32],
[-0.25, 0.065, -0.16]
]));
const cellLabel = makeLabel("0.50 m CELL PITCH", "#55e5ff", 1.65);
cellLabel.position.set(0.9, 0.2, -0.65);
dimensionGroup.add(cellLabel);
// Controls.
const toggleMarkersButton = document.getElementById("toggleMarkers");
const toggleDimensionsButton = document.getElementById("toggleDimensions");
const toggleDoorButton = document.getElementById("toggleDoor");
const resetCameraButton = document.getElementById("resetCamera");
const doorStatus = document.getElementById("doorStatus");
let doorOpen = true;
let doorAmount = 1;
toggleMarkersButton.addEventListener("click", () => {
markerGroup.visible = !markerGroup.visible;
toggleMarkersButton.classList.toggle("active", markerGroup.visible);
toggleMarkersButton.setAttribute("aria-pressed", String(markerGroup.visible));
});
toggleDimensionsButton.addEventListener("click", () => {
dimensionGroup.visible = !dimensionGroup.visible;
toggleDimensionsButton.classList.toggle("active", dimensionGroup.visible);
toggleDimensionsButton.setAttribute("aria-pressed", String(dimensionGroup.visible));
});
function setDoor(open) {
doorOpen = open;
toggleDoorButton.textContent = doorOpen ? "Close door" : "Open door";
doorStatus.textContent = doorOpen ? "Open" : "Closed";
}
toggleDoorButton.addEventListener("click", () => {
setDoor(!doorOpen);
});
function resetCamera() {
desiredTheta = 0.72;
desiredPhi = 1.14;
desiredRadius = 7.15;
}
resetCameraButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// Direct camera controls: orbit with drag, zoom with wheel or pinch.
const pointers = new Map();
let previousPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
desiredTheta -= deltaX * 0.006;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - deltaY * 0.005,
0.32,
1.48
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * previousPinchDistance / distance,
4.4,
12
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
4.4,
12
);
}, { passive: false });
function updateCamera() {
cameraTheta = THREE.MathUtils.lerp(cameraTheta, desiredTheta, 0.12);
cameraPhi = THREE.MathUtils.lerp(cameraPhi, desiredPhi, 0.12);
cameraRadius = THREE.MathUtils.lerp(cameraRadius, desiredRadius, 0.12);
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera();
doorAmount = THREE.MathUtils.lerp(
doorAmount,
doorOpen ? 1 : 0,
1 - Math.pow(0.001, delta)
);
leftDoor.position.x = -0.25 - doorAmount * 0.53;
rightDoor.position.x = 0.25 + doorAmount * 0.53;
const pulse = 0.5 + 0.5 * Math.sin(elapsed * 2.1);
markerMaterials[0].opacity = 0.25 + pulse * 0.1;
markerMaterials[1].opacity = 0.23 + (1 - pulse) * 0.1;
markerMaterials[0].emissiveIntensity = 0.28 + pulse * 0.28;
markerMaterials[1].emissiveIntensity = 0.25 + (1 - pulse) * 0.25;
buttonMaterial.emissiveIntensity = 0.65 + pulse * 0.35;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```