Prompt specification
Build or customize the Three.js 3D scene "Seated knee clearance beneath a desk" 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: Seated knee clearance beneath a desk
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/seated-knee-clearance-beneath-a-desk-x0185
Scene Description Prompt:
A stylized seated figure tests desk clearance; translucent knee and foot envelopes expose drawer and crossbar obstructions. One HTML file using Three.js from cdnjs.
Working Three.js Starter (seated-knee-clearance-beneath-a-desk-x0185):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Clearance Lab — Desk Fit Test</title>
<style>
:root {
color-scheme: light;
--ink: #172225;
--muted: #667376;
--paper: rgba(247, 248, 244, 0.86);
--line: rgba(23, 34, 37, 0.12);
--teal: #10a99d;
--orange: #ef7a45;
--danger: #e85f50;
--shadow: 0 18px 50px rgba(35, 48, 48, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 35%, #f7f7f1 0, #e9ede8 48%, #dce2de 100%);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border: 1px solid rgba(23, 34, 37, 0.17);
border-radius: 13px;
background: rgba(247, 248, 244, 0.72);
box-shadow: 0 8px 25px rgba(30, 45, 45, 0.08);
backdrop-filter: blur(12px);
}
.brand-mark::before {
content: "";
width: 17px;
height: 17px;
border: 3px solid var(--teal);
border-radius: 5px;
transform: rotate(45deg);
}
.brand-copy small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand-copy strong {
display: block;
font-size: 19px;
letter-spacing: -0.035em;
}
.brand-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 12px;
}
.diagnostics {
position: fixed;
z-index: 5;
top: 102px;
right: 24px;
width: 286px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 20px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(20px) saturate(130%);
pointer-events: none;
}
.result-head {
display: flex;
align-items: center;
gap: 14px;
padding-bottom: 16px;
border-bottom: 1px solid var(--line);
}
.score-ring {
--angle: 144deg;
position: relative;
flex: 0 0 65px;
width: 65px;
height: 65px;
display: grid;
place-items: center;
border-radius: 50%;
background: conic-gradient(var(--teal) var(--angle), #dce2de 0);
transition: background 250ms ease;
}
.score-ring::before {
content: "";
position: absolute;
inset: 7px;
border-radius: 50%;
background: rgba(247, 248, 244, 0.98);
}
.score-ring.fail {
background: conic-gradient(var(--danger) var(--angle), #eadedb 0);
}
.score-ring span {
position: relative;
z-index: 1;
font-size: 19px;
font-weight: 850;
letter-spacing: -0.05em;
}
.eyebrow {
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#resultTitle {
margin-bottom: 4px;
font-size: 15px;
font-weight: 850;
letter-spacing: -0.025em;
}
#resultCopy {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.metrics {
display: grid;
gap: 3px;
padding: 10px 0 4px;
}
.metric {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
min-height: 49px;
padding: 7px 8px;
border-radius: 10px;
transition: background 180ms ease;
}
.metric.hit {
background: rgba(232, 95, 80, 0.09);
}
.metric-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(16, 169, 157, 0.11);
}
.metric-dot.foot {
background: var(--orange);
box-shadow: 0 0 0 4px rgba(239, 122, 69, 0.11);
}
.metric-dot.top {
background: #798b8d;
box-shadow: 0 0 0 4px rgba(121, 139, 141, 0.1);
}
.metric.hit .metric-dot {
background: var(--danger);
box-shadow: 0 0 0 4px rgba(232, 95, 80, 0.13);
}
.metric b {
display: block;
font-size: 11px;
font-weight: 800;
}
.metric small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.metric strong {
color: var(--ink);
font-size: 11px;
font-weight: 850;
}
.metric.hit strong {
color: var(--danger);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
}
.legend span:nth-child(2) i {
background: var(--orange);
}
.legend span:nth-child(3) i {
background: var(--danger);
}
.control-dock {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
width: min(1080px, calc(100vw - 40px));
display: grid;
grid-template-columns:
minmax(150px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr)
auto auto auto;
align-items: end;
gap: 14px;
padding: 14px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 20px;
background: rgba(247, 248, 244, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(22px) saturate(130%);
transform: translateX(-50%);
}
.slider-control {
min-width: 0;
}
.slider-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.slider-label output {
color: var(--ink);
font-size: 10px;
letter-spacing: 0;
text-transform: none;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 4px;
display: block;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
90deg,
var(--teal) 0 var(--fill, 50%),
#d9dfdc var(--fill, 50%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #f7f8f4;
border-radius: 50%;
appearance: none;
background: var(--ink);
box-shadow: 0 2px 7px rgba(23, 34, 37, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #f7f8f4;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 7px rgba(23, 34, 37, 0.25);
}
.action-button {
height: 38px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
cursor: pointer;
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
.action-button:hover {
border-color: rgba(23, 34, 37, 0.26);
background: rgba(255, 255, 255, 0.9);
transform: translateY(-1px);
}
.action-button.primary {
border-color: transparent;
background: var(--ink);
color: white;
}
.action-button.active {
border-color: rgba(16, 169, 157, 0.3);
background: rgba(16, 169, 157, 0.12);
color: #087c73;
}
.orbit-hint {
position: fixed;
z-index: 4;
left: 26px;
bottom: 102px;
color: rgba(23, 34, 37, 0.55);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
.callout {
position: fixed;
z-index: 4;
min-width: 108px;
padding: 7px 9px;
border: 1px solid rgba(16, 169, 157, 0.24);
border-radius: 9px;
background: rgba(246, 249, 246, 0.88);
color: var(--ink);
box-shadow: 0 8px 24px rgba(24, 42, 42, 0.1);
backdrop-filter: blur(12px);
font-size: 9px;
font-weight: 800;
line-height: 1.35;
text-align: center;
pointer-events: none;
transform: translate(-50%, calc(-100% - 10px));
transition: border-color 160ms ease;
}
.callout::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
border-right: 1px solid rgba(16, 169, 157, 0.24);
border-bottom: 1px solid rgba(16, 169, 157, 0.24);
background: rgba(246, 249, 246, 0.88);
transform: translateX(-50%) rotate(45deg);
}
.callout span {
display: block;
margin-bottom: 2px;
color: var(--teal);
font-size: 8px;
letter-spacing: 0.13em;
}
.callout.hit {
border-color: rgba(232, 95, 80, 0.42);
}
.callout.hit span {
color: var(--danger);
}
.callout.hit::after {
border-color: rgba(232, 95, 80, 0.42);
}
@media (max-width: 900px) {
.diagnostics {
top: 88px;
right: 12px;
width: 245px;
padding: 14px;
}
.topbar {
top: 16px;
left: 16px;
}
.brand-copy span {
display: none;
}
.control-dock {
bottom: 12px;
width: calc(100vw - 24px);
grid-template-columns: repeat(3, 1fr);
gap: 11px;
padding: 12px;
}
.action-button {
width: 100%;
}
.orbit-hint {
display: none;
}
}
@media (max-width: 590px) {
.brand-copy strong {
font-size: 16px;
}
.diagnostics {
top: 72px;
width: 210px;
}
.score-ring {
flex-basis: 52px;
width: 52px;
height: 52px;
}
.metrics {
gap: 0;
}
.metric {
min-height: 43px;
padding: 5px;
}
.legend,
#resultCopy {
display: none;
}
.control-dock {
grid-template-columns: 1fr 1fr;
}
.control-dock .slider-control:nth-child(3) {
grid-column: 1 / -1;
}
.callout {
display: none !important;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D desk clearance test"></canvas>
<header class="topbar">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<small>Clearance Lab / 02</small>
<strong>Desk Fit Test</strong>
<span>Seated ergonomics and under-desk interference</span>
</div>
</header>
<aside class="diagnostics" aria-live="polite">
<div class="result-head">
<div id="scoreRing" class="score-ring fail">
<span id="scoreValue">40</span>
</div>
<div>
<div class="eyebrow">Overall verdict</div>
<div id="resultTitle">CLEARANCE FAIL</div>
<p id="resultCopy">2 obstructions intersect the clearance envelopes.</p>
</div>
</div>
<div class="metrics">
<div id="kneeRow" class="metric hit">
<i class="metric-dot"></i>
<div>
<b>Knee envelope</b>
<small id="kneeLabel">Drawer intrusion</small>
</div>
<strong id="kneeValue">—</strong>
</div>
<div id="footRow" class="metric hit">
<i class="metric-dot foot"></i>
<div>
<b>Foot envelope</b>
<small id="footLabel">Crossbar intrusion</small>
</div>
<strong id="footValue">—</strong>
</div>
<div id="topRow" class="metric">
<i class="metric-dot top"></i>
<div>
<b>Top edge</b>
<small id="topLabel">Vertical clearance</small>
</div>
<strong id="topValue">—</strong>
</div>
</div>
<div class="legend">
<span><i></i>Knee zone</span>
<span><i></i>Foot zone</span>
<span><i></i>Obstruction</span>
</div>
</aside>
<div id="kneeCallout" class="callout"></div>
<div id="footCallout" class="callout"></div>
<div class="orbit-hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<section class="control-dock" aria-label="Desk test controls">
<label class="slider-control">
<span class="slider-label">
Desk height
<output id="heightOutput">135 cm</output>
</span>
<input id="heightSlider" type="range" min="112" max="155" value="135" />
</label>
<label class="slider-control">
<span class="slider-label">
Drawer extension
<output id="drawerOutput">28 cm open</output>
</span>
<input id="drawerSlider" type="range" min="0" max="50" value="28" />
</label>
<label class="slider-control">
<span class="slider-label">
Crossbar height
<output id="barOutput">22 cm</output>
</span>
<input id="barSlider" type="range" min="2" max="45" value="22" />
</label>
<button id="testButton" class="action-button primary" type="button">
Run test
</button>
<button id="envelopeButton" class="action-button active" type="button">
Envelopes on
</button>
<button id="resetButton" class="action-button" type="button">
Reset
</button>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ece7);
scene.fog = new THREE.Fog(0xe8ece7, 9, 18);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraState = {
theta: 0.72,
phi: 1.13,
radius: 6.45,
target: new THREE.Vector3(0, 1.02, 0.42)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfffbef, 0x75847f, 2.1);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff6e8, 3.2);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbfe6e8, 1.25);
fillLight.position.set(-5, 3, -2);
scene.add(fillLight);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const state = {
height: 1.35,
drawer: 0.28,
bar: 0.22,
envelopes: true,
pulse: 0
};
const lastHits = {
drawer: false,
foot: false,
top: false
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const up = new THREE.Vector3(0, 1, 0);
function box(parent, material, width, height, depth, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function placeSegment(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.scale.set(1, length, 1);
}
function segment(parent, material, radius, a, b) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 18),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
placeSegment(mesh, a, b);
return mesh;
}
function sphere(parent, material, radius, x, y, z, scale = null) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 24, 18),
material
);
mesh.position.set(x, y, z);
if (scale) {
mesh.scale.set(...scale);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xdfe5df,
roughness: 0.96
}),
rug: new THREE.MeshStandardMaterial({
color: 0xcdd9d2,
roughness: 1
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe3e8e3,
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: 0xd8c7a6,
roughness: 0.62
}),
frame: new THREE.MeshStandardMaterial({
color: 0x435156,
roughness: 0.55,
metalness: 0.28
}),
drawer: new THREE.MeshStandardMaterial({
color: 0xb9c6c0,
roughness: 0.7
}),
drawerFace: new THREE.MeshStandardMaterial({
color: 0xcbd4ce,
roughness: 0.68
}),
handle: new THREE.MeshStandardMaterial({
color: 0x4b5a5d,
roughness: 0.48,
metalness: 0.3
}),
chair: new THREE.MeshStandardMaterial({
color: 0x596b70,
roughness: 0.76
}),
chairFrame: new THREE.MeshStandardMaterial({
color: 0x344247,
roughness: 0.5,
metalness: 0.35
}),
shirt: new THREE.MeshStandardMaterial({
color: 0x405961,
roughness: 0.76
}),
pants: new THREE.MeshStandardMaterial({
color: 0x26373f,
roughness: 0.82
}),
skin: new THREE.MeshStandardMaterial({
color: 0xd5a583,
roughness: 0.78
}),
hair: new THREE.MeshStandardMaterial({
color: 0x273237,
roughness: 0.9
}),
shoe: new THREE.MeshStandardMaterial({
color: 0x1d292e,
roughness: 0.88
}),
eye: new THREE.MeshStandardMaterial({
color: 0x172225,
roughness: 0.6
})
};
// ------------------------------------------------------------
// Room
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const rug = new THREE.Mesh(
new THREE.CircleGeometry(2.65, 80),
materials.rug
);
rug.rotation.x = -Math.PI / 2;
rug.position.y = 0.006;
rug.receiveShadow = true;
scene.add(rug);
const grid = new THREE.GridHelper(20, 40, 0x84938e, 0x9da9a4);
grid.position.y = 0.009;
grid.material.transparent = true;
grid.material.opacity = 0.15;
grid.material.depthWrite = false;
scene.add(grid);
const wall = box(scene, materials.wall, 12, 6, 0.12, 0, 3, -4.2);
wall.castShadow = false;
// ------------------------------------------------------------
// Desk
// ------------------------------------------------------------
const desk = new THREE.Group();
scene.add(desk);
const desktop = box(
desk,
materials.wood,
3.4,
0.12,
1.45,
0,
state.height,
0
);
const deskLegLeft = box(
desk,
materials.frame,
0.13,
state.height,
1.05,
-1.52,
state.height / 2,
-0.03
);
const deskLegRight = box(
desk,
materials.frame,
0.13,
state.height,
1.05,
1.52,
state.height / 2,
-0.03
);
const deskFootLeft = box(
desk,
materials.frame,
0.29,
0.06,
1.19,
-1.52,
0.03,
-0.03
);
const deskFootRight = box(
desk,
materials.frame,
0.29,
0.06,
1.19,
1.52,
0.03,
-0.03
);
const rearRail = box(
desk,
materials.frame,
2.9,
0.11,
0.11,
0,
state.height - 0.19,
-0.58
);
// Drawer assembly slides toward the seated figure.
const drawerAssembly = new THREE.Group();
desk.add(drawerAssembly);
const drawerBody = box(
drawerAssembly,
materials.drawer,
0.78,
0.85,
0.78,
-0.35,
0.845,
-0.04
);
const drawerPanelLower = box(
drawerAssembly,
materials.drawerFace,
0.7,
0.38,
0.035,
-0.35,
0.645,
0.365
);
const drawerPanelUpper = box(
drawerAssembly,
materials.drawerFace,
0.7,
0.38,
0.035,
-0.35,
1.065,
0.365
);
const drawerHandleLower = box(
drawerAssembly,
materials.handle,
0.23,
0.025,
0.045,
-0.35,
0.72,
0.402
);
const drawerHandleUpper = box(
drawerAssembly,
materials.handle,
0.23,
0.025,
0.045,
-0.35,
1.14,
0.402
);
// Obstruction crossbar.
const crossbarAssembly = new THREE.Group();
desk.add(crossbarAssembly);
const crossbar = box(
crossbarAssembly,
materials.frame,
2.86,
0.1,
0.12,
0,
0,
-0.03
);
const crossbarCapLeft = box(
crossbarAssembly,
materials.handle,
0.08,
0.14,
0.16,
-1.43,
0,
-0.03
);
const crossbarCapRight = box(
crossbarAssembly,
materials.handle,
0.08,
0.14,
0.16,
1.43,
0,
-0.03
);
// ------------------------------------------------------------
// Seated figure
// ------------------------------------------------------------
const figure = new THREE.Group();
scene.add(figure);
// Chair.
box(figure, materials.chair, 0.9, 0.12, 0.82, 0.15, 0.58, 1.48);
box(figure, materials.chair, 0.9, 0.83, 0.11, 0.15, 1.03, 1.86);
const chairLegPositions = [
[-0.18, 0.08, 1.16],
[0.48, 0.08, 1.16],
[-0.18, 0.08, 1.78],
[0.48, 0.08, 1.78]
];
for (const [x, y, z] of chairLegPositions) {
segment(
figure,
materials.chairFrame,
0.035,
new THREE.Vector3(x, 0.05, z),
new THREE.Vector3(x * 0.85, 0.56, z)
);
}
// Pelvis and torso.
sphere(figure, materials.pants, 0.25, 0.15, 0.81, 1.2, [1.05, 0.72, 0.88]);
const torso = new THREE.Mesh(
new THREE.CapsuleGeometry(0.255, 0.37, 7, 20),
materials.shirt
);
torso.position.set(0.15, 1.31, 0.99);
torso.rotation.x = -0.12;
torso.castShadow = true;
torso.receiveShadow = true;
figure.add(torso);
segment(
figure,
materials.skin,
0.09,
new THREE.Vector3(0.15, 1.66, 0.9),
new THREE.Vector3(0.15, 1.8, 0.83)
);
// Head, hair and simple facial details.
sphere(figure, materials.skin, 0.225, 0.15, 1.96, 0.77, [0.96, 1.08, 0.96]);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.229, 24, 16, 0, Math.PI * 2, 0, Math.PI * 0.52),
materials.hair
);
hair.position.set(0.15, 1.985, 0.785);
hair.rotation.x = -0.08;
hair.castShadow = true;
figure.add(hair);
sphere(figure, materials.skin, 0.038, 0.15, 1.94, 0.552, [0.8, 0.9, 1.1]);
sphere(figure, materials.eye, 0.013, 0.08, 1.995, 0.558);
sphere(figure, materials.eye, 0.013, 0.22, 1.995, 0.558);
// Arms reach toward the desktop.
const shoulderL = new THREE.Vector3(-0.12, 1.55, 0.91);
const shoulderR = new THREE.Vector3(0.42, 1.55, 0.91);
const elbowL = new THREE.Vector3(-0.29, 1.32, 0.44);
const elbowR = new THREE.Vector3(0.59, 1.32, 0.44);
const wristL = new THREE.Vector3(-0.2, state.height + 0.075, -0.03);
const wristR = new THREE.Vector3(0.5, state.height + 0.075, -0.03);
segment(figure, materials.shirt, 0.09, shoulderL, elbowL);
segment(figure, materials.shirt, 0.09, shoulderR, elbowR);
const forearmL = segment(
figure,
materials.skin,
0.067,
elbowL,
wristL
);
const forearmR = segment(
figure,
materials.skin,
0.067,
elbowR,
wristR
);
const handL = sphere(figure, materials.skin, 0.083, wristL.x, wristL.y, wristL.z, [1.1, 0.7, 1]);
const handR = sphere(figure, materials.skin, 0.083, wristR.x, wristR.y, wristR.z, [1.1, 0.7, 1]);
// Legs.
const hipL = new THREE.Vector3(0.01, 0.82, 1.17);
const hipR = new THREE.Vector3(0.29, 0.82, 1.17);
const kneeL = new THREE.Vector3(0.01, 0.82, 0.55);
const kneeR = new THREE.Vector3(0.29, 0.82, 0.55);
const ankleL = new THREE.Vector3(0.01, 0.26, 0.42);
const ankleR = new THREE.Vector3(0.29, 0.26, 0.42);
segment(figure, materials.pants, 0.12, hipL, kneeL);
segment(figure, materials.pants, 0.12, hipR, kneeR);
segment(figure, materials.pants, 0.095, kneeL, ankleL);
segment(figure, materials.pants, 0.095, kneeR, ankleR);
sphere(figure, materials.pants, 0.125, 0.01, 0.82, 0.55);
sphere(figure, materials.pants, 0.125, 0.29, 0.82, 0.55);
const shoeL = new THREE.Mesh(
new THREE.CapsuleGeometry(0.105, 0.27, 5, 14),
materials.shoe
);
shoeL.rotation.x = Math.PI / 2;
shoeL.position.set(0.01, 0.12, 0.11);
shoeL.castShadow = true;
figure.add(shoeL);
const shoeR = shoeL.clone();
shoeR.position.x = 0.29;
figure.add(shoeR);
// ------------------------------------------------------------
// Translucent clearance envelopes
// ------------------------------------------------------------
const envelopeGroup = new THREE.Group();
scene.add(envelopeGroup);
const kneeEnvelopeMaterial = new THREE.MeshBasicMaterial({
color: 0x10b5a7,
transparent: true,
opacity: 0.16,
depthWrite: false,
depthTest: false,
side: THREE.DoubleSide
});
const footEnvelopeMaterial = new THREE.MeshBasicMaterial({
color: 0xef7a45,
transparent: true,
opacity: 0.18,
depthWrite: false,
depthTest: false,
side: THREE.DoubleSide
});
const kneeRingMaterial = new THREE.MeshBasicMaterial({
color: 0x10b5a7,
transparent: true,
opacity: 0.62,
depthWrite: false,
depthTest: false
});
const footRingMaterial = new THREE.MeshBasicMaterial({
color: 0xef7a45,
transparent: true,
opacity: 0.66,
depthWrite: false,
depthTest: false
});
const kneeEnvelope = new THREE.Mesh(
new THREE.CapsuleGeometry(0.32, 0.42, 8, 24),
kneeEnvelopeMaterial
);
kneeEnvelope.rotation.x = Math.PI / 2;
kneeEnvelope.position.set(0.15, 0.88, 0.56);
kneeEnvelope.renderOrder = 20;
envelopeGroup.add(kneeEnvelope);
const footEnvelope = new THREE.Mesh(
new THREE.CapsuleGeometry(0.17, 0.4, 8, 24),
footEnvelopeMaterial
);
footEnvelope.rotation.x = Math.PI / 2;
footEnvelope.position.set(0.15, 0.23, 0.04);
footEnvelope.renderOrder = 21;
envelopeGroup.add(footEnvelope);
const kneeRings = [];
const footRings = [];
for (const z of [0.29, 0.56, 0.83]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.323, 0.007, 8, 64),
kneeRingMaterial
);
ring.position.set(0.15, 0.88, z);
ring.renderOrder = 22;
envelopeGroup.add(ring);
kneeRings.push(ring);
}
for (const z of [-0.16, 0.04, 0.24]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.173, 0.006, 8, 64),
footRingMaterial
);
ring.position.set(0.15, 0.23, z);
ring.renderOrder = 23;
envelopeGroup.add(ring);
footRings.push(ring);
}
// ------------------------------------------------------------
// Dynamic desk and figure updates
// ------------------------------------------------------------
function updateDesk() {
const h = state.height;
desktop.position.y = h;
deskLegLeft.scale.y = h;
deskLegRight.scale.y = h;
deskLegLeft.position.y = h / 2;
deskLegRight.position.y = h / 2;
rearRail.position.y = h - 0.19;
const drawerBottom = 0.42;
const drawerTop = h - 0.08;
const drawerHeight = Math.max(0.56, drawerTop - drawerBottom);
const panelHeight = (drawerHeight - 0.09) / 2;
const lowerCenter = drawerBottom + 0.03 + panelHeight / 2;
const upperCenter = lowerCenter + panelHeight + 0.035;
drawerBody.scale.set(0.78, drawerHeight, 0.78);
drawerBody.position.set(-0.35, (drawerBottom + drawerTop) / 2, -0.04);
drawerPanelLower.scale.set(0.7, panelHeight, 0.035);
drawerPanelLower.position.set(-0.35, lowerCenter, 0.365);
drawerPanelUpper.scale.set(0.7, panelHeight, 0.035);
drawerPanelUpper.position.set(-0.35, upperCenter, 0.365);
drawerHandleLower.position.set(-0.35, lowerCenter + 0.09, 0.402);
drawerHandleUpper.position.set(-0.35, upperCenter + 0.09, 0.402);
drawerAssembly.position.z = state.drawer;
crossbarAssembly.position.y = state.bar;
wristL.set(-0.2, h + 0.075, -0.03);
wristR.set(0.5, h + 0.075, -0.03);
placeSegment(forearmL, elbowL, wristL);
placeSegment(forearmR, elbowR, wristR);
handL.position.copy(wristL);
handR.position.copy(wristR);
}
// ------------------------------------------------------------
// Collision / clearance calculations
// ------------------------------------------------------------
function overlaps(a, b, epsilon = 0.0005) {
return (
Math.min(a.max.x, b.max.x) - Math.max(a.min.x, b.min.x) > epsilon &&
Math.min(a.max.y, b.max.y) - Math.max(a.min.y, b.min.y) > epsilon &&
Math.min(a.max.z, b.max.z) - Math.max(a.min.z, b.min.z) > epsilon
);
}
function overlapDepth(a, b) {
const x = Math.min(a.max.x, b.max.x) - Math.max(a.min.x, b.min.x);
const y = Math.min(a.max.y, b.max.y) - Math.max(a.min.y, b.min.y);
const z = Math.min(a.max.z, b.max.z) - Math.max(a.min.z, b.min.z);
if (x <= 0 || y <= 0 || z <= 0) {
return 0;
}
return Math.min(x, y, z);
}
function separation(a, b) {
const dx = Math.max(a.min.x - b.max.x, b.min.x - a.max.x, 0);
const dy = Math.max(a.min.y - b.max.y, b.min.y - a.max.y, 0);
const dz = Math.max(a.min.z - b.max.z, b.min.z - a.max.z, 0);
return Math.hypot(dx, dy, dz);
}
function setConflictMaterial(material, hit, baseColor) {
material.color.setHex(hit ? 0xe96353 : baseColor);
material.emissive.setHex(hit ? 0x501008 : 0x000000);
material.emissiveIntensity = hit ? 0.18 : 0;
}
const ui = {
heightSlider: document.getElementById("heightSlider"),
drawerSlider: document.getElementById("drawerSlider"),
barSlider: document.getElementById("barSlider"),
heightOutput: document.getElementById("heightOutput"),
drawerOutput: document.getElementById("drawerOutput"),
barOutput: document.getElementById("barOutput"),
resultTitle: document.getElementById("resultTitle"),
resultCopy: document.getElementById("resultCopy"),
scoreRing: document.getElementById("scoreRing"),
scoreValue: document.getElementById("scoreValue"),
kneeRow: document.getElementById("kneeRow"),
footRow: document.getElementById("footRow"),
topRow: document.getElementById("topRow"),
kneeLabel: document.getElementById("kneeLabel"),
footLabel: document.getElementById("footLabel"),
topLabel: document.getElementById("topLabel"),
kneeValue: document.getElementById("kneeValue"),
footValue: document.getElementById("footValue"),
topValue: document.getElementById("topValue"),
kneeCallout: document.getElementById("kneeCallout"),
footCallout: document.getElementById("footCallout"),
testButton: document.getElementById("testButton"),
envelopeButton: document.getElementById("envelopeButton"),
resetButton: document.getElementById("resetButton")
};
function evaluateClearance() {
scene.updateMatrixWorld(true);
const kneeBounds = new THREE.Box3().setFromObject(kneeEnvelope);
const footBounds = new THREE.Box3().setFromObject(footEnvelope);
const drawerBounds = new THREE.Box3().setFromObject(drawerAssembly);
const barBounds = new THREE.Box3().setFromObject(crossbarAssembly);
const topBounds = new THREE.Box3().setFromObject(desktop);
const drawerHit = overlaps(kneeBounds, drawerBounds);
const footHit = overlaps(footBounds, barBounds);
const topHit = overlaps(kneeBounds, topBounds);
lastHits.drawer = drawerHit;
lastHits.foot = footHit;
lastHits.top = topHit;
const drawerDepthCm = Math.round(overlapDepth(kneeBounds, drawerBounds) * 100);
const footDepthCm = Math.round(overlapDepth(footBounds, barBounds) * 100);
const topGapCm = Math.round((topBounds.min.y - kneeBounds.max.y) * 100);
const footGapCm = Math.round(separation(footBounds, barBounds) * 100);
const hits = Number(drawerHit) + Number(footHit) + Number(topHit);
const score = Math.max(0, 100 - hits * 30);
ui.resultTitle.textContent = hits ? "CLEARANCE FAIL" : "CLEARANCE PASS";
ui.resultCopy.textContent = hits
? `${hits} obstruction${hits === 1 ? "" : "s"} intersect${hits === 1 ? "s" : ""} a clearance envelope.`
: "No geometric interference was detected.";
ui.scoreValue.textContent = score;
ui.scoreRing.style.setProperty("--angle", `${score * 3.6}deg`);
ui.scoreRing.classList.toggle("fail", hits > 0);
ui.kneeRow.classList.toggle("hit", drawerHit || topHit);
ui.footRow.classList.toggle("hit", footHit);
ui.topRow.classList.toggle("hit", topHit);
if (drawerHit) {
ui.kneeLabel.textContent = "Drawer intrusion";
ui.kneeValue.textContent = `${drawerDepthCm} cm`;
} else if (topHit) {
ui.kneeLabel.textContent = "Top-edge collision";
ui.kneeValue.textContent = "Contact";
} else {
ui.kneeLabel.textContent = "No drawer interference";
ui.kneeValue.textContent = "Clear";
}
if (footHit) {
ui.footLabel.textContent = "Crossbar intrusion";
ui.footValue.textContent = `${footDepthCm} cm`;
} else {
ui.footLabel.textContent = "No crossbar interference";
ui.footValue.textContent = `${footGapCm} cm`;
}
if (topHit) {
ui.topLabel.textContent = "Underside collision";
ui.topValue.textContent = "Contact";
} else {
ui.topLabel.textContent = "Vertical clearance";
ui.topValue.textContent = `${topGapCm} cm`;
}
setConflictMaterial(materials.drawer, drawerHit, 0xb9c6c0);
setConflictMaterial(materials.drawerFace, drawerHit, 0xcbd4ce);
setConflictMaterial(materials.frame, footHit, 0x435156);
setConflictMaterial(materials.handle, footHit, 0x4b5a5d);
kneeEnvelopeMaterial.color.setHex(
drawerHit || topHit ? 0xf06454 : 0x10b5a7
);
kneeRingMaterial.color.setHex(
drawerHit || topHit ? 0xf06454 : 0x10b5a7
);
footEnvelopeMaterial.color.setHex(footHit ? 0xf06454 : 0xef7a45);
footRingMaterial.color.setHex(footHit ? 0xf06454 : 0xef7a45);
ui.kneeCallout.classList.toggle("hit", drawerHit || topHit);
ui.footCallout.classList.toggle("hit", footHit);
const kneeText = drawerHit
? `DRAWER · ${drawerDepthCm} cm`
: topHit
? "TOP EDGE · CONTACT"
: `TOP EDGE · ${topGapCm} cm`;
const footText = footHit
? `CROSSBAR · ${footDepthCm} cm`
: `CLEAR · ${footGapCm} cm`;
ui.kneeCallout.innerHTML = `<span>KNEE ZONE</span>${kneeText}`;
ui.footCallout.innerHTML = `<span>FOOT ZONE</span>${footText}`;
}
// ------------------------------------------------------------
// UI bindings
// ------------------------------------------------------------
function syncOutputs() {
ui.heightOutput.textContent = `${Math.round(state.height * 100)} cm`;
ui.drawerOutput.textContent = `${Math.round(state.drawer * 100)} cm open`;
ui.barOutput.textContent = `${Math.round(state.bar * 100)} cm`;
for (const slider of [
ui.heightSlider,
ui.drawerSlider,
ui.barSlider
]) {
const percent =
((Number(slider.value) - Number(slider.min)) /
(Number(slider.max) - Number(slider.min))) *
100;
slider.style.setProperty("--fill", `${percent}%`);
}
}
ui.heightSlider.addEventListener("input", (event) => {
state.height = Number(event.target.value) / 100;
syncOutputs();
updateDesk();
evaluateClearance();
});
ui.drawerSlider.addEventListener("input", (event) => {
state.drawer = Number(event.target.value) / 100;
syncOutputs();
updateDesk();
evaluateClearance();
});
ui.barSlider.addEventListener("input", (event) => {
state.bar = Number(event.target.value) / 100;
syncOutputs();
updateDesk();
evaluateClearance();
});
ui.testButton.addEventListener("click", () => {
state.pulse = 1;
evaluateClearance();
ui.testButton.textContent = "Test complete";
window.setTimeout(() => {
ui.testButton.textContent = "Run test";
}, 850);
});
ui.envelopeButton.addEventListener("click", () => {
state.envelopes = !state.envelopes;
envelopeGroup.visible = state.envelopes;
ui.envelopeButton.textContent = state.envelopes
? "Envelopes on"
: "Envelopes off";
ui.envelopeButton.classList.toggle("active", state.envelopes);
});
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 1.13;
cameraState.radius = 6.45;
cameraState.target.set(0, 1.02, 0.42);
updateCamera();
}
ui.resetButton.addEventListener("click", () => {
state.height = 1.35;
state.drawer = 0.28;
state.bar = 0.22;
state.pulse = 1;
ui.heightSlider.value = 135;
ui.drawerSlider.value = 28;
ui.barSlider.value = 22;
syncOutputs();
updateDesk();
evaluateClearance();
resetCamera();
});
// ------------------------------------------------------------
// Direct orbit and zoom controls — no external addons
// ------------------------------------------------------------
const drag = {
active: false,
lastX: 0,
lastY: 0,
pointerId: null
};
canvas.addEventListener("pointerdown", (event) => {
drag.active = true;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.pointerId = event.pointerId;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!drag.active || event.pointerId !== drag.pointerId) {
return;
}
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.48,
1.46
);
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== drag.pointerId) {
return;
}
drag.active = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (1 + event.deltaY * 0.001),
3.8,
10
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Projected HTML annotations
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function positionCallout(element, anchor) {
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.display = visible && state.envelopes ? "block" : "none";
if (!visible) {
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
syncOutputs();
updateDesk();
evaluateClearance();
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (state.pulse > 0) {
state.pulse = Math.max(0, state.pulse - dt * 0.8);
}
const wave = Math.sin((1 - state.pulse) * Math.PI * 4) * state.pulse;
kneeEnvelopeMaterial.opacity = 0.16 + state.pulse * 0.1;
footEnvelopeMaterial.opacity = 0.18 + state.pulse * 0.1;
kneeRingMaterial.opacity = 0.62 + state.pulse * 0.25;
footRingMaterial.opacity = 0.66 + state.pulse * 0.25;
for (const ring of kneeRings) {
ring.scale.setScalar(1 + wave * 0.012);
}
for (const ring of footRings) {
ring.scale.setScalar(1 + wave * 0.016);
}
if (lastHits.drawer) {
materials.drawer.emissiveIntensity = 0.18 + state.pulse * 0.55;
materials.drawerFace.emissiveIntensity = 0.18 + state.pulse * 0.55;
}
if (lastHits.foot) {
materials.frame.emissiveIntensity = 0.18 + state.pulse * 0.55;
materials.handle.emissiveIntensity = 0.18 + state.pulse * 0.55;
}
positionCallout(
ui.kneeCallout,
new THREE.Vector3(0.15, 1.14, 0.12)
);
positionCallout(
ui.footCallout,
new THREE.Vector3(0.16, 0.38, 0.06)
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```