Prompt specification
Build or customize the Three.js 3D scene "Small recording desk wiring" 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: Small recording desk wiring
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-recording-desk-wiring-x0175
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Compose a desk with speakers, screen, microphone, and labeled cable ports; selecting a device highlights its uninterrupted route beneath the worktop to the appropriate connection.
Working Three.js Starter (small-recording-desk-wiring-x0175):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Signal Desk</title>
<style>
:root {
color-scheme: dark;
--bg: #0b0f14;
--panel: rgba(16, 22, 29, 0.9);
--border: rgba(255, 255, 255, 0.12);
--text: #eef5f8;
--muted: #8fa1ad;
--screen: #57e6ff;
--speakers: #ffb347;
--microphone: #ff5fa2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: "Courier New", Courier, monospace;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.brand strong {
display: block;
margin-bottom: 7px;
font-size: 18px;
color: #ffffff;
}
.brand span {
color: var(--muted);
font-size: 10px;
}
.brand::before {
content: "";
display: inline-block;
width: 9px;
height: 9px;
margin-right: 10px;
background: var(--screen);
box-shadow: 0 0 18px var(--screen);
}
.selector {
position: absolute;
top: 24px;
right: 24px;
width: 310px;
padding: 18px;
border: 1px solid var(--border);
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
pointer-events: auto;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0 0 16px;
font-size: 17px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.device-list {
display: grid;
gap: 8px;
}
.device-button {
--accent: #ffffff;
display: grid;
grid-template-columns: 28px 1fr 12px;
align-items: center;
gap: 10px;
width: 100%;
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.09);
background: rgba(255, 255, 255, 0.025);
color: #aab8c1;
font: inherit;
font-size: 12px;
letter-spacing: 0.08em;
text-align: left;
text-transform: uppercase;
cursor: pointer;
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.device-button:hover {
color: #ffffff;
border-color: rgba(255, 255, 255, 0.24);
transform: translateX(-2px);
}
.device-button.active {
color: #ffffff;
border-color: var(--accent);
background: color-mix(in srgb, var(--accent) 10%, transparent);
box-shadow: inset 3px 0 0 var(--accent);
}
.device-number {
color: var(--muted);
font-size: 10px;
}
.device-dot {
width: 7px;
height: 7px;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
.route-card {
margin-top: 16px;
padding: 14px;
border: 1px solid rgba(255, 255, 255, 0.09);
background: rgba(0, 0, 0, 0.18);
}
#route-title {
margin-bottom: 7px;
font-size: 12px;
letter-spacing: 0.08em;
}
#route-subtitle {
min-height: 28px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.route-meter {
height: 3px;
margin: 13px 0 10px;
overflow: hidden;
background: rgba(255, 255, 255, 0.08);
}
.route-meter span {
display: block;
width: 100%;
height: 100%;
background: var(--screen);
box-shadow: 0 0 12px var(--screen);
transition: background 180ms ease, box-shadow 180ms ease;
}
.route-foot {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
}
.route-foot b {
color: var(--screen);
}
.hint {
position: absolute;
left: 26px;
bottom: 23px;
color: var(--muted);
font-size: 10px;
line-height: 1.7;
letter-spacing: 0.07em;
}
.hint kbd {
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.18);
color: #dbe6eb;
background: rgba(255, 255, 255, 0.04);
font: inherit;
}
#tooltip {
position: fixed;
z-index: 5;
display: none;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.18);
background: rgba(10, 14, 19, 0.94);
color: #ffffff;
font-size: 10px;
letter-spacing: 0.09em;
pointer-events: none;
transform: translate(12px, 12px);
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
}
.brand strong {
font-size: 14px;
}
.selector {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 12px;
}
.selector h1 {
margin-bottom: 10px;
font-size: 13px;
}
.device-list {
grid-template-columns: repeat(3, 1fr);
}
.device-button {
grid-template-columns: 1fr;
gap: 5px;
padding: 9px;
font-size: 9px;
}
.device-number,
.device-dot {
display: none;
}
.route-card {
margin-top: 10px;
padding: 10px;
}
#route-subtitle,
.route-foot {
display: none;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel desk scene"></canvas>
<div class="hud">
<div class="brand">
<strong>Signal / Desk 04</strong>
<span>Interactive cable routing study</span>
</div>
<section class="selector" aria-label="Device selector">
<p class="eyebrow">Select a device</p>
<h1>Trace the signal path</h1>
<div class="device-list">
<button
class="device-button active"
data-device="screen"
style="--accent: var(--screen)"
aria-pressed="true"
>
<span class="device-number">01</span>
<span>Screen</span>
<span class="device-dot"></span>
</button>
<button
class="device-button"
data-device="speakers"
style="--accent: var(--speakers)"
aria-pressed="false"
>
<span class="device-number">02</span>
<span>Speakers</span>
<span class="device-dot"></span>
</button>
<button
class="device-button"
data-device="microphone"
style="--accent: var(--microphone)"
aria-pressed="false"
>
<span class="device-number">03</span>
<span>Microphone</span>
<span class="device-dot"></span>
</button>
</div>
<div class="route-card">
<div id="route-title">USB-C VIDEO ROUTE</div>
<div id="route-subtitle">
SCREEN → PORT 02 / DISPLAY<br />
Continuous path beneath the worktop
</div>
<div class="route-meter"><span id="route-meter-fill"></span></div>
<div class="route-foot">
<span>UNDER-WORKTOP PATH</span>
<b id="route-state">LOCKED</b>
</div>
</div>
</section>
<div class="hint">
DRAG TO ORBIT · SCROLL TO ZOOM<br />
<kbd>1</kbd> <kbd>2</kbd> <kbd>3</kbd> SELECT DEVICE ·
<kbd>R</kbd> RESET VIEW
</div>
</div>
<div id="tooltip"></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 canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b0f14);
scene.fog = new THREE.Fog(0x0b0f14, 15, 31);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
// -------------------------------------------------------------------------
// Lights
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb8d8ff, 0x3b271a, 1.85));
const keyLight = new THREE.DirectionalLight(0xffddb5, 3.2);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x57e6ff, 22, 12, 2);
cyanLight.position.set(-4.5, 4.8, 4.2);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff8759, 18, 10, 2);
warmLight.position.set(4, 3.2, 3.5);
scene.add(warmLight);
const focusLight = new THREE.PointLight(0x57e6ff, 8, 4.5, 2);
scene.add(focusLight);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.08,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 1,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true
});
}
function box(parent, size, position, color, options = {}) {
const material = color?.isMaterial
? color
: makeMaterial(color, options);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function labelPlane(text, accent, width = 1.55, height = 0.32) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 112;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 112);
context.fillStyle = "rgba(7, 12, 17, 0.94)";
context.fillRect(0, 0, 512, 112);
context.strokeStyle = accent;
context.lineWidth = 5;
context.strokeRect(3, 3, 506, 106);
context.fillStyle = accent;
context.fillRect(18, 21, 7, 70);
context.font = "700 31px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#eef7fb";
context.fillText(text, 264, 58, 445);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
})
);
return mesh;
}
// -------------------------------------------------------------------------
// Floor
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
makeMaterial(0x111820, {
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x354550, 0x26333c);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
// -------------------------------------------------------------------------
// Desk
// -------------------------------------------------------------------------
const desk = new THREE.Group();
scene.add(desk);
const wood = makeMaterial(0xc7a77c, {
roughness: 0.82,
metalness: 0.02
});
const darkWood = makeMaterial(0x694c38, {
roughness: 0.9,
metalness: 0.02
});
const charcoal = makeMaterial(0x1b2229, {
roughness: 0.58,
metalness: 0.22
});
const almostBlack = makeMaterial(0x090d12, {
roughness: 0.64,
metalness: 0.18
});
box(desk, [8.6, 0.3, 3.7], [0, 3.05, 0], wood);
box(desk, [8.66, 0.11, 3.76], [0, 2.87, 0], darkWood);
// Pixel trim along the front edge.
for (let i = 0; i < 20; i++) {
const x = -3.9 + i * 0.41;
const trimColor = i % 5 === 0 ? 0xd99a5b : 0x896548;
box(
desk,
[0.28, 0.07, 0.05],
[x, 3.035, 1.872],
trimColor,
{ castShadow: false }
);
}
// Four chunky voxel legs.
for (const x of [-3.65, 3.65]) {
for (const z of [-1.35, 1.35]) {
box(desk, [0.42, 2.78, 0.42], [x, 1.46, z], charcoal);
box(desk, [0.62, 0.14, 0.62], [x, 0.12, z], almostBlack);
}
}
box(desk, [7.7, 0.25, 0.28], [0, 0.42, -1.35], charcoal);
box(desk, [7.7, 0.25, 0.28], [0, 0.42, 1.35], charcoal);
box(desk, [0.28, 0.25, 2.45], [-3.65, 0.42, 0], charcoal);
box(desk, [0.28, 0.25, 2.45], [3.65, 0.42, 0], charcoal);
// Under-desk patch panel.
box(desk, [5.7, 0.68, 0.18], [0, 2.56, 1.9], almostBlack);
box(desk, [5.78, 0.08, 0.22], [0, 2.93, 1.9], charcoal);
// -------------------------------------------------------------------------
// Screen
// -------------------------------------------------------------------------
const screenGroup = new THREE.Group();
screenGroup.userData.focus = new THREE.Vector3(0, 4.6, -0.45);
scene.add(screenGroup);
box(screenGroup, [1.45, 0.13, 0.84], [0, 3.28, -0.58], charcoal);
box(screenGroup, [0.3, 0.94, 0.3], [0, 3.76, -0.65], charcoal);
box(screenGroup, [2.85, 1.75, 0.28], [0, 4.77, -0.62], almostBlack);
const displayMaterial = makeMaterial(0x102b38, {
roughness: 0.28,
metalness: 0.15,
emissive: 0x0c4353,
emissiveIntensity: 0.75
});
box(
screenGroup,
[2.58, 1.48, 0.055],
[0, 4.77, -0.455],
displayMaterial,
{ castShadow: false }
);
// Pixel dashboard on the display.
const screenPixels = [
[-1.04, 5.18, 0.48, 0.09, 0x57e6ff],
[-1.04, 4.98, 0.78, 0.09, 0x27788d],
[-1.04, 4.82, 0.54, 0.07, 0x27788d],
[-0.22, 5.18, 0.54, 0.09, 0xffb347],
[-0.22, 4.99, 0.31, 0.07, 0x775738],
[0.62, 5.08, 0.35, 0.29, 0xff5fa2],
[0.02, 4.56, 0.78, 0.06, 0x57e6ff],
[0.02, 4.41, 0.48, 0.06, 0x27788d]
];
for (const [x, y, w, h, color] of screenPixels) {
box(
screenGroup,
[w, h, 0.025],
[x, y, -0.416],
makeMaterial(color, {
emissive: color,
emissiveIntensity: 1.35,
roughness: 0.4
}),
{ castShadow: false }
);
}
// -------------------------------------------------------------------------
// Speakers
// -------------------------------------------------------------------------
const speakerGroup = new THREE.Group();
speakerGroup.userData.focus = new THREE.Vector3(-2.45, 4.05, -0.25);
scene.add(speakerGroup);
const cabinetMaterial = makeMaterial(0xa95543, {
roughness: 0.66,
metalness: 0.08
});
const coneMaterial = makeMaterial(0x20262b, {
roughness: 0.88,
metalness: 0.04
});
const speakerTrim = makeMaterial(0xe08a67, {
roughness: 0.5,
metalness: 0.12
});
function makeSpeaker(x) {
const speaker = new THREE.Group();
speaker.position.set(x, 0, -0.35);
speakerGroup.add(speaker);
box(speaker, [0.8, 1.48, 0.7], [0, 3.95, 0], cabinetMaterial);
box(speaker, [0.87, 0.09, 0.76], [0, 3.25, 0], almostBlack);
box(speaker, [0.58, 0.58, 0.055], [0, 3.76, 0.375], speakerTrim);
box(speaker, [0.46, 0.46, 0.065], [0, 3.76, 0.413], coneMaterial);
box(speaker, [0.19, 0.19, 0.075], [0, 3.76, 0.45], almostBlack);
box(speaker, [0.34, 0.3, 0.055], [0, 4.37, 0.375], almostBlack);
box(speaker, [0.23, 0.19, 0.065], [0, 4.37, 0.412], speakerTrim);
box(speaker, [0.08, 0.08, 0.025], [0.24, 3.37, 0.39], 0xffb347, {
emissive: 0xff8c2b,
emissiveIntensity: 1.1,
castShadow: false
});
}
makeSpeaker(-3.05);
makeSpeaker(-1.95);
// -------------------------------------------------------------------------
// Microphone
// -------------------------------------------------------------------------
const microphoneGroup = new THREE.Group();
microphoneGroup.position.set(2.35, 0, 0.62);
microphoneGroup.userData.focus = new THREE.Vector3(2.35, 4.35, 1.12);
scene.add(microphoneGroup);
const micMetal = makeMaterial(0xcbd4d9, {
roughness: 0.38,
metalness: 0.62
});
const micDark = makeMaterial(0x161c22, {
roughness: 0.7,
metalness: 0.32
});
box(microphoneGroup, [0.92, 0.13, 0.78], [0, 3.28, 0], micDark);
box(microphoneGroup, [0.18, 1.22, 0.18], [0, 3.91, 0], micMetal);
box(microphoneGroup, [0.18, 0.18, 0.83], [0, 4.48, 0.36], micMetal);
box(microphoneGroup, [0.48, 0.48, 0.48], [0, 4.46, 0.82], micDark);
for (let i = 0; i < 4; i++) {
box(
microphoneGroup,
[0.5, 0.025, 0.5],
[0, 4.31 + i * 0.1, 0.82],
0x5c6870,
{ castShadow: false }
);
}
box(
microphoneGroup,
[0.1, 0.1, 0.06],
[0, 4.47, 1.075],
makeMaterial(0xff5fa2, {
emissive: 0xff5fa2,
emissiveIntensity: 1.8
}),
{ castShadow: false }
);
// -------------------------------------------------------------------------
// Keyboard and mouse
// -------------------------------------------------------------------------
const accessories = new THREE.Group();
scene.add(accessories);
box(accessories, [3.12, 0.025, 1.03], [0, 3.21, 0.72], 0x202a31);
box(accessories, [2.78, 0.12, 0.72], [0, 3.28, 0.72], almostBlack);
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 10; column++) {
const accent = (row === 0 && column === 9) || (row === 2 && column === 0);
box(
accessories,
[0.19, 0.075, 0.16],
[-1.12 + column * 0.25, 3.37, 0.5 + row * 0.22],
accent ? 0x57e6ff : 0x3b4851,
{
emissive: accent ? 0x57e6ff : 0x000000,
emissiveIntensity: accent ? 0.9 : 0,
castShadow: false
}
);
}
}
box(accessories, [0.43, 0.14, 0.57], [1.65, 3.32, 0.73], 0x313b43);
box(accessories, [0.035, 0.02, 0.19], [1.65, 3.405, 0.54], 0xff5fa2, {
emissive: 0xff5fa2,
emissiveIntensity: 0.65,
castShadow: false
});
// -------------------------------------------------------------------------
// Cable grommets
// -------------------------------------------------------------------------
const grommetPositions = [
[0, -0.55],
[-3.05, -0.35],
[-1.95, -0.35],
[2.35, 0.62]
];
for (const [x, z] of grommetPositions) {
box(accessories, [0.31, 0.045, 0.31], [x, 3.225, z], 0x10161c);
}
// -------------------------------------------------------------------------
// Labeled ports
// -------------------------------------------------------------------------
const portDefs = {
speakers: {
x: -1.72,
label: "LINE OUT / L-R",
accent: "#ffb347"
},
screen: {
x: 0,
label: "USB-C / VIDEO",
accent: "#57e6ff"
},
microphone: {
x: 1.72,
label: "USB / MIC IN",
accent: "#ff5fa2"
}
};
for (const [id, port] of Object.entries(portDefs)) {
const outer = box(
desk,
[0.48, 0.3, 0.16],
[port.x, 2.55, 2.01],
0x080c10
);
const innerMaterial = makeMaterial(0x26343d, {
roughness: 0.45,
metalness: 0.48,
emissive: 0x000000,
emissiveIntensity: 0.1
});
const inner = box(
desk,
[0.22, 0.11, 0.055],
[port.x, 2.55, 2.105],
innerMaterial,
{ castShadow: false }
);
const label = labelPlane(port.label, port.accent);
label.position.set(port.x, 2.79, 2.006);
desk.add(label);
port.outer = outer;
port.inner = inner;
port.innerMaterial = innerMaterial;
}
// -------------------------------------------------------------------------
// Under-desk route builder
// -------------------------------------------------------------------------
function createRoute(points, color) {
const group = new THREE.Group();
const glowGroup = new THREE.Group();
group.add(glowGroup);
scene.add(group);
const coreMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.25,
roughness: 0.4,
metalness: 0.12,
transparent: true,
opacity: 0.14,
depthWrite: false
});
const glowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.14,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const cumulative = [0];
let totalLength = 0;
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const delta = [
Math.abs(b[0] - a[0]),
Math.abs(b[1] - a[1]),
Math.abs(b[2] - a[2])
];
const length = delta[0] + delta[1] + delta[2];
totalLength += length;
cumulative.push(totalLength);
const center = [
(a[0] + b[0]) / 2,
(a[1] + b[1]) / 2,
(a[2] + b[2]) / 2
];
const coreSize = [0.09, 0.09, 0.09];
const glowSize = [0.23, 0.23, 0.23];
if (delta[0] > 0) {
coreSize[0] = delta[0] + 0.1;
glowSize[0] = delta[0] + 0.18;
} else if (delta[1] > 0) {
coreSize[1] = delta[1] + 0.1;
glowSize[1] = delta[1] + 0.18;
} else {
coreSize[2] = delta[2] + 0.1;
glowSize[2] = delta[2] + 0.18;
}
box(group, coreSize, center, coreMaterial, {
castShadow: false,
receiveShadow: false
});
box(glowGroup, glowSize, center, glowMaterial, {
castShadow: false,
receiveShadow: false
});
}
// Corner blocks overlap the segments, keeping every route continuous.
for (let i = 1; i < points.length - 1; i++) {
box(
group,
[0.13, 0.13, 0.13],
points[i],
coreMaterial,
{ castShadow: false, receiveShadow: false }
);
}
const pulseGeometry = new THREE.BoxGeometry(0.13, 0.13, 0.13);
const pulseColor = new THREE.Color(color).lerp(new THREE.Color(0xffffff), 0.55);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: pulseColor,
transparent: true,
opacity: 0.95,
depthWrite: false,
toneMapped: false
});
const pulses = [];
for (let i = 0; i < 3; i++) {
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
pulse.visible = false;
pulse.renderOrder = 6;
group.add(pulse);
pulses.push(pulse);
}
function sample(distance) {
const d = ((distance % totalLength) + totalLength) % totalLength;
for (let i = 0; i < points.length - 1; i++) {
if (d <= cumulative[i + 1]) {
const segmentLength = cumulative[i + 1] - cumulative[i];
const t = segmentLength === 0
? 0
: (d - cumulative[i]) / segmentLength;
const a = points[i];
const b = points[i + 1];
return new THREE.Vector3(
THREE.MathUtils.lerp(a[0], b[0], t),
THREE.MathUtils.lerp(a[1], b[1], t),
THREE.MathUtils.lerp(a[2], b[2], t)
);
}
}
return new THREE.Vector3(...points[points.length - 1]);
}
return {
group,
glowGroup,
coreMaterial,
glowMaterial,
pulses,
sample,
totalLength,
color
};
}
const routes = {
screen: [
createRoute([
[0, 3.18, -0.55],
[0, 2.58, -0.55],
[0, 2.58, 2.06]
], 0x57e6ff)
],
speakers: [
createRoute([
[-3.05, 3.18, -0.35],
[-3.05, 2.58, -0.35],
[-3.05, 2.58, 1.28],
[-1.72, 2.58, 1.28],
[-1.72, 2.58, 2.06]
], 0xffb347),
createRoute([
[-1.95, 3.18, -0.35],
[-1.95, 2.58, -0.35],
[-1.95, 2.58, 1.12],
[-1.72, 2.58, 1.12],
[-1.72, 2.58, 2.06]
], 0xffb347)
],
microphone: [
createRoute([
[2.35, 3.18, 0.62],
[2.35, 2.58, 0.62],
[2.35, 2.58, 1.28],
[1.72, 2.58, 1.28],
[1.72, 2.58, 2.06]
], 0xff5fa2)
]
};
// -------------------------------------------------------------------------
// Device definitions and selection visuals
// -------------------------------------------------------------------------
const devices = {
screen: {
group: screenGroup,
color: 0x57e6ff,
css: "#57e6ff",
title: "USB-C VIDEO ROUTE",
subtitle: "SCREEN → PORT 02 / USB-C VIDEO<br>Continuous path beneath the worktop"
},
speakers: {
group: speakerGroup,
color: 0xffb347,
css: "#ffb347",
title: "STEREO LINE ROUTE",
subtitle: "SPEAKERS → PORT 01 / LINE OUT L-R<br>Dual continuous routes converge at the output"
},
microphone: {
group: microphoneGroup,
color: 0xff5fa2,
css: "#ff5fa2",
title: "USB AUDIO ROUTE",
subtitle: "MICROPHONE → PORT 03 / USB MIC IN<br>Continuous path beneath the worktop"
}
};
const selectionBox = new THREE.Box3Helper(new THREE.Box3(), 0x57e6ff);
selectionBox.material.transparent = true;
selectionBox.material.opacity = 0.9;
selectionBox.material.depthTest = false;
selectionBox.material.toneMapped = false;
selectionBox.renderOrder = 10;
scene.add(selectionBox);
const pickables = [];
for (const [id, device] of Object.entries(devices)) {
device.group.traverse((object) => {
if (object.isMesh) {
object.userData.deviceId = id;
pickables.push(object);
}
});
}
const buttons = [...document.querySelectorAll("[data-device]")];
const routeTitle = document.querySelector("#route-title");
const routeSubtitle = document.querySelector("#route-subtitle");
const routeMeterFill = document.querySelector("#route-meter-fill");
const routeState = document.querySelector("#route-state");
let selectedDevice = "screen";
function selectDevice(id) {
selectedDevice = id;
const device = devices[id];
for (const button of buttons) {
const active = button.dataset.device === id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
routeTitle.textContent = device.title;
routeSubtitle.innerHTML = device.subtitle;
routeMeterFill.style.background = device.css;
routeMeterFill.style.boxShadow = `0 0 12px ${device.css}`;
routeState.style.color = device.css;
for (const [routeId, routeList] of Object.entries(routes)) {
const active = routeId === id;
for (const route of routeList) {
route.coreMaterial.color.setHex(device.color);
route.coreMaterial.emissive.setHex(device.color);
route.coreMaterial.opacity = active ? 0.98 : 0.12;
route.coreMaterial.emissiveIntensity = active ? 2.15 : 0.12;
route.glowGroup.visible = active;
route.glowMaterial.color.setHex(device.color);
route.glowMaterial.opacity = active ? 0.15 : 0;
for (const pulse of route.pulses) {
pulse.visible = active;
}
}
}
for (const [portId, port] of Object.entries(portDefs)) {
const active = portId === id;
port.innerMaterial.color.setHex(active ? device.color : 0x26343d);
port.innerMaterial.emissive.setHex(active ? device.color : 0x000000);
port.innerMaterial.emissiveIntensity = active ? 2.3 : 0.1;
}
device.group.updateMatrixWorld(true);
selectionBox.box.setFromObject(device.group);
selectionBox.material.color.setHex(device.color);
selectionBox.updateMatrixWorld(true);
focusLight.color.setHex(device.color);
focusLight.position.copy(device.group.userData.focus);
}
for (const button of buttons) {
button.addEventListener("click", () => {
selectDevice(button.dataset.device);
});
}
selectDevice(selectedDevice);
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 2.55, 0),
radius: 13.2,
theta: 0.58,
phi: 1.4
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.radius = 13.2;
orbit.theta = 0.58;
orbit.phi = 1.4;
applyCamera();
}
applyCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const tooltip = document.querySelector("#tooltip");
let pointerDown = false;
let lastX = 0;
let lastY = 0;
let travel = 0;
function pickAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.deviceId : null;
}
function updateTooltip(event) {
const id = pickAt(event.clientX, event.clientY);
if (!id) {
tooltip.style.display = "none";
canvas.style.cursor = "grab";
return;
}
tooltip.style.display = "block";
tooltip.style.left = `${event.clientX}px`;
tooltip.style.top = `${event.clientY}px`;
tooltip.textContent = `SELECT ${devices[id].group === screenGroup
? "SCREEN"
: devices[id].group === speakerGroup
? "SPEAKERS"
: "MICROPHONE"}`;
canvas.style.cursor = "pointer";
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
pointerDown = true;
travel = 0;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) {
updateTooltip(event);
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.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.42,
1.53
);
applyCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && travel < 6) {
const id = pickAt(event.clientX, event.clientY);
if (id) selectDevice(id);
}
pointerDown = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointerleave", () => {
if (!pointerDown) {
tooltip.style.display = "none";
}
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.009,
8.5,
18
);
applyCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "1") selectDevice("screen");
if (event.key === "2") selectDevice("speakers");
if (event.key === "3") selectDevice("microphone");
if (event.key.toLowerCase() === "r") resetCamera();
});
// -------------------------------------------------------------------------
// Ambient voxel dust
// -------------------------------------------------------------------------
const dustGeometry = new THREE.BoxGeometry(0.055, 0.055, 0.055);
const dustMaterial = new THREE.MeshBasicMaterial({
color: 0x86a6b4,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const dust = new THREE.InstancedMesh(dustGeometry, dustMaterial, 30);
dust.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(dust);
const dustData = [];
for (let i = 0; i < 30; i++) {
dustData.push({
x: (Math.random() - 0.5) * 15,
y: 0.7 + Math.random() * 7,
z: (Math.random() - 0.5) * 12,
phase: Math.random() * Math.PI * 2,
speed: 0.18 + Math.random() * 0.22
});
}
const dustDummy = new THREE.Object3D();
function updateDust(elapsed) {
dustData.forEach((particle, index) => {
dustDummy.position.set(
particle.x + Math.sin(elapsed * particle.speed + particle.phase) * 0.12,
particle.y + Math.sin(elapsed * particle.speed * 0.7 + particle.phase) * 0.18,
particle.z
);
dustDummy.rotation.set(
elapsed * 0.15 + particle.phase,
elapsed * 0.2,
0
);
dustDummy.updateMatrix();
dust.setMatrixAt(index, dustDummy.matrix);
});
dust.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
const elapsed = clock.getElapsedTime();
for (const [id, routeList] of Object.entries(routes)) {
const active = id === selectedDevice;
for (const route of routeList) {
route.glowMaterial.opacity = active
? 0.11 + Math.sin(elapsed * 4.2) * 0.035
: 0;
route.pulses.forEach((pulse, index) => {
if (!active) return;
const distance =
elapsed * 1.65 +
index * route.totalLength / route.pulses.length;
pulse.position.copy(route.sample(distance));
pulse.rotation.set(
elapsed * 2.4,
elapsed * 3.1,
elapsed * 1.8
);
});
}
}
focusLight.intensity = 7 + Math.sin(elapsed * 3.4) * 1.3;
updateDust(elapsed);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```