Prompt specification
Build or customize the Three.js 3D scene "Room-temperature toy controller scene" 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: Room-temperature toy controller scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/room-temperature-toy-controller-scene-x1871
Scene Description Prompt:
A voxel toy thermostat room showing target, measured temperature, heater state, and external disturbance. Three.js from cdnjs, one HTML file.
Working Three.js Starter (room-temperature-toy-controller-scene-x1871):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thermo Hut — Voxel Thermostat Room</title>
<style>
:root {
--ink: #183142;
--muted: #607788;
--panel: rgba(249, 252, 250, 0.9);
--line: rgba(24, 49, 66, 0.14);
--cyan: #27b8cc;
--orange: #ff8a3d;
--blue: #4b91db;
--shadow: 0 12px 35px rgba(36, 62, 76, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8d9e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.brand-mark {
position: relative;
width: 45px;
height: 45px;
border: 3px solid var(--ink);
border-radius: 12px;
background: #f7fbf8;
box-shadow: 5px 5px 0 rgba(24, 49, 66, 0.18);
transform: rotate(-3deg);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
display: block;
background: var(--ink);
}
.brand-mark::before {
width: 19px;
height: 6px;
left: 10px;
top: 10px;
box-shadow: 0 9px 0 var(--ink);
}
.brand-mark::after {
width: 6px;
height: 19px;
left: 17px;
top: 10px;
}
.eyebrow {
margin: 0 0 3px;
color: #527080;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 6px 0 0;
color: #526c7a;
font-size: 12px;
font-weight: 600;
}
.live-pill {
position: absolute;
top: 27px;
right: 26px;
display: flex;
align-items: center;
gap: 8px;
padding: 9px 13px;
border: 1px solid rgba(24, 49, 66, 0.12);
border-radius: 999px;
background: rgba(250, 253, 250, 0.78);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #42c49a;
box-shadow: 0 0 0 5px rgba(66, 196, 154, 0.14);
animation: livePulse 2s infinite;
}
@keyframes livePulse {
50% {
box-shadow: 0 0 0 8px rgba(66, 196, 154, 0);
}
}
.readouts {
position: absolute;
top: 83px;
right: 26px;
display: grid;
grid-template-columns: repeat(2, minmax(138px, 1fr));
gap: 9px;
width: min(360px, calc(100vw - 52px));
}
.metric {
min-height: 91px;
padding: 13px 14px 12px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
overflow: hidden;
}
.metric-label {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric-icon {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--cyan);
box-shadow: 3px 3px 0 rgba(39, 184, 204, 0.2);
}
.metric-value {
display: block;
font-size: 25px;
line-height: 1;
font-weight: 850;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.metric-detail {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.metric.heater .metric-icon {
background: var(--orange);
box-shadow: 3px 3px 0 rgba(255, 138, 61, 0.22);
}
.metric.heater.on {
background: rgba(255, 244, 232, 0.94);
}
.metric.heater.on .metric-value {
color: #d85d18;
}
.metric.external .metric-icon {
background: var(--blue);
box-shadow: 3px 3px 0 rgba(75, 145, 219, 0.2);
}
.metric.external.active {
background: rgba(234, 245, 255, 0.94);
}
.metric.external.active .metric-value {
color: #2877c1;
}
.controls {
position: absolute;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
display: grid;
grid-template-columns: minmax(260px, 1.4fr) minmax(205px, 0.9fr) auto;
gap: 18px;
align-items: center;
width: min(830px, calc(100vw - 40px));
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 21px;
background: rgba(249, 252, 249, 0.92);
box-shadow: 0 18px 50px rgba(28, 52, 66, 0.21);
backdrop-filter: blur(15px);
pointer-events: auto;
}
.control-title {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 10px;
gap: 12px;
}
.control-title strong {
font-size: 12px;
letter-spacing: 0.02em;
}
.control-title output {
color: var(--cyan);
font-size: 19px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--fill: 69%;
width: 100%;
height: 7px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--cyan) 0,
var(--cyan) var(--fill),
#dbe5e4 var(--fill),
#dbe5e4 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 4px solid white;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 2px 8px rgba(24, 49, 66, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 4px solid white;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 2px 8px rgba(24, 49, 66, 0.28);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: #80919a;
font-size: 9px;
font-weight: 800;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
min-height: 48px;
padding: 10px 12px;
border: 1px solid #d8e1df;
border-radius: 13px;
background: #f4f8f6;
color: var(--ink);
cursor: pointer;
transition: 160ms ease;
}
.toggle:hover {
transform: translateY(-1px);
border-color: #a8c6d5;
}
.toggle.active {
border-color: #72add8;
background: #e7f4ff;
color: #216da9;
}
.toggle-copy {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
}
.toggle-copy strong {
font-size: 12px;
}
.toggle-copy small {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.switch {
position: relative;
width: 38px;
height: 22px;
flex: 0 0 auto;
border-radius: 999px;
background: #cbd7d5;
transition: 160ms ease;
}
.switch::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 16px;
height: 16px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(24, 49, 66, 0.25);
transition: 160ms ease;
}
.toggle.active .switch {
background: var(--blue);
}
.toggle.active .switch::after {
transform: translateX(16px);
}
.actions {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 6px;
}
.small-button {
padding: 8px 11px;
border: 1px solid #d5dfdc;
border-radius: 10px;
background: white;
color: var(--ink);
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: 140ms ease;
}
.small-button:hover {
background: #eef6f3;
transform: translateY(-1px);
}
.hint {
color: #819198;
font-size: 9px;
font-weight: 700;
text-align: center;
white-space: nowrap;
}
@media (max-width: 760px) {
.brand {
top: 17px;
left: 17px;
}
.brand-mark {
width: 39px;
height: 39px;
}
.brand-mark::before {
left: 8px;
top: 8px;
}
.brand-mark::after {
left: 15px;
top: 8px;
}
.subtitle {
display: none;
}
.live-pill {
top: 19px;
right: 16px;
padding: 8px 10px;
}
.live-pill span:last-child {
display: none;
}
.readouts {
top: 69px;
right: 16px;
left: 16px;
width: auto;
gap: 6px;
}
.metric {
min-height: 76px;
padding: 10px;
border-radius: 13px;
}
.metric-label {
margin-bottom: 6px;
font-size: 8px;
}
.metric-value {
font-size: 20px;
}
.metric-detail {
margin-top: 4px;
font-size: 8px;
}
.controls {
bottom: 12px;
grid-template-columns: 1fr 1fr;
gap: 12px;
width: calc(100vw - 24px);
padding: 12px;
border-radius: 17px;
}
.actions {
grid-column: 1 / -1;
flex-direction: row;
align-items: center;
}
.actions .small-button {
flex: 1;
}
.hint {
flex: 1.4;
}
}
@media (max-height: 590px) and (min-width: 761px) {
.readouts {
top: 76px;
}
.metric {
min-height: 78px;
}
.controls {
bottom: 12px;
padding-top: 11px;
padding-bottom: 11px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene"></div>
<div class="hud">
<header class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Voxel climate lab</p>
<h1>Thermo Hut</h1>
<p class="subtitle">A tiny room with a very big thermostat.</p>
</div>
</header>
<div class="live-pill">
<span class="live-dot"></span>
<span>Simulation live</span>
</div>
<section class="readouts" aria-label="Thermostat readings">
<article class="metric">
<div class="metric-label">
<span class="metric-icon"></span>
Target
</div>
<span class="metric-value" id="targetValue">21.5°C</span>
<span class="metric-detail">Thermostat setpoint</span>
</article>
<article class="metric">
<div class="metric-label">
<span class="metric-icon" style="background:#49c39a"></span>
Measured
</div>
<span class="metric-value" id="measuredValue">19.0°C</span>
<span class="metric-detail">Room temperature</span>
</article>
<article class="metric heater" id="heaterCard">
<div class="metric-label">
<span class="metric-icon"></span>
Heater
</div>
<span class="metric-value" id="heaterValue">ON</span>
<span class="metric-detail" id="heaterDetail">Radiator warming</span>
</article>
<article class="metric external" id="disturbanceCard">
<div class="metric-label">
<span class="metric-icon"></span>
External
</div>
<span class="metric-value" id="outsideValue">4.0°C</span>
<span class="metric-detail" id="disturbanceDetail">No disturbance</span>
</article>
</section>
<section class="controls" aria-label="Thermostat controls">
<div>
<label class="control-title" for="targetSlider">
<strong>Target temperature</strong>
<output id="targetOutput" for="targetSlider">21.5°C</output>
</label>
<input
id="targetSlider"
type="range"
min="16"
max="25"
step="0.5"
value="21.5"
aria-label="Target temperature"
>
<div class="range-labels">
<span>16°C</span>
<span>25°C</span>
</div>
</div>
<button class="toggle" id="disturbanceButton" type="button" aria-pressed="false">
<span class="toggle-copy">
<strong>Cold-window draft</strong>
<small>Click the blue window too</small>
</span>
<span class="switch" aria-hidden="true"></span>
</button>
<div class="actions">
<button class="small-button" id="resetButton" type="button">Reset room</button>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</div>
</section>
</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 container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.08;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc7d9e2);
scene.fog = new THREE.Fog(0xc7d9e2, 20, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(-0.1, 1.85, -0.35),
radius: 15.4,
theta: 0.64,
phi: 1.03
};
const defaultCamera = { ...cameraState, target: cameraState.target.clone() };
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xeaf7ff, 0x9d765d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d8, 3.4);
sun.position.set(6, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00045;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9dcff, 0.8);
fill.position.set(-6, 5, 2);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(w, h, d, color, x, y, z, parent = scene) {
const material = color?.isMaterial ? color : getMaterial(color);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and raised toy-room platform.
box(80, 0.12, 80, 0xb7ccd3, 0, -0.5, 0);
box(10.8, 0.42, 8.8, 0x6d7880, 0, -0.21, 0);
box(10.55, 0.18, 8.55, 0xb88964, 0, 0.03, 0);
const floorColors = [0xd9b887, 0xe1c397, 0xd2ad7c, 0xe6c9a0, 0xd5b181];
for (let x = 0; x < 10; x++) {
for (let z = 0; z < 8; z++) {
const color = floorColors[(x * 3 + z * 5) % floorColors.length];
box(0.97, 0.14, 0.97, color, -4.5 + x, 0.15, -3.5 + z);
}
}
// Cutaway voxel walls.
const wallColors = [0xf1dfc2, 0xf5e5ca, 0xecd8ba, 0xf7e8cf];
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 10; col++) {
const isWindow = (row === 2 || row === 3) && (col === 7 || col === 8);
if (isWindow) continue;
const color = wallColors[(row + col * 2) % wallColors.length];
box(
0.98,
0.83,
0.28,
color,
-4.5 + col,
0.14 + (row + 0.5) * 0.85,
-4.0
);
}
}
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 8; col++) {
const color = wallColors[(row * 2 + col + 1) % wallColors.length];
box(
0.28,
0.83,
0.98,
color,
-5.0,
0.14 + (row + 0.5) * 0.85,
-3.5 + col
);
}
}
// Window, frame, winter sky, and snow.
const windowSkyMaterial = new THREE.MeshStandardMaterial({
color: 0x7db5d0,
emissive: 0x376b91,
emissiveIntensity: 0.18,
roughness: 1
});
box(2.15, 1.78, 0.06, windowSkyMaterial, 3.0, 2.69, -4.28);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x9fe7f2,
transparent: true,
opacity: 0.27,
roughness: 0.18,
metalness: 0.05,
depthWrite: false
});
const windowGlass = box(
2.04,
1.66,
0.06,
glassMaterial,
3.0,
2.69,
-4.04
);
windowGlass.castShadow = false;
windowGlass.userData.interactive = "window";
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x426879,
roughness: 0.7
});
box(0.18, 1.94, 0.18, frameMaterial, 1.91, 2.69, -3.83);
box(0.18, 1.94, 0.18, frameMaterial, 4.09, 2.69, -3.83);
box(2.36, 0.18, 0.18, frameMaterial, 3.0, 1.72, -3.83);
box(2.36, 0.18, 0.18, frameMaterial, 3.0, 3.66, -3.83);
box(0.12, 1.72, 0.14, frameMaterial, 3.0, 2.69, -3.82);
box(2.08, 0.11, 0.14, frameMaterial, 3.0, 2.68, -3.82);
box(2.36, 0.18, 0.44, 0xe8d3b3, 3.0, 1.65, -3.72);
const snowGroup = new THREE.Group();
scene.add(snowGroup);
const snowMeshes = [];
for (let i = 0; i < 19; i++) {
const size = 0.045 + Math.random() * 0.055;
const snow = box(
size,
size,
size,
0xf7ffff,
2.08 + Math.random() * 1.84,
1.9 + Math.random() * 1.65,
-4.18,
snowGroup
);
snow.castShadow = false;
snowMeshes.push({
mesh: snow,
speed: 0.09 + Math.random() * 0.13,
phase: Math.random() * Math.PI * 2
});
}
// Voxel thermostat with a live canvas display.
const thermostat = new THREE.Group();
thermostat.position.set(-0.55, 3.12, -3.72);
scene.add(thermostat);
box(1.65, 1.5, 0.25, 0x243a48, 0, 0, 0, thermostat);
box(1.43, 1.28, 0.08, 0x142b37, 0, 0.03, 0.15, thermostat);
const thermostatCanvas = document.createElement("canvas");
thermostatCanvas.width = 256;
thermostatCanvas.height = 256;
const thermostatContext = thermostatCanvas.getContext("2d");
const thermostatTexture = new THREE.CanvasTexture(thermostatCanvas);
thermostatTexture.colorSpace = THREE.SRGBColorSpace;
thermostatTexture.minFilter = THREE.NearestFilter;
thermostatTexture.magFilter = THREE.NearestFilter;
thermostatTexture.generateMipmaps = false;
const screenMaterial = new THREE.MeshBasicMaterial({ map: thermostatTexture });
const screen = new THREE.Mesh(new THREE.PlaneGeometry(1.18, 1.05), screenMaterial);
screen.position.set(0, 0.04, 0.202);
thermostat.add(screen);
const heaterLedMaterial = new THREE.MeshStandardMaterial({
color: 0xff8a3d,
emissive: 0xff5b10,
emissiveIntensity: 1.8,
roughness: 0.4
});
box(0.16, 0.12, 0.08, heaterLedMaterial, 0.58, -0.61, 0.2, thermostat);
// Radiator and glowing heat strips.
const radiator = new THREE.Group();
radiator.position.set(3.0, 0.0, -3.52);
scene.add(radiator);
for (let i = 0; i < 9; i++) {
box(0.16, 0.9, 0.35, 0xf2eee3, -0.88 + i * 0.22, 0.88, 0, radiator);
}
box(1.98, 0.16, 0.42, 0xe5e4dc, 0, 1.31, 0, radiator);
box(1.98, 0.14, 0.42, 0xe5e4dc, 0, 0.43, 0, radiator);
box(0.12, 0.78, 0.12, 0xc8cdca, -0.98, 0.2, 0, radiator);
box(0.12, 0.78, 0.12, 0xc8cdca, 0.98, 0.2, 0, radiator);
const heatGlowMaterial = new THREE.MeshStandardMaterial({
color: 0xff7433,
emissive: 0xff4e11,
emissiveIntensity: 1.9,
transparent: true,
opacity: 0.78
});
const heatGlow = new THREE.Group();
scene.add(heatGlow);
for (let i = 0; i < 3; i++) {
box(1.9, 0.09, 0.05, heatGlowMaterial, 3.0, 0.55 + i * 0.31, -3.83, heatGlow);
}
const heaterLight = new THREE.PointLight(0xff7433, 0, 5, 2);
heaterLight.position.set(3.0, 1.1, -3.1);
scene.add(heaterLight);
// Heat particles.
const heatGroup = new THREE.Group();
scene.add(heatGroup);
const heatParticles = [];
for (let i = 0; i < 13; i++) {
const size = 0.08 + Math.random() * 0.07;
const particle = box(
size,
size,
size,
0xff9a52,
2.25 + Math.random() * 1.5,
0.5,
-3.05,
heatGroup
);
particle.castShadow = false;
heatParticles.push({
mesh: particle,
speed: 0.45 + Math.random() * 0.45,
offset: Math.random() * 1.4
});
}
// Cold draft particles.
const gustGroup = new THREE.Group();
scene.add(gustGroup);
const gustParticles = [];
const gustMaterial = new THREE.MeshStandardMaterial({
color: 0x68c8f1,
emissive: 0x3b9ccc,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.6,
depthWrite: false
});
for (let i = 0; i < 15; i++) {
const size = 0.09 + Math.random() * 0.11;
const particle = box(
size,
size,
size,
gustMaterial,
2.9 + Math.random() * 0.4,
2.25 + Math.random() * 0.75,
-3.6,
gustGroup
);
particle.castShadow = false;
gustParticles.push({
mesh: particle,
speed: 0.65 + Math.random() * 0.75,
phase: Math.random()
});
}
// Blocky sofa against the left wall.
const sofa = new THREE.Group();
sofa.position.set(-3.9, 0, -0.35);
sofa.rotation.y = Math.PI / 2;
scene.add(sofa);
box(2.9, 0.42, 1.45, 0xb95e53, 0, 0.53, 0, sofa);
box(2.9, 1.18, 0.34, 0xd96f60, 0, 1.03, -0.58, sofa);
box(0.36, 0.86, 1.46, 0xc76255, -1.45, 0.75, 0, sofa);
box(0.36, 0.86, 1.46, 0xc76255, 1.45, 0.75, 0, sofa);
box(1.12, 0.25, 1.12, 0xf08b76, -0.65, 0.88, 0.08, sofa);
box(1.12, 0.25, 1.12, 0xf08b76, 0.65, 0.88, 0.08, sofa);
box(0.84, 0.76, 0.22, 0xf2c27f, -0.65, 1.27, -0.32, sofa);
box(0.84, 0.76, 0.22, 0xf2c27f, 0.65, 1.27, -0.32, sofa);
for (const x of [-1.1, 1.1]) {
for (const z of [-0.46, 0.46]) {
box(0.17, 0.3, 0.17, 0x654b43, x, 0.24, z, sofa);
}
}
// Rug and coffee table.
box(4.3, 0.08, 3.0, 0x719b9d, -1.7, 0.26, 0.65);
box(3.75, 0.035, 2.5, 0x91b4ad, -1.7, 0.315, 0.65);
box(2.05, 0.22, 1.2, 0x9a6848, -1.65, 0.92, 1.65);
for (const x of [-2.45, -0.85]) {
for (const z of [1.25, 2.05]) {
box(0.16, 0.64, 0.16, 0x64463c, x, 0.57, z);
}
}
box(0.78, 0.1, 0.58, 0x4f6d75, -1.95, 1.08, 1.55);
box(0.62, 0.08, 0.5, 0xe7b65f, -1.9, 1.16, 1.53);
box(0.35, 0.28, 0.35, 0xece8dc, -1.25, 1.16, 1.72);
// Cabinet, drawers, and a potted plant.
const cabinet = new THREE.Group();
cabinet.position.set(4.25, 0, -0.35);
scene.add(cabinet);
box(1.55, 1.75, 1.25, 0xd7ad73, 0, 1.02, 0, cabinet);
box(1.68, 0.16, 1.38, 0xefc996, 0, 1.97, 0, cabinet);
for (let i = 0; i < 3; i++) {
box(1.25, 0.42, 0.1, 0xe7bf83, 0, 0.48 + i * 0.52, 0.66, cabinet);
box(0.22, 0.09, 0.09, 0x72533f, 0, 0.48 + i * 0.52, 0.74, cabinet);
}
function makePlant(parent, x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
box(0.48, 0.42, 0.48, 0xc66f50, 0, 0.21, 0, group);
box(0.54, 0.1, 0.54, 0xde8a65, 0, 0.45, 0, group);
box(0.09, 0.75, 0.09, 0x4d7957, 0, 0.83, 0, group);
box(0.42, 0.22, 0.22, 0x5b9566, -0.18, 0.88, 0, group);
box(0.22, 0.4, 0.22, 0x67a16c, 0.2, 1.1, 0.02, group);
box(0.26, 0.24, 0.26, 0x4e895c, -0.08, 1.31, 0, group);
return group;
}
makePlant(cabinet, 0.12, 2.04, 0, 0.78);
makePlant(scene, 4.15, 0.22, 2.6, 1.2);
// Voxel floor lamp.
box(0.52, 0.12, 0.52, 0x44545c, 4.35, 0.28, -2.55);
box(0.1, 2.55, 0.1, 0x53636b, 4.35, 1.55, -2.55);
box(0.72, 0.68, 0.72, 0xf2c56d, 4.35, 2.92, -2.55);
box(0.8, 0.1, 0.8, 0xe3aa52, 4.35, 3.3, -2.55);
// Small wall artwork.
const art = new THREE.Group();
art.position.set(-3.45, 3.15, -3.78);
scene.add(art);
box(1.72, 1.42, 0.12, 0x785c4c, 0, 0, 0, art);
box(1.48, 1.18, 0.08, 0xf3dfbc, 0, 0, 0.08, art);
box(0.48, 0.46, 0.07, 0x5f9fa5, -0.32, 0.14, 0.15, art);
box(0.35, 0.62, 0.07, 0xe58259, 0.28, 0.05, 0.15, art);
box(0.72, 0.18, 0.07, 0xefc65f, -0.1, -0.36, 0.15, art);
// Simulation state.
const state = {
target: 21.5,
measured: 19.0,
heater: true,
disturbance: false,
outside: 4.0
};
const targetSlider = document.getElementById("targetSlider");
const targetOutput = document.getElementById("targetOutput");
const targetValue = document.getElementById("targetValue");
const measuredValue = document.getElementById("measuredValue");
const heaterCard = document.getElementById("heaterCard");
const heaterValue = document.getElementById("heaterValue");
const heaterDetail = document.getElementById("heaterDetail");
const disturbanceCard = document.getElementById("disturbanceCard");
const outsideValue = document.getElementById("outsideValue");
const disturbanceDetail = document.getElementById("disturbanceDetail");
const disturbanceButton = document.getElementById("disturbanceButton");
const resetButton = document.getElementById("resetButton");
function updateSliderFill() {
const percent =
((parseFloat(targetSlider.value) - parseFloat(targetSlider.min)) /
(parseFloat(targetSlider.max) - parseFloat(targetSlider.min))) *
100;
targetSlider.style.setProperty("--fill", `${percent}%`);
}
function updateThermostatDisplay() {
const ctx = thermostatContext;
ctx.fillStyle = "#10252f";
ctx.fillRect(0, 0, 256, 256);
ctx.strokeStyle = "#31505c";
ctx.lineWidth = 4;
ctx.strokeRect(4, 4, 248, 248);
ctx.textAlign = "center";
ctx.fillStyle = "#82dbe8";
ctx.font = "bold 21px monospace";
ctx.fillText("TARGET", 128, 39);
ctx.fillStyle = "#f5fbfa";
ctx.font = "bold 50px monospace";
ctx.fillText(`${state.target.toFixed(1)}°`, 128, 94);
ctx.strokeStyle = "#37505a";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(24, 113);
ctx.lineTo(232, 113);
ctx.stroke();
ctx.fillStyle = "#8ba4ad";
ctx.font = "bold 18px monospace";
ctx.fillText("ROOM", 128, 142);
ctx.fillStyle = state.heater ? "#ffb35d" : "#9ce4c2";
ctx.font = "bold 52px monospace";
ctx.fillText(`${state.measured.toFixed(1)}°`, 128, 198);
ctx.fillStyle = state.disturbance ? "#77bff2" : "#78939c";
ctx.font = "bold 17px monospace";
ctx.fillText(
state.disturbance ? "COLD DRAFT" : state.heater ? "HEATING" : "AUTO",
128,
235
);
thermostatTexture.needsUpdate = true;
}
function updateUI() {
const targetText = `${state.target.toFixed(1)}°C`;
targetOutput.textContent = targetText;
targetValue.textContent = targetText;
measuredValue.textContent = `${state.measured.toFixed(1)}°C`;
heaterValue.textContent = state.heater ? "ON" : "OFF";
heaterDetail.textContent = state.heater ? "Radiator warming" : "At target · idle";
heaterCard.classList.toggle("on", state.heater);
outsideValue.textContent = `${state.outside.toFixed(1)}°C`;
disturbanceDetail.textContent = state.disturbance
? "Cold draft active"
: "No disturbance";
disturbanceCard.classList.toggle("active", state.disturbance);
disturbanceButton.classList.toggle("active", state.disturbance);
disturbanceButton.setAttribute("aria-pressed", String(state.disturbance));
heaterLedMaterial.color.set(state.heater ? 0xff8a3d : 0x53666f);
heaterLedMaterial.emissive.set(state.heater ? 0xff5b10 : 0x000000);
heaterLedMaterial.emissiveIntensity = state.heater ? 1.8 : 0;
heatGlow.visible = state.heater;
heaterLight.intensity = state.heater ? 18 : 0;
glassMaterial.opacity = state.disturbance ? 0.44 : 0.27;
windowSkyMaterial.emissiveIntensity = state.disturbance ? 0.48 : 0.18;
updateThermostatDisplay();
}
function toggleDisturbance() {
state.disturbance = !state.disturbance;
updateUI();
}
targetSlider.addEventListener("input", () => {
state.target = parseFloat(targetSlider.value);
updateSliderFill();
updateUI();
});
disturbanceButton.addEventListener("click", toggleDisturbance);
resetButton.addEventListener("click", () => {
state.target = 21.5;
state.measured = 19.0;
state.heater = true;
state.disturbance = false;
targetSlider.value = "21.5";
updateSliderFill();
updateUI();
});
updateSliderFill();
updateUI();
// Direct camera controls: drag to orbit and wheel/pinch to zoom.
let dragging = false;
let movedDistance = 0;
let lastPointerX = 0;
let lastPointerY = 0;
const activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
movedDistance = 0;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + (pinchDistance - distance) * 0.018,
9.5,
23
);
pinchDistance = distance;
updateCamera();
return;
}
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
movedDistance += Math.abs(deltaX) + Math.abs(deltaY);
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.48,
1.42
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
if (activePointers.size === 0) {
dragging = false;
renderer.domElement.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
9.5,
23
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.target.copy(defaultCamera.target);
updateCamera();
});
// Clicking the glass window toggles the external disturbance.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("click", (event) => {
if (movedDistance > 7) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(windowGlass);
if (hits.length) toggleDisturbance();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let elapsed = 0;
let uiTimer = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
// Thermostat hysteresis.
if (state.measured < state.target - 0.25) {
state.heater = true;
} else if (state.measured > state.target + 0.25) {
state.heater = false;
}
const heaterGain = state.heater ? 0.28 : 0;
const passiveLoss = 0.07;
const disturbanceLoss = state.disturbance ? 0.18 : 0;
const tinyVariation = Math.sin(elapsed * 1.4) * 0.004;
state.measured +=
(heaterGain - passiveLoss - disturbanceLoss + tinyVariation) * delta;
state.measured = THREE.MathUtils.clamp(state.measured, 4, 28);
// Snow outside the window.
for (const snow of snowMeshes) {
snow.mesh.position.y -= snow.speed * delta;
snow.mesh.position.x += Math.sin(elapsed * 0.7 + snow.phase) * 0.0018;
if (snow.mesh.position.y < 1.84) {
snow.mesh.position.y = 3.5;
snow.mesh.position.x = 2.08 + Math.random() * 1.84;
}
}
// Rising warm cubes above the radiator.
heatGroup.visible = state.heater;
if (state.heater) {
for (const particle of heatParticles) {
const progress = (elapsed * particle.speed + particle.offset) % 1;
particle.mesh.position.y = 0.55 + progress * 1.55;
particle.mesh.position.z = -3.05 + progress * 0.35;
particle.mesh.position.x += Math.sin(elapsed * 2 + particle.offset) * 0.001;
const scale = 1 - progress * 0.7;
particle.mesh.scale.set(scale, scale, scale);
}
}
// Cold cubes entering from the window.
gustGroup.visible = state.disturbance;
if (state.disturbance) {
for (const particle of gustParticles) {
particle.mesh.position.z += particle.speed * delta;
particle.mesh.position.x -= particle.speed * delta * 0.22;
particle.mesh.position.y += Math.sin(elapsed * 3 + particle.phase) * 0.003;
if (particle.mesh.position.z > 1.8) {
particle.mesh.position.set(
2.9 + Math.random() * 0.4,
2.25 + Math.random() * 0.75,
-3.6
);
}
}
}
uiTimer += delta;
if (uiTimer > 0.12) {
uiTimer = 0;
updateUI();
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```