Prompt specification
Build or customize the Three.js 3D scene "Character Beside Three Chair Heights" 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: Character Beside Three Chair Heights
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/character-beside-three-chair-heights-x3737
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing character poses relative to furniture scale. Model one original character and three chairs with different seat heights. Show leg and seat relationships without claiming the examples represent ergonomic recommendations. Stylized solid forms.
Working Three.js Starter (character-beside-three-chair-heights-x3737):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Character Pose and Seat-Height Scale Study</title>
<style>
:root {
--ink: #273332;
--muted: #66716d;
--paper: rgba(250, 251, 247, 0.91);
--line: rgba(39, 51, 50, 0.14);
--accent: #287f77;
--warning: #936d22;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9ede6;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport,
#labels {
position: fixed;
inset: 0;
}
#viewport {
z-index: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
body.dragging #viewport canvas {
cursor: grabbing;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.station-tag,
.measure-tag {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
opacity: 0;
transition: opacity 180ms ease;
}
.station-tag {
min-width: 136px;
padding: 9px 12px;
border: 1px solid rgba(39, 51, 50, 0.13);
border-radius: 12px;
background: rgba(255, 255, 252, 0.87);
box-shadow: 0 8px 24px rgba(45, 56, 53, 0.09);
backdrop-filter: blur(8px);
transform: translate(-50%, 0);
}
.station-tag .tag-top {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.station-tag .swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}
.station-tag strong {
display: block;
margin-top: 3px;
font-size: 18px;
line-height: 1.05;
letter-spacing: -0.03em;
}
.station-tag small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.measure-tag {
padding: 5px 8px;
border-radius: 999px;
background: rgba(39, 51, 50, 0.82);
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translate(8px, -50%);
box-shadow: 0 4px 12px rgba(39, 51, 50, 0.15);
}
#info {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 20px;
border: 1px solid rgba(39, 51, 50, 0.12);
border-radius: 20px;
background: var(--paper);
box-shadow: 0 18px 48px rgba(48, 59, 56, 0.12);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 13px;
}
.metric {
min-width: 0;
padding: 10px 9px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.52);
}
.metric b {
display: block;
font-size: 14px;
letter-spacing: -0.02em;
}
.metric span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.model-note {
margin: 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.model-note strong {
color: var(--ink);
}
.disclaimer {
display: flex;
gap: 9px;
align-items: flex-start;
margin-top: 13px;
padding: 11px 12px;
border: 1px solid rgba(147, 109, 34, 0.18);
border-radius: 12px;
background: #fff6dc;
color: #6d531c;
font-size: 11px;
line-height: 1.45;
}
.disclaimer::before {
content: "i";
display: grid;
flex: 0 0 18px;
width: 18px;
height: 18px;
place-items: center;
border-radius: 50%;
background: #936d22;
color: white;
font-family: Georgia, serif;
font-size: 12px;
font-weight: 700;
}
#toolbar {
position: fixed;
z-index: 11;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid rgba(39, 51, 50, 0.14);
border-radius: 16px;
background: rgba(250, 251, 247, 0.92);
box-shadow: 0 12px 36px rgba(45, 56, 53, 0.13);
backdrop-filter: blur(12px);
transform: translateX(-50%);
}
.toolbar-label {
padding: 0 6px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.toolbar button {
min-width: 38px;
height: 34px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
transform 120ms ease,
background 120ms ease,
color 120ms ease;
}
.toolbar button:hover {
transform: translateY(-1px);
background: #edf4ef;
}
.toolbar button.active {
border-color: var(--accent);
background: var(--accent);
color: white;
}
.guide-toggle {
display: flex;
align-items: center;
gap: 7px;
margin-left: 3px;
padding: 0 8px;
color: var(--muted);
font-size: 11px;
white-space: nowrap;
cursor: pointer;
}
.guide-toggle input {
accent-color: var(--accent);
}
#camera-help {
position: fixed;
z-index: 9;
right: 22px;
bottom: 23px;
color: rgba(39, 51, 50, 0.65);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e9ede6;
color: var(--muted);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#info {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 15px;
border-radius: 16px;
}
.intro {
margin: 9px 0 11px;
font-size: 11px;
}
.metrics {
gap: 5px;
}
.metric {
padding: 8px 7px;
}
.model-note {
font-size: 10px;
}
.disclaimer {
font-size: 10px;
}
#toolbar {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
overflow-x: auto;
}
.toolbar-label,
#camera-help {
display: none;
}
.station-tag {
min-width: 108px;
padding: 7px 9px;
}
.station-tag strong {
font-size: 15px;
}
.station-tag small {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels" aria-hidden="true"></div>
<section id="info">
<p class="eyebrow">Form + Furniture Scale</p>
<h1>One character,<br>three seat heights</h1>
<p class="intro">
A single original character design is repeated in three neutral seated
studies. The pelvis-to-seat distance and limb segment lengths stay
constant while the chair height changes the hip–knee–ankle relationship.
</p>
<div class="metrics">
<div class="metric">
<b>41 cm</b>
<span>Upper leg</span>
</div>
<div class="metric">
<b>43 cm</b>
<span>Lower leg</span>
</div>
<div class="metric">
<b>12 cm</b>
<span>Seat to pelvis</span>
</div>
</div>
<p class="model-note">
<strong>Model setup:</strong> pelvis center is 12 cm above each seat top.
Feet meet the common floor plane. Chair and body dimensions are
illustrative geometry, not a claim about fit or suitability.
</p>
<div class="disclaimer">
<span>
These examples are <strong>not ergonomic recommendations</strong>.
Actual proportions and comfort depend on the person, task,
footwear, and environment.
</span>
</div>
</section>
<nav id="toolbar" aria-label="View controls">
<span class="toolbar-label">View</span>
<button type="button" data-focus="overview" class="active">All</button>
<button type="button" data-focus="-1.55">42 cm</button>
<button type="button" data-focus="0">48 cm</button>
<button type="button" data-focus="1.55">54 cm</button>
<label class="guide-toggle">
<input id="guides" type="checkbox" checked>
Guides
</label>
</nav>
<div id="camera-help">Drag to orbit · Scroll or pinch to zoom · R to reset</div>
<div id="loading">Preparing scale study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9ede6);
scene.fog = new THREE.Fog(0xe9ede6, 8.5, 18);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
40
);
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional character and chair scale comparison"
);
viewport.appendChild(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0xffffff, 0x758074, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff1d9, 3.25);
keyLight.position.set(-3.5, 6.5, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 4;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 15;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e4ec, 0.75);
fillLight.position.set(4, 3, -3);
scene.add(fillLight);
// Palette
const material = (color, roughness = 0.76, metalness = 0.0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
const materials = {
lowChair: material(0x7699c4),
middleChair: material(0xd17d6d),
highChair: material(0xd1a24f),
frame: material(0x4a5553, 0.72),
rubber: material(0x313938, 0.9),
shirt: material(0x2b8a80),
shirtDark: material(0x23746d),
pants: material(0x464b68),
skin: material(0xd79a74),
hair: material(0x302b35),
eyes: material(0x1f2525, 0.48),
shoes: material(0xf2eee3),
mat: material(0xdce2d8, 0.94),
guide: material(0x52605d, 0.86),
ground: material(0xe4e9df, 0.98)
};
// Shared helpers
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function addMesh(parent, geometry, mat, position) {
const mesh = new THREE.Mesh(geometry, mat);
if (position) mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rod(parent, start, end, radius, mat, endRadius = radius) {
const direction = end.clone().sub(start);
const length = direction.length();
if (length < 0.00001) {
return new THREE.Group();
}
const geometry = new THREE.CylinderGeometry(
endRadius,
radius,
1,
20,
1,
false
);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.scale.y = length;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, position, radius, mat, scale = null) {
const mesh = addMesh(
parent,
new THREE.SphereGeometry(radius, 24, 16),
mat,
position
);
if (scale) mesh.scale.set(...scale);
return mesh;
}
function roundedPrism(
parent,
width,
height,
depth,
radius,
mat,
position
) {
const bevel = Math.min(radius * 0.28, height * 0.2, depth * 0.2);
const shapeWidth = width - bevel * 2;
const shapeHeight = height - bevel * 2;
const corner = Math.max(0.001, radius - bevel);
const x = -shapeWidth / 2;
const y = -shapeHeight / 2;
const shape = new THREE.Shape();
shape.moveTo(x + corner, y);
shape.lineTo(x + shapeWidth - corner, y);
shape.quadraticCurveTo(
x + shapeWidth,
y,
x + shapeWidth,
y + corner
);
shape.lineTo(x + shapeWidth, y + shapeHeight - corner);
shape.quadraticCurveTo(
x + shapeWidth,
y + shapeHeight,
x + shapeWidth - corner,
y + shapeHeight
);
shape.lineTo(x + corner, y + shapeHeight);
shape.quadraticCurveTo(
x,
y + shapeHeight,
x,
y + shapeHeight - corner
);
shape.lineTo(x, y + corner);
shape.quadraticCurveTo(x, y, x + corner, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.001, depth - bevel * 2),
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: bevel,
bevelThickness: bevel,
curveSegments: 10
});
geometry.center();
return addMesh(parent, geometry, mat, position);
}
// Ground
const ground = addMesh(
scene,
new THREE.PlaneGeometry(24, 20),
materials.ground,
new THREE.Vector3(0, -0.015, 0)
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
const guideObjects = [];
function makeChair(seatHeight, seatMaterial) {
const chair = new THREE.Group();
const seatThickness = 0.075;
roundedPrism(
chair,
0.64,
seatThickness,
0.56,
0.045,
seatMaterial,
new THREE.Vector3(0, seatHeight - seatThickness / 2, -0.04)
);
// Four tapered-looking legs made from simple solid cylinders.
const legX = 0.245;
const legZ = 0.205;
for (const side of [-1, 1]) {
for (const front of [-1, 1]) {
const bottom = new THREE.Vector3(
side * legX,
0.025,
-0.04 + front * legZ
);
const top = new THREE.Vector3(
side * (legX - 0.015),
seatHeight - 0.055,
-0.04 + front * (legZ - 0.012)
);
rod(chair, bottom, top, 0.027, materials.frame);
sphere(chair, bottom, 0.031, materials.rubber);
}
}
// Rear uprights and slightly reclined back.
for (const side of [-1, 1]) {
rod(
chair,
new THREE.Vector3(side * 0.245, seatHeight - 0.08, -0.24),
new THREE.Vector3(side * 0.245, seatHeight + 0.49, -0.34),
0.026,
materials.frame
);
}
const back = roundedPrism(
chair,
0.64,
0.43,
0.085,
0.052,
seatMaterial,
new THREE.Vector3(0, seatHeight + 0.265, -0.325)
);
back.rotation.x = -0.105;
// Under-seat cross brace.
rod(
chair,
new THREE.Vector3(-0.245, seatHeight - 0.13, -0.235),
new THREE.Vector3(0.245, seatHeight - 0.13, -0.235),
0.018,
materials.frame
);
return chair;
}
// Two-link inverse kinematics in the sagittal YZ plane.
// It places the knee forward while both feet remain on the floor.
function solveKnee(hip, ankle, upperLength, lowerLength) {
const delta = ankle.clone().sub(hip);
const distance = delta.length();
const direction = delta.clone().normalize();
const along =
(upperLength * upperLength -
lowerLength * lowerLength +
distance * distance) /
(2 * distance);
const perpendicularDistance = Math.sqrt(
Math.max(0, upperLength * upperLength - along * along)
);
// Positive Z component keeps the knee in front of the hip.
const perpendicular = new THREE.Vector3(
0,
direction.z,
-direction.y
).normalize();
return hip
.clone()
.add(direction.multiplyScalar(along))
.add(perpendicular.multiplyScalar(perpendicularDistance));
}
function makeCharacter(seatHeight, poseIndex) {
const character = new THREE.Group();
const upperLegLength = 0.41;
const lowerLegLength = 0.43;
const hipY = seatHeight + 0.12;
const hipZ = -0.025;
const ankleY = 0.10;
const ankleZ = 0.47;
// Pelvis
sphere(
character,
new THREE.Vector3(0, hipY, hipZ),
0.15,
materials.pants,
[1.08, 0.78, 0.8]
);
// Torso: the lean is changed slightly between neutral arm poses.
const shoulderZ = [0.02, 0.105, -0.005][poseIndex];
const shoulderY = hipY + 0.47;
rod(
character,
new THREE.Vector3(0, hipY + 0.025, hipZ),
new THREE.Vector3(0, shoulderY, shoulderZ),
0.195,
materials.shirt,
0.17
);
sphere(
character,
new THREE.Vector3(0, shoulderY - 0.015, shoulderZ),
0.18,
materials.shirt,
[1.05, 0.8, 0.78]
);
// Head and face
const headY = shoulderY + 0.205;
const headZ = shoulderZ + 0.012;
sphere(
character,
new THREE.Vector3(0, headY, headZ),
0.13,
materials.skin
);
const hair = addMesh(
character,
new THREE.SphereGeometry(
0.139,
28,
14,
0,
Math.PI * 2,
0,
Math.PI * 0.53
),
materials.hair,
new THREE.Vector3(0, headY + 0.006, headZ - 0.008)
);
hair.castShadow = true;
sphere(
character,
new THREE.Vector3(-0.127, headY - 0.012, headZ),
0.027,
materials.skin
);
sphere(
character,
new THREE.Vector3(0.127, headY - 0.012, headZ),
0.027,
materials.skin
);
for (const side of [-1, 1]) {
sphere(
character,
new THREE.Vector3(
side * 0.043,
headY + 0.018,
headZ + 0.121
),
0.012,
materials.eyes
);
}
sphere(
character,
new THREE.Vector3(0, headY - 0.022, headZ + 0.127),
0.018,
materials.skin
);
// Legs: identical segment lengths, changing knee angle by seat height.
const knees = [];
for (const side of [-1, 1]) {
const hip = new THREE.Vector3(
side * 0.105,
hipY,
hipZ
);
const ankle = new THREE.Vector3(
side * 0.12,
ankleY,
ankleZ
);
const knee = solveKnee(
hip,
ankle,
upperLegLength,
lowerLegLength
);
knees.push(knee);
rod(
character,
hip,
knee,
0.091,
materials.pants,
0.083
);
sphere(character, knee, 0.079, materials.pants);
rod(
character,
knee,
ankle,
0.073,
materials.pants,
0.057
);
sphere(character, ankle, 0.057, materials.pants);
roundedPrism(
character,
0.155,
0.095,
0.27,
0.035,
materials.shoes,
new THREE.Vector3(
side * 0.12,
0.052,
ankleZ + 0.055
)
);
}
// Arms: neutral pose changes only; no pose is presented as preferable.
const leftKnee = knees[0];
const rightKnee = knees[1];
let leftElbow;
let leftHand;
let rightElbow;
let rightHand;
if (poseIndex === 0) {
leftElbow = new THREE.Vector3(-0.27, shoulderY - 0.23, shoulderZ + 0.07);
leftHand = new THREE.Vector3(-0.14, hipY + 0.16, 0.22);
rightElbow = new THREE.Vector3(0.27, shoulderY - 0.23, shoulderZ + 0.07);
rightHand = new THREE.Vector3(0.14, hipY + 0.16, 0.22);
} else if (poseIndex === 1) {
leftElbow = new THREE.Vector3(-0.28, shoulderY - 0.28, 0.22);
leftHand = new THREE.Vector3(-0.12, leftKnee.y + 0.035, leftKnee.z + 0.025);
rightElbow = new THREE.Vector3(0.28, shoulderY - 0.28, 0.22);
rightHand = new THREE.Vector3(0.12, rightKnee.y + 0.035, rightKnee.z + 0.025);
} else {
leftElbow = new THREE.Vector3(-0.27, shoulderY - 0.22, 0.01);
leftHand = new THREE.Vector3(-0.22, seatHeight + 0.10, 0.18);
rightElbow = new THREE.Vector3(0.28, shoulderY - 0.22, 0.04);
rightHand = new THREE.Vector3(0.14, hipY + 0.17, 0.23);
}
const arms = [
{
side: -1,
shoulder: new THREE.Vector3(-0.17, shoulderY - 0.025, shoulderZ),
elbow: leftElbow,
hand: leftHand
},
{
side: 1,
shoulder: new THREE.Vector3(0.17, shoulderY - 0.025, shoulderZ),
elbow: rightElbow,
hand: rightHand
}
];
for (const arm of arms) {
sphere(character, arm.shoulder, 0.072, materials.shirt);
rod(
character,
arm.shoulder,
arm.elbow,
0.062,
materials.shirt,
0.052
);
sphere(character, arm.elbow, 0.052, materials.skin);
rod(
character,
arm.elbow,
arm.hand,
0.048,
materials.skin,
0.039
);
sphere(character, arm.hand, 0.052, materials.skin, [0.9, 1, 1.1]);
}
return character;
}
function makeMeasurementGuides(seatHeight, hipY) {
const group = new THREE.Group();
const guideX = 0.44;
const guideZ = -0.37;
// Main seat-height ruler.
rod(
group,
new THREE.Vector3(guideX, 0.02, guideZ),
new THREE.Vector3(guideX, seatHeight, guideZ),
0.0055,
materials.guide
);
// End caps.
rod(
group,
new THREE.Vector3(guideX - 0.065, 0.02, guideZ),
new THREE.Vector3(guideX + 0.065, 0.02, guideZ),
0.0055,
materials.guide
);
rod(
group,
new THREE.Vector3(guideX - 0.065, seatHeight, guideZ),
new THREE.Vector3(guideX + 0.065, seatHeight, guideZ),
0.0055,
materials.guide
);
// 10 cm ruler divisions.
for (let y = 0.1; y < seatHeight - 0.04; y += 0.1) {
rod(
group,
new THREE.Vector3(guideX - 0.025, y, guideZ),
new THREE.Vector3(guideX + 0.025, y, guideZ),
0.004,
materials.guide
);
}
// Dashed model reference for seat-top-to-pelvis-center distance.
const gapGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.30, seatHeight, -0.02),
new THREE.Vector3(-0.30, hipY, -0.02)
]);
const gapLine = new THREE.Line(
gapGeometry,
new THREE.LineDashedMaterial({
color: 0x53625e,
dashSize: 0.025,
gapSize: 0.018,
transparent: true,
opacity: 0.8
})
);
gapLine.computeLineDistances();
group.add(gapLine);
guideObjects.push(group);
return group;
}
const seatHeights = [0.42, 0.48, 0.54];
const stationX = [-1.55, 0, 1.55];
const chairMaterials = [
materials.lowChair,
materials.middleChair,
materials.highChair
];
const poseNames = [
"Pose A · relaxed arms",
"Pose B · arms forward",
"Pose C · mixed arm pose"
];
const stationLabels = [];
stationX.forEach((x, index) => {
const station = new THREE.Group();
station.position.x = x;
scene.add(station);
const rug = addMesh(
station,
new THREE.CylinderGeometry(0.77, 0.77, 0.026, 64),
materials.mat,
new THREE.Vector3(0, 0.002, 0.02)
);
rug.castShadow = false;
const chair = makeChair(seatHeights[index], chairMaterials[index]);
station.add(chair);
const character = makeCharacter(seatHeights[index], index);
station.add(character);
const guide = makeMeasurementGuides(
seatHeights[index],
seatHeights[index] + 0.12
);
station.add(guide);
const tag = document.createElement("div");
tag.className = "station-tag";
tag.innerHTML = `
<div class="tag-top">
<span class="swatch"></span>
Seat study ${String.fromCharCode(65 + index)}
</div>
<strong>${Math.round(seatHeights[index] * 100)} cm seat</strong>
<small>${poseNames[index]}</small>
`;
tag.querySelector(".swatch").style.background =
`#${chairMaterials[index].color.getHexString()}`;
labelLayer.appendChild(tag);
const measureTag = document.createElement("div");
measureTag.className = "measure-tag";
measureTag.textContent = "Seat top";
labelLayer.appendChild(measureTag);
stationLabels.push({
tag,
measureTag,
stationPoint: new THREE.Vector3(x, 0.035, 0.82),
measurePoint: new THREE.Vector3(
x + 0.47,
seatHeights[index] * 0.52,
-0.35
)
});
});
// Camera and directly implemented controls
const orbit = {
theta: 0.31,
phi: 1.19,
radius: 7.4
};
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
const desiredTarget = cameraTarget.clone();
let desiredRadius = orbit.radius;
let focusedStation = null;
function overviewRadius() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 0.8 ? 10.7 : 7.4;
}
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
function resetView() {
focusedStation = null;
desiredTarget.set(0, 0.72, 0);
desiredRadius = overviewRadius();
updateFocusButtons();
}
const pointers = new Map();
let lastPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
document.body.classList.add("dragging");
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.62,
1.47
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0 && distance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (lastPinchDistance / distance),
4.25,
13
);
desiredRadius = orbit.radius;
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
if (pointers.size === 0) {
document.body.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
4.25,
13
);
desiredRadius = orbit.radius;
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
const focusButtons = [
...document.querySelectorAll("[data-focus]")
];
function updateFocusButtons() {
focusButtons.forEach((button) => {
const value = button.dataset.focus;
const isActive =
value === "overview"
? focusedStation === null
: Number(value) === focusedStation;
button.classList.toggle("active", isActive);
});
}
focusButtons.forEach((button) => {
button.addEventListener("click", () => {
const value = button.dataset.focus;
if (value === "overview") {
resetView();
return;
}
focusedStation = Number(value);
desiredTarget.set(focusedStation, 0.72, 0.02);
desiredRadius =
window.innerWidth / window.innerHeight < 0.8 ? 7.0 : 4.75;
updateFocusButtons();
});
});
const guidesCheckbox = document.getElementById("guides");
guidesCheckbox.addEventListener("change", () => {
for (const object of guideObjects) {
object.visible = guidesCheckbox.checked;
}
for (const label of stationLabels) {
label.measureTag.style.visibility = guidesCheckbox.checked
? "visible"
: "hidden";
}
});
// Project HTML labels from their 3D anchor points.
const projected = new THREE.Vector3();
function placeLabel(element, worldPoint, offsetY = 0) {
projected.copy(worldPoint).project(camera);
const inFront =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
element.style.opacity = inFront ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
if (focusedStation === null) {
desiredRadius = overviewRadius();
}
}
window.addEventListener("resize", onResize);
onResize();
desiredRadius = overviewRadius();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
cameraTarget.lerp(desiredTarget, 0.085);
orbit.radius += (desiredRadius - orbit.radius) * 0.085;
updateCamera();
camera.updateMatrixWorld();
for (const label of stationLabels) {
placeLabel(label.tag, label.stationPoint, 15);
placeLabel(label.measureTag, label.measurePoint);
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
}
}
animate();
</script>
</body>
</html>
```