Prompt specification
Build or customize the Three.js 3D scene "Undercut Prevents Straight Mold Release" 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: Undercut Prevents Straight Mold Release
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/undercut-prevents-straight-mold-release-x2050
Scene Description Prompt:
Show why an undercut blocks a rigid voxel part from leaving a split mold. One self-contained HTML file with Three.js from cdnjs.
Working Three.js Starter (undercut-prevents-straight-mold-release-x2050):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Why an Undercut Traps a Rigid Voxel Part</title>
<style>
:root {
color-scheme: dark;
--bg: #07131d;
--panel: rgba(10, 25, 37, 0.88);
--line: rgba(157, 205, 224, 0.18);
--text: #eaf6fb;
--muted: #94afbd;
--cyan: #56d5e8;
--amber: #ffc857;
--red: #ff5f5f;
--green: #6de3a4;
}
* { 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;
}
#view {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
#intro {
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 19px 20px 17px;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 8px;
font-size: clamp(22px, 2.4vw, 32px);
line-height: 1.08;
letter-spacing: -0.035em;
}
#intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
margin-top: 14px;
font-size: 11px;
color: #bfd2dc;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
#metrics {
top: 20px;
right: 20px;
width: 285px;
padding: 16px;
pointer-events: none;
}
.metric-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 8px 0;
border-top: 1px solid var(--line);
font-size: 12px;
color: var(--muted);
}
.metric b {
color: var(--text);
font-size: 15px;
font-variant-numeric: tabular-nums;
}
#status {
margin-top: 12px;
padding: 12px;
border: 1px solid rgba(109, 227, 164, 0.28);
border-radius: 11px;
background: rgba(109, 227, 164, 0.07);
}
#status.blocked {
border-color: rgba(255, 95, 95, 0.5);
background: rgba(255, 95, 95, 0.09);
}
#status.moving {
border-color: rgba(86, 213, 232, 0.35);
background: rgba(86, 213, 232, 0.07);
}
.status-head {
display: flex;
align-items: center;
gap: 8px;
color: var(--green);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#status.blocked .status-head { color: var(--red); }
#status.moving .status-head { color: var(--cyan); }
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
#statusText {
margin-top: 7px;
color: #c8dbe4;
font-size: 12px;
line-height: 1.45;
}
#controls {
left: 50%;
bottom: 22px;
z-index: 8;
display: flex;
align-items: center;
gap: 9px;
padding: 10px;
transform: translateX(-50%);
white-space: nowrap;
}
button {
appearance: none;
border: 1px solid rgba(163, 211, 229, 0.23);
border-radius: 10px;
padding: 10px 13px;
background: rgba(34, 64, 80, 0.9);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 120ms, border-color 120ms, transform 120ms;
}
button:hover {
background: rgba(51, 91, 110, 0.95);
border-color: rgba(86, 213, 232, 0.55);
}
button:active { transform: translateY(1px); }
button.primary {
background: var(--amber);
border-color: var(--amber);
color: #271b06;
}
button.primary:hover {
background: #ffd778;
border-color: #ffd778;
}
.slider-wrap {
display: flex;
align-items: center;
gap: 9px;
padding: 0 8px;
color: var(--muted);
font-size: 11px;
}
input[type="range"] {
width: 135px;
accent-color: var(--amber);
}
.check {
display: flex;
align-items: center;
gap: 6px;
padding: 0 5px;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.check input { accent-color: var(--cyan); }
#hint {
position: fixed;
left: 50%;
bottom: 92px;
z-index: 4;
transform: translateX(-50%);
color: rgba(190, 213, 224, 0.65);
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
}
.world-tag {
position: fixed;
z-index: 4;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(157, 205, 224, 0.25);
border-radius: 8px;
background: rgba(7, 19, 29, 0.82);
color: #d9edf5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.035em;
pointer-events: none;
white-space: nowrap;
box-shadow: 0 7px 20px rgba(0, 0, 0, 0.25);
}
.world-tag.amber {
border-color: rgba(255, 200, 87, 0.55);
color: var(--amber);
}
.world-tag.red {
border-color: rgba(255, 95, 95, 0.65);
color: #ff9292;
}
.world-tag.cyan {
border-color: rgba(86, 213, 232, 0.55);
color: var(--cyan);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 820px) {
#metrics { display: none; }
#intro { width: min(340px, calc(100vw - 40px)); }
#controls {
max-width: calc(100vw - 20px);
flex-wrap: wrap;
justify-content: center;
white-space: normal;
}
#hint { display: none; }
}
</style>
</head>
<body>
<canvas id="view"></canvas>
<section id="intro" class="panel">
<div class="eyebrow">Rigid-body extraction study</div>
<h1>The undercut blocks the rigid voxel head.</h1>
<p>
The narrow stem fits the throat, but the much taller head cannot pass it.
Pushing farther along +X creates overlap with the internal shoulder;
it does not create more clearance.
</p>
<div class="legend">
<span><i class="swatch" style="background:#ffc857;color:#ffc857"></i>rigid part</span>
<span><i class="swatch" style="background:#ef8354;color:#ef8354"></i>undercut shoulder</span>
<span><i class="swatch" style="background:#31576a;color:#31576a"></i>mold</span>
</div>
</section>
<section id="metrics" class="panel">
<div class="metric-title">Kinematic proof</div>
<div class="metric"><span>Rigid head height</span><b>4.80</b></div>
<div class="metric"><span>Throat height</span><b>1.60</b></div>
<div class="metric"><span>Head interference</span><b>3.20</b></div>
<div class="metric"><span>Allowed +X travel</span><b id="travelMetric">0.00</b></div>
<div class="metric"><span>Mold split</span><b id="splitMetric">0.90</b></div>
<div id="status">
<div class="status-head"><i class="status-dot"></i><span id="statusHead">Ready</span></div>
<div id="statusText">The part is seated. Pull it along the +X draw direction.</div>
</div>
</section>
<div id="hint">
Drag: orbit · Wheel: zoom · Shift/right-drag: pan · Space: pull rigid part
</div>
<div id="controls" class="panel">
<button id="splitButton">Close split mold</button>
<button id="pullButton" class="primary">Pull rigid part</button>
<button id="resetButton">Reset</button>
<label class="slider-wrap">
Attempted draw
<input id="travelSlider" type="range" min="0" max="1.6" step="0.01" value="0">
<b id="requestedReadout">0.00</b>
</label>
<label class="check">
<input id="xray" type="checkbox">
X-ray mold
</label>
</div>
<div id="headTag" class="world-tag amber">rigid voxel head</div>
<div id="shoulderTag" class="world-tag red">undercut shoulder</div>
<div id="throatTag" class="world-tag cyan">narrow throat</div>
<div id="drawTag" class="world-tag">+X extraction</div>
<div id="loading">Loading geometry…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
Scene
-------------------------------------------------------------------------- */
const canvas = document.getElementById("view");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 18, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(4.8, 3.45, 0);
let yaw = 0.46;
let pitch = 0.34;
let radius = 16.5;
function updateCamera() {
const cp = Math.cos(pitch);
camera.position.set(
target.x + radius * cp * Math.sin(yaw),
target.y + radius * Math.sin(pitch),
target.z + radius * cp * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xb9e9ff, 0x152333, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffffff, 3.1);
key.position.set(5, 13, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 12;
key.shadow.camera.bottom = -12;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.normalBias = 0.035;
scene.add(key);
const rim = new THREE.DirectionalLight(0x56d5e8, 1.8);
rim.position.set(10, 6, -11);
scene.add(rim);
const warm = new THREE.PointLight(0xffb84d, 22, 18, 2);
warm.position.set(7, 6, 4);
scene.add(warm);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x0a1a25,
roughness: 0.92,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x2d5265, 0x173342);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.55;
scene.add(grid);
/* --------------------------------------------------------------------------
Voxel mold and cavity
Draw direction: +X
Mold parting direction: +/-Z
Wide chamber transitions to a short throat at x = 4.8.
-------------------------------------------------------------------------- */
const CELL = 0.8;
const NX = 12;
const NY = 9;
const NZ = 10;
const SHOULDER_X = 4.8;
const HEAD_MAX_X = 4.0;
const MAX_TRAVEL = SHOULDER_X - HEAD_MAX_X;
function isChamber(ix, iy, iz) {
return ix >= 2 && ix < 6 &&
iy >= 1 && iy < 8 &&
iz >= 1 && iz < 9;
}
function isThroat(ix, iy, iz) {
return ix >= 6 && ix < 12 &&
iy >= 3 && iy < 5 &&
iz >= 3 && iz < 7;
}
function isCavity(ix, iy, iz) {
return isChamber(ix, iy, iz) || isThroat(ix, iy, iz);
}
function cellPosition(ix, iy, iz) {
return new THREE.Vector3(
(ix + 0.5) * CELL,
(iy + 0.5) * CELL,
(iz - (NZ - 1) / 2) * CELL
);
}
function isShoulder(ix, iy, iz) {
return ix === 6 &&
(iy < 3 || iy >= 5) &&
iz >= 1 && iz < 9;
}
function adjacentToCavity(ix, iy, iz) {
const offsets = [
[1, 0, 0], [-1, 0, 0],
[0, 1, 0], [0, -1, 0],
[0, 0, 1], [0, 0, -1]
];
return offsets.some(([dx, dy, dz]) =>
isCavity(ix + dx, iy + dy, iz + dz)
);
}
const frontHalf = new THREE.Group();
const backHalf = new THREE.Group();
scene.add(frontHalf, backHalf);
const moldFrontMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.06
});
const moldBackMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0.05
});
const moldGeometry = new THREE.BoxGeometry(CELL * 0.985, CELL * 0.985, CELL * 0.985);
const baseMoldColor = new THREE.Color(0x31576a);
const surfaceMoldColor = new THREE.Color(0x3f7182);
const shoulderColor = new THREE.Color(0xef8354);
function buildMoldHalf(front) {
const cells = [];
for (let ix = 0; ix < NX; ix++) {
for (let iy = 0; iy < NY; iy++) {
for (let iz = 0; iz < NZ; iz++) {
if (isCavity(ix, iy, iz)) continue;
const z = (iz - (NZ - 1) / 2) * CELL;
const belongsToFront = z > 0;
if (belongsToFront !== front) continue;
let color = baseMoldColor.clone();
if (isShoulder(ix, iy, iz)) {
color = shoulderColor.clone();
} else if (adjacentToCavity(ix, iy, iz)) {
color = surfaceMoldColor.clone();
}
cells.push({
position: cellPosition(ix, iy, iz),
color
});
}
}
}
const mesh = new THREE.InstancedMesh(
moldGeometry,
front ? moldFrontMaterial : moldBackMaterial,
cells.length
);
const dummy = new THREE.Object3D();
cells.forEach((cell, i) => {
dummy.position.copy(cell.position);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
mesh.setColorAt(i, cell.color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
frontHalf.add(buildMoldHalf(true));
backHalf.add(buildMoldHalf(false));
/* --------------------------------------------------------------------------
Rigid voxel part
Continuous envelope boxes make the collision mathematically obvious even
though the visible surface is drawn as individual voxel cubes.
-------------------------------------------------------------------------- */
const partGroup = new THREE.Group();
scene.add(partGroup);
const voxelGeometry = new THREE.BoxGeometry(CELL * 0.94, CELL * 0.94, CELL * 0.94);
const partMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.44,
metalness: 0.18
});
const headVoxels = [];
for (let ix = 2; ix < 5; ix++) {
for (let iy = 1; iy < 7; iy++) {
for (let iz = 3; iz < 7; iz++) {
headVoxels.push({
position: cellPosition(ix, iy, iz),
shade: (ix + iy + iz) % 2
});
}
}
}
const stemVoxels = [];
for (let ix = 4; ix < 12; ix++) {
for (let iy = 3; iy < 5; iy++) {
for (let iz = 4; iz < 6; iz++) {
stemVoxels.push({
position: cellPosition(ix, iy, iz),
shade: (ix + iy + iz) % 2
});
}
}
}
function buildPartVoxels(items, colorA, colorB) {
const mesh = new THREE.InstancedMesh(voxelGeometry, partMaterial, items.length);
const dummy = new THREE.Object3D();
items.forEach((item, i) => {
dummy.position.copy(item.position);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
mesh.setColorAt(i, new THREE.Color(item.shade ? colorA : colorB));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
partGroup.add(buildPartVoxels(headVoxels, 0xffc857, 0xffb13b));
partGroup.add(buildPartVoxels(stemVoxels, 0xffdf83, 0xffca57));
function addEnvelope(parent, size, position, color, opacity = 1) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(size.x, size.y, size.z)
);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
const lines = new THREE.LineSegments(geometry, material);
lines.position.copy(position);
parent.add(lines);
return lines;
}
addEnvelope(
partGroup,
new THREE.Vector3(2.4, 4.8, 3.2),
new THREE.Vector3(2.8, 3.2, 0),
0xffe29a,
0.9
);
addEnvelope(
partGroup,
new THREE.Vector3(8.0, 1.6, 1.6),
new THREE.Vector3(6.4, 3.2, 0),
0xffe29a,
0.72
);
/* --------------------------------------------------------------------------
Collision visualization
-------------------------------------------------------------------------- */
const collisionGroup = new THREE.Group();
collisionGroup.visible = false;
scene.add(collisionGroup);
const contactPlane = new THREE.Mesh(
new THREE.PlaneGeometry(3.2, 4.8),
new THREE.MeshBasicMaterial({
color: 0xff4040,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false
})
);
contactPlane.rotation.y = Math.PI / 2;
contactPlane.position.set(SHOULDER_X, 3.2, 0);
collisionGroup.add(contactPlane);
const contactEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.09, 4.8, 3.2)),
new THREE.LineBasicMaterial({ color: 0xff6b6b })
);
contactEdges.position.set(SHOULDER_X, 3.2, 0);
collisionGroup.add(contactEdges);
// Ghost of an impossible continuation beyond the contact point.
const ghostGroup = new THREE.Group();
ghostGroup.visible = false;
ghostGroup.position.x = 1.6;
scene.add(ghostGroup);
const ghostMaterial = new THREE.MeshBasicMaterial({
color: 0xff6565,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
});
const ghostHead = new THREE.Mesh(new THREE.BoxGeometry(2.4, 4.8, 3.2), ghostMaterial);
ghostHead.position.set(2.8, 3.2, 0);
ghostGroup.add(ghostHead);
addEnvelope(
ghostGroup,
new THREE.Vector3(2.4, 4.8, 3.2),
new THREE.Vector3(2.8, 3.2, 0),
0xff6969,
0.8
);
/* Direction arrows */
const drawArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(7.4, 6.85, 0),
3.2,
0xffc857,
0.55,
0.34
);
scene.add(drawArrow);
const splitArrowA = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(9.0, 0.35, 0.4),
1.45,
0x56d5e8,
0.38,
0.25
);
const splitArrowB = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(9.0, 0.35, -0.4),
1.45,
0x56d5e8,
0.38,
0.25
);
scene.add(splitArrowA, splitArrowB);
/* --------------------------------------------------------------------------
UI state
-------------------------------------------------------------------------- */
const splitButton = document.getElementById("splitButton");
const pullButton = document.getElementById("pullButton");
const resetButton = document.getElementById("resetButton");
const travelSlider = document.getElementById("travelSlider");
const requestedReadout = document.getElementById("requestedReadout");
const travelMetric = document.getElementById("travelMetric");
const splitMetric = document.getElementById("splitMetric");
const status = document.getElementById("status");
const statusHead = document.getElementById("statusHead");
const statusText = document.getElementById("statusText");
const xray = document.getElementById("xray");
let splitAmount = 0.9;
let splitTarget = 0.9;
let pull = 0;
let pullTarget = 0;
let requestedTravel = 0;
function setStatus(kind, head, text) {
status.className = kind;
statusHead.textContent = head;
statusText.textContent = text;
}
splitButton.addEventListener("click", () => {
if (splitTarget > 0.1) {
splitTarget = 0;
splitButton.textContent = "Open split mold";
} else {
splitTarget = 0.9;
splitButton.textContent = "Close split mold";
}
});
pullButton.addEventListener("click", () => {
requestedTravel = MAX_TRAVEL;
travelSlider.value = String(requestedTravel);
requestedReadout.textContent = requestedTravel.toFixed(2);
pullTarget = MAX_TRAVEL;
setStatus(
"moving",
"Pulling +X",
"The rigid head is moving toward the internal shoulder. No voxel can deform."
);
});
resetButton.addEventListener("click", () => {
requestedTravel = 0;
pullTarget = 0;
travelSlider.value = "0";
requestedReadout.textContent = "0.00";
setStatus(
"",
"Ready",
"The part is seated. Pull it along the +X draw direction."
);
});
travelSlider.addEventListener("input", () => {
requestedTravel = Number(travelSlider.value);
requestedReadout.textContent = requestedTravel.toFixed(2);
pullTarget = Math.min(requestedTravel, MAX_TRAVEL);
if (requestedTravel > MAX_TRAVEL + 0.001) {
setStatus(
"blocked",
"Contact limit",
`Requested travel is ${requestedTravel.toFixed(2)}, but rigid contact occurs at ${MAX_TRAVEL.toFixed(2)}.`
);
} else {
setStatus(
"moving",
"Pulling +X",
"The rigid voxel envelope moves as one body toward the throat."
);
}
});
xray.addEventListener("change", () => {
for (const material of [moldFrontMaterial, moldBackMaterial]) {
material.transparent = xray.checked;
material.opacity = xray.checked ? 0.20 : 1;
material.depthWrite = !xray.checked;
material.needsUpdate = true;
}
});
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
pullButton.click();
}
if (event.key.toLowerCase() === "o") splitButton.click();
if (event.key.toLowerCase() === "r") resetButton.click();
});
/* --------------------------------------------------------------------------
Direct camera controls: orbit, zoom and pan.
-------------------------------------------------------------------------- */
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const up = new THREE.Vector3().crossVectors(right, forward).normalize();
const scale = radius * 0.0015;
target.addScaledVector(right, -dx * scale);
target.addScaledVector(up, dy * scale);
} else {
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, -0.12, 1.22);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
radius = THREE.MathUtils.clamp(radius * Math.exp(event.deltaY * 0.001), 8, 31);
updateCamera();
}, { passive: false });
/* --------------------------------------------------------------------------
Projected labels
-------------------------------------------------------------------------- */
const labels = [
{ element: document.getElementById("headTag"), position: new THREE.Vector3(2.8, 5.85, 1.65) },
{ element: document.getElementById("shoulderTag"), position: new THREE.Vector3(4.8, 5.25, 1.05) },
{ element: document.getElementById("throatTag"), position: new THREE.Vector3(7.0, 4.1, -1.15) },
{ element: document.getElementById("drawTag"), position: new THREE.Vector3(9.0, 6.85, 0) }
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const p = label.position.clone().project(camera);
const visible = p.z > -1 && p.z < 1 && Math.abs(p.x) < 1.12 && Math.abs(p.y) < 1.12;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
label.element.style.left = `${(p.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-p.y * 0.5 + 0.5) * height}px`;
}
}
/* --------------------------------------------------------------------------
Animation
-------------------------------------------------------------------------- */
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const blend = 1 - Math.exp(-dt * 8);
splitAmount += (splitTarget - splitAmount) * blend;
frontHalf.position.z = splitAmount;
backHalf.position.z = -splitAmount;
pull += (pullTarget - pull) * blend;
if (Math.abs(pull - pullTarget) < 0.001) pull = pullTarget;
partGroup.position.x = pull;
const blocked = pull >= MAX_TRAVEL - 0.006 && requestedTravel >= MAX_TRAVEL - 0.006;
collisionGroup.visible = blocked;
ghostGroup.visible = blocked;
if (blocked) {
setStatus(
"blocked",
"Blocked",
`The 4.80-high head reaches the 1.60-high throat at ${MAX_TRAVEL.toFixed(2)} travel. Further +X motion produces solid overlap.`
);
}
travelMetric.textContent = pull.toFixed(2);
splitMetric.textContent = splitAmount.toFixed(2);
updateLabels();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
document.getElementById("loading").style.display = "none";
animate();
</script>
</body>
</html>
```