Prompt specification
Build or customize the Three.js 3D scene "Moist-air measurement chamber" 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: Moist-air measurement chamber
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/moist-air-measurement-chamber-x1241
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: moist-air measurement chamber. Build a transparent chamber with separate temperature and water-vapor counters; display relative humidity as a labeled derived quantity rather than visible floating liquid droplets. Return one self-contained HTML file.
Working Three.js Starter (moist-air-measurement-chamber-x1241):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Moist-Air Measurement Chamber</title>
<style>
:root {
color-scheme: dark;
--bg: #061019;
--panel: rgba(9, 23, 33, 0.82);
--line: rgba(139, 214, 232, 0.18);
--text: #e8f5f8;
--muted: #87a8b4;
--cyan: #5ed8f4;
--amber: #ffb65d;
--green: #72e6b5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
cursor: grab;
touch-action: none;
}
#scene.grabbing {
cursor: grabbing;
}
.ambient {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 45% 43%, transparent 0 35%, rgba(0, 7, 12, 0.22) 74%),
linear-gradient(180deg, rgba(3, 12, 19, 0.12), rgba(2, 8, 13, 0.55));
}
header {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
width: min(540px, calc(100vw - 410px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(94, 216, 244, 0.8);
}
h1 {
margin: 0;
max-width: 520px;
font-size: clamp(25px, 3.1vw, 43px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
h1 span {
display: block;
margin-top: 5px;
color: #91b4c0;
font-size: 0.47em;
font-weight: 500;
letter-spacing: 0.105em;
}
.subtitle {
margin: 15px 0 0;
max-width: 470px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.readouts {
position: fixed;
z-index: 6;
top: 28px;
right: 28px;
width: 330px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(18px);
}
.readout-head {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 12px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--green);
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.live.paused {
color: var(--amber);
}
.card {
position: relative;
overflow: hidden;
margin-top: 8px;
padding: 14px 15px 13px;
border: 1px solid rgba(132, 198, 216, 0.14);
border-radius: 11px;
background: rgba(18, 39, 51, 0.62);
}
.card::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
background: var(--cyan);
opacity: 0.8;
}
.card.vapor::after {
background: var(--amber);
}
.card.derived {
background: linear-gradient(135deg, rgba(18, 52, 63, 0.88), rgba(12, 32, 43, 0.8));
border-color: rgba(94, 216, 244, 0.27);
}
.card.derived::after {
background: var(--green);
box-shadow: 0 0 14px rgba(114, 230, 181, 0.55);
}
.label-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.label {
color: #b9d2da;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.kind {
color: #648894;
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.derived .kind {
color: var(--green);
}
.value-row {
display: flex;
align-items: baseline;
gap: 8px;
margin-top: 7px;
}
.value {
font: 650 32px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: -0.06em;
font-variant-numeric: tabular-nums;
}
.unit {
color: var(--muted);
font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.meter {
height: 3px;
margin-top: 11px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.meter > span {
display: block;
width: 78%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--green));
box-shadow: 0 0 10px rgba(114, 230, 181, 0.5);
transition: width 180ms ease;
}
.formula {
margin-top: 9px;
color: #7195a1;
font: 500 9px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.note {
margin: 12px 2px 1px;
color: #668894;
font-size: 10px;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 7;
left: 30px;
bottom: 27px;
display: flex;
align-items: center;
gap: 9px;
}
button {
border: 1px solid rgba(134, 209, 227, 0.2);
border-radius: 8px;
padding: 9px 12px;
color: #c9e0e6;
background: rgba(10, 27, 37, 0.8);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}
button:hover {
color: white;
border-color: rgba(94, 216, 244, 0.55);
background: rgba(17, 42, 54, 0.9);
}
.hint {
margin-left: 5px;
color: #557783;
font: 500 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.04em;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.sensor-tag {
position: absolute;
min-width: 145px;
padding: 8px 10px;
border: 1px solid rgba(94, 216, 244, 0.3);
border-left: 2px solid var(--cyan);
border-radius: 5px;
color: #cce7ee;
background: rgba(4, 17, 25, 0.84);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(8px);
font: 700 9px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
transition: opacity 120ms ease;
}
.sensor-tag strong {
display: block;
margin-top: 3px;
color: white;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.03em;
}
#tag-temp {
transform: translate(-100%, -50%);
}
#tag-vapor {
transform: translate(14px, -50%);
border-color: rgba(255, 182, 93, 0.3);
border-left-color: var(--amber);
}
@media (max-width: 900px) {
header {
width: calc(100vw - 390px);
}
.subtitle {
display: none;
}
}
@media (max-width: 720px) {
header {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
font-size: 24px;
}
h1 span {
font-size: 0.44em;
}
.readouts {
top: auto;
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
padding: 10px;
}
.readout-head {
margin-bottom: 7px;
}
.cards {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.card {
margin: 0;
padding: 10px;
}
.card.derived {
grid-column: 1 / -1;
}
.value {
font-size: 24px;
}
.formula,
.note {
display: none;
}
.controls {
left: 16px;
bottom: 260px;
}
.hint {
display: none;
}
#labels {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly moist-air measurement chamber"></canvas>
<div class="ambient"></div>
<header>
<div class="eyebrow">Instrument bay / A–04</div>
<h1>Moist Air <span>Measurement Chamber</span></h1>
<p class="subtitle">
A transparent low-poly test cell with independent temperature and
water-vapor sensing channels.
</p>
</header>
<aside class="readouts" aria-label="Measurement readouts">
<div class="readout-head">
<span>Acquisition channels</span>
<span id="liveStatus" class="live">Live sample</span>
</div>
<div class="cards">
<article class="card">
<div class="label-row">
<span class="label">Temperature</span>
<span class="kind">Direct / CH 01</span>
</div>
<div class="value-row">
<output id="tempValue" class="value">24.6</output>
<span class="unit">°C</span>
</div>
</article>
<article class="card vapor">
<div class="label-row">
<span class="label">Water vapor</span>
<span class="kind">Direct / CH 02</span>
</div>
<div class="value-row">
<output id="vaporValue" class="value">17.4</output>
<span class="unit">g/m³</span>
</div>
</article>
<article class="card derived">
<div class="label-row">
<span class="label">Relative humidity</span>
<span class="kind">Derived quantity</span>
</div>
<div class="value-row">
<output id="rhValue" class="value">77.9</output>
<span class="unit">% RH</span>
</div>
<div class="meter"><span id="rhMeter"></span></div>
<div class="formula">ρv → pv / RH = 100 · pv / psat(T)</div>
</article>
</div>
<p class="note">
Humidity is calculated from the two measured channels. No liquid or
condensation is visualized.
</p>
</aside>
<div id="labels" aria-hidden="true">
<div id="tag-temp" class="sensor-tag">
Ch 01 / Temperature
<strong id="tagTempValue">24.6 °C</strong>
</div>
<div id="tag-vapor" class="sensor-tag">
Ch 02 / Vapor density
<strong id="tagVaporValue">17.4 g/m³</strong>
</div>
</div>
<div class="controls">
<button id="pauseButton" type="button">Hold sample</button>
<button id="resetButton" type="button">Reset view</button>
<span class="hint">Drag to orbit · wheel to zoom</span>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x061019, 1);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x061019, 18, 35);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const target = new THREE.Vector3(-0.15, 2.45, 0);
const orbit = {
radius: window.innerWidth < 720 ? 13.2 : 11.8,
theta: 0.68,
phi: 1.10
};
const orbitGoal = { ...orbit };
function updateCamera(dt = 1) {
const smoothing = 1 - Math.exp(-dt * 9);
orbit.radius += (orbitGoal.radius - orbit.radius) * smoothing;
orbit.theta += (orbitGoal.theta - orbit.theta) * smoothing;
orbit.phi += (orbitGoal.phi - orbit.phi) * smoothing;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xa9e7ff, 0x071018, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x32c8ef, 24, 13, 2);
cyanLight.position.set(-3.6, 3.2, 3.3);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa64f, 16, 9, 2);
amberLight.position.set(2.5, 2.1, 1.5);
scene.add(amberLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(45, 45),
new THREE.MeshStandardMaterial({
color: 0x061018,
roughness: 0.92,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x2e7e93, 0x193d49);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
const materials = {
dark: new THREE.MeshStandardMaterial({
color: 0x10212a,
roughness: 0.64,
metalness: 0.7,
flatShading: true
}),
deck: new THREE.MeshStandardMaterial({
color: 0x1a303a,
roughness: 0.52,
metalness: 0.58,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x91a7ab,
roughness: 0.35,
metalness: 0.78,
flatShading: true
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x54d4f2,
emissive: 0x0d6077,
emissiveIntensity: 0.85,
roughness: 0.32,
metalness: 0.45,
flatShading: true
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffad50,
emissive: 0x7a3609,
emissiveIntensity: 0.65,
roughness: 0.38,
metalness: 0.42,
flatShading: true
}),
green: new THREE.MeshStandardMaterial({
color: 0x6ee4af,
emissive: 0x14583f,
emissiveIntensity: 0.8,
roughness: 0.35,
metalness: 0.35,
flatShading: true
})
};
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, segments = 8, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Instrument platform.
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(4.65, 4.85, 0.23, 48),
materials.dark
);
platform.position.y = 0.115;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformInset = new THREE.Mesh(
new THREE.CylinderGeometry(4.42, 4.42, 0.025, 48),
materials.deck
);
platformInset.position.y = 0.245;
platformInset.receiveShadow = true;
scene.add(platformInset);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(4.56, 0.022, 6, 64),
materials.cyan
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.y = 0.25;
scene.add(platformRing);
// Chamber base and feet.
for (const x of [-2.65, 2.65]) {
for (const z of [-1.85, 1.85]) {
box(0.52, 0.14, 0.52, materials.dark, x, 0.31, z);
}
}
box(6.45, 0.34, 4.9, materials.dark, 0, 0.51, 0);
box(5.98, 0.075, 4.45, materials.deck, 0, 0.71, 0);
// Transparent chamber volume.
const glassMaterial = new THREE.MeshPhongMaterial({
color: 0x9ceaff,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false,
shininess: 100,
specular: 0xb8f4ff
});
const chamberGlass = new THREE.Mesh(
new THREE.BoxGeometry(6.05, 4.42, 4.42),
glassMaterial
);
chamberGlass.position.y = 2.96;
chamberGlass.renderOrder = 10;
scene.add(chamberGlass);
const airVolume = new THREE.Mesh(
new THREE.BoxGeometry(5.82, 4.18, 4.2),
new THREE.MeshBasicMaterial({
color: 0x55d7f0,
transparent: true,
opacity: 0.018,
side: THREE.BackSide,
depthWrite: false
})
);
airVolume.position.y = 2.96;
scene.add(airVolume);
const chamberEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(6.05, 4.42, 4.42)),
new THREE.LineBasicMaterial({
color: 0x75d7e8,
transparent: true,
opacity: 0.42
})
);
chamberEdges.position.y = 2.96;
scene.add(chamberEdges);
// Structural frame.
for (const y of [0.76, 5.16]) {
for (const z of [-2.23, 2.23]) {
box(6.2, 0.09, 0.09, materials.metal, 0, y, z);
}
for (const x of [-3.06, 3.06]) {
box(0.09, 0.09, 4.55, materials.metal, x, y, 0);
}
}
for (const x of [-3.06, 3.06]) {
for (const z of [-2.23, 2.23]) {
box(0.075, 4.45, 0.075, materials.metal, x, 2.96, z);
}
}
// Recessed intake and exhaust grilles.
box(0.11, 2.85, 3.25, materials.dark, -3.02, 2.86, 0);
box(0.11, 2.85, 3.25, materials.dark, 3.02, 2.86, 0);
for (let i = 0; i < 8; i++) {
const y = 1.72 + i * 0.325;
box(0.14, 0.085, 2.9, materials.metal, -3.075, y, 0);
box(0.14, 0.085, 2.9, materials.metal, 3.075, y, 0);
}
// Internal mounting rails.
box(0.08, 0.08, 3.45, materials.metal, -1.15, 0.82, 0);
box(0.08, 0.08, 3.45, materials.metal, 1.15, 0.82, 0);
// Temperature channel: dry shielded probe, not a wet bulb.
const tempPedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.39, 0.18, 10),
materials.deck
);
tempPedestal.position.set(-0.92, 0.84, -0.12);
tempPedestal.castShadow = true;
scene.add(tempPedestal);
cylinderBetween(
[-0.92, 0.92, -0.12],
[-0.92, 2.64, -0.12],
0.055,
materials.metal
);
box(0.52, 0.58, 0.3, materials.dark, -0.92, 1.85, -0.26);
box(0.34, 0.035, 0.025, materials.cyan, -0.92, 1.9, -0.09);
box(0.76, 0.16, 0.46, materials.metal, -0.92, 2.68, -0.12);
for (let i = 0; i < 8; i++) {
box(
0.026,
0.34,
0.56,
i % 2 === 0 ? materials.cyan : materials.metal,
-1.23 + i * 0.088,
2.72,
-0.12
);
}
cylinderBetween(
[-0.92, 2.68, 0.1],
[-0.92, 2.68, 0.48],
0.034,
materials.metal
);
box(0.09, 0.09, 0.13, materials.cyan, -0.92, 2.68, 0.52);
// Water-vapor channel: compact analyzer with an intake grille.
const vaporPedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.42, 0.46, 0.2, 10),
materials.deck
);
vaporPedestal.position.set(1.2, 0.83, 0.05);
vaporPedestal.castShadow = true;
scene.add(vaporPedestal);
box(0.98, 0.86, 0.74, materials.dark, 1.2, 1.36, 0.05);
box(0.78, 0.55, 0.045, materials.deck, 1.2, 1.37, 0.445);
for (let i = 0; i < 7; i++) {
box(
0.045,
0.48,
0.055,
materials.amber,
0.9 + i * 0.1,
1.37,
0.48
);
}
box(0.56, 0.045, 0.025, materials.amber, 1.2, 1.7, 0.435);
cylinderBetween(
[1.2, 1.79, 0.05],
[1.2, 2.08, 0.05],
0.075,
materials.metal
);
// Sample plumbing between the chamber and the vapor analyzer.
cylinderBetween(
[-2.88, 2.15, -0.62],
[-0.35, 2.15, -0.62],
0.065,
materials.deck,
8
);
cylinderBetween(
[-0.35, 2.15, -0.62],
[0.7, 1.52, -0.42],
0.065,
materials.deck,
8
);
cylinderBetween(
[1.7, 1.46, -0.1],
[2.88, 2.1, -0.1],
0.06,
materials.deck,
8
);
// Fixed airflow direction indicators, intentionally not particulate droplets.
const chevronVertices = [];
for (const x of [-2.1, -0.15, 1.75]) {
const y = 1.28;
const z = 1.24;
chevronVertices.push(
x - 0.16, y, z - 0.19,
x, y, z,
x, y, z,
x - 0.16, y, z + 0.19
);
}
const flowGeometry = new THREE.BufferGeometry();
flowGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(chevronVertices, 3)
);
const flowLines = new THREE.LineSegments(
flowGeometry,
new THREE.LineBasicMaterial({
color: 0x55d7ee,
transparent: true,
opacity: 0.38
})
);
scene.add(flowLines);
// A small generated front nameplate.
const plateCanvas = document.createElement("canvas");
plateCanvas.width = 512;
plateCanvas.height = 112;
const ctx = plateCanvas.getContext("2d");
ctx.fillStyle = "#091820";
ctx.fillRect(0, 0, 512, 112);
ctx.strokeStyle = "#2a6575";
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, 506, 106);
ctx.fillStyle = "#68d8ef";
ctx.fillRect(24, 30, 12, 52);
ctx.fillStyle = "#e4f4f7";
ctx.font = "bold 39px monospace";
ctx.fillText("HYGRO / A-04", 55, 55);
ctx.fillStyle = "#658c98";
ctx.font = "18px monospace";
ctx.fillText("MOIST AIR TEST CELL", 57, 84);
const plateTexture = new THREE.CanvasTexture(plateCanvas);
plateTexture.colorSpace = THREE.SRGBColorSpace;
const plate = new THREE.Mesh(
new THREE.PlaneGeometry(1.82, 0.4),
new THREE.MeshBasicMaterial({ map: plateTexture })
);
plate.position.set(0, 0.51, 2.456);
scene.add(plate);
// Measurement state and derived relative humidity.
const tempOutput = document.querySelector("#tempValue");
const vaporOutput = document.querySelector("#vaporValue");
const rhOutput = document.querySelector("#rhValue");
const rhMeter = document.querySelector("#rhMeter");
const tagTemp = document.querySelector("#tagTempValue");
const tagVapor = document.querySelector("#tagVaporValue");
const liveStatus = document.querySelector("#liveStatus");
const pauseButton = document.querySelector("#pauseButton");
let elapsed = 0;
let paused = false;
function calculateRH(temperatureC, vaporDensityGM3) {
const temperatureK = temperatureC + 273.15;
const vaporDensityKgM3 = vaporDensityGM3 / 1000;
const vaporPressureKPa =
vaporDensityKgM3 * 0.4615 * temperatureK;
const saturationPressureKPa =
0.61094 *
Math.exp((17.625 * temperatureC) / (temperatureC + 243.04));
return 100 * (vaporPressureKPa / saturationPressureKPa);
}
function updateReadouts() {
const temperature =
24.6 +
Math.sin(elapsed * 0.31) * 0.11 +
Math.sin(elapsed * 0.73) * 0.025;
const vaporDensity =
17.4 +
Math.sin(elapsed * 0.23 + 1.4) * 0.065 +
Math.sin(elapsed * 0.51) * 0.018;
const relativeHumidity = calculateRH(temperature, vaporDensity);
tempOutput.textContent = temperature.toFixed(1);
vaporOutput.textContent = vaporDensity.toFixed(1);
rhOutput.textContent = relativeHumidity.toFixed(1);
rhMeter.style.width = `${Math.max(0, Math.min(100, relativeHumidity))}%`;
tagTemp.textContent = `${temperature.toFixed(1)} °C`;
tagVapor.textContent = `${vaporDensity.toFixed(1)} g/m³`;
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume sample" : "Hold sample";
liveStatus.textContent = paused ? "Sample held" : "Live sample";
liveStatus.classList.toggle("paused", paused);
});
// Custom camera controls: no external control modules.
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("grabbing");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbitGoal.theta -= dx * 0.006;
orbitGoal.phi = THREE.MathUtils.clamp(
orbitGoal.phi - dy * 0.005,
0.48,
1.43
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("grabbing");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitGoal.radius = THREE.MathUtils.clamp(
orbitGoal.radius + event.deltaY * 0.008,
7.2,
18
);
},
{ passive: false }
);
document.querySelector("#resetButton").addEventListener("click", () => {
orbitGoal.radius = window.innerWidth < 720 ? 13.2 : 11.8;
orbitGoal.theta = 0.68;
orbitGoal.phi = 1.10;
});
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbitGoal.theta += 0.09;
if (event.key === "ArrowRight") orbitGoal.theta -= 0.09;
if (event.key === "ArrowUp") orbitGoal.phi -= 0.06;
if (event.key === "ArrowDown") orbitGoal.phi += 0.06;
orbitGoal.phi = THREE.MathUtils.clamp(orbitGoal.phi, 0.48, 1.43);
});
// Projected labels for the two direct sensing channels.
const tempAnchor = new THREE.Vector3(-1.05, 3.02, 0.08);
const vaporAnchor = new THREE.Vector3(1.25, 1.95, 0.42);
const projected = new THREE.Vector3();
function positionTag(element, anchor) {
projected.copy(anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
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.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += dt;
uiAccumulator += dt;
if (uiAccumulator >= 0.08) {
updateReadouts();
uiAccumulator = 0;
}
updateCamera(dt);
positionTag(document.querySelector("#tag-temp"), tempAnchor);
positionTag(document.querySelector("#tag-vapor"), vaporAnchor);
renderer.render(scene, camera);
}
updateReadouts();
animate();
</script>
</body>
</html>
```