Prompt specification
Build or customize the Three.js 3D scene "Compare shallow and deep foundation concepts" 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: Compare shallow and deep foundation concepts
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-shallow-and-deep-foundation-concepts-x2200
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows building foundations and soil contact. Let users switch a schematic building between spread footings and piles reaching a stronger layer. Show load paths and explicitly avoid predicting site-specific bearing capacity. Low-poly.
Working Three.js Starter (compare-shallow-and-deep-foundation-concepts-x2200):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Foundation + Soil Contact Explorer</title>
<style>
:root {
--ink: #17312e;
--muted: #536965;
--paper: rgba(250, 252, 249, 0.92);
--line: rgba(23, 49, 46, 0.15);
--accent: #df8b45;
--accent-dark: #a95d26;
--teal: #2b8e82;
--cyan: #61c7c1;
--shadow: 0 18px 50px rgba(35, 57, 52, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e5ebe6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-radius: 18px;
}
.header {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(223, 139, 69, 0.15);
content: "";
}
h1 {
margin: 0;
max-width: 330px;
font-size: clamp(25px, 3vw, 36px);
line-height: 1.04;
letter-spacing: -0.04em;
}
.header p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.mode-panel {
top: 22px;
right: 22px;
width: min(350px, calc(100vw - 44px));
padding: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.panel-heading strong {
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.concept-badge {
padding: 5px 8px;
border-radius: 999px;
background: rgba(223, 139, 69, 0.13);
color: var(--accent-dark);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
white-space: nowrap;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 4px;
border-radius: 12px;
background: rgba(23, 49, 46, 0.07);
}
.segmented button {
min-height: 42px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
transition: background 160ms ease, color 160ms ease,
box-shadow 160ms ease, transform 160ms ease;
}
.segmented button:hover {
color: var(--ink);
}
.segmented button[aria-selected="true"] {
background: #fff;
color: var(--ink);
box-shadow: 0 4px 14px rgba(23, 49, 46, 0.12);
}
.mode-panel h2 {
margin: 17px 0 6px;
font-size: 18px;
letter-spacing: -0.025em;
}
.mode-description {
min-height: 58px;
margin: 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.48;
}
.facts {
display: grid;
gap: 7px;
margin-top: 14px;
}
.fact {
display: grid;
grid-template-columns: 54px 1fr;
gap: 9px;
align-items: start;
padding: 9px 10px;
border: 1px solid rgba(23, 49, 46, 0.09);
border-radius: 10px;
background: rgba(255, 255, 255, 0.52);
}
.fact span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.fact b {
font-size: 11.5px;
line-height: 1.35;
}
.scope-note {
margin-top: 12px;
padding: 10px 11px;
border-left: 3px solid var(--accent);
border-radius: 0 8px 8px 0;
background: rgba(223, 139, 69, 0.09);
color: #6e4a30;
font-size: 10.5px;
line-height: 1.42;
}
.controls {
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border-radius: 14px;
}
.controls button {
border: 1px solid rgba(23, 49, 46, 0.15);
border-radius: 9px;
padding: 8px 10px;
background: #fff;
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
}
.controls button:hover {
border-color: var(--teal);
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
color: var(--ink);
font-size: 11px;
font-weight: 700;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 14px;
height: 14px;
accent-color: var(--teal);
}
.control-help {
max-width: 190px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.legend {
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
gap: 15px;
align-items: center;
padding: 10px 14px;
border-radius: 14px;
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
}
.swatch.load {
background: var(--accent);
border-radius: 999px;
width: 5px;
height: 17px;
}
.swatch.contact {
background: var(--cyan);
}
.swatch.strong {
background: rgba(43, 142, 130, 0.62);
}
.disclaimer {
right: 22px;
bottom: 22px;
display: flex;
gap: 11px;
width: min(390px, calc(100vw - 44px));
padding: 13px 15px;
border-radius: 14px;
background: rgba(255, 248, 240, 0.94);
}
.warning {
display: grid;
flex: 0 0 25px;
height: 25px;
place-items: center;
border-radius: 50%;
background: var(--accent);
color: white;
font-size: 14px;
font-weight: 900;
}
.disclaimer strong {
display: block;
margin-bottom: 3px;
font-size: 11.5px;
}
.disclaimer p {
margin: 0;
color: #725744;
font-size: 10.5px;
line-height: 1.42;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
top: 0;
left: 0;
padding: 6px 9px;
border: 1px solid rgba(23, 49, 46, 0.14);
border-radius: 999px;
background: rgba(250, 252, 249, 0.88);
box-shadow: 0 5px 15px rgba(23, 49, 46, 0.09);
color: var(--ink);
font-size: 9.5px;
font-weight: 800;
letter-spacing: 0.02em;
white-space: nowrap;
will-change: transform, opacity;
}
.world-label.building {
border-color: rgba(223, 139, 69, 0.35);
color: var(--accent-dark);
}
.world-label.strong {
border-color: rgba(43, 142, 130, 0.34);
color: #216d65;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #e5ebe6;
color: var(--muted);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 980px) {
.header {
width: 330px;
}
.mode-panel {
top: 190px;
width: 320px;
}
.legend {
display: none;
}
.disclaimer {
width: 330px;
}
}
@media (max-width: 680px) {
.header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.header p {
display: none;
}
h1 {
font-size: 24px;
}
.mode-panel {
top: 122px;
right: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.mode-description {
min-height: 0;
}
.facts {
grid-template-columns: 1fr 1fr;
}
.fact {
grid-template-columns: 1fr;
gap: 3px;
}
.scope-note {
display: none;
}
.controls {
left: 12px;
bottom: 12px;
}
.control-help {
display: none;
}
.disclaimer {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.world-label {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive schematic of foundations and soil contact"></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="panel header">
<div class="eyebrow">Schematic / Geotechnical</div>
<h1>Foundation + Soil Contact</h1>
<p>
Explore how a conceptual building load can be transferred through shallow
footings or deep piles.
</p>
</header>
<section class="panel mode-panel" aria-label="Foundation type">
<div class="panel-heading">
<strong>Foundation system</strong>
<span class="concept-badge">CONCEPT ONLY</span>
</div>
<div class="segmented" role="tablist" aria-label="Select foundation type">
<button
id="spreadButton"
role="tab"
aria-selected="true"
aria-controls="modeDescription"
data-mode="spread"
>Spread footings</button>
<button
id="pileButton"
role="tab"
aria-selected="false"
aria-controls="modeDescription"
data-mode="piles"
>Deep piles</button>
</div>
<div id="modeDescription" role="tabpanel" aria-live="polite">
<h2 id="modeTitle">Spread footings · upper soil</h2>
<p class="mode-description" id="modeDescriptionText">
Columns transfer load to wider footings, producing a conceptual
contact footprint within the shallow soil layer.
</p>
<div class="facts">
<div class="fact">
<span>Path</span>
<b id="pathText">Columns → footings → upper soil</b>
</div>
<div class="fact">
<span>Contact</span>
<b id="contactText">Distributed footing footprint</b>
</div>
</div>
<div class="scope-note">
Layer thickness, footing size, and contact zones are diagrammatic.
They are not calibrated to a site and do not represent a recommended design.
</div>
</div>
</section>
<div class="panel controls" aria-label="View controls">
<button id="resetButton" type="button">Reset view</button>
<label class="toggle">
<input id="loadToggle" type="checkbox" checked>
Load paths
</label>
<span class="control-help">
Drag to orbit · wheel to zoom · right-drag to pan
</span>
</div>
<div class="panel legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch load"></span>
Load path
</div>
<div class="legend-item">
<span class="swatch contact"></span>
Contact zone
</div>
<div class="legend-item">
<span class="swatch strong"></span>
Stronger layer
</div>
</div>
<aside class="panel disclaimer" aria-label="Important limitation">
<div class="warning">!</div>
<div>
<strong>Not a site-specific capacity assessment</strong>
<p>
This visualization does not calculate or predict bearing capacity,
settlement, pile length, or foundation suitability. Actual design
requires site-specific investigation and engineering review.
</p>
</div>
</aside>
<div id="loading">Loading schematic…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const labelLayer = document.getElementById("labels");
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe5ebe6);
scene.fog = new THREE.Fog(0xe5ebe6, 48, 92);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemisphere = new THREE.HemisphereLight(0xf9fff8, 0x6e786d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.1);
sun.position.set(16, 28, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x8bcac3, 1.1);
rim.position.set(-18, 10, -16);
scene.add(rim);
const world = new THREE.Group();
scene.add(world);
const columnX = [-4.1, 0, 4.1];
const columnZ = [-2.7, 2.7];
const floorLevels = [0.28, 3.08, 5.88, 8.68, 11.48];
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...options
});
}
function box(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x47625c, opacity = 0.32) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.renderOrder = 3;
mesh.parent.add(edges);
return edges;
}
// ---------------------------------------------------------------
// Soil block: illustrative, non-calibrated strata.
// ---------------------------------------------------------------
const soil = new THREE.Group();
world.add(soil);
function addLayer(name, top, bottom, color, opacity) {
const height = top - bottom;
const material = standardMaterial(color, {
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
const layer = box(
soil,
[20, height, 12],
[0, (top + bottom) / 2, 0],
material,
false
);
layer.renderOrder = 1;
addEdges(layer, color, 0.55);
return layer;
}
addLayer("Upper soil", 0, -5, 0xc7a979, 0.29);
addLayer("Intermediate soil", -5, -9, 0x9f9b77, 0.22);
addLayer("Stronger illustrative layer", -9, -18, 0x479f93, 0.31);
addLayer("Deep substrate", -18, -21, 0x536b68, 0.25);
const groundMaterial = standardMaterial(0xd8bd8d, {
transparent: true,
opacity: 0.42,
depthWrite: false,
side: THREE.DoubleSide
});
const groundSurface = new THREE.Mesh(
new THREE.PlaneGeometry(20, 12),
groundMaterial
);
groundSurface.rotation.x = -Math.PI / 2;
groundSurface.position.y = 0.015;
groundSurface.receiveShadow = true;
groundSurface.renderOrder = 2;
soil.add(groundSurface);
// A subtle shadow catcher below the soil block.
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.ShadowMaterial({ color: 0x41534c, opacity: 0.12 })
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -21.15;
shadowPlane.receiveShadow = true;
world.add(shadowPlane);
// Low-poly inclusions in the shallow layer add depth without implying data.
const pebbleGeometry = new THREE.DodecahedronGeometry(0.27, 0);
const pebbleMaterials = [
standardMaterial(0xa98d62, { transparent: true, opacity: 0.48 }),
standardMaterial(0xb49d78, { transparent: true, opacity: 0.42 }),
standardMaterial(0x8f8b68, { transparent: true, opacity: 0.4 })
];
let randomSeed = 9327;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
for (let i = 0; i < 28; i++) {
const pebble = new THREE.Mesh(
pebbleGeometry,
pebbleMaterials[i % pebbleMaterials.length]
);
pebble.position.set(
-9 + random() * 18,
-0.7 - random() * 3.9,
-5.4 + random() * 10.8
);
pebble.rotation.set(random() * 3, random() * 3, random() * 3);
const scale = 0.65 + random() * 0.9;
pebble.scale.setScalar(scale);
soil.add(pebble);
}
// ---------------------------------------------------------------
// Schematic building.
// ---------------------------------------------------------------
const building = new THREE.Group();
world.add(building);
const concrete = standardMaterial(0xe8e4d8);
const concreteSide = standardMaterial(0xc9c8bd);
const roofMaterial = standardMaterial(0xd9d4c7);
const coreMaterial = standardMaterial(0x6f9993, {
transparent: true,
opacity: 0.5,
depthWrite: false
});
floorLevels.forEach((level, index) => {
const slab = box(
building,
[11.2, 0.25, 8.2],
[0, level, 0],
index === floorLevels.length - 1 ? roofMaterial : concrete
);
slab.receiveShadow = true;
if (index < floorLevels.length - 1) {
const lower = level + 0.14;
const upper = floorLevels[index + 1] - 0.14;
const height = upper - lower;
columnX.forEach((x) => {
columnZ.forEach((z) => {
box(
building,
[0.34, height, 0.34],
[x, lower + height / 2, z],
concreteSide
);
});
});
}
});
// Lightweight infill panels preserve a schematic, low-poly appearance.
box(building, [0.18, 2.45, 7.5], [-5.35, 1.68, 0], coreMaterial);
box(building, [0.18, 2.45, 7.5], [5.35, 1.68, 0], coreMaterial);
box(building, [2.1, 2.45, 0.18], [-3.7, 7.48, 3.92], coreMaterial);
// Roof accents and a simple service core.
box(building, [2.3, 1.15, 2.4], [1.6, 12.2, -1.3], concreteSide);
box(building, [11.5, 0.12, 8.5], [0, 11.69, 0], roofMaterial);
// ---------------------------------------------------------------
// Foundation systems.
// ---------------------------------------------------------------
const spreadGroup = new THREE.Group();
const pileGroup = new THREE.Group();
world.add(spreadGroup, pileGroup);
const footingMaterial = standardMaterial(0xc9c6b8);
const contactMaterial = new THREE.MeshBasicMaterial({
color: 0x61c7c1,
transparent: true,
opacity: 0.72,
depthWrite: false,
side: THREE.DoubleSide
});
const pileMaterial = standardMaterial(0xd8894a, {
roughness: 0.62,
metalness: 0.08
});
const pileCapMaterial = standardMaterial(0xb8b6aa);
columnX.forEach((x) => {
columnZ.forEach((z) => {
// Shallow spread footing.
box(
spreadGroup,
[1.7, 0.55, 1.7],
[x, -0.38, z],
footingMaterial
);
box(
spreadGroup,
[0.68, 0.78, 0.68],
[x, 0.22, z],
footingMaterial
);
const contactPatch = new THREE.Mesh(
new THREE.PlaneGeometry(1.55, 1.55),
contactMaterial
);
contactPatch.rotation.x = -Math.PI / 2;
contactPatch.position.set(x, -0.67, z);
contactPatch.renderOrder = 8;
spreadGroup.add(contactPatch);
// Deep pile with cap, shaft, and tip.
box(
pileGroup,
[1.25, 0.38, 1.25],
[x, -0.12, z],
pileCapMaterial
);
const pileTop = -0.22;
const pileTip = -14.45;
const pileLength = pileTop - pileTip;
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.31, pileLength, 8),
pileMaterial
);
shaft.position.set(x, pileTop - pileLength / 2, z);
shaft.castShadow = true;
shaft.receiveShadow = true;
pileGroup.add(shaft);
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.31, 0.75, 8),
pileMaterial
);
tip.rotation.z = Math.PI;
tip.position.set(x, pileTip + 0.375, z);
tip.castShadow = true;
pileGroup.add(tip);
const tipContact = new THREE.Mesh(
new THREE.CircleGeometry(0.62, 16),
contactMaterial
);
tipContact.rotation.x = -Math.PI / 2;
tipContact.position.set(x, pileTip - 0.02, z);
tipContact.renderOrder = 8;
pileGroup.add(tipContact);
});
});
// ---------------------------------------------------------------
// Load path arrows. They are diagrammatic overlays, not force values.
// ---------------------------------------------------------------
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xdf8b45,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xffd19a,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
});
const pulseGeometry = new THREE.SphereGeometry(0.115, 8, 6);
const pulses = [];
function createLoadGroup(endY) {
const group = new THREE.Group();
const topY = 13.2;
let index = 0;
columnX.forEach((x) => {
columnZ.forEach((z) => {
const ox = x + 0.38;
const oz = z + 0.38;
const coneHeight = 0.62;
const baseY = endY + coneHeight;
const shaftLength = topY - baseY;
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, shaftLength, 8),
arrowMaterial
);
shaft.position.set(ox, (topY + baseY) / 2, oz);
shaft.renderOrder = 20;
group.add(shaft);
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.18, coneHeight, 8),
arrowMaterial
);
cone.rotation.z = Math.PI;
cone.position.set(ox, endY + coneHeight / 2, oz);
cone.renderOrder = 20;
group.add(cone);
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
pulse.renderOrder = 21;
group.add(pulse);
pulses.push({
mesh: pulse,
group,
start: topY - 0.3,
end: endY - 0.25,
offset: index * 0.19
});
index++;
});
});
return group;
}
const spreadLoadGroup = createLoadGroup(-0.85);
const pileLoadGroup = createLoadGroup(-14.65);
world.add(spreadLoadGroup, pileLoadGroup);
// ---------------------------------------------------------------
// Projected HTML labels.
// ---------------------------------------------------------------
const labels = [];
function addWorldLabel(text, className, position) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position)
});
return element;
}
addWorldLabel("Schematic building", "building", [0, 13.35, 0]);
addWorldLabel("Upper soil", "soil", [7.7, -2.5, 5.7]);
addWorldLabel("Stronger layer · illustrative", "strong", [7.3, -12.4, 5.7]);
const spreadLabel = addWorldLabel(
"Spread contact footprint",
"contact",
[4.4, -0.9, 3.7]
);
const pileLabel = addWorldLabel(
"Pile shaft + tip contact",
"contact",
[4.6, -10.2, 3.7]
);
function updateLabels() {
labels.forEach((label) => {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
if (!visible) {
label.element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.opacity = "1";
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
});
}
// ---------------------------------------------------------------
// Mode switching and explanatory content.
// ---------------------------------------------------------------
const modeContent = {
spread: {
title: "Spread footings · upper soil",
description:
"Columns transfer load to wider footings, producing a conceptual contact footprint within the shallow soil layer.",
path: "Columns → footings → upper soil",
contact: "Distributed footing footprint"
},
piles: {
title: "Deep piles · stronger layer",
description:
"Columns transfer load through slender piles toward a deeper illustrative stronger layer. The shown depth is not a design recommendation.",
path: "Columns → piles → deeper stronger layer",
contact: "Shaft and tip contact"
}
};
let currentMode = "spread";
let showLoadPaths = true;
function setMode(mode) {
currentMode = mode;
const isSpread = mode === "spread";
spreadGroup.visible = isSpread;
pileGroup.visible = !isSpread;
spreadLoadGroup.visible = isSpread && showLoadPaths;
pileLoadGroup.visible = !isSpread && showLoadPaths;
spreadLabel.style.display = isSpread ? "block" : "none";
pileLabel.style.display = isSpread ? "none" : "block";
document.querySelectorAll(".segmented button").forEach((button) => {
button.setAttribute(
"aria-selected",
String(button.dataset.mode === mode)
);
});
const content = modeContent[mode];
document.getElementById("modeTitle").textContent = content.title;
document.getElementById("modeDescriptionText").textContent =
content.description;
document.getElementById("pathText").textContent = content.path;
document.getElementById("contactText").textContent = content.contact;
}
document.querySelectorAll(".segmented button").forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
document.getElementById("loadToggle").addEventListener("change", (event) => {
showLoadPaths = event.target.checked;
spreadLoadGroup.visible = currentMode === "spread" && showLoadPaths;
pileLoadGroup.visible = currentMode === "piles" && showLoadPaths;
});
// ---------------------------------------------------------------
// Direct camera controls: no examples/addons are imported.
// ---------------------------------------------------------------
const view = {
target: new THREE.Vector3(0, -3.6, 0),
radius: 37,
theta: 0.69,
phi: 1.07
};
const defaultView = {
target: new THREE.Vector3(0, -3.6, 0),
radius: 37,
theta: 0.69,
phi: 1.07
};
function updateCamera() {
const spherical = new THREE.Spherical(view.radius, view.phi, view.theta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(view.target).add(offset);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
function resetView() {
view.target.copy(defaultView.target);
view.radius = defaultView.radius;
view.theta = defaultView.theta;
view.phi = defaultView.phi;
}
document.getElementById("resetButton").addEventListener("click", resetView);
let drag = null;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
drag = {
pointerId: event.pointerId,
button: event.button,
x: event.clientX,
y: event.clientY
};
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || drag.pointerId !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.button === 2) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1)
.normalize();
const panScale = view.radius * 0.0012;
view.target.addScaledVector(right, -dx * panScale);
view.target.addScaledVector(up, dy * panScale);
} else {
view.theta -= dx * 0.0055;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.0048,
0.24,
1.47
);
}
});
function endDrag(event) {
if (drag && drag.pointerId === event.pointerId) drag = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
21,
68
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------
// Animation.
// ---------------------------------------------------------------
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
pulses.forEach((pulse) => {
if (!pulse.group.visible) return;
const progress = (elapsed * 0.24 + pulse.offset) % 1;
const eased = progress * progress * (3 - 2 * progress);
pulse.mesh.position.y = THREE.MathUtils.lerp(
pulse.start,
pulse.end,
eased
);
const pulseScale = reduceMotion
? 1
: 0.82 + Math.sin(progress * Math.PI) * 0.35;
pulse.mesh.scale.setScalar(pulseScale);
});
updateLabels();
renderer.render(scene, camera);
}
setMode("spread");
updateCamera();
animate();
document.getElementById("loading").remove();
</script>
</body>
</html>
```