Prompt specification
Build or customize the Three.js 3D scene "Community Kit Assembly Bench" 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: Community Kit Assembly Bench
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-kit-assembly-bench-x2027
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring keyed connectors for unambiguous assembly. Build an original assembly kit whose tabs, colors, and shapes provide redundant guidance. Show correct sequence and common mismatches using actual part geometry. Voxel style.
Working Three.js Starter (community-kit-assembly-bench-x2027):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KEYLOOM — Voxel Assembly Kit</title>
<style>
:root {
color-scheme: dark;
--bg: #071019;
--panel: rgba(10, 20, 29, 0.88);
--panel-border: rgba(160, 220, 255, 0.16);
--text: #e8f6ff;
--muted: #87a0af;
--cross: #b9f45d;
--corner: #3dd5ff;
--diamond: #ff5faf;
--good: #63f5b0;
--bad: #ff526d;
--warn: #ffc857;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.part-label {
position: absolute;
min-width: 126px;
padding: 8px 10px 8px 12px;
transform: translate(10px, -50%);
border: 1px solid color-mix(in srgb, var(--accent) 44%, transparent);
border-left: 3px solid var(--accent);
border-radius: 7px;
background: rgba(5, 13, 20, 0.82);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(10px);
transition: opacity 180ms ease;
}
.part-label strong {
display: block;
color: var(--accent);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.part-label span {
display: block;
margin-top: 3px;
color: #d7e7ef;
font: 600 10px/1.25 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
}
header {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
color: var(--cross);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.22em;
}
h1 {
margin: 7px 0 3px;
font-size: clamp(25px, 3vw, 42px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 850;
}
header p {
margin: 8px 0 0;
color: var(--muted);
font: 500 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.035em;
}
.live {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 8px;
border: 1px solid rgba(105, 245, 176, 0.25);
border-radius: 4px;
color: #9dffc9;
background: rgba(34, 109, 75, 0.11);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 1px;
background: var(--good);
box-shadow: 0 0 12px var(--good);
}
.panel {
position: fixed;
z-index: 4;
border: 1px solid var(--panel-border);
border-radius: 11px;
background: var(--panel);
box-shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(15px);
}
#build-panel {
top: 142px;
left: 24px;
width: 258px;
padding: 13px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #adc2ce;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
}
.panel-title b {
color: #526b79;
font-weight: 600;
}
#steps {
display: grid;
gap: 7px;
}
.step {
width: 100%;
display: grid;
grid-template-columns: 32px 1fr 42px;
align-items: center;
gap: 9px;
padding: 9px;
text-align: left;
color: #d9e7ed;
border: 1px solid rgba(150, 210, 240, 0.11);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 160ms ease;
}
.step:hover {
border-color: rgba(150, 210, 240, 0.3);
transform: translateX(2px);
background: rgba(255, 255, 255, 0.055);
}
.step.active {
border-color: color-mix(in srgb, var(--accent) 60%, transparent);
background: color-mix(in srgb, var(--accent) 9%, transparent);
}
.step-no {
display: grid;
place-items: center;
height: 28px;
border-radius: 5px;
color: var(--accent);
background: color-mix(in srgb, var(--accent) 11%, transparent);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.step-copy strong {
display: block;
font: 750 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
}
.step-copy small {
display: block;
margin-top: 4px;
color: #748c9a;
font: 500 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mini-key {
display: grid;
grid-template-columns: repeat(7, 3px);
grid-template-rows: repeat(7, 3px);
gap: 1px;
justify-content: center;
padding: 4px;
border-radius: 4px;
background: rgba(0, 0, 0, 0.24);
}
.mini-key i {
display: block;
width: 3px;
height: 3px;
border-radius: 1px;
background: transparent;
}
.mini-key i.on {
background: var(--accent);
box-shadow: 0 0 4px color-mix(in srgb, var(--accent) 65%, transparent);
}
#legend-panel {
top: 24px;
right: 24px;
width: 232px;
padding: 13px;
}
.legend-row {
display: grid;
grid-template-columns: 48px 1fr;
align-items: center;
gap: 10px;
padding: 8px 0;
border-top: 1px solid rgba(150, 210, 240, 0.08);
}
.legend-row:first-of-type { border-top: 0; }
.legend-row strong {
display: block;
color: var(--accent);
font: 750 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.legend-row small {
display: block;
margin-top: 3px;
color: #748c9a;
font: 500 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.key-icon {
display: grid;
grid-template-columns: repeat(7, 4px);
grid-template-rows: repeat(7, 4px);
gap: 1px;
justify-content: center;
align-content: center;
width: 44px;
height: 44px;
border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
border-radius: 6px;
background: color-mix(in srgb, var(--accent) 6%, rgba(0, 0, 0, 0.25));
}
.key-icon i {
width: 4px;
height: 4px;
border-radius: 1px;
background: transparent;
}
.key-icon i.on {
background: var(--accent);
box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 70%, transparent);
}
#mismatch-panel {
top: 204px;
right: 24px;
width: 232px;
padding: 13px;
display: none;
}
#mismatch-panel.show { display: block; }
.mismatch-button {
width: 100%;
margin-top: 6px;
padding: 8px 9px;
text-align: left;
color: #cbdce4;
border: 1px solid rgba(255, 120, 140, 0.14);
border-radius: 6px;
background: rgba(255, 80, 100, 0.035);
cursor: pointer;
font: 650 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.03em;
}
.mismatch-button:hover,
.mismatch-button.active {
color: #fff;
border-color: rgba(255, 82, 109, 0.55);
background: rgba(255, 82, 109, 0.12);
}
#notice {
position: fixed;
z-index: 6;
top: 25px;
left: 50%;
width: min(440px, calc(100vw - 580px));
min-width: 300px;
transform: translateX(-50%);
padding: 12px 15px;
border: 1px solid rgba(130, 210, 255, 0.2);
border-radius: 9px;
background: rgba(7, 16, 25, 0.9);
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(14px);
pointer-events: none;
transition: 180ms ease;
}
#notice::before {
content: "";
position: absolute;
top: 10px;
bottom: 10px;
left: 0;
width: 3px;
border-radius: 3px;
background: #70cfff;
}
#notice.good::before { background: var(--good); }
#notice.bad::before { background: var(--bad); }
#notice.warn::before { background: var(--warn); }
#notice-title {
color: #eaf8ff;
font: 800 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
}
#notice-copy {
margin-top: 5px;
color: #829aa7;
font: 500 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#controls {
position: fixed;
z-index: 7;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
gap: 6px;
padding: 7px;
border: 1px solid var(--panel-border);
border-radius: 10px;
background: rgba(7, 16, 25, 0.9);
box-shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(15px);
}
.control {
padding: 10px 13px;
color: #a9bfca;
border: 1px solid transparent;
border-radius: 6px;
background: transparent;
cursor: pointer;
white-space: nowrap;
font: 750 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
transition: 150ms ease;
}
.control:hover {
color: #fff;
background: rgba(255, 255, 255, 0.06);
}
.control.primary {
color: #07130f;
background: var(--cross);
}
.control.primary:hover { background: #d0ff84; }
.control.lab.active {
color: #ffd7dd;
border-color: rgba(255, 82, 109, 0.35);
background: rgba(255, 82, 109, 0.1);
}
#hint {
position: fixed;
z-index: 4;
right: 25px;
bottom: 27px;
color: #5f7886;
font: 500 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
pointer-events: none;
text-align: right;
}
#progress {
position: fixed;
z-index: 8;
left: 0;
bottom: 0;
width: 0;
height: 3px;
background: var(--cross);
box-shadow: 0 0 12px var(--cross);
transition: width 300ms ease, background 200ms ease;
}
@media (max-width: 900px) {
#legend-panel { top: auto; bottom: 85px; right: 15px; width: 195px; }
#mismatch-panel { top: auto; bottom: 85px; right: 15px; }
#notice {
top: 108px;
width: min(420px, calc(100vw - 30px));
min-width: 0;
}
#build-panel { top: 125px; left: 15px; width: 220px; }
header { left: 16px; top: 17px; }
#hint { display: none; }
}
@media (max-width: 620px) {
#build-panel { display: none; }
#legend-panel { display: none; }
#mismatch-panel { top: 115px; bottom: auto; width: 220px; }
#notice { top: 80px; width: calc(100vw - 24px); }
#controls { bottom: 12px; width: calc(100vw - 20px); overflow-x: auto; }
.control { padding: 9px 10px; }
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div id="labels"></div>
<header>
<div class="eyebrow">ORIGINAL VOXEL ASSEMBLY SYSTEM</div>
<h1>KEYLOOM / 04</h1>
<p>Shape lock + paint code + sequence lock.</p>
<div class="live">LIVE PART GEOMETRY</div>
</header>
<aside id="build-panel" class="panel">
<div class="panel-title"><span>BUILD ORDER</span><b>4 MODULES</b></div>
<div id="steps"></div>
</aside>
<aside id="legend-panel" class="panel">
<div class="panel-title"><span>CONNECTOR KEY</span><b>1:1 PROFILE</b></div>
<div id="legend"></div>
</aside>
<aside id="mismatch-panel" class="panel">
<div class="panel-title"><span>MISMATCH LAB</span><b>REJECT TEST</b></div>
<button class="mismatch-button" data-mismatch="0">01 · CORNER → CROSS</button>
<button class="mismatch-button" data-mismatch="1">02 · CROSS → DIAMOND</button>
<button class="mismatch-button" data-mismatch="2">03 · CORNER ROTATED 90°</button>
<button class="mismatch-button" data-mismatch="3">04 · CORRECT SHAPE / WRONG COLOR</button>
</aside>
<div id="notice">
<div id="notice-title">EXPLODED VIEW</div>
<div id="notice-copy">Three keyed interfaces are exposed. Select a build step or play the correct sequence.</div>
</div>
<nav id="controls">
<button id="btn-exploded" class="control">EXPLODED</button>
<button id="btn-play" class="control primary">PLAY SEQUENCE</button>
<button id="btn-complete" class="control">COMPLETE BUILD</button>
<button id="btn-lab" class="control lab">MISMATCH LAB</button>
</nav>
<div id="hint">DRAG TO ORBIT · WHEEL TO ZOOM<br>SPACE: PLAY · R: RESET</div>
<div id="progress"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
KEYLOOM connector definitions
Every key is a real plan-view voxel profile. A matching male tab can enter
the matching open well; every other profile physically overlaps the rim.
--------------------------------------------------------------------------- */
const CELL = 0.42;
const KEY_COLORS = {
cross: 0xb9f45d,
corner: 0x3dd5ff,
diamond: 0xff5faf
};
const KEY_CSS = {
cross: "#b9f45d",
corner: "#3dd5ff",
diamond: "#ff5faf"
};
const KEY_DEFS = {
cross: {
name: "CROSS",
cells: [[0,0], [-1,0], [1,0], [0,-1], [0,1]]
},
corner: {
name: "CORNER",
cells: [[-1,-1], [0,-1], [0,0]]
},
diamond: {
name: "DIAMOND",
cells: [[0,0], [-1,-1], [1,-1], [-1,1], [1,1]]
}
};
const $ = selector => document.querySelector(selector);
const canvas = $("#scene");
const labelLayer = $("#labels");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.FogExp2(0x071019, 0.026);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);
/* Camera controls, implemented directly without add-ons. */
const controls = {
yaw: 0.62,
phi: 1.08,
radius: 13.8,
targetY: 4.0,
desiredYaw: 0.62,
desiredPhi: 1.08,
desiredRadius: 13.8,
desiredTargetY: 4.0,
dragging: false,
lastX: 0,
lastY: 0
};
canvas.addEventListener("pointerdown", event => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.desiredYaw -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(controls.desiredPhi - dy * 0.005, 0.42, 1.48);
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture?.(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius + event.deltaY * 0.009,
7.2,
19
);
}, { passive: false });
/* Lighting and studio. */
scene.add(new THREE.HemisphereLight(0x9ddcff, 0x111823, 1.8));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x36caff, 20, 12, 2);
cyanLight.position.set(-5, 3.2, 3);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff4f9c, 16, 10, 2);
pinkLight.position.set(4, 5.5, -3);
scene.add(pinkLight);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(6.4, 0.24, 6.4),
new THREE.MeshStandardMaterial({ color: 0x111c26, roughness: 0.82, metalness: 0.22 })
);
platform.position.y = -0.13;
platform.receiveShadow = true;
scene.add(platform);
const platformInset = new THREE.Mesh(
new THREE.BoxGeometry(5.8, 0.025, 5.8),
new THREE.MeshStandardMaterial({
color: 0x173242,
emissive: 0x0c2634,
emissiveIntensity: 0.45,
roughness: 0.72,
metalness: 0.18
})
);
platformInset.position.y = 0.005;
platformInset.receiveShadow = true;
scene.add(platformInset);
const grid = new THREE.GridHelper(18, 36, 0x315463, 0x18303e);
grid.position.y = 0.02;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
/* Small voxel corner beacons around the platform. */
for (const [x, z, color] of [
[-2.75, -2.75, 0x36caff],
[2.75, -2.75, 0xff5faf],
[-2.75, 2.75, 0xb9f45d],
[2.75, 2.75, 0x36caff]
]) {
const beacon = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.18, 0.18),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.6,
roughness: 0.4
})
);
beacon.position.set(x, 0.12, z);
scene.add(beacon);
}
/* --------------------------------------------------------------------------
Geometry builders
--------------------------------------------------------------------------- */
function voxelColor(hex, variation) {
return new THREE.Color(hex).offsetHSL(0, 0, variation);
}
function createVoxelBody(group, baseColor, layers, style = "standard") {
const cells = [];
for (let layer = 0; layer < layers; layer++) {
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
const corner = Math.abs(x) === 3 && Math.abs(z) === 3;
if (style === "standard" && corner) continue;
if (style === "pulse" && layer === 1 && Math.abs(x) === 3) continue;
if (style === "crown" && layer === 0 && corner) continue;
cells.push({ x, z, layer });
}
}
}
const geometry = new THREE.BoxGeometry(CELL * 0.91, CELL * 0.91, CELL * 0.91);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.67,
metalness: 0.11
});
const mesh = new THREE.InstancedMesh(geometry, material, cells.length);
mesh.castShadow = true;
mesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
cells.forEach((cell, index) => {
dummy.position.set(cell.x * CELL, cell.layer * CELL + CELL * 0.5, cell.z * CELL);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const variation = ((cell.x + cell.z + cell.layer) % 3 - 1) * 0.035
+ (cell.layer === layers - 1 ? 0.025 : 0);
color.copy(voxelColor(baseColor, variation));
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
group.add(mesh);
}
function createMaleKey(group, type) {
const color = KEY_COLORS[type];
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.22,
roughness: 0.4,
metalness: 0.22
});
const geometry = new THREE.BoxGeometry(CELL * 0.88, 0.36, CELL * 0.88);
for (const [x, z] of KEY_DEFS[type].cells) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x * CELL, -0.18, z * CELL);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
return material;
}
function createFemaleWell(group, type, bodyTop) {
const keyColor = KEY_COLORS[type];
const rimMaterial = new THREE.MeshStandardMaterial({
color: keyColor,
emissive: keyColor,
emissiveIntensity: 0.18,
roughness: 0.44,
metalness: 0.22
});
const floorColor = new THREE.Color(keyColor).multiplyScalar(0.19);
const floorMaterial = new THREE.MeshStandardMaterial({
color: floorColor,
emissive: keyColor,
emissiveIntensity: 0.05,
roughness: 0.75,
metalness: 0.1
});
const cavity = new Set(KEY_DEFS[type].cells.map(([x, z]) => `${x},${z}`));
const wall = new Set();
const adjacent = (x, z) => {
for (let dx = -1; dx <= 1; dx++) {
for (let dz = -1; dz <= 1; dz++) {
if (!dx && !dz) continue;
if (cavity.has(`${x + dx},${z + dz}`)) return true;
}
}
return false;
};
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
if (!cavity.has(`${x},${z}`) && adjacent(x, z)) {
wall.add(`${x},${z}`);
}
}
}
const floorGeometry = new THREE.BoxGeometry(CELL * 0.9, 0.06, CELL * 0.9);
for (const [x, z] of KEY_DEFS[type].cells) {
const floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.position.set(x * CELL, bodyTop + 0.03, z * CELL);
floor.receiveShadow = true;
group.add(floor);
}
const wallGeometry = new THREE.BoxGeometry(CELL * 0.91, 0.42, CELL * 0.91);
for (const position of wall) {
const [x, z] = position.split(",").map(Number);
const block = new THREE.Mesh(wallGeometry, rimMaterial);
block.position.set(x * CELL, bodyTop + 0.21, z * CELL);
block.castShadow = true;
block.receiveShadow = true;
group.add(block);
}
return rimMaterial;
}
function addProfileBadge(group, type, y, z, scale = 0.085) {
const color = KEY_COLORS[type];
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.7,
roughness: 0.36,
metalness: 0.12
});
const geometry = new THREE.BoxGeometry(scale, scale, scale * 0.45);
for (const [x, z] of KEY_DEFS[type].cells) {
const badge = new THREE.Mesh(geometry, material);
badge.position.set(x * scale, y, z * scale);
group.add(badge);
}
}
function addPartDetails(group, bodyTop, maleType, socketType, accent) {
const frontZ = 3 * CELL + 0.035;
const sideX = 3 * CELL + 0.035;
const lampMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 1.35,
roughness: 0.28
});
const lampGeometry = new THREE.BoxGeometry(0.12, 0.12, 0.045);
for (let i = -1; i <= 1; i++) {
const lamp = new THREE.Mesh(lampGeometry, lampMaterial);
lamp.position.set(i * 0.31 + 0.83, bodyTop - 0.24, frontZ);
group.add(lamp);
}
const sideMaterial = new THREE.MeshStandardMaterial({
color: 0x12212a,
roughness: 0.56,
metalness: 0.38
});
const ventGeometry = new THREE.BoxGeometry(0.045, 0.08, 0.5);
for (let i = -1; i <= 1; i++) {
const vent = new THREE.Mesh(ventGeometry, sideMaterial);
vent.position.set(sideX, bodyTop * 0.48, i * 0.35);
group.add(vent);
}
if (maleType) addProfileBadge(group, maleType, 0.22, frontZ + 0.005);
if (socketType) addProfileBadge(group, socketType, bodyTop - 0.22, frontZ + 0.005);
}
function makePart(config) {
const group = new THREE.Group();
const bodyTop = config.layers * CELL;
createVoxelBody(group, config.color, config.layers, config.style);
const maleMaterial = config.maleType ? createMaleKey(group, config.maleType) : null;
if (config.socketType) createFemaleWell(group, config.socketType, bodyTop);
addPartDetails(group, bodyTop, config.maleType, config.socketType, config.accent);
if (config.crown) {
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xf0eee2,
roughness: 0.62,
metalness: 0.08
});
const capGeometry = new THREE.BoxGeometry(0.27, 0.16, 0.27);
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
if (Math.abs(x) === 1 && Math.abs(z) === 1) continue;
const cap = new THREE.Mesh(capGeometry, capMaterial);
cap.position.set(x * 0.28, bodyTop + 0.1, z * 0.28);
cap.castShadow = true;
group.add(cap);
}
}
const mast = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.86, 0.15),
new THREE.MeshStandardMaterial({ color: 0x263743, metalness: 0.6, roughness: 0.4 })
);
mast.position.y = bodyTop + 0.61;
mast.castShadow = true;
group.add(mast);
const beaconColor = 0xff5faf;
const beacon = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.28, 0.28),
new THREE.MeshStandardMaterial({
color: beaconColor,
emissive: beaconColor,
emissiveIntensity: 1.8,
roughness: 0.3
})
);
beacon.position.y = bodyTop + 1.16;
beacon.castShadow = true;
group.add(beacon);
}
scene.add(group);
return {
group,
bodyTop,
maleType: config.maleType,
socketType: config.socketType,
maleMaterial,
originalMaleColor: config.maleType ? KEY_COLORS[config.maleType] : null,
...config
};
}
const BASE_Y = 0.08;
const BASE_SOCKET_TOP = BASE_Y + 2 * CELL + 0.42;
const SPINE_TOP = BASE_SOCKET_TOP + 3 * CELL;
const PULSE_SOCKET_TOP = SPINE_TOP + 0.42;
const CROWN_BASE = PULSE_SOCKET_TOP + 0.42;
const parts = [
makePart({
code: "ROOT-01",
name: "ROOT",
role: "CROSS WELL",
color: 0x1c7479,
accent: 0x44e5df,
layers: 2,
style: "standard",
maleType: null,
socketType: "cross"
}),
makePart({
code: "SPINE-02",
name: "SPINE",
role: "CROSS TAB",
color: 0x3158d5,
accent: 0x7695ff,
layers: 3,
style: "standard",
maleType: "cross",
socketType: "corner"
}),
makePart({
code: "PULSE-03",
name: "PULSE",
role: "CORNER TAB",
color: 0xe5575d,
accent: 0xff9297,
layers: 3,
style: "pulse",
maleType: "corner",
socketType: "diamond"
}),
makePart({
code: "CROWN-04",
name: "CROWN",
role: "DIAMOND TAB",
color: 0xe6a52d,
accent: 0xffe087,
layers: 2,
style: "crown",
maleType: "diamond",
socketType: null,
crown: true
})
];
const assembledPositions = [
new THREE.Vector3(0, BASE_Y, 0),
new THREE.Vector3(0, BASE_SOCKET_TOP, 0),
new THREE.Vector3(0, PULSE_SOCKET_TOP, 0),
new THREE.Vector3(0, CROWN_BASE, 0)
];
const explodedPositions = [
new THREE.Vector3(0, BASE_Y, 0),
new THREE.Vector3(0, 3.55, 0),
new THREE.Vector3(0, 6.15, 0),
new THREE.Vector3(0, 8.75, 0)
];
parts.forEach((part, index) => {
part.assembled = assembledPositions[index];
part.exploded = explodedPositions[index];
part.group.position.copy(part.exploded);
});
/* --------------------------------------------------------------------------
UI
--------------------------------------------------------------------------- */
function makeKeyIcon(type, mini = false) {
const element = document.createElement("div");
element.className = mini ? "mini-key" : "key-icon";
element.style.setProperty("--accent", KEY_CSS[type]);
for (let z = -3; z <= 3; z++) {
for (let x = -3; x <= 3; x++) {
const cell = document.createElement("i");
const match = KEY_DEFS[type].cells.some(([cx, cz]) => cx === x && cz === z);
if (match) cell.classList.add("on");
element.appendChild(cell);
}
}
return element;
}
const stepMeta = [
{ type: "cross", sub: "Place chassis / open well" },
{ type: "cross", sub: "Cross tab into cross well" },
{ type: "corner", sub: "Corner tab into corner well" },
{ type: "diamond", sub: "Diamond tab into diamond well" }
];
const stepButtons = [];
parts.forEach((part, index) => {
const button = document.createElement("button");
button.className = "step";
button.style.setProperty("--accent", KEY_CSS[stepMeta[index].type]);
button.innerHTML = `
<span class="step-no">0${index + 1}</span>
<span class="step-copy">
<strong>${part.name}</strong>
<small>${stepMeta[index].sub}</small>
</span>
`;
button.appendChild(makeKeyIcon(stepMeta[index].type, true));
button.addEventListener("click", () => selectStep(index));
$("#steps").appendChild(button);
stepButtons.push(button);
});
for (const type of ["cross", "corner", "diamond"]) {
const row = document.createElement("div");
row.className = "legend-row";
row.style.setProperty("--accent", KEY_CSS[type]);
row.appendChild(makeKeyIcon(type));
const copy = document.createElement("div");
copy.innerHTML = `
<strong>${KEY_DEFS[type].name} KEY</strong>
<small>${
type === "cross" ? "Five-cell cruciform profile" :
type === "corner" ? "Three-cell offset L profile" :
"Five-cell diagonal profile"
}</small>
`;
row.appendChild(copy);
$("#legend").appendChild(row);
}
parts.forEach(part => {
const label = document.createElement("div");
label.className = "part-label";
label.style.setProperty("--accent", KEY_CSS[stepMeta[parts.indexOf(part)].type]);
label.innerHTML = `<strong>${part.code}</strong><span>${part.role}</span>`;
labelLayer.appendChild(label);
part.label = label;
});
function setSelected(index) {
stepButtons.forEach((button, i) => button.classList.toggle("active", i === index));
}
function setNotice(title, copy, tone = "info") {
$("#notice-title").textContent = title;
$("#notice-copy").textContent = copy;
$("#notice").className = tone;
}
function setProgress(value, color = "#b9f45d") {
$("#progress").style.width = `${value * 100}%`;
$("#progress").style.background = color;
}
/* --------------------------------------------------------------------------
Assembly animation
--------------------------------------------------------------------------- */
let runToken = 0;
let mode = "exploded";
let selectedStep = 0;
function schedule(callback, delay, token) {
setTimeout(() => {
if (token === runToken) callback();
}, delay);
}
function movePart(part, target, options = {}) {
const duration = options.duration ?? 950;
part.group.userData.tween = {
from: part.group.position.clone(),
to: target.clone(),
rotationFrom: part.group.rotation.y,
rotationTo: options.rotation ?? 0,
start: performance.now(),
duration,
done: options.done
};
}
function placePart(part, target, rotation = 0) {
part.group.userData.tween = null;
part.group.position.copy(target);
part.group.rotation.set(0, rotation, 0);
}
function restoreMaleColors() {
for (const part of parts) {
if (!part.maleMaterial) continue;
const color = part.originalMaleColor;
part.maleMaterial.color.setHex(color);
part.maleMaterial.emissive.setHex(color);
part.maleMaterial.emissiveIntensity = 0.22;
}
}
function resetScenePositions() {
parts.forEach((part, index) => {
part.group.visible = true;
placePart(part, part.exploded);
});
restoreMaleColors();
marker.visible = false;
}
function selectStep(index) {
runToken++;
mode = "step";
selectedStep = index;
setSelected(index);
restoreMaleColors();
$("#mismatch-panel").classList.remove("show");
$("#btn-lab").classList.remove("active");
parts.forEach((part, i) => {
part.group.visible = true;
if (i < index) {
placePart(part, part.assembled);
} else if (i > index) {
placePart(part, part.exploded);
} else if (index === 0) {
placePart(part, part.assembled);
} else {
placePart(part, part.exploded);
movePart(part, part.assembled, {
duration: 850,
done: () => {
setNotice(
`${part.code} / LOCKED`,
`${KEY_DEFS[part.maleType].name} tab seated in the matching ${KEY_DEFS[parts[i - 1].socketType].name.toLowerCase()} well.`,
"good"
);
setProgress((index + 1) / 4);
}
});
}
});
controls.desiredTargetY = index === 0 ? 1.2 : 3.7;
controls.desiredRadius = index === 0 ? 8.2 : 12.5;
if (index === 0) {
setNotice("STEP 01 / ROOT", "Place the chassis first. Its raised green rim forms the CROSS well.", "info");
setProgress(0.25);
} else {
setNotice(`STEP 0${index + 1} / ${parts[index].name}`, "Moving the keyed tab into the matching receiver…", "info");
setProgress(index / 4);
}
}
function playSequence() {
runToken++;
const token = runToken;
mode = "correct";
selectedStep = 3;
setSelected(3);
restoreMaleColors();
resetScenePositions();
$("#mismatch-panel").classList.remove("show");
$("#btn-lab").classList.remove("active");
controls.desiredTargetY = 3.7;
controls.desiredRadius = 13.4;
setNotice("SEQUENCE ARMED", "Follow the keyed stack: CROSS → CORNER → DIAMOND.", "info");
setProgress(0);
schedule(() => {
movePart(parts[1], parts[1].assembled, {
duration: 1050,
done: () => {
setNotice("01 / 03 — CROSS LOCKED", "The green cruciform tab is fully seated in ROOT-01.", "good");
setProgress(0.42);
schedule(() => {
movePart(parts[2], parts[2].assembled, {
duration: 1050,
done: () => {
setNotice("02 / 03 — CORNER LOCKED", "The cyan L-tab clears the socket walls and enters the corner well.", "good");
setProgress(0.72);
schedule(() => {
movePart(parts[3], parts[3].assembled, {
duration: 1050,
done: () => {
setNotice("ASSEMBLY COMPLETE", "All four modules are seated. Shape, color, and order agree.", "good");
setProgress(1);
}
});
}, 220, token);
}
});
}, 220, token);
}
});
}, 380, token);
}
function completeBuild() {
runToken++;
mode = "correct";
selectedStep = 3;
setSelected(3);
restoreMaleColors();
$("#mismatch-panel").classList.remove("show");
$("#btn-lab").classList.remove("active");
parts.forEach((part, index) => {
part.group.visible = true;
if (index === 0) {
placePart(part, part.assembled);
} else {
placePart(part, part.exploded);
movePart(part, part.assembled, { duration: 1050 });
}
});
controls.desiredTargetY = 3.0;
controls.desiredRadius = 11.7;
setNotice("ASSEMBLY COMPLETE", "All keyed interfaces are seated in the required sequence.", "good");
setProgress(1);
}
function showExploded() {
runToken++;
mode = "exploded";
selectedStep = 0;
setSelected(0);
resetScenePositions();
$("#mismatch-panel").classList.remove("show");
$("#btn-lab").classList.remove("active");
controls.desiredTargetY = 4.0;
controls.desiredRadius = 13.8;
setNotice("EXPLODED VIEW", "Three keyed interfaces are exposed. Select a build step or play the correct sequence.", "info");
setProgress(0);
}
/* --------------------------------------------------------------------------
Mismatch laboratory. The obstruction is produced by the actual tab and
well geometry; no collision state is merely painted onto the scene.
--------------------------------------------------------------------------- */
const marker = new THREE.Group();
marker.visible = false;
scene.add(marker);
let markerUntil = 0;
function setMarker(type, colorHex, y, duration = Infinity) {
while (marker.children.length) {
const child = marker.children[0];
child.geometry?.dispose();
child.material?.dispose();
marker.remove(child);
}
const color = new THREE.Color(colorHex);
for (const [x, z] of KEY_DEFS[type].cells) {
const box = new THREE.BoxGeometry(CELL * 0.98, 0.08, CELL * 0.98);
const edges = new THREE.EdgesGeometry(box);
box.dispose();
const line = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
line.position.set(x * CELL, 0, z * CELL);
line.renderOrder = 10;
marker.add(line);
}
marker.position.y = y;
marker.visible = true;
markerUntil = performance.now() + duration;
}
function enterLab() {
runToken++;
mode = "lab";
selectedStep = -1;
setSelected(-1);
$("#mismatch-panel").classList.add("show");
$("#btn-lab").classList.add("active");
controls.desiredTargetY = 2.5;
controls.desiredRadius = 10.7;
setupMismatch(0);
}
function setupMismatch(index) {
runToken++;
const token = runToken;
mode = "lab";
restoreMaleColors();
marker.visible = false;
document.querySelectorAll(".mismatch-button").forEach((button, i) => {
button.classList.toggle("active", i === index);
});
parts.forEach(part => {
part.group.visible = false;
placePart(part, part.exploded);
});
if (index === 0) {
// Real CORNER tab from PULSE-03 offered to ROOT-01's CROSS well.
parts[0].group.visible = true;
placePart(parts[0], parts[0].assembled);
parts[2].group.visible = true;
placePart(parts[2], new THREE.Vector3(0, 4.75, 0));
setNotice("REJECT / WRONG PROFILE", "Offering the cyan CORNER tab to the green CROSS well.", "bad");
setProgress(0.62, "#ff526d");
movePart(parts[2], new THREE.Vector3(0, BASE_SOCKET_TOP, 0), {
duration: 1450,
done: () => {
if (token !== runToken) return;
setMarker("cross", 0xff526d, BASE_SOCKET_TOP + 0.035);
setNotice(
"GEOMETRIC COLLISION",
"The corner-shaped tab overlaps the cross-well rim. It cannot seat: wrong shape, wrong color, wrong station.",
"bad"
);
}
});
}
if (index === 1) {
// Real CROSS tab from SPINE-02 offered to PULSE-03's DIAMOND well.
parts[2].group.visible = true;
placePart(parts[2], new THREE.Vector3(0, BASE_SOCKET_TOP, 0));
parts[1].group.visible = true;
placePart(parts[1], new THREE.Vector3(0, 5.15, 0));
setNotice("REJECT / NON-MATCHING RECEIVER", "Offering the green CROSS tab to the magenta DIAMOND well.", "bad");
setProgress(0.72, "#ff526d");
movePart(parts[1], new THREE.Vector3(0, PULSE_SOCKET_TOP, 0), {
duration: 1450,
done: () => {
if (token !== runToken) return;
setMarker("diamond", 0xff526d, PULSE_SOCKET_TOP + 0.035);
setNotice(
"GEOMETRIC COLLISION",
"The cruciform tab and diagonal well do not share a boundary. Physical insertion is blocked.",
"bad"
);
}
});
}
if (index === 2) {
// The same real CORNER tab is rotated 90 degrees.
parts[0].group.visible = true;
placePart(parts[0], parts[0].assembled);
parts[2].group.visible = true;
placePart(parts[2], new THREE.Vector3(0, 4.8, 0));
setNotice("REJECT / ROTATED PROFILE", "The cyan CORNER tab is presented 90° out of orientation.", "bad");
setProgress(0.66, "#ff526d");
movePart(parts[2], new THREE.Vector3(0, BASE_SOCKET_TOP, 0), {
duration: 1450,
rotation: Math.PI / 2,
done: () => {
if (token !== runToken) return;
setMarker("cross", 0xff526d, BASE_SOCKET_TOP + 0.035);
setNotice(
"GEOMETRIC COLLISION",
"Rotation changes the actual L footprint. The tab intersects the receiver rim instead of entering the cavity.",
"bad"
);
}
});
}
if (index === 3) {
// The shape genuinely fits, but the paint code is intentionally wrong.
parts[0].group.visible = true;
placePart(parts[0], parts[0].assembled);
parts[1].group.visible = true;
placePart(parts[1], new THREE.Vector3(0, 4.5, 0));
const wrongColor = KEY_COLORS.diamond;
parts[1].maleMaterial.color.setHex(wrongColor);
parts[1].maleMaterial.emissive.setHex(wrongColor);
parts[1].maleMaterial.emissiveIntensity = 0.35;
setNotice("REJECT / PAINT CODE", "The CROSS geometry fits, but the tab is magenta rather than green.", "warn");
setProgress(0.78, "#ffc857");
movePart(parts[1], parts[1].assembled, {
duration: 1450,
done: () => {
if (token !== runToken) return;
setMarker("cross", 0xffc857, BASE_SOCKET_TOP + 0.035);
setNotice(
"SHAPE PASS / COLOR FAIL",
"The tab would physically enter the cross well, but redundant color coding rejects the mismatched paint code.",
"warn"
);
}
});
}
}
document.querySelectorAll(".mismatch-button").forEach(button => {
button.addEventListener("click", () => setupMismatch(Number(button.dataset.mismatch)));
});
$("#btn-exploded").addEventListener("click", showExploded);
$("#btn-play").addEventListener("click", playSequence);
$("#btn-complete").addEventListener("click", completeBuild);
$("#btn-lab").addEventListener("click", () => {
if (mode === "lab") showExploded();
else enterLab();
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
playSequence();
}
if (event.key.toLowerCase() === "r") showExploded();
});
/* --------------------------------------------------------------------------
Animation and label projection
--------------------------------------------------------------------------- */
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
const labelPosition = new THREE.Vector3();
function updateTweens(now) {
for (const part of parts) {
const tween = part.group.userData.tween;
if (!tween) continue;
const elapsed = now - tween.start;
const t = Math.min(elapsed / tween.duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
part.group.position.lerpVectors(tween.from, tween.to, eased);
part.group.rotation.y = THREE.MathUtils.lerp(
tween.rotationFrom,
tween.rotationTo,
eased
);
if (t >= 1) {
part.group.userData.tween = null;
tween.done?.();
}
}
}
function updateCamera() {
controls.yaw = THREE.MathUtils.lerp(controls.yaw, controls.desiredYaw, 0.085);
controls.phi = THREE.MathUtils.lerp(controls.phi, controls.desiredPhi, 0.085);
controls.radius = THREE.MathUtils.lerp(controls.radius, controls.desiredRadius, 0.08);
controls.targetY = THREE.MathUtils.lerp(controls.targetY, controls.desiredTargetY, 0.08);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
Math.sin(controls.yaw) * sinPhi * controls.radius,
controls.targetY + Math.cos(controls.phi) * controls.radius,
Math.cos(controls.yaw) * sinPhi * controls.radius
);
camera.lookAt(0, controls.targetY, 0);
}
function updateLabels() {
parts.forEach((part, index) => {
if (!part.group.visible) {
part.label.style.opacity = "0";
return;
}
labelPosition.set(1.85, part.bodyTop * 0.55, 0);
part.group.localToWorld(labelPosition);
projected.copy(labelPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
part.label.style.opacity = visible ? "1" : "0";
part.label.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
part.label.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
});
}
function animate(now) {
const dt = clock.getDelta();
updateTweens(now);
updateCamera();
if (marker.visible) {
const pulse = 1 + Math.sin(now * 0.008) * 0.035;
marker.scale.set(pulse, 1, pulse);
marker.children.forEach(child => {
child.material.opacity = 0.72 + Math.sin(now * 0.008) * 0.22;
});
if (now > markerUntil) marker.visible = false;
}
cyanLight.position.x = -5 + Math.sin(now * 0.00035) * 1.2;
pinkLight.position.z = -3 + Math.cos(now * 0.00031) * 1.1;
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
setSelected(0);
setNotice(
"EXPLODED VIEW",
"Three keyed interfaces are exposed. Select a build step or play the correct sequence.",
"info"
);
</script>
</body>
</html>
```