Prompt specification
Build or customize the Three.js 3D scene "Coupling Before Alignment Puzzle" 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: Coupling Before Alignment Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coupling-before-alignment-puzzle-x2020
Scene Description Prompt:
Make a voxel shaft-coupling puzzle requiring compatible alignment and speed before engagement, visibly rejecting invalid combinations. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (coupling-before-alignment-puzzle-x2020):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#0b111a">
<title>Coupling Lab — Voxel Shaft Puzzle</title>
<style>
:root {
--bg: #0b111a;
--panel: rgba(14, 23, 35, 0.9);
--panel-soft: rgba(22, 34, 49, 0.72);
--line: rgba(145, 183, 216, 0.17);
--text: #e9f3ff;
--muted: #7f96ad;
--cyan: #55ddd7;
--green: #77e69a;
--amber: #f4c35e;
--red: #ff6b67;
--accent: #55ddd7;
}
* {
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,
input {
font: inherit;
}
button {
color: inherit;
}
[hidden] {
display: none !important;
}
#app,
#world {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#world {
display: block;
cursor: grab;
touch-action: none;
outline: none;
}
#world:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 54% 48%, transparent 20%, rgba(2, 6, 12, 0.18) 68%, rgba(2, 6, 12, 0.72) 115%),
linear-gradient(180deg, rgba(3, 8, 14, 0.35), transparent 22%, transparent 70%, rgba(3, 8, 14, 0.42));
z-index: 2;
}
.ui {
position: fixed;
z-index: 5;
pointer-events: none;
}
.panel {
pointer-events: auto;
background:
linear-gradient(145deg, rgba(25, 38, 54, 0.88), rgba(10, 17, 27, 0.92)),
var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.045);
backdrop-filter: blur(16px);
}
.topbar {
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
text-shadow: 0 2px 16px #000;
}
.brand-icon {
width: 35px;
height: 35px;
position: relative;
transform: rotate(45deg);
border: 2px solid var(--cyan);
box-shadow:
inset 0 0 18px rgba(85, 221, 215, 0.13),
0 0 24px rgba(85, 221, 215, 0.12);
}
.brand-icon::before,
.brand-icon::after {
content: "";
position: absolute;
background: var(--cyan);
}
.brand-icon::before {
width: 2px;
height: 21px;
left: 15px;
top: 5px;
}
.brand-icon::after {
width: 21px;
height: 2px;
left: 5px;
top: 15px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand p {
margin: 6px 0 0;
color: var(--muted);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.bay-status {
display: flex;
gap: 9px;
align-items: center;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(10, 17, 27, 0.68);
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.bay-status i {
width: 7px;
height: 7px;
background: var(--green);
border-radius: 50%;
box-shadow: 0 0 11px var(--green);
}
.manifest {
top: 92px;
left: 20px;
width: 318px;
padding: 18px;
}
.eyebrow {
color: var(--cyan);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.manifest h2 {
margin: 8px 0 5px;
font-size: 22px;
line-height: 1.1;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.description {
min-height: 34px;
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.target-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.target-cell {
min-height: 76px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(6, 13, 22, 0.48);
}
.target-cell small {
display: block;
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.target-cell strong {
display: block;
margin-top: 8px;
color: var(--amber);
font: 700 18px ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.tolerance {
margin: 9px 0 16px;
color: #657c93;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-align: right;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #b8c9d9;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.state-badge {
padding: 4px 7px;
border: 1px solid rgba(244, 195, 94, 0.25);
border-radius: 5px;
color: var(--amber);
background: rgba(244, 195, 94, 0.07);
font-size: 8px;
}
.state-badge.pass {
color: var(--green);
border-color: rgba(119, 230, 154, 0.3);
background: rgba(119, 230, 154, 0.08);
}
.state-badge.fail {
color: var(--red);
border-color: rgba(255, 107, 103, 0.3);
background: rgba(255, 107, 103, 0.08);
}
.checks {
display: grid;
gap: 6px;
}
.check {
display: grid;
grid-template-columns: 10px 1fr auto;
gap: 9px;
align-items: center;
min-height: 36px;
padding: 0 10px;
border: 1px solid rgba(142, 173, 202, 0.11);
border-radius: 8px;
background: rgba(255, 255, 255, 0.018);
}
.check .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 9px rgba(255, 107, 103, 0.55);
}
.check.pass .dot {
background: var(--green);
box-shadow: 0 0 9px rgba(119, 230, 154, 0.55);
}
.check span {
color: #b9c9d8;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.check b {
color: var(--red);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.check.pass b {
color: var(--green);
}
.readout {
margin-top: 12px;
padding: 10px;
border-radius: 8px;
background: rgba(85, 221, 215, 0.045);
border: 1px solid rgba(85, 221, 215, 0.1);
color: var(--muted);
font: 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.controls {
right: 20px;
bottom: 20px;
width: 390px;
padding: 18px;
}
.control-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
margin-bottom: 15px;
}
.control-heading h2 {
margin: 5px 0 0;
font-size: 17px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.reset-button {
pointer-events: auto;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
border-radius: 7px;
padding: 7px 9px;
cursor: pointer;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.reset-button:hover {
color: var(--text);
border-color: rgba(85, 221, 215, 0.4);
}
.control-row {
margin-bottom: 14px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.control-label output {
color: var(--text);
font-size: 15px;
font-weight: 700;
letter-spacing: 0.04em;
}
input[type="range"] {
--fill: 0%;
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 5px;
border-radius: 5px;
background: linear-gradient(
to right,
var(--cyan) 0,
var(--cyan) var(--fill),
#26384b var(--fill),
#26384b 100%
);
}
input[type="range"]::-moz-range-track {
height: 5px;
border-radius: 5px;
background: #26384b;
}
input[type="range"]::-moz-range-progress {
height: 5px;
border-radius: 5px;
background: var(--cyan);
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 16px;
height: 16px;
margin-top: -5.5px;
border: 3px solid #dffdfc;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 13px rgba(85, 221, 215, 0.4);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #dffdfc;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 13px rgba(85, 221, 215, 0.4);
}
input[type="range"]:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.profile-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 4px;
}
.profile-button {
min-height: 51px;
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.018);
color: var(--muted);
cursor: pointer;
transition: 140ms ease;
}
.profile-button strong,
.profile-button small {
display: block;
}
.profile-button strong {
color: #c7d5e3;
font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.profile-button small {
margin-top: 4px;
font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.profile-button:hover:not(:disabled) {
border-color: rgba(85, 221, 215, 0.35);
}
.profile-button.selected {
border-color: rgba(85, 221, 215, 0.7);
background: rgba(85, 221, 215, 0.09);
box-shadow: inset 0 0 20px rgba(85, 221, 215, 0.035);
}
.profile-button.selected strong {
color: var(--cyan);
}
.profile-button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.engage-button {
width: 100%;
min-height: 50px;
margin-top: 17px;
border: 1px solid rgba(255, 107, 103, 0.38);
border-radius: 9px;
background: rgba(255, 107, 103, 0.08);
color: #ffd0cd;
cursor: pointer;
font: 700 12px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: 150ms ease;
}
.engage-button:hover:not(:disabled) {
transform: translateY(-1px);
background: rgba(255, 107, 103, 0.14);
}
.engage-button.ready {
color: #dffff0;
border-color: rgba(119, 230, 154, 0.65);
background: rgba(119, 230, 154, 0.12);
box-shadow: 0 0 28px rgba(119, 230, 154, 0.08);
}
.engage-button:disabled {
cursor: default;
opacity: 0.68;
}
.next-button {
width: 100%;
min-height: 42px;
margin-top: 8px;
border: 1px solid rgba(85, 221, 215, 0.4);
border-radius: 9px;
background: rgba(85, 221, 215, 0.09);
color: var(--cyan);
cursor: pointer;
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.control-foot {
margin: 10px 0 0;
color: #647b91;
font: 9px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.level-panel {
top: 92px;
right: 20px;
min-width: 190px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(10, 17, 27, 0.74);
backdrop-filter: blur(12px);
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
}
.level-row {
display: flex;
justify-content: space-between;
gap: 25px;
margin-bottom: 10px;
}
.level-row strong {
color: var(--text);
font-size: 10px;
}
.progress {
display: flex;
gap: 5px;
}
.progress i {
width: 24px;
height: 4px;
border-radius: 4px;
background: #27374a;
}
.progress i.active {
background: var(--cyan);
box-shadow: 0 0 10px rgba(85, 221, 215, 0.3);
}
.progress i.done {
background: var(--green);
}
.toast {
position: fixed;
left: 50%;
top: 82px;
z-index: 20;
width: min(460px, calc(100vw - 28px));
padding: 13px 17px;
border: 1px solid rgba(85, 221, 215, 0.28);
border-radius: 10px;
background: rgba(11, 20, 31, 0.96);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
color: var(--text);
text-align: center;
pointer-events: none;
opacity: 0;
transform: translate(-50%, -12px);
transition: 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.error {
border-color: rgba(255, 107, 103, 0.55);
}
.toast.success {
border-color: rgba(119, 230, 154, 0.55);
}
.toast strong {
display: block;
margin-bottom: 5px;
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
}
.toast span {
color: var(--muted);
font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.flash {
position: fixed;
inset: 0;
z-index: 15;
pointer-events: none;
opacity: 0;
background: radial-gradient(circle at 50% 48%, rgba(255, 70, 64, 0.3), rgba(255, 40, 40, 0.04) 36%, transparent 70%);
}
.flash.active {
animation: reject-flash 0.65s ease-out;
}
.flash.good {
background: radial-gradient(circle at 50% 48%, rgba(76, 255, 140, 0.24), transparent 60%);
}
@keyframes reject-flash {
0% { opacity: 0; }
18% { opacity: 1; }
100% { opacity: 0; }
}
.world-label {
position: fixed;
z-index: 4;
pointer-events: none;
padding: 4px 7px;
border: 1px solid rgba(151, 188, 218, 0.18);
border-radius: 4px;
background: rgba(6, 12, 20, 0.66);
color: #91a8bc;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
transform: translate(-50%, -50%);
}
.orbit-hint {
left: 50%;
bottom: 15px;
transform: translateX(-50%);
color: rgba(161, 183, 202, 0.55);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
@media (max-width: 980px) {
.manifest {
width: 285px;
}
.controls {
width: 350px;
}
.description {
display: none;
}
}
@media (max-width: 720px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand h1 {
font-size: 14px;
}
.brand p,
.bay-status,
.level-panel,
.orbit-hint {
display: none;
}
.manifest {
top: 68px;
left: 10px;
right: 10px;
width: auto;
padding: 12px;
}
.manifest h2 {
margin: 5px 0 10px;
font-size: 16px;
}
.target-cell {
min-height: 56px;
padding: 8px;
}
.target-cell strong {
margin-top: 6px;
font-size: 14px;
}
.tolerance {
margin-bottom: 10px;
}
.readout {
display: none;
}
.controls {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
padding: 13px;
max-height: 48vh;
overflow-y: auto;
}
.control-heading {
margin-bottom: 10px;
}
.control-row {
margin-bottom: 10px;
}
.profile-button {
min-height: 43px;
}
.toast {
top: auto;
bottom: 51vh;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="world" aria-label="Interactive 3D voxel shaft coupling puzzle"></canvas>
<div class="vignette"></div>
<header class="topbar ui">
<div class="brand">
<div class="brand-icon" aria-hidden="true"></div>
<div>
<h1>Coupling Lab</h1>
<p>Voxel shaft alignment puzzle</p>
</div>
</div>
<div class="bay-status">
<i></i>
BAY 04 / ONLINE
</div>
</header>
<aside class="manifest panel ui">
<div class="eyebrow">Match Manifest</div>
<h2 id="targetName">Starter Link</h2>
<p class="description" id="targetDescription"></p>
<div class="target-grid">
<div class="target-cell">
<small>Target phase</small>
<strong id="targetPhase">045°</strong>
</div>
<div class="target-cell">
<small>Target speed</small>
<strong id="targetRpm">060 RPM</strong>
</div>
<div class="target-cell">
<small>Interface</small>
<strong id="targetType">6T KEY</strong>
</div>
</div>
<div class="tolerance">TOLERANCE: PHASE ±10° / SPEED ±5 RPM</div>
<div class="section-title">
<span>Pre-engagement checks</span>
<span class="state-badge" id="stateBadge">Checking</span>
</div>
<div class="checks">
<div class="check" id="phaseCheck">
<i class="dot"></i>
<span>Phase alignment</span>
<b id="phaseDelta">Δ 45°</b>
</div>
<div class="check" id="speedCheck">
<i class="dot"></i>
<span>Speed compatibility</span>
<b id="speedDelta">Δ 30 RPM</b>
</div>
<div class="check" id="typeCheck">
<i class="dot"></i>
<span>Profile compatibility</span>
<b id="typeDelta">Mismatch</b>
</div>
</div>
<div class="readout" id="readout">
Match the manifest before attempting engagement. Invalid combinations
will trigger a mechanical lockout.
</div>
</aside>
<section class="controls panel ui">
<div class="control-heading">
<div>
<div class="eyebrow">Drive setup</div>
<h2>Configure Shaft</h2>
</div>
<button class="reset-button" id="resetButton" type="button">Reset</button>
</div>
<div class="control-row">
<label class="control-label" for="phaseRange">
<span>Coupling phase</span>
<output id="phaseValue" for="phaseRange">000°</output>
</label>
<input id="phaseRange" type="range" min="0" max="355" step="5" value="0">
</div>
<div class="control-row">
<label class="control-label" for="rpmRange">
<span>Drive speed</span>
<output id="rpmValue" for="rpmRange">030 RPM</output>
</label>
<input id="rpmRange" type="range" min="0" max="120" step="5" value="30">
</div>
<div class="control-row">
<div class="control-label">
<span>Interface profile</span>
<output id="profileValue">6T KEY</output>
</div>
<div class="profile-grid" id="profileGrid">
<button class="profile-button selected" data-type="6T" type="button">
<strong>6T</strong>
<small>KEYED</small>
</button>
<button class="profile-button" data-type="8T" type="button">
<strong>8T</strong>
<small>SPLINED</small>
</button>
<button class="profile-button" data-type="SQUARE" type="button">
<strong>SQ</strong>
<small>FLANGE</small>
</button>
</div>
</div>
<button class="engage-button" id="engageButton" type="button">Attempt engagement</button>
<button class="next-button" id="nextButton" type="button" hidden>Next manifest</button>
<p class="control-foot">
Matching phase, speed, and interface are required before the lock engages.
</p>
</section>
<aside class="level-panel ui">
<div class="level-row">
<span>MANIFEST</span>
<strong id="levelText">01 / 04</strong>
</div>
<div class="progress" id="progress">
<i class="active"></i><i></i><i></i><i></i>
</div>
</aside>
<div class="toast" id="toast" role="status" aria-live="polite">
<strong id="toastTitle">Manifest loaded</strong>
<span id="toastDetail"></span>
</div>
<div class="flash" id="flash"></div>
<div class="world-label" id="inputLabel">DRIVE IN</div>
<div class="world-label" id="outputLabel">LOAD OUT</div>
<div class="orbit-hint ui">Drag to orbit · Wheel to zoom · Double-click to recenter</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("world");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b111a);
scene.fog = new THREE.Fog(0x0b111a, 15, 31);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.68,
phi: 1.03,
radius: 13.7,
target: new THREE.Vector3(0, 1.05, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb5d9ff, 0x18202c, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd9edff, 3.2);
keyLight.position.set(6, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x55ddd7, 22, 8, 2);
cyanLight.position.set(-3.5, 3.6, 3.4);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xffb75d, 18, 7, 2);
warmLight.position.set(4, 3, -3);
scene.add(warmLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standard(color, metalness = 0.15, roughness = 0.72, emissive = 0x000000) {
return new THREE.MeshStandardMaterial({
color,
metalness,
roughness,
emissive,
emissiveIntensity: emissive ? 0.6 : 0
});
}
const materials = {
floor: standard(0x0c131d, 0.05, 0.95),
platform: standard(0x172331, 0.55, 0.62),
platformEdge: standard(0x26384b, 0.65, 0.5),
rail: standard(0x33485d, 0.72, 0.42),
dark: standard(0x111923, 0.35, 0.8),
darker: standard(0x090f16, 0.2, 0.9),
steel: standard(0x9aabba, 0.78, 0.34),
steelAlt: standard(0x718596, 0.72, 0.42),
housing: standard(0x40556a, 0.65, 0.48),
motor: standard(0x47647c, 0.55, 0.55),
motorDark: standard(0x243b4e, 0.55, 0.62),
amber: standard(0xf1b84d, 0.45, 0.45),
cyan: standard(0x55ddd7, 0.45, 0.38, 0x164943),
green: standard(0x77e69a, 0.35, 0.4, 0x164c2b),
red: standard(0xff6b67, 0.35, 0.45, 0x4c1716),
white: standard(0xdde9f3, 0.2, 0.55)
};
function box(parent, sx, sy, sz, x, y, z, material) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const staticMachine = new THREE.Group();
const mechanism = new THREE.Group();
scene.add(staticMachine, mechanism);
// Floor and raised service platform.
box(scene, 30, 0.1, 24, 0, -0.06, 0, materials.floor);
const grid = new THREE.GridHelper(30, 30, 0x284258, 0x172838);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.55;
scene.add(grid);
box(staticMachine, 15, 0.28, 6.4, 0, 0.2, 0, materials.platform);
box(staticMachine, 15.15, 0.12, 6.55, 0, 0.38, 0, materials.platformEdge);
for (const z of [-2.65, 2.65]) {
box(staticMachine, 13.9, 0.22, 0.26, 0, 0.54, z, materials.rail);
}
for (let x = -6.5; x <= 6.5; x += 0.65) {
box(
staticMachine,
0.34,
0.06,
0.18,
x,
0.49,
-2.65,
Math.round(x * 10) % 2 === 0 ? materials.amber : materials.dark
);
box(
staticMachine,
0.34,
0.06,
0.18,
x,
0.49,
2.65,
Math.round(x * 10) % 2 === 0 ? materials.amber : materials.dark
);
}
for (const x of [-7, 7]) {
for (const z of [-2.8, 2.8]) {
box(staticMachine, 0.36, 0.22, 0.36, x, 0.56, z, materials.steelAlt);
}
}
const shaftY = 1.55;
function buildBearing(x) {
box(staticMachine, 1.05, 0.72, 1.5, x, 0.75, 0, materials.housing);
box(staticMachine, 1.18, 0.22, 1.62, x, 1.16, 0, materials.steelAlt);
box(staticMachine, 1.02, 0.32, 1.5, x, 2.22, 0, materials.housing);
box(staticMachine, 1.02, 0.7, 0.26, x, 1.67, -0.63, materials.housing);
box(staticMachine, 1.02, 0.7, 0.26, x, 1.67, 0.63, materials.housing);
box(staticMachine, 0.18, 0.82, 0.2, x, 0.91, -0.8, materials.steelAlt);
box(staticMachine, 0.18, 0.82, 0.2, x, 0.91, 0.8, materials.steelAlt);
for (const z of [-0.72, 0.72]) {
for (const dx of [-0.34, 0.34]) {
box(staticMachine, 0.14, 0.14, 0.14, x + dx, 2.43, z, materials.steel);
}
}
}
buildBearing(-3.55);
buildBearing(3.55);
// Voxel drive motor.
box(staticMachine, 1.75, 1.65, 1.8, -6.15, 1.38, 0, materials.motor);
box(staticMachine, 1.92, 0.22, 1.96, -6.15, 2.26, 0, materials.motorDark);
box(staticMachine, 1.92, 0.22, 1.96, -6.15, 0.55, 0, materials.motorDark);
for (let x = -6.85; x <= -5.45; x += 0.22) {
box(staticMachine, 0.09, 1.4, 2.02, x, 1.4, 0, materials.motorDark);
}
box(staticMachine, 0.22, 0.75, 0.75, -5.15, shaftY, 0, materials.steelAlt);
box(staticMachine, 0.32, 0.22, 0.9, -6.15, 2.48, 0, materials.cyan);
// Voxel output gearbox.
box(staticMachine, 1.9, 1.65, 2.05, 6.15, 1.38, 0, materials.motor);
box(staticMachine, 2.05, 0.22, 2.18, 6.15, 2.26, 0, materials.motorDark);
box(staticMachine, 0.25, 0.8, 0.8, 5.1, shaftY, 0, materials.steelAlt);
for (const z of [-0.73, 0.73]) {
box(staticMachine, 1.55, 0.7, 0.14, 6.15, 1.4, z, materials.motorDark);
}
const typeData = {
"6T": {
label: "6T KEYED",
short: "6T KEY",
pitch: 60,
color: 0xf4bd54
},
"8T": {
label: "8T SPLINED",
short: "8T SPL",
pitch: 45,
color: 0x55ddd7
},
SQUARE: {
label: "SQUARE FLANGE",
short: "SQ FLG",
pitch: 90,
color: 0xff7b66
}
};
const typeMaterials = {};
for (const [key, data] of Object.entries(typeData)) {
const base = new THREE.Color(data.color);
const shellColor = base.clone().multiplyScalar(0.56);
const toothColor = base.clone().lerp(new THREE.Color(0xffffff), 0.12);
const darkColor = base.clone().multiplyScalar(0.27);
typeMaterials[key] = {
shell: standard(shellColor.getHex(), 0.7, 0.4),
tooth: standard(toothColor.getHex(), 0.65, 0.34),
dark: standard(darkColor.getHex(), 0.5, 0.62)
};
}
function buildRotor(direction) {
const rotor = new THREE.Group();
rotor.position.y = shaftY;
mechanism.add(rotor);
const from = direction < 0 ? -5.28 : 1.04;
const to = direction < 0 ? -1.04 : 5.28;
const count = Math.floor(Math.abs(to - from) / 0.31);
for (let i = 0; i < count; i++) {
const x = from + Math.sign(to - from) * (i + 0.5) * 0.31;
box(
rotor,
0.29,
0.27,
0.27,
x,
0,
0,
i % 3 === 0 ? materials.steelAlt : materials.steel
);
}
const collarX = direction < 0 ? -3.02 : 3.02;
const ringPositions = [
[0, 0.43, 0],
[0, 0.3, 0.3],
[0, 0, 0.43],
[0, -0.3, 0.3],
[0, -0.43, 0],
[0, -0.3, -0.3],
[0, 0, -0.43],
[0, 0.3, -0.3]
];
for (const [x, y, z] of ringPositions) {
box(
rotor,
0.43,
0.25,
0.25,
collarX + x,
y,
z,
iColor(collarX)
);
}
const keyX = direction < 0 ? -2.1 : 2.1;
box(
rotor,
0.72,
0.08,
0.1,
keyX,
0.2,
0,
direction < 0 ? materials.amber : materials.cyan
);
return rotor;
}
function iColor() {
return materials.steelAlt;
}
const leftRotor = buildRotor(-1);
const rightRotor = buildRotor(1);
function buildCouplerHalf(isLeft) {
const root = new THREE.Group();
root.position.set(isLeft ? -0.72 : 0.72, shaftY, 0);
mechanism.add(root);
const kinds = {};
for (const [type, data] of Object.entries(typeData)) {
const kind = new THREE.Group();
kind.rotation.x = (isLeft ? -1 : 1) * THREE.MathUtils.degToRad(data.pitch / 2);
kind.visible = false;
root.add(kind);
kinds[type] = kind;
const mats = typeMaterials[type];
// Solid voxel hub built from cubic lattice cells.
for (let ix = -1; ix <= 1; ix++) {
for (let iy = -2; iy <= 2; iy++) {
for (let iz = -2; iz <= 2; iz++) {
if (iy * iy + iz * iz > 4.8) continue;
const alternate = (ix + iy + iz + 9) % 5 === 0;
box(
kind,
0.245,
0.265,
0.265,
ix * 0.245,
iy * 0.27,
iz * 0.27,
alternate ? mats.dark : mats.shell
);
}
}
}
const toothCount = type === "SQUARE" ? 4 : Number(type.slice(0, -1));
const radius = type === "SQUARE" ? 1.03 : 1.13;
for (let i = 0; i < toothCount; i++) {
const angle = THREE.MathUtils.degToRad(
i * data.pitch + (type === "SQUARE" ? data.pitch / 2 : 0)
);
const tooth = box(
kind,
0.54,
type === "SQUARE" ? 0.38 : 0.44,
type === "SQUARE" ? 0.36 : 0.23,
isLeft ? 0.48 : -0.48,
Math.cos(angle) * radius,
Math.sin(angle) * radius,
mats.tooth
);
tooth.rotation.x = angle;
}
// Dark central jaw face.
box(
kind,
0.58,
0.58,
0.58,
isLeft ? 0.375 : -0.375,
0,
0,
mats.dark
);
}
// External phase index. Matching phase aligns the two indices.
const marker = box(
root,
0.13,
0.47,
0.16,
isLeft ? 0.37 : -0.37,
1.43,
0,
isLeft ? materials.amber : materials.cyan
);
marker.castShadow = false;
return { root, kinds };
}
const leftCoupler = buildCouplerHalf(true);
const rightCoupler = buildCouplerHalf(false);
// Three physical status lamps above the coupling.
const ledMaterials = [
standard(0xff6b67, 0.2, 0.3, 0x501817),
standard(0xff6b67, 0.2, 0.3, 0x501817),
standard(0xff6b67, 0.2, 0.3, 0x501817)
];
for (let i = 0; i < 3; i++) {
box(mechanism, 0.16, 0.16, 0.16, (i - 1) * 0.3, 2.65, 0, ledMaterials[i]);
}
// Beacon on the service platform.
box(staticMachine, 0.15, 1.4, 0.15, 0, 1.06, -2.35, materials.steelAlt);
box(staticMachine, 0.52, 0.15, 0.52, 0, 1.84, -2.35, materials.dark);
const beaconMaterial = standard(0xf4c35e, 0.2, 0.25, 0x5b3d0d);
box(staticMachine, 0.34, 0.34, 0.34, 0, 2.1, -2.35, beaconMaterial);
const levels = [
{
name: "Starter Link",
description: "A warm-up transfer line. Match the reference phase and low-speed duty before the jaws are allowed to lock.",
phase: 45,
rpm: 60,
type: "6T"
},
{
name: "Crosswind Array",
description: "A splined array is running faster. The key phase and rotational speed must agree before contact.",
phase: 135,
rpm: 90,
type: "8T"
},
{
name: "Precision Bus",
description: "A square-flange precision bus. Exact orientation and speed are required to avoid impact loading.",
phase: 300,
rpm: 105,
type: "SQUARE"
},
{
name: "Night Shift",
description: "The final transfer uses a keyed six-tooth interface with a lower duty speed.",
phase: 210,
rpm: 75,
type: "6T"
}
];
const state = {
level: 0,
phase: 0,
rpm: 30,
type: "6T",
mode: "ready",
engaged: false,
attempts: 0,
levelAttempts: 0,
rejectStart: 0,
rejectToken: 0,
couplingSpin: 0
};
const ui = {
targetName: document.getElementById("targetName"),
targetDescription: document.getElementById("targetDescription"),
targetPhase: document.getElementById("targetPhase"),
targetRpm: document.getElementById("targetRpm"),
targetType: document.getElementById("targetType"),
stateBadge: document.getElementById("stateBadge"),
phaseCheck: document.getElementById("phaseCheck"),
speedCheck: document.getElementById("speedCheck"),
typeCheck: document.getElementById("typeCheck"),
phaseDelta: document.getElementById("phaseDelta"),
speedDelta: document.getElementById("speedDelta"),
typeDelta: document.getElementById("typeDelta"),
readout: document.getElementById("readout"),
phaseRange: document.getElementById("phaseRange"),
rpmRange: document.getElementById("rpmRange"),
phaseValue: document.getElementById("phaseValue"),
rpmValue: document.getElementById("rpmValue"),
profileValue: document.getElementById("profileValue"),
engageButton: document.getElementById("engageButton"),
nextButton: document.getElementById("nextButton"),
resetButton: document.getElementById("resetButton"),
levelText: document.getElementById("levelText"),
progress: document.getElementById("progress"),
toast: document.getElementById("toast"),
toastTitle: document.getElementById("toastTitle"),
toastDetail: document.getElementById("toastDetail"),
flash: document.getElementById("flash"),
inputLabel: document.getElementById("inputLabel"),
outputLabel: document.getElementById("outputLabel")
};
const profileButtons = [...document.querySelectorAll(".profile-button")];
function target() {
return levels[state.level];
}
function pad(value, width = 3) {
return String(value).padStart(width, "0");
}
function phaseDifference(a, b) {
return Math.abs(((a - b + 540) % 360) - 180);
}
function getChecks() {
const t = target();
const phaseDiff = phaseDifference(state.phase, t.phase);
const speedDiff = Math.abs(state.rpm - t.rpm);
return {
phaseDiff,
speedDiff,
phase: phaseDiff <= 10,
speed: speedDiff <= 5,
type: state.type === t.type,
all: phaseDiff <= 10 && speedDiff <= 5 && state.type === t.type
};
}
function setTypeVisibility(half, type) {
for (const [key, group] of Object.entries(half.kinds)) {
group.visible = key === type;
}
}
function setLed(material, pass, active = true) {
const color = pass ? 0x77e69a : 0xff6b67;
material.color.setHex(color);
material.emissive.setHex(color);
material.emissiveIntensity = active ? 0.72 : 0.15;
}
function updateUI() {
const t = target();
const checks = getChecks();
ui.targetName.textContent = t.name;
ui.targetDescription.textContent = t.description;
ui.targetPhase.textContent = `${pad(t.phase)}°`;
ui.targetRpm.textContent = `${pad(t.rpm)} RPM`;
ui.targetType.textContent = typeData[t.type].short;
ui.phaseValue.textContent = `${pad(state.phase)}°`;
ui.rpmValue.textContent = `${pad(state.rpm)} RPM`;
ui.profileValue.textContent = typeData[state.type].short;
ui.phaseRange.value = state.phase;
ui.rpmRange.value = state.rpm;
ui.phaseRange.style.setProperty("--fill", `${(state.phase / 355) * 100}%`);
ui.rpmRange.style.setProperty("--fill", `${(state.rpm / 120) * 100}%`);
ui.phaseCheck.classList.toggle("pass", checks.phase);
ui.speedCheck.classList.toggle("pass", checks.speed);
ui.typeCheck.classList.toggle("pass", checks.type);
ui.phaseDelta.textContent = checks.phase
? `Δ ${checks.phaseDiff}°`
: `Δ ${checks.phaseDiff}°`;
ui.speedDelta.textContent = `Δ ${checks.speedDiff} RPM`;
ui.typeDelta.textContent = checks.type ? "Compatible" : "Mismatch";
ui.stateBadge.className = "state-badge";
if (state.mode === "success") {
ui.stateBadge.textContent = "Locked";
ui.stateBadge.classList.add("pass");
} else if (state.mode === "reject") {
ui.stateBadge.textContent = "Rejected";
ui.stateBadge.classList.add("fail");
} else if (checks.all) {
ui.stateBadge.textContent = "Ready";
ui.stateBadge.classList.add("pass");
} else {
const failed = [!checks.phase, !checks.speed, !checks.type].filter(Boolean).length;
ui.stateBadge.textContent = `${failed} Failed`;
ui.stateBadge.classList.add("fail");
}
ui.readout.textContent = checks.all
? "All three interlocks are satisfied. The coupling will lock without impact."
: "Match the manifest before attempting engagement. Invalid combinations will trigger a mechanical lockout.";
ui.engageButton.classList.toggle("ready", checks.all);
ui.engageButton.disabled = state.engaged || state.mode === "reject";
ui.nextButton.hidden = !state.engaged;
if (state.engaged) {
ui.engageButton.textContent = "Coupling locked";
} else if (state.mode === "reject") {
ui.engageButton.textContent = "Rejected — resetting";
} else {
ui.engageButton.textContent = "Attempt engagement";
}
ui.levelText.textContent = `${pad(state.level + 1)} / ${pad(levels.length)}`;
[...ui.progress.children].forEach((item, index) => {
item.classList.toggle("active", index === state.level);
item.classList.toggle("done", index < state.level);
});
profileButtons.forEach(button => {
button.classList.toggle("selected", button.dataset.type === state.type);
});
ui.phaseRange.disabled = state.engaged;
ui.rpmRange.disabled = state.engaged;
profileButtons.forEach(button => {
button.disabled = state.engaged;
});
setLed(ledMaterials[0], checks.phase);
setLed(ledMaterials[1], checks.speed);
setLed(ledMaterials[2], checks.type);
if (state.mode === "success") {
beaconMaterial.color.setHex(0x77e69a);
beaconMaterial.emissive.setHex(0x77e69a);
beaconMaterial.emissiveIntensity = 0.8;
} else if (state.mode === "reject") {
beaconMaterial.color.setHex(0xff6b67);
beaconMaterial.emissive.setHex(0xff6b67);
beaconMaterial.emissiveIntensity = 0.9;
} else {
beaconMaterial.color.setHex(0xf4c35e);
beaconMaterial.emissive.setHex(0xf4c35e);
beaconMaterial.emissiveIntensity = 0.45;
}
}
let toastTimer = 0;
function showToast(title, detail, kind = "") {
clearTimeout(toastTimer);
ui.toastTitle.textContent = title;
ui.toastDetail.textContent = detail;
ui.toast.className = `toast visible ${kind}`;
toastTimer = setTimeout(() => {
ui.toast.classList.remove("visible");
}, 3200);
}
function flashScreen(good = false) {
ui.flash.classList.remove("active", "good");
void ui.flash.offsetWidth;
ui.flash.classList.add("active");
if (good) ui.flash.classList.add("good");
}
const particles = [];
const particleGeometry = unitBox;
const successParticleMaterial = standard(0x77e69a, 0.2, 0.3, 0x2e7e49);
const errorParticleMaterial = standard(0xff6b67, 0.2, 0.3, 0x7d2421);
function spawnParticles(success) {
const material = success ? successParticleMaterial : errorParticleMaterial;
for (let i = 0; i < 34; i++) {
const mesh = new THREE.Mesh(particleGeometry, material);
const size = 0.045 + Math.random() * 0.075;
mesh.scale.setScalar(size);
mesh.position.set(
(Math.random() - 0.5) * 0.7,
shaftY + (Math.random() - 0.3) * 0.7,
(Math.random() - 0.5) * 0.9
);
scene.add(mesh);
const angle = Math.random() * Math.PI * 2;
const speed = 0.8 + Math.random() * 2.2;
particles.push({
mesh,
size,
life: 0.65 + Math.random() * 0.75,
maxLife: 1.4,
velocity: new THREE.Vector3(
Math.cos(angle) * speed,
0.8 + Math.random() * 2,
Math.sin(angle) * speed
)
});
}
}
function updateParticles(dt) {
for (let i = particles.length - 1; i >= 0; i--) {
const p = particles[i];
p.life -= dt;
p.velocity.y -= 3.2 * dt;
p.mesh.position.addScaledVector(p.velocity, dt);
p.mesh.rotation.x += dt * 5;
p.mesh.rotation.z += dt * 4;
p.mesh.scale.setScalar(p.size * Math.max(0, p.life / p.maxLife));
if (p.life <= 0) {
scene.remove(p.mesh);
particles.splice(i, 1);
}
}
}
function loadLevel(index) {
state.level = (index + levels.length) % levels.length;
state.phase = 0;
state.rpm = 30;
state.type = levels[state.level].type === "6T" ? "8T" : "6T";
state.mode = "ready";
state.engaged = false;
state.levelAttempts = 0;
state.couplingSpin = 0;
state.rejectToken++;
leftCoupler.root.position.x = -0.72;
rightCoupler.root.position.x = 0.72;
setTypeVisibility(leftCoupler, state.type);
setTypeVisibility(rightCoupler, target().type);
updateUI();
showToast(
`Manifest ${pad(state.level + 1)} loaded`,
`Match ${pad(target().phase)}° phase, ${pad(target().rpm)} RPM, and ${typeData[target().type].label}.`
);
}
function attemptEngagement() {
if (state.engaged || state.mode === "reject") return;
const checks = getChecks();
state.attempts++;
state.levelAttempts++;
if (!checks.all) {
const failures = [];
if (!checks.phase) failures.push(`PHASE Δ ${checks.phaseDiff}°`);
if (!checks.speed) failures.push(`SPEED Δ ${checks.speedDiff} RPM`);
if (!checks.type) {
failures.push(
`${typeData[state.type].short} ≠ ${typeData[target().type].short}`
);
}
state.mode = "reject";
state.rejectStart = performance.now();
const token = ++state.rejectToken;
flashScreen(false);
spawnParticles(false);
showToast(
"Engagement rejected",
failures.join(" • "),
"error"
);
updateUI();
setTimeout(() => {
if (token !== state.rejectToken || state.mode !== "reject") return;
state.mode = "ready";
updateUI();
}, 900);
return;
}
state.mode = "success";
state.engaged = true;
flashScreen(true);
spawnParticles(true);
showToast(
"Engagement accepted",
"All interlocks passed. The voxel coupling is locked and synchronized.",
"success"
);
updateUI();
}
ui.phaseRange.addEventListener("input", event => {
if (state.engaged) return;
state.phase = Number(event.target.value);
updateUI();
});
ui.rpmRange.addEventListener("input", event => {
if (state.engaged) return;
state.rpm = Number(event.target.value);
updateUI();
});
profileButtons.forEach(button => {
button.addEventListener("click", () => {
if (state.engaged) return;
state.type = button.dataset.type;
setTypeVisibility(leftCoupler, state.type);
updateUI();
});
});
ui.engageButton.addEventListener("click", attemptEngagement);
ui.resetButton.addEventListener("click", () => loadLevel(state.level));
ui.nextButton.addEventListener("click", () => loadLevel(state.level + 1));
// Direct camera controls: orbit, zoom, and recenter.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.48, 1.36);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
8.5,
20
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => {
orbit.theta = 0.68;
orbit.phi = 1.03;
orbit.radius = 13.7;
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const inputAnchor = new THREE.Vector3(-4.65, 2.85, 0);
const outputAnchor = new THREE.Vector3(4.65, 2.85, 0);
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
loadLevel(0);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const t = clock.elapsedTime;
leftRotor.rotation.x += state.rpm * dt * 0.085;
rightRotor.rotation.x -= target().rpm * dt * 0.07;
if (state.engaged) {
const commonSpeed = (state.rpm + target().rpm) * 0.5;
state.couplingSpin += commonSpeed * dt * 0.085;
}
leftCoupler.root.rotation.x =
THREE.MathUtils.degToRad(state.phase) + state.couplingSpin;
rightCoupler.root.rotation.x =
THREE.MathUtils.degToRad(target().phase) + state.couplingSpin;
if (state.engaged) {
leftCoupler.root.position.x = THREE.MathUtils.lerp(
leftCoupler.root.position.x,
-0.3,
1 - Math.pow(0.001, dt)
);
rightCoupler.root.position.x = THREE.MathUtils.lerp(
rightCoupler.root.position.x,
0.3,
1 - Math.pow(0.001, dt)
);
mechanism.position.x = 0;
} else if (state.mode === "reject") {
const progress = THREE.MathUtils.clamp(
(performance.now() - state.rejectStart) / 900,
0,
1
);
const bump = Math.sin(progress * Math.PI);
const shake = Math.sin(progress * Math.PI * 12) * 0.045 * bump;
leftCoupler.root.position.x = -0.72 + bump * 0.16;
rightCoupler.root.position.x = 0.72 - bump * 0.16;
mechanism.position.x = shake;
} else {
leftCoupler.root.position.x = THREE.MathUtils.lerp(
leftCoupler.root.position.x,
-0.72,
1 - Math.pow(0.001, dt)
);
rightCoupler.root.position.x = THREE.MathUtils.lerp(
rightCoupler.root.position.x,
0.72,
1 - Math.pow(0.001, dt)
);
mechanism.position.x = 0;
}
updateParticles(dt);
positionLabel(ui.inputLabel, inputAnchor);
positionLabel(ui.outputLabel, outputAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```