Prompt specification
Build or customize the Three.js 3D scene "Manual Height-Adjustment Workbench" 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: Manual Height-Adjustment Workbench
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/manual-height-adjustment-workbench-x2071
Scene Description Prompt:
A voxel workbench lift using a single-start lead screw, guided nut, and moving platform. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (manual-height-adjustment-workbench-x2071):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Workbench Lift</title>
<style>
:root {
color-scheme: dark;
--bg: #091017;
--panel: rgba(14, 23, 32, 0.92);
--panel-line: rgba(255, 255, 255, 0.1);
--text: #edf5f8;
--muted: #8293a2;
--orange: #f5a623;
--cyan: #42c8dc;
--green: #55d98b;
--red: #ff6b65;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(circle at 46% 44%, transparent 25%, rgba(2, 6, 10, 0.22) 76%),
linear-gradient(180deg, rgba(2, 6, 10, 0.24), transparent 22%, transparent 76%, rgba(2, 6, 10, 0.36));
}
.brand {
position: fixed;
z-index: 10;
top: 22px;
left: 24px;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 2px solid var(--orange);
border-radius: 9px;
transform: rotate(-8deg);
box-shadow: 0 0 24px rgba(245, 166, 35, 0.15);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--orange);
}
.brand-mark::before {
width: 18px;
height: 3px;
left: 8px;
top: 10px;
}
.brand-mark::after {
width: 3px;
height: 18px;
left: 16px;
top: 8px;
}
.brand-kicker {
margin-bottom: 2px;
color: var(--orange);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: 20px;
font-weight: 750;
letter-spacing: -0.025em;
}
.brand h1 span {
color: var(--muted);
font-weight: 500;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
right: 20px;
width: 326px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 18px;
border: 1px solid var(--panel-line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #344555 transparent;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 16px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.01em;
}
.status {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
color: var(--muted);
background: rgba(255, 255, 255, 0.025);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
white-space: nowrap;
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--muted);
box-shadow: 0 0 0 3px rgba(130, 147, 162, 0.08);
}
.status.running .status-dot {
background: var(--green);
box-shadow: 0 0 0 3px rgba(85, 217, 139, 0.12), 0 0 12px rgba(85, 217, 139, 0.5);
}
.status.seeking .status-dot {
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(66, 200, 220, 0.12), 0 0 12px rgba(66, 200, 220, 0.5);
}
.section {
padding: 14px 0;
border-top: 1px solid var(--panel-line);
}
.section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: #aab8c4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title output {
color: var(--text);
font-size: 11px;
letter-spacing: 0;
font-variant-numeric: tabular-nums;
}
.motor-button {
width: 100%;
min-height: 47px;
border: 1px solid rgba(85, 217, 139, 0.36);
border-radius: 10px;
background: rgba(85, 217, 139, 0.1);
cursor: pointer;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: 150ms ease;
}
.motor-button:hover {
background: rgba(85, 217, 139, 0.17);
transform: translateY(-1px);
}
.motor-button.running {
border-color: rgba(255, 107, 101, 0.38);
background: rgba(255, 107, 101, 0.1);
}
.motor-button.running:hover {
background: rgba(255, 107, 101, 0.16);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 9px;
}
.small-button {
min-height: 35px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: #aebcc8;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: 140ms ease;
}
.small-button:hover {
border-color: rgba(255, 255, 255, 0.22);
color: white;
background: rgba(255, 255, 255, 0.07);
}
.small-button.active {
border-color: rgba(66, 200, 220, 0.42);
color: #a9f2fb;
background: rgba(66, 200, 220, 0.1);
}
.control {
margin-top: 13px;
}
.control:first-child {
margin-top: 0;
}
.control-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
color: #aebcc8;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-head output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--pct: 0%;
--accent: var(--cyan);
width: 100%;
height: 4px;
margin: 5px 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--pct),
rgba(255, 255, 255, 0.12) var(--pct),
rgba(255, 255, 255, 0.12) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #d9f8fb;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(66, 200, 220, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #d9f8fb;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(66, 200, 220, 0.12);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #637583;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
}
.formula {
padding: 11px 12px;
border: 1px solid rgba(66, 200, 220, 0.12);
border-radius: 9px;
background: rgba(66, 200, 220, 0.045);
color: #a7b6c3;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.7;
}
.formula strong {
color: var(--cyan);
font-weight: 700;
}
.toggle-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.toggle-row .small-button[aria-pressed="true"] {
border-color: rgba(245, 166, 35, 0.4);
color: #ffd28a;
background: rgba(245, 166, 35, 0.1);
}
.metrics {
position: fixed;
z-index: 10;
left: 24px;
bottom: 22px;
display: flex;
gap: 8px;
pointer-events: none;
}
.metric {
min-width: 112px;
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 10px;
background: rgba(12, 20, 28, 0.74);
backdrop-filter: blur(12px);
}
.metric-label {
display: block;
margin-bottom: 4px;
color: #6f8493;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.metric-value {
font-size: 16px;
font-weight: 760;
font-variant-numeric: tabular-nums;
}
.metric-value small {
margin-left: 4px;
color: #758997;
font-size: 9px;
font-weight: 600;
}
.hints {
position: fixed;
z-index: 10;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 999px;
background: rgba(9, 16, 23, 0.6);
color: #657986;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.05em;
pointer-events: none;
white-space: nowrap;
}
.hints b {
color: #9babb7;
font-weight: 800;
}
#leader-lines {
position: fixed;
inset: 0;
z-index: 4;
width: 100%;
height: 100%;
pointer-events: none;
}
#leader-lines line {
stroke-width: 1;
opacity: 0.7;
}
.scene-label {
position: fixed;
z-index: 5;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 5px;
background: rgba(8, 15, 21, 0.84);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
color: #b7c5cf;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
transform: translate(-50%, -50%);
pointer-events: none;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.scene-label.orange {
color: #ffd18a;
border-color: rgba(245, 166, 35, 0.26);
}
.scene-label.cyan {
color: #a9f2fb;
border-color: rgba(66, 200, 220, 0.26);
}
.scene-label.blue {
color: #b7dcff;
border-color: rgba(83, 157, 228, 0.28);
}
.annotations-hidden .scene-label,
.annotations-hidden #leader-lines {
display: none;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
}
.brand h1 {
font-size: 16px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 45vh;
padding: 14px;
}
.metrics,
.hints,
.scene-label,
#leader-lines {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="vignette"></div>
<header class="brand">
<div class="brand-mark"></div>
<div>
<div class="brand-kicker">Kinematic workbench</div>
<h1>Voxel Lift <span>/ K-01</span></h1>
</div>
</header>
<aside class="panel">
<div class="panel-head">
<div>
<p class="eyebrow">Single-start drive</p>
<h2>Lead Screw Controller</h2>
</div>
<div class="status" id="status">
<span class="status-dot"></span>
<span id="status-text">Motor held</span>
</div>
</div>
<section class="section">
<div class="section-title">
<span>Motor drive</span>
<output id="rpm-output">24 RPM</output>
</div>
<button class="motor-button" id="motor-button" type="button">Start motor</button>
<div class="button-row">
<button class="small-button active" id="raise-button" type="button">Raise</button>
<button class="small-button" id="lower-button" type="button">Lower</button>
</div>
<div class="control">
<div class="control-head">
<span>Spindle speed</span>
<output id="rpm-value">24 RPM</output>
</div>
<input id="rpm-range" type="range" min="6" max="48" value="24" step="1" />
<div class="range-ends"><span>6 RPM</span><span>48 RPM</span></div>
</div>
</section>
<section class="section">
<div class="section-title">
<span>Command height</span>
<output id="command-output">0.95 u</output>
</div>
<div class="control">
<input id="command-range" type="range" min="0.72" max="4.10" value="0.95" step="0.01" />
<div class="range-ends"><span>HOME</span><span>MAX TRAVEL</span></div>
</div>
<div class="button-row">
<button class="small-button" id="home-button" type="button">Return home</button>
<button class="small-button" id="center-button" type="button">Center travel</button>
</div>
</section>
<section class="section">
<div class="section-title"><span>Kinematics</span></div>
<div class="formula">
Drive: <strong>1 start</strong><br />
Lead: <strong>p = 0.38 u/turn</strong><br />
Travel: <strong>h = h₀ + pθ / 2π</strong><br />
<span id="kinematic-readout">θ = +0.00 turns</span>
</div>
</section>
<section class="section">
<div class="section-title"><span>Camera & inspection</span></div>
<div class="toggle-row">
<button class="small-button" id="iso-button" type="button">Isometric</button>
<button class="small-button" id="front-button" type="button">Front</button>
<button class="small-button" id="detail-button" type="button">Detail</button>
<button class="small-button" id="annotation-button" type="button" aria-pressed="true">Labels on</button>
</div>
</section>
</aside>
<svg id="leader-lines" aria-hidden="true">
<line id="line-screw" stroke="#f5a623"></line>
<line id="line-nut" stroke="#42c8dc"></line>
<line id="line-platform" stroke="#75a9e8"></line>
<line id="line-guide" stroke="#91a3b0"></line>
</svg>
<div class="scene-label orange" id="label-screw">Single-start lead screw</div>
<div class="scene-label cyan" id="label-nut">Guided bronze nut</div>
<div class="scene-label blue" id="label-platform">Moving platform</div>
<div class="scene-label" id="label-guide">Anti-rotation guides</div>
<section class="metrics">
<div class="metric">
<span class="metric-label">Platform height</span>
<span class="metric-value"><span id="actual-height">0.95</span><small>u</small></span>
</div>
<div class="metric">
<span class="metric-label">Screw turns</span>
<span class="metric-value"><span id="turn-count">+0.00</span><small>rev</small></span>
</div>
<div class="metric">
<span class="metric-label">Linear rate</span>
<span class="metric-value"><span id="linear-rate">0.15</span><small>u/s</small></span>
</div>
</section>
<footer class="hints">
<b>Drag</b> orbit · <b>Wheel</b> zoom · <b>Shift/Right drag</b> pan ·
<b>Space</b> motor · <b>↑ ↓</b> travel · <b>R</b> reset view
</footer>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091017);
scene.fog = new THREE.Fog(0x091017, 13, 25);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const TAU = Math.PI * 2;
const PITCH = 0.38;
const HOME = 0.72;
const MIN_HEIGHT = 0.72;
const MAX_HEIGHT = 4.1;
const SCREW_Z = -0.64;
const state = {
position: 0.95,
command: 0.95,
running: false,
locked: false,
mode: "manual",
direction: 1,
rpm: 24
};
const materials = {
base: new THREE.MeshStandardMaterial({
color: 0x17212b,
roughness: 0.67,
metalness: 0.48
}),
deck: new THREE.MeshStandardMaterial({
color: 0x263646,
roughness: 0.72,
metalness: 0.38
}),
frame: new THREE.MeshStandardMaterial({
color: 0xe89b2f,
roughness: 0.48,
metalness: 0.35
}),
frameDark: new THREE.MeshStandardMaterial({
color: 0x5d431e,
roughness: 0.58,
metalness: 0.45
}),
platform: new THREE.MeshStandardMaterial({
color: 0xd7dfe3,
roughness: 0.56,
metalness: 0.28
}),
platformBlue: new THREE.MeshStandardMaterial({
color: 0x397da6,
roughness: 0.54,
metalness: 0.3
}),
steel: new THREE.MeshStandardMaterial({
color: 0xaebbc5,
roughness: 0.27,
metalness: 0.88
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x344452,
roughness: 0.35,
metalness: 0.78
}),
thread: new THREE.MeshStandardMaterial({
color: 0xd4dde2,
roughness: 0.24,
metalness: 0.92
}),
bronze: new THREE.MeshStandardMaterial({
color: 0xce8944,
roughness: 0.31,
metalness: 0.77
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x42c8dc,
roughness: 0.43,
metalness: 0.25
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x0d141b,
roughness: 0.92,
metalness: 0.05
}),
red: new THREE.MeshStandardMaterial({
color: 0xef554f,
roughness: 0.5,
metalness: 0.2
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x0b1219,
transparent: true,
opacity: 0.5
});
function addBox(w, h, d, x, y, z, material, parent = scene, outlined = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
mesh.add(edges);
}
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
material,
parent = scene,
segments = 20
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Lighting.
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x192028, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff2dd, 3.1);
keyLight.position.set(6, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x54b9ff, 1.8);
rimLight.position.set(-7, 5, -5);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xf5a623, 18, 12, 2);
fillLight.position.set(-3, 3, 4);
scene.add(fillLight);
// Ground and technical grid.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(28, 28),
new THREE.MeshStandardMaterial({
color: 0x0c141c,
roughness: 0.94,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x33495a, 0x1a2a36);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const floorRing = new THREE.Mesh(
new THREE.TorusGeometry(3.05, 0.018, 6, 96),
new THREE.MeshBasicMaterial({
color: 0xf5a623,
transparent: true,
opacity: 0.35
})
);
floorRing.rotation.x = Math.PI / 2;
floorRing.position.y = 0.022;
scene.add(floorRing);
// Voxel workbench base.
addBox(4.42, 0.34, 3.02, 0, 0.25, 0, materials.base, scene, true);
addBox(4.08, 0.12, 2.7, 0, 0.48, 0, materials.deck, scene, true);
for (const x of [-1.7, 1.7]) {
for (const z of [-1.0, 1.0]) {
addBox(0.58, 0.14, 0.54, x, 0.08, z, materials.rubber, scene, true);
}
}
addBox(0.18, 0.25, 2.76, -2.16, 0.28, 0, materials.frame, scene, true);
addBox(0.18, 0.25, 2.76, 2.16, 0.28, 0, materials.frame, scene, true);
addBox(4.0, 0.08, 0.18, 0, 0.56, 1.39, materials.frameDark, scene, true);
// Rear structural frame.
for (const x of [-1.83, 1.83]) {
addBox(0.23, 4.95, 0.3, x, 3.02, -0.93, materials.frame, scene, true);
addBox(0.34, 0.19, 0.4, x, 0.62, -0.93, materials.darkSteel, scene, true);
addBox(0.34, 0.19, 0.4, x, 5.42, -0.93, materials.darkSteel, scene, true);
}
addBox(3.9, 0.25, 0.35, 0, 5.42, -0.93, materials.frame, scene, true);
addBox(3.42, 0.12, 0.2, 0, 5.62, -0.91, materials.frameDark, scene, true);
// Anti-rotation guide rails.
for (const x of [-0.58, 0.58]) {
addCylinder(
0.057,
0.057,
4.72,
x,
2.98,
SCREW_Z,
materials.steel,
scene,
16
);
addBox(0.18, 0.12, 0.18, x, 0.61, SCREW_Z, materials.darkSteel, scene, true);
addBox(0.18, 0.12, 0.18, x, 5.35, SCREW_Z, materials.darkSteel, scene, true);
}
// One-start helical thread.
class HelixCurve extends THREE.Curve {
constructor(radius, height, turns) {
super();
this.radius = radius;
this.height = height;
this.turns = turns;
}
getPoint(t, target = new THREE.Vector3()) {
const angle = t * this.turns * TAU;
return target.set(
Math.cos(angle) * this.radius,
t * this.height,
Math.sin(angle) * this.radius
);
}
}
const screwGroup = new THREE.Group();
screwGroup.position.set(0, 0.52, SCREW_Z);
scene.add(screwGroup);
addCylinder(
0.067,
0.067,
4.72,
0,
2.36,
0,
materials.darkSteel,
screwGroup,
20
);
const helix = new HelixCurve(0.125, 4.72, 4.72 / PITCH);
const threadGeometry = new THREE.TubeGeometry(helix, 700, 0.035, 7, false);
const thread = new THREE.Mesh(threadGeometry, materials.thread);
thread.castShadow = true;
thread.receiveShadow = true;
screwGroup.add(thread);
addCylinder(
0.18,
0.18,
0.24,
0,
0.11,
0,
materials.bronze,
screwGroup,
20
);
// Rotation index and longitudinal key make spindle rotation legible.
addBox(
0.29,
0.055,
0.075,
0.145,
0.16,
0,
materials.red,
screwGroup,
true
);
addBox(
0.08,
0.62,
0.11,
0.09,
0.65,
0,
materials.cyan,
screwGroup,
true
);
// Bottom bearing and upper motor.
addCylinder(
0.28,
0.31,
0.2,
0,
0.58,
SCREW_Z,
materials.darkSteel,
scene,
24
);
addCylinder(
0.38,
0.38,
0.6,
0,
5.51,
SCREW_Z,
materials.frame,
scene,
24
);
addCylinder(
0.34,
0.34,
0.12,
0,
5.87,
SCREW_Z,
materials.darkSteel,
scene,
24
);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * TAU;
const fin = addBox(
0.085,
0.43,
0.18,
Math.cos(angle) * 0.39,
5.51,
SCREW_Z + Math.sin(angle) * 0.39,
materials.frameDark,
scene,
true
);
fin.rotation.y = -angle;
}
addBox(0.86, 0.24, 0.72, 0, 6.03, SCREW_Z, materials.frameDark, scene, true);
// Moving assembly.
const movingGroup = new THREE.Group();
movingGroup.position.y = state.position;
scene.add(movingGroup);
addBox(
3.38,
0.28,
2.08,
0,
0,
0.25,
materials.platform,
movingGroup,
true
);
addBox(
3.12,
0.055,
1.82,
0,
0.17,
0.25,
materials.platformBlue,
movingGroup,
true
);
addBox(
3.22,
0.14,
0.12,
0,
-0.01,
1.32,
materials.frame,
movingGroup,
true
);
// Carriage behind the platform.
addBox(
1.72,
0.48,
0.23,
0,
0.27,
-0.82,
materials.darkSteel,
movingGroup,
true
);
for (const x of [-0.58, 0.58]) {
addCylinder(
0.125,
0.125,
0.37,
x,
0.27,
SCREW_Z,
materials.frame,
movingGroup,
20
);
addBox(
0.18,
0.18,
0.46,
x,
0.27,
-0.58,
materials.frameDark,
movingGroup,
true
);
}
// Guided bronze nut surrounding the spinning screw.
addBox(
0.49,
0.5,
0.51,
0,
0.27,
SCREW_Z,
materials.bronze,
movingGroup,
true
);
addBox(
0.68,
0.13,
0.62,
0,
0.03,
SCREW_Z,
materials.bronze,
movingGroup,
true
);
addBox(
0.62,
0.11,
0.56,
0,
0.51,
SCREW_Z,
materials.bronze,
movingGroup,
true
);
for (const x of [-0.14, 0.14]) {
addCylinder(
0.043,
0.043,
0.045,
x,
0.59,
SCREW_Z,
materials.steel,
movingGroup,
12
);
}
// Platform brackets.
for (const x of [-1.17, 1.17]) {
addBox(
0.16,
0.22,
0.72,
x,
0.11,
-0.4,
materials.darkSteel,
movingGroup,
true
);
}
// Voxel fixture blocks on the deck.
addBox(
0.38,
0.38,
0.38,
-0.72,
0.41,
0.32,
materials.frame,
movingGroup,
true
);
addBox(
0.38,
0.38,
0.38,
-0.34,
0.41,
0.32,
materials.cyan,
movingGroup,
true
);
addBox(
0.38,
0.38,
0.38,
-0.34,
0.79,
0.32,
materials.frame,
movingGroup,
true
);
// Fixture stops and deck bolts.
for (const x of [-1.38, 1.38]) {
for (const z of [-0.38, 0.88]) {
addCylinder(
0.055,
0.055,
0.045,
x,
0.225,
z,
materials.steel,
movingGroup,
12
);
}
}
for (const x of [-0.82, 0.82]) {
addBox(
0.16,
0.17,
0.22,
x,
0.28,
0.89,
materials.red,
movingGroup,
true
);
}
// Front safety markings.
for (let i = 0; i < 12; i++) {
const stripe = addBox(
0.09,
0.16,
0.026,
-1.35 + i * 0.245,
0,
1.391,
i % 2 ? materials.darkSteel : materials.frame,
movingGroup
);
stripe.rotation.z = -0.35;
}
// Ruler ticks on the platform deck.
for (let i = 0; i < 17; i++) {
addBox(
0.018,
0.012,
i % 5 === 0 ? 0.22 : 0.12,
-1.3 + i * 0.16,
0.207,
1.02,
materials.steel,
movingGroup
);
}
// Custom camera controller: orbit, pan and zoom without addons.
const cameraGoal = {
theta: 0.72,
phi: 1.12,
radius: 10.2,
target: new THREE.Vector3(0, 2.55, 0)
};
const cameraCurrent = {
theta: cameraGoal.theta,
phi: cameraGoal.phi,
radius: cameraGoal.radius,
target: cameraGoal.target.clone()
};
function setCameraView(name) {
if (name === "iso") {
cameraGoal.theta = 0.72;
cameraGoal.phi = 1.12;
cameraGoal.radius = 10.2;
cameraGoal.target.set(0, 2.55, 0);
} else if (name === "front") {
cameraGoal.theta = 0;
cameraGoal.phi = 1.2;
cameraGoal.radius = 8.5;
cameraGoal.target.set(0, 2.65, 0);
} else if (name === "detail") {
cameraGoal.theta = 0.55;
cameraGoal.phi = 1.25;
cameraGoal.radius = 6.5;
cameraGoal.target.set(0, 2.3, -0.1);
}
}
let dragging = false;
let dragButton = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragButton = event.button;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey || dragButton === 2) {
const scale = cameraGoal.radius * 0.0013;
cameraGoal.target.x -= dx * scale * Math.cos(cameraGoal.theta);
cameraGoal.target.z += dx * scale * Math.sin(cameraGoal.theta);
cameraGoal.target.y += dy * scale;
cameraGoal.target.y = THREE.MathUtils.clamp(cameraGoal.target.y, 0.6, 5.2);
} else {
cameraGoal.theta -= dx * 0.006;
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi - dy * 0.005,
0.34,
1.47
);
}
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius * Math.exp(event.deltaY * 0.001),
4.8,
18
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => setCameraView("iso"));
// UI.
const motorButton = document.querySelector("#motor-button");
const raiseButton = document.querySelector("#raise-button");
const lowerButton = document.querySelector("#lower-button");
const rpmRange = document.querySelector("#rpm-range");
const commandRange = document.querySelector("#command-range");
const rpmValue = document.querySelector("#rpm-value");
const rpmOutput = document.querySelector("#rpm-output");
const commandOutput = document.querySelector("#command-output");
const actualHeight = document.querySelector("#actual-height");
const turnCount = document.querySelector("#turn-count");
const linearRate = document.querySelector("#linear-rate");
const status = document.querySelector("#status");
const statusText = document.querySelector("#status-text");
const kinematicReadout = document.querySelector("#kinematic-readout");
function updateRangeFill(range, accent) {
const min = Number(range.min);
const max = Number(range.max);
const value = Number(range.value);
const percent = ((value - min) / (max - min)) * 100;
range.style.setProperty("--pct", `${percent}%`);
if (accent) range.style.setProperty("--accent", accent);
}
function setDirection(direction) {
state.direction = direction;
state.mode = "manual";
state.locked = false;
state.running = true;
raiseButton.classList.toggle("active", direction > 0);
lowerButton.classList.toggle("active", direction < 0);
}
function seekTo(value) {
state.command = THREE.MathUtils.clamp(value, MIN_HEIGHT, MAX_HEIGHT);
state.mode = "seek";
state.locked = false;
state.running = true;
}
motorButton.addEventListener("click", () => {
if (state.running) {
state.running = false;
} else if (state.mode === "seek") {
state.running = true;
} else {
state.mode = "manual";
state.locked = false;
state.running = true;
}
});
raiseButton.addEventListener("click", () => setDirection(1));
lowerButton.addEventListener("click", () => setDirection(-1));
rpmRange.addEventListener("input", () => {
state.rpm = Number(rpmRange.value);
rpmValue.textContent = `${state.rpm} RPM`;
rpmOutput.textContent = `${state.rpm} RPM`;
updateRangeFill(rpmRange, "#f5a623");
});
commandRange.addEventListener("input", () => {
seekTo(Number(commandRange.value));
});
document.querySelector("#home-button").addEventListener("click", () => {
seekTo(HOME);
});
document.querySelector("#center-button").addEventListener("click", () => {
seekTo((MIN_HEIGHT + MAX_HEIGHT) * 0.5);
});
document.querySelector("#iso-button").addEventListener("click", () => setCameraView("iso"));
document.querySelector("#front-button").addEventListener("click", () => setCameraView("front"));
document.querySelector("#detail-button").addEventListener("click", () => setCameraView("detail"));
const annotationButton = document.querySelector("#annotation-button");
let annotationsVisible = true;
annotationButton.addEventListener("click", () => {
annotationsVisible = !annotationsVisible;
document.body.classList.toggle("annotations-hidden", !annotationsVisible);
annotationButton.setAttribute("aria-pressed", String(annotationsVisible));
annotationButton.textContent = annotationsVisible ? "Labels on" : "Labels off";
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.code === "Space") {
event.preventDefault();
motorButton.click();
} else if (event.code === "ArrowUp") {
event.preventDefault();
setDirection(1);
} else if (event.code === "ArrowDown") {
event.preventDefault();
setDirection(-1);
} else if (event.code === "KeyH") {
seekTo(HOME);
} else if (event.code === "KeyR") {
setCameraView("iso");
}
});
// Scene annotations projected from world positions into the DOM.
const annotations = [
{
line: document.querySelector("#line-screw"),
label: document.querySelector("#label-screw"),
world: new THREE.Vector3(0.12, 1.55, SCREW_Z),
offset: [78, -30]
},
{
line: document.querySelector("#line-nut"),
label: document.querySelector("#label-nut"),
world: new THREE.Vector3(0.25, state.position + 0.3, SCREW_Z),
offset: [95, -54]
},
{
line: document.querySelector("#line-platform"),
label: document.querySelector("#label-platform"),
world: new THREE.Vector3(1.48, state.position + 0.15, 0.85),
offset: [82, 52]
},
{
line: document.querySelector("#line-guide"),
label: document.querySelector("#label-guide"),
world: new THREE.Vector3(-0.58, 2.48, SCREW_Z),
offset: [-92, -18]
}
];
function updateAnnotations() {
for (const annotation of annotations) {
const projected = annotation.world.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.line.style.display = visible ? "" : "none";
annotation.label.style.display = visible ? "" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const x2 = x + annotation.offset[0];
const y2 = y + annotation.offset[1];
annotation.line.setAttribute("x1", x);
annotation.line.setAttribute("y1", y);
annotation.line.setAttribute("x2", x2);
annotation.line.setAttribute("y2", y2);
annotation.label.style.left = `${x2}px`;
annotation.label.style.top = `${y2}px`;
}
}
function updateUI() {
const turns = (state.position - HOME) / PITCH;
const angularSpeed = state.rpm * TAU / 60;
const linearSpeed = PITCH * angularSpeed / TAU;
actualHeight.textContent = state.position.toFixed(3);
turnCount.textContent = `${turns >= 0 ? "+" : ""}${turns.toFixed(2)}`;
linearRate.textContent = linearSpeed.toFixed(2);
kinematicReadout.textContent = `θ = ${turns >= 0 ? "+" : ""}${turns.toFixed(2)} turns`;
commandOutput.textContent = `${state.command.toFixed(2)} u`;
commandRange.value = state.command.toFixed(2);
updateRangeFill(commandRange, "#42c8dc");
updateRangeFill(rpmRange, "#f5a623");
motorButton.textContent = state.running ? "Hold motor" : "Start motor";
motorButton.classList.toggle("running", state.running);
status.classList.toggle("running", state.running && state.mode === "manual");
status.classList.toggle("seeking", state.running && state.mode === "seek");
if (state.running && state.mode === "seek") {
statusText.textContent = "Seeking target";
} else if (state.running) {
statusText.textContent = "Motor running";
} else if (state.locked) {
statusText.textContent = "Target locked";
} else {
statusText.textContent = "Motor held";
}
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateRangeFill(rpmRange, "#f5a623");
updateRangeFill(commandRange, "#42c8dc");
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (state.running) {
const angularSpeed = state.rpm * TAU / 60;
const maxLinearSpeed = PITCH * angularSpeed / TAU;
if (state.mode === "seek") {
const difference = state.command - state.position;
const step = maxLinearSpeed * dt;
if (Math.abs(difference) <= step) {
state.position = state.command;
state.running = false;
state.mode = "idle";
state.locked = true;
} else {
state.position += Math.sign(difference) * step;
}
} else {
const step = maxLinearSpeed * dt;
const nextPosition = state.position + state.direction * step;
if (nextPosition <= MIN_HEIGHT || nextPosition >= MAX_HEIGHT) {
state.position = THREE.MathUtils.clamp(nextPosition, MIN_HEIGHT, MAX_HEIGHT);
state.running = false;
} else {
state.position = nextPosition;
}
state.command = state.position;
}
}
state.position = THREE.MathUtils.clamp(
state.position,
MIN_HEIGHT,
MAX_HEIGHT
);
movingGroup.position.y = state.position;
// Exact single-start kinematic relationship:
// displacement = pitch * rotation / 2π.
const screwRotation = ((state.position - HOME) / PITCH) * TAU;
screwGroup.rotation.y = screwRotation;
// Smooth camera motion.
cameraCurrent.theta = THREE.MathUtils.lerp(
cameraCurrent.theta,
cameraGoal.theta,
0.09
);
cameraCurrent.phi = THREE.MathUtils.lerp(
cameraCurrent.phi,
cameraGoal.phi,
0.09
);
cameraCurrent.radius = THREE.MathUtils.lerp(
cameraCurrent.radius,
cameraGoal.radius,
0.09
);
cameraCurrent.target.lerp(cameraGoal.target, 0.09);
const sinPhi = Math.sin(cameraCurrent.phi);
camera.position.set(
cameraCurrent.target.x +
cameraCurrent.radius * sinPhi * Math.cos(cameraCurrent.theta),
cameraCurrent.target.y + cameraCurrent.radius * Math.cos(cameraCurrent.phi),
cameraCurrent.target.z +
cameraCurrent.radius * sinPhi * Math.sin(cameraCurrent.theta)
);
camera.lookAt(cameraCurrent.target);
updateUI();
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```