Prompt specification
Build or customize the Three.js 3D scene "Wall corner with a continuous insulation layer" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Wall corner with a continuous insulation layer
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wall-corner-with-a-continuous-insulation-layer-x2178
Scene Description Prompt:
Create a wall-to-roof corner cutaway and trace the insulation around it. Highlight any deliberate gap without inventing numerical heat-loss values unsupported by the model. Use Three.js from cdnjs in a single HTML file, with a 3D cutaway.
Working Three.js Starter (wall-corner-with-a-continuous-insulation-layer-x2178):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Wall-to-Roof Insulation Cutaway</title>
<style>
:root {
--bg: #07111b;
--panel: rgba(12, 24, 36, 0.88);
--panel-border: rgba(170, 210, 230, 0.16);
--text: #e8f1f5;
--muted: #9fb2bf;
--cyan: #49d7e8;
--cyan-soft: rgba(73, 215, 232, 0.14);
--amber: #ffad42;
--amber-soft: rgba(255, 173, 66, 0.14);
--shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
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;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.header {
position: absolute;
top: 26px;
left: 28px;
max-width: min(540px, calc(100vw - 56px));
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
font-weight: 650;
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.status {
position: absolute;
top: 27px;
right: 28px;
padding: 10px 13px;
border: 1px solid rgba(255, 173, 66, 0.35);
border-radius: 999px;
background: rgba(30, 22, 15, 0.76);
color: #ffd39a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.status::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 8px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 12px var(--amber);
vertical-align: 1px;
}
.controls {
position: absolute;
top: 80px;
right: 28px;
display: flex;
flex-direction: column;
gap: 8px;
width: 186px;
pointer-events: auto;
}
.controls button {
width: 100%;
padding: 11px 12px;
border: 1px solid var(--panel-border);
border-radius: 10px;
background: var(--panel);
color: var(--muted);
font: inherit;
font-size: 12px;
text-align: left;
cursor: pointer;
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.controls button:hover {
color: var(--text);
border-color: rgba(73, 215, 232, 0.42);
transform: translateX(-2px);
}
.controls button.active {
color: var(--cyan);
border-color: rgba(73, 215, 232, 0.42);
background:
linear-gradient(90deg, var(--cyan-soft), transparent),
var(--panel);
}
.button-row {
display: flex;
align-items: center;
gap: 8px;
}
.button-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.observation {
position: absolute;
left: 28px;
bottom: 28px;
width: min(390px, calc(100vw - 56px));
padding: 17px 18px 16px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.observation-title {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--amber);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.observation-title::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 173, 66, 0.72);
}
.observation p {
margin: 0;
color: #c7d3da;
font-size: 12px;
line-height: 1.55;
}
.observation p + p {
margin-top: 8px;
}
.disclaimer {
color: #8298a6 !important;
font-size: 11px !important;
}
.legend {
position: absolute;
right: 28px;
bottom: 28px;
min-width: 200px;
padding: 14px 16px;
border: 1px solid var(--panel-border);
border-radius: 12px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: #c3d0d8;
font-size: 11px;
}
.swatch {
width: 20px;
height: 4px;
border-radius: 99px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(73, 215, 232, 0.52);
}
.swatch.gap {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 173, 66, 0.52);
}
.swatch.construction {
background: #81909a;
box-shadow: none;
}
.callout {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(73, 215, 232, 0.34);
border-radius: 8px;
background: rgba(7, 17, 27, 0.88);
color: #dffaff;
font-size: 11px;
font-weight: 650;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
}
.callout::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
}
.callout.gap {
color: #ffe1b7;
border-color: rgba(255, 173, 66, 0.52);
background: rgba(31, 21, 13, 0.92);
}
.callout.gap::before {
background: var(--amber);
box-shadow: 0 0 11px var(--amber);
}
.callout.neutral {
color: #d5dee4;
border-color: rgba(170, 190, 205, 0.24);
}
.callout.neutral::before {
background: #9ba9b3;
box-shadow: none;
}
.help {
position: absolute;
left: 50%;
bottom: 29px;
transform: translateX(-50%);
color: rgba(190, 207, 217, 0.62);
font-size: 10px;
letter-spacing: 0.05em;
white-space: nowrap;
}
@media (max-width: 900px) {
.status {
top: auto;
right: 18px;
bottom: 18px;
}
.controls {
top: 18px;
right: 18px;
width: 164px;
}
.header {
top: 18px;
left: 18px;
max-width: calc(100vw - 205px);
}
.observation {
left: 18px;
bottom: 18px;
width: min(340px, calc(100vw - 36px));
}
.legend,
.help {
display: none;
}
}
@media (max-width: 620px) {
.controls {
top: auto;
right: 14px;
bottom: 14px;
width: 142px;
}
.controls button {
padding: 9px 10px;
font-size: 10px;
}
.header {
left: 14px;
top: 14px;
max-width: calc(100vw - 28px);
}
.subtitle {
max-width: 260px;
}
.observation {
left: 14px;
bottom: 14px;
width: calc(100vw - 176px);
padding: 13px;
}
.observation-title {
font-size: 10px;
}
.observation p {
font-size: 10px;
}
.observation .disclaimer {
display: none;
}
.status {
display: none;
}
.callout {
font-size: 9px;
padding: 5px 7px;
}
.callout.optional {
display: none !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional wall-to-roof insulation cutaway"
></canvas>
<div class="ui">
<header class="header">
<div class="eyebrow">Envelope junction study</div>
<h1>Wall-to-roof<br />insulation cutaway</h1>
<div class="subtitle">
Explore the insulation route through a sectioned wall and pitched roof.
Drag to orbit, scroll to zoom, or use the view controls.
</div>
</header>
<div class="status">Geometry only · no thermal calculation</div>
<div class="controls" aria-label="Scene controls">
<button id="explodeButton" class="active" type="button">
<span class="button-row"><span class="button-dot"></span>Separate layers</span>
</button>
<button id="traceButton" class="active" type="button">
<span class="button-row"><span class="button-dot"></span>Insulation trace</span>
</button>
<button id="labelsButton" class="active" type="button">
<span class="button-row"><span class="button-dot"></span>Callouts</span>
</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<section class="observation">
<div class="observation-title">Deliberate discontinuity</div>
<p>
The highlighted interruption separates the wall-insulation route from
the roof-insulation route. Its presence is shown explicitly; its
design intent or performance effect is not inferred here.
</p>
<p class="disclaimer">
This is a schematic geometry model. It does not calculate heat loss,
thermal resistance, condensation risk, or overall envelope performance.
</p>
</section>
<section class="legend" aria-label="Legend">
<div class="legend-title">Visual key</div>
<div class="legend-row">
<span class="swatch"></span>
Insulation and continuity trace
</div>
<div class="legend-row">
<span class="swatch gap"></span>
Deliberate gap
</div>
<div class="legend-row">
<span class="swatch construction"></span>
Adjacent construction
</div>
</section>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</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.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111b);
scene.fog = new THREE.Fog(0x07111b, 18, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const orbit = {
target: new THREE.Vector3(-0.55, 3.15, 1.45),
radius: 14.6,
yaw: 0.79,
pitch: 0.31
};
function updateCamera() {
const horizontal = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb9dcff, 0x182028, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dd, 4.1);
keyLight.position.set(7, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x49d7e8, 2.2);
rimLight.position.set(-8, 5, -6);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffad42, 8, 8, 2);
warmFill.position.set(2.1, 4.7, 1.0);
scene.add(warmFill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1720,
roughness: 0.92,
metalness: 0.05
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.02;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 32, 0x26404e, 0x142630);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const model = new THREE.Group();
scene.add(model);
const materials = {
insulation: new THREE.MeshStandardMaterial({
color: 0x37b9cc,
emissive: 0x063c48,
emissiveIntensity: 0.62,
roughness: 0.72,
metalness: 0.02
}),
sheathing: new THREE.MeshStandardMaterial({
color: 0xb89b72,
roughness: 0.88
}),
roofDeck: new THREE.MeshStandardMaterial({
color: 0x6d5543,
roughness: 0.82
}),
interior: new THREE.MeshStandardMaterial({
color: 0xd8e0e4,
roughness: 0.62,
metalness: 0.04
}),
cladding: new THREE.MeshStandardMaterial({
color: 0x3c4c5a,
roughness: 0.68,
metalness: 0.12
}),
concrete: new THREE.MeshStandardMaterial({
color: 0x52616a,
roughness: 0.94
}),
seam: new THREE.MeshStandardMaterial({
color: 0x1a7f8f,
roughness: 0.9,
transparent: true,
opacity: 0.66
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xd9f4ff,
transparent: true,
opacity: 0.18
});
function addEdges(mesh, opacity = 0.18) {
const edgeMaterialLocal = edgeMaterial.clone();
edgeMaterialLocal.opacity = opacity;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterialLocal
);
mesh.add(edges);
return edges;
}
function makeBox({
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = model,
edges = true
}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (edges) addEdges(mesh);
return mesh;
}
// Wall assembly.
const wallXMin = -5.1;
const wallXMax = 2.6;
const wallWidth = wallXMax - wallXMin;
const wallCenterX = (wallXMin + wallXMax) / 2;
const wallCore = makeBox({
width: wallWidth,
height: 4.43,
depth: 0.2,
material: materials.sheathing,
x: wallCenterX,
y: 2.335,
z: 0.1
});
const wallInsulation = makeBox({
width: wallWidth,
height: 4.0,
depth: 0.34,
material: materials.insulation,
x: wallCenterX,
y: 2.28,
z: 0.37
});
const innerFinish = makeBox({
width: 6.1,
height: 4.31,
depth: 0.09,
material: materials.interior,
x: -2.05,
y: 2.315,
z: -0.045
});
const exteriorCladding = makeBox({
width: 5.75,
height: 4.31,
depth: 0.11,
material: materials.cladding,
x: -2.225,
y: 2.315,
z: 0.595
});
const foundation = makeBox({
width: wallWidth + 0.25,
height: 0.15,
depth: 1.04,
material: materials.concrete,
x: wallCenterX,
y: 0.075,
z: 0.21,
edges: false
});
// Fine seams in the exposed insulation.
for (const x of [-3.15, -1.2, 0.75]) {
makeBox({
width: 0.018,
height: 3.88,
depth: 0.012,
material: materials.seam,
x,
y: 2.27,
z: 0.546,
edges: false
});
}
// Roof assembly. Local z runs up the roof; local y is the roof normal.
const roofAngle = 0.36;
const roofGroup = new THREE.Group();
roofGroup.position.set(0, 4.62, 0);
roofGroup.rotation.x = -roofAngle;
model.add(roofGroup);
const roofDeck = makeBox({
width: wallWidth,
height: 0.22,
depth: 6.2,
material: materials.roofDeck,
x: wallCenterX,
y: 0.14,
z: 3.1,
parent: roofGroup
});
const roofInsulation = makeBox({
width: wallWidth,
height: 0.28,
depth: 5.23,
material: materials.insulation,
x: wallCenterX,
y: -0.1,
z: 3.355,
parent: roofGroup
});
const ceiling = makeBox({
width: 6.2,
height: 0.1,
depth: 6.15,
material: materials.interior,
x: -2.0,
y: -0.34,
z: 3.075,
parent: roofGroup
});
for (const x of [-3.2, -1.25, 0.7]) {
makeBox({
width: 0.016,
height: 0.012,
depth: 5.12,
material: materials.seam,
x,
y: -0.246,
z: 3.355,
parent: roofGroup,
edges: false
});
}
model.updateMatrixWorld(true);
// Deliberate gap at the roof/wall junction.
const gapMaterial = new THREE.MeshBasicMaterial({
color: 0xffad42,
transparent: true,
opacity: 0.24,
depthWrite: false
});
const gapVolume = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.31, 0.43),
gapMaterial
);
gapVolume.position.set(1.62, 4.43, 0.57);
gapVolume.renderOrder = 4;
model.add(gapVolume);
const gapEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xffad42,
transparent: true,
opacity: 0.95
});
const gapEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(gapVolume.geometry),
gapEdgeMaterial
);
gapVolume.add(gapEdges);
const gapPulseMaterial = new THREE.MeshBasicMaterial({
color: 0xffc46c,
transparent: true,
opacity: 0.9
});
const gapPulse = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 24, 16),
gapPulseMaterial
);
gapPulse.position.set(1.62, 4.45, 0.58);
model.add(gapPulse);
const seamPoints = [
new THREE.Vector3(-4.85, 4.42, 0.56),
new THREE.Vector3(2.52, 4.42, 0.56)
];
const gapSeam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(seamPoints),
new THREE.LineDashedMaterial({
color: 0xffad42,
dashSize: 0.18,
gapSize: 0.1,
transparent: true,
opacity: 0.86
})
);
gapSeam.computeLineDistances();
model.add(gapSeam);
// Bracket at the exposed section edge.
const bracketPoints = [
new THREE.Vector3(2.67, 4.20, 0.29),
new THREE.Vector3(2.67, 4.20, 0.78),
new THREE.Vector3(2.67, 4.67, 0.86),
new THREE.Vector3(2.67, 4.67, 0.29)
];
const gapBracket = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(bracketPoints),
gapEdgeMaterial
);
model.add(gapBracket);
// Insulation continuity trace, intentionally split at the gap.
const traceGroup = new THREE.Group();
model.add(traceGroup);
const traceMaterial = new THREE.MeshBasicMaterial({
color: 0x7af3ff,
transparent: true,
opacity: 0.96
});
const traceGlowMaterial = new THREE.MeshBasicMaterial({
color: 0x49d7e8,
transparent: true,
opacity: 0.16,
depthWrite: false
});
function makeTube(points, radius, material, tubularSegments = 64) {
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.02
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(
curve,
tubularSegments,
radius,
8,
false
),
material
);
traceGroup.add(mesh);
return { curve, mesh };
}
const wallTracePoints = [
new THREE.Vector3(2.66, 0.31, 0.4),
new THREE.Vector3(2.66, 4.27, 0.4)
];
const roofTracePoints = [];
for (let z = 0.74; z <= 5.97; z += 0.18) {
roofTracePoints.push(
roofGroup.localToWorld(
new THREE.Vector3(2.66, -0.255, z)
)
);
}
const wallTrace = makeTube(
wallTracePoints,
0.027,
traceMaterial,
48
);
const roofTrace = makeTube(
roofTracePoints,
0.027,
traceMaterial,
96
);
makeTube(
wallTracePoints,
0.075,
traceGlowMaterial,
48
);
makeTube(
roofTracePoints,
0.075,
traceGlowMaterial,
96
);
const tracerMaterial = new THREE.MeshBasicMaterial({
color: 0xd4fbff
});
const tracer = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 20, 14),
tracerMaterial
);
tracerGroup: {
// Kept as a grouped scene object without any external helpers.
}
traceGroup.add(tracer);
const wallEndpoint = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 20, 14),
tracerMaterial
);
wallEndpoint.position.copy(wallTracePoints[1]);
traceGroup.add(wallEndpoint);
const roofEndpoint = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 20, 14),
tracerMaterial
);
roofEndpoint.position.copy(roofTracePoints[0]);
traceGroup.add(roofEndpoint);
// Projected HTML callouts.
const labelsLayer = document.createElement("div");
labelsLayer.style.position = "fixed";
labelsLayer.style.inset = "0";
labelsLayer.style.pointerEvents = "none";
labelsLayer.style.zIndex = "8";
document.body.appendChild(labelsLayer);
function createCallout(text, className = "", optional = false) {
const element = document.createElement("div");
element.className = `callout ${className}${optional ? " optional" : ""}`;
element.textContent = text;
labelsLayer.appendChild(element);
return element;
}
const callouts = [
{
element: createCallout("Deliberate gap"),
anchor: new THREE.Vector3(1.62, 4.48, 0.62),
className: "gap"
},
{
element: createCallout("Insulation trace"),
anchor: new THREE.Vector3(2.68, 5.35, 1.42),
className: ""
},
{
element: createCallout("Wall insulation"),
anchor: new THREE.Vector3(2.68, 2.42, 0.4),
className: ""
},
{
element: createCallout("Roof insulation"),
anchor: new THREE.Vector3(2.68, 5.72, 2.35),
className: ""
},
{
element: createCallout("Section edge", "", true),
anchor: new THREE.Vector3(2.68, 0.66, 0.02),
className: "neutral"
}
];
function updateCallouts() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const callout of callouts) {
const projected = callout.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
callout.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
callout.element.style.left = `${x}px`;
callout.element.style.top = `${y}px`;
}
}
// UI state.
let explosionTarget = 1;
let explosionCurrent = 1;
let tracesVisible = true;
let labelsVisible = true;
const explodeButton = document.querySelector("#explodeButton");
const traceButton = document.querySelector("#traceButton");
const labelsButton = document.querySelector("#labelsButton");
const resetButton = document.querySelector("#resetButton");
explodeButton.addEventListener("click", () => {
explosionTarget = explosionTarget > 0.5 ? 0 : 1;
explodeButton.classList.toggle("active", explosionTarget > 0.5);
});
traceButton.addEventListener("click", () => {
tracesVisible = !tracesVisible;
traceGroup.visible = tracesVisible;
traceButton.classList.toggle("active", tracesVisible);
});
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsLayer.style.display = labelsVisible ? "block" : "none";
labelsButton.classList.toggle("active", labelsVisible);
});
function resetView() {
orbit.target.set(-0.55, 3.15, 1.45);
orbit.radius = 14.6;
orbit.yaw = 0.79;
orbit.pitch = 0.31;
}
resetButton.addEventListener("click", resetView);
// Direct camera controls, implemented without external add-ons.
let pointerActive = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
pointerActive = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerActive || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.005,
-0.08,
1.08
);
});
function endPointer(event) {
if (event.pointerId !== pointerId) return;
pointerActive = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
8.5,
23
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.target !== canvas) return;
if (event.key === "ArrowLeft") orbit.yaw += 0.08;
if (event.key === "ArrowRight") orbit.yaw -= 0.08;
if (event.key === "ArrowUp") orbit.pitch += 0.06;
if (event.key === "ArrowDown") orbit.pitch -= 0.06;
if (event.key === "+" || event.key === "=") {
orbit.radius = Math.max(8.5, orbit.radius - 0.7);
}
if (event.key === "-") {
orbit.radius = Math.min(23, orbit.radius + 0.7);
}
if (event.key.toLowerCase() === "r") resetView();
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch,
-0.08,
1.08
);
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const delta = clock.getDelta();
explosionCurrent +=
(explosionTarget - explosionCurrent) * Math.min(1, delta * 7);
roofDeck.position.y = 0.14 + explosionCurrent * 0.62;
ceiling.position.y = -0.34 - explosionCurrent * 0.52;
exteriorCladding.position.z = 0.595 + explosionCurrent * 0.72;
innerFinish.position.z = -0.045 - explosionCurrent * 0.46;
const traceCycle = elapsed % 7.5;
if (traceCycle < 3.6) {
const t = traceCycle / 3.6;
tracer.visible = true;
tracer.position.copy(wallTrace.curve.getPointAt(t));
} else if (traceCycle < 7.2) {
const t = (traceCycle - 3.6) / 3.6;
tracer.visible = true;
tracer.position.copy(roofTrace.curve.getPointAt(t));
} else {
tracer.visible = false;
}
const pulse = 1 + Math.sin(elapsed * 4.4) * 0.3;
gapPulse.scale.setScalar(pulse);
gapPulseMaterial.opacity = 0.62 + Math.sin(elapsed * 4.4) * 0.22;
gapMaterial.opacity = 0.19 + Math.sin(elapsed * 2.2) * 0.055;
updateCamera();
updateCallouts();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```