Prompt specification
Build or customize the Three.js 3D scene "Wall corner with interlocking courses" 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: Wall corner with interlocking courses
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wall-corner-with-interlocking-courses-x2174
Scene Description Prompt:
Wall corner with interlocking courses. Model a low masonry corner with alternating brick overlaps. Lift one course slightly to reveal how units connect the two perpendicular wall directions. Please build this with Three.js from cdnjs in one self-contained HTML file, using a 3D cutaway.
Working Three.js Starter (wall-corner-with-interlocking-courses-x2174):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Interlocking Masonry Corner</title>
<style>
:root {
--ink: #252927;
--muted: #68706c;
--paper: #ece9e2;
--panel: rgba(248, 247, 242, 0.88);
--line: rgba(37, 41, 39, 0.16);
--brick: #a95742;
--cyan: #168f9d;
--orange: #d77a38;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-block {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
width: min(410px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
background: var(--orange);
content: "";
}
h1 {
max-width: 380px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 54px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.subtitle {
max-width: 355px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.control-panel {
position: fixed;
z-index: 8;
top: 26px;
right: 26px;
width: 240px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 15px 40px rgba(48, 43, 36, 0.09);
backdrop-filter: blur(14px);
}
.panel-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#lift-value {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0 0 14px;
accent-color: var(--cyan);
cursor: ew-resize;
}
.button-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
button {
min-height: 34px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(22, 143, 157, 0.48);
background: #fff;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.legend {
position: fixed;
z-index: 6;
left: 30px;
bottom: 28px;
display: grid;
gap: 9px;
padding: 13px 15px;
border-left: 2px solid var(--orange);
background: rgba(248, 247, 242, 0.74);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #505753;
font-size: 11px;
line-height: 1.2;
}
.swatch {
width: 18px;
height: 7px;
border-radius: 2px;
background: var(--brick);
}
.swatch.active {
background: transparent;
border: 2px solid var(--cyan);
}
.swatch.section {
width: 8px;
height: 18px;
background: var(--orange);
}
.help {
position: fixed;
z-index: 5;
right: 28px;
bottom: 24px;
color: rgba(37, 41, 39, 0.62);
font-size: 11px;
letter-spacing: 0.02em;
pointer-events: none;
}
.tag {
position: fixed;
z-index: 4;
left: 0;
top: 0;
padding: 8px 10px;
border: 1px solid rgba(37, 41, 39, 0.13);
border-radius: 7px;
background: rgba(249, 248, 243, 0.9);
box-shadow: 0 8px 24px rgba(41, 35, 30, 0.09);
color: var(--ink);
font-size: 10px;
font-weight: 760;
letter-spacing: 0.09em;
line-height: 1.3;
text-align: center;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
}
.tag.primary {
border-color: rgba(22, 143, 157, 0.6);
color: #0b6c76;
}
.tag.primary small {
display: block;
margin-top: 3px;
color: #587074;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.07em;
}
.tag.axis {
padding: 6px 8px;
background: rgba(37, 41, 39, 0.78);
color: white;
box-shadow: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
color: var(--muted);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-block {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.control-panel {
top: auto;
right: 14px;
bottom: 14px;
width: 205px;
}
.legend,
.help,
.axis-tag {
display: none;
}
.tag.primary {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="title-block">
<div class="eyebrow">Masonry study / 04</div>
<h1>Interlocking corner</h1>
<p class="subtitle">
Alternating stretcher and header courses turn ninety degrees at the
corner. The upper course is lifted to expose the continuous bond.
</p>
</header>
<aside class="control-panel" aria-label="Model controls">
<div class="panel-row">
<span>Course lift</span>
<output id="lift-value">0.90</output>
</div>
<input
id="lift"
type="range"
min="0"
max="1.8"
step="0.01"
value="0.9"
aria-label="Lift the upper masonry course"
/>
<div class="button-row">
<button id="iso" type="button">Iso</button>
<button id="section" type="button">Section</button>
<button id="reset" type="button">Reset</button>
</div>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="swatch active"></span>
Alternating corner header
</div>
<div class="legend-item">
<span class="swatch"></span>
Stretcher units
</div>
<div class="legend-item">
<span class="swatch section"></span>
Cutaway section face
</div>
</div>
<div class="help">Drag to orbit · Scroll to zoom · Arrow keys to inspect</div>
<div id="header-tag" class="tag primary">
Bond header
<small>turns 90° each course</small>
</div>
<div id="course-tag" class="tag">Lifted course</div>
<div id="wall-a-tag" class="tag axis">Wall A / X</div>
<div id="wall-b-tag" class="tag axis">Wall B / Z</div>
<div id="loading">Assembling masonry corner…</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.querySelector("#viewport");
const liftSlider = document.querySelector("#lift");
const liftValue = document.querySelector("#lift-value");
const loading = document.querySelector("#loading");
// ---------------------------------------------------------------------
// Scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e6df);
scene.fog = new THREE.Fog(0xe9e6df, 19, 38);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional masonry corner"
);
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf5f3ec, 0x6a655d, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2dd, 3.2);
keyLight.position.set(-4, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e3e7, 1.15);
fillLight.position.set(9, 6, -8);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xd8d5cd,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x8f948f, 0xb0b2ac);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
// ---------------------------------------------------------------------
// Masonry dimensions
// ---------------------------------------------------------------------
const BRICK_LENGTH = 2.18;
const BRICK_HEIGHT = 0.45;
const BRICK_THICKNESS = 0.74;
const COURSE_HEIGHT = 0.50;
const COURSE_COUNT = 5;
const WALL_BASE_Y = 0.34;
const WALL_X_LENGTH = 7.7;
const WALL_Z_LENGTH = 7.0;
const SELECTED_COURSE = COURSE_COUNT - 1;
const wallTop =
WALL_BASE_Y + COURSE_COUNT * COURSE_HEIGHT;
const geometryCache = new Map();
function roundedBrickGeometry(length) {
const key = length.toFixed(3);
if (geometryCache.has(key)) {
return geometryCache.get(key);
}
const halfL = length / 2;
const halfH = BRICK_HEIGHT / 2;
const radius = 0.045;
const shape = new THREE.Shape();
shape.moveTo(-halfL + radius, -halfH);
shape.lineTo(halfL - radius, -halfH);
shape.quadraticCurveTo(halfL, -halfH, halfL, -halfH + radius);
shape.lineTo(halfL, halfH - radius);
shape.quadraticCurveTo(halfL, halfH, halfL - radius, halfH);
shape.lineTo(-halfL + radius, halfH);
shape.quadraticCurveTo(-halfL, halfH, -halfL, halfH - radius);
shape.lineTo(-halfL, -halfH + radius);
shape.quadraticCurveTo(-halfL, -halfH, -halfL + radius, -halfH);
const bevel = 0.018;
const depth = BRICK_THICKNESS - bevel * 2;
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 3,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: bevel,
bevelThickness: bevel
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
geometryCache.set(key, geometry);
return geometry;
}
const brickPalette = [
0xa75240,
0xb35d47,
0x9d4939,
0xbd694e,
0xaa5944,
0xc07154,
0x93483b
];
function brickMaterial(course, index, header = false) {
if (header) {
return new THREE.MeshStandardMaterial({
color: 0xc47a50,
roughness: 0.84,
metalness: 0,
emissive: 0x0b4850,
emissiveIntensity: 0.08
});
}
const base = new THREE.Color(
brickPalette[(course * 5 + index * 3) % brickPalette.length]
);
base.offsetHSL(0, 0, ((index % 3) - 1) * 0.018);
return new THREE.MeshStandardMaterial({
color: base,
roughness: 0.88,
metalness: 0
});
}
const mortarMaterial = new THREE.MeshStandardMaterial({
color: 0x77736b,
roughness: 1,
metalness: 0
});
// ---------------------------------------------------------------------
// L-shaped cutaway foundation
// ---------------------------------------------------------------------
const foundationShape = new THREE.Shape();
const foundationPoints = [
[-0.68, -0.68],
[WALL_X_LENGTH + 0.68, -0.68],
[WALL_X_LENGTH + 0.68, BRICK_THICKNESS / 2 + 0.68],
[BRICK_THICKNESS / 2 + 0.68, BRICK_THICKNESS / 2 + 0.68],
[BRICK_THICKNESS / 2 + 0.68, WALL_Z_LENGTH + 0.68],
[-0.68, WALL_Z_LENGTH + 0.68]
];
foundationShape.moveTo(
foundationPoints[0][0],
foundationPoints[0][1]
);
for (let i = 1; i < foundationPoints.length; i++) {
foundationShape.lineTo(
foundationPoints[i][0],
foundationPoints[i][1]
);
}
foundationShape.closePath();
const foundationGeometry = new THREE.ExtrudeGeometry(foundationShape, {
depth: 0.28,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.035,
bevelThickness: 0.035
});
// The extrusion is rotated so its local XY plane becomes the world XZ plane.
foundationGeometry.rotateX(Math.PI / 2);
const foundation = new THREE.Mesh(
foundationGeometry,
new THREE.MeshStandardMaterial({
color: 0x535956,
roughness: 0.93,
metalness: 0.02
})
);
foundation.position.y = 0.32;
foundation.castShadow = true;
foundation.receiveShadow = true;
scene.add(foundation);
// ---------------------------------------------------------------------
// Bonding logic
//
// Even course:
// Header runs along Z through the X wall corner.
//
// Odd course:
// Header runs along X through the Z wall corner.
//
// The stretcher starts alternate with the header, creating staggered
// vertical joints and a continuous interlocking corner.
// ---------------------------------------------------------------------
const courseGroups = [];
const courseBaseY = [];
let selectedHeader = null;
function addMortarCore(group, axis) {
const coreHeight = BRICK_HEIGHT - 0.035;
const coreThickness = BRICK_THICKNESS - 0.085;
if (axis === "x") {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
WALL_X_LENGTH,
coreHeight,
coreThickness
),
mortarMaterial
);
mesh.position.set(WALL_X_LENGTH / 2, BRICK_HEIGHT / 2, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
} else {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
coreThickness,
coreHeight,
WALL_Z_LENGTH
),
mortarMaterial
);
mesh.position.set(0, BRICK_HEIGHT / 2, WALL_Z_LENGTH / 2);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
}
function addBrickRun(group, axis, start, end, rotationY, course, armIndex) {
let cursor = start;
let index = 0;
while (end - cursor > 0.08) {
const room = end - cursor;
const nominalLength = Math.min(BRICK_LENGTH, room);
// Avoid an unusably thin sliver at the cut end.
if (nominalLength < 0.42 && index > 0) {
break;
}
const actualLength = Math.max(0.12, nominalLength - 0.035);
const mesh = new THREE.Mesh(
roundedBrickGeometry(actualLength),
brickMaterial(course, armIndex * 11 + index)
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.rotation.y = rotationY;
mesh.position.y = BRICK_HEIGHT / 2;
if (axis === "x") {
mesh.position.x = cursor + nominalLength / 2;
} else {
mesh.position.z = cursor + nominalLength / 2;
}
group.add(mesh);
cursor += nominalLength;
index++;
}
}
for (let course = 0; course < COURSE_COUNT; course++) {
const group = new THREE.Group();
const baseY = WALL_BASE_Y + course * COURSE_HEIGHT;
const isEven = course % 2 === 0;
group.position.y = baseY;
group.userData.baseY = baseY;
scene.add(group);
courseGroups.push(group);
courseBaseY.push(baseY);
addMortarCore(group, "x");
addMortarCore(group, "z");
const header = new THREE.Mesh(
roundedBrickGeometry(BRICK_LENGTH - 0.035),
brickMaterial(course, 0, true)
);
header.position.y = BRICK_HEIGHT / 2;
header.rotation.y = isEven ? Math.PI / 2 : 0;
header.castShadow = true;
header.receiveShadow = true;
header.userData.isHeader = true;
group.add(header);
if (course === SELECTED_COURSE) {
selectedHeader = header;
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(header.geometry, 24),
new THREE.LineBasicMaterial({
color: 0x30c4d1,
transparent: true,
opacity: 0.95
})
);
outline.scale.setScalar(1.008);
outline.renderOrder = 4;
header.add(outline);
}
const headerHalfLength = (BRICK_LENGTH - 0.035) / 2;
const halfThickness = BRICK_THICKNESS / 2;
if (isEven) {
// Z-running header; the X wall's first stretcher butts into its end.
addBrickRun(
group,
"x",
halfThickness,
WALL_X_LENGTH,
0,
course,
0
);
addBrickRun(
group,
"z",
headerHalfLength,
WALL_Z_LENGTH,
Math.PI / 2,
course,
1
);
} else {
// X-running header; the Z wall's first stretler butts into its end.
addBrickRun(
group,
"x",
headerHalfLength,
WALL_X_LENGTH,
0,
course,
0
);
addBrickRun(
group,
"z",
halfThickness,
WALL_Z_LENGTH,
Math.PI / 2,
course,
1
);
}
}
// ---------------------------------------------------------------------
// Cutaway section faces at the truncated wall ends
// ---------------------------------------------------------------------
const sectionMaterial = new THREE.MeshBasicMaterial({
color: 0xe58b48,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false
});
const sectionLineMaterial = new THREE.LineBasicMaterial({
color: 0xd77a38,
transparent: true,
opacity: 0.8
});
function addSectionFace(axis) {
const sectionHeight = COURSE_COUNT * COURSE_HEIGHT;
const cap = new THREE.Mesh(
new THREE.PlaneGeometry(BRICK_THICKNESS, sectionHeight),
sectionMaterial
);
if (axis === "x") {
cap.rotation.y = Math.PI / 2;
cap.position.set(
WALL_X_LENGTH + 0.012,
WALL_BASE_Y + sectionHeight / 2,
0
);
} else {
cap.position.set(
0,
WALL_BASE_Y + sectionHeight / 2,
WALL_Z_LENGTH + 0.012
);
}
scene.add(cap);
const points = [];
const y0 = WALL_BASE_Y;
const y1 = WALL_BASE_Y + sectionHeight;
const h = BRICK_THICKNESS / 2;
if (axis === "x") {
const x = WALL_X_LENGTH + 0.018;
points.push(
new THREE.Vector3(x, y0, -h),
new THREE.Vector3(x, y1, -h),
new THREE.Vector3(x, y0, h),
new THREE.Vector3(x, y1, h),
new THREE.Vector3(x, y0, -h),
new THREE.Vector3(x, y0, h),
new THREE.Vector3(x, y1, -h),
new THREE.Vector3(x, y1, h)
);
} else {
const z = WALL_Z_LENGTH + 0.018;
points.push(
new THREE.Vector3(-h, y0, z),
new THREE.Vector3(-h, y1, z),
new THREE.Vector3(h, y0, z),
new THREE.Vector3(h, y1, z),
new THREE.Vector3(-h, y0, z),
new THREE.Vector3(h, y0, z),
new THREE.Vector3(-h, y1, z),
new THREE.Vector3(h, y1, z)
);
}
const outline = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(points),
sectionLineMaterial
);
scene.add(outline);
}
addSectionFace("x");
addSectionFace("z");
// ---------------------------------------------------------------------
// Lift guide and axis indicators
// ---------------------------------------------------------------------
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(BRICK_THICKNESS / 2 + 0.08, 0, 0),
new THREE.Vector3(BRICK_THICKNESS / 2 + 0.08, 1, 0)
]);
const guideLine = new THREE.Line(
guideGeometry,
new THREE.LineDashedMaterial({
color: 0x168f9d,
dashSize: 0.08,
gapSize: 0.055,
transparent: true,
opacity: 0.7,
depthTest: false
})
);
guideLine.computeLineDistances();
guideLine.renderOrder = 8;
scene.add(guideLine);
const xArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
1.35,
0xd77a38,
0.23,
0.14
);
const zArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(),
1.35,
0x168f9d,
0.23,
0.14
);
xArrow.line.material.transparent = true;
xArrow.line.material.opacity = 0.8;
xArrow.cone.material.transparent = true;
xArrow.cone.material.opacity = 0.8;
zArrow.line.material.transparent = true;
zArrow.line.material.opacity = 0.8;
zArrow.cone.material.transparent = true;
zArrow.cone.material.opacity = 0.8;
scene.add(xArrow, zArrow);
// ---------------------------------------------------------------------
// Direct camera controls — no addons
// ---------------------------------------------------------------------
const controls = {
theta: 0.72,
phi: 0.94,
radius: 13.8,
target: new THREE.Vector3(2.45, 1.25, 2.25)
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function setView(type) {
if (type === "iso") {
controls.theta = 0.72;
controls.phi = 0.94;
controls.radius = 13.8;
} else if (type === "section") {
controls.theta = 0.06;
controls.phi = 1.18;
controls.radius = 11.4;
} else {
controls.theta = 0.72;
controls.phi = 0.94;
controls.radius = 13.8;
controls.target.set(2.45, 1.25, 2.25);
}
updateCamera();
}
document.querySelector("#iso").addEventListener("click", () => {
setView("iso");
});
document.querySelector("#section").addEventListener("click", () => {
setView("section");
});
document.querySelector("#reset").addEventListener("click", () => {
setView("reset");
controls.target.set(2.45, 1.25, 2.25);
targetLift = 0.9;
liftSlider.value = "0.9";
liftValue.value = "0.90";
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.12,
1.36
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.008,
7.2,
23
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") controls.theta += step;
else if (event.key === "ArrowRight") controls.theta -= step;
else if (event.key === "ArrowUp") controls.phi -= step;
else if (event.key === "ArrowDown") controls.phi += step;
else if (event.key === "+" || event.key === "=") controls.radius -= 0.5;
else if (event.key === "-") controls.radius += 0.5;
else if (event.key.toLowerCase() === "r") setView("reset");
else return;
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.12, 1.36);
controls.radius = THREE.MathUtils.clamp(controls.radius, 7.2, 23);
updateCamera();
});
// ---------------------------------------------------------------------
// Lift interaction and annotations
// ---------------------------------------------------------------------
let targetLift = Number(liftSlider.value);
let currentLift = 0;
const reduceMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
if (reduceMotion) {
currentLift = targetLift;
}
liftSlider.addEventListener("input", () => {
targetLift = Number(liftSlider.value);
liftValue.value = targetLift.toFixed(2);
});
const headerTag = document.querySelector("#header-tag");
const courseTag = document.querySelector("#course-tag");
const wallATag = document.querySelector("#wall-a-tag");
const wallBTag = document.querySelector("#wall-b-tag");
const projected = new THREE.Vector3();
function positionTag(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateAnnotations() {
const selectedBase = courseBaseY[SELECTED_COURSE];
const headerCenterY =
selectedBase + BRICK_HEIGHT / 2 + currentLift;
positionTag(
headerTag,
new THREE.Vector3(0, headerCenterY + 0.63, 0)
);
positionTag(
courseTag,
new THREE.Vector3(3.2, headerCenterY + 0.42, 0)
);
positionTag(
wallATag,
new THREE.Vector3(5.7, wallTop + 0.24, 0)
);
positionTag(
wallBTag,
new THREE.Vector3(0, wallTop + 0.24, 5.2)
);
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
new ResizeObserver(resize).observe(viewport);
resize();
updateCamera();
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
currentLift = reduceMotion
? targetLift
: THREE.MathUtils.lerp(
currentLift,
targetLift,
1 - Math.exp(-delta * 7)
);
courseGroups[SELECTED_COURSE].position.y =
courseBaseY[SELECTED_COURSE] + currentLift;
const selectedBase = courseBaseY[SELECTED_COURSE];
const originalHeaderCenter = selectedBase + BRICK_HEIGHT / 2;
const raisedHeaderCenter = originalHeaderCenter + currentLift;
const guidePositions = guideGeometry.attributes.position.array;
guidePositions[1] = originalHeaderCenter;
guidePositions[4] = raisedHeaderCenter;
guideGeometry.attributes.position.needsUpdate = true;
guideLine.computeLineDistances();
const arrowY = raisedHeaderCenter + BRICK_HEIGHT / 2 + 0.20;
xArrow.position.set(-1.35, arrowY, 0);
zArrow.position.set(0, arrowY, -0.45);
updateAnnotations();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```