Prompt specification
Build or customize the Three.js 3D scene "Small house foundation cutaway" 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: Small house foundation cutaway
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-house-foundation-cutaway-x2199
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build a compact house cutaway showing walls, slab, footings, and soil layers. Connect each supported wall to its foundation and separate drainage details from load-bearing elements.
Working Three.js Starter (small-house-foundation-cutaway-x2199):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly House Cutaway</title>
<style>
:root {
--ink: #17333a;
--muted: #60747a;
--panel: rgba(249, 250, 247, 0.91);
--border: rgba(23, 51, 58, 0.14);
--structure: #c7b88d;
--drainage: #168da5;
--soil: #8d6448;
--load: #e59632;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#viewport,
#labels,
#leaders {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#labels,
#leaders {
pointer-events: none;
}
#leaders {
width: 100%;
height: 100%;
overflow: visible;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 14px 40px rgba(28, 53, 58, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 17px 18px 15px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 5px;
color: #4c7b80;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.2vw, 29px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro p {
margin: 9px 0 0;
max-width: 330px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.controls {
top: 18px;
right: 18px;
width: 278px;
padding: 15px;
border-radius: 16px;
}
.controls header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
}
.controls h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.01em;
}
.tiny {
color: var(--muted);
font-size: 10px;
}
.control-group {
padding: 11px 0;
border-top: 1px solid var(--border);
}
.control-group:first-of-type {
padding-top: 0;
border-top: 0;
}
.check {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
cursor: pointer;
font-size: 12px;
}
.check input {
width: 15px;
height: 15px;
margin: 0;
accent-color: #247b83;
}
.range-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
}
.range-row output {
min-width: 35px;
color: var(--ink);
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
width: 100%;
accent-color: var(--drainage);
}
.range-wrap {
grid-column: 1 / -1;
}
.load-path {
padding: 10px;
border-radius: 10px;
background: rgba(229, 150, 50, 0.10);
color: #76511f;
font-size: 10px;
line-height: 1.45;
}
.load-path strong {
display: block;
margin-bottom: 2px;
color: #9b6119;
font-size: 11px;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 12px;
}
button {
flex: 1;
padding: 9px 10px;
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition: background 120ms ease, transform 120ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
.legend {
left: 18px;
bottom: 18px;
padding: 13px 15px;
border-radius: 14px;
}
.legend-title {
margin-bottom: 9px;
font-size: 11px;
font-weight: 800;
}
.legend-grid {
display: grid;
grid-template-columns: repeat(2, auto);
gap: 7px 15px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.swatch {
width: 11px;
height: 11px;
border: 1px solid rgba(0, 0, 0, 0.10);
border-radius: 3px;
}
.swatch.wall { background: #e4d7b9; }
.swatch.concrete { background: #b9b7ae; }
.swatch.drain { background: #168da5; }
.swatch.gravel { background: #83877e; }
.swatch.path { background: #e59632; }
.swatch.soil { background: #a87951; }
.selection {
right: 18px;
bottom: 18px;
width: 278px;
min-height: 92px;
padding: 14px 15px;
border-radius: 14px;
}
.selection .category {
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.selection h3 {
margin: 0 0 4px;
font-size: 14px;
}
.selection p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(249, 250, 247, 0.80);
color: var(--muted);
font-size: 10px;
pointer-events: none;
white-space: nowrap;
}
.label {
position: absolute;
z-index: 3;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-left-width: 3px;
border-radius: 6px;
background: rgba(250, 251, 248, 0.90);
box-shadow: 0 4px 14px rgba(26, 52, 58, 0.10);
color: #29444a;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
transition: opacity 120ms ease;
}
.label.structure { border-left-color: #a39058; }
.label.drainage { border-left-color: var(--drainage); }
.label.soil { border-left-color: var(--soil); }
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #dce8e7;
color: #4a7378;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 820px) {
.intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
}
.intro p { display: none; }
.controls {
top: 101px;
right: 10px;
width: 230px;
max-height: calc(100vh - 220px);
overflow: auto;
}
.legend {
left: 10px;
bottom: 10px;
}
.legend-grid {
grid-template-columns: auto;
}
.selection {
right: 10px;
bottom: 10px;
width: 230px;
}
.hint { display: none; }
}
@media (max-width: 520px) {
.controls {
top: 88px;
width: 205px;
padding: 11px;
}
.legend { display: none; }
.selection { width: 205px; min-height: 74px; }
.label { font-size: 9px; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<section class="panel intro">
<div class="eyebrow">Architectural systems study</div>
<h1>Compact house cutaway</h1>
<p>
Continuous wall-to-slab-to-footing load paths are shown separately from
the blue perimeter drainage assembly. Drag to orbit; shift-drag to pan.
</p>
</section>
<section class="panel controls">
<header>
<h2>Scene controls</h2>
<span class="tiny">Interactive model</span>
</header>
<div class="control-group">
<label class="check">
<input id="toggle-structure" type="checkbox" checked>
Structural system
</label>
<label class="check">
<input id="toggle-interior" type="checkbox" checked>
Interior furnishings
</label>
<label class="check">
<input id="toggle-drainage" type="checkbox" checked>
Drainage assembly
</label>
<label class="check">
<input id="toggle-soil" type="checkbox" checked>
Sectioned soil strata
</label>
<label class="check">
<input id="toggle-paths" type="checkbox" checked>
Load-path arrows
</label>
<label class="check">
<input id="toggle-labels" type="checkbox" checked>
Component labels
</label>
</div>
<div class="control-group">
<div class="range-row">
<span>Drainage separation</span>
<output id="explode-value">35%</output>
<div class="range-wrap">
<input id="explode" type="range" min="0" max="100" value="35">
</div>
</div>
</div>
<div class="load-path">
<strong>Structural load path</strong>
Wall → reinforced slab → continuous stem wall → spread footing → soil
</div>
<div class="button-row">
<button id="reset-view" type="button">Reset view</button>
<button id="reset-selection" type="button">Clear selection</button>
</div>
</section>
<section class="panel legend">
<div class="legend-title">Material / system key</div>
<div class="legend-grid">
<div class="legend-item"><span class="swatch wall"></span>Wall</div>
<div class="legend-item"><span class="swatch concrete"></span>Concrete</div>
<div class="legend-item"><span class="swatch drain"></span>Drainage</div>
<div class="legend-item"><span class="swatch gravel"></span>Filter aggregate</div>
<div class="legend-item"><span class="swatch path"></span>Load path</div>
<div class="legend-item"><span class="swatch soil"></span>Soil strata</div>
</div>
</section>
<section class="panel selection" id="selection-panel">
<div class="category" id="selection-category">Inspection</div>
<h3 id="selection-title">Select a component</h3>
<p id="selection-description">
Click the model to identify structural, soil, and drainage elements.
</p>
</section>
<div class="hint">
Drag: orbit · Shift/right-drag: pan · Wheel/pinch: zoom · R: reset
</div>
<div id="loading">Building cutaway scene…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
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;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e7);
scene.fog = new THREE.Fog(0xdce8e7, 25, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xeaf8f7, 0x7b624a, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.1);
keyLight.position.set(9, 15, 10);
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 = 40;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dce5, 1.0);
fillLight.position.set(-10, 7, -8);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
flatShading: true,
...options
});
const mats = {
wall: material(0xe5d8bb),
wallSide: material(0xcdbf9f),
cutWall: material(0xf0e6ce),
concrete: material(0xb9b8af),
concreteDark: material(0x93968f),
slab: material(0xc9c9bf),
wood: material(0x9f7047),
woodLight: material(0xc39a67),
cabinet: material(0xd6dfd5),
countertop: material(0x6e7775),
upholstery: material(0x6d9290),
metal: material(0x8d999b, { metalness: 0.3, roughness: 0.55 }),
pipe: material(0x168da5, { roughness: 0.48 }),
pipeDark: material(0x075365, { roughness: 0.65 }),
fabric: material(0x95cdd0, {
transparent: true,
opacity: 0.68,
depthWrite: false
}),
gravel: material(0x858981),
gravelLight: material(0xa3a39a),
gravelDark: material(0x656a65),
glass: material(0x8bc4cf, {
transparent: true,
opacity: 0.48,
roughness: 0.18,
metalness: 0.08,
depthWrite: false,
side: THREE.DoubleSide
}),
frame: material(0x6b5844),
grass: material(0x769565),
grassDark: material(0x5f8154),
floor: material(0xd7ded7)
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x44545a,
transparent: true,
opacity: 0.18,
depthWrite: false
});
function box(parent, size, position, mat, withEdges = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (withEdges) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 24),
edgeMaterial.clone()
);
mesh.add(edges);
}
return mesh;
}
function cylinder(
parent,
radius,
length,
position,
mat,
axis = "y",
radialSegments = 10
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
),
mat
);
mesh.position.set(position[0], position[1], position[2]);
if (axis === "x") mesh.rotation.z = Math.PI / 2;
if (axis === "z") mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function component(group, title, description, category) {
group.userData.component = { title, description, category };
return group;
}
function visibleInHierarchy(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(73421);
const structuralGroup = new THREE.Group();
const foundationGroup = new THREE.Group();
const wallGroup = new THREE.Group();
const slabGroup = new THREE.Group();
const interiorGroup = new THREE.Group();
const soilGroup = new THREE.Group();
const drainageGroup = new THREE.Group();
const loadPathGroup = new THREE.Group();
scene.add(
structuralGroup,
interiorGroup,
soilGroup,
drainageGroup,
loadPathGroup
);
structuralGroup.add(foundationGroup, wallGroup, slabGroup);
component(
structuralGroup,
"Structural system",
"Walls, bearing pads, reinforced slab, continuous stem walls, and spread footings form the gravity-load path.",
"structure"
);
component(
foundationGroup,
"Strip foundations",
"Continuous concrete stem walls and widened spread footings support every exterior wall and the central partition. The front section is exposed by the excavation.",
"structure"
);
component(
wallGroup,
"Load-bearing walls",
"Exterior walls and the central partition bear on continuous concrete pads over the slab, with foundations directly below.",
"structure"
);
component(
slabGroup,
"Reinforced concrete slab",
"The floor slab spans between perimeter foundations and distributes wall loads to the continuous stems and footings.",
"structure"
);
component(
soilGroup,
"Sectioned soil strata",
"The soil block is cut open to reveal the relationship between shallow footings and deeper competent strata.",
"soil"
);
component(
drainageGroup,
"Non-structural drainage assembly",
"Perforated pipe, filter fabric, aggregate, cleanout, and catch basin are shown as a separate cyan system outside the structural footing envelope.",
"drainage"
);
// -------------------------------------------------------------------------
// Soil block with an open front-center inspection section
// -------------------------------------------------------------------------
const soilLayers = [
{
name: "Bedrock",
bottom: -3.25,
top: -2.25,
color: 0x665f58
},
{
name: "Clay",
bottom: -2.25,
top: -1.10,
color: 0x9a6848
},
{
name: "Sandy subsoil",
bottom: -1.10,
top: -0.25,
color: 0xb08a60
},
{
name: "Topsoil",
bottom: -0.25,
top: 0,
color: 0x7d8b62
}
];
const xMin = -6.3;
const xMax = 6.3;
const zMin = -5;
const zMax = 5;
const sectionZ = 1.35;
const notchHalfWidth = 5.05;
for (const layer of soilLayers) {
const height = layer.top - layer.bottom;
const centerY = (layer.top + layer.bottom) / 2;
const mat = material(layer.color);
// Back volume, ending at the visible section plane.
box(
soilGroup,
[xMax - xMin, height, sectionZ - zMin],
[
0,
centerY,
(zMin + sectionZ) / 2
],
mat,
true
);
// Side wings preserve the outside ground while exposing the house section.
const wingWidth = xMax - notchHalfWidth;
const wingDepth = zMax - sectionZ;
const wingCenterX = notchHalfWidth + wingWidth / 2;
const wingCenterZ = sectionZ + wingDepth / 2;
box(
soilGroup,
[wingWidth, height, wingDepth],
[-wingCenterX, centerY, wingCenterZ],
mat,
true
);
box(
soilGroup,
[wingWidth, height, wingDepth],
[wingCenterX, centerY, wingCenterZ],
mat,
true
);
}
// Small low-poly stones exposed on the section face.
const stoneGeometry = new THREE.IcosahedronGeometry(0.09, 0);
for (let i = 0; i < 44; i++) {
const layerIndex = i % 3;
const layer = soilLayers[layerIndex];
const stone = new THREE.Mesh(
stoneGeometry,
i % 2 ? mats.gravelDark : mats.gravel
);
stone.position.set(
-4.7 + random() * 9.4,
layer.bottom + 0.15 + random() * Math.max(0.12, layer.top - layer.bottom - 0.3),
1.365
);
stone.scale.set(
0.65 + random() * 0.9,
0.5 + random() * 0.7,
0.35 + random() * 0.35
);
stone.rotation.set(random() * 3, random() * 3, random() * 3);
soilGroup.add(stone);
}
// Sparse angular grass clumps on the remaining top surface.
const grassGeometry = new THREE.ConeGeometry(0.13, 0.32, 4);
for (let i = 0; i < 32; i++) {
let x = -6.05 + random() * 12.1;
let z = -4.75 + random() * 9.5;
const inHouse = Math.abs(x) < 4.7 && Math.abs(z) < 3.55;
const inOpening = Math.abs(x) < 5.05 && z > sectionZ;
if (inHouse || inOpening) continue;
const grass = new THREE.Mesh(
grassGeometry,
i % 3 ? mats.grass : mats.grassDark
);
grass.position.set(x, 0.14, z);
grass.rotation.y = random() * Math.PI;
grass.scale.setScalar(0.7 + random() * 0.8);
grass.castShadow = true;
soilGroup.add(grass);
}
// -------------------------------------------------------------------------
// Foundation system: slab → bearing pads → walls
// -------------------------------------------------------------------------
const slab = box(
slabGroup,
[8.45, 0.26, 6.45],
[0, 0.13, 0],
mats.slab,
true
);
slab.userData.component = {
title: "Reinforced concrete slab",
description:
"The slab rests on the continuous perimeter stems and central foundation strip, tying the separate wall foundations into one structural system.",
category: "structure"
};
// Continuous bearing pads directly under every supported wall.
box(foundationGroup, [8.35, 0.12, 0.34], [0, 0.32, -3.05], mats.concrete);
box(foundationGroup, [8.35, 0.12, 0.34], [0, 0.32, 3.05], mats.concrete);
box(foundationGroup, [0.34, 0.12, 6.10], [-4.10, 0.32, 0], mats.concrete);
box(foundationGroup, [0.34, 0.12, 6.10], [4.10, 0.32, 0], mats.concrete);
box(foundationGroup, [0.34, 0.12, 4.70], [0, 0.32, -0.70], mats.concrete);
// Continuous perimeter stem walls below the slab.
box(foundationGroup, [8.35, 1.10, 0.62], [0, -0.29, -3.05], mats.concrete, true);
box(foundationGroup, [8.35, 1.10, 0.62], [0, -0.29, 3.05], mats.concrete, true);
box(foundationGroup, [0.62, 1.10, 6.10], [-4.10, -0.29, 0], mats.concrete, true);
box(foundationGroup, [0.62, 1.10, 6.10], [4.10, -0.29, 0], mats.concrete, true);
// Central partition foundation strip.
box(foundationGroup, [0.52, 1.10, 4.70], [0, -0.29, -0.70], mats.concrete, true);
// Widened strip footings below each stem wall.
box(foundationGroup, [9.15, 0.44, 1.08], [0, -1.06, -3.05], mats.concreteDark, true);
box(foundationGroup, [9.15, 0.44, 1.08], [0, -1.06, 3.05], mats.concreteDark, true);
box(foundationGroup, [1.08, 0.44, 6.85], [-4.10, -1.06, 0], mats.concreteDark, true);
box(foundationGroup, [1.08, 0.44, 6.85], [4.10, -1.06, 0], mats.concreteDark, true);
box(foundationGroup, [1.02, 0.44, 5.25], [0, -1.06, -0.70], mats.concreteDark, true);
// Rebar-like dots on the exposed front spread footing.
for (let i = 0; i < 13; i++) {
const rebar = cylinder(
foundationGroup,
0.026,
0.026,
[-3.85 + i * 0.64, -1.06, 3.596],
mats.metal,
"z",
8
);
rebar.castShadow = false;
}
// -------------------------------------------------------------------------
// Cutaway walls, windows, and central partition
// -------------------------------------------------------------------------
const WALL_BOTTOM = 0.38;
const WALL_TOP = 3.55;
function wallBox(size, position, mat = mats.wall) {
return box(wallGroup, size, position, mat, true);
}
// Back wall with a large window opening.
const backOpeningLeft = -2.50;
const backOpeningRight = 0.00;
const openingBottom = 1.25;
const openingTop = 2.55;
wallBox(
[backOpeningLeft + 4.10, WALL_TOP - WALL_BOTTOM, 0.24],
[(-4.10 + backOpeningLeft) / 2, (WALL_TOP + WALL_BOTTOM) / 2, -3.05]
);
wallBox(
[4.10 - backOpeningRight, WALL_TOP - WALL_BOTTOM, 0.24],
[(4.10 + backOpeningRight) / 2, (WALL_TOP + WALL_BOTTOM) / 2, -3.05]
);
wallBox(
[backOpeningRight - backOpeningLeft, openingBottom - WALL_BOTTOM, 0.24],
[
(backOpeningLeft + backOpeningRight) / 2,
(WALL_BOTTOM + openingBottom) / 2,
-3.05
]
);
wallBox(
[backOpeningRight - backOpeningLeft, WALL_TOP - openingTop, 0.24],
[
(backOpeningLeft + backOpeningRight) / 2,
(openingTop + WALL_TOP) / 2,
-3.05
]
);
// Back window glass and frame.
box(
wallGroup,
[2.31, 1.12, 0.035],
[-1.25, 1.90, -3.05],
mats.glass
);
box(wallGroup, [0.08, 1.30, 0.13], [-2.43, 1.90, -2.91], mats.frame);
box(wallGroup, [0.08, 1.30, 0.13], [-0.07, 1.90, -2.91], mats.frame);
box(wallGroup, [2.44, 0.08, 0.13], [-1.25, 1.29, -2.91], mats.frame);
box(wallGroup, [2.44, 0.08, 0.13], [-1.25, 2.51, -2.91], mats.frame);
// Left wall with a second window opening.
const leftOpeningBack = -0.50;
const leftOpeningFront = 1.40;
wallBox(
[0.24, WALL_TOP - WALL_BOTTOM, leftOpeningBack + 3.05],
[-4.10, (WALL_TOP + WALL_BOTTOM) / 2, (-3.05 + leftOpeningBack) / 2]
);
wallBox(
[0.24, WALL_TOP - WALL_BOTTOM, 3.05 - leftOpeningFront],
[-4.10, (WALL_TOP + WALL_BOTTOM) / 2, (leftOpeningFront + 3.05) / 2]
);
wallBox(
[0.24, openingBottom - WALL_BOTTOM, leftOpeningFront - leftOpeningBack],
[
-4.10,
(WALL_BOTTOM + openingBottom) / 2,
(leftOpeningBack + leftOpeningFront) / 2
]
);
wallBox(
[0.24, WALL_TOP - openingTop, leftOpeningFront - leftOpeningBack],
[
-4.10,
(openingTop + WALL_TOP) / 2,
(leftOpeningBack + leftOpeningFront) / 2
]
);
box(
wallGroup,
[0.035, 1.12, 1.72],
[-4.10, 1.90, 0.45],
mats.glass
);
box(wallGroup, [0.13, 1.30, 0.08], [-3.96, 1.90, -0.43], mats.frame);
box(wallGroup, [0.13, 1.30, 0.08], [-3.96, 1.90, 1.33], mats.frame);
box(wallGroup, [0.13, 0.08, 1.84], [-3.96, 1.29, 0.45], mats.frame);
box(wallGroup, [0.13, 0.08, 1.84], [-3.96, 2.51, 0.45], mats.frame);
// Right wall: rear full-height section plus a low cutaway section.
wallBox(
[0.24, WALL_TOP - WALL_BOTTOM, 2.15],
[4.10, (WALL_TOP + WALL_BOTTOM) / 2, -1.975]
);
wallBox(
[0.24, 0.72, 3.95],
[4.10, WALL_BOTTOM + 0.36, 1.075],
mats.cutWall
);
// Front wall remnants make the cutaway explicit while retaining support.
wallBox(
[1.10, 0.72, 0.24],
[-3.55, WALL_BOTTOM + 0.36, 3.05],
mats.cutWall
);
wallBox(
[1.10, 0.72, 0.24],
[3.55, WALL_BOTTOM + 0.36, 3.05],
mats.cutWall
);
// Central load-bearing partition with a door opening.
const partitionTop = 2.95;
const partitionDoorBack = 0.25;
const partitionDoorFront = 1.40;
const doorHead = 2.15;
wallBox(
[0.16, partitionTop - WALL_BOTTOM, partitionDoorBack + 3.05],
[0, (partitionTop + WALL_BOTTOM) / 2, (-3.05 + partitionDoorBack) / 2],
mats.wallSide
);
wallBox(
[0.16, partitionTop - WALL_BOTTOM, 1.65 - partitionDoorFront],
[0, (partitionTop + WALL_BOTTOM) / 2, (partitionDoorFront + 1.65) / 2],
mats.wallSide
);
wallBox(
[0.16, partitionTop - doorHead, partitionDoorFront - partitionDoorBack],
[0, (doorHead + partitionTop) / 2, (partitionDoorBack + partitionDoorFront) / 2],
mats.wallSide
);
// -------------------------------------------------------------------------
// Lightweight low-poly interior
// -------------------------------------------------------------------------
component(
interiorGroup,
"Interior furnishings",
"Simple furniture provides scale and makes the cutaway rooms readable without obscuring the structural section.",
"interior"
);
// Kitchen run.
box(interiorGroup, [3.35, 0.76, 0.72], [2.20, 0.64, -2.56], mats.cabinet, true);
box(interiorGroup, [3.47, 0.10, 0.82], [2.20, 1.07, -2.56], mats.countertop, true);
for (let i = 0; i < 5; i++) {
box(
interiorGroup,
[0.025, 0.60, 0.025],
[0.78 + i * 0.71, 0.65, -2.185],
mats.metal
);
}
box(interiorGroup, [0.78, 0.035, 0.46], [2.50, 1.135, -2.52], mats.metal);
box(interiorGroup, [0.40, 0.42, 0.38], [3.45, 1.36, -2.58], mats.countertop, true);
// Refrigerator.
box(interiorGroup, [0.78, 1.55, 0.72], [3.88, 1.04, -2.52], mats.cabinet, true);
box(interiorGroup, [0.025, 0.48, 0.04], [3.47, 1.10, -2.15], mats.metal);
// Round table and chairs.
cylinder(interiorGroup, 0.72, 0.10, [1.35, 1.04, -0.15], mats.woodLight, "y", 12);
cylinder(interiorGroup, 0.10, 0.76, [1.35, 0.62, -0.15], mats.wood, "y", 8);
for (const angle of [0, 2.1, 4.2]) {
const x = 1.35 + Math.cos(angle) * 1.18;
const z = -0.15 + Math.sin(angle) * 1.18;
box(interiorGroup, [0.42, 0.08, 0.42], [x, 0.73, z], mats.woodLight, true);
box(interiorGroup, [0.42, 0.50, 0.08], [x, 0.99, z + 0.18], mats.woodLight, true);
}
// Sofa in the front-left room.
box(interiorGroup, [1.95, 0.36, 0.78], [-2.55, 0.48, 1.70], mats.upholstery, true);
box(interiorGroup, [1.95, 0.60, 0.18], [-2.55, 0.78, 2.04], mats.upholstery, true);
box(interiorGroup, [0.18, 0.48, 0.78], [-3.48, 0.67, 1.70], mats.upholstery, true);
box(interiorGroup, [0.18, 0.48, 0.78], [-1.62, 0.67, 1.70], mats.upholstery, true);
// -------------------------------------------------------------------------
// Drainage system: separate color, footprint, and components
// -------------------------------------------------------------------------
const filterGroup = new THREE.Group();
const pipeGroup = new THREE.Group();
const basinGroup = new THREE.Group();
drainageGroup.add(filterGroup, pipeGroup, basinGroup);
component(
filterGroup,
"Filter fabric and aggregate envelope",
"A pale filter fabric layer and coarse aggregate surround the perforated pipe. This assembly is non-load-bearing and remains outside the foundation strips.",
"drainage"
);
component(
pipeGroup,
"Perforated drainage pipe",
"The cyan perforated pipe collects groundwater through perforations and conveys it toward the catch basin. It does not support the house.",
"drainage"
);
component(
basinGroup,
"Catch basin and cleanout",
"A removable-grate catch basin collects the perforated pipe run. A vertical cleanout provides access to the drain, while a separate outlet leads away from the foundation.",
"drainage"
);
// Filter fabric strips.
box(filterGroup, [9.70, 0.035, 0.72], [0, -0.59, 3.90], mats.fabric);
box(filterGroup, [0.72, 0.035, 2.70], [-4.80, -0.59, 2.58], mats.fabric);
box(filterGroup, [0.72, 0.035, 2.70], [4.80, -0.59, 2.58], mats.fabric);
// Aggregate beds.
box(filterGroup, [9.70, 0.20, 0.64], [0, -0.47, 3.90], mats.gravel);
box(filterGroup, [0.64, 0.20, 2.70], [-4.80, -0.47, 2.58], mats.gravel);
box(filterGroup, [0.64, 0.20, 2.70], [4.80, -0.47, 2.58], mats.gravel);
// Main perforated pipes.
cylinder(pipeGroup, 0.14, 9.60, [0, -0.22, 3.90], mats.pipe, "x", 12);
cylinder(pipeGroup, 0.14, 2.70, [-4.80, -0.22, 2.58], mats.pipe, "z", 12);
cylinder(pipeGroup, 0.14, 2.70, [4.80, -0.22, 2.58], mats.pipe, "z", 12);
// Dark perforation marks on the visible upper surfaces.
for (let x = -4.50; x <= 4.51; x += 0.42) {
cylinder(
pipeGroup,
0.026,
0.020,
[x, -0.076, 3.90],
mats.pipeDark,
"y",
8
);
}
for (const x of [-4.80, 4.80]) {
for (let z = 1.48; z <= 3.70; z += 0.42) {
cylinder(
pipeGroup,
0.026,
0.020,
[x, -0.076, z],
mats.pipeDark,
"y",
8
);
}
}
// Extra perforation marks on the camera-facing side of the right pipe.
for (let z = 1.55; z <= 3.70; z += 0.46) {
cylinder(
pipeGroup,
0.025,
0.020,
[4.94, -0.22, z],
mats.pipeDark,
"x",
8
);
}
// Loose angular aggregate around the pipe.
const gravelGeometry = new THREE.IcosahedronGeometry(0.085, 0);
const gravelMaterials = [mats.gravel, mats.gravelLight, mats.gravelDark];
function gravelChip(parent, x, y, z, scale = 1) {
const chip = new THREE.Mesh(
gravelGeometry,
gravelMaterials[Math.floor(random() * gravelMaterials.length)]
);
chip.position.set(x, y, z);
chip.scale.set(
scale * (0.75 + random() * 0.7),
scale * (0.65 + random() * 0.8),
scale * (0.75 + random() * 0.7)
);
chip.rotation.set(random() * 3, random() * 3, random() * 3);
chip.receiveShadow = true;
parent.add(chip);
}
for (let i = 0; i < 85; i++) {
const x = -4.65 + random() * 9.3;
const side = random() > 0.5 ? 1 : -1;
const z = 3.90 + side * (0.17 + random() * 0.15);
gravelChip(filterGroup, x, -0.28 + random() * 0.09, z, 0.7 + random() * 0.7);
}
for (const x of [-4.80, 4.80]) {
for (let i = 0; i < 27; i++) {
const z = 1.30 + random() * 2.55;
const side = random() > 0.5 ? 1 : -1;
gravelChip(
filterGroup,
x + side * (0.17 + random() * 0.15),
-0.28 + random() * 0.09,
z,
0.7 + random() * 0.7
);
}
}
// Catch basin.
box(basinGroup, [1.00, 0.42, 0.94], [4.78, -0.17, 3.90], mats.pipeDark, true);
box(basinGroup, [0.86, 0.07, 0.80], [4.78, 0.075, 3.90], mats.pipe, true);
for (let i = 0; i < 6; i++) {
box(
basinGroup,
[0.055, 0.035, 0.72],
[4.43 + i * 0.14, 0.13, 3.90],
mats.pipeDark
);
}
// Cleanout riser and cap.
cylinder(basinGroup, 0.15, 1.10, [-3.60, 0.32, 3.90], mats.pipe, "y", 10);
cylinder(basinGroup, 0.22, 0.09, [-3.60, 0.91, 3.90], mats.pipeDark, "y", 10);
// Separate outlet and directional marker.
cylinder(basinGroup, 0.11, 0.95, [4.78, -0.25, 4.48], mats.pipe, "z", 10);
const outletArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 0.36, 8),
mats.pipeDark
);
outletArrow.position.set(4.78, -0.25, 5.02);
outletArrow.rotation.x = Math.PI / 2;
basinGroup.add(outletArrow);
// -------------------------------------------------------------------------
// Load-path arrows
// -------------------------------------------------------------------------
const pathMaterial = new THREE.LineDashedMaterial({
color: 0xe59632,
dashSize: 0.14,
gapSize: 0.10,
transparent: true,
opacity: 0.9,
depthTest: false
});
const pathHeadMaterial = new THREE.MeshBasicMaterial({
color: 0xe59632,
depthTest: false,
transparent: true,
opacity: 0.95
});
function loadPath(x, z, top = 2.4) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, top, z),
new THREE.Vector3(x, -1.02, z)
]);
const line = new THREE.Line(geometry, pathMaterial);
line.computeLineDistances();
line.renderOrder = 8;
loadPathGroup.add(line);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.30, 8),
pathHeadMaterial
);
arrow.position.set(x, -1.03, z);
arrow.rotation.z = Math.PI;
arrow.renderOrder = 9;
loadPathGroup.add(arrow);
}
loadPath(-3.45, -3.05, 2.70);
loadPath(-4.10, -2.05, 2.70);
loadPath(4.10, 2.00, 2.70);
loadPath(3.45, 3.05, 1.05);
loadPath(0, 1.48, 2.70);
// -------------------------------------------------------------------------
// Ground and contact shadows
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
material(0xd5e1df)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -3.27;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Custom orbit, pan, zoom, and touch controls
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, -0.35, 0.20);
const desiredTarget = target.clone();
let radius = 18.5;
let desiredRadius = 18.5;
let theta = 0.72;
let desiredTheta = 0.72;
let phi = 1.02;
let desiredPhi = 1.02;
const pointers = new Map();
let mouseMode = "orbit";
let gestureMidX = 0;
let gestureMidY = 0;
let gestureDistance = 0;
function orbitBy(dx, dy) {
desiredTheta -= dx * 0.006;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - dy * 0.006,
0.30,
1.48
);
}
function panBy(dx, dy) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, new THREE.Vector3(0, 1, 0))
.normalize();
const scale = radius * 0.0015;
desiredTarget.addScaledVector(right, -dx * scale);
desiredTarget.y += dy * scale;
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -7, 7);
desiredTarget.y = THREE.MathUtils.clamp(desiredTarget.y, -2.6, 3.0);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -7, 7);
}
function zoomBy(factor) {
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * factor,
8.5,
30
);
}
function updateGesture() {
const values = [...pointers.values()];
if (values.length < 2) {
gestureDistance = 0;
return;
}
gestureMidX = (values[0].x + values[1].x) / 2;
gestureMidY = (values[0].y + values[1].y) / 2;
gestureDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (event.pointerType === "mouse") {
mouseMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
}
updateGesture();
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) {
updateHover(event);
return;
}
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (event.pointerType === "mouse" && mouseMode === "pan") {
panBy(dx, dy);
} else {
orbitBy(dx, dy);
}
} else if (pointers.size === 2) {
const oldMidX = gestureMidX;
const oldMidY = gestureMidY;
const oldDistance = gestureDistance;
updateGesture();
if (oldDistance > 0 && gestureDistance > 0) {
panBy(gestureMidX - oldMidX, gestureMidY - oldMidY);
zoomBy(oldDistance / gestureDistance);
}
}
});
canvas.addEventListener("pointerup", event => {
const start = pointers.get(event.pointerId);
if (
start &&
event.pointerType === "mouse" &&
event.button === 0 &&
Math.hypot(event.clientX - start.x, event.clientY - start.y) < 6
) {
selectAt(event);
}
pointers.delete(event.pointerId);
updateGesture();
});
canvas.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
updateGesture();
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
zoomBy(Math.exp(event.deltaY * 0.001));
}, { passive: false });
function resetView() {
desiredTarget.set(0, -0.35, 0.20);
desiredRadius = 18.5;
desiredTheta = 0.72;
desiredPhi = 1.02;
}
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "ArrowLeft") desiredTheta += 0.08;
if (event.key === "ArrowRight") desiredTheta -= 0.08;
if (event.key === "ArrowUp") desiredPhi -= 0.06;
if (event.key === "ArrowDown") desiredPhi += 0.06;
if (event.key === "+" || event.key === "=") zoomBy(0.90);
if (event.key === "-" || event.key === "_") zoomBy(1.10);
});
// -------------------------------------------------------------------------
// Picking and selection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let selectedObject = null;
let selectionBox = null;
function findComponent(object) {
let current = object;
while (current) {
if (current.userData.component) return current.userData.component;
current = current.parent;
}
return null;
}
function hitAt(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 intersections = raycaster.intersectObjects(scene.children, true);
for (const intersection of intersections) {
if (!intersection.object.isMesh) continue;
if (!visibleInHierarchy(intersection.object)) continue;
const info = findComponent(intersection.object);
if (info) return { object: intersection.object, info };
}
return null;
}
function selectAt(event) {
const hit = hitAt(event);
if (!hit) {
clearSelection();
return;
}
selectedObject = hit.object;
if (!selectionBox) {
selectionBox = new THREE.BoxHelper(selectedObject, 0xe59632);
selectionBox.material.depthTest = false;
selectionBox.material.transparent = true;
selectionBox.material.opacity = 0.95;
selectionBox.renderOrder = 20;
scene.add(selectionBox);
} else {
selectionBox.setFromObject(selectedObject);
}
document.getElementById("selection-category").textContent =
hit.info.category === "drainage"
? "Drainage — non-structural"
: hit.info.category === "soil"
? "Geotechnical section"
: "Structural element";
document.getElementById("selection-title").textContent = hit.info.title;
document.getElementById("selection-description").textContent =
hit.info.description;
}
function updateHover(event) {
const hit = hitAt(event);
canvas.style.cursor = hit ? "pointer" : "grab";
}
function clearSelection() {
selectedObject = null;
if (selectionBox) selectionBox.visible = false;
document.getElementById("selection-category").textContent = "Inspection";
document.getElementById("selection-title").textContent = "Select a component";
document.getElementById("selection-description").textContent =
"Click the model to identify structural, soil, and drainage elements.";
}
document.getElementById("reset-selection").addEventListener("click", clearSelection);
document.getElementById("reset-view").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
const toggleStructure = document.getElementById("toggle-structure");
const toggleInterior = document.getElementById("toggle-interior");
const toggleDrainage = document.getElementById("toggle-drainage");
const toggleSoil = document.getElementById("toggle-soil");
const togglePaths = document.getElementById("toggle-paths");
const toggleLabels = document.getElementById("toggle-labels");
const explodeInput = document.getElementById("explode");
const explodeValue = document.getElementById("explode-value");
toggleStructure.addEventListener("change", () => {
structuralGroup.visible = toggleStructure.checked;
loadPathGroup.visible = togglePaths.checked && toggleStructure.checked;
if (!toggleStructure.checked) clearSelection();
});
toggleInterior.addEventListener("change", () => {
interiorGroup.visible = toggleInterior.checked;
});
toggleDrainage.addEventListener("change", () => {
drainageGroup.visible = toggleDrainage.checked;
if (!toggleDrainage.checked) clearSelection();
});
toggleSoil.addEventListener("change", () => {
soilGroup.visible = toggleSoil.checked;
});
togglePaths.addEventListener("change", () => {
loadPathGroup.visible = togglePaths.checked && toggleStructure.checked;
});
toggleLabels.addEventListener("change", () => {
labelsEnabled = toggleLabels.checked;
});
let explosionTarget = Number(explodeInput.value) / 100;
let explosionCurrent = explosionTarget;
explodeInput.addEventListener("input", () => {
explosionTarget = Number(explodeInput.value) / 100;
explodeValue.textContent = `${explodeInput.value}%`;
});
// -------------------------------------------------------------------------
// Projected HTML labels and leader lines
// -------------------------------------------------------------------------
const labelsLayer = document.getElementById("labels");
const leadersLayer = document.getElementById("leaders");
let labelsEnabled = true;
const labelDefinitions = [
{
text: "Load-bearing wall",
category: "structure",
group: structuralGroup,
anchor: new THREE.Vector3(-3.25, 2.55, -3.05),
offset: [-72, -38]
},
{
text: "Reinforced slab",
category: "structure",
group: structuralGroup,
anchor: new THREE.Vector3(1.25, 0.30, 2.50),
offset: [42, 28]
},
{
text: "Strip footing",
category: "structure",
group: structuralGroup,
anchor: new THREE.Vector3(0.90, -1.04, 3.12),
offset: [42, 54]
},
{
text: "Central partition",
category: "structure",
group: structuralGroup,
anchor: new THREE.Vector3(0.08, 1.85, 0.05),
offset: [60, -18]
},
{
text: "Perforated drain pipe",
category: "drainage",
group: drainageGroup,
anchor: new THREE.Vector3(-0.30, -0.10, 3.90),
offset: [-25, 61]
},
{
text: "Filter aggregate",
category: "drainage",
group: drainageGroup,
anchor: new THREE.Vector3(-2.80, -0.34, 4.04),
offset: [-90, 38]
},
{
text: "Catch basin",
category: "drainage",
group: drainageGroup,
anchor: new THREE.Vector3(4.78, 0.13, 3.90),
offset: [70, -37]
},
{
text: "Sectioned soil strata",
category: "soil",
group: soilGroup,
anchor: new THREE.Vector3(3.90, -1.18, 1.37),
offset: [82, 0]
}
];
const labelColor = {
structure: "#a39058",
drainage: "#168da5",
soil: "#8d6448"
};
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `label ${definition.category}`;
element.textContent = definition.text;
labelsLayer.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", labelColor[definition.category]);
line.setAttribute("stroke-width", "1.2");
line.setAttribute("stroke-opacity", "0.65");
leadersLayer.appendChild(line);
definition.element = element;
definition.line = line;
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
if (
!labelsEnabled ||
!visibleInHierarchy(definition.group) ||
(definition.group === structuralGroup && !structuralGroup.visible)
) {
definition.element.style.display = "none";
definition.line.style.display = "none";
continue;
}
projected.copy(definition.anchor);
if (definition.group === drainageGroup) {
projected.y += drainageGroup.position.y;
}
projected.project(camera);
if (projected.z < -1 || projected.z > 1) {
definition.element.style.display = "none";
definition.line.style.display = "none";
continue;
}
const screenX = (projected.x * 0.5 + 0.5) * width;
const screenY = (-projected.y * 0.5 + 0.5) * height;
const labelX = THREE.MathUtils.clamp(
screenX + definition.offset[0],
65,
width - 65
);
const labelY = THREE.MathUtils.clamp(
screenY + definition.offset[1],
35,
height - 35
);
definition.element.style.display = "block";
definition.element.style.left = `${labelX}px`;
definition.element.style.top = `${labelY}px`;
definition.line.style.display = "block";
definition.line.setAttribute("x1", screenX);
definition.line.setAttribute("y1", screenY);
definition.line.setAttribute("x2", labelX);
definition.line.setAttribute("y2", labelY);
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
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);
function animate() {
requestAnimationFrame(animate);
const damping = 0.12;
theta += (desiredTheta - theta) * damping;
phi += (desiredPhi - phi) * damping;
radius += (desiredRadius - radius) * damping;
target.lerp(desiredTarget, damping);
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
explosionCurrent += (explosionTarget - explosionCurrent) * 0.08;
// Lift and slightly expand the drainage ring to separate it visually
// from the structural foundation without changing its relative layout.
drainageGroup.position.y = explosionCurrent * 0.72;
const drainScale = 1 + explosionCurrent * 0.075;
drainageGroup.scale.set(drainScale, 1, drainScale);
if (selectionBox && selectedObject) {
if (visibleInHierarchy(selectedObject)) {
selectionBox.visible = true;
selectionBox.setFromObject(selectedObject);
} else {
selectionBox.visible = false;
}
}
updateLabels();
renderer.render(scene, camera);
}
document.getElementById("loading")?.remove();
animate();
</script>
</body>
</html>
```