Prompt specification
Build or customize the Three.js 3D scene "Column bay with a measured grid" 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: Column bay with a measured grid
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/column-bay-with-a-measured-grid-x2205
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: column bay with a measured grid. Build one rectangular structural bay with four columns and a roof panel. Show grid spacing and align column centers precisely to the marked modular intersections. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (column-bay-with-a-measured-grid-x2205):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Measured Structural Bay</title>
<style>
:root {
color-scheme: light;
--ink: #24312e;
--muted: #64736e;
--paper: rgba(249, 249, 244, 0.88);
--line: rgba(48, 65, 60, 0.16);
--accent: #e56f45;
--accent-soft: rgba(229, 111, 69, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eee8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(42, 57, 52, 0.1);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 3vw, 29px);
font-weight: 720;
letter-spacing: -0.035em;
line-height: 1.08;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.specs {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.chip {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.52);
color: #42514c;
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
.chip strong {
color: var(--ink);
}
.readout {
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
min-height: 76px;
padding: 14px 16px;
pointer-events: none;
}
.readout-label {
margin-bottom: 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#readout-text {
margin: 0;
color: #44534e;
font-size: 13px;
line-height: 1.45;
}
#readout-text strong {
color: var(--ink);
}
.controls {
right: 22px;
bottom: 22px;
padding: 10px;
}
.button-row {
display: flex;
gap: 7px;
}
button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.68);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 140ms ease;
}
button:hover {
border-color: rgba(229, 111, 69, 0.48);
background: #fff;
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
button[aria-pressed="false"] {
color: var(--muted);
background: transparent;
}
.hint {
margin: 9px 3px 1px;
color: var(--muted);
font-size: 10px;
text-align: right;
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.specs {
margin-top: 10px;
}
.readout {
left: 12px;
bottom: 70px;
width: calc(100vw - 24px);
min-height: auto;
padding: 11px 13px;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive Three.js structural column bay"></div>
<section class="panel title-panel">
<div class="eyebrow">Measured Modular Study</div>
<h1>Rectangular Structural Bay</h1>
<p class="subtitle">
Four columns are centered exactly on the highlighted corner grid
intersections. The roof panel spans the complete measured bay.
</p>
<div class="specs">
<span class="chip"><strong>1.50 × 1.50 m</strong> module</span>
<span class="chip"><strong>3 × 2</strong> modules</span>
<span class="chip"><strong>4.50 × 3.00 m</strong> bay</span>
<span class="chip"><strong>3.20 m</strong> height</span>
</div>
</section>
<section class="panel readout" aria-live="polite">
<div class="readout-label">Alignment Inspector</div>
<p id="readout-text">
Hover a column to inspect its exact grid intersection and center coordinate.
</p>
</section>
<nav class="panel controls" aria-label="Scene controls">
<div class="button-row">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-grid" type="button" aria-pressed="true">Hide grid</button>
<button id="toggle-roof" type="button" aria-pressed="true">Hide roof</button>
</div>
<div class="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.querySelector("#scene");
const readout = document.querySelector("#readout-text");
// ------------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Orbitable structural bay. Drag to rotate and use the mouse wheel to zoom."
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee8);
scene.fog = new THREE.Fog(0xe9eee8, 12, 25);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(
0xf8fbf7,
0x83928b,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.25);
sun.position.set(5.5, 9, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 22;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d8df, 1.05);
fill.position.set(-6, 4, -5);
scene.add(fill);
// ------------------------------------------------------------------
// Shared measured-grid constants
//
// Every column, grid intersection, dimension, and roof dimension is
// derived from these values. No decorative offset is introduced.
// ------------------------------------------------------------------
const MODULES_X = 3;
const MODULES_Z = 2;
const MODULE_X = 1.5;
const MODULE_Z = 1.5;
const BAY_WIDTH = MODULES_X * MODULE_X;
const BAY_DEPTH = MODULES_Z * MODULE_Z;
const COLUMN_HEIGHT = 3.2;
const ROOF_THICKNESS = 0.22;
const gridX = (i) => (i - MODULES_X / 2) * MODULE_X;
const gridZ = (j) => (j - MODULES_Z / 2) * MODULE_Z;
const axisLetter = (j) => String.fromCharCode(65 + j);
// ------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xdfe5de,
roughness: 0.96,
metalness: 0
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0xf7f3e9,
roughness: 0.72,
metalness: 0.02
});
const columnMaterial = new THREE.MeshStandardMaterial({
color: 0xeee9df,
roughness: 0.78,
metalness: 0.015
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0xd7d2c7,
roughness: 0.82
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x596963,
transparent: true,
opacity: 0.48
});
const gridMaterial = new THREE.LineBasicMaterial({
color: 0x71827b,
transparent: true,
opacity: 0.55
});
const borderGridMaterial = new THREE.LineBasicMaterial({
color: 0x42554e,
transparent: true,
opacity: 0.72
});
const accentMaterial = new THREE.LineBasicMaterial({
color: 0xe56f45,
transparent: true,
opacity: 0.95
});
const intersectionMaterial = new THREE.MeshBasicMaterial({
color: 0x60736b,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide
});
const cornerMaterial = new THREE.MeshBasicMaterial({
color: 0xe56f45,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide
});
// ------------------------------------------------------------------
// Ground
// ------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(18, 14),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
// A subtle plinth under the bay makes the measured rectangle legible.
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(BAY_WIDTH + 0.18, 0.06, BAY_DEPTH + 0.18),
new THREE.MeshStandardMaterial({
color: 0xd4dcd5,
roughness: 0.92
})
);
plinth.position.y = -0.045;
plinth.receiveShadow = true;
scene.add(plinth);
// ------------------------------------------------------------------
// Measured grid and marked intersections
// ------------------------------------------------------------------
const gridGroup = new THREE.Group();
gridGroup.name = "Measured grid";
scene.add(gridGroup);
function addLine(group, points, material) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
group.add(line);
return line;
}
for (let i = 0; i <= MODULES_X; i++) {
const x = gridX(i);
const material =
i === 0 || i === MODULES_X
? borderGridMaterial
: gridMaterial;
addLine(
gridGroup,
[
new THREE.Vector3(x, 0.012, gridZ(0)),
new THREE.Vector3(x, 0.012, gridZ(MODULES_Z))
],
material
);
}
for (let j = 0; j <= MODULES_Z; j++) {
const z = gridZ(j);
const material =
j === 0 || j === MODULES_Z
? borderGridMaterial
: gridMaterial;
addLine(
gridGroup,
[
new THREE.Vector3(gridX(0), 0.012, z),
new THREE.Vector3(gridX(MODULES_X), 0.012, z)
],
material
);
}
const intersectionGeometry = new THREE.CircleGeometry(0.045, 24);
const cornerRingGeometry = new THREE.RingGeometry(0.265, 0.302, 64);
for (let i = 0; i <= MODULES_X; i++) {
for (let j = 0; j <= MODULES_Z; j++) {
const isCorner =
(i === 0 || i === MODULES_X) &&
(j === 0 || j === MODULES_Z);
if (isCorner) {
// The larger ring remains visible around the column footprint and
// explicitly marks the exact center of each structural column.
const ring = new THREE.Mesh(
cornerRingGeometry,
cornerMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(gridX(i), 0.018, gridZ(j));
gridGroup.add(ring);
addLine(
gridGroup,
[
new THREE.Vector3(
gridX(i) - 0.36,
0.021,
gridZ(j)
),
new THREE.Vector3(
gridX(i) + 0.36,
0.021,
gridZ(j)
)
],
accentMaterial
);
addLine(
gridGroup,
[
new THREE.Vector3(
gridX(i),
0.021,
gridZ(j) - 0.36
),
new THREE.Vector3(
gridX(i),
0.021,
gridZ(j) + 0.36
)
],
accentMaterial
);
} else {
const marker = new THREE.Mesh(
intersectionGeometry,
intersectionMaterial
);
marker.rotation.x = -Math.PI / 2;
marker.position.set(gridX(i), 0.018, gridZ(j));
gridGroup.add(marker);
}
}
}
// ------------------------------------------------------------------
// Canvas-texture labels: no examples/addons are used
// ------------------------------------------------------------------
function roundedRectPath(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function makeTextSprite(
text,
{
worldWidth = 1.1,
worldHeight = 0.28,
foreground = "#2f3d38",
background = "rgba(248,249,244,0.92)",
border = "rgba(48,65,60,0.18)",
fontSize = 76
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
let size = fontSize;
let font = `700 ${size}px Inter, Arial, sans-serif`;
ctx.font = font;
while (
ctx.measureText(text).width > 880 &&
size > 34
) {
size -= 2;
font = `700 ${size}px Inter, Arial, sans-serif`;
ctx.font = font;
}
const metrics = ctx.measureText(text);
const textWidth = metrics.width;
const paddingX = 44;
const pillWidth = Math.min(960, textWidth + paddingX * 2);
const pillHeight = 142;
const x = (canvas.width - pillWidth) / 2;
const y = (canvas.height - pillHeight) / 2;
roundedRectPath(ctx, x, y, pillWidth, pillHeight, 48);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 4;
ctx.stroke();
ctx.font = font;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = 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, worldHeight, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeAxisBadge(text, position) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 256);
ctx.beginPath();
ctx.arc(128, 128, 100, 0, Math.PI * 2);
ctx.fillStyle = "rgba(249,249,244,0.95)";
ctx.fill();
ctx.strokeStyle = "rgba(48,65,60,0.25)";
ctx.lineWidth = 7;
ctx.stroke();
ctx.fillStyle = "#2d3b36";
ctx.font = "800 96px Inter, Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 132);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.copy(position);
sprite.scale.set(0.34, 0.34, 1);
sprite.renderOrder = 21;
return sprite;
}
// ------------------------------------------------------------------
// Dimension lines and module labels
// ------------------------------------------------------------------
const dimensionGroup = new THREE.Group();
gridGroup.add(dimensionGroup);
const moduleDimensionZ = BAY_DEPTH / 2 + 0.72;
const overallDimensionZ = BAY_DEPTH / 2 + 1.28;
const moduleDimensionX = BAY_WIDTH / 2 + 0.72;
const overallDimensionX = BAY_WIDTH / 2 + 1.28;
// Horizontal module dimensions.
for (let i = 0; i < MODULES_X; i++) {
const x1 = gridX(i);
const x2 = gridX(i + 1);
const z = moduleDimensionZ;
addLine(
dimensionGroup,
[
new THREE.Vector3(x1, 0.026, z),
new THREE.Vector3(x2, 0.026, z)
],
accentMaterial
);
for (const x of [x1, x2]) {
addLine(
dimensionGroup,
[
new THREE.Vector3(x, 0.026, z - 0.10),
new THREE.Vector3(x, 0.026, z + 0.10)
],
accentMaterial
);
addLine(
dimensionGroup,
[
new THREE.Vector3(x, 0.020, BAY_DEPTH / 2),
new THREE.Vector3(x, 0.020, z + 0.13)
],
accentMaterial
);
}
const label = makeTextSprite(`${MODULE_X.toFixed(2)} m`, {
worldWidth: 1.08,
worldHeight: 0.27,
foreground: "#b55434"
});
label.position.set((x1 + x2) / 2, 0.09, z + 0.17);
dimensionGroup.add(label);
}
// Depth module dimensions.
for (let j = 0; j < MODULES_Z; j++) {
const z1 = gridZ(j);
const z2 = gridZ(j + 1);
const x = moduleDimensionX;
addLine(
dimensionGroup,
[
new THREE.Vector3(x, 0.026, z1),
new THREE.Vector3(x, 0.026, z2)
],
accentMaterial
);
for (const z of [z1, z2]) {
addLine(
dimensionGroup,
[
new THREE.Vector3(x - 0.10, 0.026, z),
new THREE.Vector3(x + 0.10, 0.026, z)
],
accentMaterial
);
addLine(
dimensionGroup,
[
new THREE.Vector3(BAY_WIDTH / 2, 0.020, z),
new THREE.Vector3(x + 0.13, 0.020, z)
],
accentMaterial
);
}
const label = makeTextSprite(`${MODULE_Z.toFixed(2)} m`, {
worldWidth: 1.08,
worldHeight: 0.27,
foreground: "#b55434"
});
label.position.set(x + 0.17, 0.09, (z1 + z2) / 2);
dimensionGroup.add(label);
}
// Overall width.
addLine(
dimensionGroup,
[
new THREE.Vector3(gridX(0), 0.028, overallDimensionZ),
new THREE.Vector3(gridX(MODULES_X), 0.028, overallDimensionZ)
],
accentMaterial
);
for (const x of [gridX(0), gridX(MODULES_X)]) {
addLine(
dimensionGroup,
[
new THREE.Vector3(x, 0.028, overallDimensionZ - 0.13),
new THREE.Vector3(x, 0.028, overallDimensionZ + 0.13)
],
accentMaterial
);
}
const widthLabel = makeTextSprite(
`${BAY_WIDTH.toFixed(2)} m OVERALL`,
{
worldWidth: 1.95,
worldHeight: 0.31,
foreground: "#b55434"
}
);
widthLabel.position.set(0, 0.095, overallDimensionZ + 0.18);
dimensionGroup.add(widthLabel);
// Overall depth.
addLine(
dimensionGroup,
[
new THREE.Vector3(overallDimensionX, 0.028, gridZ(0)),
new THREE.Vector3(overallDimensionX, 0.028, gridZ(MODULES_Z))
],
accentMaterial
);
for (const z of [gridZ(0), gridZ(MODULES_Z)]) {
addLine(
dimensionGroup,
[
new THREE.Vector3(overallDimensionX - 0.13, 0.028, z),
new THREE.Vector3(overallDimensionX + 0.13, 0.028, z)
],
accentMaterial
);
}
const depthLabel = makeTextSprite(
`${BAY_DEPTH.toFixed(2)} m OVERALL`,
{
worldWidth: 2.12,
worldHeight: 0.31,
foreground: "#b55434"
}
);
depthLabel.position.set(
overallDimensionX + 0.18,
0.095,
0
);
dimensionGroup.add(depthLabel);
// Architectural grid bubbles.
for (let i = 0; i <= MODULES_X; i++) {
const badge = makeAxisBadge(
String(i + 1),
new THREE.Vector3(
gridX(i),
0.075,
BAY_DEPTH / 2 + 0.24
)
);
gridGroup.add(badge);
}
for (let j = 0; j <= MODULES_Z; j++) {
const badge = makeAxisBadge(
axisLetter(j),
new THREE.Vector3(
BAY_WIDTH / 2 + 0.24,
0.075,
gridZ(j)
)
);
gridGroup.add(badge);
}
// ------------------------------------------------------------------
// Four columns, positioned only from exact grid intersection values
// ------------------------------------------------------------------
const columnGroup = new THREE.Group();
columnGroup.name = "Four structural columns";
scene.add(columnGroup);
const columnRecords = [];
const columnMeshes = [];
const cornerDefinitions = [
{ i: 0, j: 0, number: 1 },
{ i: MODULES_X, j: 0, number: 2 },
{ i: MODULES_X, j: MODULES_Z, number: 3 },
{ i: 0, j: MODULES_Z, number: 4 }
];
const columnGeometry = new THREE.BoxGeometry(
0.30,
COLUMN_HEIGHT,
0.30
);
for (const definition of cornerDefinitions) {
const x = gridX(definition.i);
const z = gridZ(definition.j);
const group = new THREE.Group();
group.position.set(x, 0, z);
const material = columnMaterial.clone();
const mesh = new THREE.Mesh(columnGeometry, material);
mesh.position.y = COLUMN_HEIGHT / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
const edgeMaterialForColumn = edgeMaterial.clone();
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(columnGeometry),
edgeMaterialForColumn
);
edges.position.copy(mesh.position);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.08, 0.38),
trimMaterial
);
foot.position.y = 0.04;
foot.castShadow = true;
foot.receiveShadow = true;
const capital = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.09, 0.38),
trimMaterial
);
capital.position.y = COLUMN_HEIGHT - 0.045;
capital.castShadow = true;
capital.receiveShadow = true;
group.add(mesh, edges, foot, capital);
columnGroup.add(group);
const record = {
mesh,
material,
edgeMaterial: edgeMaterialForColumn,
number: definition.number,
gridIndex: `${definition.i + 1} / ${axisLetter(definition.j)}`,
x,
z
};
mesh.userData.columnRecord = record;
columnRecords.push(record);
columnMeshes.push(mesh);
}
// ------------------------------------------------------------------
// Single roof panel, sized directly from the measured bay
// ------------------------------------------------------------------
const roofGroup = new THREE.Group();
roofGroup.name = "Roof panel";
scene.add(roofGroup);
const roofGeometry = new THREE.BoxGeometry(
BAY_WIDTH,
ROOF_THICKNESS,
BAY_DEPTH
);
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.y = COLUMN_HEIGHT + ROOF_THICKNESS / 2;
roof.castShadow = true;
roof.receiveShadow = true;
roofGroup.add(roof);
const roofEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(roofGeometry),
new THREE.LineBasicMaterial({
color: 0x5c6b65,
transparent: true,
opacity: 0.58
})
);
roofEdges.position.copy(roof.position);
roofGroup.add(roofEdges);
const roofTopY = COLUMN_HEIGHT + ROOF_THICKNESS + 0.006;
const roofTopBorder = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
-BAY_WIDTH / 2 + 0.12,
roofTopY,
-BAY_DEPTH / 2 + 0.12
),
new THREE.Vector3(
BAY_WIDTH / 2 - 0.12,
roofTopY,
-BAY_DEPTH / 2 + 0.12
),
new THREE.Vector3(
BAY_WIDTH / 2 - 0.12,
roofTopY,
BAY_DEPTH / 2 - 0.12
),
new THREE.Vector3(
-BAY_WIDTH / 2 + 0.12,
roofTopY,
BAY_DEPTH / 2 - 0.12
)
]),
new THREE.LineBasicMaterial({
color: 0xc2b9a9,
transparent: true,
opacity: 0.75
})
);
roofGroup.add(roofTopBorder);
// ------------------------------------------------------------------
// Custom orbit camera — implemented directly, without camera addons
// ------------------------------------------------------------------
const orbit = {
theta: 0.72,
phi: 1.08,
radius: 10.8,
target: new THREE.Vector3(0, 1.22, 0)
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x +
orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y +
orbit.radius * Math.cos(orbit.phi),
orbit.target.z +
orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.72;
orbit.phi = 1.08;
orbit.radius = 10.8;
orbit.target.set(0, 1.22, 0);
applyCamera();
}
function zoomBy(factor) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * factor,
5.8,
18
);
applyCamera();
}
const canvas = renderer.domElement;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let moved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let hoveredColumn = null;
function setHoveredColumn(record) {
if (hoveredColumn === record) return;
if (hoveredColumn) {
hoveredColumn.material.emissive.set(0x000000);
hoveredColumn.material.emissiveIntensity = 0;
hoveredColumn.edgeMaterial.color.set(0x596963);
hoveredColumn.edgeMaterial.opacity = 0.48;
}
hoveredColumn = record;
if (hoveredColumn) {
hoveredColumn.material.emissive.set(0xe56f45);
hoveredColumn.material.emissiveIntensity = 0.16;
hoveredColumn.edgeMaterial.color.set(0xe56f45);
hoveredColumn.edgeMaterial.opacity = 0.95;
readout.innerHTML =
`<strong>Column ${String(hoveredColumn.number).padStart(2, "0")}</strong>` +
` · Grid intersection <strong>${hoveredColumn.gridIndex}</strong><br>` +
`Center: X = <strong>${hoveredColumn.x.toFixed(2)} m</strong>, ` +
`Z = <strong>${hoveredColumn.z.toFixed(2)} m</strong> · ` +
`Locked to the marked modular intersection.`;
} else {
readout.innerHTML =
"Hover a column to inspect its exact grid intersection and center coordinate.";
}
}
function inspectPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(columnMeshes, false);
setHoveredColumn(hits.length ? hits[0].object.userData.columnRecord : null);
}
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
moved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) {
inspectPointer(event);
return;
}
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
moved = true;
}
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.32,
1.43
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
applyCamera();
});
function endPointer(event) {
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", () => {
if (!pointerDown) setHoveredColumn(null);
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomBy(Math.exp(event.deltaY * 0.001));
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta += 0.09;
break;
case "ArrowRight":
orbit.theta -= 0.09;
break;
case "ArrowUp":
orbit.phi = Math.max(0.32, orbit.phi - 0.07);
break;
case "ArrowDown":
orbit.phi = Math.min(1.43, orbit.phi + 0.07);
break;
case "+":
case "=":
zoomBy(0.88);
break;
case "-":
case "_":
zoomBy(1.12);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
applyCamera();
}
});
// ------------------------------------------------------------------
// UI controls
// ------------------------------------------------------------------
const resetButton = document.querySelector("#reset-view");
const gridButton = document.querySelector("#toggle-grid");
const roofButton = document.querySelector("#toggle-roof");
resetButton.addEventListener("click", resetCamera);
gridButton.addEventListener("click", () => {
const visible = !gridGroup.visible;
gridGroup.visible = visible;
gridButton.textContent = visible ? "Hide grid" : "Show grid";
gridButton.setAttribute("aria-pressed", String(visible));
});
roofButton.addEventListener("click", () => {
const visible = !roofGroup.visible;
roofGroup.visible = visible;
roofButton.textContent = visible ? "Hide roof" : "Show roof";
roofButton.setAttribute("aria-pressed", String(visible));
});
// ------------------------------------------------------------------
// Resize and render
// ------------------------------------------------------------------
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);
applyCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```