Prompt specification
Build or customize the Three.js 3D scene "Temperature and elevation reference gallery" 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: Temperature and elevation reference gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/temperature-and-elevation-reference-gallery-x1703
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing signed numbers and changes around zero. Compose two clearly synthetic scales, one relative to a temperature zero and another to a height datum; explain that negative values depend on the chosen reference. Voxel style.
Working Three.js Starter (temperature-and-elevation-reference-gallery-x1703):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#07101d">
<title>Signed Values Around Zero</title>
<style>
:root {
color-scheme: dark;
--ink: #07101d;
--panel: rgba(8, 17, 30, 0.91);
--line: #2a3c55;
--text: #eaf4ff;
--muted: #9eb0c7;
--yellow: #ffd166;
--negative: #54a7ff;
--temperature: #ff7a45;
--height: #42d392;
--pink: #f45bba;
--cyan: #54e0dc;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--text);
font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 28px;
left: 30px;
max-width: 540px;
text-shadow: 0 3px 0 rgba(0, 0, 0, 0.38);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
padding: 7px 10px;
border: 2px solid var(--line);
background: rgba(7, 16, 29, 0.84);
color: var(--yellow);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.16em;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--yellow);
box-shadow: 4px 4px 0 rgba(255, 209, 102, 0.28);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 58px);
line-height: 0.94;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.subtitle {
max-width: 510px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.toolbar {
position: absolute;
top: 28px;
right: 28px;
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
appearance: none;
border: 2px solid var(--line);
border-radius: 0;
padding: 10px 12px;
background: rgba(7, 16, 29, 0.86);
color: var(--muted);
font: 700 10px/1 "Courier New", monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.25);
}
button:hover,
button:focus-visible {
border-color: var(--yellow);
color: var(--text);
outline: none;
}
button.active {
border-color: var(--yellow);
background: var(--yellow);
color: var(--ink);
}
.notes {
position: absolute;
right: 28px;
bottom: 28px;
width: 370px;
max-width: calc(100vw - 36px);
pointer-events: auto;
border: 2px solid var(--line);
background: var(--panel);
box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
.notes-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 11px 13px;
border-bottom: 2px solid var(--line);
color: var(--yellow);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.notes-head span:last-child {
color: var(--muted);
text-align: right;
}
.note-card {
padding: 14px 14px 13px;
border-bottom: 1px solid var(--line);
}
.note-card h2 {
display: flex;
align-items: center;
gap: 9px;
margin: 0 0 8px;
font-size: 13px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.note-card h2::before {
content: "";
width: 10px;
height: 10px;
box-shadow: 3px 3px 0 rgba(255, 255, 255, 0.12);
}
.temperature h2::before {
background: var(--temperature);
}
.height h2::before {
background: var(--height);
}
.note-card p {
margin: 6px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.equation {
color: var(--text) !important;
font-weight: 700;
}
.equation b {
color: var(--yellow);
}
.principle {
padding: 13px 14px 14px;
color: var(--text);
font-size: 11px;
line-height: 1.55;
}
.principle strong {
color: var(--yellow);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
padding: 11px 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
display: inline-block;
background: currentColor;
}
.negative {
color: var(--negative);
}
.positive {
color: var(--temperature);
}
.zero {
color: var(--yellow);
}
.hint {
position: absolute;
left: 30px;
bottom: 28px;
padding: 9px 11px;
border: 2px solid var(--line);
background: rgba(7, 16, 29, 0.78);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.hint b {
color: var(--text);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #07101d;
color: var(--yellow);
font-size: 12px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 220ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
header {
top: 18px;
left: 16px;
max-width: calc(100vw - 32px);
}
h1 {
font-size: clamp(25px, 8vw, 42px);
}
.subtitle {
max-width: 430px;
font-size: 10px;
}
.toolbar {
top: auto;
right: 16px;
bottom: 16px;
flex-direction: column;
}
button {
padding: 9px 10px;
font-size: 9px;
}
.notes {
right: 16px;
bottom: 16px;
width: min(360px, calc(100vw - 116px));
max-height: 38vh;
overflow: auto;
}
.notes-head span:last-child,
.hint {
display: none;
}
.note-card {
padding: 10px 11px;
}
.note-card p,
.principle {
font-size: 10px;
}
}
@media (max-width: 560px) {
.subtitle {
display: none;
}
.eyebrow {
margin-bottom: 8px;
font-size: 9px;
}
.notes {
right: 10px;
bottom: 10px;
width: calc(100vw - 84px);
max-height: 31vh;
}
.notes-head {
padding: 9px 10px;
font-size: 8px;
}
.note-card h2 {
font-size: 10px;
}
.note-card p,
.principle {
font-size: 9px;
}
.legend {
display: none;
}
.toolbar {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<div id="loading">Building voxel reference lab...</div>
<div id="hud">
<header>
<div class="eyebrow">Reference Lab / Synthetic Instruments</div>
<h1>Signed values<br>around zero</h1>
<p class="subtitle">
Two illustrative scales show how negative and positive values relate
to a selected zero. The blocks are conceptual—not calibrated instruments.
</p>
</header>
<nav class="toolbar" aria-label="Camera views">
<button class="active" data-view="all">Both scales</button>
<button data-view="temperature">Temperature</button>
<button data-view="height">Height</button>
</nav>
<aside class="notes" aria-label="Reference notes">
<div class="notes-head">
<span>Reference notes</span>
<span>Synthetic / Not calibrated</span>
</div>
<article class="note-card temperature">
<h2>01 / Temperature scale</h2>
<p>
Here, <strong>0°C</strong> is the selected thermal reference.
Values below it are negative; values above it are positive.
</p>
<p class="equation">−8°C → +12°C = <b>+20°C change</b></p>
</article>
<article class="note-card height">
<h2>02 / Height datum</h2>
<p>
Here, <strong>0 m</strong> is the selected sea-level datum.
Below-datum heights are negative; above-datum heights are positive.
</p>
<p class="equation">−7 m → +14 m = <b>+21 m change</b></p>
</article>
<div class="principle">
<strong>Negative does not mean “nothing.”</strong>
It means less than the chosen reference. Shift the reference and the
same reading can receive a different signed value.
</div>
<div class="legend" aria-label="Color legend">
<span class="negative"><i class="swatch"></i>Below zero</span>
<span class="positive"><i class="swatch"></i>Above zero</span>
<span class="zero"><i class="swatch"></i>Selected zero</span>
</div>
</aside>
<div class="hint">
<b>Drag</b> to orbit · <b>Scroll</b> to zoom<br>
Keys: arrows orbit · +/− zoom · 1/2/3 views
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
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.12;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101d);
scene.fog = new THREE.Fog(0x07101d, 27, 57);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
scene.add(new THREE.HemisphereLight(0x9fc6ff, 0x1a1026, 2.1));
const keyLight = new THREE.DirectionalLight(0xffe0ba, 3.2);
keyLight.position.set(8, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const pinkLight = new THREE.PointLight(0xf45bba, 26, 18, 2);
pinkLight.position.set(-7, 5, 3);
scene.add(pinkLight);
const cyanLight = new THREE.PointLight(0x54e0dc, 24, 18, 2);
cyanLight.position.set(7, 4, 2);
scene.add(cyanLight);
// ------------------------------------------------------------
// Palette and voxel helpers
// ------------------------------------------------------------
const COLORS = {
background: 0x07101d,
floor: 0x101b2c,
floorTop: 0x17263b,
grid: 0x263a54,
dark: 0x17263a,
darker: 0x0b1422,
white: 0xeaf4ff,
muted: 0x7890aa,
yellow: 0xffd166,
negative: 0x54a7ff,
negativeDark: 0x246db7,
temperature: 0xff7a45,
temperatureDark: 0xc94f2e,
height: 0x42d392,
heightDark: 0x238a62,
pink: 0xf45bba,
cyan: 0x54e0dc
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.04,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
const materials = {
floor: material(COLORS.floor),
floorTop: material(COLORS.floorTop),
grid: material(COLORS.grid),
dark: material(COLORS.dark),
darker: material(COLORS.darker),
white: material(COLORS.white),
muted: material(COLORS.muted),
yellow: material(COLORS.yellow, {
emissive: COLORS.yellow,
emissiveIntensity: 0.16
}),
negative: material(COLORS.negative),
negativeDark: material(COLORS.negativeDark),
temperature: material(COLORS.temperature),
temperatureDark: material(COLORS.temperatureDark),
height: material(COLORS.height),
heightDark: material(COLORS.heightDark),
pink: material(COLORS.pink, {
emissive: COLORS.pink,
emissiveIntensity: 0.28
}),
cyan: material(COLORS.cyan, {
emissive: COLORS.cyan,
emissiveIntensity: 0.28
})
};
function box(width, height, depth, mat, x, y, z, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Pixel-like billboard labels rendered into local canvas textures.
function makeLabel(text, options = {}) {
const upper = text.toUpperCase();
const canvas = document.createElement("canvas");
const fontSize = options.fontSize ?? 44;
const padding = options.padding ?? 22;
const charWidth = options.charWidth ?? 29;
const height = options.pixelHeight ?? 72;
canvas.width = Math.max(88, Math.ceil(upper.length * charWidth + padding * 2));
canvas.height = height;
const context = canvas.getContext("2d");
context.imageSmoothingEnabled = false;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = options.bg ?? "rgba(7,16,29,0.88)";
context.fillRect(0, 0, canvas.width, canvas.height);
if (options.border !== false) {
context.strokeStyle = options.border ?? "#314761";
context.lineWidth = 4;
context.strokeRect(2, 2, canvas.width - 4, canvas.height - 4);
}
context.fillStyle = options.color ?? "#eaf4ff";
context.font = `700 ${fontSize}px "Courier New", monospace`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(upper, canvas.width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.generateMipmaps = false;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
const worldHeight = options.worldHeight ?? 0.34;
sprite.scale.set(
worldHeight * canvas.width / canvas.height,
worldHeight,
1
);
sprite.renderOrder = 10;
return sprite;
}
function addLabel(parent, text, x, y, z, options = {}) {
const label = makeLabel(text, options);
label.position.set(x, y, z);
parent.add(label);
return label;
}
// ------------------------------------------------------------
// Ground and deterministic background voxel field
// ------------------------------------------------------------
box(19, 0.38, 10, materials.floor, 0, -2.78, 0);
box(18.6, 0.08, 9.6, materials.floorTop, 0, -2.55, 0);
for (let x = -8; x <= 8; x += 1) {
box(0.025, 0.018, 9.3, materials.grid, x, -2.50, 0, scene, false);
}
for (let z = -4; z <= 4; z += 1) {
box(18.3, 0.018, 0.025, materials.grid, 0, -2.50, z, scene, false);
}
// A stepped central path ties the two separate scales together.
for (let i = 0; i < 8; i++) {
const width = 1.05 + i * 0.08;
box(
width,
0.055 + i * 0.012,
0.72,
i % 2 ? materials.dark : materials.darker,
0,
-2.48 + i * 0.012,
3.9 - i * 0.08,
scene,
false
);
}
let seed = 9137;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const dustMaterials = [
material(0x162941),
material(0x213451),
material(0x293653)
];
for (let i = 0; i < 42; i++) {
const size = 0.08 + random() * 0.28;
box(
size,
size,
size,
dustMaterials[i % dustMaterials.length],
-11 + random() * 22,
-1 + random() * 9,
-4 - random() * 8,
scene,
false
);
}
// ------------------------------------------------------------
// Synthetic scale construction
// ------------------------------------------------------------
const ZERO_Y = 1.0;
const SCALE_UNIT = 0.115;
const SCALE_BOTTOM = -2.45;
const SCALE_TOP = 4.45;
function valueToY(value) {
return ZERO_Y + value * SCALE_UNIT;
}
function buildVoxelArrow(parent, x, startY, endY, arrowMaterial) {
const step = 0.19;
const cube = 0.16;
const shaftTop = endY - 0.34;
for (let y = startY + 0.13; y <= shaftTop; y += step) {
box(cube, cube, cube, arrowMaterial, x, y, 0.25, parent);
}
// Chunky three-tier arrowhead.
box(cube, cube, cube, arrowMaterial, x, endY, 0.25, parent);
box(cube, cube, cube, arrowMaterial, x - 0.17, endY - 0.16, 0.25, parent);
box(cube, cube, cube, arrowMaterial, x + 0.17, endY - 0.16, 0.25, parent);
box(cube, cube, cube, arrowMaterial, x - 0.10, endY - 0.32, 0.25, parent);
box(cube, cube, cube, arrowMaterial, x + 0.10, endY - 0.32, 0.25, parent);
box(0.28, 0.28, 0.28, arrowMaterial, x, startY, 0.25, parent);
}
function buildScale(config) {
const group = new THREE.Group();
group.position.x = config.x;
scene.add(group);
// Separate pedestal makes each instrument visibly synthetic.
box(5.65, 0.34, 3.25, materials.dark, 0, -2.31, 0, group);
box(5.28, 0.08, 2.9, materials.darker, 0, -2.10, 0, group);
for (const x of [-2.5, 2.5]) {
for (const z of [-1.2, 1.2]) {
box(0.28, 0.44, 0.28, config.baseMaterial, x, -1.92, z, group);
box(0.16, 0.12, 0.16, materials.yellow, x, -1.64, z, group);
}
}
// Dark spine behind the colored voxel column.
box(0.84, 7.25, 0.3, materials.darker, 0, 0.93, -0.43, group);
box(0.98, 0.13, 0.46, materials.dark, 0, 4.55, -0.38, group);
// Individually stacked blocks emphasize the voxel treatment.
const blockCount = 24;
const blockHeight = (SCALE_TOP - SCALE_BOTTOM) / blockCount;
for (let i = 0; i < blockCount; i++) {
const y = SCALE_BOTTOM + (i + 0.5) * blockHeight;
const isNegative = y < ZERO_Y;
const mat = isNegative
? config.negativeMaterial
: config.positiveMaterial;
box(0.50, blockHeight - 0.035, 0.42, mat, 0, y, 0.02, group);
}
// Ticks every five units; labels every ten units.
for (let value = -30; value <= 30; value += 5) {
const y = valueToY(value);
const isMajor = value % 10 === 0;
const isZero = value === 0;
const tickMat = isZero
? materials.yellow
: value < 0
? config.negativeMaterial
: config.positiveMaterial;
box(
isMajor ? 0.82 : 0.55,
0.075,
0.24,
tickMat,
0.47,
y,
0.30,
group
);
if (isMajor) {
const text = value === 0
? "0"
: value > 0
? `+${value}`
: `${value}`;
const label = addLabel(
group,
text,
-0.95,
y,
0.55,
{
worldHeight: value === 0 ? 0.39 : 0.30,
color: isZero ? "#07101d" : value < 0 ? "#78b8ff" : config.labelColor,
bg: isZero ? "#ffd166" : "rgba(7,16,29,0.91)",
border: isZero ? "#fff0a8" : value < 0 ? "#346fae" : config.borderColor,
fontSize: value === 0 ? 49 : 43,
charWidth: 28
}
);
label.renderOrder = 12;
}
}
// Prominent selected-zero datum.
box(3.85, 0.13, 0.52, materials.yellow, 0, ZERO_Y, 0.27, group);
box(4.22, 0.055, 0.64, config.zeroLineMaterial, 0, ZERO_Y - 0.14, 0.20, group);
addLabel(group, "SELECTED 0", -1.60, ZERO_Y, 0.56, {
worldHeight: 0.22,
color: "#ffd166",
bg: "rgba(7,16,29,0.90)",
border: "#6f6039",
fontSize: 35,
charWidth: 24
});
// Top labels.
addLabel(group, config.serial, 0, 5.34, 0.30, {
worldHeight: 0.42,
color: "#ffd166",
bg: "rgba(7,16,29,0.91)",
border: "#42526a",
fontSize: 43,
charWidth: 29
});
addLabel(group, config.title, 0, 4.91, 0.30, {
worldHeight: 0.33,
color: config.labelColor,
bg: "rgba(7,16,29,0.91)",
border: config.borderColor,
fontSize: 42,
charWidth: 28
});
// Signed change from a negative reading to a positive reading.
buildVoxelArrow(
group,
1.24,
valueToY(config.startValue),
valueToY(config.endValue),
config.arrowMaterial
);
addLabel(
group,
`${config.startValue > 0 ? "+" : ""}${config.startValue} ${config.unit}`,
1.92,
valueToY(config.startValue),
0.48,
{
worldHeight: 0.27,
color: "#78b8ff",
bg: "rgba(7,16,29,0.93)",
border: "#346fae"
}
);
addLabel(
group,
`${config.endValue > 0 ? "+" : ""}${config.endValue} ${config.unit}`,
1.92,
valueToY(config.endValue),
0.48,
{
worldHeight: 0.27,
color: config.labelColor,
bg: "rgba(7,16,29,0.93)",
border: config.borderColor
}
);
const change = config.endValue - config.startValue;
addLabel(
group,
`DELTA +${change} ${config.unit}`,
1.12,
Math.min(4.12, valueToY(config.endValue) + 0.76),
0.48,
{
worldHeight: 0.29,
color: "#07101d",
bg: config.arrowMaterial === materials.pink ? "#f45bba" : "#54e0dc",
border: "#ffffff",
fontSize: 39,
charWidth: 27
}
);
// Sign-region labels.
addLabel(group, "NEG", -0.05, 0.35, 0.47, {
worldHeight: 0.23,
color: "#78b8ff",
bg: "rgba(7,16,29,0.88)",
border: "#315f91",
fontSize: 35,
charWidth: 23
});
addLabel(group, "POS", -0.05, 1.65, 0.47, {
worldHeight: 0.23,
color: config.labelColor,
bg: "rgba(7,16,29,0.88)",
border: config.borderColor,
fontSize: 35,
charWidth: 23
});
// Explicitly identify the graphic as an illustrative, uncalibrated scale.
addLabel(group, "SYNTHETIC / NOT CALIBRATED", 0, -2.08, 1.72, {
worldHeight: 0.22,
color: "#8ea2ba",
bg: "rgba(7,16,29,0.90)",
border: "#314761",
fontSize: 31,
charWidth: 21
});
return group;
}
buildScale({
x: -4.15,
serial: "SYNTHETIC A",
title: "TEMP / C",
unit: "C",
startValue: -8,
endValue: 12,
negativeMaterial: materials.negative,
positiveMaterial: materials.temperature,
baseMaterial: materials.temperatureDark,
zeroLineMaterial: materials.temperatureDark,
arrowMaterial: materials.pink,
labelColor: "#ff9a70",
borderColor: "#9b4935"
});
buildScale({
x: 4.15,
serial: "SYNTHETIC B",
title: "HEIGHT / M",
unit: "M",
startValue: -7,
endValue: 14,
negativeMaterial: materials.negative,
positiveMaterial: materials.height,
baseMaterial: materials.heightDark,
zeroLineMaterial: materials.heightDark,
arrowMaterial: materials.cyan,
labelColor: "#73e6b2",
borderColor: "#32775c"
});
// Small central sign emphasizes the common idea without merging the scales.
box(0.13, 1.35, 0.13, materials.yellow, 0, -1.53, 1.28);
addLabel(scene, "ZERO = A REFERENCE", 0, -0.72, 1.30, {
worldHeight: 0.27,
color: "#ffd166",
bg: "rgba(7,16,29,0.94)",
border: "#6f6039",
fontSize: 37,
charWidth: 25
});
// ------------------------------------------------------------
// Directly implemented camera controls
// ------------------------------------------------------------
const views = {
all: {
target: new THREE.Vector3(0, 1.0, 0),
height: 10.8,
width: 12.3
},
temperature: {
target: new THREE.Vector3(-4.15, 1.0, 0),
height: 7.8,
width: 5.8
},
height: {
target: new THREE.Vector3(4.15, 1.0, 0),
height: 7.8,
width: 5.8
}
};
const orbit = {
theta: 0.04,
targetTheta: 0.04,
phi: 1.25,
targetPhi: 1.25
};
const cameraTarget = views.all.target.clone();
const desiredTarget = views.all.target.clone();
let currentHeight = views.all.height;
let targetHeight = views.all.height;
let currentWidth = views.all.width;
let targetWidth = views.all.width;
function setView(name) {
const view = views[name];
desiredTarget.copy(view.target);
targetHeight = view.height;
targetWidth = view.width;
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let travel = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
travel = 0;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
travel += Math.abs(dx) + Math.abs(dy);
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi -= dy * 0.0045;
orbit.targetTheta = THREE.MathUtils.clamp(orbit.targetTheta, -0.78, 0.78);
orbit.targetPhi = THREE.MathUtils.clamp(orbit.targetPhi, 0.72, 1.46);
});
function endDrag(event) {
if (!dragging || event.pointerId !== pointerId) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(pointerId)) {
renderer.domElement.releasePointerCapture(pointerId);
}
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetHeight = THREE.MathUtils.clamp(
targetHeight + event.deltaY * 0.008,
5.4,
15.5
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
orbit.targetTheta = THREE.MathUtils.clamp(orbit.targetTheta - 0.08, -0.78, 0.78);
break;
case "ArrowRight":
orbit.targetTheta = THREE.MathUtils.clamp(orbit.targetTheta + 0.08, -0.78, 0.78);
break;
case "ArrowUp":
orbit.targetPhi = THREE.MathUtils.clamp(orbit.targetPhi - 0.06, 0.72, 1.46);
break;
case "ArrowDown":
orbit.targetPhi = THREE.MathUtils.clamp(orbit.targetPhi + 0.06, 0.72, 1.46);
break;
case "+":
case "=":
targetHeight = THREE.MathUtils.clamp(targetHeight - 0.5, 5.4, 15.5);
break;
case "-":
case "_":
targetHeight = THREE.MathUtils.clamp(targetHeight + 0.5, 5.4, 15.5);
break;
case "1":
setView("all");
break;
case "2":
setView("temperature");
break;
case "3":
setView("height");
break;
}
});
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const cameraOffset = new THREE.Vector3();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.pow(0.0008, delta);
orbit.theta = THREE.MathUtils.lerp(orbit.theta, orbit.targetTheta, smoothing);
orbit.phi = THREE.MathUtils.lerp(orbit.phi, orbit.targetPhi, smoothing);
cameraTarget.lerp(desiredTarget, smoothing);
currentHeight = THREE.MathUtils.lerp(currentHeight, targetHeight, smoothing);
currentWidth = THREE.MathUtils.lerp(currentWidth, targetWidth, smoothing);
const aspect = window.innerWidth / window.innerHeight;
// Maintain enough horizontal field of view for both instruments.
const effectiveHeight = Math.max(currentHeight, currentWidth / aspect);
camera.left = -effectiveHeight * aspect / 2;
camera.right = effectiveHeight * aspect / 2;
camera.top = effectiveHeight / 2;
camera.bottom = -effectiveHeight / 2;
camera.updateProjectionMatrix();
const radius = 30;
cameraOffset.set(
Math.sin(orbit.phi) * Math.sin(orbit.theta),
Math.cos(orbit.phi),
Math.sin(orbit.phi) * Math.cos(orbit.theta)
);
camera.position.copy(cameraTarget).addScaledVector(cameraOffset, radius);
camera.lookAt(cameraTarget);
const pulse = 1 + Math.sin(clock.elapsedTime * 1.7) * 0.08;
pinkLight.intensity = 26 * pulse;
cyanLight.intensity = 24 * (2 - pulse);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 260);
});
</script>
</body>
</html>
```