Prompt specification
Build or customize the Three.js 3D scene "Redesign a Confusing Assembly Step" 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: Redesign a Confusing Assembly Step
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/redesign-a-confusing-assembly-step-x2028
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts keyed connectors for unambiguous assembly. Create a puzzle where users choose one geometry change that prevents an observed mistake. Verify the corrected fit and preserve the valid assembly path. Low-poly.
Working Three.js Starter (redesign-a-confusing-assembly-step-x2028):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Form / Fit — Keyed Connector Lab</title>
<style>
:root {
--bg: #07111e;
--panel: #0c1726;
--panel-2: #111f31;
--line: #24364b;
--text: #eef5fb;
--muted: #8fa3b8;
--teal: #58d4cb;
--orange: #f39a62;
--gold: #f4c85a;
--red: #ff5a6b;
--green: #62e6a5;
--amber: #ffbf69;
}
* {
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;
}
#app {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
background:
radial-gradient(circle at 25% 15%, rgba(40, 115, 126, 0.16), transparent 36%),
var(--bg);
}
header {
height: 72px;
flex: 0 0 72px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 30, 0.94);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 36px;
height: 36px;
display: grid;
place-items: center;
border: 1px solid rgba(88, 212, 203, 0.55);
color: var(--teal);
font-size: 21px;
transform: rotate(45deg);
border-radius: 7px;
box-shadow: inset 0 0 18px rgba(88, 212, 203, 0.08);
}
.brand-mark span {
transform: rotate(-45deg);
}
.brand strong {
display: block;
font-size: 14px;
letter-spacing: 0.18em;
}
.brand small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.14em;
}
.steps {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.1em;
}
.step {
display: flex;
align-items: center;
gap: 7px;
}
.step i {
width: 22px;
height: 22px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
font-style: normal;
font-size: 10px;
}
.step.active {
color: var(--text);
}
.step.active i {
border-color: var(--teal);
color: var(--teal);
background: rgba(88, 212, 203, 0.08);
}
.step-line {
width: 38px;
height: 1px;
background: var(--line);
}
main {
min-height: 0;
flex: 1;
display: flex;
}
#stage {
position: relative;
min-width: 0;
flex: 1;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, rgba(31, 74, 89, 0.22), transparent 45%),
linear-gradient(180deg, #081422, #07111e);
}
canvas.webgl {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas.webgl:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
z-index: 5;
}
.scene-id {
display: flex;
align-items: center;
gap: 9px;
color: #b9c9d8;
font-size: 10px;
letter-spacing: 0.14em;
}
.scene-id .pulse {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 14px var(--teal);
}
.view-tools {
display: flex;
gap: 8px;
pointer-events: auto;
}
.tool-button {
border: 1px solid rgba(143, 163, 184, 0.25);
background: rgba(7, 17, 30, 0.66);
color: #b9c9d8;
border-radius: 7px;
padding: 8px 11px;
cursor: pointer;
font-size: 10px;
letter-spacing: 0.08em;
backdrop-filter: blur(8px);
}
.tool-button:hover {
border-color: rgba(88, 212, 203, 0.55);
color: white;
}
.candidate-badge {
position: absolute;
top: 62px;
left: 22px;
z-index: 5;
display: none;
align-items: center;
gap: 8px;
border: 1px solid rgba(244, 200, 90, 0.3);
border-radius: 6px;
padding: 8px 10px;
background: rgba(20, 26, 31, 0.72);
color: var(--gold);
font-size: 10px;
letter-spacing: 0.08em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.candidate-badge.visible {
display: flex;
}
.candidate-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 10px var(--gold);
}
.scene-label {
position: absolute;
z-index: 6;
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
font-size: 9px;
letter-spacing: 0.12em;
color: #b9c9d8;
text-shadow: 0 2px 8px #000;
}
.scene-label::after {
content: "";
display: block;
width: 1px;
height: 22px;
margin: 6px auto 0;
background: linear-gradient(rgba(185, 201, 216, 0.65), transparent);
}
.scene-label.receiver {
color: var(--teal);
}
.scene-label.plug {
color: var(--orange);
}
.scene-label.error {
color: var(--red);
}
.scene-label.path {
color: #8fb6d3;
}
.scene-label.success {
color: var(--green);
}
.stage-bottom {
position: absolute;
left: 22px;
right: 22px;
bottom: 18px;
z-index: 5;
display: flex;
align-items: flex-end;
justify-content: space-between;
pointer-events: none;
}
.legend {
display: flex;
gap: 14px;
flex-wrap: wrap;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.07em;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
display: inline-block;
}
.camera-hint {
color: #71869c;
font-size: 9px;
letter-spacing: 0.08em;
text-align: right;
}
aside {
width: 400px;
flex: 0 0 400px;
min-height: 0;
overflow-y: auto;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(17, 31, 49, 0.95), rgba(9, 20, 33, 0.98));
z-index: 10;
scrollbar-width: thin;
scrollbar-color: #2a4057 transparent;
}
.panel-inner {
padding: 24px;
}
.eyebrow {
color: var(--teal);
font-size: 10px;
letter-spacing: 0.17em;
font-weight: 700;
}
h1 {
margin: 8px 0 9px;
font-size: 27px;
line-height: 1.12;
letter-spacing: -0.03em;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.issue-card {
margin-top: 20px;
padding: 14px;
border: 1px solid rgba(255, 90, 107, 0.3);
border-left: 3px solid var(--red);
border-radius: 8px;
background: rgba(255, 90, 107, 0.055);
}
.issue-title {
display: flex;
align-items: center;
justify-content: space-between;
color: #ff9aa5;
font-size: 10px;
letter-spacing: 0.12em;
font-weight: 700;
}
.issue-code {
color: #9b5a63;
font-size: 9px;
}
.issue-card p {
margin: 10px 0 12px;
color: #c9b7bb;
font-size: 12px;
line-height: 1.5;
}
.text-button {
border: 0;
padding: 0;
color: #ff9aa5;
background: transparent;
cursor: pointer;
font-size: 11px;
}
.text-button:hover {
color: white;
}
.section-title {
margin: 24px 0 10px;
display: flex;
align-items: center;
justify-content: space-between;
color: #c8d5e2;
font-size: 11px;
letter-spacing: 0.08em;
font-weight: 700;
}
.section-title span {
color: #61758b;
font-size: 9px;
font-weight: 500;
}
.options {
display: grid;
gap: 9px;
}
.option {
width: 100%;
display: grid;
grid-template-columns: 30px 1fr 18px;
gap: 10px;
align-items: center;
text-align: left;
padding: 13px 12px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--text);
background: rgba(9, 19, 31, 0.62);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.option:hover {
border-color: #3c566f;
transform: translateY(-1px);
}
.option.selected {
border-color: rgba(88, 212, 203, 0.72);
background: rgba(88, 212, 203, 0.075);
}
.option-number {
color: #657b92;
font-size: 10px;
letter-spacing: 0.08em;
}
.option.selected .option-number {
color: var(--teal);
}
.option strong {
display: block;
font-size: 12px;
line-height: 1.35;
}
.option small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.radio {
width: 15px;
height: 15px;
border: 1px solid #455c74;
border-radius: 50%;
position: relative;
}
.option.selected .radio {
border-color: var(--teal);
}
.option.selected .radio::after {
content: "";
position: absolute;
inset: 3px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 8px rgba(88, 212, 203, 0.6);
}
.actions {
margin-top: 18px;
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
}
.primary-button {
min-height: 46px;
border: 0;
border-radius: 8px;
padding: 0 18px;
color: #061318;
background: var(--teal);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.03em;
cursor: pointer;
box-shadow: 0 8px 24px rgba(88, 212, 203, 0.13);
transition:
opacity 160ms ease,
transform 160ms ease;
}
.primary-button:hover:not(:disabled) {
transform: translateY(-1px);
}
.primary-button:disabled {
opacity: 0.34;
cursor: not-allowed;
box-shadow: none;
}
.reset-button {
width: 46px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--muted);
background: rgba(9, 19, 31, 0.62);
cursor: pointer;
font-size: 18px;
}
.reset-button:hover {
border-color: #3c566f;
color: white;
}
.result {
margin-top: 16px;
display: none;
padding: 15px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(6, 15, 27, 0.58);
}
.result.visible {
display: grid;
grid-template-columns: 32px 1fr;
gap: 11px;
animation: result-in 260ms ease-out;
}
@keyframes result-in {
from {
opacity: 0;
transform: translateY(6px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.result.success {
border-color: rgba(98, 230, 165, 0.42);
background: rgba(98, 230, 165, 0.055);
}
.result.fail {
border-color: rgba(255, 90, 107, 0.38);
background: rgba(255, 90, 107, 0.045);
}
.result.warning {
border-color: rgba(255, 191, 105, 0.4);
background: rgba(255, 191, 105, 0.05);
}
.result-icon {
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 50%;
font-size: 15px;
font-weight: 900;
}
.success .result-icon {
color: var(--green);
background: rgba(98, 230, 165, 0.12);
}
.fail .result-icon {
color: var(--red);
background: rgba(255, 90, 107, 0.12);
}
.warning .result-icon {
color: var(--amber);
background: rgba(255, 191, 105, 0.12);
}
.result strong {
display: block;
font-size: 13px;
}
.result p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.metrics {
margin-top: 20px;
border-top: 1px solid var(--line);
padding-top: 16px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px 8px;
border: 1px solid rgba(143, 163, 184, 0.13);
border-radius: 7px;
background: rgba(5, 13, 24, 0.32);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: #63778d;
font-size: 8px;
letter-spacing: 0.12em;
}
.metric-value {
display: block;
overflow: hidden;
color: #c7d5e2;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
text-overflow: ellipsis;
}
.metric-value.good {
color: var(--green);
}
.metric-value.bad {
color: var(--red);
}
.metric-value.warn {
color: var(--amber);
}
@media (max-width: 850px) {
html,
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100%;
}
header {
padding: 0 15px;
}
.steps {
display: none;
}
main {
flex-direction: column;
}
#stage {
flex: none;
width: 100%;
height: 58vh;
min-height: 430px;
}
aside {
width: 100%;
flex: none;
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark"><span>◇</span></div>
<div>
<strong>FORM / FIT</strong>
<small>KEYED CONNECTOR LAB</small>
</div>
</div>
<div class="steps" aria-label="Puzzle progress">
<div class="step"><i>1</i> DIAGNOSE</div>
<div class="step-line"></div>
<div class="step active"><i>2</i> CHANGE</div>
<div class="step-line"></div>
<div class="step"><i>3</i> VERIFY</div>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive 3D connector assembly">
<div class="stage-top">
<div class="scene-id">
<span class="pulse"></span>
LIVE GEOMETRY / KC-07
</div>
<div class="view-tools">
<button class="tool-button" id="cameraReset" type="button">
RESET VIEW
</button>
</div>
</div>
<div class="candidate-badge" id="candidateBadge">
CANDIDATE GEOMETRY APPLIED
</div>
<div class="scene-label receiver" id="receiverLabel">
RECEIVER / INDEXED SOCKET
</div>
<div class="scene-label plug" id="plugLabel">
DRIVE PLUG
</div>
<div class="scene-label error" id="errorLabel">
OBSERVED CONTACT
</div>
<div class="scene-label path" id="pathLabel">
VALID INSERTION PATH
</div>
<div class="scene-label success" id="successLabel">
FIT VERIFIED
</div>
<div class="stage-bottom">
<div class="legend">
<span><i style="background:#25828a"></i>RECEIVER</span>
<span><i style="background:#d8713f"></i>PLUG</span>
<span><i style="background:#f4c85a"></i>DRIVE KEY</span>
<span><i style="background:#ff5a6b"></i>INTERFERENCE</span>
</div>
<div class="camera-hint">
DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET
</div>
</div>
</section>
<aside>
<div class="panel-inner">
<div class="eyebrow">DIAGNOSTIC / E-17</div>
<h1>The key meets the wrong wall.</h1>
<p class="intro">
During insertion, the gold drive key contacts a raised stop.
Change one feature so the plug can seat without losing its
keyed orientation.
</p>
<div class="issue-card">
<div class="issue-title">
<span>OBSERVED MISTAKE</span>
<span class="issue-code">CONTACT AT 38 MM</span>
</div>
<p>
The original key is offset from the receiver channel. The
straight assembly path is interrupted before the plug reaches
its seat.
</p>
<button class="text-button" id="replayBtn" type="button">
↻ Replay observed contact
</button>
</div>
<div class="section-title">
<div>CHOOSE ONE GEOMETRY CHANGE</div>
<span>ONLY ONE IS ACCEPTED</span>
</div>
<div class="options" role="radiogroup" aria-label="Geometry changes">
<button
class="option"
type="button"
role="radio"
aria-checked="false"
data-option="relocate"
>
<span class="option-number">01</span>
<span>
<strong>Translate key to the indexed channel</strong>
<small>Move the gold drive key 43 mm to its matching guide.</small>
</span>
<span class="radio"></span>
</button>
<button
class="option"
type="button"
role="radio"
aria-checked="false"
data-option="raise"
>
<span class="option-number">02</span>
<span>
<strong>Raise key above the interference stop</strong>
<small>Lift the key 35 mm while leaving its index position.</small>
</span>
<span class="radio"></span>
</button>
<button
class="option"
type="button"
role="radio"
aria-checked="false"
data-option="widen"
>
<span class="option-number">03</span>
<span>
<strong>Widen the upper opening</strong>
<small>Remove clearance restrictions around the original key.</small>
</span>
<span class="radio"></span>
</button>
</div>
<div class="actions">
<button class="primary-button" id="verifyBtn" type="button" disabled>
APPLY CHANGE & VERIFY FIT
</button>
<button class="reset-button" id="resetBtn" type="button" title="Reset">
↺
</button>
</div>
<div class="result" id="resultPanel" aria-live="polite">
<div class="result-icon" id="resultIcon">✓</div>
<div>
<strong id="resultTitle"></strong>
<p id="resultText"></p>
</div>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">CONTACT</span>
<span class="metric-value bad" id="metricContact">1 collision</span>
</div>
<div class="metric">
<span class="metric-label">INDEXING</span>
<span class="metric-value" id="metricIndex">Polarized</span>
</div>
<div class="metric">
<span class="metric-label">PATH</span>
<span class="metric-value" id="metricPath">Straight</span>
</div>
</div>
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const verifyButton = document.getElementById("verifyBtn");
const resetButton = document.getElementById("resetBtn");
const replayButton = document.getElementById("replayBtn");
const cameraResetButton = document.getElementById("cameraReset");
const resultPanel = document.getElementById("resultPanel");
const resultIcon = document.getElementById("resultIcon");
const resultTitle = document.getElementById("resultTitle");
const resultText = document.getElementById("resultText");
const candidateBadge = document.getElementById("candidateBadge");
const metricContact = document.getElementById("metricContact");
const metricIndex = document.getElementById("metricIndex");
const metricPath = document.getElementById("metricPath");
const receiverLabel = document.getElementById("receiverLabel");
const plugLabel = document.getElementById("plugLabel");
const errorLabel = document.getElementById("errorLabel");
const pathLabel = document.getElementById("pathLabel");
const successLabel = document.getElementById("successLabel");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111e);
scene.fog = new THREE.FogExp2(0x07111e, 0.027);
const camera = new THREE.PerspectiveCamera(
39,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.className = "webgl";
renderer.domElement.setAttribute(
"aria-label",
"3D keyed connector assembly. Drag to orbit and scroll to zoom."
);
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xb9e8ff,
0x14202b,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d3, 4.1);
keyLight.position.set(3.5, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4cc9c3, 2.2);
rimLight.position.set(-5, 2.5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8b54, 16, 8, 2);
warmLight.position.set(3, 0.8, 3);
scene.add(warmLight);
const cameraTarget = new THREE.Vector3(0, -0.08, 0);
const cameraState = {
radius: 8.3,
theta: 0.72,
phi: 1.06
};
const defaultCamera = {
radius: 8.3,
theta: 0.72,
phi: 1.06
};
function updateCamera() {
const { radius, theta, phi } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Low-poly materials.
const receiverMaterial = new THREE.MeshStandardMaterial({
color: 0x247b84,
roughness: 0.68,
metalness: 0.36,
flatShading: true
});
const receiverDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x123d49,
roughness: 0.76,
metalness: 0.42,
flatShading: true
});
const interiorMaterial = new THREE.MeshStandardMaterial({
color: 0x081923,
roughness: 0.92,
metalness: 0.15
});
const plugMaterial = new THREE.MeshStandardMaterial({
color: 0xd87342,
roughness: 0.62,
metalness: 0.42,
flatShading: true
});
const plugDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x713721,
roughness: 0.76,
metalness: 0.5,
flatShading: true
});
const steelMaterial = new THREE.MeshStandardMaterial({
color: 0x9cafbd,
roughness: 0.48,
metalness: 0.75,
flatShading: true
});
const guideMaterial = new THREE.MeshStandardMaterial({
color: 0x657f91,
roughness: 0.52,
metalness: 0.68,
flatShading: true
});
const keyMaterial = new THREE.MeshStandardMaterial({
color: 0xf4c85a,
roughness: 0.38,
metalness: 0.62,
flatShading: true,
emissive: 0x4b3105,
emissiveIntensity: 0.18
});
const ribMaterial = new THREE.MeshStandardMaterial({
color: 0xff5264,
roughness: 0.55,
metalness: 0.34,
flatShading: true,
emissive: 0x5c0c16,
emissiveIntensity: 0.34
});
const errorMaterial = new THREE.MeshBasicMaterial({
color: 0xff5264,
transparent: true,
opacity: 0.95
});
const successMaterial = new THREE.MeshBasicMaterial({
color: 0x62e6a5,
transparent: true,
opacity: 0.95
});
const slotHighlightMaterial = new THREE.MeshBasicMaterial({
color: 0xf4c85a,
transparent: true,
opacity: 0.18,
depthWrite: false
});
function addEdges(mesh, color = 0xb5d8df, opacity = 0.25) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 25),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return mesh;
}
function makeBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
outlined = false
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) addEdges(mesh);
return mesh;
}
// Ground and low-poly stage.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.96,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.68;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(4.5, 4.75, 0.14, 12),
new THREE.MeshStandardMaterial({
color: 0x102437,
roughness: 0.82,
metalness: 0.35,
flatShading: true
})
);
platform.position.y = -1.59;
platform.receiveShadow = true;
addEdges(platform, 0x376075, 0.18);
scene.add(platform);
const grid = new THREE.GridHelper(16, 32, 0x315069, 0x193146);
grid.position.y = -1.505;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
// Receiver: an open, box-built socket.
const receiver = new THREE.Group();
scene.add(receiver);
makeBox(0.24, 2.16, 2.16, receiverDarkMaterial, -2.05, 0, 0, receiver, true);
makeBox(1.62, 0.28, 2.16, receiverMaterial, -1.24, 0.94, 0, receiver, true);
makeBox(1.62, 0.28, 2.16, receiverMaterial, -1.24, -0.94, 0, receiver, true);
makeBox(1.62, 1.58, 0.28, receiverMaterial, -1.24, 0, 0.94, receiver, true);
makeBox(1.62, 1.58, 0.28, receiverMaterial, -1.24, 0, -0.94, receiver, true);
makeBox(0.08, 1.58, 1.58, interiorMaterial, -1.9, 0, 0, receiver);
// Front collar.
makeBox(0.22, 0.28, 1.84, receiverDarkMaterial, -0.43, 0.78, 0, receiver, true);
makeBox(0.22, 0.28, 1.84, receiverDarkMaterial, -0.43, -0.78, 0, receiver, true);
makeBox(0.22, 1.3, 0.25, receiverDarkMaterial, -0.43, 0, 0.79, receiver, true);
makeBox(0.22, 1.3, 0.25, receiverDarkMaterial, -0.43, 0, -0.79, receiver, true);
// Receiver channel: two guide rails define the correct keyed path.
const guideA = makeBox(
0.25,
0.25,
0.22,
guideMaterial,
-0.34,
0.52,
-0.68,
receiver,
true
);
const guideB = makeBox(
0.25,
0.25,
0.22,
guideMaterial,
-0.34,
0.52,
-0.18,
receiver,
true
);
// Raised stop that the original key incorrectly encounters.
const interferenceRib = makeBox(
0.22,
0.24,
0.24,
ribMaterial,
-0.38,
0.52,
0.08,
receiver,
true
);
// Receiver fasteners.
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2 + Math.PI / 8;
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.065, 0.08, 6),
steelMaterial
);
bolt.rotation.z = Math.PI / 2;
bolt.position.set(
-0.285,
Math.cos(angle) * 0.81,
Math.sin(angle) * 0.81
);
bolt.castShadow = true;
receiver.add(bolt);
}
// Small mounting feet.
makeBox(0.42, 0.35, 0.52, receiverDarkMaterial, -1.75, -1.27, 0.48, receiver, true);
makeBox(0.42, 0.35, 0.52, receiverDarkMaterial, -0.85, -1.27, -0.48, receiver, true);
// Plug assembly.
const plug = new THREE.Group();
scene.add(plug);
const plugBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.74, 0.78, 1.5, 8),
plugMaterial
);
plugBody.rotation.z = Math.PI / 2;
plugBody.position.set(1.1, 0, 0);
plugBody.castShadow = true;
plugBody.receiveShadow = true;
addEdges(plugBody, 0xffb080, 0.28);
plug.add(plugBody);
const plugFlange = new THREE.Mesh(
new THREE.CylinderGeometry(0.86, 0.86, 0.16, 8),
plugDarkMaterial
);
plugFlange.rotation.z = Math.PI / 2;
plugFlange.position.set(0.31, 0, 0);
plugFlange.castShadow = true;
addEdges(plugFlange, 0xffa46d, 0.25);
plug.add(plugFlange);
const driveShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.3, 0.34, 1.35, 8),
steelMaterial
);
driveShaft.rotation.z = Math.PI / 2;
driveShaft.position.set(2.3, 0, 0);
driveShaft.castShadow = true;
addEdges(driveShaft, 0xdceaf4, 0.22);
plug.add(driveShaft);
const shaftEnd = new THREE.Mesh(
new THREE.CylinderGeometry(0.44, 0.44, 0.13, 8),
plugDarkMaterial
);
shaftEnd.rotation.z = Math.PI / 2;
shaftEnd.position.set(3.0, 0, 0);
shaftEnd.castShadow = true;
plug.add(shaftEnd);
const driveKey = makeBox(
0.5,
0.18,
0.16,
keyMaterial,
0.1,
0.52,
0,
plug,
true
);
// Plug fasteners.
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2 + Math.PI / 8;
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.062, 0.07, 6),
steelMaterial
);
bolt.rotation.z = Math.PI / 2;
bolt.position.set(
0.205,
Math.cos(angle) * 0.69,
Math.sin(angle) * 0.69
);
bolt.castShadow = true;
plug.add(bolt);
}
// Highlight for the indexed channel, revealed by the correct candidate.
const channelHighlight = new THREE.Mesh(
new THREE.BoxGeometry(0.66, 0.205, 0.27),
slotHighlightMaterial
);
channelHighlight.position.set(-0.64, 0.52, -0.43);
channelHighlight.visible = false;
receiver.add(channelHighlight);
// Visible interference marker.
const errorMarker = new THREE.Group();
const errorRing = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.025, 6, 24),
errorMaterial
);
errorRing.rotation.y = Math.PI / 2;
errorMarker.add(errorRing);
const errorLight = new THREE.PointLight(0xff4058, 2.6, 2.1, 2);
errorMarker.add(errorLight);
errorMarker.position.set(-0.27, 0.54, 0.08);
scene.add(errorMarker);
// Successful seat marker.
const successMarker = new THREE.Group();
const successRing = new THREE.Mesh(
new THREE.TorusGeometry(0.91, 0.022, 6, 40),
successMaterial
);
successRing.rotation.y = Math.PI / 2;
successMarker.add(successRing);
successMarker.position.set(-0.5, 0, 0);
successMarker.visible = false;
scene.add(successMarker);
// Straight-line assembly path.
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(1.62, 1.22, 0),
new THREE.Vector3(-1.05, 1.22, 0)
]);
const pathMaterial = new THREE.LineDashedMaterial({
color: 0x75aeca,
dashSize: 0.13,
gapSize: 0.075,
transparent: true,
opacity: 0.8
});
const pathLine = new THREE.Line(pathGeometry, pathMaterial);
pathLine.computeLineDistances();
scene.add(pathLine);
const pathArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(1.62, 1.22, 0),
2.67,
0x75aeca,
0.18,
0.1
);
scene.add(pathArrow);
// A faint exploded assembly axis.
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.45, 0, 0),
new THREE.Vector3(3.18, 0, 0)
]);
const axisLine = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x355068,
dashSize: 0.08,
gapSize: 0.08,
transparent: true,
opacity: 0.45
})
);
axisLine.computeLineDistances();
scene.add(axisLine);
const INITIAL_PLUG_X = 1.15;
const SEATED_PLUG_X = -0.75;
plug.position.x = INITIAL_PLUG_X;
let selectedOption = null;
let animation = null;
const optionButtons = [...document.querySelectorAll(".option")];
function setMetric(element, text, state = "") {
element.textContent = text;
element.className = `metric-value${state ? ` ${state}` : ""}`;
}
function resetMetrics() {
setMetric(metricContact, "1 collision", "bad");
setMetric(metricIndex, "Polarized");
setMetric(metricPath, "Straight");
}
function resetPathColor() {
pathMaterial.color.set(0x75aeca);
pathMaterial.opacity = 0.8;
pathArrow.setColor(0x75aeca);
}
function resetGeometry() {
driveKey.position.set(0.1, 0.52, 0);
driveKey.scale.set(1, 1, 1);
interferenceRib.visible = true;
interferenceRib.position.set(-0.38, 0.52, 0.08);
ribMaterial.color.set(0xff5264);
ribMaterial.emissive.set(0x5c0c16);
guideA.position.z = -0.68;
guideB.position.z = -0.18;
guideMaterial.color.set(0x657f91);
guideMaterial.emissive.set(0x000000);
channelHighlight.visible = false;
successMarker.visible = false;
errorMarker.visible = true;
errorMarker.position.set(-0.27, 0.54, 0.08);
errorMaterial.color.set(0xff5264);
plug.position.x = INITIAL_PLUG_X;
resetPathColor();
resetMetrics();
}
function applyOption(option) {
resetGeometry();
if (option === "relocate") {
driveKey.position.z = -0.43;
channelHighlight.visible = true;
guideMaterial.color.set(0xc6a75a);
guideMaterial.emissive.set(0x332708);
errorMarker.visible = false;
} else if (option === "raise") {
driveKey.position.y = 0.87;
errorMarker.visible = false;
} else if (option === "widen") {
interferenceRib.visible = false;
guideB.position.z = 0.28;
guideMaterial.color.set(0x9d8760);
errorMarker.visible = false;
}
}
function clearSelection() {
selectedOption = null;
for (const button of optionButtons) {
button.classList.remove("selected");
button.setAttribute("aria-checked", "false");
}
candidateBadge.classList.remove("visible");
verifyButton.disabled = true;
verifyButton.textContent = "APPLY CHANGE & VERIFY FIT";
resultPanel.className = "result";
resetGeometry();
}
function chooseOption(option) {
if (animation) return;
selectedOption = option;
for (const button of optionButtons) {
const active = button.dataset.option === option;
button.classList.toggle("selected", active);
button.setAttribute("aria-checked", String(active));
}
applyOption(option);
candidateBadge.classList.add("visible");
verifyButton.disabled = false;
resultPanel.className = "result";
}
function showResult(type, icon, title, text) {
resultPanel.className = `result visible ${type}`;
resultIcon.textContent = icon;
resultTitle.textContent = title;
resultText.textContent = text;
}
function showErrorAt(position) {
errorMarker.visible = true;
errorMarker.position.copy(position);
errorMaterial.color.set(0xff5264);
}
function easeInOut(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function startVerification() {
if (!selectedOption || animation) return;
applyOption(selectedOption);
resultPanel.className = "result";
verifyButton.disabled = true;
verifyButton.textContent = "CHECKING ASSEMBLY PATH…";
animation = {
kind: "verify",
option: selectedOption,
start: performance.now(),
duration: 1750,
hitShown: false
};
}
function startReplay() {
if (animation) return;
const savedOption = selectedOption;
resetGeometry();
resultPanel.className = "result";
verifyButton.disabled = true;
replayButton.disabled = true;
animation = {
kind: "replay",
option: savedOption,
start: performance.now(),
duration: 2550,
hitShown: false
};
}
function finishVerification() {
if (animation.option === "relocate") {
successMarker.visible = true;
errorMarker.visible = false;
ribMaterial.color.set(0x607d8b);
ribMaterial.emissive.set(0x000000);
guideMaterial.color.set(0xc6a75a);
guideMaterial.emissive.set(0x332708);
channelHighlight.visible = true;
pathMaterial.color.set(0x62e6a5);
pathMaterial.opacity = 1;
pathArrow.setColor(0x62e6a5);
setMetric(metricContact, "0 contacts", "good");
setMetric(metricIndex, "1 orientation", "good");
setMetric(metricPath, "Clear / straight", "good");
showResult(
"success",
"✓",
"Fit verified",
"The relocated key enters its indexed channel, clears the stop, and seats at 0 mm. The straight assembly path remains unobstructed."
);
verifyButton.textContent = "VERIFIED SOLUTION";
verifyButton.disabled = true;
} else if (animation.option === "raise") {
pathMaterial.color.set(0xff5a6b);
pathMaterial.opacity = 0.95;
pathArrow.setColor(0xff5a6b);
setMetric(metricContact, "Stopped early", "bad");
setMetric(metricIndex, "Not engaged", "bad");
setMetric(metricPath, "Blocked", "bad");
showResult(
"fail",
"!",
"Keyway not engaged",
"Raising the key removes contact, but the lug stays above the receiver channel. The connector cannot complete its keyed seat."
);
verifyButton.textContent = "VERIFY ANOTHER CANDIDATE";
verifyButton.disabled = false;
} else {
pathMaterial.color.set(0xffbf69);
pathMaterial.opacity = 0.95;
pathArrow.setColor(0xffbf69);
guideMaterial.color.set(0xc89a5d);
setMetric(metricContact, "0 contacts", "good");
setMetric(metricIndex, "Ambiguous", "warn");
setMetric(metricPath, "Clear / straight", "warn");
showResult(
"warning",
"!",
"Fit is ambiguous",
"The enlarged opening allows the plug to seat, but it destroys the keyed index. More than one rotation can now occupy the same socket."
);
verifyButton.textContent = "VERIFY ANOTHER CANDIDATE";
verifyButton.disabled = false;
}
}
function updateAnimation(now) {
if (!animation) return;
const elapsed = now - animation.start;
const progress = Math.min(elapsed / animation.duration, 1);
if (animation.kind === "replay") {
if (progress < 0.42) {
const p = easeInOut(progress / 0.42);
plug.position.x = lerp(
INITIAL_PLUG_X,
SEATED_PLUG_X + 0.38,
p
);
} else if (progress < 0.62) {
plug.position.x = SEATED_PLUG_X + 0.38;
} else {
const p = easeInOut((progress - 0.62) / 0.38);
plug.position.x = lerp(
SEATED_PLUG_X + 0.38,
INITIAL_PLUG_X,
p
);
}
if (progress > 0.4 && !animation.hitShown) {
animation.hitShown = true;
showErrorAt(new THREE.Vector3(-0.24, 0.55, 0.08));
pathMaterial.color.set(0xff5a6b);
pathArrow.setColor(0xff5a6b);
}
if (progress >= 1) {
const savedOption = animation.option;
animation = null;
replayButton.disabled = false;
if (savedOption) {
applyOption(savedOption);
verifyButton.disabled = false;
} else {
resetGeometry();
}
}
return;
}
if (animation.option === "raise") {
const travel = Math.min(progress / 0.72, 1);
const eased = easeInOut(travel);
plug.position.x = lerp(
INITIAL_PLUG_X,
SEATED_PLUG_X + 0.43,
eased
);
if (progress > 0.62 && !animation.hitShown) {
animation.hitShown = true;
showErrorAt(
new THREE.Vector3(
plug.position.x + 0.28,
0.88,
0
)
);
}
} else {
const eased = easeInOut(progress);
plug.position.x = lerp(
INITIAL_PLUG_X,
SEATED_PLUG_X,
eased
);
}
if (progress >= 1) {
finishVerification();
animation = null;
}
}
for (const button of optionButtons) {
button.addEventListener("click", () => {
chooseOption(button.dataset.option);
});
}
verifyButton.addEventListener("click", startVerification);
replayButton.addEventListener("click", startReplay);
resetButton.addEventListener("click", () => {
if (animation) {
animation = null;
replayButton.disabled = false;
}
clearSelection();
});
cameraResetButton.addEventListener("click", () => {
Object.assign(cameraState, defaultCamera);
updateCamera();
});
// Direct camera controls; no addons or example modules are used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.45,
1.35
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.006,
5.2,
12
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
Object.assign(cameraState, defaultCamera);
updateCamera();
});
function resizeRenderer() {
const width = Math.max(stage.clientWidth, 1);
const height = Math.max(stage.clientHeight, 1);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(stage);
resizeRenderer();
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, visible = true) {
if (!visible) {
element.style.display = "none";
return;
}
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
const inFront = projected.z > -1 && projected.z < 1;
element.style.display = inFront ? "block" : "none";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const receiverAnchor = new THREE.Vector3(-1.45, 1.38, 0.65);
const plugAnchor = new THREE.Vector3(1.45, 1.27, 0.55);
const pathAnchor = new THREE.Vector3(0.8, 1.38, 0);
const successAnchor = new THREE.Vector3(-0.55, 1.05, 0);
function updateLabels() {
placeLabel(receiverLabel, receiverAnchor);
placeLabel(
plugLabel,
new THREE.Vector3(
plug.position.x + 1.05,
1.24,
0.55
)
);
placeLabel(
errorLabel,
errorMarker.position.clone().add(new THREE.Vector3(0, 0.43, 0)),
errorMarker.visible
);
placeLabel(pathLabel, pathAnchor);
placeLabel(
successLabel,
successAnchor,
successMarker.visible
);
}
function animate(now) {
requestAnimationFrame(animate);
updateAnimation(now);
const pulse = 1 + Math.sin(now * 0.005) * 0.08;
if (errorMarker.visible) {
errorMarker.scale.setScalar(pulse);
errorRing.rotation.x = now * 0.0012;
}
if (successMarker.visible) {
successRing.rotation.x = now * 0.0015;
successMarker.scale.setScalar(1 + Math.sin(now * 0.004) * 0.025);
}
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```