Prompt specification
Build or customize the Three.js 3D scene "Screw-driven stage challenge" 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: Screw-driven stage challenge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/screw-driven-stage-challenge-x0288
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts nuts and screw threads. Build a tabletop lifting platform with two linked threaded supports; users synchronize their rotations so the platform rises level while mismatched motion visibly tilts the simplified assembly. Voxel style.
Working Three.js Starter (screw-driven-stage-challenge-x0288):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ThreadLab — Twin Screw Lift</title>
<style>
:root {
--ink: #20363b;
--muted: #6d7d7d;
--paper: #f5f0e4;
--gold: #d89c3e;
--gold-dark: #946225;
--teal: #315d62;
--line: rgba(32, 54, 59, 0.16);
--shadow: 0 18px 50px rgba(26, 43, 46, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ddd8ca;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
[role="slider"] {
-webkit-tap-highlight-color: transparent;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 48%, rgba(36, 47, 46, 0.13)),
linear-gradient(to bottom, rgba(255, 255, 255, 0.12), transparent 24%);
}
.topbar {
position: fixed;
top: 22px;
left: 24px;
right: 24px;
display: flex;
justify-content: space-between;
align-items: flex-start;
pointer-events: none;
z-index: 5;
}
.brand {
max-width: 440px;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 3px;
content: "";
background: var(--gold);
box-shadow: 6px 0 0 rgba(216, 156, 62, 0.35);
}
h1 {
margin: 0;
font-size: clamp(24px, 3.2vw, 42px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.brand p {
max-width: 390px;
margin: 10px 0 0;
color: #526867;
font-size: 13px;
line-height: 1.5;
}
.status-card {
width: 238px;
padding: 15px 16px 14px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 17px;
background: rgba(248, 244, 234, 0.78);
box-shadow: var(--shadow);
backdrop-filter: blur(13px);
pointer-events: auto;
}
.status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.status-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.status-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 999px;
background: #dce9df;
color: #2f6849;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.status-badge::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 3px rgba(47, 104, 73, 0.11);
}
.status-badge.warn {
background: #f4dfc5;
color: #9a5428;
}
.status-badge.warn::before {
box-shadow: 0 0 0 3px rgba(154, 84, 40, 0.11);
}
.status-main {
margin-top: 10px;
font-size: 24px;
font-weight: 800;
letter-spacing: -0.04em;
}
.status-detail {
min-height: 32px;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.balance-track {
position: relative;
height: 9px;
margin-top: 13px;
overflow: hidden;
border: 1px solid rgba(32, 54, 59, 0.13);
border-radius: 99px;
background:
linear-gradient(90deg, transparent 49.5%, rgba(32, 54, 59, 0.35) 49.5% 50.5%, transparent 50.5%),
#e2ddcf;
}
#balanceBubble {
position: absolute;
top: 1px;
left: 50%;
width: 18px;
height: 5px;
border-radius: 99px;
background: var(--teal);
box-shadow: 0 1px 4px rgba(25, 50, 52, 0.2);
transform: translateX(-50%);
transition: left 120ms ease-out, background 120ms ease-out;
}
.balance-caption {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #82908f;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.scene-tag {
position: fixed;
z-index: 3;
display: grid;
width: 28px;
height: 28px;
place-items: center;
border: 2px solid rgba(255, 255, 255, 0.8);
border-radius: 8px;
background: rgba(38, 70, 74, 0.87);
color: #ffe1a0;
box-shadow: 0 5px 15px rgba(22, 42, 45, 0.22);
font-size: 11px;
font-weight: 900;
pointer-events: none;
will-change: transform;
}
#controls {
position: fixed;
z-index: 10;
left: 50%;
bottom: 18px;
display: grid;
grid-template-columns: minmax(250px, 1fr) 225px minmax(250px, 1fr);
width: min(930px, calc(100vw - 32px));
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 23px;
background: rgba(248, 244, 234, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
transform: translateX(-50%);
}
.control-card {
padding: 16px 19px 15px;
}
.control-card + .control-card,
.center-card {
border-left: 1px solid var(--line);
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
}
.control-head strong {
font-size: 10px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.key {
padding: 3px 6px;
border: 1px solid var(--line);
border-radius: 5px;
color: #7e8b89;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
}
.dial-row {
display: flex;
align-items: center;
gap: 16px;
}
.dial {
--angle: 0deg;
position: relative;
flex: 0 0 auto;
width: 100px;
aspect-ratio: 1;
border: 4px solid #c89138;
border-radius: 50%;
background:
repeating-conic-gradient(
from -1deg,
rgba(255, 231, 179, 0.68) 0deg 2deg,
transparent 2deg 15deg
),
radial-gradient(
circle,
#28464b 0 31%,
#172f34 32% 49%,
#c18a35 50% 54%,
#38575b 55% 100%
);
box-shadow:
inset 0 0 0 5px rgba(16, 35, 38, 0.34),
0 8px 18px rgba(35, 49, 48, 0.2);
cursor: grab;
touch-action: none;
user-select: none;
}
.dial:active {
cursor: grabbing;
}
.dial:focus-visible {
outline: 3px solid rgba(49, 93, 98, 0.38);
outline-offset: 4px;
}
.dial-pointer {
position: absolute;
top: 13px;
left: calc(50% - 2px);
width: 4px;
height: 37%;
border-radius: 3px;
background: #ffe19a;
box-shadow: 0 0 5px rgba(255, 222, 148, 0.45);
transform: translateX(-50%) rotate(var(--angle));
transform-origin: 50% 100%;
}
.dial-hub {
position: absolute;
top: 50%;
left: 50%;
width: 18px;
height: 18px;
border: 3px solid #efc36c;
border-radius: 50%;
background: #25444a;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.28);
transform: translate(-50%, -50%);
}
.dial-hub::after {
position: absolute;
top: 50%;
left: 50%;
width: 5px;
height: 5px;
content: "";
border-radius: 50%;
background: #d89c3e;
transform: translate(-50%, -50%);
}
.counter {
min-width: 83px;
}
.turn-value {
font-variant-numeric: tabular-nums;
font-size: 31px;
font-weight: 800;
letter-spacing: -0.06em;
line-height: 1;
}
.turn-value small {
margin-left: 3px;
color: #7e8d8c;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.degree-value {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.step-buttons {
display: flex;
gap: 5px;
margin-top: 9px;
}
.step-buttons button,
.small-button {
min-width: 37px;
height: 27px;
padding: 0 8px;
border: 1px solid rgba(32, 54, 59, 0.17);
border-radius: 7px;
background: #ece6d8;
color: var(--ink);
font-size: 10px;
font-weight: 850;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
.step-buttons button:hover,
.small-button:hover {
background: #ded5c2;
transform: translateY(-1px);
}
.step-buttons button:active,
.small-button:active {
transform: translateY(0);
}
.center-card {
display: flex;
flex-direction: column;
justify-content: center;
padding: 15px 18px;
text-align: center;
}
.center-card h2 {
margin: 0 0 5px;
font-size: 13px;
letter-spacing: -0.02em;
}
.center-card p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.mini-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 11px 0;
}
.mini-stat {
padding: 7px 5px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.3);
}
.mini-stat span {
display: block;
color: #82908f;
font-size: 7px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.mini-stat strong {
display: block;
margin-top: 2px;
font-size: 14px;
font-variant-numeric: tabular-nums;
}
#resetButton {
width: 100%;
height: 31px;
}
.camera-help {
position: fixed;
z-index: 4;
right: 25px;
bottom: 202px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.38);
border-radius: 8px;
background: rgba(248, 244, 234, 0.56);
color: rgba(32, 54, 59, 0.67);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #ddd8ca;
color: var(--teal);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 300ms ease, visibility 300ms ease;
}
#loading.hidden {
visibility: hidden;
opacity: 0;
}
@media (max-width: 800px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand p {
display: none;
}
.status-card {
width: 190px;
padding: 11px 12px;
}
.status-main {
font-size: 19px;
}
.status-detail {
display: none;
}
#controls {
bottom: 10px;
grid-template-columns: 1fr 1fr;
width: calc(100vw - 20px);
}
.center-card {
grid-column: 1 / -1;
grid-row: 2;
display: grid;
grid-template-columns: 1fr 180px 100px;
align-items: center;
gap: 12px;
padding: 10px 13px;
border-top: 1px solid var(--line);
border-left: 0;
text-align: left;
}
.center-card p {
display: none;
}
.mini-stats {
margin: 0;
}
.control-card {
padding: 12px;
}
.control-card:nth-child(3) {
border-left: 1px solid var(--line);
}
.dial-row {
gap: 10px;
}
.dial {
width: 78px;
}
.turn-value {
font-size: 24px;
}
.camera-help {
display: none;
}
}
@media (max-width: 480px) {
h1 {
font-size: 23px;
}
.eyebrow {
font-size: 8px;
}
.status-card {
width: 150px;
}
.status-top {
align-items: flex-start;
flex-direction: column;
gap: 5px;
}
.status-main {
font-size: 16px;
}
.balance-track,
.balance-caption {
display: none;
}
.dial-row {
gap: 7px;
}
.dial {
width: 66px;
}
.counter {
min-width: 63px;
}
.turn-value {
font-size: 20px;
}
.key {
display: none;
}
.control-head strong {
font-size: 8px;
}
.center-card {
grid-template-columns: 1fr 145px;
}
.center-card h2 {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive voxel twin-screw lifting platform"></div>
<div id="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">ThreadLab / Mechanical Study 04</div>
<h1>Twin Screw Lift</h1>
<p>
Rotate the two brass supports independently. Match their turn counts to
lift the tabletop evenly; a mismatch makes the linked frame visibly tilt.
</p>
</div>
<section class="status-card" aria-live="polite">
<div class="status-top">
<span class="status-label">Platform state</span>
<span id="statusBadge" class="status-badge">Level locked</span>
</div>
<div id="statusMain" class="status-main">0.0° tilt</div>
<div id="statusDetail" class="status-detail">
Both supports carry equal rise.
</div>
<div class="balance-track" aria-hidden="true">
<div id="balanceBubble"></div>
</div>
<div class="balance-caption">
<span>Left high</span>
<span>Level</span>
<span>Right high</span>
</div>
</section>
</header>
<div id="tagL" class="scene-tag">L</div>
<div id="tagR" class="scene-tag">R</div>
<div class="camera-help">Drag scene to orbit · scroll to zoom</div>
<section id="controls" aria-label="Twin screw controls">
<section class="control-card">
<div class="control-head">
<strong>Left support</strong>
<span class="key">A / D</span>
</div>
<div class="dial-row">
<div
id="dial0"
class="dial"
role="slider"
tabindex="0"
aria-label="Left support rotation"
aria-valuemin="0"
aria-valuemax="22"
aria-valuenow="0"
>
<div class="dial-pointer"></div>
<div class="dial-hub"></div>
</div>
<div class="counter">
<div class="turn-value"><span id="turns0">0.00</span><small>turns</small></div>
<div id="degrees0" class="degree-value">0° rotation</div>
<div class="step-buttons">
<button type="button" data-side="0" data-delta="-1" aria-label="Turn left support counterclockwise">−1</button>
<button type="button" data-side="0" data-delta="1" aria-label="Turn left support clockwise">+1</button>
</div>
</div>
</div>
</section>
<section class="center-card">
<div>
<h2>Synchronize the screws</h2>
<p>Drag each brass dial clockwise. Equal turns produce a level platform.</p>
</div>
<div class="mini-stats">
<div class="mini-stat">
<span>Lift</span>
<strong id="liftReadout">0 cm</strong>
</div>
<div class="mini-stat">
<span>Difference</span>
<strong id="differenceReadout">0.00</strong>
</div>
</div>
<button id="resetButton" class="small-button" type="button">RESET</button>
</section>
<section class="control-card">
<div class="control-head">
<strong>Right support</strong>
<span class="key">J / L</span>
</div>
<div class="dial-row">
<div
id="dial1"
class="dial"
role="slider"
tabindex="0"
aria-label="Right support rotation"
aria-valuemin="0"
aria-valuemax="22"
aria-valuenow="0"
>
<div class="dial-pointer"></div>
<div class="dial-hub"></div>
</div>
<div class="counter">
<div class="turn-value"><span id="turns1">0.00</span><small>turns</small></div>
<div id="degrees1" class="degree-value">0° rotation</div>
<div class="step-buttons">
<button type="button" data-side="1" data-delta="-1" aria-label="Turn right support counterclockwise">−1</button>
<button type="button" data-side="1" data-delta="1" aria-label="Turn right support clockwise">+1</button>
</div>
</div>
</div>
</section>
</section>
<div id="loading">Assembling thread mechanism…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene and renderer
// ---------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xddd8ca);
scene.fog = new THREE.Fog(0xddd8ca, 25, 43);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6.2, -6.2, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 2.75, 0.2);
const cameraState = {
yaw: 0.58,
pitch: 0.38,
zoom: 1
};
function updateCamera() {
const radius = 19;
const horizontal = Math.cos(cameraState.pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontal,
cameraTarget.y + Math.sin(cameraState.pitch) * radius,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff4dc, 0x65757a, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffefd4, 3.3);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.0007;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb8d5db, 1.25);
rimLight.position.set(-8, 7, -9);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Materials and voxel helpers
// ---------------------------------------------------------------------
function material(color, roughness = 0.72, metalness = 0.04) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const mats = {
steel: material(0x31545a, 0.62, 0.18),
steelLight: material(0x58767a, 0.58, 0.2),
steelDark: material(0x1d353b, 0.67, 0.2),
gold: material(0xd79a3d, 0.48, 0.42),
goldLight: material(0xf0bd62, 0.46, 0.38),
goldDark: material(0x966125, 0.58, 0.34),
rubber: material(0x1b262a, 0.95, 0),
wood: material(0xcda66e, 0.9, 0),
woodLight: material(0xdcb87d, 0.9, 0),
woodDark: material(0xb88c55, 0.92, 0),
cream: material(0xe8dfc8, 0.86, 0),
floorA: material(0xe1dccd, 0.96, 0),
floorB: material(0xd7d2c3, 0.96, 0)
};
function box(w, h, d, mat, x, y, z, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function createNut(outerSize, holeSize, height, parent, x, y, z, bodyMat = mats.gold) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const side = (outerSize - holeSize) / 2;
const offset = holeSize / 2 + side / 2;
// Four cuboids create a true square opening.
box(side, height, outerSize, bodyMat, -offset, 0, 0, group);
box(side, height, outerSize, bodyMat, offset, 0, 0, group);
box(holeSize, height, side, bodyMat, 0, 0, -offset, group);
box(holeSize, height, side, bodyMat, 0, 0, offset, group);
// Raised top and bottom lips.
const lip = height * 0.2;
box(outerSize, lip, outerSize, mats.goldLight, 0, height * 0.53, 0, group)
.visible = false;
const lipOuter = outerSize * 0.94;
const lipHole = holeSize * 1.08;
const lipSide = (lipOuter - lipHole) / 2;
const lipOffset = lipHole / 2 + lipSide / 2;
box(lipSide, lip, lipOuter, bodyMat, -lipOffset, height / 2, 0, group);
box(lipSide, lip, lipOuter, bodyMat, lipOffset, height / 2, 0, group);
box(lipHole, lip, lipSide, bodyMat, 0, height / 2, -lipOffset, group);
box(lipHole, lip, lipSide, bodyMat, 0, height / 2, lipOffset, group);
return group;
}
// ---------------------------------------------------------------------
// Voxel floor
// ---------------------------------------------------------------------
const tileGeometry = new THREE.BoxGeometry(0.96, 0.065, 0.96);
const tileMaterial = material(0xffffff, 0.96, 0);
const tileCountX = 16;
const tileCountZ = 12;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCountX * tileCountZ
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let iz = 0; iz < tileCountZ; iz++) {
for (let ix = 0; ix < tileCountX; ix++) {
dummy.position.set(
(ix - (tileCountX - 1) / 2) * 1.02,
-0.095,
(iz - (tileCountZ - 1) / 2) * 1.02
);
dummy.rotation.y = ((ix + iz) % 2) * 0.006;
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
tileColor.set((ix + iz) % 3 === 0 ? 0xe8e2d3 : (ix + iz) % 2 ? 0xdcd7c8 : 0xe0dbcc);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// ---------------------------------------------------------------------
// Base platform
// ---------------------------------------------------------------------
const base = new THREE.Group();
scene.add(base);
box(10.6, 0.58, 6.6, mats.steelDark, 0, 0.48, 0, base);
box(10.85, 0.16, 6.85, mats.steel, 0, 0.80, 0, base);
box(9.9, 0.10, 5.95, mats.steelLight, 0, 0.90, 0, base);
for (const x of [-4.35, 4.35]) {
for (const z of [-2.55, 2.55]) {
box(1.12, 0.25, 1.12, mats.rubber, x, 0.09, z, base);
}
}
for (const z of [-2.8, 2.8]) {
box(8.8, 0.11, 0.12, mats.goldDark, 0, 0.38, z, base);
}
// Voxel mounting blocks around each threaded support.
for (const x of [-3.25, 3.25]) {
box(1.55, 0.18, 1.55, mats.steelDark, x, 1.00, 2.05, base);
box(1.18, 0.13, 1.18, mats.goldDark, x, 1.13, 2.05, base);
}
// ---------------------------------------------------------------------
// Threaded supports
// ---------------------------------------------------------------------
const SUPPORT_X = 3.25;
const SUPPORT_Z = 2.05;
const BASE_HEIGHT = 1.75;
const LIFT_PER_TURN = 0.11;
const MAX_TURNS = 22;
function createScrew(x, z) {
const root = new THREE.Group();
root.position.set(x, 0, z);
scene.add(root);
// Stationary bearing housing.
box(1.04, 0.54, 1.08, mats.steel, 0, 1.36, 0, root);
box(0.78, 0.18, 0.82, mats.goldDark, 0, 1.68, 0, root);
const rotator = new THREE.Group();
root.add(rotator);
// Square steel core.
box(0.34, 6.65, 0.34, mats.steelDark, 0, 4.22, 0, rotator);
box(0.42, 0.12, 0.42, mats.steelLight, 0, 7.55, 0, rotator);
// A stepped diagonal thread made from many small cuboids.
for (let i = 0; i < 51; i++) {
const y = 1.03 + i * 0.128;
const angle = i * 0.72;
const radius = 0.265;
const thread = box(
0.42,
0.11,
0.17,
i % 4 === 0 ? mats.goldLight : mats.gold,
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius,
rotator
);
thread.rotation.y = -angle;
}
// Forward-facing crank axle and cross handle.
box(0.24, 0.24, 1.85, mats.steelLight, 0, 1.39, 0.88, rotator);
box(0.18, 0.92, 0.18, mats.gold, 0, 1.39, 1.78, rotator);
box(0.92, 0.18, 0.18, mats.gold, 0, 1.39, 1.78, rotator);
box(0.31, 0.31, 0.31, mats.goldLight, 0, 1.86, 1.78, rotator);
box(0.31, 0.31, 0.31, mats.goldLight, 0, 0.92, 1.78, rotator);
return { root, rotator };
}
const leftScrew = createScrew(-SUPPORT_X, SUPPORT_Z);
const rightScrew = createScrew(SUPPORT_X, SUPPORT_Z);
// ---------------------------------------------------------------------
// Lifting tabletop and linked nuts
// ---------------------------------------------------------------------
const platform = new THREE.Group();
scene.add(platform);
// Main steel table slab.
box(10.55, 0.65, 5.8, mats.steel, 0, 0.95, 0, platform);
box(10.82, 0.14, 6.02, mats.steelDark, 0, 0.64, 0, platform);
// Underside frame.
for (const z of [-1.72, 1.72]) {
box(9.7, 0.34, 0.34, mats.steelDark, 0, 0.39, z, platform);
}
for (const x of [-2.05, 2.05]) {
box(0.34, 0.34, 4.75, mats.steelDark, x, 0.39, 0, platform);
}
// Six voxel wooden tabletop planks.
for (let i = 0; i < 6; i++) {
const plankMat = i % 3 === 0 ? mats.woodDark : (i % 2 ? mats.wood : mats.woodLight);
const x = -4.38 + i * 1.75;
box(1.715, 0.18, 5.40, plankMat, x, 1.37, 0, platform);
}
// Main threaded nuts and their upper mounting brackets.
createNut(1.20, 0.49, 0.55, platform, -SUPPORT_X, 0, SUPPORT_Z);
createNut(1.20, 0.49, 0.55, platform, SUPPORT_X, 0, SUPPORT_Z);
box(0.72, 0.36, 0.78, mats.steelDark, -SUPPORT_X, 0.47, SUPPORT_Z, platform);
box(0.72, 0.36, 0.78, mats.steelDark, SUPPORT_X, 0.47, SUPPORT_Z, platform);
// Visible linkage tying the two nuts together.
box(SUPPORT_X * 2, 0.22, 0.42, mats.steelLight, 0, -0.18, SUPPORT_Z, platform);
box(0.42, 0.22, 3.3, mats.steelLight, 0, -0.18, 0.55, platform);
for (const x of [-SUPPORT_X, SUPPORT_X]) {
box(0.23, 0.74, 0.23, mats.goldDark, x, -0.42, SUPPORT_Z, platform);
}
// Loose voxel nuts on the tabletop.
const looseNutA = createNut(0.48, 0.23, 0.24, platform, -1.65, 1.61, -0.85, mats.gold);
looseNutA.rotation.y = 0.36;
const looseNutB = createNut(0.38, 0.18, 0.21, platform, -0.75, 1.57, -1.48, mats.goldLight);
looseNutB.rotation.y = -0.48;
// A small loose bolt built entirely from blocks.
const looseBolt = new THREE.Group();
looseBolt.position.set(1.50, 1.56, 0.95);
looseBolt.rotation.y = -0.38;
platform.add(looseBolt);
box(0.17, 0.17, 1.18, mats.steelLight, 0, 0, 0, looseBolt);
box(0.44, 0.18, 0.30, mats.gold, 0, 0, -0.67, looseBolt);
for (let i = 0; i < 5; i++) {
box(0.23, 0.07, 0.11, mats.goldDark, 0, 0.095, -0.38 + i * 0.20, looseBolt);
}
// A second, larger bolt.
const looseBolt2 = new THREE.Group();
looseBolt2.position.set(2.55, 1.57, -1.40);
looseBolt2.rotation.y = 0.65;
platform.add(looseBolt2);
box(0.22, 0.22, 1.55, mats.steelDark, 0, 0, 0, looseBolt2);
box(0.58, 0.22, 0.40, mats.gold, 0, 0, -0.91, looseBolt2);
for (let i = 0; i < 6; i++) {
box(0.29, 0.08, 0.13, mats.goldLight, 0, 0.13, -0.58 + i * 0.23, looseBolt2);
}
// ---------------------------------------------------------------------
// Interaction state
// ---------------------------------------------------------------------
const state = {
turns: [0, 0]
};
const turnDisplays = [
document.getElementById("turns0"),
document.getElementById("turns1")
];
const degreeDisplays = [
document.getElementById("degrees0"),
document.getElementById("degrees1")
];
const dials = [
document.getElementById("dial0"),
document.getElementById("dial1")
];
const statusBadge = document.getElementById("statusBadge");
const statusMain = document.getElementById("statusMain");
const statusDetail = document.getElementById("statusDetail");
const balanceBubble = document.getElementById("balanceBubble");
const liftReadout = document.getElementById("liftReadout");
const differenceReadout = document.getElementById("differenceReadout");
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function setTurn(side, value) {
state.turns[side] = clamp(value, 0, MAX_TURNS);
refreshUI();
}
function refreshUI() {
const left = state.turns[0];
const right = state.turns[1];
const difference = right - left;
const leftHeight = BASE_HEIGHT + left * LIFT_PER_TURN;
const rightHeight = BASE_HEIGHT + right * LIFT_PER_TURN;
const averageHeight = (leftHeight + rightHeight) / 2;
const tilt = Math.abs(
Math.atan2(rightHeight - leftHeight, SUPPORT_X * 2) * 180 / Math.PI
);
for (let side = 0; side < 2; side++) {
const turns = state.turns[side];
const degrees = ((turns * 360) % 360 + 360) % 360;
turnDisplays[side].textContent = turns.toFixed(2);
degreeDisplays[side].textContent = `${Math.round(degrees)}° rotation`;
dials[side].style.setProperty("--angle", `${turns * 360}deg`);
dials[side].setAttribute("aria-valuenow", turns.toFixed(2));
}
statusMain.textContent = `${tilt.toFixed(1)}° tilt`;
differenceReadout.textContent = `${Math.abs(difference).toFixed(2)} turn`;
liftReadout.textContent = `${Math.round((averageHeight - BASE_HEIGHT) * 27.3)} cm`;
const bubbleOffset = clamp(difference * 8, -43, 43);
balanceBubble.style.left = `${50 + bubbleOffset}%`;
balanceBubble.style.background = Math.abs(difference) < 0.08 ? "#315d62" : "#d4873d";
if (Math.abs(difference) < 0.08) {
statusBadge.textContent = "Level locked";
statusBadge.className = "status-badge";
statusDetail.textContent = "Both supports carry equal rise.";
} else {
statusBadge.textContent = "Out of sync";
statusBadge.className = "status-badge warn";
const leading = difference > 0 ? "Right" : "Left";
statusDetail.textContent = `${leading} support is ahead by ${Math.abs(difference).toFixed(2)} turns.`;
}
}
// Rotary drag controls.
dials.forEach((dial, side) => {
let dragging = false;
let lastAngle = 0;
function pointerAngle(event) {
const rect = dial.getBoundingClientRect();
const x = event.clientX - (rect.left + rect.width / 2);
const y = event.clientY - (rect.top + rect.height / 2);
return Math.atan2(y, x);
}
dial.addEventListener("pointerdown", (event) => {
event.preventDefault();
dragging = true;
lastAngle = pointerAngle(event);
dial.setPointerCapture(event.pointerId);
dial.focus({ preventScroll: true });
});
dial.addEventListener("pointermove", (event) => {
if (!dragging) return;
const angle = pointerAngle(event);
let delta = angle - lastAngle;
if (delta > Math.PI) delta -= Math.PI * 2;
if (delta < -Math.PI) delta += Math.PI * 2;
setTurn(side, state.turns[side] + delta / (Math.PI * 2));
lastAngle = angle;
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && dial.hasPointerCapture(event.pointerId)) {
dial.releasePointerCapture(event.pointerId);
}
}
dial.addEventListener("pointerup", endDrag);
dial.addEventListener("pointercancel", endDrag);
dial.addEventListener("lostpointercapture", () => {
dragging = false;
});
dial.addEventListener("keydown", (event) => {
const step = event.shiftKey ? 0.1 : 0.5;
if (event.key === "ArrowUp" || event.key === "ArrowRight") {
event.preventDefault();
setTurn(side, state.turns[side] + step);
}
if (event.key === "ArrowDown" || event.key === "ArrowLeft") {
event.preventDefault();
setTurn(side, state.turns[side] - step);
}
});
});
document.querySelectorAll("[data-side][data-delta]").forEach((button) => {
button.addEventListener("click", () => {
const side = Number(button.dataset.side);
const delta = Number(button.dataset.delta);
setTurn(side, state.turns[side] + delta);
});
});
document.getElementById("resetButton").addEventListener("click", () => {
state.turns = [0, 0];
refreshUI();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
const key = event.key.toLowerCase();
if (key === "a") setTurn(0, state.turns[0] - 1);
if (key === "d") setTurn(0, state.turns[0] + 1);
if (key === "j") setTurn(1, state.turns[1] - 1);
if (key === "l") setTurn(1, state.turns[1] + 1);
});
// ---------------------------------------------------------------------
// Direct camera orbit and zoom controls
// ---------------------------------------------------------------------
let orbiting = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
orbiting = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbiting) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = clamp(cameraState.pitch + dy * 0.005, 0.2, 1.02);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function endOrbit(event) {
orbiting = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endOrbit);
renderer.domElement.addEventListener("pointercancel", endOrbit);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.7
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.58;
cameraState.pitch = 0.38;
cameraState.zoom = 1;
updateCamera();
});
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the full mechanism on narrow portrait screens.
const halfHeight = Math.max(6.2, 6.8 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(current, target, 1 - Math.exp(-lambda * dt));
}
const tagL = document.getElementById("tagL");
const tagR = document.getElementById("tagR");
const tagPositionL = new THREE.Vector3(-SUPPORT_X, 1.22, 3.65);
const tagPositionR = new THREE.Vector3(SUPPORT_X, 1.22, 3.65);
const projected = new THREE.Vector3();
function positionTag(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform = `translate(${x}px, ${y}px) translate(-50%, -50%)`;
element.style.opacity = projected.z > -1 && projected.z < 1 ? "1" : "0";
}
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const leftHeight = BASE_HEIGHT + state.turns[0] * LIFT_PER_TURN;
const rightHeight = BASE_HEIGHT + state.turns[1] * LIFT_PER_TURN;
const targetY = (leftHeight + rightHeight) / 2;
const targetTilt = Math.atan2(
rightHeight - leftHeight,
SUPPORT_X * 2
);
platform.position.y = damp(platform.position.y, targetY, 8, dt);
platform.rotation.z = damp(platform.rotation.z, targetTilt, 8, dt);
leftScrew.rotator.rotation.y = damp(
leftScrew.rotator.rotation.y,
state.turns[0] * Math.PI * 2,
9,
dt
);
rightScrew.rotator.rotation.y = damp(
rightScrew.rotator.rotation.y,
state.turns[1] * Math.PI * 2,
9,
dt
);
renderer.render(scene, camera);
positionTag(tagL, tagPositionL);
positionTag(tagR, tagPositionR);
requestAnimationFrame(animate);
}
refreshUI();
platform.position.y = BASE_HEIGHT;
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```