Prompt specification
Build or customize the Three.js 3D scene "Monitor height and viewing-direction comparison" 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: Monitor height and viewing-direction comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/monitor-height-and-viewing-direction-comparison-x1038
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows workstation reach and viewing geometry. Place identical workstations with different monitor positions and movable eye markers; show sight lines and neck orientation schematically without prescribing one universal setup. A 3D cutaway view.
Working Three.js Starter (monitor-height-and-viewing-direction-comparison-x1038):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Workstation Reach & Viewing Geometry</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 21, 36, 0.88);
--panel-border: rgba(153, 190, 218, 0.18);
--text: #eaf4ff;
--muted: #91a8bd;
--cyan: #5ee7ff;
--orange: #ffb454;
--purple: #ae92ff;
--green: #67e6b1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px) saturate(130%);
-webkit-backdrop-filter: blur(18px) saturate(130%);
}
#title {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 17px 19px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.3vw, 29px);
line-height: 1.12;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#controls {
top: 154px;
left: 18px;
width: 306px;
max-height: calc(100vh - 204px);
padding: 15px;
overflow-y: auto;
scrollbar-width: thin;
}
.section-title {
margin: 0 0 9px;
color: #c8d9e8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.station-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 15px;
}
.station-tab {
min-width: 0;
padding: 9px 6px;
border: 1px solid rgba(151, 185, 211, 0.16);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
cursor: pointer;
transition: 150ms ease;
}
.station-tab strong,
.station-tab small {
display: block;
}
.station-tab strong {
color: var(--text);
font-size: 12px;
}
.station-tab small {
margin-top: 3px;
font-size: 9px;
white-space: nowrap;
}
.station-tab.active {
border-color: rgba(94, 231, 255, 0.7);
background: rgba(94, 231, 255, 0.12);
color: var(--cyan);
}
.control-row {
margin: 13px 0;
}
.control-label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: #cbdbea;
font-size: 11px;
}
.control-label output {
color: var(--text);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 4px 0;
accent-color: var(--cyan);
cursor: pointer;
}
.toggles {
display: grid;
gap: 7px;
margin: 14px 0;
padding-top: 13px;
border-top: 1px solid rgba(153, 190, 218, 0.12);
}
.toggle {
display: flex;
align-items: center;
gap: 9px;
color: #c8d9e8;
font-size: 11px;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: var(--cyan);
}
.swatch {
width: 18px;
height: 3px;
border-radius: 3px;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.button-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 13px;
}
.button-row button {
padding: 8px 5px;
border: 1px solid rgba(151, 185, 211, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #c8d9e8;
font-size: 10px;
cursor: pointer;
}
.button-row button:hover {
border-color: rgba(94, 231, 255, 0.55);
color: var(--text);
}
.note {
margin: 13px 0 0;
padding: 10px 11px;
border-left: 2px solid var(--green);
border-radius: 0 8px 8px 0;
background: rgba(103, 230, 177, 0.07);
color: #b9d8cc;
font-size: 10px;
line-height: 1.5;
}
#stats {
top: 18px;
right: 18px;
width: 276px;
padding: 16px;
pointer-events: none;
}
.stats-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
#selected-name {
font-size: 14px;
font-weight: 700;
}
#selected-code {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
}
.stats-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px 14px;
font-size: 11px;
}
.stats-grid span:nth-child(odd) {
color: var(--muted);
}
.stats-grid span:nth-child(even) {
color: var(--text);
font-variant-numeric: tabular-nums;
}
#legend {
right: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 15px;
max-width: calc(100vw - 36px);
padding: 11px 14px;
color: #bfd0df;
font-size: 10px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-item .swatch {
width: 20px;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #07111f;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 800px) {
#title {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 15px;
}
#title .subtitle {
display: none;
}
#controls {
top: auto;
bottom: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 42vh;
padding: 12px;
}
#stats {
top: 91px;
right: 10px;
width: 218px;
padding: 12px;
}
.stats-grid {
gap: 5px 10px;
font-size: 10px;
}
#legend {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header id="title" class="panel">
<p class="eyebrow">Comparative workstation study</p>
<h1>Reach & viewing geometry</h1>
<p class="subtitle">
Three identical desks with different screen positions. Move the amber eye
markers to inspect sight lines, neck orientation, and reach relationships.
</p>
</header>
<aside id="controls" class="panel">
<p class="section-title">Select a workstation</p>
<div class="station-tabs" id="station-tabs"></div>
<div class="control-row">
<label class="control-label" for="monitor-offset">
<span>Monitor lateral offset</span>
<output id="monitor-offset-value">0 cm</output>
</label>
<input id="monitor-offset" type="range" min="-110" max="110" step="5" value="0">
</div>
<div class="control-row">
<label class="control-label" for="eye-lateral">
<span>Eye marker lateral position</span>
<output id="eye-lateral-value">0 cm</output>
</label>
<input id="eye-lateral" type="range" min="-35" max="35" step="1" value="0">
</div>
<div class="control-row">
<label class="control-label" for="eye-height">
<span>Eye marker height</span>
<output id="eye-height-value">125 cm</output>
</label>
<input id="eye-height" type="range" min="105" max="145" step="1" value="125">
</div>
<div class="toggles">
<label class="toggle">
<input id="show-sight" type="checkbox" checked>
<span class="swatch" style="color: var(--cyan)"></span>
Sight line to screen center
</label>
<label class="toggle">
<input id="show-neck" type="checkbox" checked>
<span class="swatch" style="color: var(--orange)"></span>
Neck axis and orientation change
</label>
<label class="toggle">
<input id="show-reach" type="checkbox" checked>
<span class="swatch" style="color: var(--purple)"></span>
Illustrative reach envelope
</label>
</div>
<div class="button-row">
<button id="view-overview" type="button">Overview</button>
<button id="view-plan" type="button">Plan</button>
<button id="view-front" type="button">Front</button>
</div>
<div class="button-row">
<button id="reset-station" type="button">Reset station</button>
<button id="reset-all" type="button">Reset examples</button>
<button id="reset-view" type="button">Reset camera</button>
</div>
<p class="note">
Schematic comparison only. The reach radius, body proportions, and markers
are illustrative—not a universal ergonomic prescription or a substitute
for task- and person-specific assessment.
</p>
</aside>
<aside id="stats" class="panel">
<div class="stats-heading">
<span id="selected-name">Screen left</span>
<span id="selected-code">A</span>
</div>
<div class="stats-grid" id="stats-grid"></div>
</aside>
<footer id="legend" class="panel">
<span class="legend-item">
<span class="swatch" style="color: var(--cyan)"></span>Sight line
</span>
<span class="legend-item">
<span class="swatch" style="color: var(--orange)"></span>Neck orientation
</span>
<span class="legend-item">
<span class="swatch" style="color: var(--purple)"></span>Reach geometry
</span>
<span>Drag empty space: orbit · Wheel: zoom · Shift/right drag: pan</span>
</footer>
<div id="loading">Loading three-dimensional study…</div>
<script type="module">
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
document.querySelector("#loading").textContent =
"Unable to load Three.js. Check the network connection and reload.";
throw error;
}
const $ = (selector) => document.querySelector(selector);
const sceneHost = $("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 13, 28);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9dcff, 0x17202b, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(-4, 10, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x4bc9ff, 22, 18, 2);
rimLight.position.set(5, 4, -3);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb454, 15, 14, 2);
warmLight.position.set(-5, 3, 2);
scene.add(warmLight);
const cameraState = {
target: new THREE.Vector3(0, 0.78, 0.1),
radius: 13.7,
theta: 0.61,
phi: 1.03
};
const defaultCamera = {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
};
function applyCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
applyCamera();
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x182635,
roughness: 0.93,
metalness: 0.04
}),
wall: new THREE.MeshStandardMaterial({
color: 0x26394a,
roughness: 0.9
}),
wallCut: new THREE.MeshStandardMaterial({
color: 0x7891a4,
roughness: 0.72
}),
desk: new THREE.MeshStandardMaterial({
color: 0xb99b77,
roughness: 0.7
}),
deskEdge: new THREE.MeshStandardMaterial({
color: 0x6f5943,
roughness: 0.7
}),
metal: new THREE.MeshStandardMaterial({
color: 0x3d4b58,
roughness: 0.42,
metalness: 0.7
}),
dark: new THREE.MeshStandardMaterial({
color: 0x111c28,
roughness: 0.72
}),
chair: new THREE.MeshStandardMaterial({
color: 0x31475a,
roughness: 0.78
}),
person: new THREE.MeshStandardMaterial({
color: 0x66849b,
roughness: 0.72,
transparent: true,
opacity: 0.62
}),
head: new THREE.MeshStandardMaterial({
color: 0x9dc2d8,
roughness: 0.8,
transparent: true,
opacity: 0.16,
depthWrite: false
}),
screen: new THREE.MeshBasicMaterial({ color: 0x12354e }),
screenGlow: new THREE.MeshBasicMaterial({ color: 0x1c5874 }),
screenLine: new THREE.MeshBasicMaterial({ color: 0x4fbdd7 }),
eye: new THREE.MeshStandardMaterial({
color: 0xffb454,
emissive: 0xff8a00,
emissiveIntensity: 1.3,
roughness: 0.28
})
};
function addBox(parent, width, height, depth, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(parent, a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 12),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeTextSprite(text, accent = "#5ee7ff", width = 1.35) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (112 / 512), 1);
sprite.renderOrder = 20;
function draw(nextText, nextAccent = accent) {
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(
context,
7,
9,
canvas.width - 14,
canvas.height - 18,
18
);
context.fillStyle = "rgba(5, 15, 27, 0.88)";
context.fill();
context.strokeStyle = "rgba(164, 197, 221, 0.25)";
context.lineWidth = 2;
context.stroke();
context.fillStyle = nextAccent;
roundedRect(context, 17, 23, 7, 66, 3);
context.fill();
context.font = "600 31px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#eaf4ff";
context.fillText(nextText, 269, 57);
texture.needsUpdate = true;
}
draw(text);
sprite.userData.setText = draw;
return sprite;
}
function addRoom() {
const room = new THREE.Group();
scene.add(room);
addBox(room, 14.2, 0.12, 7.6, materials.floor, 0, -0.06, 0, false);
const grid = new THREE.GridHelper(14, 28, 0x3d566a, 0x263b4c);
grid.position.y = 0.012;
grid.scale.z = 7.6 / 14;
grid.material.transparent = true;
grid.material.opacity = 0.34;
room.add(grid);
addBox(room, 14.1, 2.85, 0.12, materials.wall, 0, 1.425, -3.7);
addBox(room, 0.12, 2.85, 4.25, materials.wall, -7.05, 1.425, -1.575);
addBox(
room,
14.18,
0.055,
0.16,
materials.wallCut,
0,
2.855,
-3.69,
false
);
addBox(
room,
0.16,
0.055,
4.3,
materials.wallCut,
-7.04,
2.855,
-1.575,
false
);
const sectionMarks = new THREE.Group();
for (let x = -6.8; x <= 6.8; x += 0.34) {
addBox(
sectionMarks,
0.045,
0.18,
0.14,
materials.wallCut,
x,
2.84,
-3.59,
false
);
}
room.add(sectionMarks);
const wallLabel = makeTextSprite(
"CUTAWAY / COMPARATIVE STUDY",
"#5ee7ff",
3.5
);
wallLabel.position.set(0, 2.22, -3.57);
room.add(wallLabel);
const floorLabel = makeTextSprite(
"ILLUSTRATIVE GEOMETRY — NOT A UNIVERSAL SETUP",
"#67e6b1",
3.9
);
floorLabel.position.set(0, 0.11, 3.15);
room.add(floorLabel);
}
addRoom();
function createReachSector(radius = 1.35, halfAngle = 1.18) {
const group = new THREE.Group();
const segments = 48;
const positions = [];
for (let i = 0; i < segments; i++) {
const a0 = -halfAngle + (i / segments) * halfAngle * 2;
const a1 = -halfAngle + ((i + 1) / segments) * halfAngle * 2;
const p0 = [Math.sin(a0) * radius, 0, -Math.cos(a0) * radius];
const p1 = [Math.sin(a1) * radius, 0, -Math.cos(a1) * radius];
positions.push(
0, 0, 0,
...p0,
...p1
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const fill = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color: 0xae92ff,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false,
depthTest: false
})
);
fill.renderOrder = 3;
group.add(fill);
const points = [];
for (let i = 0; i <= 64; i++) {
const a = -halfAngle + (i / 64) * halfAngle * 2;
points.push(
new THREE.Vector3(
Math.sin(a) * radius,
0,
-Math.cos(a) * radius
)
);
}
const arc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0xae92ff,
transparent: true,
opacity: 0.58,
depthTest: false
})
);
arc.renderOrder = 5;
group.add(arc);
for (const angle of [-halfAngle, halfAngle]) {
const radial = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(
Math.sin(angle) * radius,
0,
-Math.cos(angle) * radius
)
]),
new THREE.LineDashedMaterial({
color: 0xae92ff,
transparent: true,
opacity: 0.32,
dashSize: 0.07,
gapSize: 0.05,
depthTest: false
})
);
radial.computeLineDistances();
radial.renderOrder = 5;
group.add(radial);
}
return group;
}
function replaceLinePoints(line, points) {
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
if (line.material.isLineDashedMaterial) {
line.computeLineDistances();
}
line.frustumCulled = false;
}
function createOverlayLine(color, dashed = false, opacity = 1) {
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.075,
gapSize: 0.05,
depthTest: false,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]),
material
);
line.renderOrder = 9;
return line;
}
const stationDefinitions = [
{ code: "A", name: "Screen left", offset: -0.9 },
{ code: "B", name: "Screen centered", offset: 0 },
{ code: "C", name: "Screen right", offset: 0.9 }
];
const stations = [];
const pickMeshes = [];
function buildStation(definition, index) {
const group = new THREE.Group();
group.position.x = (index - 1) * 4;
scene.add(group);
const station = {
...definition,
index,
group,
initialOffset: definition.offset,
offset: definition.offset,
eye: new THREE.Vector3(0, 1.25, 0.43),
neutralEye: new THREE.Vector3(0, 1.25, 0.43),
pivot: new THREE.Vector3(0, 1.04, 0.82)
};
// Identical desk and furniture.
addBox(group, 2.85, 0.10, 1.28, materials.desk, 0, 0.76, -0.02);
addBox(group, 2.88, 0.055, 1.31, materials.deskEdge, 0, 0.695, -0.02);
for (const x of [-1.17, 1.17]) {
for (const z of [-0.48, 0.43]) {
addBox(
group,
0.085,
0.68,
0.085,
materials.metal,
x,
0.34,
z
);
}
}
addBox(group, 0.86, 0.025, 0.27, materials.dark, -0.05, 0.825, 0.31);
addBox(group, 0.12, 0.055, 0.18, materials.dark, 0.62, 0.835, 0.29);
// Chair.
addBox(group, 0.63, 0.12, 0.60, materials.chair, 0, 0.49, 1.04);
addBox(
group,
0.62,
0.68,
0.11,
materials.chair,
0,
0.86,
1.39
);
addCylinderBetween(
group,
new THREE.Vector3(0, 0.12, 1.05),
new THREE.Vector3(0, 0.46, 1.05),
0.045,
materials.metal
);
addBox(group, 0.72, 0.055, 0.08, materials.metal, 0, 0.07, 1.05);
// Schematic seated body.
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.27, 0.55, 16),
materials.person
);
torso.position.set(0, 0.91, 0.93);
torso.rotation.x = -0.10;
torso.castShadow = true;
group.add(torso);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 24, 16),
materials.head
);
head.position.set(0, 1.26, 0.53);
head.scale.set(0.9, 1.08, 0.95);
group.add(head);
addCylinderBetween(
group,
new THREE.Vector3(-0.23, 1.04, 0.84),
new THREE.Vector3(-0.33, 0.83, 0.39),
0.058,
materials.person
);
addCylinderBetween(
group,
new THREE.Vector3(0.23, 1.04, 0.84),
new THREE.Vector3(0.33, 0.83, 0.39),
0.058,
materials.person
);
addCylinderBetween(
group,
new THREE.Vector3(-0.13, 0.62, 0.93),
new THREE.Vector3(-0.18, 0.50, 0.48),
0.075,
materials.person
);
addCylinderBetween(
group,
new THREE.Vector3(0.13, 0.62, 0.93),
new THREE.Vector3(0.18, 0.50, 0.48),
0.075,
materials.person
);
const pivotDot = new THREE.Mesh(
new THREE.SphereGeometry(0.026, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xffb454 })
);
pivotDot.position.copy(station.pivot);
group.add(pivotDot);
// Movable eye marker.
const marker = new THREE.Group();
group.add(marker);
station.marker = marker;
const eyeSphere = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 18, 12),
materials.eye
);
eyeSphere.castShadow = true;
marker.add(eyeSphere);
const eyeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.085, 0.011, 8, 28),
new THREE.MeshBasicMaterial({ color: 0xffd18b })
);
marker.add(eyeRing);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.125, 0.008, 8, 32),
new THREE.MeshBasicMaterial({
color: 0xffb454,
transparent: true,
opacity: 0.35,
depthTest: false
})
);
halo.renderOrder = 15;
marker.add(halo);
const pick = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 12, 8),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
pick.userData.stationIndex = index;
marker.add(pick);
pickMeshes.push(pick);
// Neutral eye reference.
const neutralRing = new THREE.Mesh(
new THREE.TorusGeometry(0.07, 0.006, 6, 24),
new THREE.MeshBasicMaterial({
color: 0xa8bac9,
transparent: true,
opacity: 0.42,
depthTest: false
})
);
neutralRing.position.copy(station.neutralEye);
group.add(neutralRing);
// Monitor assembly.
const monitor = new THREE.Group();
monitor.position.z = -0.55;
group.add(monitor);
station.monitor = monitor;
addBox(monitor, 0.43, 0.035, 0.23, materials.metal, 0, 0.82, 0);
addBox(monitor, 0.065, 0.34, 0.065, materials.metal, 0, 0.985, 0);
addBox(monitor, 1.08, 0.64, 0.065, materials.dark, 0, 1.31, 0);
addBox(monitor, 0.99, 0.55, 0.008, materials.screen, 0, 1.31, 0.037, false);
addBox(
monitor,
0.70,
0.035,
0.005,
materials.screenGlow,
-0.06,
1.43,
0.044,
false
);
addBox(
monitor,
0.46,
0.018,
0.005,
materials.screenLine,
-0.16,
1.35,
0.044,
false
);
addBox(
monitor,
0.53,
0.018,
0.005,
materials.screenLine,
-0.13,
1.29,
0.044,
false
);
const target = new THREE.Mesh(
new THREE.SphereGeometry(0.026, 12, 8),
new THREE.MeshBasicMaterial({
color: 0x5ee7ff,
depthTest: false
})
);
target.position.set(0, 1.31, 0.055);
target.renderOrder = 16;
monitor.add(target);
station.target = target;
// Reach sector.
const reachGroup = createReachSector();
reachGroup.position.set(0, 0.825, 0.82);
group.add(reachGroup);
station.reachGroup = reachGroup;
// Schematic overlays.
station.sightLine = createOverlayLine(0x5ee7ff, true, 0.95);
station.neckLine = createOverlayLine(0xffb454, false, 1);
station.neutralNeckLine = createOverlayLine(0x8193a3, true, 0.48);
station.neckArc = createOverlayLine(0xffb454, false, 0.72);
station.reachLine = createOverlayLine(0xae92ff, true, 0.8);
group.add(
station.sightLine,
station.neckLine,
station.neutralNeckLine,
station.neckArc,
station.reachLine
);
station.neckLabel = makeTextSprite("NECK Δ 0°", "#ffb454", 1.12);
station.neckLabel.position.set(0.45, 1.48, 0.58);
group.add(station.neckLabel);
station.reachLabel = makeTextSprite("REACH 132 cm", "#ae92ff", 1.18);
group.add(station.reachLabel);
station.monitorLabel = makeTextSprite(
"MONITOR −90 cm",
"#5ee7ff",
1.45
);
station.monitorLabel.position.set(definition.offset, 1.79, -0.48);
group.add(station.monitorLabel);
station.nameLabel = makeTextSprite(
`${definition.code} / ${definition.name.toUpperCase()}`,
"#dceaf6",
2.05
);
station.nameLabel.position.set(0, 0.28, 1.82);
group.add(station.nameLabel);
// Floor selection outline.
const selectionPoints = [
new THREE.Vector3(-1.5, 0.018, -0.77),
new THREE.Vector3(1.5, 0.018, -0.77),
new THREE.Vector3(1.5, 0.018, 1.58),
new THREE.Vector3(-1.5, 0.018, 1.58)
];
station.selection = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(selectionPoints),
new THREE.LineBasicMaterial({
color: 0x5ee7ff,
transparent: true,
opacity: 0.25,
depthTest: false
})
);
station.selection.renderOrder = 4;
group.add(station.selection);
stations.push(station);
return station;
}
stationDefinitions.forEach(buildStation);
let selectedStation = stations[0];
let selectedIndex = 0;
const stationTabs = $("#station-tabs");
stationDefinitions.forEach((definition, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "station-tab";
button.innerHTML = `
<strong>${definition.code}</strong>
<small>${definition.name.replace("Screen ", "")}</small>
`;
button.addEventListener("click", () => selectStation(index));
stationTabs.appendChild(button);
});
function signed(value, decimals = 0) {
const rounded = Number(value.toFixed(decimals));
return `${rounded > 0 ? "+" : ""}${rounded}`;
}
function slerpDirection(a, b, t) {
const dot = THREE.MathUtils.clamp(a.dot(b), -1, 1);
const omega = Math.acos(dot);
if (omega < 0.0001) {
return a.clone();
}
const sinOmega = Math.sin(omega);
return a
.clone()
.multiplyScalar(Math.sin((1 - t) * omega) / sinOmega)
.add(b.clone().multiplyScalar(Math.sin(t * omega) / sinOmega))
.normalize();
}
function updateStation(station) {
station.monitor.position.x = station.offset;
const eye = station.eye;
const pivot = station.pivot;
const neutral = station.neutralEye;
const target = new THREE.Vector3(station.offset, 1.31, -0.49);
station.marker.position.copy(eye);
replaceLinePoints(station.sightLine, [eye.clone(), target.clone()]);
replaceLinePoints(station.neckLine, [pivot.clone(), eye.clone()]);
replaceLinePoints(station.neutralNeckLine, [
pivot.clone(),
neutral.clone()
]);
const currentNeck = eye.clone().sub(pivot).normalize();
const neutralNeck = neutral.clone().sub(pivot).normalize();
const arcPoints = [];
for (let i = 0; i <= 28; i++) {
const t = i / 28;
const direction = slerpDirection(neutralNeck, currentNeck, t);
arcPoints.push(pivot.clone().add(direction.multiplyScalar(0.28)));
}
replaceLinePoints(station.neckArc, arcPoints);
const reachEnd = new THREE.Vector3(
station.offset,
pivot.y,
target.z
);
replaceLinePoints(station.reachLine, [pivot.clone(), reachEnd]);
station.reachLabel.position.copy(
pivot.clone().lerp(reachEnd, 0.52).add(new THREE.Vector3(0, 0.13, 0))
);
const neckDelta = THREE.MathUtils.radToDeg(
Math.acos(THREE.MathUtils.clamp(currentNeck.dot(neutralNeck), -1, 1))
);
const neckYaw = THREE.MathUtils.radToDeg(
Math.atan2(eye.x - pivot.x, -(eye.z - pivot.z))
);
const sightYaw = THREE.MathUtils.radToDeg(
Math.atan2(target.x - eye.x, eye.z - target.z)
);
const sightPitch = THREE.MathUtils.radToDeg(
Math.atan2(
target.y - eye.y,
Math.hypot(target.x - eye.x, target.z - eye.z)
)
);
const eyeDistance = eye.distanceTo(target);
const reachDistance = pivot.distanceTo(reachEnd);
station.metrics = {
neckDelta,
neckYaw,
sightYaw,
sightPitch,
eyeDistance,
reachDistance
};
station.neckLabel.userData.setText(
`NECK Δ ${Math.round(neckDelta)}°`,
"#ffb454"
);
station.reachLabel.userData.setText(
`REACH ${Math.round(reachDistance * 100)} cm`,
"#ae92ff"
);
station.monitorLabel.userData.setText(
`MONITOR ${signed(station.offset * 100)} cm`,
"#5ee7ff"
);
station.monitorLabel.position.x = station.offset;
if (station === selectedStation) {
updateStats(station);
}
}
function updateStats(station) {
const m = station.metrics;
const rows = [
["Monitor offset", `${signed(station.offset * 100)} cm`],
["Eye lateral", `${signed(station.eye.x * 100)} cm`],
["Eye height", `${Math.round(station.eye.y * 100)} cm`],
["Neck change", `${Math.round(m.neckDelta)}°`],
["Neck yaw", `${signed(m.neckYaw)}°`],
["Sight yaw", `${signed(m.sightYaw)}°`],
["Sight pitch", `${signed(m.sightPitch)}°`],
["Eye → screen", `${Math.round(m.eyeDistance * 100)} cm`],
["Shoulder → screen", `${Math.round(m.reachDistance * 100)} cm`]
];
$("#stats-grid").innerHTML = rows
.map(([label, value]) => `<span>${label}</span><span>${value}</span>`)
.join("");
}
function selectStation(index) {
selectedIndex = index;
selectedStation = stations[index];
stations.forEach((station, i) => {
const active = i === index;
station.selection.material.opacity = active ? 0.9 : 0.16;
station.selection.material.color.set(active ? 0x5ee7ff : 0x6f8798);
});
[...stationTabs.children].forEach((button, i) => {
button.classList.toggle("active", i === index);
});
$("#selected-name").textContent = selectedStation.name;
$("#selected-code").textContent = selectedStation.code;
updateControlValues();
updateStats(selectedStation);
}
function updateControlValues() {
const station = selectedStation;
$("#monitor-offset").value = Math.round(station.offset * 100);
$("#eye-lateral").value = Math.round(station.eye.x * 100);
$("#eye-height").value = Math.round(station.eye.y * 100);
$("#monitor-offset-value").textContent =
`${signed(station.offset * 100)} cm`;
$("#eye-lateral-value").textContent =
`${signed(station.eye.x * 100)} cm`;
$("#eye-height-value").textContent =
`${Math.round(station.eye.y * 100)} cm`;
}
stations.forEach(updateStation);
selectStation(0);
$("#monitor-offset").addEventListener("input", (event) => {
selectedStation.offset = Number(event.target.value) / 100;
updateStation(selectedStation);
updateControlValues();
});
$("#eye-lateral").addEventListener("input", (event) => {
selectedStation.eye.x = Number(event.target.value) / 100;
updateStation(selectedStation);
updateControlValues();
});
$("#eye-height").addEventListener("input", (event) => {
selectedStation.eye.y = Number(event.target.value) / 100;
updateStation(selectedStation);
updateControlValues();
});
function applyVisibility() {
const showSight = $("#show-sight").checked;
const showNeck = $("#show-neck").checked;
const showReach = $("#show-reach").checked;
stations.forEach((station) => {
station.sightLine.visible = showSight;
station.target.visible = showSight;
station.neckLine.visible = showNeck;
station.neutralNeckLine.visible = showNeck;
station.neckArc.visible = showNeck;
station.neckLabel.visible = showNeck;
station.reachGroup.visible = showReach;
station.reachLine.visible = showReach;
station.reachLabel.visible = showReach;
});
}
$("#show-sight").addEventListener("change", applyVisibility);
$("#show-neck").addEventListener("change", applyVisibility);
$("#show-reach").addEventListener("change", applyVisibility);
applyVisibility();
function resetStation(station) {
station.offset = station.initialOffset;
station.eye.set(0, 1.25, 0.43);
updateStation(station);
}
$("#reset-station").addEventListener("click", () => {
resetStation(selectedStation);
updateControlValues();
});
$("#reset-all").addEventListener("click", () => {
stations.forEach(resetStation);
updateControlValues();
});
function resetCamera() {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
applyCamera();
}
$("#reset-view").addEventListener("click", resetCamera);
$("#view-overview").addEventListener("click", resetCamera);
$("#view-plan").addEventListener("click", () => {
cameraState.target.set(0, 0.65, -0.05);
cameraState.radius = 12.2;
cameraState.theta = 0;
cameraState.phi = 0.19;
applyCamera();
});
$("#view-front").addEventListener("click", () => {
cameraState.target.set(0, 0.85, 0);
cameraState.radius = 13.4;
cameraState.theta = 0;
cameraState.phi = 1.38;
applyCamera();
});
// Direct camera controls and eye-marker dragging.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane();
const dragOffset = new THREE.Vector3();
let dragMode = null;
let activePointerId = null;
let activeStation = null;
let lastX = 0;
let lastY = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
updatePointer(event);
activePointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
const hits = raycaster.intersectObjects(pickMeshes, false);
if (event.button === 0 && hits.length) {
const index = hits[0].object.userData.stationIndex;
selectStation(index);
activeStation = stations[index];
const worldZ = activeStation.group.position.z + activeStation.eye.z;
dragPlane.set(new THREE.Vector3(0, 0, 1), -worldZ);
const hitPoint = new THREE.Vector3();
if (raycaster.ray.intersectPlane(dragPlane, hitPoint)) {
const localPoint = activeStation.group.worldToLocal(hitPoint.clone());
dragOffset.copy(activeStation.eye).sub(localPoint);
}
dragMode = "eye";
} else if (event.button === 2 || event.shiftKey) {
dragMode = "pan";
} else {
dragMode = "orbit";
}
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (event.pointerId !== activePointerId || !dragMode) {
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "eye") {
updatePointer(event);
const hitPoint = new THREE.Vector3();
if (raycaster.ray.intersectPlane(dragPlane, hitPoint)) {
const localPoint = activeStation.group.worldToLocal(hitPoint.clone());
localPoint.add(dragOffset);
activeStation.eye.x = THREE.MathUtils.clamp(localPoint.x, -0.35, 0.35);
activeStation.eye.y = THREE.MathUtils.clamp(localPoint.y, 1.05, 1.45);
activeStation.eye.z = 0.43;
updateStation(activeStation);
updateControlValues();
}
} else if (dragMode === "orbit") {
cameraState.theta -= dx * 0.0055;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.12,
1.43
);
applyCamera();
} else if (dragMode === "pan") {
const scale = cameraState.radius * 0.00125;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
applyCamera();
}
});
function endPointer(event) {
if (event.pointerId === activePointerId) {
dragMode = null;
activeStation = null;
activePointerId = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.01,
5.5,
22
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
stations.forEach((station) => {
const selected = station === selectedStation;
const pulse = selected ? 1 + Math.sin(time * 3.2) * 0.09 : 1;
station.marker.children[2].scale.setScalar(pulse);
station.marker.children[2].material.opacity = selected ? 0.58 : 0.24;
});
renderer.render(scene, camera);
}
$("#loading").remove();
animate();
</script>
</body>
</html>
```