Prompt specification
Build or customize the Three.js 3D scene "Layer spacing heat-path model" 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: Layer spacing heat-path model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/layer-spacing-heat-path-model-x0578
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts clothing insulation. Display two fabric arrangements around identical warm cylinders; schematic arrows compare heat transfer through compact and air-trapping layers with an explicitly qualitative legend. Voxel style.
Working Three.js Starter (layer-spacing-heat-path-model-x0578):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Clothing Insulation</title>
<style>
:root {
color-scheme: dark;
--bg: #071419;
--panel: rgba(8, 25, 30, 0.92);
--border: rgba(159, 210, 209, 0.22);
--text: #e8f2ee;
--muted: #91abad;
--warm: #ff9b52;
--warm-bright: #ffd27c;
--compact: #d86861;
--air: #72e0e8;
--fabric: #d8bd8d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
header {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
width: min(520px, calc(100vw - 48px));
pointer-events: none;
text-shadow: 0 2px 14px rgba(0, 0, 0, 0.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--warm-bright);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 6px;
background: var(--warm);
box-shadow: 7px 0 0 rgba(255, 155, 82, 0.42);
}
h1 {
margin: 11px 0 8px;
max-width: 510px;
font-size: clamp(25px, 3.5vw, 48px);
line-height: 0.98;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.intro {
margin: 0;
max-width: 470px;
color: #b7ccca;
font-size: 12px;
line-height: 1.65;
}
.same-core {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(255, 155, 82, 0.35);
background: rgba(255, 155, 82, 0.08);
color: var(--warm-bright);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
}
.same-core i {
width: 8px;
height: 8px;
background: var(--warm);
box-shadow: 0 0 14px rgba(255, 155, 82, 0.8);
}
.legend {
position: fixed;
top: 22px;
right: 22px;
z-index: 8;
width: 286px;
padding: 16px;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(12px);
}
.legend-head {
display: flex;
justify-content: space-between;
gap: 12px;
padding-bottom: 11px;
border-bottom: 1px solid var(--border);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
}
.legend-head span:last-child {
color: var(--warm-bright);
}
.legend-row {
display: grid;
grid-template-columns: 78px 1fr;
align-items: center;
gap: 10px;
min-height: 52px;
border-bottom: 1px solid rgba(159, 210, 209, 0.10);
}
.legend-row b,
.legend-row strong {
display: block;
color: var(--text);
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-row small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.arrow-key {
position: relative;
display: block;
height: 5px;
background: repeating-linear-gradient(
90deg,
var(--warm) 0 7px,
transparent 7px 10px
);
filter: drop-shadow(0 0 6px rgba(255, 155, 82, 0.5));
}
.arrow-key::after {
content: "";
position: absolute;
right: -1px;
top: -5px;
border-left: 9px solid var(--warm);
border-top: 7px solid transparent;
border-bottom: 7px solid transparent;
}
.arrow-key.long {
width: 74px;
}
.arrow-key.short {
width: 36px;
opacity: 0.78;
}
.swatch {
display: block;
width: 22px;
height: 22px;
margin-left: 3px;
border: 1px solid rgba(255, 255, 255, 0.16);
}
.swatch.compact {
background: var(--compact);
box-shadow: 5px 5px 0 rgba(216, 104, 97, 0.35);
}
.swatch.air {
border-color: var(--air);
background: rgba(114, 224, 232, 0.16);
box-shadow: inset 0 0 12px rgba(114, 224, 232, 0.28);
}
.swatch.fabric {
background: var(--fabric);
box-shadow: 5px 5px 0 rgba(216, 189, 141, 0.25);
}
.legend-note {
margin: 12px 0;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
.legend-note strong {
color: var(--warm-bright);
}
#reset {
width: 100%;
padding: 9px 10px;
border: 1px solid rgba(159, 210, 209, 0.28);
background: rgba(159, 210, 209, 0.06);
color: var(--text);
font: inherit;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
cursor: pointer;
text-transform: uppercase;
}
#reset:hover,
#reset:focus-visible {
border-color: var(--warm);
background: rgba(255, 155, 82, 0.10);
outline: none;
}
.scene-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 10px;
min-width: 220px;
padding: 10px 12px;
border: 1px solid var(--border);
background: rgba(7, 20, 25, 0.87);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.26);
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(7px);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: linear-gradient(var(--border), transparent);
}
.label-index {
display: grid;
place-items: center;
width: 29px;
height: 29px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.2);
color: var(--warm-bright);
font-size: 11px;
font-weight: 900;
}
.scene-label strong {
display: block;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
line-height: 1.35;
}
#label-compact {
border-top: 2px solid var(--compact);
}
#label-air {
border-top: 2px solid var(--air);
}
.hint {
position: fixed;
z-index: 5;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(159, 210, 209, 0.15);
background: rgba(7, 20, 25, 0.7);
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--warm-bright);
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 0.35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 780px) {
header {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
h1 {
max-width: 330px;
font-size: 28px;
}
.intro {
max-width: 330px;
font-size: 10px;
}
.same-core {
margin-top: 9px;
}
.legend {
top: auto;
right: 12px;
bottom: 12px;
width: 238px;
padding: 11px;
}
.legend-row {
min-height: 44px;
grid-template-columns: 65px 1fr;
}
.legend-row small,
.legend-note {
font-size: 8px;
}
.scene-label {
min-width: 165px;
padding: 8px;
}
.scene-label small {
display: none;
}
.hint {
display: none;
}
}
@media (max-height: 620px) {
.intro {
display: none;
}
.same-core {
margin-top: 8px;
}
.legend-row {
min-height: 42px;
}
.legend-note {
margin: 8px 0;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header>
<div class="eyebrow">Clothing insulation / voxel cutaway</div>
<h1>Warm core.<br>Different insulation.</h1>
<p class="intro">
Two identical warm cylinders wear different fabric arrangements.
Compact fibers create a continuous path; lofted fabric holds pockets of
still air that slow the movement of heat.
</p>
<div class="same-core"><i></i> Same core size · Same heat input</div>
</header>
<aside class="legend" aria-label="Qualitative thermal legend">
<div class="legend-head">
<span>Thermal path</span>
<span>Qualitative</span>
</div>
<div class="legend-row">
<span class="arrow-key long" aria-hidden="true"></span>
<div>
<b>Long amber arrow</b>
<small>More heat escapes the compact layer.</small>
</div>
</div>
<div class="legend-row">
<span class="arrow-key short" aria-hidden="true"></span>
<div>
<b>Short amber arrow</b>
<small>Less heat passes through trapped air.</small>
</div>
</div>
<div class="legend-row">
<i class="swatch compact" aria-hidden="true"></i>
<div>
<b>Compact fabric</b>
<small>Dense and continuously packed.</small>
</div>
</div>
<div class="legend-row">
<i class="swatch air" aria-hidden="true"></i>
<div>
<b>Trapped-air cells</b>
<small>Cyan pockets between lofted layers.</small>
</div>
</div>
<div class="legend-row">
<i class="swatch fabric" aria-hidden="true"></i>
<div>
<b>Lofted fabric</b>
<small>Separated inner and outer layers.</small>
</div>
</div>
<p class="legend-note">
<strong>Arrow length is symbolic only.</strong>
The diagram is not to scale and does not represent measured heat flux.
</p>
<button id="reset" type="button">Reset camera view</button>
</aside>
<div id="label-compact" class="scene-label" aria-hidden="true">
<span class="label-index">01</span>
<div>
<strong>Compact layer</strong>
<small>Dense fibers · higher heat escape</small>
</div>
</div>
<div id="label-air" class="scene-label" aria-hidden="true">
<span class="label-index">02</span>
<div>
<strong>Air-trapping layer</strong>
<small>Lofted fabric · reduced heat escape</small>
</div>
</div>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Double-click to reset</div>
<div id="loading">Building voxel laboratory…</div>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL could not be initialized.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene comparing compact and air-trapping clothing insulation."
);
renderer.domElement.tabIndex = 0;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071419);
scene.fog = new THREE.Fog(0x071419, 13, 27);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.85, 0);
const controls = {
theta: 0.58,
phi: 1.13,
radius: 13.6,
targetTheta: 0.58,
targetPhi: 1.13,
targetRadius: 13.6
};
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function updateCamera(delta = 1) {
const damping = 1 - Math.exp(-10 * delta);
controls.theta +=
(controls.targetTheta - controls.theta) * damping;
controls.phi +=
(controls.targetPhi - controls.phi) * damping;
controls.radius +=
(controls.targetRadius - controls.radius) * damping;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
cameraTarget.x +
controls.radius * sinPhi * Math.sin(controls.theta),
cameraTarget.y +
controls.radius * Math.cos(controls.phi),
cameraTarget.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera(1);
// Lighting
scene.add(new THREE.HemisphereLight(0xa8e0e5, 0x151217, 2.0));
const keyLight = new THREE.DirectionalLight(0xffd3a4, 3.2);
keyLight.position.set(-4, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6edce4, 1.5);
rimLight.position.set(7, 4, -8);
scene.add(rimLight);
// Shared materials
const whiteMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0
});
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0x741603,
emissiveIntensity: 0.62,
roughness: 0.48,
metalness: 0
});
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0x102b31,
roughness: 0.92
});
const pedestalTopMaterial = new THREE.MeshStandardMaterial({
color: 0x17383d,
roughness: 0.82
});
const compactAccentMaterial = new THREE.MeshStandardMaterial({
color: 0xb64e4a,
roughness: 0.85,
emissive: 0x240604,
emissiveIntensity: 0.18
});
const airAccentMaterial = new THREE.MeshStandardMaterial({
color: 0x4eaeb4,
roughness: 0.8,
emissive: 0x062629,
emissiveIntensity: 0.2
});
const airPocketMaterial = new THREE.MeshStandardMaterial({
color: 0x72e0e8,
emissive: 0x1a8d98,
emissiveIntensity: 0.5,
roughness: 0.3,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0b2025,
roughness: 1
});
// Utility functions
function addBox(parent, size, position, material, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeInstancedBoxes(parent, specifications, material, options = {}) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const mesh = new THREE.InstancedMesh(
geometry,
material,
specifications.length
);
const dummy = new THREE.Object3D();
specifications.forEach((specification, index) => {
dummy.position.set(
specification.position[0],
specification.position[1],
specification.position[2]
);
dummy.rotation.set(
0,
specification.rotationY || 0,
0
);
dummy.scale.set(
specification.size[0],
specification.size[1],
specification.size[2]
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (specification.color !== undefined) {
mesh.setColorAt(
index,
new THREE.Color(specification.color)
);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let state = seed >>> 0;
return function () {
state = (1664525 * state + 1013904223) >>> 0;
return state / 4294967296;
};
}
// Voxel floor
const floor = new THREE.Mesh(
new THREE.BoxGeometry(24, 0.18, 18),
floorMaterial
);
floor.position.y = -0.18;
floor.receiveShadow = true;
scene.add(floor);
const random = seededRandom(9142);
const tileSpecifications = [];
for (let x = -8; x <= 8; x++) {
for (let z = -6; z <= 6; z++) {
const shade = 0.72 + random() * 0.18;
const color = new THREE.Color(0x174047).multiplyScalar(shade);
tileSpecifications.push({
position: [x, -0.075, z],
size: [0.94, 0.07, 0.94],
color: color.getHex()
});
}
}
makeInstancedBoxes(
scene,
tileSpecifications,
whiteMaterial,
{ castShadow: false }
);
// Subtle voxel horizon
const horizonSpecifications = [];
for (let i = -7; i <= 7; i++) {
const height = 0.35 + random() * 1.4;
horizonSpecifications.push({
position: [i * 1.42, height / 2, -6.8],
size: [0.72, height, 0.72],
color: new THREE.Color(0x102a30)
.multiplyScalar(0.8 + random() * 0.3)
.getHex()
});
}
makeInstancedBoxes(
scene,
horizonSpecifications,
whiteMaterial,
{ castShadow: false }
);
const coreLights = [];
const heatPulses = [];
function buildPedestal(parent, accentMaterial) {
addBox(
parent,
[4.25, 0.16, 3.35],
[0, 0.07, 0],
pedestalMaterial
);
addBox(
parent,
[3.92, 0.14, 3.02],
[0, 0.22, 0],
pedestalTopMaterial
);
addBox(
parent,
[3.35, 0.035, 0.11],
[0, 0.315, 1.32],
accentMaterial
);
}
function buildVoxelCore(parent) {
const specifications = [];
const step = 0.19;
const verticalStep = 0.205;
const rows = 15;
const radiusSquared = 0.55 * 0.55;
const hotColor = new THREE.Color(0xff4e2f);
const paleColor = new THREE.Color(0xffd273);
const color = new THREE.Color();
for (let row = 0; row < rows; row++) {
const y = 0.43 + (row + 0.5) * verticalStep;
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
const px = x * step;
const pz = z * step;
const radialDistance = Math.hypot(px, pz);
if (radialDistance > radiusSquared) {
continue;
}
const heat = 1 - radialDistance / 0.55;
const variation = (row % 3) * 0.025;
color.copy(hotColor).lerp(paleColor, heat * 0.82 + variation);
specifications.push({
position: [px, y, pz],
size: [0.178, 0.194, 0.178],
color: color.getHex()
});
}
}
}
makeInstancedBoxes(parent, specifications, coreMaterial);
const heatLight = new THREE.PointLight(
0xff692d,
10,
4.3,
2
);
heatLight.position.set(0, 1.9, 0);
parent.add(heatLight);
coreLights.push(heatLight);
}
function buildCompactLayer(parent) {
const specifications = [];
const compactColors = [
0xc95752,
0xd86861,
0xe17b70,
0xb94d49
];
// The front sector is removed to form an educational cutaway.
for (let row = 0; row < 13; row++) {
const y = 0.45 + row * 0.235;
for (let degrees = 125; degrees <= 330; degrees += 13) {
const angle = THREE.MathUtils.degToRad(degrees);
const radius = 0.81 + (row % 2) * 0.018;
const color =
row === 0 || row === 12
? 0xa94443
: compactColors[(row + degrees) % compactColors.length];
specifications.push({
position: [
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
],
size: [0.34, 0.22, 0.185],
rotationY: -angle,
color
});
}
}
makeInstancedBoxes(parent, specifications, whiteMaterial);
// Darkened seam blocks emphasize that the layer is densely connected.
const seamSpecifications = [];
for (let row = 0; row < 13; row += 3) {
const y = 0.45 + row * 0.235;
for (let degrees = 125; degrees <= 330; degrees += 13) {
const angle = THREE.MathUtils.degToRad(degrees);
const radius = 0.995;
seamSpecifications.push({
position: [
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
],
size: [0.055, 0.07, 0.13],
rotationY: -angle,
color: 0x7f3436
});
}
}
makeInstancedBoxes(parent, seamSpecifications, whiteMaterial);
}
function buildAirTrappingLayer(parent) {
const innerSpecifications = [];
const outerSpecifications = [];
const pocketSpecifications = [];
const fiberSpecifications = [];
const innerColors = [0xd5b17d, 0xe0bf89, 0xc89f6e];
const outerColors = [0xbad1bd, 0xa9c6b6, 0xc8dbc6];
// Sparse inner loft
for (let row = 0; row < 12; row++) {
const y = 0.48 + row * 0.245;
for (let degrees = 125; degrees <= 330; degrees += 24) {
const angle = THREE.MathUtils.degToRad(degrees);
const radius = 0.79 + (row % 2) * 0.018;
innerSpecifications.push({
position: [
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
],
size: [0.27, 0.225, 0.215],
rotationY: -angle,
color: innerColors[(row + degrees) % innerColors.length]
});
}
}
// Sparse outer loft, separated from the inner layer
for (let row = 0; row < 12; row++) {
const y = 0.48 + row * 0.245;
for (let degrees = 125; degrees <= 330; degrees += 20) {
const angle = THREE.MathUtils.degToRad(degrees);
const radius = 1.225 + (row % 2) * 0.016;
outerSpecifications.push({
position: [
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
],
size: [0.25, 0.225, 0.235],
rotationY: -angle,
color:
row === 0 || row === 11
? 0x5a9fa0
: outerColors[(row + degrees) % outerColors.length]
});
}
}
// Visible air cells in the open gap
for (let degrees = 0; degrees < 360; degrees += 30) {
const angle = THREE.MathUtils.degToRad(degrees);
for (let y = 0.72; y <= 3.15; y += 0.55) {
const size = 0.29 + random() * 0.08;
pocketSpecifications.push({
position: [
Math.cos(angle) * 1.015,
y,
Math.sin(angle) * 1.015
],
size: [size, size * 0.9, size]
});
}
}
// Thin loft fibers divide the gap into small air pockets.
for (let degrees = 125; degrees <= 330; degrees += 35) {
const angle = THREE.MathUtils.degToRad(degrees);
for (let y = 0.57; y < 3.3; y += 0.28) {
fiberSpecifications.push({
position: [
Math.cos(angle) * 1.015,
y,
Math.sin(angle) * 1.015
],
size: [0.06, 0.24, 0.06],
rotationY: -angle,
color: 0xe4d3ad
});
}
}
makeInstancedBoxes(parent, innerSpecifications, whiteMaterial);
makeInstancedBoxes(parent, outerSpecifications, whiteMaterial);
makeInstancedBoxes(
parent,
fiberSpecifications,
whiteMaterial
);
const pockets = makeInstancedBoxes(
parent,
pocketSpecifications,
airPocketMaterial,
{ castShadow: false }
);
pockets.renderOrder = 2;
}
function createPixelArrow(
parent,
angle,
y,
startRadius,
endRadius,
speed,
phase
) {
const arrowGroup = new THREE.Group();
const arrowColor = 0xff9b52;
const arrowMaterial = new THREE.MeshStandardMaterial({
color: arrowColor,
emissive: arrowColor,
emissiveIntensity: 2.1,
roughness: 0.38
});
const count = Math.max(3, Math.floor((endRadius - startRadius) / 0.13));
const spacing = (endRadius - startRadius) / count;
for (let index = 0; index < count; index++) {
const radius = startRadius + spacing * (index + 0.5);
addBox(
arrowGroup,
[0.108, 0.108, 0.108],
[
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
],
arrowMaterial
);
}
// Pixel arrowhead
addBox(
arrowGroup,
[0.15, 0.15, 0.15],
[
Math.cos(angle) * endRadius,
y,
Math.sin(angle) * endRadius
],
arrowMaterial
);
const tangentX = -Math.sin(angle);
const tangentZ = Math.cos(angle);
for (const direction of [-1, 1]) {
const wingRadius = endRadius - 0.15;
addBox(
arrowGroup,
[0.12, 0.12, 0.12],
[
Math.cos(angle) * wingRadius +
tangentX * direction * 0.11,
y,
Math.sin(angle) * wingRadius +
tangentZ * direction * 0.11
],
arrowMaterial
);
}
const pulse = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.14, 0.14),
new THREE.MeshBasicMaterial({ color: 0xfff1b2 })
);
arrowGroup.add(pulse);
parent.add(arrowGroup);
heatPulses.push({
mesh: pulse,
angle,
y,
startRadius,
endRadius,
speed,
phase
});
}
function buildArrangement(x, type) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
if (type === "compact") {
buildPedestal(group, compactAccentMaterial);
buildVoxelCore(group);
buildCompactLayer(group);
// Longer arrows visually indicate more heat escaping.
[1.03, 2.02, 3.01].forEach((y, index) => {
createPixelArrow(
group,
THREE.MathUtils.degToRad(34),
y,
0.60,
1.58,
0.26,
index * 0.27
);
});
} else {
buildPedestal(group, airAccentMaterial);
buildVoxelCore(group);
buildAirTrappingLayer(group);
// Shorter arrows stop in the protected air gap.
[1.03, 2.02, 3.01].forEach((y, index) => {
createPixelArrow(
group,
THREE.MathUtils.degToRad(34),
y,
0.60,
1.07,
0.13,
index * 0.27
);
});
}
return group;
}
buildArrangement(-2.55, "compact");
buildArrangement(2.55, "air");
// Projected HTML labels
const labelAnchors = [
{
element: document.getElementById("label-compact"),
position: new THREE.Vector3(-2.55, 4.12, 0)
},
{
element: document.getElementById("label-air"),
position: new THREE.Vector3(2.55, 4.12, 0)
}
];
function positionLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const anchor of labelAnchors) {
const projected = anchor.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
anchor.element.style.visibility = visible ? "visible" : "hidden";
anchor.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
anchor.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// Direct camera controls: orbit, wheel zoom, and pointer pinch zoom.
const pointers = new Map();
let lastPointer = { x: 0, y: 0 };
let previousPinchDistance = 0;
function getPinchDistance() {
const values = Array.from(pointers.values());
if (values.length < 2) {
return 0;
}
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
previousPinchDistance = getPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) {
return;
}
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const deltaX = event.clientX - lastPointer.x;
const deltaY = event.clientY - lastPointer.y;
controls.targetTheta -= deltaX * 0.006;
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - deltaY * 0.005,
0.55,
1.46
);
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size >= 2) {
const distance = getPinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius *
(previousPinchDistance / distance),
8.4,
19.5
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = Array.from(pointers.values())[0];
lastPointer = { x: remaining.x, y: remaining.y };
}
previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
8.4,
19.5
);
},
{ passive: false }
);
function resetView() {
controls.targetTheta = 0.58;
controls.targetPhi = 1.13;
controls.targetRadius =
window.innerWidth / window.innerHeight < 0.8 ? 16 : 13.6;
}
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
canvas.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") {
controls.targetTheta -= 0.08;
} else if (key === "arrowright") {
controls.targetTheta += 0.08;
} else if (key === "arrowup") {
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - 0.06,
0.55,
1.46
);
} else if (key === "arrowdown") {
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi + 0.06,
0.55,
1.46
);
} else if (key === "+" || key === "=") {
controls.targetRadius = Math.max(8.4, controls.targetRadius - 0.7);
} else if (key === "-") {
controls.targetRadius = Math.min(19.5, controls.targetRadius + 0.7);
} else if (key === "enter") {
resetView();
}
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width / height < 0.8 ? 50 : 39;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
onResize();
// Animation
const clock = new THREE.Clock();
let elapsed = 0;
let firstFrame = true;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateCamera(delta);
const pulseStrength = reduceMotion
? 0
: Math.sin(elapsed * 2.1) * 0.45;
coreMaterial.emissiveIntensity = 0.62 + pulseStrength;
for (const light of coreLights) {
light.intensity = 10 + pulseStrength * 2.5;
}
for (const pulse of heatPulses) {
const progress = reduceMotion
? 0.55
: (elapsed * pulse.speed + pulse.phase) % 1;
const radius = THREE.MathUtils.lerp(
pulse.startRadius,
pulse.endRadius,
progress
);
pulse.mesh.position.set(
Math.cos(pulse.angle) * radius,
pulse.y,
Math.sin(pulse.angle) * radius
);
}
camera.updateMatrixWorld();
positionLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```