Prompt specification
Build or customize the Three.js 3D scene "Column on a spread footing" 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 on a spread footing
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/column-on-a-spread-footing-x2197
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: column on a spread footing. Model a single column on a wider footing within a cutaway soil block. Use clear geometric boundaries to distinguish the structural element from supporting ground. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (column-on-a-spread-footing-x2197):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spread Footing — Isometric Cutaway</title>
<style>
:root {
--ink: #183038;
--muted: #62747a;
--panel: rgba(248, 251, 251, 0.92);
--line: rgba(24, 48, 56, 0.13);
--accent: #2d7278;
--concrete: #cbd4d5;
--soil: #b48a62;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7edef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene,
#viewport {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#viewport {
display: block;
touch-action: none;
cursor: grab;
}
#viewport.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
width: min(330px, calc(100vw - 48px));
padding: 20px 21px 18px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(39, 56, 61, 0.14),
inset 0 0 0 1px rgba(24, 48, 56, 0.035);
backdrop-filter: blur(16px) saturate(1.1);
-webkit-backdrop-filter: blur(16px) saturate(1.1);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
border-radius: 99px;
background: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 31px);
font-weight: 760;
letter-spacing: -0.035em;
line-height: 1.05;
}
.subtitle {
margin: 9px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: grid;
gap: 9px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.legend-row {
display: grid;
grid-template-columns: 18px 1fr;
align-items: center;
gap: 9px;
color: #435a61;
font-size: 12px;
}
.swatch {
width: 13px;
height: 13px;
margin-left: 2px;
border: 1px solid rgba(24, 48, 56, 0.2);
border-radius: 3px;
}
.swatch.concrete {
background: linear-gradient(135deg, #e1e7e7, #b9c4c6);
}
.swatch.soil {
background: linear-gradient(135deg, #cfaa7e, #9d7350);
}
.swatch.cut {
background: #6f5541;
}
.toolbar {
position: fixed;
z-index: 11;
top: 24px;
right: 24px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 14px;
background: rgba(248, 251, 251, 0.9);
box-shadow: 0 12px 34px rgba(39, 56, 61, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.toolbar button {
height: 36px;
padding: 0 12px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: #3d555d;
cursor: pointer;
font-size: 12px;
font-weight: 680;
transition:
background 150ms ease,
color 150ms ease,
transform 150ms ease;
}
.toolbar button:hover {
background: #e7eeee;
color: var(--ink);
}
.toolbar button:active {
transform: translateY(1px);
}
.toolbar button[aria-pressed="true"] {
background: #dcebed;
color: #235e63;
}
.toolbar .zoom-button {
width: 36px;
padding: 0;
font-size: 19px;
font-weight: 450;
}
.toolbar .divider {
width: 1px;
height: 22px;
align-self: center;
margin: 0 2px;
background: var(--line);
}
.hint {
position: fixed;
z-index: 10;
right: 26px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 10px;
background: rgba(248, 251, 251, 0.78);
color: #60737a;
font-size: 11px;
box-shadow: 0 8px 26px rgba(39, 56, 61, 0.08);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: none;
}
.hint strong {
color: #385159;
font-weight: 750;
}
.caption {
position: fixed;
z-index: 9;
bottom: 22px;
left: 24px;
color: rgba(38, 61, 68, 0.58);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
#leaders {
position: fixed;
z-index: 4;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
transition: opacity 180ms ease;
}
#leaders line {
stroke: rgba(45, 114, 120, 0.66);
stroke-width: 1.2;
stroke-dasharray: 3 3;
}
#leaders circle {
fill: #f8fbfb;
stroke: #2d7278;
stroke-width: 1.5;
}
.annotation {
position: fixed;
z-index: 5;
top: 0;
left: 0;
min-width: 128px;
padding: 9px 12px 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(23, 43, 50, 0.91);
color: #f4f8f8;
box-shadow: 0 10px 28px rgba(27, 43, 48, 0.16);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
pointer-events: none;
transition: opacity 180ms ease;
will-change: transform;
}
.annotation b {
display: block;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.annotation small {
display: block;
margin-top: 3px;
color: rgba(236, 246, 246, 0.67);
font-size: 10px;
line-height: 1.25;
}
body.labels-off #leaders,
body.labels-off .annotation {
opacity: 0;
}
@media (max-width: 720px) {
.panel {
top: 14px;
left: 14px;
width: min(285px, calc(100vw - 28px));
padding: 15px 16px;
border-radius: 14px;
}
h1 {
font-size: 23px;
}
.subtitle {
margin-bottom: 12px;
font-size: 11px;
}
.legend {
display: none;
}
.toolbar {
top: auto;
right: 14px;
bottom: 54px;
}
.toolbar button {
padding: 0 9px;
font-size: 11px;
}
.hint {
right: 14px;
bottom: 14px;
left: 14px;
text-align: center;
}
.caption {
display: none;
}
.annotation {
min-width: 0;
padding: 7px 9px;
}
.annotation small {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<aside class="panel">
<div class="eyebrow">Isometric cutaway</div>
<h1>Spread Footing</h1>
<p class="subtitle">
A single structural column transferring its load into a wider,
isolated concrete footing within supporting ground.
</p>
<div class="legend" aria-label="Model legend">
<div class="legend-row">
<span class="swatch concrete"></span>
<span>Concrete structure and footing</span>
</div>
<div class="legend-row">
<span class="swatch soil"></span>
<span>Supporting soil strata</span>
</div>
<div class="legend-row">
<span class="swatch cut"></span>
<span>Cut edges and grade level</span>
</div>
</div>
</aside>
<nav class="toolbar" aria-label="Scene controls">
<button id="resetView" type="button">Reset view</button>
<button id="soilToggle" type="button" aria-pressed="false">X-ray soil</button>
<button id="labelsToggle" type="button" aria-pressed="true">Labels</button>
<span class="divider"></span>
<button id="zoomOut" class="zoom-button" type="button" aria-label="Zoom out">−</button>
<button id="zoomIn" class="zoom-button" type="button" aria-label="Zoom in">+</button>
</nav>
<div class="caption">Conceptual structural model / Orthographic</div>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Wheel</strong> to zoom ·
<strong>Shift-drag</strong> to pan
</div>
<svg id="leaders" aria-hidden="true"></svg>
<div class="annotation" id="label-column">
<b>Column</b>
<small>Vertical load path</small>
</div>
<div class="annotation" id="label-footing">
<b>Spread Footing</b>
<small>Wider load-distribution base</small>
</div>
<div class="annotation" id="label-soil">
<b>Supporting Soil</b>
<small>Layered cutaway ground</small>
</div>
<div class="annotation" id="label-load">
<b>Applied Load</b>
<small>Downward force</small>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.domElement.id = "viewport";
renderer.domElement.setAttribute(
"aria-label",
"Interactive isometric cutaway of a column on a spread footing"
);
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;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7edef);
scene.fog = new THREE.Fog(0xe7edef, 19, 34);
const camera = new THREE.OrthographicCamera(-6, 6, 4.2, -4.2, 0.1, 100);
camera.position.set(8, 5, 8);
const controls = {
theta: 0.72,
phi: 1.10,
zoom: 1,
target: new THREE.Vector3(0, -0.65, 0),
radius: 12
};
const hemisphere = new THREE.HemisphereLight(0xf7fcff, 0x80614c, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff7e9, 3.25);
keyLight.position.set(6.5, 10, 7.5);
keyLight.target.position.set(0, -1, 0);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0xb9d9e3, 1.05);
fillLight.position.set(-7, 4, -5);
scene.add(fillLight);
const model = new THREE.Group();
const soilGroup = new THREE.Group();
const structureGroup = new THREE.Group();
scene.add(model);
model.add(soilGroup, structureGroup);
const soilMaterials = [];
function registerSoilMaterial(material, solidOpacity, xrayOpacity, depthWrite = false) {
material.transparent = true;
material.opacity = solidOpacity;
material.depthWrite = depthWrite;
material.userData.solidOpacity = solidOpacity;
material.userData.xrayOpacity = xrayOpacity;
material.userData.solidDepthWrite = depthWrite;
soilMaterials.push(material);
return material;
}
function addEdges(mesh, color = 0x263c43, opacity = 0.72) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 24),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
edges.renderOrder = 3;
mesh.add(edges);
return edges;
}
function addBox({
parent,
size,
position,
material,
edge = true,
edgeColor = 0x263c43,
edgeOpacity = 0.72,
castShadow = false,
receiveShadow = false
}) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
if (edge) {
addEdges(mesh, edgeColor, edgeOpacity);
}
return mesh;
}
function createTaperedPrism({
parent,
bottomWidth,
bottomDepth,
topWidth,
topDepth,
height,
position,
material
}) {
const bw = bottomWidth / 2;
const bd = bottomDepth / 2;
const tw = topWidth / 2;
const td = topDepth / 2;
const y0 = -height / 2;
const y1 = height / 2;
const vertices = new Float32Array([
-bw, y0, -bd,
bw, y0, -bd,
bw, y0, bd,
-bw, y0, bd,
-tw, y1, -td,
tw, y1, -td,
tw, y1, td,
-tw, y1, td
]);
const indices = [
0, 2, 1, 0, 3, 2,
4, 5, 6, 4, 6, 7,
0, 1, 5, 0, 5, 4,
1, 2, 6, 1, 6, 5,
2, 3, 7, 2, 7, 6,
3, 0, 4, 3, 4, 7
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
addEdges(mesh, 0x243a41, 0.82);
return mesh;
}
// ------------------------------------------------------------------
// Cutaway soil block
// ------------------------------------------------------------------
const soilWidth = 7.2;
const soilDepth = 5.0;
const soilBottom = -3.65;
const soilTop = 0.45;
const soilHeight = soilTop - soilBottom;
const soilCenterY = (soilTop + soilBottom) / 2;
const holeWidth = 5.2;
const holeDepth = 3.9;
const sideStripWidth = (soilWidth - holeWidth) / 2;
const endStripDepth = (soilDepth - holeDepth) / 2;
const backSoilMaterial = registerSoilMaterial(
new THREE.MeshStandardMaterial({
color: 0xa77c58,
roughness: 0.98,
side: THREE.DoubleSide
}),
0.34,
0.075,
false
);
const sideSoilMaterial = registerSoilMaterial(
new THREE.MeshStandardMaterial({
color: 0xb58b63,
roughness: 1,
side: THREE.DoubleSide
}),
0.24,
0.055,
false
);
const topSoilMaterial = registerSoilMaterial(
new THREE.MeshStandardMaterial({
color: 0xc3a07a,
roughness: 0.96
}),
0.92,
0.23,
true
);
const bottomSoilMaterial = registerSoilMaterial(
new THREE.MeshStandardMaterial({
color: 0x9d7653,
roughness: 1,
side: THREE.DoubleSide
}),
0.58,
0.12,
false
);
const backWall = new THREE.Mesh(
new THREE.PlaneGeometry(soilWidth, soilHeight),
backSoilMaterial
);
backWall.position.set(0, soilCenterY, -soilDepth / 2);
soilGroup.add(backWall);
const leftWall = new THREE.Mesh(
new THREE.PlaneGeometry(soilDepth, soilHeight),
sideSoilMaterial
);
leftWall.rotation.y = Math.PI / 2;
leftWall.position.set(-soilWidth / 2, soilCenterY, 0);
soilGroup.add(leftWall);
const rightWall = leftWall.clone();
rightWall.position.x = soilWidth / 2;
soilGroup.add(rightWall);
const bottomWall = new THREE.Mesh(
new THREE.PlaneGeometry(soilWidth, soilDepth),
bottomSoilMaterial
);
bottomWall.rotation.x = -Math.PI / 2;
bottomWall.position.y = soilBottom;
soilGroup.add(bottomWall);
// The open top is assembled as four pieces around a rectangular cut.
addBox({
parent: soilGroup,
size: [sideStripWidth, 0.12, soilDepth],
position: [-(holeWidth / 2 + sideStripWidth / 2), soilTop, 0],
material: topSoilMaterial,
edgeColor: 0x765b43,
edgeOpacity: 0.34,
receiveShadow: true
});
addBox({
parent: soilGroup,
size: [sideStripWidth, 0.12, soilDepth],
position: [holeWidth / 2 + sideStripWidth / 2, soilTop, 0],
material: topSoilMaterial,
edgeColor: 0x765b43,
edgeOpacity: 0.34,
receiveShadow: true
});
addBox({
parent: soilGroup,
size: [holeWidth, 0.12, endStripDepth],
position: [0, soilTop, -(holeDepth / 2 + endStripDepth / 2)],
material: topSoilMaterial,
edgeColor: 0x765b43,
edgeOpacity: 0.34,
receiveShadow: true
});
addBox({
parent: soilGroup,
size: [holeWidth, 0.12, endStripDepth],
position: [0, soilTop, holeDepth / 2 + endStripDepth / 2],
material: topSoilMaterial,
edgeColor: 0x765b43,
edgeOpacity: 0.34,
receiveShadow: true
});
// Outer cutaway block boundary.
const soilOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(soilWidth, soilHeight, soilDepth)
),
new THREE.LineBasicMaterial({
color: 0x715844,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
soilOutline.position.y = soilCenterY;
soilOutline.renderOrder = 4;
soilGroup.add(soilOutline);
// Distinct soil layers, shown on the rear and side cut faces.
const layers = [
{ top: soilTop, bottom: 0.12, color: 0x75624d, solid: 0.78, xray: 0.18 },
{ top: 0.12, bottom: -0.76, color: 0x957151, solid: 0.68, xray: 0.15 },
{ top: -0.76, bottom: -1.72, color: 0xae845d, solid: 0.64, xray: 0.14 },
{ top: -1.72, bottom: -2.7, color: 0xc09a72, solid: 0.58, xray: 0.13 },
{ top: -2.7, bottom: soilBottom, color: 0xd0b08b, solid: 0.56, xray: 0.12 }
];
for (const layer of layers) {
const layerHeight = layer.top - layer.bottom;
const layerY = (layer.top + layer.bottom) / 2;
const material = registerSoilMaterial(
new THREE.MeshStandardMaterial({
color: layer.color,
roughness: 1,
side: THREE.DoubleSide
}),
layer.solid,
layer.xray,
false
);
addBox({
parent: soilGroup,
size: [soilWidth - 0.03, layerHeight, 0.028],
position: [0, layerY, -soilDepth / 2 + 0.02],
material,
edge: false
});
for (const x of [-soilWidth / 2 + 0.02, soilWidth / 2 - 0.02]) {
addBox({
parent: soilGroup,
size: [0.028, layerHeight, soilDepth - 0.04],
position: [x, layerY, 0],
material,
edge: false
});
}
}
// Dark rim emphasizes the removed section around the exposed footing.
const cutRimMaterial = registerSoilMaterial(
new THREE.MeshStandardMaterial({
color: 0x624c39,
roughness: 0.9
}),
0.86,
0.35,
false
);
addBox({
parent: soilGroup,
size: [holeWidth + 0.04, 0.035, 0.055],
position: [0, soilTop + 0.075, -holeDepth / 2],
material: cutRimMaterial,
edge: false
});
addBox({
parent: soilGroup,
size: [holeWidth + 0.04, 0.035, 0.055],
position: [0, soilTop + 0.075, holeDepth / 2],
material: cutRimMaterial,
edge: false
});
for (const x of [-holeWidth / 2, holeWidth / 2]) {
addBox({
parent: soilGroup,
size: [0.055, 0.035, holeDepth],
position: [x, soilTop + 0.075, 0],
material: cutRimMaterial,
edge: false
});
}
// ------------------------------------------------------------------
// Concrete structure: footing, tapered haunch, column, and cap
// ------------------------------------------------------------------
const footingMaterial = new THREE.MeshStandardMaterial({
color: 0xb9c4c5,
roughness: 0.86,
metalness: 0.02
});
const haunchMaterial = new THREE.MeshStandardMaterial({
color: 0xc6cfd0,
roughness: 0.82,
metalness: 0.02
});
const columnMaterial = new THREE.MeshStandardMaterial({
color: 0xdce2e1,
roughness: 0.76,
metalness: 0.02
});
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xcbd3d2,
roughness: 0.8,
metalness: 0.02
});
createTaperedPrism({
parent: structureGroup,
bottomWidth: 4.4,
bottomDepth: 3.4,
topWidth: 4.15,
topDepth: 3.15,
height: 0.57,
position: [0, -3.065, 0],
material: footingMaterial
});
createTaperedPrism({
parent: structureGroup,
bottomWidth: 3.2,
bottomDepth: 2.5,
topWidth: 1.55,
topDepth: 1.45,
height: 0.56,
position: [0, -2.5, 0],
material: haunchMaterial
});
addBox({
parent: structureGroup,
size: [1.05, 4.14, 1.05],
position: [0, -0.15, 0],
material: columnMaterial,
edgeColor: 0x1e343b,
edgeOpacity: 0.9,
castShadow: true,
receiveShadow: true
});
addBox({
parent: structureGroup,
size: [1.28, 0.18, 1.28],
position: [0, 2.01, 0],
material: capMaterial,
edgeColor: 0x1e343b,
edgeOpacity: 0.9,
castShadow: true,
receiveShadow: true
});
// Downward load indicator above the column.
const loadArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(0, 3.18, 0),
1.08,
0x2d7278,
0.24,
0.14
);
loadArrow.line.material.transparent = true;
loadArrow.line.material.opacity = 0.86;
loadArrow.cone.material.transparent = true;
loadArrow.cone.material.opacity = 0.9;
model.add(loadArrow);
// ------------------------------------------------------------------
// Ground plane and architectural grid
// ------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xdce4e5,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = soilBottom - 0.075;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x71878c, 0x91a1a4);
grid.position.y = soilBottom - 0.068;
grid.material.transparent = true;
grid.material.opacity = 0.14;
grid.material.depthWrite = false;
scene.add(grid);
// ------------------------------------------------------------------
// Custom camera controls: orbit, pan, and zoom
// ------------------------------------------------------------------
let viewWidth = window.innerWidth;
let viewHeight = window.innerHeight;
function updateCamera() {
const aspect = viewWidth / viewHeight;
const halfHeight = Math.max(4.15, 5.65 / aspect) / controls.zoom;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
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);
camera.updateMatrixWorld();
}
function resetView() {
controls.theta = 0.72;
controls.phi = 1.10;
controls.zoom = 1;
controls.target.set(0, -0.65, 0);
updateCamera();
}
function setZoom(value) {
controls.zoom = THREE.MathUtils.clamp(value, 0.62, 2.35);
updateCamera();
}
const pointer = {
active: false,
id: null,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
mode: "orbit"
};
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
if (pointer.active) return;
pointer.active = true;
pointer.id = event.pointerId;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.mode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
if (pointer.mode === "orbit") {
controls.theta -= dx * 0.0062;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0052,
0.48,
1.47
);
} else {
const worldPerPixel = (camera.top - camera.bottom) / viewHeight;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
controls.target
.addScaledVector(right, -dx * worldPerPixel)
.addScaledVector(up, dy * worldPerPixel);
}
updateCamera();
});
function releasePointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
setZoom(controls.zoom * Math.exp(-event.deltaY * 0.0011));
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
// ------------------------------------------------------------------
// HTML annotations and projected leader lines
// ------------------------------------------------------------------
const leaderSvg = document.getElementById("leaders");
const svgNamespace = "http://www.w3.org/2000/svg";
const annotations = [
{
element: document.getElementById("label-column"),
point: new THREE.Vector3(0.55, 1.22, 0.55),
offset: [115, -56]
},
{
element: document.getElementById("label-footing"),
point: new THREE.Vector3(1.0, -3.05, 1.45),
offset: [118, 30]
},
{
element: document.getElementById("label-soil"),
point: new THREE.Vector3(-3.05, -1.05, -2.28),
offset: [-120, 24]
},
{
element: document.getElementById("label-load"),
point: new THREE.Vector3(0, 3.22, 0),
offset: [92, -18]
}
];
for (const annotation of annotations) {
annotation.line = document.createElementNS(svgNamespace, "line");
annotation.dot = document.createElementNS(svgNamespace, "circle");
annotation.dot.setAttribute("r", "3.4");
leaderSvg.appendChild(annotation.line);
leaderSvg.appendChild(annotation.dot);
}
const projected = new THREE.Vector3();
function updateAnnotations() {
for (const annotation of annotations) {
projected.copy(annotation.point).project(camera);
const pointX = (projected.x * 0.5 + 0.5) * viewWidth;
const pointY = (-projected.y * 0.5 + 0.5) * viewHeight;
const labelX = THREE.MathUtils.clamp(
pointX + annotation.offset[0],
72,
viewWidth - 72
);
const labelY = THREE.MathUtils.clamp(
pointY + annotation.offset[1],
76,
viewHeight - 78
);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
pointX > -80 &&
pointX < viewWidth + 80 &&
pointY > -80 &&
pointY < viewHeight + 80;
annotation.element.style.transform =
`translate3d(${labelX}px, ${labelY}px, 0) translate(-50%, -50%)`;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.line.setAttribute("x1", pointX);
annotation.line.setAttribute("y1", pointY);
annotation.line.setAttribute("x2", labelX);
annotation.line.setAttribute("y2", labelY);
annotation.line.style.opacity = visible ? "1" : "0";
annotation.dot.setAttribute("cx", pointX);
annotation.dot.setAttribute("cy", pointY);
annotation.dot.style.opacity = visible ? "1" : "0";
}
}
// ------------------------------------------------------------------
// UI controls
// ------------------------------------------------------------------
document.getElementById("resetView").addEventListener("click", resetView);
document.getElementById("zoomIn").addEventListener("click", () => {
setZoom(controls.zoom * 1.14);
});
document.getElementById("zoomOut").addEventListener("click", () => {
setZoom(controls.zoom / 1.14);
});
let xrayEnabled = false;
function applySoilOpacity() {
for (const material of soilMaterials) {
material.opacity = xrayEnabled
? material.userData.xrayOpacity
: material.userData.solidOpacity;
material.depthWrite = xrayEnabled
? false
: material.userData.solidDepthWrite;
}
}
const soilButton = document.getElementById("soilToggle");
soilButton.addEventListener("click", () => {
xrayEnabled = !xrayEnabled;
soilButton.setAttribute("aria-pressed", String(xrayEnabled));
soilButton.textContent = xrayEnabled ? "X-ray: on" : "X-ray soil";
applySoilOpacity();
});
const labelsButton = document.getElementById("labelsToggle");
labelsButton.addEventListener("click", () => {
const enabled = !document.body.classList.contains("labels-off");
document.body.classList.toggle("labels-off", enabled);
labelsButton.setAttribute("aria-pressed", String(!enabled));
});
// ------------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------------
function resize() {
viewWidth = window.innerWidth;
viewHeight = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewWidth, viewHeight);
leaderSvg.setAttribute("viewBox", `0 0 ${viewWidth} ${viewHeight}`);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
function animate() {
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```