Prompt specification
Build or customize the Three.js 3D scene "Automatic-light concept diorama" 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: Automatic-light concept diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/automatic-light-concept-diorama-x1679
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: automatic-light concept diorama. Compose a room with a light sensor symbol, threshold comparator, transistor-switch block, and lamp; trace sensing, decision, and actuation as separate stages.
Working Three.js Starter (automatic-light-concept-diorama-x1679):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Automatic Light — Voxel Concept Diorama</title>
<style>
:root {
--bg: #08111d;
--panel: rgba(10, 21, 35, 0.88);
--border: rgba(164, 205, 232, 0.17);
--text: #eaf5ff;
--muted: #8da8bb;
--cyan: #62ddff;
--amber: #ffc75c;
--coral: #ff6f86;
--green: #79f2b5;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-card {
top: 24px;
left: 24px;
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
h1 {
margin: 0;
font-size: clamp(26px, 4vw, 52px);
font-weight: 800;
line-height: 0.98;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.subtitle {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.control-card {
top: 24px;
right: 24px;
width: 286px;
padding: 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.control-card header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.control-card h2 {
margin: 0;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.auto-pill {
padding: 5px 8px;
border: 1px solid rgba(121, 242, 181, 0.28);
border-radius: 999px;
color: var(--green);
background: rgba(121, 242, 181, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.control-row {
margin-top: 14px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 11px;
}
.control-label output {
color: var(--text);
font-variant-numeric: tabular-nums;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 10px;
outline: none;
appearance: none;
background: #263849;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #102031;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan), 0 0 13px rgba(98, 221, 255, 0.5);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #102031;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan), 0 0 13px rgba(98, 221, 255, 0.5);
cursor: pointer;
}
#threshold {
background: #34404b;
}
#threshold::-webkit-slider-thumb {
background: var(--amber);
box-shadow: 0 0 0 1px var(--amber), 0 0 13px rgba(255, 199, 92, 0.45);
}
#threshold::-moz-range-thumb {
background: var(--amber);
box-shadow: 0 0 0 1px var(--amber), 0 0 13px rgba(255, 199, 92, 0.45);
}
.state {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 12px;
margin-top: 17px;
padding-top: 14px;
border-top: 1px solid var(--border);
}
.state-label {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#lamp-state {
color: var(--green);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
left: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: min(640px, calc(100vw - 48px));
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(8, 17, 29, 0.78);
color: #b7c9d7;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 10px var(--dot);
}
.hint {
right: 24px;
bottom: 24px;
color: #718a9e;
font-size: 10px;
font-weight: 600;
letter-spacing: 0.06em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title-card {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.subtitle {
display: none;
}
.control-card {
top: auto;
right: 14px;
bottom: 62px;
width: 245px;
padding: 12px;
}
.legend {
left: 14px;
bottom: 14px;
}
.hint {
display: none;
}
.legend-item {
padding: 6px 8px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="overlay title-card">
<div class="eyebrow">Embedded systems / concept 01</div>
<h1>Automatic<br />Light</h1>
<p class="subtitle">
A voxel room-control study: a light sensor measures the environment,
a threshold comparator makes the decision, and an NPN transistor drives
the lamp.
</p>
</header>
<aside class="overlay control-card">
<header>
<h2>Live control</h2>
<span class="auto-pill">AUTO</span>
</header>
<div class="control-row">
<label class="control-label" for="ambient">
<span>Ambient light</span>
<output id="ambient-output">24 lx</output>
</label>
<input id="ambient" type="range" min="5" max="90" value="24" />
</div>
<div class="control-row">
<label class="control-label" for="threshold">
<span>Turn-on threshold</span>
<output id="threshold-output">40 lx</output>
</label>
<input id="threshold" type="range" min="5" max="90" value="40" />
</div>
<div class="state">
<span class="state-label">Lamp output<br />Light < threshold</span>
<span id="lamp-state">ON</span>
</div>
</aside>
<div class="overlay legend">
<div class="legend-item" style="--dot: var(--cyan)">
<span class="dot"></span>01 Sensing
</div>
<div class="legend-item" style="--dot: var(--amber)">
<span class="dot"></span>02 Decision
</div>
<div class="legend-item" style="--dot: var(--coral)">
<span class="dot"></span>03 Actuation
</div>
</div>
<div class="overlay hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const host = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#08111d");
scene.fog = new THREE.Fog("#08111d", 42, 76);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 120);
const controls = {
azimuth: 0.58,
targetAzimuth: 0.58,
polar: 0.98,
targetPolar: 0.98,
zoom: 1,
targetZoom: 1,
radius: 31,
target: new THREE.Vector3(0, 2.4, 0),
dragging: false,
lastX: 0,
lastY: 0,
};
const hemi = new THREE.HemisphereLight(0xaedfff, 0x162131, 1.45);
scene.add(hemi);
const sunlight = new THREE.DirectionalLight(0xfff2d7, 2.0);
sunlight.position.set(-10, 17, 12);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -19;
sunlight.shadow.camera.right = 19;
sunlight.shadow.camera.top = 18;
sunlight.shadow.camera.bottom = -16;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 50;
sunlight.shadow.bias = -0.0003;
scene.add(sunlight);
const fill = new THREE.DirectionalLight(0x5dbdff, 0.65);
fill.position.set(14, 9, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Palette and geometry helpers
// -------------------------------------------------------------------------
const palette = {
ink: "#09131f",
wall: "#203346",
wallDark: "#152637",
floor: "#31465a",
floorLine: "#223548",
steel: "#64798a",
steelDark: "#33495c",
cyan: "#62ddff",
amber: "#ffc75c",
coral: "#ff6f86",
green: "#79f2b5",
warm: "#ffd58a",
white: "#d9efff",
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.04,
...options,
});
}
const mats = {
base: material(palette.ink),
floor: material(palette.floor),
floorLine: material(palette.floorLine),
wall: material(palette.wall),
wallDark: material(palette.wallDark),
steel: material(palette.steel),
steelDark: material(palette.steelDark),
black: material("#07101a"),
white: material(palette.white),
cyan: material(palette.cyan, {
emissive: palette.cyan,
emissiveIntensity: 0.7,
}),
amber: material(palette.amber, {
emissive: palette.amber,
emissiveIntensity: 0.65,
}),
coral: material(palette.coral, {
emissive: palette.coral,
emissiveIntensity: 0.6,
}),
green: material(palette.green, {
emissive: palette.green,
emissiveIntensity: 1.3,
}),
};
function addBox(
parent,
width,
height,
depth,
mat,
x = 0,
y = 0,
z = 0,
{ cast = true, receive = true } = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addSegment(
parent,
a,
b,
width,
depth,
mat,
{ cast = true } = {}
) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, width, depth),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeBadge(text, color, width = 3.4) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(7, 17, 29, 0.91)";
ctx.fillRect(4, 4, 760, 152);
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.strokeRect(5, 5, 758, 150);
ctx.fillStyle = color;
ctx.fillRect(28, 31, 8, 98);
ctx.font = "800 56px system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(text, 59, 81);
const texture = canvasTexture(canvas);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false,
})
);
sprite.scale.set(width, width * (160 / 768), 1);
sprite.renderOrder = 10;
return sprite;
}
function makeTextPlane(
text,
width,
height,
color = "#d9efff",
background = "rgba(7, 17, 29, 0.8)",
fontSize = 64
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = Math.max(128, Math.round((height / width) * 1024));
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(168, 205, 228, 0.28)";
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
ctx.fillStyle = color;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = canvasTexture(canvas);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false,
})
);
return mesh;
}
// -------------------------------------------------------------------------
// Cutaway room
// -------------------------------------------------------------------------
addBox(scene, 25, 1, 18, mats.base, 0, -0.56, 0);
addBox(scene, 24.4, 0.12, 17.4, mats.floor, 0, -0.02, 0);
// Floor grid.
for (let x = -10; x <= 10; x += 2) {
addBox(
scene,
0.025,
0.015,
16.8,
mats.floorLine,
x,
0.052,
0,
{ cast: false }
);
}
for (let z = -7; z <= 7; z += 2) {
addBox(
scene,
23.8,
0.015,
0.025,
mats.floorLine,
0,
0.052,
z,
{ cast: false }
);
}
// Back and left walls.
addBox(scene, 25, 9, 0.42, mats.wall, 0, 4.35, -8.35);
addBox(scene, 0.42, 9, 16.6, mats.wall, -12.3, 4.35, -0.1);
addBox(scene, 25.2, 0.22, 0.65, mats.steelDark, 0, 8.85, -8.35);
addBox(scene, 0.65, 0.22, 16.8, mats.steelDark, -12.3, 8.85, -0.1);
// Lower wall panels.
addBox(scene, 24.6, 1.6, 0.12, mats.wallDark, 0, 0.78, -8.08);
addBox(scene, 0.12, 1.6, 16.2, mats.wallDark, -12.02, 0.78, -0.1);
// Wall-mounted architectural sign.
const wallSign = makeTextPlane(
"AUTOMATIC / LIGHT",
8.2,
1.55,
"#dff7ff",
"rgba(8, 20, 32, 0.94)",
76
);
wallSign.position.set(1.2, 6.75, -8.08);
scene.add(wallSign);
// Window.
const windowGroup = new THREE.Group();
windowGroup.position.set(-7.3, 5.1, -8.04);
scene.add(windowGroup);
const skyMaterial = material("#74c7e8", {
emissive: "#74c7e8",
emissiveIntensity: 0.8,
roughness: 1,
});
addBox(
windowGroup,
4.7,
3.25,
0.12,
skyMaterial,
0,
0,
0,
{ cast: false }
);
addBox(windowGroup, 0.18, 3.5, 0.24, mats.white, -2.4, 0, 0.08);
addBox(windowGroup, 0.18, 3.5, 0.24, mats.white, 2.4, 0, 0.08);
addBox(windowGroup, 4.95, 0.18, 0.24, mats.white, 0, -1.66, 0.08);
addBox(windowGroup, 4.95, 0.18, 0.24, mats.white, 0, 1.66, 0.08);
addBox(windowGroup, 0.11, 3.25, 0.22, mats.white, 0, 0, 0.09);
const windowSunMaterial = material("#ffe28b", {
emissive: "#ffe28b",
emissiveIntensity: 2.2,
});
addBox(
windowGroup,
0.7,
0.7,
0.12,
windowSunMaterial,
1.35,
0.85,
0.12,
{ cast: false }
);
// Blocky clouds.
addBox(
windowGroup,
1.1,
0.22,
0.05,
material("#d8eef8", { transparent: true, opacity: 0.8 }),
-0.7,
0.65,
0.09,
{ cast: false }
);
addBox(
windowGroup,
0.65,
0.22,
0.05,
material("#d8eef8", { transparent: true, opacity: 0.8 }),
-0.25,
0.82,
0.09,
{ cast: false }
);
// Ventilation blocks on the wall.
for (let i = 0; i < 5; i++) {
addBox(
scene,
2.3,
0.12,
0.16,
mats.steelDark,
5.3,
5.05 + i * 0.29,
-8.03
);
}
// -------------------------------------------------------------------------
// Stage floor zones and station plinths
// -------------------------------------------------------------------------
const zoneSense = material("#163a49");
const zoneDecide = material("#3b3528");
const zoneActuate = material("#402b36");
addBox(scene, 5.35, 0.045, 5.4, zoneSense, -7.65, 0.075, 0.2, {
cast: false,
});
addBox(scene, 4.75, 0.045, 5.4, zoneDecide, -2.75, 0.075, 0.2, {
cast: false,
});
addBox(scene, 7.85, 0.045, 5.4, zoneActuate, 5.7, 0.075, 0.2, {
cast: false,
});
addBox(scene, 3.2, 0.28, 3.0, mats.steelDark, -7.7, 0.25, 0.25);
addBox(scene, 4.0, 0.28, 3.0, mats.steelDark, -2.75, 0.25, 0.25);
addBox(scene, 3.15, 0.28, 3.0, mats.steelDark, 3.0, 0.25, 0.25);
addBox(scene, 2.75, 0.28, 3.0, mats.steelDark, 8.15, 0.25, 0.25);
// -------------------------------------------------------------------------
// Stage 1: light sensor
// -------------------------------------------------------------------------
const sensor = new THREE.Group();
sensor.position.set(-7.7, 0, 0.35);
scene.add(sensor);
addBox(sensor, 0.4, 1.9, 0.4, mats.steel, 0, 1.33, 0);
addBox(sensor, 2.65, 2.8, 0.48, mats.black, 0, 3.55, 0);
addBox(sensor, 2.32, 2.47, 0.08, material("#102c3c"), 0, 3.55, 0.27);
// Voxel sun / light symbol.
const sensorSymbol = new THREE.Group();
sensorSymbol.position.set(0, 4.05, 0.35);
sensor.add(sensorSymbol);
addBox(sensorSymbol, 0.42, 0.42, 0.17, mats.amber, 0, 0, 0);
addSegment(sensorSymbol, [-0.38, 0, 0], [-0.75, 0, 0], 0.12, 0.12, mats.amber);
addSegment(sensorSymbol, [0.38, 0, 0], [0.75, 0, 0], 0.12, 0.12, mats.amber);
addSegment(sensorSymbol, [0, 0.38, 0], [0, 0.75, 0], 0.12, 0.12, mats.amber);
addSegment(sensorSymbol, [0, -0.38, 0], [0, -0.75, 0], 0.12, 0.12, mats.amber);
addSegment(sensorSymbol, [-0.4, 0.4, 0], [-0.7, 0.7, 0], 0.1, 0.1, mats.amber);
addSegment(sensorSymbol, [0.4, 0.4, 0], [0.7, 0.7, 0], 0.1, 0.1, mats.amber);
addSegment(sensorSymbol, [-0.4, -0.4, 0], [-0.7, -0.7, 0], 0.1, 0.1, mats.amber);
addSegment(sensorSymbol, [0.4, -0.4, 0], [0.7, -0.7, 0], 0.1, 0.1, mats.amber);
// Square photodiode below the sun.
addSegment(sensor, [-0.48, 2.7, 0.34], [0.48, 2.7, 0.34], 0.12, 0.12, mats.cyan);
addSegment(sensor, [-0.48, 3.14, 0.34], [-0.48, 2.7, 0.34], 0.12, 0.12, mats.cyan);
addSegment(sensor, [0.48, 3.14, 0.34], [0.48, 2.7, 0.34], 0.12, 0.12, mats.cyan);
addSegment(sensor, [-0.48, 3.14, 0.34], [0.48, 3.14, 0.34], 0.12, 0.12, mats.cyan);
const sensorLabel = makeTextPlane(
"LUX SENSOR",
1.9,
0.38,
palette.cyan,
"rgba(5, 16, 27, 0.84)",
54
);
sensorLabel.position.set(0, 2.36, 0.31);
sensor.add(sensorLabel);
const senseBadge = makeBadge("01 SENSE", palette.cyan, 3.6);
senseBadge.position.set(-7.7, 5.45, 0.2);
scene.add(senseBadge);
// -------------------------------------------------------------------------
// Stage 2: threshold comparator
// -------------------------------------------------------------------------
const comparator = new THREE.Group();
comparator.position.set(-2.75, 0, 0.2);
scene.add(comparator);
addBox(comparator, 3.55, 2.25, 1.85, mats.steel, 0, 1.48, 0);
addBox(comparator, 3.25, 1.95, 0.12, mats.steelDark, 0, 1.48, 0.97);
addBox(comparator, 2.85, 1.06, 0.1, mats.black, 0, 1.78, 1.08);
const comparatorCanvas = document.createElement("canvas");
comparatorCanvas.width = 768;
comparatorCanvas.height = 288;
const comparatorContext = comparatorCanvas.getContext("2d");
const comparatorTexture = canvasTexture(comparatorCanvas);
const comparatorDisplay = new THREE.Mesh(
new THREE.PlaneGeometry(2.65, 0.94),
new THREE.MeshBasicMaterial({
map: comparatorTexture,
toneMapped: false,
})
);
comparatorDisplay.position.set(0, 1.78, 1.145);
comparator.add(comparatorDisplay);
// Comparator input and output ports.
addBox(comparator, 0.32, 0.32, 0.34, mats.cyan, -1.65, 1.0, 1.04);
addBox(comparator, 0.32, 0.32, 0.34, mats.amber, 1.65, 1.0, 1.04);
// Small level blocks and status lights.
for (let i = 0; i < 5; i++) {
addBox(
comparator,
0.18,
0.12,
0.09,
i < 3 ? mats.green : mats.steel,
-1.05 + i * 0.33,
0.86,
1.08
);
}
const comparatorLED = material(palette.green, {
emissive: palette.green,
emissiveIntensity: 2.0,
});
addBox(comparator, 0.19, 0.19, 0.12, comparatorLED, 1.25, 0.85, 1.08);
const decideBadge = makeBadge("02 DECIDE", palette.amber, 3.65);
decideBadge.position.set(-2.75, 4.25, 0.2);
scene.add(decideBadge);
// -------------------------------------------------------------------------
// Stage 3: transistor switch
// -------------------------------------------------------------------------
const transistor = new THREE.Group();
transistor.position.set(3.0, 0, 0.25);
scene.add(transistor);
addBox(transistor, 2.55, 1.95, 1.65, mats.steel, 0, 1.43, 0);
addBox(transistor, 2.2, 1.55, 0.1, mats.black, 0, 1.48, 0.87);
addBox(transistor, 0.36, 0.36, 0.3, mats.amber, -1.14, 0.96, 0.91);
addBox(transistor, 0.36, 0.36, 0.3, mats.coral, 1.14, 0.96, 0.91);
// Block-built NPN transistor schematic.
const symbol = new THREE.Group();
symbol.position.set(0.06, 1.55, 0.96);
transistor.add(symbol);
addSegment(symbol, [-0.2, -0.48, 0], [-0.2, 0.48, 0], 0.11, 0.09, mats.coral);
addSegment(symbol, [-0.2, 0.12, 0], [0.48, 0.65, 0], 0.11, 0.09, mats.coral);
addSegment(symbol, [-0.2, -0.12, 0], [0.48, -0.65, 0], 0.11, 0.09, mats.coral);
addSegment(symbol, [-0.92, 0, 0], [-0.2, 0, 0], 0.11, 0.09, mats.coral);
addSegment(symbol, [0.48, 0.65, 0], [0.95, 0.65, 0], 0.11, 0.09, mats.coral);
// Emitter arrow.
addSegment(symbol, [0.23, -0.43, 0.02], [0.38, -0.56, 0.02], 0.07, 0.07, mats.coral);
addSegment(symbol, [0.35, -0.48, 0.02], [0.24, -0.6, 0.02], 0.07, 0.07, mats.coral);
// Ground symbol.
addSegment(symbol, [0.48, -0.65, 0], [0.83, -0.65, 0], 0.1, 0.08, mats.coral);
addSegment(symbol, [0.54, -0.78, 0], [0.77, -0.78, 0], 0.1, 0.08, mats.coral);
addSegment(symbol, [0.6, -0.91, 0], [0.71, -0.91, 0], 0.1, 0.08, mats.coral);
const switchLabel = makeTextPlane(
"NPN TRANSISTOR",
1.65,
0.31,
palette.coral,
"rgba(6, 15, 25, 0.86)",
48
);
switchLabel.position.set(0, 0.84, 0.94);
transistor.add(switchLabel);
const switchLEDMaterial = material(palette.green, {
emissive: palette.green,
emissiveIntensity: 1.8,
});
addBox(transistor, 0.18, 0.18, 0.12, switchLEDMaterial, 0.9, 0.84, 0.94);
// -------------------------------------------------------------------------
// Stage 3: voxel lamp
// -------------------------------------------------------------------------
const lamp = new THREE.Group();
lamp.position.set(8.15, 0, 0.25);
scene.add(lamp);
addBox(lamp, 1.4, 0.22, 1.4, mats.steelDark, 0, 0.49, 0);
addBox(lamp, 0.26, 2.1, 0.26, mats.steel, 0, 1.52, 0);
const bulbMaterial = material("#ffe0a3", {
emissive: "#ffbd68",
emissiveIntensity: 3.2,
roughness: 0.35,
});
addBox(lamp, 0.67, 0.67, 0.67, bulbMaterial, 0, 2.68, 0);
// Stepped square shade.
addBox(lamp, 2.0, 0.22, 2.0, mats.coral, 0, 3.15, 0);
addBox(lamp, 1.55, 0.22, 1.55, mats.coral, 0, 3.38, 0);
addBox(lamp, 1.05, 0.22, 1.05, mats.coral, 0, 3.61, 0);
addBox(lamp, 0.5, 0.18, 0.5, mats.steelDark, 0, 3.81, 0);
// Shade supports.
addSegment(lamp, [-0.85, 3.05, -0.85], [0, 2.68, 0], 0.11, 0.11, mats.steel);
addSegment(lamp, [0.85, 3.05, -0.85], [0, 2.68, 0], 0.11, 0.11, mats.steel);
addSegment(lamp, [-0.85, 3.05, 0.85], [0, 2.68, 0], 0.11, 0.11, mats.steel);
addSegment(lamp, [0.85, 3.05, 0.85], [0, 2.68, 0], 0.11, 0.11, mats.steel);
const lampLight = new THREE.PointLight(0xffbf70, 15, 9, 2);
lampLight.position.set(0, 2.55, 0);
lamp.add(lampLight);
const actuateBadge = makeBadge("03 ACTUATE", palette.coral, 3.9);
actuateBadge.position.set(5.6, 5.0, 0.2);
scene.add(actuateBadge);
// -------------------------------------------------------------------------
// Signal paths: sensing → decision → actuation
// -------------------------------------------------------------------------
const packets = [];
function createSignalPath({
startX,
endX,
z,
color,
from,
to,
kind,
speed,
}) {
const pathMaterial = material(color, {
emissive: color,
emissiveIntensity: 1.15,
});
addSegment(
scene,
[startX, 0.17, z],
[endX, 0.17, z],
0.13,
0.13,
pathMaterial
);
// Voxel chevron arrow.
addSegment(
scene,
[endX - 0.36, 0.18, z - 0.23],
[endX, 0.18, z],
0.1,
0.1,
pathMaterial
);
addSegment(
scene,
[endX - 0.36, 0.18, z + 0.23],
[endX, 0.18, z],
0.1,
0.1,
pathMaterial
);
if (from) {
addSegment(scene, from, [startX, 0.17, z], 0.12, 0.12, pathMaterial);
}
if (to) {
addSegment(scene, [endX, 0.17, z], to, 0.12, 0.12, pathMaterial);
}
const packetMaterial = material("#ffffff", {
emissive: color,
emissiveIntensity: 3.0,
});
const packet = addBox(
scene,
0.25,
0.25,
0.25,
packetMaterial,
startX,
0.3,
z
);
packets.push({
mesh: packet,
startX,
endX,
z,
kind,
speed,
});
}
createSignalPath({
startX: -6.2,
endX: -4.65,
z: 2.75,
color: palette.cyan,
from: [-6.38, 1.15, 0.85],
to: [-4.5, 1.05, 0.9],
kind: "sense",
speed: 0.32,
});
createSignalPath({
startX: -0.9,
endX: 1.65,
z: 2.75,
color: palette.amber,
from: [-1.1, 1.05, 0.9],
to: [1.7, 1.0, 0.9],
kind: "decision",
speed: 0.28,
});
createSignalPath({
startX: 4.35,
endX: 7.0,
z: 2.75,
color: palette.coral,
from: [4.18, 1.0, 0.9],
to: [7.5, 0.62, 0.3],
kind: "actuation",
speed: 0.31,
});
// Small port blocks make the three stages read as discrete systems.
addBox(scene, 0.26, 0.26, 0.26, mats.cyan, -4.62, 0.17, 2.75);
addBox(scene, 0.26, 0.26, 0.26, mats.amber, 1.7, 0.17, 2.75);
addBox(scene, 0.26, 0.26, 0.26, mats.coral, 7.02, 0.17, 2.75);
// -------------------------------------------------------------------------
// Animated window light rays
// -------------------------------------------------------------------------
const rayMaterial = material("#ffe29a", {
emissive: "#ffe29a",
emissiveIntensity: 0.75,
transparent: true,
opacity: 0.2,
depthWrite: false,
});
const lightRays = [];
for (let i = 0; i < 4; i++) {
const ray = addSegment(
scene,
[-6.3 + i * 0.38, 5.2, -7.82],
[-7.15 + i * 0.26, 3.75, 0.18],
0.075,
0.075,
rayMaterial,
{ cast: false }
);
lightRays.push(ray);
}
// -------------------------------------------------------------------------
// Live control logic
// -------------------------------------------------------------------------
const ambientInput = document.querySelector("#ambient");
const thresholdInput = document.querySelector("#threshold");
const ambientOutput = document.querySelector("#ambient-output");
const thresholdOutput = document.querySelector("#threshold-output");
const lampStateOutput = document.querySelector("#lamp-state");
let ambient = Number(ambientInput.value);
let threshold = Number(thresholdInput.value);
let lampOn = ambient < threshold;
function drawComparator() {
const ctx = comparatorContext;
const w = comparatorCanvas.width;
const h = comparatorCanvas.height;
ctx.fillStyle = "#07131d";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "rgba(98, 221, 255, 0.2)";
ctx.lineWidth = 3;
ctx.strokeRect(7, 7, w - 14, h - 14);
ctx.textBaseline = "middle";
ctx.textAlign = "left";
ctx.fillStyle = "#688ca4";
ctx.font = "700 25px system-ui, sans-serif";
ctx.fillText("AMBIENT", 29, 42);
ctx.fillStyle = "#62ddff";
ctx.font = "800 56px system-ui, sans-serif";
ctx.fillText(`${ambient} lx`, 29, 103);
ctx.fillStyle = "#688ca4";
ctx.font = "700 25px system-ui, sans-serif";
ctx.fillText("THRESHOLD", 29, 163);
ctx.fillStyle = "#ffc75c";
ctx.font = "800 43px system-ui, sans-serif";
ctx.fillText(`${threshold} lx`, 205, 163);
ctx.textAlign = "right";
ctx.fillStyle = lampOn ? "#79f2b5" : "#ff6f86";
ctx.font = "900 32px system-ui, sans-serif";
ctx.fillText(lampOn ? "LAMP ON" : "LAMP OFF", w - 28, 55);
// Compact comparison graphic.
const y = 230;
ctx.strokeStyle = "#385468";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(34, y);
ctx.lineTo(490, y);
ctx.stroke();
const sensorX = 34 + (ambient / 90) * 456;
const thresholdX = 34 + (threshold / 90) * 456;
ctx.fillStyle = "#62ddff";
ctx.fillRect(sensorX - 6, y - 24, 12, 48);
ctx.fillStyle = "#ffc75c";
ctx.fillRect(thresholdX - 4, y - 34, 8, 68);
ctx.textAlign = "center";
ctx.fillStyle = "#7895a9";
ctx.font = "700 20px system-ui, sans-serif";
ctx.fillText("COMPARATOR OUTPUT", w / 2, 277);
comparatorTexture.needsUpdate = true;
}
function updateSystem() {
ambient = Number(ambientInput.value);
threshold = Number(thresholdInput.value);
lampOn = ambient < threshold;
ambientOutput.textContent = `${ambient} lx`;
thresholdOutput.textContent = `${threshold} lx`;
lampStateOutput.textContent = lampOn ? "ON" : "OFF";
lampStateOutput.style.color = lampOn ? palette.green : palette.coral;
const daylight = ambient / 90;
const nightSky = new THREE.Color("#162a45");
const daySky = new THREE.Color("#74c7e8");
skyMaterial.color.copy(nightSky).lerp(daySky, daylight);
skyMaterial.emissive.copy(skyMaterial.color);
skyMaterial.emissiveIntensity = 0.35 + daylight * 0.85;
sunlight.intensity = 0.65 + daylight * 1.6;
rayMaterial.opacity = 0.06 + daylight * 0.22;
comparatorLED.color.set(lampOn ? palette.green : palette.coral);
comparatorLED.emissive.set(lampOn ? palette.green : palette.coral);
switchLEDMaterial.color.set(lampOn ? palette.green : palette.coral);
switchLEDMaterial.emissive.set(lampOn ? palette.green : palette.coral);
drawComparator();
}
ambientInput.addEventListener("input", updateSystem);
thresholdInput.addEventListener("input", updateSystem);
updateSystem();
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
function updateCamera(delta) {
const smoothing = 1 - Math.pow(0.001, delta);
controls.azimuth +=
(controls.targetAzimuth - controls.azimuth) * smoothing;
controls.polar +=
(controls.targetPolar - controls.polar) * smoothing;
controls.zoom +=
(controls.targetZoom - controls.zoom) * smoothing;
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x +
controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.cos(controls.polar),
controls.target.z +
controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.targetAzimuth -= dx * 0.006;
controls.targetPolar = THREE.MathUtils.clamp(
controls.targetPolar - dy * 0.0045,
0.58,
1.28
);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined) {
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();
controls.targetZoom = THREE.MathUtils.clamp(
controls.targetZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.55
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.targetAzimuth = 0.58;
controls.targetPolar = 0.98;
controls.targetZoom = 1;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
const verticalSize = Math.max(18.5, 29 / aspect);
camera.left = (-verticalSize * aspect) / 2;
camera.right = (verticalSize * aspect) / 2;
camera.top = verticalSize / 2;
camera.bottom = -verticalSize / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera(1);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateCamera(delta);
for (const packet of packets) {
const t = (elapsed * packet.speed) % 1;
packet.mesh.position.x = THREE.MathUtils.lerp(
packet.startX,
packet.endX,
t
);
const active =
packet.kind === "sense" ||
(packet.kind === "decision" && lampOn) ||
(packet.kind === "actuation" && lampOn);
packet.mesh.visible = active;
const pulse = 0.75 + Math.sin(elapsed * 7 + t * Math.PI * 2) * 0.25;
packet.mesh.scale.setScalar(0.85 + pulse * 0.3);
}
const lampPulse = 0.92 + Math.sin(elapsed * 6.2) * 0.08;
bulbMaterial.emissiveIntensity = lampOn ? 2.4 + lampPulse : 0.05;
lampLight.intensity = lampOn ? 12 + lampPulse * 4 : 0;
comparatorLED.emissiveIntensity = lampOn
? 1.7 + Math.sin(elapsed * 5) * 0.35
: 0.7;
switchLEDMaterial.emissiveIntensity = lampOn
? 1.7 + Math.sin(elapsed * 5 + 1) * 0.35
: 0.7;
rayMaterial.emissiveIntensity = 0.55 + Math.sin(elapsed * 2) * 0.18;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```