Prompt specification
Build or customize the Three.js 3D scene "Cabinet handle spacing gauge" 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: Cabinet handle spacing gauge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cabinet-handle-spacing-gauge-x0269
Scene Description Prompt:
Try three voxel cabinet handles against paired mounting holes; only matching screw spacing fits. One HTML file using Three.js from cdnjs.
Working Three.js Starter (cabinet-handle-spacing-gauge-x0269):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Fit — Cabinet Handle Bench</title>
<style>
:root {
color-scheme: dark;
--bg: #0c1018;
--panel: rgba(20, 27, 39, 0.88);
--panel-strong: #151d2a;
--line: rgba(255, 255, 255, 0.11);
--text: #f4f7fb;
--muted: #98a4b7;
--amber: #ffbf69;
--green: #68e0a2;
--red: #ff6f79;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 28%, #1d293c 0%, #0c1018 56%, #080b11 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.ui button,
.measure-card {
pointer-events: auto;
}
header {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 39px;
height: 39px;
transform: rotate(-6deg);
}
.brand-mark i {
position: absolute;
display: block;
width: 15px;
height: 15px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: var(--amber);
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16);
}
.brand-mark i:nth-child(1) {
left: 1px;
top: 3px;
}
.brand-mark i:nth-child(2) {
right: 1px;
top: 3px;
background: #f4f7fb;
}
.brand-mark i:nth-child(3) {
left: 1px;
bottom: 2px;
background: #68e0a2;
}
.brand-mark i:nth-child(4) {
right: 1px;
bottom: 2px;
background: #6da8ff;
}
.eyebrow {
margin: 0 0 3px;
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.3vw, 27px);
line-height: 1;
letter-spacing: -0.04em;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.status-pill {
min-width: 92px;
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(12, 16, 24, 0.72);
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-align: center;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.status-pill.testing {
border-color: rgba(255, 191, 105, 0.45);
color: var(--amber);
}
.status-pill.no-fit {
border-color: rgba(255, 111, 121, 0.5);
color: var(--red);
}
.status-pill.fit {
border-color: rgba(104, 224, 162, 0.55);
color: var(--green);
background: rgba(35, 91, 66, 0.28);
}
.icon-button {
width: 39px;
height: 39px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(12, 16, 24, 0.72);
color: var(--text);
cursor: pointer;
backdrop-filter: blur(12px);
transition: 0.2s ease;
}
.icon-button:hover {
border-color: rgba(255, 255, 255, 0.3);
transform: translateY(-1px);
}
.measure-card {
position: absolute;
top: 98px;
left: 24px;
width: min(270px, calc(100vw - 48px));
padding: 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px);
}
.card-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.pitch-value {
margin: 9px 0 4px;
font-size: 27px;
font-weight: 850;
letter-spacing: -0.04em;
}
.pitch-value.hidden {
color: #667287;
letter-spacing: 0.02em;
font-size: 18px;
}
.measure-copy {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.measure-button {
width: 100%;
margin-top: 13px;
padding: 9px 11px;
border: 1px solid rgba(255, 191, 105, 0.35);
border-radius: 10px;
background: rgba(255, 191, 105, 0.1);
color: var(--amber);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: 0.2s ease;
}
.measure-button:hover:not(:disabled) {
background: rgba(255, 191, 105, 0.17);
}
.measure-button:disabled {
cursor: default;
opacity: 0.75;
}
.attempts {
margin-top: 10px;
color: #738096;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.dock {
position: absolute;
left: 50%;
bottom: 20px;
width: min(940px, calc(100vw - 32px));
padding: 14px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 21px;
background: rgba(16, 22, 33, 0.9);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.dock-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 0 3px 10px;
}
.dock-title {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.hint {
color: var(--muted);
font-size: 11px;
}
.dock-main {
display: grid;
grid-template-columns: minmax(0, 1fr) 190px;
gap: 12px;
}
.handle-options {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
}
.handle-button {
position: relative;
min-width: 0;
padding: 12px 13px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 14px;
background: #111927;
color: var(--text);
text-align: left;
cursor: pointer;
transition: 0.2s ease;
}
.handle-button::after {
content: "";
position: absolute;
inset: auto 0 0;
height: 3px;
background: var(--accent);
opacity: 0;
transform: scaleX(0.4);
transition: 0.2s ease;
}
.handle-button:hover:not(:disabled) {
border-color: rgba(255, 255, 255, 0.24);
background: #172131;
transform: translateY(-2px);
}
.handle-button.selected {
border-color: color-mix(in srgb, var(--accent) 64%, transparent);
background: color-mix(in srgb, var(--accent) 10%, #111927);
}
.handle-button.selected::after {
opacity: 1;
transform: scaleX(1);
}
.handle-button:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.handle-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.handle-name {
overflow: hidden;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.04em;
text-overflow: ellipsis;
white-space: nowrap;
}
.handle-pitch {
color: var(--accent);
font-size: 10px;
font-weight: 850;
white-space: nowrap;
}
.mini-handle {
display: flex;
align-items: center;
justify-content: center;
height: 38px;
margin-top: 8px;
}
.mini-handle i {
position: relative;
display: block;
width: 13px;
height: 13px;
margin-right: 3px;
background: var(--accent);
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.19);
}
.mini-handle i:nth-child(2) {
width: 43px;
height: 17px;
}
.mini-handle.rail i:nth-child(2) {
width: 62px;
}
.mini-handle.stair i:nth-child(2) {
width: 48px;
clip-path: polygon(0 35%, 18% 35%, 18% 0, 38% 0, 38% 35%, 62% 35%, 62% 0, 82% 0, 82% 35%, 100% 35%, 100% 100%, 0 100%);
}
.handle-type {
margin-top: 4px;
color: #78869b;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.test-button {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 88px;
padding: 12px;
border: 0;
border-radius: 14px;
background: var(--amber);
color: #1c160d;
cursor: pointer;
box-shadow: 0 10px 24px rgba(255, 191, 105, 0.16);
transition: 0.2s ease;
}
.test-button:hover:not(:disabled) {
background: #ffd08c;
transform: translateY(-2px);
}
.test-button:disabled {
cursor: not-allowed;
filter: saturate(0.35);
opacity: 0.7;
}
.test-button strong {
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.test-button span {
margin-top: 5px;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
opacity: 0.68;
text-transform: uppercase;
}
.feedback {
min-height: 14px;
margin: 10px 3px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.feedback.error {
color: var(--red);
}
.feedback.success {
color: var(--green);
}
.orbit-note {
position: absolute;
right: 24px;
bottom: 155px;
color: rgba(181, 194, 214, 0.55);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-align: right;
text-transform: uppercase;
}
@media (max-width: 700px) {
header {
top: 16px;
left: 16px;
right: 16px;
}
.brand-mark {
width: 34px;
height: 34px;
}
.brand-mark i {
width: 13px;
height: 13px;
}
.eyebrow {
font-size: 8px;
}
.status-pill {
display: none;
}
.measure-card {
top: 79px;
left: 16px;
width: 220px;
padding: 13px;
}
.pitch-value {
font-size: 22px;
}
.measure-copy,
.attempts {
display: none;
}
.measure-button {
margin-top: 10px;
}
.dock {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
border-radius: 17px;
}
.dock-heading {
margin-bottom: 8px;
}
.hint,
.orbit-note {
display: none;
}
.dock-main {
grid-template-columns: 1fr;
gap: 8px;
}
.handle-options {
gap: 6px;
}
.handle-button {
padding: 9px 8px;
border-radius: 11px;
}
.handle-name {
font-size: 10px;
}
.handle-pitch {
font-size: 8px;
}
.mini-handle {
height: 31px;
margin-top: 5px;
}
.mini-handle i {
width: 10px;
height: 10px;
}
.mini-handle i:nth-child(2) {
width: 30px;
height: 14px;
}
.mini-handle.rail i:nth-child(2) {
width: 45px;
}
.handle-type {
display: none;
}
.test-button {
min-height: 45px;
flex-direction: row;
gap: 8px;
border-radius: 11px;
}
.test-button span {
margin: 0;
}
.feedback {
min-height: 12px;
margin-top: 7px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div>
<p class="eyebrow">Hardware bench / 03</p>
<h1>Voxel Fit</h1>
</div>
</div>
<div class="header-actions">
<div id="status" class="status-pill">Ready</div>
<button id="reset" class="icon-button" title="Reset bench" aria-label="Reset bench">↻</button>
</div>
</header>
<section class="measure-card">
<div class="card-label">Mounting pair A</div>
<div id="pitchValue" class="pitch-value hidden">Pitch hidden</div>
<p class="measure-copy">
Screw spacing is measured center-to-center. Try each handle against the paired holes.
</p>
<button id="measure" class="measure-button">Inspect hole centers</button>
<div id="attempts" class="attempts">0 test attempts</div>
</section>
<section class="dock" aria-label="Handle selection bench">
<div class="dock-heading">
<div class="dock-title">Choose a voxel handle</div>
<div class="hint">Select a handle, then test the fit · Space to test</div>
</div>
<div class="dock-main">
<div id="handleOptions" class="handle-options"></div>
<button id="test" class="test-button">
<strong id="testTitle">Test fit</strong>
<span id="testSubtitle">48 mm selected</span>
</button>
</div>
<div id="feedback" class="feedback">Select a handle and test it against the mounting pair.</div>
</section>
<div class="orbit-note">Drag to orbit · Scroll to zoom<br>Double-click to reset view</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 sceneHost = document.getElementById("scene");
const optionsHost = document.getElementById("handleOptions");
const measureButton = document.getElementById("measure");
const pitchValue = document.getElementById("pitchValue");
const attemptsElement = document.getElementById("attempts");
const statusElement = document.getElementById("status");
const testButton = document.getElementById("test");
const testTitle = document.getElementById("testTitle");
const testSubtitle = document.getElementById("testSubtitle");
const feedback = document.getElementById("feedback");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x0c1018, 13, 29);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x0c1018, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xaec8ff, 0x241d18, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe2ba, 4.2);
keyLight.position.set(-4.5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x719dff, 2.3);
rimLight.position.set(6, 3, -4);
scene.add(rimLight);
const holeLight = new THREE.PointLight(0xffb75f, 2.2, 5, 2);
holeLight.position.set(0, 0.7, 1.4);
scene.add(holeLight);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x070a10,
transparent: true,
opacity: 0.48
});
function addVoxel(parent, size, position, material, withEdges = true) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (withEdges) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
edgeMaterial
);
edges.position.copy(mesh.position);
edges.renderOrder = 2;
parent.add(edges);
}
return mesh;
}
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0d131d,
roughness: 0.94,
metalness: 0.03
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(50, 50), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.42;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x263449, 0x182130);
grid.position.y = -3.405;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x111925,
roughness: 1
});
const wall = new THREE.Mesh(new THREE.PlaneGeometry(36, 22), wallMaterial);
wall.position.set(0, 3.6, -1.45);
wall.receiveShadow = true;
scene.add(wall);
const cabinet = new THREE.Group();
scene.add(cabinet);
const carcassMaterial = new THREE.MeshStandardMaterial({
color: 0x293446,
roughness: 0.72,
metalness: 0.08
});
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x3a4658,
roughness: 0.82
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x59657a,
roughness: 0.62,
metalness: 0.08
});
addVoxel(cabinet, [6.65, 7.0, 0.72], [0, 0.15, -0.54], carcassMaterial);
addVoxel(cabinet, [5.48, 6.18, 0.18], [0, 0.15, 0], panelMaterial);
const tileColors = [0x344153, 0x39465a, 0x303d4f, 0x3f4c61];
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 5; col++) {
const tileMaterial = new THREE.MeshStandardMaterial({
color: tileColors[(row * 2 + col) % tileColors.length],
roughness: 0.88
});
addVoxel(
cabinet,
[0.91, 0.91, 0.055],
[-2.08 + col * 1.04, -2.38 + row * 1.02, 0.115],
tileMaterial,
false
);
}
}
for (let i = 0; i < 11; i++) {
const y = -2.86 + i * 0.58;
addVoxel(cabinet, [0.5, 0.5, 0.26], [-2.72, y, 0.2], frameMaterial);
addVoxel(cabinet, [0.5, 0.5, 0.26], [2.72, y, 0.2], frameMaterial);
}
for (let i = 0; i < 9; i++) {
const x = -2.29 + i * 0.58;
addVoxel(cabinet, [0.5, 0.5, 0.26], [x, -2.95, 0.2], frameMaterial);
addVoxel(cabinet, [0.5, 0.5, 0.26], [x, 3.23, 0.2], frameMaterial);
}
const hingeMaterial = new THREE.MeshStandardMaterial({
color: 0x8b98aa,
roughness: 0.38,
metalness: 0.55
});
addVoxel(cabinet, [0.28, 0.62, 0.34], [-3.17, -1.92, 0.16], hingeMaterial);
addVoxel(cabinet, [0.28, 0.62, 0.34], [-3.17, 2.08, 0.16], hingeMaterial);
const targetSpacing = 1.8; // World units; displayed as 72 mm.
const targetHalfSpacing = targetSpacing / 2;
const holeY = 0.65;
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x05070b,
roughness: 0.55,
metalness: 0.18
});
const targetRingMaterial = new THREE.MeshBasicMaterial({
color: 0xffbd66,
transparent: true,
opacity: 0.95,
depthTest: false
});
for (const x of [-targetHalfSpacing, targetHalfSpacing]) {
const hole = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.065, 24),
holeMaterial
);
hole.rotation.x = Math.PI / 2;
hole.position.set(x, holeY, 0.18);
cabinet.add(hole);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.022, 8, 28),
targetRingMaterial
);
ring.position.set(x, holeY, 0.205);
ring.renderOrder = 5;
cabinet.add(ring);
}
function makeTextSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(15, 21, 31, 0.94)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#ffbd66";
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = "#ffcf88";
context.font = "800 48px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.45, 0.36, 1);
sprite.renderOrder = 10;
return sprite;
}
const measureGroup = new THREE.Group();
const measureMaterial = new THREE.LineBasicMaterial({
color: 0xffbd66,
transparent: true,
opacity: 0.9,
depthTest: false
});
const measurePoints = [
new THREE.Vector3(-targetHalfSpacing, 1.45, 0.28),
new THREE.Vector3(targetHalfSpacing, 1.45, 0.28),
new THREE.Vector3(-targetHalfSpacing, 1.34, 0.28),
new THREE.Vector3(-targetHalfSpacing, 1.56, 0.28),
new THREE.Vector3(targetHalfSpacing, 1.34, 0.28),
new THREE.Vector3(targetHalfSpacing, 1.56, 0.28)
];
const measureGeometry = new THREE.BufferGeometry().setFromPoints(measurePoints);
const measureLines = new THREE.LineSegments(measureGeometry, measureMaterial);
measureLines.renderOrder = 8;
measureGroup.add(measureLines);
const measureLabel = makeTextSprite("72 MM");
measureLabel.position.set(0, 1.8, 0.29);
measureGroup.add(measureLabel);
measureGroup.visible = false;
cabinet.add(measureGroup);
const handleConfigs = [
{
name: "Chunk",
pitch: 48,
spacing: 1.2,
type: "Compact pull",
accent: "#ff8066",
color: 0xe96750,
style: "chunk"
},
{
name: "Ledge",
pitch: 72,
spacing: 1.8,
type: "Stepped pull",
accent: "#ffbf69",
color: 0xe8a94e,
style: "stair"
},
{
name: "Rail",
pitch: 96,
spacing: 2.4,
type: "Long pull",
accent: "#6da8ff",
color: 0x477fca,
style: "rail"
}
];
const HOME_POSITION = new THREE.Vector3(0, -1.7, 1.25);
const HOME_ROTATION = -0.16;
const FIT_POSITION = new THREE.Vector3(0, holeY, 0.1);
let selectedIndex = 0;
let activeHandle = null;
let activeScrewMaterial = null;
let phase = "idle";
let phaseTime = 0;
let attempts = 0;
let measured = false;
let fromPosition = HOME_POSITION.clone();
let fromRotation = HOME_ROTATION;
let matchResult = false;
const particles = [];
handleConfigs.forEach((config, index) => {
const button = document.createElement("button");
button.className = "handle-button";
button.dataset.index = index;
button.style.setProperty("--accent", config.accent);
button.innerHTML = `
<div class="handle-top">
<span class="handle-name">${config.name}</span>
<span class="handle-pitch">${config.pitch} mm</span>
</div>
<div class="mini-handle ${config.style}">
<i></i><i></i><i></i>
</div>
<div class="handle-type">${config.type}</div>
`;
button.addEventListener("click", () => selectHandle(index));
optionsHost.appendChild(button);
});
function setStatus(type, text) {
statusElement.className = `status-pill ${type}`;
statusElement.textContent = text;
}
function updateCards() {
[...optionsHost.children].forEach((button, index) => {
button.classList.toggle("selected", index === selectedIndex);
button.disabled = phase === "testing" || phase === "mounted";
});
}
function createHandle(config) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: config.color,
roughness: 0.36,
metalness: 0.22
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x273140,
roughness: 0.52,
metalness: 0.32
});
activeScrewMaterial = new THREE.MeshStandardMaterial({
color: 0xd9e1e9,
roughness: 0.22,
metalness: 0.82
});
const half = config.spacing / 2;
for (const x of [-half, half]) {
addVoxel(group, [0.42, 0.46, 0.22], [x, 0, 0.11], darkMaterial);
addVoxel(group, [0.32, 0.34, 0.57], [x, 0, 0.49], bodyMaterial);
const screw = new THREE.Mesh(
new THREE.CylinderGeometry(0.088, 0.088, 0.055, 20),
activeScrewMaterial
);
screw.rotation.x = Math.PI / 2;
screw.position.set(x, 0, 0.25);
screw.castShadow = true;
group.add(screw);
const slot = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.018, 0.015),
new THREE.MeshBasicMaterial({ color: 0x313945 })
);
slot.position.set(x, 0, 0.281);
group.add(slot);
}
if (config.style === "chunk") {
addVoxel(
group,
[config.spacing + 0.52, 0.56, 0.53],
[0, 0, 0.88],
bodyMaterial
);
addVoxel(group, [0.24, 0.68, 0.64], [-0.63, 0, 0.88], darkMaterial);
addVoxel(group, [0.24, 0.68, 0.64], [0.63, 0, 0.88], darkMaterial);
} else if (config.style === "stair") {
const stepPositions = [-0.92, -0.46, 0, 0.46, 0.92];
stepPositions.forEach((x, index) => {
addVoxel(
group,
[0.48, 0.48 + (index % 2) * 0.13, 0.5],
[x, (index % 2 ? 0.08 : -0.04), 0.88],
bodyMaterial
);
});
addVoxel(group, [2.38, 0.18, 0.5], [0, -0.22, 0.88], darkMaterial);
} else {
addVoxel(
group,
[config.spacing + 0.68, 0.34, 0.5],
[0, 0, 0.9],
bodyMaterial
);
const railHalf = (config.spacing + 0.68) / 2;
addVoxel(group, [0.27, 0.66, 0.62], [-railHalf, 0, 0.88], darkMaterial);
addVoxel(group, [0.27, 0.66, 0.62], [railHalf, 0, 0.88], darkMaterial);
addVoxel(group, [0.38, 0.42, 0.59], [-0.58, 0, 0.88], bodyMaterial);
addVoxel(group, [0.38, 0.42, 0.59], [0.58, 0, 0.88], bodyMaterial);
}
group.traverse((child) => {
child.userData.isHandle = true;
});
return group;
}
function clearParticles() {
while (particles.length) {
const particle = particles.pop();
scene.remove(particle.mesh);
particle.mesh.geometry.dispose();
particle.mesh.material.dispose();
}
}
function buildActiveHandle() {
if (activeHandle) {
scene.remove(activeHandle);
}
activeHandle = createHandle(handleConfigs[selectedIndex]);
activeHandle.position.copy(HOME_POSITION);
activeHandle.rotation.y = HOME_ROTATION;
scene.add(activeHandle);
}
function selectHandle(index) {
if (phase === "testing" || phase === "mounted") return;
selectedIndex = index;
phase = "idle";
phaseTime = 0;
buildActiveHandle();
updateCards();
const config = handleConfigs[index];
testTitle.textContent = "Test fit";
testSubtitle.textContent = `${config.pitch} mm selected`;
testButton.disabled = false;
feedback.className = "feedback";
feedback.textContent = `${config.name} selected. Test its screw spacing against the mounting pair.`;
setStatus("", "Ready");
targetRingMaterial.color.setHex(0xffbd66);
}
function spawnBurst(color, correct) {
clearParticles();
const centers = correct
? [
new THREE.Vector3(-targetHalfSpacing, holeY, 0.45),
new THREE.Vector3(targetHalfSpacing, holeY, 0.45)
]
: [
new THREE.Vector3(0, holeY, 0.55)
];
const geometry = new THREE.BoxGeometry(0.09, 0.09, 0.09);
for (const center of centers) {
for (let i = 0; i < 16; i++) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 1
});
const mesh = new THREE.Mesh(geometry.clone(), material);
mesh.position.copy(center);
mesh.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
scene.add(mesh);
particles.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 2.8,
0.7 + Math.random() * 2.2,
(Math.random() - 0.5) * 2
),
life: 0.75 + Math.random() * 0.45
});
}
}
}
function testFit() {
if (phase === "testing" || phase === "mounted") return;
attempts += 1;
attemptsElement.textContent = `${attempts} test attempt${attempts === 1 ? "" : "s"}`;
phase = "testing";
phaseTime = 0;
matchResult = handleConfigs[selectedIndex].spacing === targetSpacing;
fromPosition = activeHandle.position.clone();
fromRotation = activeHandle.rotation.y;
activeScrewMaterial.color.setHex(matchResult ? 0x8de9b6 : 0xffb15f);
setStatus("testing", "Testing");
feedback.className = "feedback";
feedback.textContent = "Moving the handle toward the mounting pair…";
testButton.disabled = true;
updateCards();
}
function resetBench() {
phase = "idle";
phaseTime = 0;
attempts = 0;
measured = false;
selectedIndex = 0;
measured = false;
attemptsElement.textContent = "0 test attempts";
pitchValue.textContent = "Pitch hidden";
pitchValue.classList.add("hidden");
measureButton.textContent = "Inspect hole centers";
measureButton.disabled = false;
measureGroup.visible = false;
targetRingMaterial.color.setHex(0xffbd66);
holeLight.color.setHex(0xffb75f);
holeLight.intensity = 2.2;
clearParticles();
buildActiveHandle();
updateCards();
testTitle.textContent = "Test fit";
testSubtitle.textContent = "48 mm selected";
testButton.disabled = false;
feedback.className = "feedback";
feedback.textContent = "Select a handle and test it against the mounting pair.";
setStatus("", "Ready");
}
measureButton.addEventListener("click", () => {
measured = true;
measureGroup.visible = true;
pitchValue.textContent = "72 mm center-to-center";
pitchValue.classList.remove("hidden");
measureButton.textContent = "Pitch revealed · 72 mm";
measureButton.disabled = true;
feedback.className = "feedback";
feedback.textContent = "The mounting holes are 72 mm apart. Choose the 72 mm handle.";
});
testButton.addEventListener("click", testFit);
document.getElementById("reset").addEventListener("click", resetBench);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
testFit();
}
if (event.key.toLowerCase() === "r") {
resetBench();
}
if (["1", "2", "3"].includes(event.key)) {
selectHandle(Number(event.key) - 1);
}
});
const cameraState = {
theta: -0.28,
phi: 0.08,
radius: 12.5,
target: new THREE.Vector3(0, 0.15, 0)
};
function updateCamera() {
const responsiveScale = Math.max(1, 0.86 / camera.aspect);
const radius = cameraState.radius * responsiveScale;
const horizontal = Math.cos(cameraState.phi) * radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.theta) * horizontal,
cameraState.target.y + Math.sin(cameraState.phi) * radius,
cameraState.target.z + Math.cos(cameraState.theta) * horizontal
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = -0.28;
cameraState.phi = 0.08;
cameraState.radius = 12.5;
updateCamera();
}
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let pointerDown = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 5) {
pointerDown.moved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.004,
-0.18,
0.58
);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown) return;
const wasClick = !pointerDown.moved;
pointerDown = null;
if (!wasClick || !activeHandle) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(activeHandle.children, true);
if (hits.length) {
testFit();
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8.8,
16.5
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const easeOutCubic = (value) => 1 - Math.pow(1 - value, 3);
function updateParticles(delta) {
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.life -= delta;
particle.velocity.y -= 4.8 * delta;
particle.mesh.position.addScaledVector(particle.velocity, delta);
particle.mesh.rotation.x += delta * 5;
particle.mesh.rotation.y += delta * 4;
particle.mesh.material.opacity = Math.max(0, particle.life * 1.6);
if (particle.life <= 0) {
scene.remove(particle.mesh);
particle.mesh.geometry.dispose();
particle.mesh.material.dispose();
particles.splice(i, 1);
}
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (phase === "idle") {
activeHandle.position.y = HOME_POSITION.y + Math.sin(elapsed * 1.65) * 0.075;
activeHandle.position.x = HOME_POSITION.x + Math.sin(elapsed * 0.9) * 0.035;
activeHandle.rotation.y = HOME_ROTATION + Math.sin(elapsed * 0.8) * 0.035;
activeHandle.scale.setScalar(1);
} else if (phase === "testing") {
phaseTime += delta;
const progress = Math.min(phaseTime / 0.72, 1);
const eased = easeOutCubic(progress);
activeHandle.position.lerpVectors(fromPosition, FIT_POSITION, eased);
activeHandle.rotation.y = THREE.MathUtils.lerp(fromRotation, 0, eased);
activeHandle.scale.setScalar(1 + Math.sin(progress * Math.PI) * 0.045);
if (progress >= 1) {
if (matchResult) {
phase = "mounted";
activeHandle.position.copy(FIT_POSITION);
activeHandle.rotation.y = 0;
activeHandle.scale.setScalar(1);
activeScrewMaterial.color.setHex(0x9bf0c1);
targetRingMaterial.color.setHex(0x68e0a2);
holeLight.color.setHex(0x68e0a2);
holeLight.intensity = 3.4;
spawnBurst(0x68e0a2, true);
setStatus("fit", "Fit");
testTitle.textContent = "Fit confirmed";
testSubtitle.textContent = "Both screws seated";
testButton.disabled = true;
feedback.className = "feedback success";
feedback.textContent = "72 mm matches the 72 mm hole pitch. The handle locks cleanly onto both screws.";
updateCards();
} else {
phase = "reject";
phaseTime = 0;
activeScrewMaterial.color.setHex(0xff6f79);
targetRingMaterial.color.setHex(0xff6f79);
spawnBurst(0xff6f79, false);
setStatus("no-fit", "No fit");
feedback.className = "feedback error";
feedback.textContent = `${handleConfigs[selectedIndex].pitch} mm does not match the 72 mm hole spacing. The screws cannot seat.`;
}
}
} else if (phase === "reject") {
phaseTime += delta;
if (phaseTime < 0.52) {
activeHandle.position.copy(FIT_POSITION);
activeHandle.position.x += Math.sin(phaseTime * 75) * 0.055;
activeHandle.position.y += Math.sin(phaseTime * 91) * 0.018;
} else if (phaseTime < 1.28) {
const returnProgress = easeOutCubic((phaseTime - 0.52) / 0.76);
activeHandle.position.lerpVectors(FIT_POSITION, HOME_POSITION, returnProgress);
activeHandle.rotation.y = THREE.MathUtils.lerp(0, HOME_ROTATION, returnProgress);
} else {
phase = "idle";
activeHandle.position.copy(HOME_POSITION);
activeHandle.rotation.y = HOME_ROTATION;
activeScrewMaterial.color.setHex(0xd9e1e9);
targetRingMaterial.color.setHex(0xffbd66);
holeLight.color.setHex(0xffb75f);
holeLight.intensity = 2.2;
testButton.disabled = false;
testTitle.textContent = "Test fit";
testSubtitle.textContent = `${handleConfigs[selectedIndex].pitch} mm selected`;
updateCards();
}
}
if (measured || phase === "mounted") {
holeLight.intensity = 2.2 + Math.sin(elapsed * 3.2) * 0.35;
}
updateParticles(delta);
renderer.render(scene, camera);
}
buildActiveHandle();
updateCards();
resize();
animate();
</script>
</body>
</html>
```