Prompt specification
Build or customize the Three.js 3D scene "Uneven-floor furniture workshop" 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: Uneven-floor furniture workshop
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/uneven-floor-furniture-workshop-x0316
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a spirit level. Build a miniature workshop with sloped floor sections and adjustable feet; users level a work surface while independent floor and tabletop angle indicators remain visible. Low-poly.
Working Three.js Starter (uneven-floor-furniture-workshop-x0316):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tiny Tilt Workshop</title>
<style>
:root {
--ink: #25312d;
--muted: #6e7974;
--paper: rgba(255, 252, 244, 0.92);
--line: rgba(37, 49, 45, 0.13);
--orange: #e96f36;
--orange-dark: #b84922;
--teal: #248b83;
--teal-dark: #14645f;
--yellow: #f1bf36;
--green: #4f9f68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e0d2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}
.brand-kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 5px;
color: var(--orange-dark);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.brand-kicker::before {
width: 25px;
height: 4px;
border-radius: 99px;
background: var(--orange);
content: "";
}
.brand h1 {
margin: 0;
font-size: clamp(24px, 3vw, 40px);
font-weight: 900;
letter-spacing: -0.055em;
line-height: 0.95;
}
.brand p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
font-weight: 650;
}
#gauges {
position: fixed;
top: 20px;
right: 20px;
z-index: 6;
display: flex;
gap: 10px;
pointer-events: none;
}
.gauge {
display: grid;
grid-template-columns: 58px 1fr;
gap: 11px;
align-items: center;
width: 210px;
min-height: 82px;
padding: 11px 13px 11px 10px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(47, 55, 48, 0.12);
backdrop-filter: blur(14px);
}
.bubble-stage {
position: relative;
width: 58px;
height: 58px;
overflow: hidden;
border: 1px solid rgba(37, 49, 45, 0.17);
border-radius: 50%;
background:
linear-gradient(transparent 49%, rgba(37, 49, 45, 0.13) 49% 51%, transparent 51%),
linear-gradient(90deg, transparent 49%, rgba(37, 49, 45, 0.13) 49% 51%, transparent 51%),
#f8f3e8;
box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.5);
}
.bubble-stage::after {
position: absolute;
inset: 20px;
border: 1px solid rgba(37, 49, 45, 0.12);
border-radius: 50%;
content: "";
}
.bubble-dot {
position: absolute;
top: 50%;
left: 50%;
z-index: 2;
width: 13px;
height: 13px;
border: 2px solid rgba(255, 255, 255, 0.9);
border-radius: 50%;
background: var(--teal);
box-shadow: 0 2px 7px rgba(20, 100, 95, 0.32);
transform: translate(-50%, -50%);
transition: left 100ms linear, top 100ms linear;
}
.gauge.floor .bubble-dot {
background: var(--orange);
}
.gauge-label {
margin-bottom: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.gauge-value {
font-size: 23px;
font-weight: 900;
letter-spacing: -0.04em;
line-height: 1;
}
.gauge-detail {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
white-space: nowrap;
}
.gauge-status {
display: inline-block;
margin-top: 4px;
padding: 2px 6px;
border-radius: 99px;
background: rgba(242, 191, 54, 0.2);
color: #8a6110;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.gauge-status.level {
background: rgba(79, 159, 104, 0.16);
color: #34784b;
}
#console {
position: fixed;
bottom: 18px;
left: 18px;
z-index: 7;
width: 330px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 17px;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(47, 55, 48, 0.16);
backdrop-filter: blur(16px);
scrollbar-width: thin;
}
.console-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.console-head h2 {
margin: 0;
font-size: 17px;
font-weight: 900;
letter-spacing: -0.035em;
}
.console-head p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.icon-button {
display: grid;
width: 31px;
height: 31px;
flex: 0 0 auto;
place-items: center;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.68);
font-size: 16px;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
.icon-button:hover {
background: white;
transform: translateY(-1px);
}
.section {
padding-top: 14px;
border-top: 1px solid var(--line);
}
.section:first-of-type {
padding-top: 0;
border-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.tiny-button {
padding: 4px 7px;
border: 1px solid var(--line);
border-radius: 7px;
background: transparent;
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
cursor: pointer;
}
.tiny-button:hover {
background: white;
color: var(--ink);
}
.slider-row {
display: grid;
grid-template-columns: 54px 1fr 43px;
gap: 9px;
align-items: center;
margin: 9px 0;
}
.slider-row label {
font-size: 10px;
font-weight: 800;
}
.slider-row output {
padding: 4px 5px;
border-radius: 7px;
background: rgba(36, 139, 131, 0.09);
color: var(--teal-dark);
font-size: 10px;
font-weight: 900;
text-align: center;
}
input[type="range"] {
width: 100%;
height: 4px;
border-radius: 99px;
outline: none;
background: linear-gradient(90deg, var(--teal), #b8d1ca);
cursor: pointer;
accent-color: var(--teal);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 11px;
}
.action-button {
min-height: 38px;
padding: 8px 9px;
border: 0;
border-radius: 11px;
background: var(--orange);
color: white;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.06em;
cursor: pointer;
box-shadow: 0 5px 12px rgba(233, 111, 54, 0.22);
transition: transform 120ms ease, filter 120ms ease;
}
.action-button.secondary {
background: rgba(36, 139, 131, 0.1);
color: var(--teal-dark);
box-shadow: none;
}
.action-button:hover {
filter: brightness(1.05);
transform: translateY(-1px);
}
.foot-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.foot-control {
display: grid;
grid-template-columns: 23px 28px 1fr 28px;
align-items: center;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.48);
}
.foot-code {
padding-left: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
}
.foot-control button {
width: 28px;
height: 31px;
padding: 0;
border: 0;
background: transparent;
color: var(--teal-dark);
font-size: 16px;
font-weight: 800;
cursor: pointer;
}
.foot-control button:hover {
background: rgba(36, 139, 131, 0.1);
}
.foot-control output {
color: var(--ink);
font-size: 9px;
font-weight: 850;
text-align: center;
}
.console-foot {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.key {
display: inline-block;
padding: 1px 4px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font-size: 8px;
font-weight: 900;
}
#hint {
position: fixed;
right: 20px;
bottom: 19px;
z-index: 5;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 99px;
background: rgba(255, 252, 244, 0.72);
color: var(--muted);
font-size: 9px;
font-weight: 750;
pointer-events: none;
backdrop-filter: blur(10px);
}
@media (max-width: 920px) {
#gauges {
top: 14px;
right: 14px;
}
.gauge {
width: 184px;
}
.brand p {
display: none;
}
}
@media (max-width: 680px) {
.brand {
top: 16px;
left: 15px;
}
.brand h1 {
max-width: 145px;
font-size: 25px;
}
.brand-kicker {
font-size: 8px;
}
#gauges {
top: 83px;
left: 10px;
right: 10px;
gap: 7px;
}
.gauge {
grid-template-columns: 43px 1fr;
width: 50%;
min-height: 65px;
padding: 8px;
border-radius: 14px;
}
.bubble-stage {
width: 43px;
height: 43px;
}
.gauge-value {
font-size: 18px;
}
.gauge-detail {
overflow: hidden;
text-overflow: ellipsis;
}
#console {
right: 8px;
bottom: 8px;
left: 8px;
width: auto;
max-height: 43vh;
padding: 13px;
border-radius: 17px;
}
.console-head {
margin-bottom: 11px;
}
.console-head p,
#hint {
display: none;
}
.section {
padding-top: 10px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive miniature workshop"></main>
<header class="brand">
<div class="brand-kicker">Precision in miniature</div>
<h1>Tiny Tilt<br>Workshop</h1>
<p>Level the bench without trusting the floor.</p>
</header>
<aside id="gauges" aria-label="Independent angle indicators">
<section class="gauge floor">
<div class="bubble-stage">
<div id="floorBubble" class="bubble-dot"></div>
</div>
<div>
<div class="gauge-label">Floor decks</div>
<div id="floorValue" class="gauge-value">+0.0°</div>
<div id="floorDetail" class="gauge-detail">Rear + front mean</div>
<span id="floorStatus" class="gauge-status">Two sections</span>
</div>
</section>
<section class="gauge table">
<div class="bubble-stage">
<div id="tableBubble" class="bubble-dot"></div>
</div>
<div>
<div class="gauge-label">Tabletop</div>
<div id="tableValue" class="gauge-value">0.0°</div>
<div id="tableDetail" class="gauge-detail">Absolute tilt</div>
<span id="tableStatus" class="gauge-status level">Level</span>
</div>
</section>
</aside>
<section id="console" class="panel" aria-label="Workshop controls">
<div class="console-head">
<div>
<h2>Leveling console</h2>
<p>Adjust the split floor, then trim each adjustable foot.</p>
</div>
<button id="resetView" class="icon-button" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<div class="section">
<div class="section-title">
<span>Floor sections</span>
<button id="resetFloor" class="tiny-button">RESET</button>
</div>
<div class="slider-row">
<label for="rearAngle">Rear deck</label>
<input id="rearAngle" type="range" min="-8" max="8" step="0.1" value="-5">
<output id="rearAngleValue">−5.0°</output>
</div>
<div class="slider-row">
<label for="frontAngle">Front deck</label>
<input id="frontAngle" type="range" min="-8" max="8" step="0.1" value="4.5">
<output id="frontAngleValue">+4.5°</output>
</div>
</div>
<div class="section">
<div class="section-title">
<span>Adjustable feet</span>
<button id="resetFeet" class="tiny-button">CENTER</button>
</div>
<div id="footControls" class="foot-grid"></div>
<div class="button-row">
<button id="autoLevel" class="action-button">AUTO-LEVEL TABLE</button>
<button id="followFloor" class="action-button secondary">MATCH FLOOR</button>
</div>
</div>
<div class="console-foot">
<span>Click the tabletop to auto-level.</span>
<span><span class="key">L</span> level · <span class="key">R</span> view</span>
</div>
</section>
<div id="hint">Drag to orbit · Wheel/pinch to zoom · Right-drag to pan</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.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e0d2);
scene.fog = new THREE.Fog(0xe8e0d2, 19, 36);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xfff7e7, 0x77604c, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d7, 3.3);
sun.position.set(7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xaed9df, 1.15);
rimLight.position.set(-8, 6, -7);
scene.add(rimLight);
const materials = {
base: new THREE.MeshStandardMaterial({
color: 0x5e665f, roughness: 0.93, flatShading: true
}),
slab: new THREE.MeshStandardMaterial({
color: 0xb58b5d, roughness: 0.9, flatShading: true
}),
wall: new THREE.MeshStandardMaterial({
color: 0xd5c5a7, roughness: 0.95, flatShading: true
}),
pegboard: new THREE.MeshStandardMaterial({
color: 0xb47b4f, roughness: 0.9, flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x674a35, roughness: 0.92, flatShading: true
}),
teal: new THREE.MeshStandardMaterial({
color: 0x287f78, roughness: 0.65, metalShading: true, flatShading: true
}),
orange: new THREE.MeshStandardMaterial({
color: 0xe66c37, roughness: 0.68, flatShading: true
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xf0bd35, roughness: 0.6, flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0x8b9691, roughness: 0.38, metalness: 0.75, flatShading: true
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x38433f, roughness: 0.46, metalness: 0.58, flatShading: true
}),
brass: new THREE.MeshStandardMaterial({
color: 0xd2a44f, roughness: 0.4, metalness: 0.58, flatShading: true
}),
black: new THREE.MeshStandardMaterial({
color: 0x202724, roughness: 0.72, flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf0e8d6, roughness: 0.85, flatShading: true
}),
green: new THREE.MeshStandardMaterial({
color: 0x72d46d, emissive: 0x1e6727, emissiveIntensity: 0.42,
roughness: 0.28, flatShading: true
}),
terracotta: new THREE.MeshStandardMaterial({
color: 0xb95f43, roughness: 0.92, flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x4d8b5c, roughness: 0.92, flatShading: true
})
};
const woodMaterials = [
new THREE.MeshStandardMaterial({ color: 0xc99b64, roughness: 0.88, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0xd1a66e, roughness: 0.88, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0xbe8e58, roughness: 0.9, flatShading: true })
];
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, position, material, segments = 10) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, radius, position, material, detail = 1) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// Studio ground and fixed miniature plinth.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe8e0d2,
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.3;
ground.receiveShadow = true;
scene.add(ground);
addBox(scene, [10.35, 0.3, 6.35], [0, -0.15, 0], materials.base);
let rearDeckDegrees = -5;
let frontDeckDegrees = 4.5;
function buildDeck(centerZ) {
const deck = new THREE.Group();
deck.position.z = centerZ;
scene.add(deck);
addBox(deck, [9.8, 0.3, 3], [0, 0.15, 0], materials.slab);
for (let i = 0; i < 8; i++) {
const board = addBox(
deck,
[9.7, 0.05, 0.35],
[0, 0.325, -1.31 + i * 0.375],
woodMaterials[i % woodMaterials.length]
);
board.castShadow = false;
}
return deck;
}
const rearDeck = buildDeck(-1.5);
const frontDeck = buildDeck(1.5);
const hinge = addCylinder(
scene,
0.085,
0.085,
9.9,
[0, 0.24, 0],
materials.brass,
10
);
hinge.rotation.z = Math.PI / 2;
for (const x of [-4.9, 4.9]) {
addCylinder(scene, 0.13, 0.13, 0.18, [x, 0.24, 0], materials.darkSteel, 8);
}
// Back wall and pegboard belong to the rear deck.
addBox(rearDeck, [9.45, 3.45, 0.16], [0, 2.02, -1.38], materials.wall);
addBox(rearDeck, [5.25, 1.78, 0.08], [-1.3, 2.45, -1.26], materials.pegboard);
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x65442f,
roughness: 1,
flatShading: true
});
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 11; col++) {
const hole = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.018, 7),
holeMaterial
);
hole.rotation.x = Math.PI / 2;
hole.position.set(-3.55 + col * 0.45, 1.77 + row * 0.34, -1.211);
rearDeck.add(hole);
}
}
// Hammer.
const hammer = new THREE.Group();
hammer.position.set(-2.75, 2.38, -1.13);
rearDeck.add(hammer);
addCylinder(hammer, 0.055, 0.07, 0.75, [0, -0.17, 0], materials.darkWood, 8);
addBox(hammer, [0.48, 0.18, 0.18], [0, 0.27, 0], materials.steel);
// Hand saw.
const saw = new THREE.Group();
saw.position.set(-1.65, 2.31, -1.11);
saw.rotation.z = -0.12;
rearDeck.add(saw);
addBox(saw, [1.05, 0.31, 0.045], [0.15, 0, 0], materials.steel);
const sawHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.065, 6, 10),
materials.orange
);
sawHandle.position.set(-0.5, 0, 0);
sawHandle.scale.set(1, 1.35, 1);
sawHandle.castShadow = true;
saw.add(sawHandle);
// Wrench.
const wrench = new THREE.Group();
wrench.position.set(-0.65, 2.36, -1.12);
wrench.rotation.z = 0.18;
rearDeck.add(wrench);
addBox(wrench, [0.11, 0.85, 0.06], [0, 0, 0], materials.steel);
addCylinder(wrench, 0.16, 0.16, 0.065, [0, 0.47, 0], materials.steel, 8);
const wrenchNotch = addBox(
wrench,
[0.12, 0.12, 0.08],
[0, 0.49, 0.02],
materials.cream,
false
);
wrenchNotch.position.z = 0.035;
// Shelf, cans and jar.
addBox(rearDeck, [2.9, 0.13, 0.62], [2.72, 2.82, -1.08], materials.darkWood);
addBox(rearDeck, [0.12, 0.48, 0.44], [1.55, 2.58, -1.13], materials.darkSteel);
addBox(rearDeck, [0.12, 0.48, 0.44], [3.86, 2.58, -1.13], materials.darkSteel);
addCylinder(rearDeck, 0.19, 0.19, 0.43, [1.88, 3.1, -1.06], materials.teal, 8);
addCylinder(rearDeck, 0.14, 0.14, 0.34, [2.37, 3.055, -1.06], materials.yellow, 8);
addCylinder(rearDeck, 0.2, 0.2, 0.4, [3.55, 3.085, -1.06], materials.cream, 8);
// Pendant lamp.
addCylinder(rearDeck, 0.025, 0.025, 0.8, [0.88, 3.2, -1.07], materials.darkSteel, 6);
const lampShade = new THREE.Mesh(
new THREE.ConeGeometry(0.35, 0.42, 9, 1, true),
materials.teal
);
lampShade.position.set(0.88, 2.65, -1.07);
lampShade.castShadow = true;
rearDeck.add(lampShade);
const bulb = addSphere(
rearDeck,
0.105,
[0.88, 2.45, -1.07],
new THREE.MeshStandardMaterial({
color: 0xffe9a6,
emissive: 0xffc85b,
emissiveIntensity: 2,
flatShading: true
})
);
bulb.castShadow = false;
const lampLight = new THREE.PointLight(0xffcc75, 8, 5, 2);
lampLight.position.set(0.88, 2.38, -1.07);
rearDeck.add(lampLight);
// Toolbox on the front deck.
const toolbox = new THREE.Group();
toolbox.position.set(-3.62, 0.37, 0.77);
frontDeck.add(toolbox);
addBox(toolbox, [1.15, 0.54, 0.56], [0, 0.27, 0], materials.orange);
addBox(toolbox, [0.58, 0.09, 0.09], [0, 0.6, 0], materials.darkSteel);
addBox(toolbox, [0.16, 0.15, 0.58], [-0.42, 0.6, 0], materials.darkSteel);
addBox(toolbox, [0.16, 0.15, 0.58], [0.42, 0.6, 0], materials.darkSteel);
// Low-poly potted plant.
const plant = new THREE.Group();
plant.position.set(3.72, 0.36, 0.75);
frontDeck.add(plant);
addCylinder(plant, 0.27, 0.2, 0.48, [0, 0.24, 0], materials.terracotta, 8);
addCylinder(plant, 0.25, 0.25, 0.04, [0, 0.48, 0], materials.darkWood, 8);
const leafGeometry = new THREE.ConeGeometry(0.17, 0.75, 5);
[
[0.13, 0.82, 0.02, -0.4, 0.1, 0.25],
[-0.12, 0.72, 0.05, 0.45, 0.15, -0.3],
[0.02, 0.95, -0.02, -0.1, -0.25, 0.1],
[-0.03, 0.65, 0.12, 0.12, 0.35, 0.4]
].forEach(([x, y, z, rx, ry, rz]) => {
const leaf = new THREE.Mesh(leafGeometry, materials.leaf);
leaf.position.set(x, y, z);
leaf.rotation.set(rx, ry, rz);
leaf.castShadow = true;
plant.add(leaf);
});
// Workbench top and its rigid frame.
const tableGroup = new THREE.Group();
scene.add(tableGroup);
for (let i = 0; i < 7; i++) {
const board = addBox(
tableGroup,
[4.65, 0.22, 0.35],
[0, -0.11, -1.15 + i * 0.385],
woodMaterials[(i + 1) % woodMaterials.length]
);
board.castShadow = true;
}
addBox(tableGroup, [4.35, 0.28, 0.13], [0, -0.36, -1.14], materials.darkWood);
addBox(tableGroup, [4.35, 0.28, 0.13], [0, -0.36, 1.14], materials.darkWood);
addBox(tableGroup, [0.13, 0.28, 2.16], [-2.17, -0.36, 0], materials.darkWood);
addBox(tableGroup, [0.13, 0.28, 2.16], [2.17, -0.36, 0], materials.darkWood);
// Spirit level resting on the tabletop.
const spiritLevel = new THREE.Group();
spiritLevel.position.set(-0.62, 0, 0.38);
tableGroup.add(spiritLevel);
addBox(spiritLevel, [1.8, 0.18, 0.55], [0, 0.09, 0], materials.yellow);
addBox(spiritLevel, [0.16, 0.2, 0.57], [-0.87, 0.09, 0], materials.black);
addBox(spiritLevel, [0.16, 0.2, 0.57], [0.87, 0.09, 0], materials.black);
const targetRing = new THREE.Mesh(
new THREE.RingGeometry(0.105, 0.165, 20),
materials.black
);
targetRing.rotation.x = -Math.PI / 2;
targetRing.position.y = 0.186;
spiritLevel.add(targetRing);
const targetInner = new THREE.Mesh(
new THREE.CircleGeometry(0.103, 20),
new THREE.MeshBasicMaterial({ color: 0xf6edc8 })
);
targetInner.rotation.x = -Math.PI / 2;
targetInner.position.y = 0.187;
spiritLevel.add(targetInner);
const bubble = addSphere(
spiritLevel,
0.063,
[0, 0.215, 0],
materials.green,
1
);
bubble.castShadow = false;
addBox(spiritLevel, [0.58, 0.028, 0.13], [0.55, 0.188, 0], materials.darkSteel);
const vialBubble = addSphere(
spiritLevel,
0.038,
[0.54, 0.21, 0],
materials.green,
1
);
vialBubble.castShadow = false;
// Small tools on the work surface.
const ruler = addBox(
tableGroup,
[0.17, 0.035, 1.05],
[1.72, 0.018, 0.2],
materials.orange
);
ruler.rotation.y = -0.18;
const mallet = new THREE.Group();
mallet.position.set(1.0, 0.1, -0.42);
mallet.rotation.y = -0.55;
tableGroup.add(mallet);
addCylinder(mallet, 0.055, 0.07, 0.9, [0, 0, 0], materials.darkWood, 8);
addBox(mallet, [0.42, 0.2, 0.2], [0, 0.44, 0], materials.steel);
// Four independently adjustable feet.
const corners = [
{ id: "FL", label: "Front left", x: -1.84, z: 0.82, offset: 0.14 },
{ id: "FR", label: "Front right", x: 1.84, z: 0.82, offset: -0.06 },
{ id: "RL", label: "Rear left", x: -1.84, z: -0.82, offset: 0.07 },
{ id: "RR", label: "Rear right", x: 1.84, z: -0.82, offset: -0.10 }
];
const TABLE_BASE_HEIGHT = 2.65;
const tableNormal = new THREE.Vector3(0, 1, 0);
const yAxis = new THREE.Vector3(0, 1, 0);
const zAxis = new THREE.Vector3(0, 0, 1);
const footVisuals = corners.map(() => {
const pad = addCylinder(
scene,
0.25,
0.29,
0.1,
[0, 0, 0],
materials.darkSteel,
10
);
const screw = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 8),
materials.steel
);
screw.castShadow = true;
scene.add(screw);
const rings = [];
for (let i = 0; i < 6; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.085, 0.013, 4, 9),
materials.darkSteel
);
ring.castShadow = true;
scene.add(ring);
rings.push(ring);
}
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 8),
materials.yellow
);
collar.castShadow = true;
scene.add(collar);
return { pad, screw, rings, collar };
});
function placeCylinder(mesh, start, end, radius) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.scale.set(radius, length, radius);
}
function getFloorTopY(worldZ) {
const isFront = worldZ >= 0;
const angle = THREE.MathUtils.degToRad(
isFront ? frontDeckDegrees : rearDeckDegrees
);
const centerZ = isFront ? 1.5 : -1.5;
const topLocalY = 0.35;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const localZ = (worldZ - centerZ - sin * topLocalY) / cos;
return topLocalY * cos - localZ * sin;
}
function fitTable() {
const heights = corners.map(c => TABLE_BASE_HEIGHT + c.offset);
const centerHeight = heights.reduce((sum, value) => sum + value, 0) / heights.length;
let pitchSlope = 0;
let rollSlope = 0;
corners.forEach((corner, index) => {
const delta = heights[index] - centerHeight;
pitchSlope += corner.x * delta;
rollSlope += corner.z * delta;
});
pitchSlope /= corners.reduce((sum, corner) => sum + corner.x * corner.x, 0);
rollSlope /= corners.reduce((sum, corner) => sum + corner.z * corner.z, 0);
const normal = new THREE.Vector3(-pitchSlope, 1, -rollSlope).normalize();
const xDirection = new THREE.Vector3(1, pitchSlope, 0).normalize();
const zDirection = new THREE.Vector3()
.crossVectors(xDirection, normal)
.normalize();
const basis = new THREE.Matrix4().makeBasis(
xDirection,
normal,
zDirection
);
tableGroup.quaternion.setFromRotationMatrix(basis);
tableGroup.position.set(0, centerHeight, 0);
tableNormal.copy(normal);
tableGroup.updateMatrixWorld(true);
}
function updateFeet() {
corners.forEach((corner, index) => {
const visual = footVisuals[index];
const topPoint = tableGroup.localToWorld(
new THREE.Vector3(corner.x, -0.27, corner.z)
);
const floorY = getFloorTopY(topPoint.z);
const isFront = topPoint.z >= 0;
const floorAngle = THREE.MathUtils.degToRad(
isFront ? frontDeckDegrees : rearDeckDegrees
);
const floorNormal = new THREE.Vector3(0, 1, 0).applyEuler(
new THREE.Euler(floorAngle, 0, 0)
);
const padPoint = new THREE.Vector3(
topPoint.x,
floorY,
topPoint.z
).addScaledVector(floorNormal, 0.05);
visual.pad.position.copy(padPoint);
visual.pad.quaternion.setFromUnitVectors(yAxis, floorNormal);
const screwStart = padPoint.clone().addScaledVector(floorNormal, 0.045);
placeCylinder(visual.screw, screwStart, topPoint, 0.074);
const direction = new THREE.Vector3().subVectors(topPoint, screwStart);
const length = direction.length();
direction.normalize();
visual.rings.forEach((ring, ringIndex) => {
const t = 0.25 + ringIndex * 0.095;
ring.position.copy(screwStart).lerp(topPoint, t);
ring.quaternion.setFromUnitVectors(zAxis, direction);
});
const collarStart = topPoint.clone().addScaledVector(tableNormal, -0.15);
const collarEnd = topPoint.clone().addScaledVector(tableNormal, 0.02);
placeCylinder(visual.collar, collarStart, collarEnd, 0.16);
});
}
// Billboard gauge cards inside the 3D scene.
function roundedRectPath(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function createGaugeSprite(position) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.copy(position);
sprite.scale.set(2.85, 0.8, 1);
sprite.renderOrder = 20;
scene.add(sprite);
function draw(title, value, detail, accent) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(30, 42, 37, .18)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 7;
roundedRectPath(ctx, 8, 8, 624, 158, 25);
ctx.fillStyle = "rgba(255, 252, 244, .94)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.shadowBlur = 0;
ctx.shadowOffsetY = 0;
ctx.fillStyle = accent;
roundedRectPath(ctx, 25, 27, 9, 117, 5);
ctx.fill();
ctx.font = "800 20px system-ui, sans-serif";
ctx.letterSpacing = "2px";
ctx.fillStyle = "#6e7974";
ctx.fillText(title, 56, 50);
ctx.font = "900 49px system-ui, sans-serif";
ctx.fillStyle = "#25312d";
ctx.fillText(value, 53, 108);
ctx.font = "700 18px system-ui, sans-serif";
ctx.fillStyle = "#6e7974";
ctx.fillText(detail, 55, 143);
texture.needsUpdate = true;
}
return { sprite, draw };
}
const floorSceneGauge = createGaugeSprite(new THREE.Vector3(4.48, 1.05, 2.65));
const tableSceneGauge = createGaugeSprite(new THREE.Vector3(4.48, 3.36, 2.65));
const ui = {
rearAngle: document.querySelector("#rearAngle"),
frontAngle: document.querySelector("#frontAngle"),
rearValue: document.querySelector("#rearAngleValue"),
frontValue: document.querySelector("#frontAngleValue"),
floorValue: document.querySelector("#floorValue"),
floorDetail: document.querySelector("#floorDetail"),
floorStatus: document.querySelector("#floorStatus"),
floorBubble: document.querySelector("#floorBubble"),
tableValue: document.querySelector("#tableValue"),
tableDetail: document.querySelector("#tableDetail"),
tableStatus: document.querySelector("#tableStatus"),
tableBubble: document.querySelector("#tableBubble")
};
function signedDegrees(value, decimals = 1) {
const rounded = Math.abs(value) < 0.0005 ? 0 : value;
return `${rounded >= 0 ? "+" : "−"}${Math.abs(rounded).toFixed(decimals)}°`;
}
function getFloorMeanAngle() {
const rearSlope = -Math.tan(THREE.MathUtils.degToRad(rearDeckDegrees));
const frontSlope = -Math.tan(THREE.MathUtils.degToRad(frontDeckDegrees));
return THREE.MathUtils.radToDeg(Math.atan((rearSlope + frontSlope) / 2));
}
function updateReadouts() {
const floorMean = getFloorMeanAngle();
const floorSplit = Math.abs(frontDeckDegrees - rearDeckDegrees);
const roll = THREE.MathUtils.radToDeg(
Math.atan2(-tableNormal.x, tableNormal.y)
);
const pitch = THREE.MathUtils.radToDeg(
Math.atan2(-tableNormal.z, tableNormal.y)
);
const tilt = Math.hypot(roll, pitch);
ui.rearValue.textContent = signedDegrees(rearDeckDegrees);
ui.frontValue.textContent = signedDegrees(frontDeckDegrees);
ui.floorValue.textContent = signedDegrees(floorMean);
ui.floorDetail.textContent =
`R ${signedDegrees(rearDeckDegrees)} · F ${signedDegrees(frontDeckDegrees)}`;
ui.floorStatus.textContent = `Split ${floorSplit.toFixed(1)}°`;
ui.floorStatus.classList.remove("level");
ui.tableValue.textContent = `${tilt.toFixed(1)}°`;
ui.tableDetail.textContent = `Roll ${signedDegrees(roll)} · Pitch ${signedDegrees(pitch)}`;
ui.tableStatus.textContent = tilt < 0.25 ? "Level" : "Adjust feet";
ui.tableStatus.classList.toggle("level", tilt < 0.25);
const floorBubbleTop = THREE.MathUtils.clamp(50 - floorMean * 3.4, 14, 86);
ui.floorBubble.style.top = `${floorBubbleTop}%`;
const tableBubbleLeft = THREE.MathUtils.clamp(50 - roll * 3.4, 14, 86);
const tableBubbleTop = THREE.MathUtils.clamp(50 - pitch * 3.4, 14, 86);
ui.tableBubble.style.left = `${tableBubbleLeft}%`;
ui.tableBubble.style.top = `${tableBubbleTop}%`;
bubble.position.x = THREE.MathUtils.clamp(-roll * 0.018, -0.13, 0.13);
bubble.position.z = THREE.MathUtils.clamp(-pitch * 0.018, -0.13, 0.13);
vialBubble.position.x = THREE.MathUtils.clamp(-roll * 0.012, -0.14, 0.14);
floorSceneGauge.draw(
"FLOOR DECKS",
signedDegrees(floorMean),
`REAR ${signedDegrees(rearDeckDegrees)} FRONT ${signedDegrees(frontDeckDegrees)}`,
"#e96f36"
);
tableSceneGauge.draw(
"TABLETOP",
`${tilt.toFixed(1)}°`,
`ROLL ${signedDegrees(roll)} PITCH ${signedDegrees(pitch)}`,
"#248b83"
);
}
function updateEverything() {
rearDeck.rotation.x = THREE.MathUtils.degToRad(rearDeckDegrees);
frontDeck.rotation.x = THREE.MathUtils.degToRad(frontDeckDegrees);
fitTable();
updateFeet();
updateReadouts();
}
// Foot controls.
const footControls = document.querySelector("#footControls");
corners.forEach((corner, index) => {
const row = document.createElement("div");
row.className = "foot-control";
row.innerHTML = `
<span class="foot-code">${corner.id}</span>
<button type="button" aria-label="Lower ${corner.label}">−</button>
<output>0 mm</output>
<button type="button" aria-label="Raise ${corner.label}">+</button>
`;
const [minusButton, output, plusButton] = row.querySelectorAll("button, output");
const syncFoot = () => {
output.textContent = `${corner.offset >= 0 ? "+" : "−"}${Math.round(Math.abs(corner.offset) * 100)} mm`;
};
minusButton.addEventListener("click", () => {
corner.offset = THREE.MathUtils.clamp(corner.offset - 0.05, -0.35, 0.35);
syncFoot();
updateEverything();
});
plusButton.addEventListener("click", () => {
corner.offset = THREE.MathUtils.clamp(corner.offset + 0.05, -0.35, 0.35);
syncFoot();
updateEverything();
});
syncFoot();
footControls.appendChild(row);
});
let tableTransition = null;
function animateToOffsets(targetOffsets) {
tableTransition = {
from: corners.map(corner => corner.offset),
to: [...targetOffsets],
start: performance.now(),
duration: 650
};
}
function autoLevel() {
animateToOffsets([0, 0, 0, 0]);
pulseStart = performance.now();
}
function matchFloor() {
const rearSlope = -Math.tan(THREE.MathUtils.degToRad(rearDeckDegrees));
const frontSlope = -Math.tan(THREE.MathUtils.degToRad(frontDeckDegrees));
const meanSlope = (rearSlope + frontSlope) / 2;
animateToOffsets(corners.map(corner => meanSlope * corner.z));
pulseStart = performance.now();
}
ui.rearAngle.addEventListener("input", event => {
rearDeckDegrees = Number(event.target.value);
updateEverything();
});
ui.frontAngle.addEventListener("input", event => {
frontDeckDegrees = Number(event.target.value);
updateEverything();
});
document.querySelector("#autoLevel").addEventListener("click", autoLevel);
document.querySelector("#followFloor").addEventListener("click", matchFloor);
document.querySelector("#resetFeet").addEventListener("click", () => {
animateToOffsets([0, 0, 0, 0]);
pulseStart = performance.now();
});
document.querySelector("#resetFloor").addEventListener("click", () => {
rearDeckDegrees = -5;
frontDeckDegrees = 4.5;
ui.rearAngle.value = rearDeckDegrees;
ui.frontAngle.value = frontDeckDegrees;
updateEverything();
});
// Custom orbit, pan and zoom controls: no Three.js addons.
let yaw = 0.66;
let pitch = 0.43;
let cameraDistance = 13.7;
const cameraTarget = new THREE.Vector3(0, 1.55, 0);
const initialCamera = {
yaw,
pitch,
distance: cameraDistance,
target: cameraTarget.clone()
};
function updateCamera() {
const sinPitch = Math.sin(pitch);
const offset = new THREE.Vector3(
cameraDistance * sinPitch * Math.sin(yaw),
cameraDistance * Math.cos(pitch),
cameraDistance * sinPitch * Math.cos(yaw)
);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
yaw = initialCamera.yaw;
pitch = initialCamera.pitch;
cameraDistance = initialCamera.distance;
cameraTarget.copy(initialCamera.target);
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetCamera);
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
button: event.button,
shift: event.shiftKey
});
if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", event => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * (pinchDistance / Math.max(distance, 1)),
7,
24
);
}
pinchDistance = distance;
updateCamera();
return;
}
const panMode = pointer.button === 2 || pointer.shift;
if (panMode) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const panScale = cameraDistance * 0.0015;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(up, dy * panScale);
} else {
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.12, 1.15);
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * Math.exp(event.deltaY * 0.001),
7,
24
);
updateCamera();
}, { passive: false });
// Clicking the tabletop triggers the same automatic leveling action.
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("pointerup", event => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const moved = Math.hypot(
event.clientX - pointer.startX,
event.clientY - pointer.startY
);
if (moved > 6 || event.button !== 0) return;
pointerNDC.x = event.clientX / window.innerWidth * 2 - 1;
pointerNDC.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObject(tableGroup, true);
if (hits.length) autoLevel();
});
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "l") autoLevel();
if (event.key.toLowerCase() === "r") resetCamera();
});
let pulseStart = -1000;
function animate(now) {
requestAnimationFrame(animate);
if (tableTransition) {
const t = THREE.MathUtils.clamp(
(now - tableTransition.start) / tableTransition.duration,
0,
1
);
const eased = 1 - Math.pow(1 - t, 3);
corners.forEach((corner, index) => {
corner.offset = THREE.MathUtils.lerp(
tableTransition.from[index],
tableTransition.to[index],
eased
);
});
updateEverything();
if (t >= 1) tableTransition = null;
}
const pulseTime = now - pulseStart;
if (pulseTime >= 0 && pulseTime < 700) {
const amount = 1 + Math.sin(pulseTime / 700 * Math.PI * 4) * 0.16 * (1 - pulseTime / 700);
spiritLevel.scale.set(amount, amount, amount);
} else {
spiritLevel.scale.set(1, 1, 1);
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
updateEverything();
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```