Prompt specification
Build or customize the Three.js 3D scene "Toy seesaw pivot assembly" 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: Toy seesaw pivot assembly
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/toy-seesaw-pivot-assembly-x0365
Scene Description Prompt:
Toy seesaw pivot assembly. Model a short board on a central rounded pivot with two seated toy figures; expose the support contact and mark equal distances to each seat. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (toy-seesaw-pivot-assembly-x0365):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Toy Seesaw — Pivot Assembly</title>
<style>
:root {
color-scheme: light;
--ink: #203047;
--muted: #66758a;
--panel: rgba(255, 255, 255, 0.88);
--teal: #25b7a5;
--gold: #efb84f;
--coral: #ed705f;
--blue: #518bd8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
background:
radial-gradient(circle at 50% 30%, #ffffff 0, #eef3f8 58%, #e3eaf2 100%);
color: var(--ink);
}
#app,
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title-panel {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(37, 53, 76, 0.13);
backdrop-filter: blur(16px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(37, 183, 165, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 32px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.toolbar {
position: fixed;
z-index: 20;
right: 24px;
top: 24px;
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
border: 1px solid rgba(32, 48, 71, 0.12);
border-radius: 13px;
padding: 11px 15px;
background: rgba(255, 255, 255, 0.92);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 24px rgba(37, 53, 76, 0.1);
backdrop-filter: blur(12px);
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fff;
}
button:focus-visible {
outline: 3px solid rgba(37, 183, 165, 0.35);
outline-offset: 2px;
}
.hint {
bottom: 24px;
left: 24px;
padding: 11px 15px;
border-radius: 14px;
background: rgba(255, 255, 255, 0.82);
color: var(--muted);
font-size: 12px;
box-shadow: 0 10px 30px rgba(37, 53, 76, 0.08);
backdrop-filter: blur(12px);
}
.hint strong {
color: var(--ink);
}
.legend {
right: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 9px;
max-width: min(460px, calc(100vw - 48px));
}
.chip {
display: flex;
align-items: center;
gap: 7px;
padding: 9px 12px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.86);
color: var(--muted);
font-size: 11px;
font-weight: 650;
box-shadow: 0 8px 24px rgba(37, 53, 76, 0.08);
backdrop-filter: blur(12px);
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
}
@media (max-width: 700px) {
.title-panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.subtitle {
max-width: 270px;
}
.toolbar {
top: auto;
right: 14px;
bottom: 54px;
flex-direction: column;
}
button {
padding: 10px 13px;
}
.hint {
left: 14px;
bottom: 14px;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section class="panel title-panel">
<div class="eyebrow">Mechanical study</div>
<h1>Toy seesaw pivot</h1>
<p class="subtitle">
A level solid-model assembly with an exposed support contact and
matched pivot-to-seat distances.
</p>
</section>
<nav class="toolbar" aria-label="Model controls">
<button id="focusButton" type="button">Inspect contact</button>
<button id="resetButton" type="button">Reset view</button>
</nav>
<div class="panel hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom
</div>
<div class="panel legend" aria-label="Model legend">
<div class="chip"><span class="swatch" style="background:#efb84f"></span>Board</div>
<div class="chip"><span class="swatch" style="background:#25b7a5"></span>Rounded pivot</div>
<div class="chip"><span class="swatch" style="background:#85e6b8"></span>Contact zone</div>
<div class="chip"><span class="swatch" style="background:#ed705f"></span>Figure A</div>
<div class="chip"><span class="swatch" style="background:#518bd8"></span>Figure B</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene and renderer
// ------------------------------------------------------------
const app = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
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;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xeef3f8, 18, 38);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xffffff, 0xaeb9c8, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff6df, 4.1);
keyLight.position.set(6, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d9ff, 1.5);
fillLight.position.set(-6, 5, 4);
scene.add(fillLight);
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
// Horizontal slab: width along X, depth along Z, thickness along Y.
function roundedSlabGeometry(width, depth, thickness, radius) {
const shape = roundedRectShape(width, depth, radius);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: thickness,
bevelEnabled: false,
curveSegments: 32
});
geometry.translate(0, 0, -thickness / 2);
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
// Upright solid with rounded front edges.
function roundedBoxGeometry(width, height, depth, radius) {
const shape = roundedRectShape(width, height, radius);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: 24
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
function addMesh(parent, geometry, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCapsuleBetween(
parent,
start,
end,
radius,
material,
radialSegments = 14
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const cylinderLength = Math.max(0.01, length - radius * 2);
const geometry = new THREE.CapsuleGeometry(
radius,
cylinderLength,
7,
radialSegments
);
const mesh = new THREE.Mesh(geometry, 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 makeLabel(text, subtitle, accent = "#25b7a5", width = 2.3) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 190;
const ctx = canvas.getContext("2d");
const r = 28;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.moveTo(r, 5);
ctx.lineTo(canvas.width - r, 5);
ctx.quadraticCurveTo(
canvas.width - 5, 5, canvas.width - 5, 5 + r
);
ctx.lineTo(canvas.width - 5, canvas.height - 5 - r);
ctx.quadraticCurveTo(
canvas.width - 5, canvas.height - 5,
canvas.width - r, canvas.height - 5
);
ctx.lineTo(r, canvas.height - 5);
ctx.quadraticCurveTo(
5, canvas.height - 5, 5, canvas.height - 5 - r
);
ctx.lineTo(5, 5 + r);
ctx.quadraticCurveTo(5, 5, r, 5);
ctx.closePath();
ctx.fillStyle = "rgba(255,255,255,0.96)";
ctx.fill();
ctx.strokeStyle = "rgba(32,48,71,0.12)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(18, 18, 11, canvas.height - 36);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#203047";
ctx.font = "800 43px system-ui, sans-serif";
ctx.fillText(text, canvas.width / 2 + 7, 76);
ctx.fillStyle = "#69778a";
ctx.font = "600 27px system-ui, sans-serif";
ctx.fillText(subtitle, canvas.width / 2 + 7, 132);
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 * 190 / 640, 1);
sprite.renderOrder = 100;
return sprite;
}
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
board: new THREE.MeshStandardMaterial({
color: 0xefb84f,
roughness: 0.64,
metalness: 0.02,
transparent: true
}),
boardEdge: new THREE.MeshStandardMaterial({
color: 0xd5952c,
roughness: 0.72
}),
pivot: new THREE.MeshStandardMaterial({
color: 0x25b7a5,
roughness: 0.42,
metalness: 0.08
}),
pivotLight: new THREE.MeshStandardMaterial({
color: 0x69d8c9,
roughness: 0.38
}),
support: new THREE.MeshStandardMaterial({
color: 0x2d4261,
roughness: 0.68,
transparent: true
}),
base: new THREE.MeshStandardMaterial({
color: 0x263b58,
roughness: 0.68
}),
baseInset: new THREE.MeshStandardMaterial({
color: 0x3a5274,
roughness: 0.72
}),
seatA: new THREE.MeshStandardMaterial({
color: 0xed705f,
roughness: 0.72
}),
seatB: new THREE.MeshStandardMaterial({
color: 0x518bd8,
roughness: 0.72
}),
cream: new THREE.MeshStandardMaterial({
color: 0xfff2d5,
roughness: 0.76
}),
wood: new THREE.MeshStandardMaterial({
color: 0xf0c69f,
roughness: 0.82
}),
hair: new THREE.MeshStandardMaterial({
color: 0x59433b,
roughness: 0.9
}),
trousers: new THREE.MeshStandardMaterial({
color: 0x34425a,
roughness: 0.85
}),
shoes: new THREE.MeshStandardMaterial({
color: 0xf7f1e7,
roughness: 0.85
}),
eyes: new THREE.MeshBasicMaterial({ color: 0x263347 }),
contact: new THREE.MeshStandardMaterial({
color: 0x85e6b8,
emissive: 0x2e9b72,
emissiveIntensity: 0.55,
roughness: 0.35
})
};
// ------------------------------------------------------------
// Ground, base and supports
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(200, 200),
new THREE.MeshStandardMaterial({
color: 0xe8edf4,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
const assembly = new THREE.Group();
scene.add(assembly);
addMesh(
assembly,
roundedSlabGeometry(3.25, 2.72, 0.28, 0.28),
materials.base,
[0, 0.14, 0]
);
addMesh(
assembly,
roundedSlabGeometry(2.55, 2.08, 0.08, 0.22),
materials.baseInset,
[0, 0.31, 0]
);
const supportGeometry = roundedBoxGeometry(0.54, 1.28, 0.28, 0.16);
const rearSupport = addMesh(
assembly,
supportGeometry,
materials.support,
[0, 0.96, -1.04]
);
const frontSupportMaterial = materials.support.clone();
const frontSupport = addMesh(
assembly,
supportGeometry,
frontSupportMaterial,
[0, 0.96, 1.04]
);
// Central rounded pivot barrel. Its axis runs front-to-back.
const pivot = new THREE.Mesh(
new THREE.CapsuleGeometry(0.72, 0.36, 10, 32),
materials.pivot
);
pivot.position.set(0, 1.45, 0);
pivot.rotation.x = Math.PI / 2;
pivot.castShadow = true;
pivot.receiveShadow = true;
assembly.add(pivot);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.15, 2.42, 24),
materials.cream
);
axle.position.set(0, 1.45, 0);
axle.rotation.x = Math.PI / 2;
axle.castShadow = true;
assembly.add(axle);
// ------------------------------------------------------------
// Board with central inspection aperture
// ------------------------------------------------------------
const boardWidth = 7.2;
const boardDepth = 2.25;
const boardThickness = 0.34;
const boardY = 2.25;
const boardTop = boardY + boardThickness / 2;
const boardBottom = boardY - boardThickness / 2;
const boardShape = roundedRectShape(boardWidth, boardDepth, 0.34);
const inspectionHole = new THREE.Path();
inspectionHole.absarc(0, 0, 0.62, 0, Math.PI * 2, true);
boardShape.holes.push(inspectionHole);
const boardGeometry = new THREE.ExtrudeGeometry(boardShape, {
depth: boardThickness,
bevelEnabled: false,
curveSegments: 48
});
boardGeometry.translate(0, 0, -boardThickness / 2);
boardGeometry.rotateX(-Math.PI / 2);
boardGeometry.computeVertexNormals();
const board = new THREE.Mesh(boardGeometry, materials.board);
board.position.y = boardY;
board.castShadow = true;
board.receiveShadow = true;
assembly.add(board);
const apertureRim = new THREE.Mesh(
new THREE.TorusGeometry(0.62, 0.035, 12, 72),
materials.boardEdge
);
apertureRim.rotation.x = Math.PI / 2;
apertureRim.position.y = boardY;
apertureRim.castShadow = true;
assembly.add(apertureRim);
// ------------------------------------------------------------
// Seats and seated toy figures
// ------------------------------------------------------------
const seatDistance = 2.25;
function addSeat(x, seatMaterial) {
const seatGroup = new THREE.Group();
seatGroup.position.x = x;
assembly.add(seatGroup);
addMesh(
seatGroup,
roundedSlabGeometry(0.98, 0.86, 0.16, 0.16),
seatMaterial,
[0, boardTop + 0.08, 0]
);
addMesh(
seatGroup,
roundedBoxGeometry(0.96, 0.55, 0.14, 0.15),
seatMaterial,
[0, boardTop + 0.42, -0.43]
);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.51, 0.024, 10, 64),
materials.cream
);
ring.rotation.x = Math.PI / 2;
ring.position.set(0, boardTop + 0.018, 0);
ring.castShadow = true;
seatGroup.add(ring);
const boltGeometry = new THREE.SphereGeometry(0.047, 16, 10);
for (const bx of [-0.37, 0.37]) {
for (const bz of [-0.27, 0.27]) {
addMesh(
seatGroup,
boltGeometry,
materials.cream,
[bx, boardTop + 0.17, bz]
);
}
}
}
function addFigure(x, shirtMaterial, variant = 0) {
const figure = new THREE.Group();
figure.position.set(x, boardTop + 0.16, 0);
assembly.add(figure);
// Pelvis and torso.
const pelvis = addMesh(
figure,
new THREE.SphereGeometry(0.38, 28, 18),
shirtMaterial,
[0, 0.16, 0]
);
pelvis.scale.set(1.12, 0.67, 0.86);
const torso = new THREE.Mesh(
new THREE.CapsuleGeometry(0.34, 0.38, 8, 24),
shirtMaterial
);
torso.position.set(0, 0.68, 0);
torso.castShadow = true;
figure.add(torso);
// Head and hair cap.
const head = addMesh(
figure,
new THREE.SphereGeometry(0.37, 32, 22),
materials.wood,
[0, 1.4, 0]
);
head.scale.set(0.96, 1, 0.94);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(
0.385,
32,
20,
0,
Math.PI * 2,
0,
1.10
),
materials.hair
);
hair.position.set(0, 1.4, -0.012);
hair.castShadow = true;
figure.add(hair);
// Face.
for (const ex of [-0.105, 0.105]) {
addMesh(
figure,
new THREE.SphereGeometry(0.032, 14, 10),
materials.eyes,
[ex, 1.405, 0.331]
);
}
addMesh(
figure,
new THREE.SphereGeometry(0.055, 16, 10),
materials.wood,
[0, 1.32, 0.363]
);
const smilePoints = [
new THREE.Vector3(-0.075, 1.235, 0.337),
new THREE.Vector3(0, 1.205, 0.347),
new THREE.Vector3(0.075, 1.235, 0.337)
];
const smile = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(smilePoints),
new THREE.LineBasicMaterial({ color: 0x8a5f4c })
);
figure.add(smile);
// Arms.
const leftShoulder = [-0.31, 0.97, 0];
const leftElbow = [-0.5, 0.68, 0.12];
const leftHand = [-0.4, 0.46, 0.35];
const rightShoulder = [0.31, 0.97, 0];
const rightElbow = [0.5, 0.68, 0.12];
const rightHand = [0.4, 0.46, 0.35];
makeCapsuleBetween(figure, leftShoulder, leftElbow, 0.095, shirtMaterial);
makeCapsuleBetween(figure, leftElbow, leftHand, 0.09, shirtMaterial);
makeCapsuleBetween(figure, rightShoulder, rightElbow, 0.095, shirtMaterial);
makeCapsuleBetween(figure, rightElbow, rightHand, 0.09, shirtMaterial);
addMesh(
figure,
new THREE.SphereGeometry(0.105, 18, 12),
materials.wood,
leftHand
);
addMesh(
figure,
new THREE.SphereGeometry(0.105, 18, 12),
materials.wood,
rightHand
);
// Bent seated legs and shoes.
for (const side of [-1, 1]) {
const hip = [side * 0.2, 0.17, 0.04];
const knee = [
side * 0.26,
0.12,
0.51 + (variant === 1 && side === 1 ? 0.035 : 0)
];
const ankle = [
side * 0.28,
-0.015,
0.72 + (variant === 1 && side === 1 ? 0.035 : 0)
];
makeCapsuleBetween(figure, hip, knee, 0.13, materials.trousers);
makeCapsuleBetween(figure, knee, ankle, 0.115, materials.trousers);
const shoe = addMesh(
figure,
new THREE.SphereGeometry(0.2, 20, 14),
materials.shoes,
[side * 0.28, -0.035, ankle[2] + 0.08]
);
shoe.scale.set(0.88, 0.57, 1.22);
}
}
addSeat(-seatDistance, materials.seatA);
addSeat(seatDistance, materials.seatB);
addFigure(-seatDistance, materials.seatA, 0);
addFigure(seatDistance, materials.seatB, 1);
// ------------------------------------------------------------
// Exposed support contact
// ------------------------------------------------------------
const contactMarker = new THREE.Group();
assembly.add(contactMarker);
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.035, 12, 56),
materials.contact
);
contactRing.rotation.x = Math.PI / 2;
contactRing.position.set(0, 2.18, 0);
contactMarker.add(contactRing);
const contactDot = addMesh(
contactMarker,
new THREE.SphereGeometry(0.095, 20, 14),
materials.contact,
[0, 2.18, 0]
);
contactDot.castShadow = false;
const contactLeader = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 2.18, 0.12),
new THREE.Vector3(0, 2.58, 0.72),
new THREE.Vector3(0, 2.82, 1.30)
]),
new THREE.LineDashedMaterial({
color: 0x25a98f,
dashSize: 0.08,
gapSize: 0.055,
transparent: true,
opacity: 0.9
})
);
contactLeader.computeLineDistances();
contactMarker.add(contactLeader);
const contactLabel = makeLabel(
"SUPPORT CONTACT",
"pivot meets board",
"#25b7a5",
2.55
);
contactLabel.position.set(0, 3.0, 1.31);
contactMarker.add(contactLabel);
// ------------------------------------------------------------
// Equal-distance dimension marks
// ------------------------------------------------------------
const measurements = new THREE.Group();
assembly.add(measurements);
const dimensionY = 2.51;
const dimensionZ = 1.48;
const dimensionColor = 0x27374d;
const rightArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(0, dimensionY, dimensionZ),
seatDistance,
dimensionColor,
0.18,
0.11
);
const leftArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(0, dimensionY, dimensionZ),
seatDistance,
dimensionColor,
0.18,
0.11
);
measurements.add(rightArrow, leftArrow);
const centerTick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, dimensionY - 0.12, dimensionZ),
new THREE.Vector3(0, dimensionY + 0.12, dimensionZ)
]),
new THREE.LineBasicMaterial({ color: dimensionColor })
);
measurements.add(centerTick);
for (const sign of [-1, 1]) {
const x = sign * seatDistance;
const tick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, dimensionY - 0.13, dimensionZ),
new THREE.Vector3(x, dimensionY + 0.13, dimensionZ)
]),
new THREE.LineBasicMaterial({ color: dimensionColor })
);
measurements.add(tick);
// Dashed leader links the dimension endpoint to its actual seat.
const seatLeader = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, boardTop + 0.03, 0),
new THREE.Vector3(x, dimensionY, dimensionZ)
]),
new THREE.LineDashedMaterial({
color: dimensionColor,
dashSize: 0.075,
gapSize: 0.055,
transparent: true,
opacity: 0.72
})
);
seatLeader.computeLineDistances();
measurements.add(seatLeader);
const label = makeLabel(
"d = 2.25",
"equal from pivot",
"#efb84f",
1.72
);
label.position.set(sign * 1.125, 2.78, dimensionZ);
measurements.add(label);
}
// ------------------------------------------------------------
// Direct camera controls — no addons required
// ------------------------------------------------------------
const cameraState = {
radius: 11.6,
theta: 0.48,
phi: 1.27,
target: new THREE.Vector3(0, 1.9, 0)
};
let cameraGoal = null;
let focusAmount = 0;
let focusGoal = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function setCameraGoal(goal) {
cameraGoal = {
radius: goal.radius,
theta: goal.theta,
phi: goal.phi,
target: goal.target.clone()
};
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraGoal = null;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.50
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.1,
18
);
},
{ passive: false }
);
const resetButton = document.querySelector("#resetButton");
const focusButton = document.querySelector("#focusButton");
resetButton.addEventListener("click", () => {
focusGoal = 0;
focusButton.textContent = "Inspect contact";
setCameraGoal({
radius: 11.6,
theta: 0.48,
phi: 1.27,
target: new THREE.Vector3(0, 1.9, 0)
});
});
focusButton.addEventListener("click", () => {
if (focusGoal === 0) {
focusGoal = 1;
focusButton.textContent = "Show full assembly";
setCameraGoal({
radius: 4.8,
theta: 0.13,
phi: 1.47,
target: new THREE.Vector3(0, 2.03, 0)
});
} else {
focusGoal = 0;
focusButton.textContent = "Inspect contact";
setCameraGoal({
radius: 11.6,
theta: 0.48,
phi: 1.27,
target: new THREE.Vector3(0, 1.9, 0)
});
}
});
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const ease = 1 - Math.exp(-dt * 5.2);
if (cameraGoal) {
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius, cameraGoal.radius, ease
);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta, cameraGoal.theta, ease
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi, cameraGoal.phi, ease
);
cameraState.target.lerp(cameraGoal.target, ease);
}
focusAmount = THREE.MathUtils.lerp(
focusAmount, focusGoal, ease
);
// Inspection mode makes the board and front support translucent.
materials.board.opacity = 1 - focusAmount * 0.76;
materials.board.depthWrite = focusAmount < 0.08;
frontSupportMaterial.opacity = 1 - focusAmount * 0.9;
frontSupportMaterial.depthWrite = focusAmount < 0.08;
contactRing.material.emissiveIntensity =
0.45 + Math.sin(clock.elapsedTime * 2.5) * 0.12;
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```