Prompt specification
Build or customize the Three.js 3D scene "Different-conductivity bar comparison" 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: Different-conductivity bar comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/different-conductivity-bar-comparison-x1474
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows heat conduction through solid materials. Place equal-sized bars with different model conductivities between identical hot and cold boundaries; compare steady temperature gradients and heat-flow rates under stated conditions. Stylized solid forms.
Working Three.js Starter (different-conductivity-bar-comparison-x1474):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="dark" />
<title>Heat Conduction Through Solid Materials</title>
<style>
:root {
--bg: #07111d;
--panel: rgba(8, 18, 32, 0.82);
--panel-border: rgba(167, 206, 235, 0.15);
--text: #eef7ff;
--muted: #9db2c6;
--hot: #ff655f;
--cold: #3488ff;
--mid: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 28% 22%, rgba(35, 83, 121, 0.28), transparent 38%),
radial-gradient(circle at 80% 70%, rgba(63, 38, 104, 0.18), transparent 42%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.36),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
.title-card {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(460px, calc(100vw - 44px));
padding: 21px 22px 18px;
border-radius: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: #8ed7ff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #64d7ff;
box-shadow: 0 0 15px #64d7ff;
content: "";
}
h1 {
max-width: 420px;
margin: 10px 0 7px;
font-size: clamp(27px, 3.2vw, 39px);
line-height: 1.04;
letter-spacing: -0.045em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.conditions {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 16px;
}
.condition {
padding: 9px 8px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.condition small,
.metric small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.condition b {
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.hot-text {
color: #ff8b83;
}
.cold-text {
color: #73b7ff;
}
.toolbar {
display: flex;
gap: 8px;
margin-top: 13px;
}
.tool-button {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 34px;
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #dbeafe;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.tool-button:hover {
border-color: rgba(142, 215, 255, 0.35);
background: rgba(111, 201, 255, 0.11);
transform: translateY(-1px);
}
.tool-button:focus-visible {
outline: 2px solid #74d3ff;
outline-offset: 2px;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
width: 370px;
max-height: calc(100vh - 44px);
padding: 18px;
overflow: auto;
border-radius: 20px;
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.steady-badge {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid rgba(109, 227, 170, 0.22);
border-radius: 999px;
background: rgba(57, 205, 129, 0.08);
color: #89efb8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.equation {
margin-bottom: 14px;
padding: 13px 14px;
border: 1px solid rgba(118, 196, 255, 0.16);
border-radius: 14px;
background:
linear-gradient(135deg, rgba(73, 154, 225, 0.11), rgba(255, 255, 255, 0.025));
}
.equation-title {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.equation-main {
display: flex;
align-items: baseline;
gap: 10px;
margin-top: 5px;
}
.equation strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 500;
letter-spacing: 0.01em;
}
.equation code {
color: #a9c2d8;
font-size: 11px;
}
.gradient-row {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 9px;
padding-top: 9px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #cfe3f4;
font-size: 11px;
}
.gradient-row b {
color: white;
font-variant-numeric: tabular-nums;
}
.section-label {
margin: 15px 0 8px;
color: #839ab0;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.model-list {
display: grid;
gap: 8px;
}
.model-card {
position: relative;
padding: 11px 12px 10px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 13px;
background: rgba(255, 255, 255, 0.03);
}
.model-card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
background: var(--accent);
box-shadow: 0 0 15px color-mix(in srgb, var(--accent) 55%, transparent);
content: "";
}
.model-head {
display: flex;
align-items: center;
gap: 8px;
}
.model-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 65%, transparent);
}
.model-name {
flex: 1;
min-width: 0;
}
.model-name strong {
display: block;
font-size: 12px;
}
.model-name small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.metric {
padding: 8px;
border-radius: 9px;
background: rgba(0, 0, 0, 0.15);
}
.metric b {
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.flow-track {
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.07);
}
.flow-track span {
display: block;
height: 100%;
min-width: 2px;
border-radius: inherit;
background: linear-gradient(90deg, var(--hot), #fff0a1, var(--cold));
box-shadow: 0 0 10px rgba(255, 215, 135, 0.5);
}
.insight {
margin-top: 13px;
padding: 12px 13px;
border-left: 3px solid #74d3ff;
border-radius: 4px 11px 11px 4px;
background: rgba(90, 175, 240, 0.075);
color: #c8d9e8;
font-size: 11px;
line-height: 1.55;
}
.insight strong {
color: white;
}
.assumptions {
margin: 12px 2px 0;
color: #8198ae;
font-size: 10px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 10;
bottom: 22px;
left: 22px;
width: 330px;
padding: 13px 15px;
border-radius: 16px;
}
.legend-title {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.legend-title span:last-child {
color: var(--muted);
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.thermal-gradient {
height: 9px;
border-radius: 99px;
background: linear-gradient(90deg, #3488ff 0%, #ffd166 50%, #ff655f 100%);
box-shadow: 0 0 18px rgba(91, 165, 255, 0.18);
}
.legend-values {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #aec1d2;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.flow-key {
display: flex;
align-items: center;
gap: 8px;
margin-top: 9px;
color: #9fb3c5;
font-size: 9px;
line-height: 1.35;
}
.flow-symbol {
position: relative;
width: 35px;
height: 10px;
flex: 0 0 auto;
}
.flow-symbol::before {
position: absolute;
top: 4px;
left: 0;
width: 27px;
height: 2px;
background: white;
content: "";
}
.flow-symbol::after {
position: absolute;
top: 1px;
right: 0;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 7px solid white;
content: "";
}
.hint {
position: fixed;
z-index: 8;
bottom: 25px;
left: 50%;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
background: rgba(5, 13, 24, 0.55);
color: #8fa5b9;
font-size: 10px;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
#world-labels {
position: fixed;
z-index: 6;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(6, 14, 25, 0.76);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.25);
color: #e9f5ff;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.world-label.boundary {
padding: 6px 9px;
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.world-label.model-label {
border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.world-label.model-label::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
background: var(--accent);
content: "";
}
.world-label.dimension {
color: #9fb5c8;
font-size: 9px;
font-weight: 600;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #07111d;
color: #b8d9ef;
font-size: 13px;
letter-spacing: 0.08em;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 960px) {
.title-card {
width: min(420px, calc(100vw - 32px));
top: 16px;
left: 16px;
}
.panel {
top: auto;
right: 16px;
bottom: 16px;
left: 16px;
width: auto;
max-height: 43vh;
border-radius: 18px;
}
.legend,
.hint {
display: none;
}
}
@media (max-width: 600px) {
.title-card {
padding: 16px;
}
.subtitle {
font-size: 11px;
}
.conditions {
grid-template-columns: repeat(2, 1fr);
}
.condition {
padding: 7px;
}
.tool-button {
padding: 6px 9px;
font-size: 11px;
}
.panel {
max-height: 39vh;
padding: 14px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="world-labels"></div>
<header class="title-card glass">
<div class="eyebrow">Thermal comparison bench</div>
<h1>Heat Conduction Through Solid Materials</h1>
<p class="subtitle">
Equal-sized solids connect identical hot and cold boundaries.
Conductivity changes the heat-transfer rate, while fixed endpoint
temperatures produce the same linear temperature gradient.
</p>
<div class="conditions">
<div class="condition">
<small>Hot boundary</small>
<b class="hot-text">373 K</b>
</div>
<div class="condition">
<small>Cold boundary</small>
<b class="cold-text">273 K</b>
</div>
<div class="condition">
<small>Length</small>
<b>6.0 m</b>
</div>
<div class="condition">
<small>Area</small>
<b>1.0 m²</b>
</div>
</div>
<div class="toolbar">
<button class="tool-button" id="pause-button" type="button">
<span id="pause-symbol">Ⅱ</span>
<span id="pause-text">Pause flow</span>
</button>
<button class="tool-button" id="reset-button" type="button">↺ Reset view</button>
</div>
</header>
<aside class="panel glass">
<div class="panel-heading">
<div>
<h2>Steady-state comparison</h2>
<p>Three illustrative model solids with identical geometry.</p>
</div>
<span class="steady-badge">1D steady</span>
</div>
<div class="equation">
<div class="equation-title">Fourier conduction law</div>
<div class="equation-main">
<strong>Q = k A ΔT / L</strong>
<code>Q [W], k [W/m·K]</code>
</div>
<div class="gradient-row">
<span>Temperature gradient</span>
<b>|∇T| = ΔT/L = 16.7 K/m</b>
</div>
</div>
<div class="section-label">Model conductivities</div>
<div class="model-list" id="model-list"></div>
<div class="insight">
<strong>Key comparison:</strong> with the same prescribed end temperatures,
every bar has the same linear temperature profile and gradient.
The heat rate <strong>Q varies linearly with conductivity k</strong>.
</div>
<p class="assumptions">
Assumptions: one-dimensional steady-state conduction, no internal heat
generation, constant conductivity, perfect thermal contact, and no
convection or radiation from the bar surfaces. The 3D geometry is
stylized; the stated length and area define the calculations.
</p>
</aside>
<div class="legend glass">
<div class="legend-title">
<span>Local temperature</span>
<span>Color follows T(x)</span>
</div>
<div class="thermal-gradient"></div>
<div class="legend-values">
<span>273 K · cold</span>
<span>323 K</span>
<span>373 K · hot</span>
</div>
<div class="flow-key">
<span class="flow-symbol"></span>
<span>Moving markers indicate relative heat rate; marker speed and count scale with Q.</span>
</div>
</div>
<div class="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<div id="loading">Loading 3D thermal bench…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Physical conditions
// -------------------------------------------------------------------------
const LENGTH = 6.0; // m
const AREA = 1.0; // m²
const HOT_TEMP = 373; // K
const COLD_TEMP = 273; // K
const DELTA_T = HOT_TEMP - COLD_TEMP;
const GRADIENT = DELTA_T / LENGTH;
const models = [
{
id: "low",
name: "Low-k composite",
k: 5,
z: -2.35,
accent: "#7dd3fc",
roughness: 0.76,
metalness: 0.05
},
{
id: "mid",
name: "Mid-k alloy",
k: 50,
z: 0,
accent: "#fde68a",
roughness: 0.38,
metalness: 0.46
},
{
id: "high",
name: "High-k solid",
k: 200,
z: 2.35,
accent: "#fda4af",
roughness: 0.22,
metalness: 0.7
}
];
models.forEach((model) => {
model.q = (model.k * AREA * DELTA_T) / LENGTH;
model.flux = model.q / AREA;
});
const maxQ = Math.max(...models.map((model) => model.q));
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of heat conduction through three solid bars"
);
document.getElementById("scene").appendChild(renderer.domElement);
const cameraState = {
theta: 0.34,
phi: 1.03,
radius: 15.8,
target: new THREE.Vector3(0, -0.1, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.34;
cameraState.phi = 1.03;
cameraState.radius = 15.8;
cameraState.target.set(0, -0.1, 0);
updateCamera();
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9e6ff, 0x111827, 2.15));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(3.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x74bfff, 1.6);
rimLight.position.set(-8, 5, -7);
scene.add(rimLight);
const hotLight = new THREE.PointLight(0xff4f32, 28, 7, 2);
hotLight.position.set(-4.2, 1.1, 0);
scene.add(hotLight);
const coldLight = new THREE.PointLight(0x318dff, 24, 7, 2);
coldLight.position.set(4.2, 1.1, 0);
scene.add(coldLight);
// -------------------------------------------------------------------------
// Stylized platform and grid
// -------------------------------------------------------------------------
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1725,
roughness: 0.8,
metalness: 0.16
});
const platform = new THREE.Mesh(
new THREE.BoxGeometry(11.6, 0.34, 9.2),
platformMaterial
);
platform.position.y = -1.42;
platform.receiveShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(11, 28, 0x28506b, 0x153047);
grid.position.y = -1.235;
grid.scale.z = 0.78;
grid.material.transparent = true;
grid.material.opacity = 0.45;
scene.add(grid);
// -------------------------------------------------------------------------
// Identical hot and cold boundary plates
// -------------------------------------------------------------------------
function createBoundaryPlate(x, color, emissive) {
const material = new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity: 0.55,
roughness: 0.28,
metalness: 0.4
});
const plate = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 2.75, 8.15),
material
);
plate.position.x = x;
plate.castShadow = true;
plate.receiveShadow = true;
scene.add(plate);
const capMaterial = new THREE.MeshStandardMaterial({
color: emissive,
emissive,
emissiveIntensity: 0.8,
roughness: 0.3,
metalness: 0.25
});
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 2.85, 8.25),
capMaterial
);
cap.position.x = x + (x < 0 ? -0.035 : 0.035);
cap.castShadow = true;
scene.add(cap);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(cap.geometry),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.18
})
);
edge.position.copy(cap.position);
scene.add(edge);
}
createBoundaryPlate(-3.15, 0x9d2e2b, 0xff4939);
createBoundaryPlate(3.15, 0x235e9c, 0x287dff);
// -------------------------------------------------------------------------
// Thermal color mapping and solid bars
// -------------------------------------------------------------------------
const coldColor = new THREE.Color(0x3488ff);
const midColor = new THREE.Color(0xffd166);
const hotColor = new THREE.Color(0xff655f);
function thermalColor(t, output) {
t = THREE.MathUtils.clamp(t, 0, 1);
if (t < 0.5) {
output.copy(coldColor).lerp(midColor, t * 2);
} else {
output.copy(midColor).lerp(hotColor, (t - 0.5) * 2);
}
return output;
}
const barGeometry = new THREE.BoxGeometry(
LENGTH,
1.08,
1.08,
72,
4,
4
);
const positions = barGeometry.attributes.position;
const vertexColors = new Float32Array(positions.count * 3);
const workingColor = new THREE.Color();
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const t = (x + LENGTH / 2) / LENGTH;
thermalColor(t, workingColor);
vertexColors[i * 3] = workingColor.r;
vertexColors[i * 3 + 1] = workingColor.g;
vertexColors[i * 3 + 2] = workingColor.b;
}
barGeometry.setAttribute(
"color",
new THREE.BufferAttribute(vertexColors, 3)
);
const flowMarkers = [];
const labelItems = [];
function createWorldLabel(html, position, className = "", accent = null) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
if (accent) {
element.style.setProperty("--accent", accent);
}
document.getElementById("world-labels").appendChild(element);
labelItems.push({ element, position: position.clone() });
return element;
}
const markerGeometry = new THREE.SphereGeometry(0.075, 12, 8);
models.forEach((model) => {
const group = new THREE.Group();
group.position.z = model.z;
scene.add(group);
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: model.roughness,
metalness: model.metalness,
emissive: 0x090b0d,
emissiveIntensity: 0.18
});
const bar = new THREE.Mesh(barGeometry, material);
bar.castShadow = true;
bar.receiveShadow = true;
group.add(bar);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(barGeometry, 25),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.52
})
);
group.add(edge);
// Subtle rail beneath each solid.
const rail = new THREE.Mesh(
new THREE.BoxGeometry(LENGTH + 0.22, 0.16, 1.24),
new THREE.MeshStandardMaterial({
color: 0x101f2d,
roughness: 0.65,
metalness: 0.35
})
);
rail.position.y = -0.69;
rail.castShadow = true;
rail.receiveShadow = true;
group.add(rail);
// Tick marks at one-meter intervals.
const tickPositions = [];
for (let x = -2; x <= 2; x++) {
tickPositions.push(x, 0.548, -0.49);
tickPositions.push(x, 0.548, 0.49);
}
const tickGeometry = new THREE.BufferGeometry();
tickGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tickPositions, 3)
);
const ticks = new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.22
})
);
group.add(ticks);
// A small arrow establishes the hot-to-cold flow direction.
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-2.55, 0.76, 0),
1.45,
0xffffff,
0.22,
0.12
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.65;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.8;
group.add(arrow);
// Marker count and speed encode relative heat rate qualitatively.
const ratio = model.q / maxQ;
const markerCount = 4 + Math.round(ratio * 8);
const markerSpeed = 0.22 + ratio * 0.78;
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.9
});
for (let i = 0; i < markerCount; i++) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.y = 0.73;
marker.position.z = ((i % 3) - 1) * 0.22;
marker.userData.phase = i / markerCount;
marker.userData.speed = markerSpeed;
marker.userData.z = marker.position.z;
group.add(marker);
flowMarkers.push(marker);
}
createWorldLabel(
`${model.name} · k ${model.k} W/m·K`,
new THREE.Vector3(-0.45, 1.02, model.z),
"model-label",
model.accent
);
});
// Boundary and dimension labels.
createWorldLabel(
"Hot boundary · 373 K",
new THREE.Vector3(-3.15, 1.68, -2.75),
"boundary"
).style.borderColor = "rgba(255, 101, 95, 0.4)";
createWorldLabel(
"Cold boundary · 273 K",
new THREE.Vector3(3.15, 1.68, -2.75),
"boundary"
).style.borderColor = "rgba(52, 136, 255, 0.4)";
createWorldLabel(
"Equal conduction length · L = 6.0 m",
new THREE.Vector3(0, -0.92, 3.72),
"dimension"
);
// -------------------------------------------------------------------------
// Quantitative comparison cards
// -------------------------------------------------------------------------
function formatPower(watts) {
if (watts >= 1000) {
return `${(watts / 1000).toFixed(2)} kW`;
}
if (watts >= 100) {
return `${Math.round(watts)} W`;
}
return `${watts.toFixed(1)} W`;
}
const modelList = document.getElementById("model-list");
models.forEach((model) => {
const ratio = model.q / maxQ;
const card = document.createElement("article");
card.className = "model-card";
card.style.setProperty("--accent", model.accent);
card.innerHTML = `
<div class="model-head">
<span class="model-dot"></span>
<div class="model-name">
<strong>${model.name}</strong>
<small>Model conductivity · k = ${model.k} W/m·K</small>
</div>
</div>
<div class="metrics">
<div class="metric">
<small>Steady gradient</small>
<b>${GRADIENT.toFixed(1)} K/m</b>
</div>
<div class="metric">
<small>Heat rate Q</small>
<b>${formatPower(model.q)}</b>
</div>
</div>
<div class="flow-track" title="Relative heat rate: ${(ratio * 100).toFixed(1)}%">
<span style="width: ${ratio * 100}%"></span>
</div>
`;
modelList.appendChild(card);
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and reset
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.006,
0.35,
1.46
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8.5,
25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta -= 0.08;
break;
case "ArrowRight":
cameraState.theta += 0.08;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.35, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.46, cameraState.phi + 0.06);
break;
case "+":
case "=":
cameraState.radius = Math.max(8.5, cameraState.radius - 0.7);
break;
case "-":
cameraState.radius = Math.min(25, cameraState.radius + 0.7);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("reset-button").addEventListener("click", resetCamera);
let paused = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function updatePauseButton() {
document.getElementById("pause-symbol").textContent = paused ? "▶" : "Ⅱ";
document.getElementById("pause-text").textContent = paused
? "Resume flow"
: "Pause flow";
}
document.getElementById("pause-button").addEventListener("click", () => {
paused = !paused;
updatePauseButton();
});
updatePauseButton();
// -------------------------------------------------------------------------
// Label projection and animation
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
labelItems.forEach((item) => {
projected.copy(item.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
item.element.style.display = visible ? "block" : "none";
if (visible) {
item.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
});
}
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();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
flowMarkers.forEach((marker) => {
const phase =
(elapsed * marker.userData.speed + marker.userData.phase) % 1;
marker.position.x = -LENGTH / 2 + phase * LENGTH;
marker.position.y = 0.73 + Math.sin(elapsed * 3 + marker.userData.phase * 8) * 0.025;
marker.position.z = marker.userData.z;
});
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```