Prompt specification
Build or customize the Three.js 3D scene "Insulation structure classroom sandbox" 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: Insulation structure classroom sandbox
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/insulation-structure-classroom-sandbox-x0580
Scene Description Prompt:
Adjust low-poly textile spacing and compression around a symbolic heat source, showing illustrative insulation-flow arrows. Three.js from cdnjs, one HTML file.
Working Three.js Starter (insulation-structure-classroom-sandbox-x0580):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Thermal Textile — Low-Poly Insulation Study</title>
<style>
:root {
color-scheme: dark;
--bg: #061019;
--panel: rgba(9, 24, 34, 0.78);
--panel-border: rgba(147, 221, 218, 0.18);
--text: #e8f4f2;
--muted: #87a6aa;
--mint: #79ddd4;
--mint-bright: #b7fff2;
--orange: #ff9b4a;
--orange-bright: #ffd08a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
background:
radial-gradient(circle at 53% 47%, rgba(35, 99, 104, 0.2), transparent 27%),
radial-gradient(circle at 18% 16%, rgba(38, 85, 104, 0.17), transparent 35%),
linear-gradient(145deg, #07131d 0%, #050d15 52%, #08151c 100%);
}
#scene {
position: absolute;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(circle at center, transparent 45%, rgba(1, 7, 12, 0.3) 76%, rgba(1, 6, 10, 0.74) 100%);
}
header {
position: absolute;
z-index: 4;
top: 28px;
left: 32px;
max-width: 520px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--mint);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--mint);
box-shadow: 0 0 12px rgba(121, 221, 212, 0.8);
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 56px);
font-weight: 520;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 430px;
margin: 16px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.controls {
position: absolute;
z-index: 6;
left: 28px;
bottom: 28px;
width: min(340px, calc(100vw - 56px));
padding: 20px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(18px) saturate(125%);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 21px;
}
.panel-heading strong {
font-size: 11px;
font-weight: 720;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--mint);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 12px var(--mint);
animation: pulse 2s infinite;
}
@keyframes pulse {
50% {
opacity: 0.35;
}
}
.control {
margin-bottom: 20px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 12px;
}
.control-label span:first-child {
color: #d8e7e6;
font-weight: 580;
}
output {
color: var(--mint-bright);
font-variant-numeric: tabular-nums;
font-size: 11px;
}
.control-note {
margin-top: 7px;
color: #67888d;
font-size: 10px;
line-height: 1.45;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 3px;
margin: 4px 0;
border-radius: 10px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--mint) 0,
var(--mint) var(--fill),
rgba(132, 174, 177, 0.2) var(--fill),
rgba(132, 174, 177, 0.2) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #0b2029;
border-radius: 50%;
appearance: none;
background: var(--mint-bright);
box-shadow: 0 0 0 1px rgba(183, 255, 242, 0.4), 0 0 14px rgba(121, 221, 212, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #0b2029;
border-radius: 50%;
background: var(--mint-bright);
box-shadow: 0 0 0 1px rgba(183, 255, 242, 0.4), 0 0 14px rgba(121, 221, 212, 0.45);
}
#compression {
background: linear-gradient(
to right,
var(--orange) 0,
var(--orange) var(--fill),
rgba(132, 174, 177, 0.2) var(--fill),
rgba(132, 174, 177, 0.2) 100%
);
}
#compression::-webkit-slider-thumb {
background: var(--orange-bright);
box-shadow: 0 0 0 1px rgba(255, 208, 138, 0.45), 0 0 14px rgba(255, 155, 74, 0.5);
}
#compression::-moz-range-thumb {
background: var(--orange-bright);
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 15px;
border-top: 1px solid rgba(143, 204, 203, 0.11);
}
.switch-row span {
color: #c8d9d8;
font-size: 12px;
font-weight: 560;
}
.switch {
position: relative;
display: inline-block;
width: 38px;
height: 21px;
}
.switch input {
width: 0;
height: 0;
opacity: 0;
}
.slider {
position: absolute;
inset: 0;
border: 1px solid rgba(144, 204, 203, 0.24);
border-radius: 20px;
background: rgba(121, 221, 212, 0.12);
cursor: pointer;
transition: 160ms ease;
}
.slider::before {
position: absolute;
left: 3px;
bottom: 3px;
width: 13px;
height: 13px;
content: "";
border-radius: 50%;
background: #86a6aa;
transition: 160ms ease;
}
.switch input:checked + .slider {
border-color: rgba(121, 221, 212, 0.6);
background: rgba(121, 221, 212, 0.25);
}
.switch input:checked + .slider::before {
transform: translateX(17px);
background: var(--mint-bright);
box-shadow: 0 0 12px rgba(121, 221, 212, 0.7);
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 18px;
}
.metric {
padding: 10px 9px;
border: 1px solid rgba(143, 204, 203, 0.1);
border-radius: 10px;
background: rgba(3, 13, 20, 0.28);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: #62858a;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
color: #d7ebe8;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 16px;
}
.disclaimer {
color: #56777c;
font-size: 9px;
line-height: 1.4;
}
.reset {
flex: 0 0 auto;
padding: 7px 11px;
border: 1px solid rgba(121, 221, 212, 0.2);
border-radius: 8px;
color: var(--mint);
background: transparent;
font-size: 10px;
cursor: pointer;
transition: 150ms ease;
}
.reset:hover {
border-color: rgba(121, 221, 212, 0.55);
background: rgba(121, 221, 212, 0.08);
}
.legend {
position: absolute;
z-index: 4;
top: 32px;
right: 30px;
width: 190px;
padding: 15px 16px;
border: 1px solid rgba(147, 221, 218, 0.12);
border-radius: 14px;
background: rgba(6, 18, 27, 0.54);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 12px;
color: #6e9195;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 9px 0;
color: #adc3c2;
font-size: 10px;
}
.swatch {
width: 18px;
height: 3px;
flex: 0 0 auto;
border-radius: 5px;
}
.swatch.heat {
background: var(--orange);
box-shadow: 0 0 9px rgba(255, 155, 74, 0.65);
}
.swatch.textile {
height: 8px;
border: 1px solid var(--mint);
background: rgba(121, 221, 212, 0.18);
}
.swatch.flow {
background: linear-gradient(90deg, var(--orange), var(--mint));
box-shadow: 0 0 8px rgba(121, 221, 212, 0.3);
}
.world-label {
position: absolute;
z-index: 3;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 7px;
color: #c8dcda;
background: rgba(5, 15, 22, 0.68);
backdrop-filter: blur(8px);
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.world-label::before {
width: 5px;
height: 5px;
content: "";
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 9px var(--mint);
}
#heatLabel::before {
background: var(--orange);
box-shadow: 0 0 9px var(--orange);
}
.hint {
position: absolute;
z-index: 4;
right: 30px;
bottom: 28px;
color: #5e7d82;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: var(--mint);
background: #061019;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 20px;
left: 20px;
right: 20px;
}
.subtitle {
max-width: 320px;
font-size: 11px;
}
.legend,
.hint,
.world-label {
display: none;
}
.controls {
right: 16px;
bottom: 16px;
left: 16px;
width: auto;
padding: 16px;
}
.control {
margin-bottom: 15px;
}
.metrics {
margin-top: 13px;
}
.panel-footer {
margin-top: 12px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene" aria-label="Interactive low-poly textile insulation visualization"></div>
<div class="vignette"></div>
<header>
<div class="eyebrow">Thermal field / Textile study 04</div>
<h1>Insulation,<br />under pressure.</h1>
<p class="subtitle">
Adjust the course spacing and compression of a faceted textile shell
surrounding a symbolic heat source.
</p>
</header>
<section class="controls" aria-label="Textile controls">
<div class="panel-heading">
<strong>Material Controls</strong>
<span class="live">Live model</span>
</div>
<div class="control">
<label class="control-label" for="spacing">
<span>Textile spacing</span>
<output id="spacingValue">0.28</output>
</label>
<input id="spacing" type="range" min="0.14" max="0.42" step="0.01" value="0.28" />
<div class="control-note">Separates the four visible insulation courses.</div>
</div>
<div class="control">
<label class="control-label" for="compression">
<span>Compression</span>
<output id="compressionValue">32%</output>
</label>
<input id="compression" type="range" min="0" max="100" step="1" value="32" />
<div class="control-note">Pulls the courses inward and shortens protruding fibers.</div>
</div>
<div class="switch-row">
<span>Illustrative flow arrows</span>
<label class="switch">
<input id="showFlow" type="checkbox" checked aria-label="Show illustrative flow arrows" />
<span class="slider"></span>
</label>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Courses</span>
<span class="metric-value">04</span>
</div>
<div class="metric">
<span class="metric-label">Gap index</span>
<span class="metric-value" id="gapMetric">0.19</span>
</div>
<div class="metric">
<span class="metric-label">Fiber length</span>
<span class="metric-value" id="fiberMetric">92%</span>
</div>
</div>
<div class="panel-footer">
<span class="disclaimer">Relative visual model<br />Not a thermal simulation</span>
<button class="reset" id="reset" type="button">Reset study</button>
</div>
</section>
<aside class="legend" aria-label="Visualization legend">
<div class="legend-title">Reading the field</div>
<div class="legend-row"><span class="swatch heat"></span>Symbolic heat source</div>
<div class="legend-row"><span class="swatch textile"></span>Low-poly textile courses</div>
<div class="legend-row"><span class="swatch flow"></span>Illustrative displaced flow</div>
</aside>
<div class="world-label" id="heatLabel">Heat source</div>
<div class="world-label" id="textileLabel">Textile envelope</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<div id="loading">Constructing thermal field</div>
</main>
<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.querySelector("#scene");
const loading = document.querySelector("#loading");
const spacingInput = document.querySelector("#spacing");
const compressionInput = document.querySelector("#compression");
const spacingValue = document.querySelector("#spacingValue");
const compressionValue = document.querySelector("#compressionValue");
const gapMetric = document.querySelector("#gapMetric");
const fiberMetric = document.querySelector("#fiberMetric");
const showFlowInput = document.querySelector("#showFlow");
const resetButton = document.querySelector("#reset");
const heatLabel = document.querySelector("#heatLabel");
const textileLabel = document.querySelector("#textileLabel");
const COURSE_COUNT = 4;
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is unavailable";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x061019, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x061019, 0.033);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
yaw: 0.68,
pitch: 0.31,
distance: 8.2,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const cosPitch = Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + orbit.distance * cosPitch * Math.sin(orbit.yaw),
orbit.target.y + orbit.distance * Math.sin(orbit.pitch),
orbit.target.z + orbit.distance * cosPitch * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
}
updateCamera();
// Lighting.
scene.add(new THREE.HemisphereLight(0x9ed9e0, 0x11121b, 1.25));
const keyLight = new THREE.DirectionalLight(0xe8ffff, 2.25);
keyLight.position.set(4, 6, 5);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x47bfc8, 1.6);
rimLight.position.set(-5, 2, -4);
scene.add(rimLight);
const fillLight = new THREE.DirectionalLight(0xffa061, 0.9);
fillLight.position.set(3, -1, 2);
scene.add(fillLight);
// Subtle suspended particles.
const particleCount = 280;
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i++) {
const radius = 5.2 + Math.random() * 7;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
particlePositions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
particlePositions[i * 3 + 1] = radius * Math.cos(phi);
particlePositions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particleMaterial = new THREE.PointsMaterial({
color: 0x81c8ca,
size: 0.035,
transparent: true,
opacity: 0.32,
depthWrite: false,
sizeAttenuation: true
});
const particles = new THREE.Points(particleGeometry, particleMaterial);
scene.add(particles);
// Low-poly platform.
const platform = new THREE.Group();
platform.position.y = -2.34;
scene.add(platform);
const platformMesh = new THREE.Mesh(
new THREE.CircleGeometry(4.15, 64),
new THREE.MeshStandardMaterial({
color: 0x081821,
roughness: 0.95,
metalness: 0.05,
transparent: true,
opacity: 0.62,
side: THREE.DoubleSide
})
);
platformMesh.rotation.x = -Math.PI / 2;
platform.add(platformMesh);
[2.45, 2.85, 3.3, 3.8].forEach((radius, index) => {
const ring = new THREE.Mesh(
new THREE.RingGeometry(radius - 0.008, radius + 0.008, 96),
new THREE.MeshBasicMaterial({
color: index < 2 ? 0x39777b : 0x244d56,
transparent: true,
opacity: index < 2 ? 0.26 : 0.15,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
platform.add(ring);
});
// Symbolic heat source.
const heatGroup = new THREE.Group();
scene.add(heatGroup);
const heatCore = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.76, 1),
new THREE.MeshStandardMaterial({
color: 0xffa14d,
emissive: 0xff4b0b,
emissiveIntensity: 2.7,
roughness: 0.35,
metalness: 0.04,
flatShading: true
})
);
heatGroup.add(heatCore);
const heatInner = new THREE.Mesh(
new THREE.OctahedronGeometry(0.43, 0),
new THREE.MeshStandardMaterial({
color: 0xffe2a4,
emissive: 0xff8b23,
emissiveIntensity: 3.5,
roughness: 0.2,
flatShading: true
})
);
heatGroup.add(heatInner);
const heatEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.79, 1)),
new THREE.LineBasicMaterial({
color: 0xffd09a,
transparent: true,
opacity: 0.58
})
);
heatGroup.add(heatEdges);
const heatLight = new THREE.PointLight(0xff6b20, 16, 8, 2);
heatGroup.add(heatLight);
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(64, 64, 0, 64, 64, 64);
gradient.addColorStop(0, "rgba(255, 231, 171, 1)");
gradient.addColorStop(0.2, "rgba(255, 145, 54, 0.72)");
gradient.addColorStop(0.52, "rgba(255, 78, 16, 0.2)");
gradient.addColorStop(1, "rgba(255, 60, 10, 0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const glowMaterial = new THREE.SpriteMaterial({
map: makeGlowTexture(),
color: 0xff8a35,
transparent: true,
opacity: 0.42,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const heatGlow = new THREE.Sprite(glowMaterial);
heatGlow.scale.set(3.1, 3.1, 1);
heatGroup.add(heatGlow);
// Textile courses.
const textileGroup = new THREE.Group();
scene.add(textileGroup);
let outerTextileRadius = 1.85;
let currentSpacing = Number(spacingInput.value);
let currentCompression = Number(compressionInput.value) / 100;
function disposeGroup(group) {
const geometries = new Set();
const materials = new Set();
group.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
const objectMaterials = Array.isArray(object.material)
? object.material
: [object.material];
objectMaterials.forEach((material) => materials.add(material));
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
group.clear();
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
function buildTextile() {
disposeGroup(textileGroup);
currentSpacing = Number(spacingInput.value);
currentCompression = Number(compressionInput.value) / 100;
const effectiveGap =
currentSpacing * (1 - 0.45 * currentCompression);
const radialCompression = 1 - 0.12 * currentCompression;
const verticalCompression = 1 - 0.13 * currentCompression;
const innerRadius = 1.04;
const innerColor = new THREE.Color(0x5acfc9);
const outerColor = new THREE.Color(0xc0d7ca);
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
const axis = new THREE.Vector3(0, 1, 0);
for (let course = 0; course < COURSE_COUNT; course++) {
const radius =
(innerRadius + course * effectiveGap) * radialCompression;
const layerColor = new THREE.Color().lerpColors(
innerColor,
outerColor,
course / (COURSE_COUNT - 1)
);
const layer = new THREE.Group();
layer.scale.y = verticalCompression;
textileGroup.add(layer);
const shellGeometry = new THREE.IcosahedronGeometry(radius, 1);
const shell = new THREE.Mesh(
shellGeometry,
new THREE.MeshStandardMaterial({
color: layerColor,
roughness: 1,
metalness: 0,
transparent: true,
opacity: 0.026,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true
})
);
shell.renderOrder = 10 + course;
layer.add(shell);
const lattice = new THREE.Mesh(
shellGeometry,
new THREE.MeshBasicMaterial({
color: layerColor,
wireframe: true,
transparent: true,
opacity: 0.18 - course * 0.018,
depthWrite: false
})
);
lattice.renderOrder = 14 + course;
layer.add(lattice);
const fiberCount = 72 + course * 16;
const fiberGeometry = new THREE.CylinderGeometry(
0.018,
0.009,
1,
5,
1,
false
);
const fiberMaterial = new THREE.MeshStandardMaterial({
color: layerColor,
roughness: 0.94,
metalness: 0,
emissive: layerColor,
emissiveIntensity: 0.08,
flatShading: true
});
const fibers = new THREE.InstancedMesh(
fiberGeometry,
fiberMaterial,
fiberCount
);
fibers.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
fibers.renderOrder = 18 + course;
const random = seededRandom(9173 + course * 193);
const dummy = new THREE.Object3D();
const normal = new THREE.Vector3();
const position = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
for (let fiber = 0; fiber < fiberCount; fiber++) {
const y = 1 - (fiber / (fiberCount - 1)) * 2;
const ringRadius = Math.sqrt(Math.max(0, 1 - y * y));
const theta = goldenAngle * fiber;
const jitter = 1 + (random() - 0.5) * 0.075;
normal
.set(
Math.cos(theta) * ringRadius,
y,
Math.sin(theta) * ringRadius
)
.multiplyScalar(jitter)
.normalize();
position.copy(normal).multiplyScalar(radius);
quaternion.setFromUnitVectors(axis, normal);
const length =
(0.12 + random() * 0.095) *
(1 - 0.28 * currentCompression) *
(1 - course * 0.035);
scale.set(1, length, 1);
dummy.position.copy(position);
dummy.quaternion.copy(quaternion);
dummy.scale.copy(scale);
dummy.updateMatrix();
fibers.setMatrixAt(fiber, dummy.matrix);
const fiberTint = layerColor.clone().offsetHSL(
(random() - 0.5) * 0.025,
0,
(random() - 0.5) * 0.1
);
fibers.setColorAt(fiber, fiberTint);
}
fibers.instanceMatrix.needsUpdate = true;
if (fibers.instanceColor) fibers.instanceColor.needsUpdate = true;
layer.add(fibers);
}
outerTextileRadius =
(innerRadius + (COURSE_COUNT - 1) * effectiveGap) *
radialCompression;
updateReadouts(effectiveGap);
}
// Illustrative, curved insulation-flow arrows.
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const flowTracers = [];
const flowMaterials = [];
const warmColor = new THREE.Color(0xff8c43);
const coolColor = new THREE.Color(0x79e1df);
function spherical(radius, azimuth, elevation) {
return new THREE.Vector3(
radius * Math.cos(elevation) * Math.cos(azimuth),
radius * Math.sin(elevation),
radius * Math.cos(elevation) * Math.sin(azimuth)
);
}
function buildFlow() {
const elevations = [-0.42, -0.1, 0.24, 0.45, 0.08, -0.28];
for (let arrowIndex = 0; arrowIndex < 6; arrowIndex++) {
const azimuth = arrowIndex * (Math.PI / 3) + 0.16;
const elevation = elevations[arrowIndex];
const points = [
spherical(4.05, azimuth, elevation),
spherical(3.15, azimuth + 0.18, elevation + 0.03),
spherical(2.32, azimuth + 0.48, elevation + 0.05),
spherical(1.43, azimuth + 0.86, elevation),
spherical(1.67, azimuth + 1.31, elevation - 0.04),
spherical(2.72, azimuth + 1.76, elevation - 0.02),
spherical(3.78, azimuth + 2.1, elevation)
];
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.38
);
const geometry = new THREE.TubeGeometry(
curve,
72,
0.019,
5,
false
);
const positionAttribute = geometry.getAttribute("position");
const colors = new Float32Array(positionAttribute.count * 3);
const color = new THREE.Color();
for (let vertex = 0; vertex < positionAttribute.count; vertex++) {
const vertexPosition = new THREE.Vector3().fromBufferAttribute(
positionAttribute,
vertex
);
const mix = THREE.MathUtils.clamp(
(vertexPosition.length() - 1.2) / 2.5,
0,
1
);
color.copy(warmColor).lerp(coolColor, mix);
colors[vertex * 3] = color.r;
colors[vertex * 3 + 1] = color.g;
colors[vertex * 3 + 2] = color.b;
}
geometry.setAttribute(
"color",
new THREE.BufferAttribute(colors, 3)
);
const material = new THREE.MeshBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.78,
depthTest: false,
depthWrite: false
});
const tube = new THREE.Mesh(geometry, material);
tube.renderOrder = 30;
flowGroup.add(tube);
flowMaterials.push(material);
const end = curve.getPointAt(1);
const tangent = curve.getTangentAt(1).normalize();
const headMaterial = new THREE.MeshBasicMaterial({
color: coolColor,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.078, 0.22, 7),
headMaterial
);
arrowHead.position.copy(end);
arrowHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrowHead.renderOrder = 31;
flowGroup.add(arrowHead);
flowMaterials.push(headMaterial);
for (let tracer = 0; tracer < 3; tracer++) {
const tracerMaterial = new THREE.MeshBasicMaterial({
color: warmColor,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const tracerMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.034, 7, 5),
tracerMaterial
);
tracerMesh.renderOrder = 32;
flowGroup.add(tracerMesh);
flowTracers.push({
mesh: tracerMesh,
curve,
phase: tracer / 3 + arrowIndex * 0.071,
material: tracerMaterial
});
}
}
}
buildFlow();
// Projected DOM labels.
const projected = new THREE.Vector3();
const heatLabelPosition = new THREE.Vector3(0.48, 0.96, 0.54);
const textileLabelPosition = new THREE.Vector3();
function placeLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform = `translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
function updateReadouts(effectiveGap) {
spacingValue.textContent = currentSpacing.toFixed(2);
compressionValue.textContent = `${Math.round(currentCompression * 100)}%`;
gapMetric.textContent = effectiveGap.toFixed(2);
fiberMetric.textContent = `${Math.round(
(1 - 0.28 * currentCompression) * 100
)}%`;
const spacingFill =
((currentSpacing - Number(spacingInput.min)) /
(Number(spacingInput.max) - Number(spacingInput.min))) *
100;
const compressionFill = currentCompression * 100;
spacingInput.style.setProperty("--fill", `${spacingFill}%`);
compressionInput.style.setProperty("--fill", `${compressionFill}%`);
}
buildTextile();
spacingInput.addEventListener("input", buildTextile);
compressionInput.addEventListener("input", buildTextile);
showFlowInput.addEventListener("change", () => {
flowGroup.visible = showFlowInput.checked;
});
// Direct camera controls, implemented without external addons.
const canvas = renderer.domElement;
let dragging = false;
let previousX = 0;
let previousY = 0;
function resetCamera() {
orbit.yaw = 0.68;
orbit.pitch = 0.31;
orbit.distance = 8.2;
orbit.target.set(0, 0, 0);
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.yaw -= deltaX * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + deltaY * 0.005,
-0.22,
1.15
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance * Math.exp(event.deltaY * 0.001),
4.25,
12
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", () => {
spacingInput.value = "0.28";
compressionInput.value = "32";
showFlowInput.checked = true;
flowGroup.visible = true;
buildTextile();
resetCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
const tracerColor = new THREE.Color();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
heatCore.rotation.y = elapsed * 0.13;
heatCore.rotation.x = elapsed * 0.07;
heatInner.rotation.y = -elapsed * 0.22;
heatEdges.rotation.copy(heatCore.rotation);
const heatPulse = 1 + Math.sin(elapsed * 2.15) * 0.035;
heatGroup.scale.setScalar(heatPulse);
glowMaterial.opacity = 0.37 + Math.sin(elapsed * 2.15) * 0.07;
particles.rotation.y = elapsed * 0.012;
particles.rotation.x = Math.sin(elapsed * 0.08) * 0.035;
flowMaterials.forEach((material, index) => {
material.opacity =
0.68 + Math.sin(elapsed * 1.4 + index * 0.33) * 0.13;
});
flowTracers.forEach((tracer) => {
const progress = (elapsed * 0.085 + tracer.phase) % 1;
const point = tracer.curve.getPointAt(progress);
const mix = THREE.MathUtils.clamp(
(point.length() - 1.2) / 2.5,
0,
1
);
tracer.mesh.position.copy(point);
tracerColor.copy(warmColor).lerp(coolColor, mix);
tracer.material.color.copy(tracerColor);
});
textileLabelPosition.set(
outerTextileRadius * 0.68,
outerTextileRadius * 0.47,
outerTextileRadius * 0.1
);
placeLabel(heatLabel, heatLabelPosition);
placeLabel(textileLabel, textileLabelPosition);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```