Prompt specification
Build or customize the Three.js 3D scene "Clamp jaw padding 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: Clamp jaw padding comparison
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/clamp-jaw-padding-comparison-x0253
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Show a clamp contacting two soft wood samples, one with a broad pad; highlight contact regions and make the pad's thickness visible between jaw and wood.
Working Three.js Starter (clamp-jaw-padding-comparison-x0253):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Soft Contact Clamp — Three.js</title>
<style>
:root {
--ink: #183034;
--muted: #526669;
--paper: rgba(248, 246, 238, 0.88);
--orange: #ef713b;
--cyan: #43e1c2;
--gold: #ffc45d;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce3df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: clamp(18px, 4vw, 42px);
left: clamp(18px, 4vw, 48px);
max-width: 460px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: .18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 3px;
border-radius: 99px;
background: var(--orange);
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 54px);
line-height: .98;
letter-spacing: -.055em;
font-weight: 820;
}
.subtitle {
margin: 12px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
position: absolute;
left: clamp(18px, 4vw, 48px);
bottom: clamp(18px, 4vw, 42px);
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.chip {
display: flex;
align-items: center;
gap: 8px;
min-height: 34px;
padding: 7px 11px;
border: 1px solid rgba(24, 48, 52, .10);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 8px 24px rgba(34, 55, 57, .08);
backdrop-filter: blur(12px);
color: #40575a;
font-size: 10px;
font-weight: 750;
letter-spacing: .09em;
text-transform: uppercase;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 3px rgba(239, 113, 59, .13);
}
.dot.cyan {
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(67, 225, 194, .16);
}
.dot.gold {
background: var(--gold);
box-shadow: 0 0 0 3px rgba(255, 196, 93, .16);
}
.controls {
position: absolute;
right: clamp(18px, 4vw, 48px);
bottom: clamp(18px, 4vw, 42px);
display: flex;
align-items: center;
gap: 12px;
}
.hint {
color: rgba(32, 55, 58, .62);
font-size: 10px;
font-weight: 700;
letter-spacing: .09em;
text-transform: uppercase;
}
button {
pointer-events: auto;
border: 0;
border-radius: 999px;
padding: 10px 15px;
background: var(--ink);
color: #f8f6ee;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: .1em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 8px 22px rgba(20, 42, 45, .18);
transition: transform .18s ease, background .18s ease;
}
button:hover {
transform: translateY(-2px);
background: #27474b;
}
.callout {
position: absolute;
z-index: 3;
min-width: 145px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, .48);
border-radius: 12px;
background: rgba(248, 246, 238, .90);
box-shadow: 0 12px 34px rgba(31, 55, 57, .13);
backdrop-filter: blur(12px);
transform: translate(-50%, -100%);
pointer-events: none;
}
.callout strong {
display: block;
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: .12em;
text-transform: uppercase;
}
.callout span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: visible;
}
#leaders line {
stroke-width: 1.25;
stroke-dasharray: 3 3;
}
#leaders circle {
stroke: white;
stroke-width: 1.5;
}
@media (max-width: 720px) {
.subtitle { display: none; }
.hint { display: none; }
.callout { display: none; }
#leaders { display: none; }
.title-block { max-width: 300px; }
.legend { max-width: calc(100vw - 36px); }
}
</style>
</head>
<body>
<div id="scene"></div>
<svg id="leaders" aria-hidden="true">
<line id="pad-leader" stroke="#279f8a"></line>
<circle id="pad-dot" r="4" fill="#43e1c2"></circle>
<line id="face-leader" stroke="#b87827"></line>
<circle id="face-dot" r="4" fill="#ffc45d"></circle>
</svg>
<div class="hud">
<section class="title-block">
<div class="eyebrow">Material interface study</div>
<h1>Soft Contact<br />Clamp</h1>
<p class="subtitle">
Two softwood samples held between opposing jaws. The right interface uses
a broad 12 mm elastomer pad; contact pressure is highlighted in cyan.
</p>
</section>
<div class="legend">
<div class="chip"><span class="dot cyan"></span>Broad pad contact</div>
<div class="chip"><span class="dot gold"></span>Direct steel face</div>
<div class="chip"><span class="dot"></span>Clamp frame</div>
</div>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
</div>
<div id="pad-label" class="callout">
<strong>Broad elastomer pad</strong>
<span>12 mm thickness · full-face support</span>
</div>
<div id="face-label" class="callout">
<strong>Direct contact face</strong>
<span>Localized pressure region</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneEl = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneEl.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce3df);
scene.fog = new THREE.Fog(0xdce3df, 13, 25);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0, 1.05, 0),
radius: 7.65,
theta: 0.34,
phi: 1.17
};
function updateCamera() {
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);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xfff6e9, 0x61706d, 2.15));
const key = new THREE.DirectionalLight(0xfff1d6, 3.2);
key.position.set(5.5, 9, 6.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.00025;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9fe9e0, 1.25);
fill.position.set(-5, 4, 3);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xff9a67, 1.75);
rim.position.set(4, 5, -6);
scene.add(rim);
const contactLight = new THREE.PointLight(0x43e1c2, 2.6, 3.2, 2);
contactLight.position.set(1.75, 1.0, 1.25);
scene.add(contactLight);
const faceLight = new THREE.PointLight(0xffc45d, 1.35, 2.4, 2);
faceLight.position.set(-1.65, 0.9, 1.05);
scene.add(faceLight);
// Procedural wood textures
function seededRandom(seed) {
let s = seed >>> 0;
return () => {
s = (1664525 * s + 1013904223) >>> 0;
return s / 4294967296;
};
}
function makeWoodTexture(base, dark, light, seed) {
const random = seededRandom(seed);
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 0, 512);
gradient.addColorStop(0, light);
gradient.addColorStop(0.48, base);
gradient.addColorStop(1, dark);
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1024, 512);
for (let i = 0; i < 82; i++) {
const y = random() * 512;
const phase = random() * Math.PI * 2;
const amplitude = 2 + random() * 12;
const frequency = 0.004 + random() * 0.011;
ctx.beginPath();
for (let x = -20; x <= 1044; x += 10) {
const yy =
y +
Math.sin(x * frequency + phase) * amplitude +
Math.sin(x * frequency * 2.7 + phase * 0.6) * amplitude * 0.28;
if (x === -20) ctx.moveTo(x, yy);
else ctx.lineTo(x, yy);
}
const alpha = 0.035 + random() * 0.10;
ctx.strokeStyle = `rgba(65, 34, 15, ${alpha})`;
ctx.lineWidth = 0.6 + random() * 2.1;
ctx.stroke();
}
for (let i = 0; i < 4; i++) {
const x = 100 + random() * 824;
const y = 65 + random() * 380;
const rx = 22 + random() * 38;
const ry = 6 + random() * 13;
for (let ring = 0; ring < 6; ring++) {
ctx.beginPath();
ctx.ellipse(
x,
y,
rx + ring * 8,
ry + ring * 3.2,
-0.12,
0,
Math.PI * 2
);
ctx.strokeStyle = `rgba(78, 38, 16, ${0.13 - ring * 0.014})`;
ctx.lineWidth = 1.5;
ctx.stroke();
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.25, 1.5);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makePressureTexture(color) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.save();
ctx.translate(128, 128);
ctx.scale(0.72, 1);
const gradient = ctx.createRadialGradient(0, 0, 8, 0, 0, 122);
gradient.addColorStop(0, color.replace("ALPHA", "0.88"));
gradient.addColorStop(0.38, color.replace("ALPHA", "0.42"));
gradient.addColorStop(0.72, color.replace("ALPHA", "0.12"));
gradient.addColorStop(1, color.replace("ALPHA", "0"));
ctx.fillStyle = gradient;
ctx.fillRect(-150, -150, 300, 300);
ctx.restore();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const woodATexture = makeWoodTexture(
"#bf8650", "#80502d", "#d5a66c", 31
);
const woodBTexture = makeWoodTexture(
"#cb985f", "#8a572f", "#e2b879", 87
);
const materials = {
woodA: new THREE.MeshStandardMaterial({
map: woodATexture,
bumpMap: woodATexture,
bumpScale: 0.026,
roughness: 0.76,
metalness: 0.0,
color: 0xffffff
}),
woodB: new THREE.MeshStandardMaterial({
map: woodBTexture,
bumpMap: woodBTexture,
bumpScale: 0.024,
roughness: 0.73,
metalness: 0.0,
color: 0xffffff
}),
orange: new THREE.MeshStandardMaterial({
color: 0xef713b,
roughness: 0.37,
metalness: 0.38
}),
orangeDark: new THREE.MeshStandardMaterial({
color: 0xa94727,
roughness: 0.48,
metalness: 0.34
}),
steel: new THREE.MeshStandardMaterial({
color: 0x9baab0,
roughness: 0.27,
metalness: 0.86
}),
brightSteel: new THREE.MeshStandardMaterial({
color: 0xd8e0e1,
roughness: 0.2,
metalness: 0.9
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x174f50,
emissive: 0x073e38,
emissiveIntensity: 0.17,
roughness: 0.93,
metalness: 0.02
}),
rubberEdge: new THREE.MeshStandardMaterial({
color: 0x286b65,
emissive: 0x0b5147,
emissiveIntensity: 0.12,
roughness: 0.88
}),
floor: new THREE.MeshStandardMaterial({
color: 0xd6ddd7,
roughness: 0.94,
metalness: 0
}),
platform: new THREE.MeshStandardMaterial({
color: 0xe9e5d9,
roughness: 0.86,
metalness: 0
})
};
function roundedBox(width, height, depth, radius, material) {
const bs = Math.min(radius * 0.38, width * 0.08, height * 0.08);
const bt = Math.min(radius * 0.42, depth * 0.2);
const shapeWidth = Math.max(0.01, width - bs * 2);
const shapeHeight = Math.max(0.01, height - bs * 2);
const r = Math.max(0.01, Math.min(radius - bs * 0.35, shapeWidth / 2, shapeHeight / 2));
const shape = new THREE.Shape();
shape.moveTo(-shapeWidth / 2 + r, -shapeHeight / 2);
shape.lineTo(shapeWidth / 2 - r, -shapeHeight / 2);
shape.quadraticCurveTo(shapeWidth / 2, -shapeHeight / 2, shapeWidth / 2, -shapeHeight / 2 + r);
shape.lineTo(shapeWidth / 2, shapeHeight / 2 - r);
shape.quadraticCurveTo(shapeWidth / 2, shapeHeight / 2, shapeWidth / 2 - r, shapeHeight / 2);
shape.lineTo(-shapeWidth / 2 + r, shapeHeight / 2);
shape.quadraticCurveTo(-shapeWidth / 2, shapeHeight / 2, -shapeWidth / 2, shapeHeight / 2 - r);
shape.lineTo(-shapeWidth / 2, -shapeHeight / 2 + r);
shape.quadraticCurveTo(-shapeWidth / 2, -shapeHeight / 2, -shapeWidth / 2 + r, -shapeHeight / 2);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.01, depth - bt * 2),
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: bs,
bevelThickness: bt,
curveSegments: 8
});
geometry.translate(0, 0, -(depth - bt * 2) / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addMesh(geometry, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Platform and floor
const platform = addMesh(
new THREE.CylinderGeometry(4.35, 4.5, 0.18, 96),
materials.platform,
0,
-0.1,
0,
false
);
platform.receiveShadow = true;
const floor = addMesh(
new THREE.PlaneGeometry(40, 40),
materials.floor,
0,
-0.2,
0,
false
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
const grid = new THREE.GridHelper(8.4, 24, 0x60706b, 0x71807a);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.10;
scene.add(grid);
// Two softwood samples, separated by a narrow reveal
const woodWidth = 1.82;
const woodHeight = 1.48;
const woodDepth = 2.08;
const woodY = 0.79;
const leftWood = addMesh(
new THREE.BoxGeometry(woodWidth, woodHeight, woodDepth),
materials.woodA,
-1.03,
woodY,
0
);
const rightWood = addMesh(
new THREE.BoxGeometry(woodWidth, woodHeight, woodDepth),
materials.woodB,
1.03,
woodY,
0
);
[leftWood, rightWood].forEach((wood) => {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(wood.geometry, 24),
new THREE.LineBasicMaterial({
color: 0x5f3924,
transparent: true,
opacity: 0.28
})
);
wood.add(edges);
});
// Rear clamp frame
const frame = new THREE.Group();
scene.add(frame);
function framePart(mesh, x, y, z) {
mesh.position.set(x, y, z);
frame.add(mesh);
return mesh;
}
framePart(roundedBox(0.38, 2.38, 0.42, 0.1, materials.orange), -2.56, 1.34, -1.36);
framePart(roundedBox(0.38, 2.38, 0.42, 0.1, materials.orange), 2.56, 1.34, -1.36);
framePart(roundedBox(5.46, 0.3, 0.42, 0.1, materials.orangeDark), 0, 0.2, -1.36);
framePart(roundedBox(5.34, 0.22, 0.36, 0.08, materials.orange), 0, 2.42, -1.42);
// Jaw-to-frame bridges
framePart(roundedBox(0.3, 1.25, 1.72, 0.1, materials.orange), -2.45, 0.79, -0.55);
framePart(roundedBox(0.3, 1.25, 1.72, 0.1, materials.orange), 2.45, 0.79, -0.55);
// Horizontal adjustment screw and guide bearings
const bearingLeft = framePart(
roundedBox(0.62, 0.62, 0.62, 0.14, materials.orange),
-2.52,
2.66,
-1.36
);
const bearingRight = framePart(
roundedBox(0.62, 0.62, 0.62, 0.14, materials.orange),
2.52,
2.66,
-1.36
);
const screw = addMesh(
new THREE.CylinderGeometry(0.105, 0.105, 5.82, 32),
materials.brightSteel,
0.25,
2.67,
-1.36
);
screw.rotation.z = Math.PI / 2;
const threadGeometry = new THREE.TorusGeometry(0.127, 0.017, 8, 40);
for (let x = -2.5; x <= 3.02; x += 0.105) {
const thread = new THREE.Mesh(threadGeometry, materials.steel);
thread.rotation.y = Math.PI / 2;
thread.position.set(x, 2.67, -1.36);
thread.castShadow = true;
frame.add(thread);
}
// T-handle
const handle = addMesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.92, 20),
materials.brightSteel,
3.16,
2.67,
-1.36
);
handle.castShadow = true;
const handleHub = addMesh(
new THREE.SphereGeometry(0.15, 24, 16),
materials.orange,
3.16,
2.67,
-1.36
);
// Left direct steel contact shoe
const leftBacking = roundedBox(
0.24, 1.48, 1.82, 0.1, materials.orangeDark
);
leftBacking.position.set(-2.46, woodY, 0);
scene.add(leftBacking);
const leftShoe = roundedBox(
0.38, 1.16, 1.76, 0.09, materials.steel
);
leftShoe.position.set(-2.13, woodY, 0);
scene.add(leftShoe);
// Right side: distinct wood / broad pad / steel / frame stack
const rightBacking = roundedBox(
0.24, 1.46, 1.82, 0.1, materials.orange
);
rightBacking.position.set(2.48, woodY, 0);
scene.add(rightBacking);
const rightShoe = roundedBox(
0.24, 1.18, 2.0, 0.08, materials.brightSteel
);
rightShoe.position.set(2.24, woodY, 0);
scene.add(rightShoe);
const broadPad = roundedBox(
0.18, 1.56, 2.28, 0.08, materials.rubber
);
broadPad.position.set(2.03, woodY, 0);
scene.add(broadPad);
// A slim cyan edge makes the 12 mm layer thickness legible at the front.
const padEdgeMaterial = new THREE.MeshBasicMaterial({
color: 0x58f1d3,
transparent: true,
opacity: 0.76,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const edgeDepth = 0.017;
const edgeX = 2.03;
const edgeY = woodY;
const edgeZ = 1.145;
addMesh(
new THREE.BoxGeometry(0.18, edgeDepth, edgeDepth),
padEdgeMaterial,
edgeX,
edgeY + 0.78,
edgeZ,
false
);
addMesh(
new THREE.BoxGeometry(0.18, edgeDepth, edgeDepth),
padEdgeMaterial,
edgeX,
edgeY - 0.78,
edgeZ,
false
);
addMesh(
new THREE.BoxGeometry(edgeDepth, 1.56, edgeDepth),
padEdgeMaterial,
edgeX - 0.09,
edgeY,
edgeZ,
false
);
addMesh(
new THREE.BoxGeometry(edgeDepth, 1.56, edgeDepth),
padEdgeMaterial,
edgeX + 0.09,
edgeY,
edgeZ,
false
);
// Fasteners on the visible orange jaw backing
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0x3e4b4d,
roughness: 0.34,
metalness: 0.75
});
for (const y of [0.42, 1.16]) {
const bolt = addMesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.035, 18),
boltMaterial,
2.48,
y,
0.925,
false
);
bolt.rotation.x = Math.PI / 2;
}
// Actual interface glow planes
const rightInterfaceMaterial = new THREE.MeshBasicMaterial({
map: makePressureTexture("rgba(67,225,194,ALPHA)"),
transparent: true,
opacity: 0.62,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide
});
const leftInterfaceMaterial = new THREE.MeshBasicMaterial({
map: makePressureTexture("rgba(255,196,93,ALPHA)"),
transparent: true,
opacity: 0.6,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide
});
const rightInterface = addMesh(
new THREE.PlaneGeometry(2.0, 1.28),
rightInterfaceMaterial,
1.945,
woodY,
0,
false
);
rightInterface.rotation.y = Math.PI / 2;
const leftInterface = addMesh(
new THREE.PlaneGeometry(1.58, 1.04),
leftInterfaceMaterial,
-1.945,
woodY,
0,
false
);
leftInterface.rotation.y = Math.PI / 2;
// Visible pressure-spread decals on the front faces of the samples
const rightFrontGlow = addMesh(
new THREE.PlaneGeometry(0.66, 1.18),
rightInterfaceMaterial.clone(),
1.63,
woodY,
woodDepth / 2 + 0.008,
false
);
const leftFrontGlow = addMesh(
new THREE.PlaneGeometry(0.42, 1.0),
leftInterfaceMaterial.clone(),
-1.73,
woodY,
woodDepth / 2 + 0.008,
false
);
// Subtle compression arrows
function makeForceArrow(x, direction, color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.34,
roughness: 0.45,
metalness: 0.08,
transparent: true,
opacity: 0.9
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.28, 14),
material
);
shaft.rotation.z = direction > 0 ? -Math.PI / 2 : Math.PI / 2;
shaft.position.x = direction * 0.14;
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.2, 20),
material
);
cone.rotation.z = direction > 0 ? -Math.PI / 2 : Math.PI / 2;
cone.position.x = direction * 0.33;
group.add(shaft, cone);
group.position.set(x, 1.84, 1.12);
scene.add(group);
}
makeForceArrow(-1.22, 1, 0xffc45d);
makeForceArrow(1.22, -1, 0x43e1c2);
// Annotation anchors
const padAnchor = new THREE.Vector3(2.03, 1.18, 1.15);
const faceAnchor = new THREE.Vector3(-1.94, 1.1, 1.05);
const padLabel = document.getElementById("pad-label");
const faceLabel = document.getElementById("face-label");
const padLeader = document.getElementById("pad-leader");
const faceLeader = document.getElementById("face-leader");
const padDot = document.getElementById("pad-dot");
const faceDot = document.getElementById("face-dot");
function positionCallout(label, line, dot, anchor, offsetX, offsetY) {
const projected = anchor.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const labelX = x + offsetX;
const labelY = y + offsetY;
label.style.left = `${labelX}px`;
label.style.top = `${labelY}px`;
line.setAttribute("x1", x);
line.setAttribute("y1", y);
line.setAttribute("x2", labelX);
line.setAttribute("y2", labelY);
dot.setAttribute("cx", x);
dot.setAttribute("cy", y);
}
// Direct camera controls: drag to orbit and wheel/pinch to zoom.
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
5.2,
11.5
);
}
pinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.0052;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.48,
1.43
);
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
if (activePointers.size === 0) dragging = false;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.004,
5.2,
11.5
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
cameraState.radius = 7.65;
cameraState.theta = 0.34;
cameraState.phi = 1.17;
cameraState.target.set(0, 1.05, 0);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const pulse = 0.5 + 0.5 * Math.sin(elapsed * 2.2);
updateCamera();
rightInterfaceMaterial.opacity = 0.47 + pulse * 0.19;
leftInterfaceMaterial.opacity = 0.43 + pulse * 0.2;
rightFrontGlow.material.opacity = 0.48 + pulse * 0.17;
leftFrontGlow.material.opacity = 0.44 + pulse * 0.16;
padEdgeMaterial.opacity = 0.58 + pulse * 0.28;
materials.rubber.emissiveIntensity = 0.11 + pulse * 0.12;
contactLight.intensity = 2.1 + pulse * 1.25;
faceLight.intensity = 1.05 + pulse * 0.65;
rightFrontGlow.scale.x = 1 + Math.sin(elapsed * 1.7) * 0.025;
leftFrontGlow.scale.x = 1 + Math.sin(elapsed * 1.9 + 1.2) * 0.025;
positionCallout(
padLabel,
padLeader,
padDot,
padAnchor,
window.innerWidth > 720 ? 115 : 0,
window.innerWidth > 720 ? -28 : 0
);
positionCallout(
faceLabel,
faceLeader,
faceDot,
faceAnchor,
window.innerWidth > 720 ? -135 : 0,
window.innerWidth > 720 ? -30 : 0
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```