Prompt specification
Build or customize the Three.js 3D scene "Layered wall sample on a stand" 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: Layered wall sample on a stand
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/layered-wall-sample-on-a-stand-x2177
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows an exploded wall sample with cladding, insulation, structure, and interior finish. Use offset layers and connecting pins so their order remains unambiguous when rotated. Stylized solid forms.
Working Three.js Starter (layered-wall-sample-on-a-stand-x2177):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Exploded Wall Assembly</title>
<style>
:root {
--ink: #26302f;
--muted: #6d7571;
--paper: #f4f0e8;
--cladding: #df7447;
--insulation: #d96f88;
--structure: #c7955d;
--interior: #83aaa5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e3d8;
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;
outline: none;
cursor: grab;
touch-action: none;
}
#scene.grabbing {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 30px;
left: 34px;
max-width: 420px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #66706c;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 31px;
height: 2px;
background: var(--cladding);
}
h1 {
margin: 0;
font-size: clamp(30px, 3.5vw, 52px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 340px;
margin: 15px 0 0;
color: #69716d;
font-size: 13px;
line-height: 1.55;
}
.view-tag {
position: absolute;
top: 34px;
left: 50%;
transform: translateX(-50%);
padding: 9px 13px;
border: 1px solid rgba(38, 48, 47, 0.13);
border-radius: 999px;
background: rgba(249, 246, 240, 0.72);
backdrop-filter: blur(12px);
color: #5f6965;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend {
position: absolute;
top: 30px;
right: 30px;
width: 278px;
padding: 18px;
border: 1px solid rgba(38, 48, 47, 0.12);
border-radius: 18px;
background: rgba(248, 245, 239, 0.82);
box-shadow: 0 16px 48px rgba(56, 53, 45, 0.09);
backdrop-filter: blur(18px);
}
.legend-title {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 11px;
color: #737b77;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-title strong {
color: var(--ink);
font-size: 11px;
}
.layers {
display: grid;
gap: 3px;
margin: 0;
padding: 0;
list-style: none;
}
.layers li {
display: grid;
grid-template-columns: 34px 1fr 12px;
align-items: center;
gap: 9px;
min-height: 54px;
padding: 7px 4px;
border-top: 1px solid rgba(38, 48, 47, 0.09);
}
.layer-number {
color: #777f7b;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
}
.layer-name {
display: block;
font-size: 13px;
font-weight: 720;
}
.layer-detail {
display: block;
margin-top: 2px;
color: #818783;
font-size: 10px;
letter-spacing: 0.02em;
}
.swatch {
width: 9px;
height: 32px;
border-radius: 99px;
}
.legend-note {
display: flex;
align-items: center;
gap: 9px;
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid rgba(38, 48, 47, 0.09);
color: #6c7570;
font-size: 10px;
line-height: 1.4;
}
.pin-symbol {
position: relative;
flex: 0 0 25px;
height: 13px;
}
.pin-symbol::before {
content: "";
position: absolute;
top: 5px;
left: 1px;
width: 23px;
height: 3px;
border-radius: 4px;
background: #697572;
box-shadow: -2px -2px 0 -1px #697572,
22px -2px 0 -1px #697572;
}
.direction {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
color: #59635f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.direction-line {
position: relative;
flex: 1;
height: 1px;
margin: 0 12px;
background: rgba(38, 48, 47, 0.25);
}
.direction-line::after {
content: "";
position: absolute;
right: -1px;
top: -3px;
width: 6px;
height: 6px;
border-right: 1px solid #59635f;
border-bottom: 1px solid #59635f;
transform: rotate(45deg);
}
.controls {
position: absolute;
left: 50%;
bottom: 27px;
display: flex;
align-items: center;
gap: 18px;
width: min(620px, calc(100vw - 40px));
padding: 13px 14px 13px 18px;
border: 1px solid rgba(38, 48, 47, 0.12);
border-radius: 18px;
background: rgba(248, 245, 239, 0.88);
box-shadow: 0 18px 55px rgba(56, 53, 45, 0.13);
backdrop-filter: blur(18px);
pointer-events: auto;
transform: translateX(-50%);
}
.slider-block {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
gap: 12px;
flex: 1;
}
.slider-label {
color: #56605c;
font-size: 9px;
font-weight: 780;
letter-spacing: 0.14em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(
to right,
var(--cladding) 0%,
var(--cladding) 62%,
#d2ccc1 62%,
#d2ccc1 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #f8f5ef;
border-radius: 50%;
appearance: none;
background: var(--ink);
box-shadow: 0 2px 7px rgba(30, 35, 34, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #f8f5ef;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 7px rgba(30, 35, 34, 0.28);
}
.control-buttons {
display: flex;
gap: 7px;
}
button {
height: 35px;
padding: 0 12px;
border: 1px solid rgba(38, 48, 47, 0.15);
border-radius: 10px;
background: rgba(255, 255, 255, 0.6);
color: #45504c;
font: inherit;
font-size: 10px;
font-weight: 720;
letter-spacing: 0.04em;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fff;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.hint {
position: absolute;
left: 34px;
bottom: 35px;
color: rgba(57, 66, 62, 0.65);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.spec {
position: absolute;
right: 34px;
bottom: 35px;
color: rgba(57, 66, 62, 0.65);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 850px) {
.brand {
top: 20px;
left: 20px;
}
.subtitle,
.hint,
.spec,
.view-tag {
display: none;
}
.legend {
top: 18px;
right: 18px;
width: 225px;
padding: 13px;
}
.legend-note,
.direction {
display: none;
}
.layers li {
min-height: 44px;
}
.layer-detail {
display: none;
}
.controls {
bottom: 18px;
gap: 10px;
padding-left: 12px;
}
.slider-label {
display: none;
}
}
@media (max-width: 560px) {
h1 {
font-size: 27px;
}
.eyebrow {
font-size: 9px;
}
.legend {
top: auto;
right: 12px;
bottom: 88px;
width: 178px;
padding: 10px;
}
.legend-title {
margin-bottom: 5px;
}
.layers li {
grid-template-columns: 26px 1fr 7px;
min-height: 35px;
}
.layer-name {
font-size: 10px;
}
.swatch {
width: 6px;
height: 22px;
}
.controls {
width: calc(100vw - 24px);
}
button {
padding: 0 9px;
}
#labelButton {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive exploded wall assembly. Drag to rotate and scroll to zoom."
></canvas>
<div class="hud">
<header class="brand">
<div class="eyebrow">Build-up study / section A</div>
<h1>Exploded<br />Wall Assembly</h1>
<p class="subtitle">
Four offset construction layers held on a common pin axis.
Rotate the sample to inspect the exterior-to-interior sequence.
</p>
</header>
<div class="view-tag" id="viewTag">Exploded view</div>
<aside class="legend">
<div class="legend-title">
<span>Assembly order</span>
<strong>04 layers</strong>
</div>
<ol class="layers">
<li>
<span class="layer-number">01</span>
<span>
<span class="layer-name">Cladding</span>
<span class="layer-detail">Rainscreen panels</span>
</span>
<span class="swatch" style="background: var(--cladding)"></span>
</li>
<li>
<span class="layer-number">02</span>
<span>
<span class="layer-name">Insulation</span>
<span class="layer-detail">Mineral wool batts</span>
</span>
<span class="swatch" style="background: var(--insulation)"></span>
</li>
<li>
<span class="layer-number">03</span>
<span>
<span class="layer-name">Structure</span>
<span class="layer-detail">Timber stud frame</span>
</span>
<span class="swatch" style="background: var(--structure)"></span>
</li>
<li>
<span class="layer-number">04</span>
<span>
<span class="layer-name">Interior finish</span>
<span class="layer-detail">Drywall and trim</span>
</span>
<span class="swatch" style="background: var(--interior)"></span>
</li>
</ol>
<div class="legend-note">
<span class="pin-symbol"></span>
<span>Four steel alignment pins keep the stack order explicit.</span>
</div>
<div class="direction">
<span>Outside</span>
<span class="direction-line"></span>
<span>Inside</span>
</div>
</aside>
<section class="controls" aria-label="Model controls">
<div class="slider-block">
<label class="slider-label" for="explode">Separation</label>
<input
id="explode"
type="range"
min="0"
max="1.4"
step="0.01"
value="1.15"
aria-label="Layer separation"
/>
</div>
<div class="control-buttons">
<button id="labelButton" type="button" aria-pressed="true">Labels on</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="spec">7.2 × 4.4 sample / Pin-aligned</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 explodeInput = document.querySelector("#explode");
const labelButton = document.querySelector("#labelButton");
const resetButton = document.querySelector("#resetButton");
const viewTag = document.querySelector("#viewTag");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d8);
scene.fog = new THREE.Fog(0xe9e3d8, 19, 36);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
// Lighting
const hemisphere = new THREE.HemisphereLight(0xfff9ed, 0x8c928d, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d8, 3.3);
keyLight.position.set(7, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xdce9ed, 1.35);
fillLight.position.set(-8, 4, -7);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffffff, 0.8);
rimLight.position.set(0, 7, -10);
scene.add(rimLight);
// Ground and grid
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xded7ca,
roughness: 0.94,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.43;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0xb7afa2, 0xd1c9bb);
grid.position.y = -2.415;
grid.material.transparent = true;
grid.material.opacity = 0.4;
scene.add(grid);
// Shared materials
const steelMaterial = new THREE.MeshStandardMaterial({
color: 0x66716f,
roughness: 0.24,
metalness: 0.86
});
const darkSteelMaterial = new THREE.MeshStandardMaterial({
color: 0x3c4644,
roughness: 0.3,
metalness: 0.72
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0xc7955d,
roughness: 0.78,
metalness: 0
});
const woodLightMaterial = new THREE.MeshStandardMaterial({
color: 0xd2a66f,
roughness: 0.76,
metalness: 0
});
const woodDarkMaterial = new THREE.MeshStandardMaterial({
color: 0xa97743,
roughness: 0.82,
metalness: 0
});
const insulationMaterial = new THREE.MeshStandardMaterial({
color: 0xd96f88,
roughness: 0.97,
metalness: 0
});
const insulationLightMaterial = new THREE.MeshStandardMaterial({
color: 0xe58ca0,
roughness: 1,
metalness: 0
});
const insulationDarkMaterial = new THREE.MeshStandardMaterial({
color: 0xb95872,
roughness: 1,
metalness: 0
});
const interiorMaterial = new THREE.MeshStandardMaterial({
color: 0x87ada8,
roughness: 0.86,
metalness: 0
});
const interiorLightMaterial = new THREE.MeshStandardMaterial({
color: 0x9abbb6,
roughness: 0.88,
metalness: 0
});
const interiorDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x668e89,
roughness: 0.83,
metalness: 0
});
const layerDefinitions = [
{
name: "Cladding",
detail: "Rainscreen panels",
color: "#df7447"
},
{
name: "Insulation",
detail: "Mineral wool batts",
color: "#d96f88"
},
{
name: "Structure",
detail: "Timber stud frame",
color: "#c7955d"
},
{
name: "Interior finish",
detail: "Drywall and trim",
color: "#83aaa5"
}
];
const layerGroups = layerDefinitions.map(() => {
const group = new THREE.Group();
scene.add(group);
return group;
});
function addBox(parent, width, height, depth, material, x, y, z) {
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);
return mesh;
}
function addBeamXY(
parent,
x1,
y1,
x2,
y2,
thickness,
depth,
material
) {
const length = Math.hypot(x2 - x1, y2 - y1);
const angle = Math.atan2(y2 - y1, x2 - x1);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, thickness, depth),
material
);
mesh.position.set((x1 + x2) / 2, (y1 + y2) / 2, 0);
mesh.rotation.z = angle;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Layer 01: solid rainscreen cladding
const cladding = layerGroups[0];
const claddingBackingMaterial = new THREE.MeshStandardMaterial({
color: 0xa85131,
roughness: 0.84
});
addBox(
cladding,
7.35,
4.28,
0.1,
claddingBackingMaterial,
0,
0,
-0.05
);
const tileMaterials = [
new THREE.MeshStandardMaterial({ color: 0xe17a4d, roughness: 0.78 }),
new THREE.MeshStandardMaterial({ color: 0xd96c41, roughness: 0.8 }),
new THREE.MeshStandardMaterial({ color: 0xe58859, roughness: 0.76 })
];
const columns = 4;
const rows = 5;
const tileWidth = 1.76;
const tileHeight = 0.78;
const tileGap = 0.055;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x =
(column - (columns - 1) / 2) * (tileWidth + tileGap);
const y =
(row - (rows - 1) / 2) * (tileHeight + tileGap);
const material =
tileMaterials[(column + row * 2) % tileMaterials.length];
addBox(
cladding,
tileWidth,
tileHeight,
0.15,
material,
x,
y,
0.035
);
}
}
// Thin perimeter rails give the cladding a manufactured edge.
addBox(
cladding,
7.35,
0.08,
0.2,
claddingBackingMaterial,
0,
2.12,
0.045
);
addBox(
cladding,
7.35,
0.08,
0.2,
claddingBackingMaterial,
0,
-2.12,
0.045
);
// Layer 02: mineral wool batts
const insulation = layerGroups[1];
const bayCenters = [-2.52, -0.84, 0.84, 2.52];
bayCenters.forEach((x, index) => {
addBox(
insulation,
1.55,
3.78,
0.36,
insulationMaterial,
x,
0,
0
);
// Stylized compressed mineral fibers.
for (let groove = -1; groove <= 1; groove++) {
addBox(
insulation,
1.22,
0.035,
0.025,
groove === 0
? insulationDarkMaterial
: insulationLightMaterial,
x,
groove * 0.72,
0.192
);
}
// Small folded edge detail.
addBox(
insulation,
0.055,
3.62,
0.035,
insulationDarkMaterial,
x + (index % 2 === 0 ? -0.69 : 0.69),
0,
0.195
);
});
// Layer 03: open timber stud structure
const structure = layerGroups[2];
const studPositions = [-3.3, -1.65, 0, 1.65, 3.3];
studPositions.forEach((x, index) => {
addBox(
structure,
0.18,
4.04,
0.27,
index % 2 === 0 ? woodMaterial : woodLightMaterial,
x,
0,
0
);
// Restrained wood grain marks.
addBox(
structure,
0.018,
3.55,
0.012,
woodDarkMaterial,
x - 0.035,
0.05,
0.141
);
});
addBox(
structure,
6.95,
0.27,
0.28,
woodLightMaterial,
0,
1.91,
0
);
addBox(
structure,
6.95,
0.27,
0.28,
woodLightMaterial,
0,
-1.91,
0
);
// Diagonal brace in the first bay.
addBeamXY(
structure,
-3.12,
-1.73,
-0.34,
1.73,
0.16,
0.23,
woodDarkMaterial
);
// Layer 04: interior drywall sheets and trim
const interior = layerGroups[3];
addBox(
interior,
7.28,
4.18,
0.1,
interiorDarkMaterial,
0,
0,
-0.055
);
const sheetCenters = [-2.39, 0, 2.39];
sheetCenters.forEach((x, index) => {
addBox(
interior,
2.35,
4.02,
0.15,
index === 1 ? interiorLightMaterial : interiorMaterial,
x,
0,
0.015
);
});
// Narrow vertical joints and a lower trim rail.
addBox(
interior,
0.028,
3.98,
0.022,
interiorDarkMaterial,
-1.195,
0,
0.104
);
addBox(
interior,
0.028,
3.98,
0.022,
interiorDarkMaterial,
1.195,
0,
0.104
);
addBox(
interior,
7.06,
0.2,
0.075,
interiorDarkMaterial,
0,
-1.83,
0.115
);
// Alignment pins: one continuous rod per corner, passing through all layers.
const pinPositions = [
[-3.22, -1.78],
[3.22, -1.78],
[-3.22, 1.78],
[3.22, 1.78]
];
const pins = [];
pinPositions.forEach(([x, y]) => {
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 1, 14),
steelMaterial
);
rod.rotation.x = Math.PI / 2;
rod.position.set(x, y, 0);
rod.castShadow = true;
scene.add(rod);
const frontCap = new THREE.Mesh(
new THREE.SphereGeometry(0.1, 16, 10),
darkSteelMaterial
);
frontCap.castShadow = true;
scene.add(frontCap);
const rearCap = frontCap.clone();
scene.add(rearCap);
// Collars sit on each layer and make the shared pin axis explicit.
layerGroups.forEach((group) => {
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.125, 0.125, 0.26, 16),
steelMaterial
);
collar.rotation.x = Math.PI / 2;
collar.position.set(x, y, 0);
collar.castShadow = true;
group.add(collar);
});
pins.push({
x,
y,
rod,
frontCap,
rearCap
});
});
// Assembly-axis arrow.
const axisArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(-4.15, -1.42, 3),
6,
0x687470,
0.34,
0.2
);
scene.add(axisArrow);
// Canvas-generated labels remain readable from every viewing angle.
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function createLayerLabel(group, definition, index) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 180;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
ctx.shadowColor = "rgba(30, 35, 34, 0.25)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
ctx.fillStyle = "rgba(31, 39, 38, 0.94)";
roundedRect(ctx, 5, 5, 758, 170, 27);
ctx.fill();
ctx.shadowColor = "transparent";
ctx.fillStyle = definition.color;
roundedRect(ctx, 17, 18, 14, 144, 7);
ctx.fill();
ctx.fillStyle = definition.color;
ctx.font = "800 57px Arial, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(String(index + 1).padStart(2, "0"), 55, 80);
ctx.fillStyle = "#ffffff";
ctx.font = "700 40px Arial, sans-serif";
ctx.fillText(definition.name.toUpperCase(), 155, 66);
ctx.fillStyle = "rgba(255, 255, 255, 0.62)";
ctx.font = "500 23px Arial, sans-serif";
ctx.fillText(definition.detail.toUpperCase(), 157, 116);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(4.02, 2.38 - index * 0.8, 0);
sprite.scale.set(3.15, 0.738, 1);
sprite.renderOrder = 30;
group.add(sprite);
return sprite;
}
const labels = layerDefinitions.map((definition, index) =>
createLayerLabel(layerGroups[index], definition, index)
);
// Custom camera controls: orbit, zoom, reset, and keyboard support.
const target = new THREE.Vector3(0, 0, 0);
const defaultCamera = {
theta: 0.68,
phi: 1.18,
radius: 14.2
};
let theta = defaultCamera.theta;
let phi = defaultCamera.phi;
let radius = defaultCamera.radius;
let dragging = false;
let previousX = 0;
let previousY = 0;
let targetExplosion = Number(explodeInput.value);
let currentExplosion = targetExplosion;
let labelsVisible = true;
const compactPositions = [0.5, 0.16, -0.16, -0.5];
const separationDirections = [1, 0.333, -0.333, -1];
function updateCamera() {
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);
}
function updateAssembly(explosion) {
layerGroups.forEach((group, index) => {
group.position.z =
compactPositions[index] +
separationDirections[index] * 2.1 * explosion;
});
const frontZ = layerGroups[0].position.z;
const rearZ = layerGroups[3].position.z;
const pinMinimum = rearZ - 0.27;
const pinMaximum = frontZ + 0.27;
const pinLength = pinMaximum - pinMinimum;
const pinCenter = (pinMaximum + pinMinimum) / 2;
pins.forEach((pin) => {
pin.rod.scale.y = pinLength;
pin.rod.position.z = pinCenter;
pin.frontCap.position.set(pin.x, pin.y, pinMaximum);
pin.rearCap.position.set(pin.x, pin.y, pinMinimum);
});
axisArrow.position.set(-4.15, -1.42, frontZ + 0.18);
axisArrow.setLength(
Math.max(0.4, frontZ - rearZ),
0.34,
0.2
);
const progress = (explosion / 1.4) * 100;
explodeInput.style.background =
`linear-gradient(to right, ` +
`#df7447 0%, #df7447 ${progress}%, ` +
`#d2ccc1 ${progress}%, #d2ccc1 100%)`;
if (explosion < 0.08) {
viewTag.textContent = "Stacked view";
} else if (explosion < 0.55) {
viewTag.textContent = "Partially exploded";
} else {
viewTag.textContent = "Exploded view";
}
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("grabbing");
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
theta -= dx * 0.007;
phi -= dy * 0.006;
phi = THREE.MathUtils.clamp(phi, 0.3, Math.PI - 0.3);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("grabbing");
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius *= Math.exp(event.deltaY * 0.001);
radius = THREE.MathUtils.clamp(radius, 8, 24);
},
{ passive: false }
);
explodeInput.addEventListener("input", () => {
targetExplosion = Number(explodeInput.value);
});
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labels.forEach((label) => {
label.visible = labelsVisible;
});
labelButton.textContent = labelsVisible ? "Labels on" : "Labels off";
labelButton.setAttribute("aria-pressed", String(labelsVisible));
});
resetButton.addEventListener("click", () => {
theta = defaultCamera.theta;
phi = defaultCamera.phi;
radius = defaultCamera.radius;
targetExplosion = defaultCamera.radius / 12.3;
explodeInput.value = String(targetExplosion);
updateCamera();
});
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") {
theta += step;
event.preventDefault();
} else if (event.key === "ArrowRight") {
theta -= step;
event.preventDefault();
} else if (event.key === "ArrowUp") {
phi = Math.max(0.3, phi - step);
event.preventDefault();
} else if (event.key === "ArrowDown") {
phi = Math.min(Math.PI - 0.3, phi + step);
event.preventDefault();
} else if (event.key === "+" || event.key === "=") {
radius = Math.max(8, radius - 0.7);
} else if (event.key === "-" || event.key === "_") {
radius = Math.min(24, radius + 0.7);
} else if (event.key.toLowerCase() === "r") {
theta = defaultCamera.theta;
phi = defaultCamera.phi;
radius = defaultCamera.radius;
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
updateCamera();
updateAssembly(currentExplosion);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.pow(0.001, delta);
currentExplosion +=
(targetExplosion - currentExplosion) * easing;
updateAssembly(currentExplosion);
updateCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```