Prompt specification
Build or customize the Three.js 3D scene "Tape end-hook reference study" 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: Tape end-hook reference study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tape-end-hook-reference-study-x0281
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: tape end-hook reference study. Model a tape-measure end hook, marked ribbon, and block edge; show the hook's small allowed movement as separate inside and outside measurement reference positions. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (tape-end-hook-reference-study-x0281):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Tape End-Hook Reference Study</title>
<style>
:root {
color-scheme: dark;
--bg: #08111d;
--panel: rgba(12, 23, 38, 0.84);
--line: rgba(177, 211, 234, 0.18);
--text: #eaf4fb;
--muted: #91a7b9;
--inside: #39dcff;
--outside: #ff6f73;
--metal: #dce8ee;
--edge: #ffad4a;
}
* { 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;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.title-card,
.legend-card,
.control-card,
.help {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 16px 44px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.title-card {
top: 22px;
left: 22px;
padding: 15px 18px 14px;
border-radius: 14px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: var(--inside);
font: 700 10px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.2vw, 28px);
line-height: 1.05;
letter-spacing: -0.03em;
}
.subtitle {
margin-top: 7px;
color: var(--muted);
font: 500 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.legend-card {
top: 22px;
right: 22px;
width: 220px;
padding: 13px 15px;
border-radius: 14px;
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.swatch {
width: 12px;
height: 12px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 3px;
box-shadow: 0 0 12px currentColor;
}
.swatch.inside { color: var(--inside); background: var(--inside); }
.swatch.outside { color: var(--outside); background: var(--outside); }
.swatch.metal { color: var(--metal); background: var(--metal); }
.swatch.edge { color: var(--edge); background: var(--edge); }
#annotations {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-left: 3px solid var(--accent, var(--metal));
border-radius: 7px;
background: rgba(7, 16, 28, 0.88);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
color: var(--accent, var(--text));
font: 700 9px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.annotation .dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.control-card {
right: 22px;
bottom: 22px;
width: min(340px, calc(100vw - 44px));
padding: 15px;
border-radius: 15px;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.control-title {
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#offset-value {
color: var(--metal);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.range-wrap {
position: relative;
margin: 2px 0 13px;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 5px;
border-radius: 99px;
background:
linear-gradient(90deg,
var(--inside) 0%,
var(--inside) 25%,
var(--metal) 25%,
var(--metal) 75%,
var(--outside) 75%,
var(--outside) 100%);
opacity: 0.78;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -5.5px;
appearance: none;
border: 2px solid #07101c;
border-radius: 4px;
background: #fff;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55), 0 0 15px rgba(255, 255, 255, 0.32);
}
input[type="range"]::-moz-range-track {
height: 5px;
border-radius: 99px;
background: linear-gradient(90deg,
var(--inside) 0%,
var(--inside) 25%,
var(--metal) 25%,
var(--metal) 75%,
var(--outside) 75%,
var(--outside) 100%);
opacity: 0.78;
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 2px solid #07101c;
border-radius: 4px;
background: #fff;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
}
button {
min-height: 34px;
padding: 7px 8px;
border: 1px solid rgba(180, 214, 236, 0.22);
border-radius: 8px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
cursor: pointer;
transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
button:hover {
border-color: rgba(180, 214, 236, 0.45);
background: rgba(255, 255, 255, 0.1);
}
button:active { transform: translateY(1px); }
button.active {
border-color: var(--inside);
color: var(--inside);
background: rgba(57, 220, 255, 0.09);
}
.help {
left: 22px;
bottom: 22px;
padding: 9px 12px;
border-radius: 10px;
color: var(--muted);
font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
pointer-events: none;
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
padding: 12px 14px;
}
.legend-card {
top: 12px;
right: 12px;
width: 154px;
padding: 10px;
}
.legend-title { display: none; }
.legend-row { margin: 5px 0; font-size: 9px; }
.control-card {
right: 12px;
bottom: 12px;
width: min(330px, calc(100vw - 24px));
}
.help {
display: none;
}
.annotation {
padding: 5px 7px;
font-size: 8px;
}
.annotation.optional { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="title-card">
<div class="eyebrow">Measurement / Motion Study</div>
<h1>Tape end-hook reference</h1>
<div class="subtitle">Voxel ribbon · independent inside / outside hook positions</div>
</header>
<aside class="legend-card">
<div class="legend-title">Reference key</div>
<div class="legend-row"><span class="swatch inside"></span>Inside position</div>
<div class="legend-row"><span class="swatch outside"></span>Outside position</div>
<div class="legend-row"><span class="swatch metal"></span>Working hook</div>
<div class="legend-row"><span class="swatch edge"></span>Block contact edge</div>
</aside>
<div id="annotations"></div>
<section class="control-card">
<div class="control-head">
<span class="control-title">Hook travel</span>
<span id="offset-value">0.00 u</span>
</div>
<div class="range-wrap">
<input id="travel" type="range" min="-1" max="1" step="0.01" value="0"
aria-label="Hook travel position" />
<div class="range-labels">
<span>INSIDE −0.18</span>
<span>NEUTRAL</span>
<span>OUTSIDE +0.18</span>
</div>
</div>
<div class="buttons">
<button id="play" type="button">PLAY</button>
<button id="refs" class="active" type="button" aria-pressed="true">REFS ON</button>
<button id="reset" type="button">RESET VIEW</button>
</div>
</section>
<div class="help">DRAG: orbit · SHIFT / RIGHT-DRAG: pan · WHEEL: zoom · DOUBLE-CLICK: reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const annotationLayer = document.getElementById("annotations");
const travelInput = document.getElementById("travel");
const offsetValue = document.getElementById("offset-value");
const playButton = document.getElementById("play");
const refsButton = document.getElementById("refs");
const resetButton = document.getElementById("reset");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111d);
scene.fog = new THREE.Fog(0x08111d, 15, 27);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
camera.zoom = 1.04;
const hemisphere = new THREE.HemisphereLight(0xb8dcff, 0x172033, 2.3);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58c7ff, 1.8);
rimLight.position.set(7, 5, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb75e, 18, 12, 2);
warmLight.position.set(2.8, 2.8, 4.5);
scene.add(warmLight);
const palette = {
ground: new THREE.MeshStandardMaterial({ color: 0x101b29, roughness: 0.92, metalness: 0.02 }),
grid: new THREE.LineBasicMaterial({ color: 0x294054, transparent: true, opacity: 0.38 }),
tape: new THREE.MeshStandardMaterial({ color: 0xf2c23f, roughness: 0.56, metalness: 0.08 }),
tapeSide: new THREE.MeshStandardMaterial({ color: 0xc9951b, roughness: 0.62, metalness: 0.08 }),
tick: new THREE.MeshStandardMaterial({ color: 0x17212a, roughness: 0.78 }),
redTick: new THREE.MeshStandardMaterial({ color: 0xc94035, roughness: 0.72 }),
metal: new THREE.MeshStandardMaterial({ color: 0xd7e3e9, roughness: 0.3, metalness: 0.78 }),
metalDark: new THREE.MeshStandardMaterial({ color: 0x6c7d88, roughness: 0.38, metalness: 0.72 }),
case: new THREE.MeshStandardMaterial({ color: 0x172534, roughness: 0.58, metalness: 0.22 }),
caseTop: new THREE.MeshStandardMaterial({ color: 0x23374a, roughness: 0.5, metalness: 0.28 }),
orange: new THREE.MeshStandardMaterial({ color: 0xffa343, roughness: 0.48, metalness: 0.14 }),
edge: new THREE.LineBasicMaterial({ color: 0x07101b, transparent: true, opacity: 0.52 }),
softEdge: new THREE.LineBasicMaterial({ color: 0x9db4c4, transparent: true, opacity: 0.3 })
};
function addBox(parent, size, position, material, outlineMaterial = palette.edge) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlineMaterial) {
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
outlineMaterial
);
outline.renderOrder = 2;
mesh.add(outline);
}
return mesh;
}
// Ground and an understated measurement grid.
addBox(scene, [17, 0.14, 13], [0, -0.09, 0], palette.ground, null);
const grid = new THREE.GridHelper(14, 28, 0x355168, 0x23384b);
grid.position.y = -0.012;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
// A cropped voxel tape-measure case establishes the measuring ribbon.
const caseGroup = new THREE.Group();
scene.add(caseGroup);
addBox(caseGroup, [1.42, 1.28, 1.34], [-4.92, 1.08, 0], palette.case);
addBox(caseGroup, [1.22, 0.35, 1.28], [-4.92, 1.86, 0], palette.caseTop);
addBox(caseGroup, [1.16, 0.22, 1.22], [-4.94, 0.43, 0], palette.caseTop);
addBox(caseGroup, [0.35, 0.42, 1.03], [-4.14, 1.49, 0], palette.tapeSide);
addBox(caseGroup, [0.13, 0.16, 0.38], [-5.25, 1.28, 0.69], palette.orange);
// Yellow marked ribbon.
const ribbonGroup = new THREE.Group();
scene.add(ribbonGroup);
const ribbonStart = -4.20;
const ribbonEnd = 2.36;
const ribbonLength = ribbonEnd - ribbonStart;
const ribbonCenter = (ribbonStart + ribbonEnd) / 2;
addBox(
ribbonGroup,
[ribbonLength, 0.085, 1.0],
[ribbonCenter, 1.50, 0],
palette.tape
);
addBox(
ribbonGroup,
[ribbonLength, 0.035, 0.035],
[ribbonCenter, 1.485, -0.49],
palette.tapeSide,
null
);
addBox(
ribbonGroup,
[ribbonLength, 0.035, 0.035],
[ribbonCenter, 1.485, 0.49],
palette.tapeSide,
null
);
// Pixel-style raised ruler marks.
const tickGeometry = new THREE.BoxGeometry(1, 1, 1);
const tickCount = 27;
for (let i = 0; i < tickCount; i++) {
const x = -4.05 + i * 0.25;
const length = i % 5 === 0 ? 0.68 : (i % 2 === 0 ? 0.47 : 0.27);
const material = i % 10 === 0 ? palette.redTick : palette.tick;
const tick = new THREE.Mesh(tickGeometry, material);
tick.scale.set(0.025, 0.014, length);
tick.position.set(x, 1.554, -0.455 + length / 2);
tick.castShadow = true;
ribbonGroup.add(tick);
}
// Tiny voxel numerals on the ribbon.
const digitPatterns = {
"0": ["01110", "10001", "10011", "10101", "11001", "10001", "01110"],
"1": ["00100", "01100", "00100", "00100", "00100", "00100", "01110"],
"2": ["01110", "10001", "00001", "00010", "00100", "01000", "11111"],
"3": ["11110", "00001", "00001", "01110", "00001", "00001", "11110"]
};
function addVoxelNumber(text, originX, originZ, scale = 0.048) {
[...text].forEach((digit, digitIndex) => {
const pattern = digitPatterns[digit];
pattern.forEach((row, rowIndex) => {
[...row].forEach((cell, columnIndex) => {
if (cell !== "1") return;
const number = new THREE.Mesh(tickGeometry, palette.tick);
number.scale.set(scale, 0.015, scale);
number.position.set(
originX + (digitIndex * 6 + columnIndex) * scale,
1.557,
originZ + (3 - rowIndex) * scale
);
ribbonGroup.add(number);
});
});
});
}
addVoxelNumber("10", -2.78, 0.20);
addVoxelNumber("20", -0.22, 0.20);
addVoxelNumber("30", 1.78, 0.20);
// Voxel hook construction. The group origin is the neutral hook position.
function makeHook(ghostColor = null) {
const group = new THREE.Group();
const fill = ghostColor
? new THREE.MeshStandardMaterial({
color: ghostColor,
transparent: true,
opacity: 0.15,
roughness: 0.32,
metalness: 0.45,
depthWrite: false
})
: palette.metal;
const detail = ghostColor
? fill
: palette.metalDark;
const outline = ghostColor
? new THREE.LineBasicMaterial({
color: ghostColor,
transparent: true,
opacity: 0.96,
depthTest: false
})
: palette.edge;
const web = addBox(group, [0.10, 0.72, 0.90], [0, 1.11, 0], fill, outline);
const strap = addBox(group, [0.36, 0.07, 0.90], [0.11, 1.50, 0], fill, outline);
const lip = addBox(group, [0.22, 0.09, 0.90], [0.11, 0.78, 0], fill, outline);
if (ghostColor) {
web.renderOrder = 8;
strap.renderOrder = 8;
lip.renderOrder = 8;
}
addBox(group, [0.13, 0.11, 0.10], [0.01, 1.26, -0.29], detail, outline);
addBox(group, [0.13, 0.11, 0.10], [0.01, 1.26, 0.29], detail, outline);
// Bright folded lower contact edge.
addBox(
group,
[0.225, 0.026, 0.91],
[0.11, 0.822, 0],
ghostColor ? fill : palette.softEdge,
ghostColor ? outline : null
);
return group;
}
const neutralHookX = 2.42;
const referenceTravel = 0.18;
const actualHook = makeHook();
actualHook.position.x = neutralHookX;
scene.add(actualHook);
const referenceGroup = new THREE.Group();
scene.add(referenceGroup);
const insideHook = makeHook(0x39dcff);
insideHook.position.x = neutralHookX - referenceTravel;
referenceGroup.add(insideHook);
const outsideHook = makeHook(0xff6f73);
outsideHook.position.x = neutralHookX + referenceTravel;
referenceGroup.add(outsideHook);
// Voxel gage block assembled from discrete cubes.
const blockGroup = new THREE.Group();
scene.add(blockGroup);
const blockMaterials = [
new THREE.MeshStandardMaterial({ color: 0x526579, roughness: 0.82, metalness: 0.06 }),
new THREE.MeshStandardMaterial({ color: 0x5b6d7e, roughness: 0.8, metalness: 0.06 }),
new THREE.MeshStandardMaterial({ color: 0x475b6d, roughness: 0.84, metalness: 0.05 }),
new THREE.MeshStandardMaterial({ color: 0x647789, roughness: 0.78, metalness: 0.07 })
];
const cubeSize = 0.82;
const pitch = 0.85;
for (let ix = 0; ix < 3; ix++) {
for (let iy = 0; iy < 3; iy++) {
for (let iz = 0; iz < 2; iz++) {
const materialIndex = (ix + iy * 2 + iz) % blockMaterials.length;
addBox(
blockGroup,
[cubeSize, cubeSize, cubeSize],
[3.21 + ix * pitch, 0.41 + iy * pitch, -0.41 + iz * pitch],
blockMaterials[materialIndex]
);
}
}
}
// Orange contact-edge indicators on the block's measuring face.
addBox(
blockGroup,
[0.045, 0.83, 0.055],
[2.775, 1.28, 0.47],
palette.orange,
null
);
addBox(
blockGroup,
[0.045, 0.13, 0.13],
[2.77, 0.79, 0.43],
palette.orange,
null
);
addBox(
blockGroup,
[0.045, 0.13, 0.13],
[2.77, 1.69, -0.32],
palette.orange,
null
);
// Box-built travel dimension beneath the hook references.
const travelDimension = new THREE.Group();
referenceGroup.add(travelDimension);
const cyanMaterial = new THREE.MeshBasicMaterial({
color: 0x39dcff,
transparent: true,
opacity: 0.85,
depthTest: false
});
const coralMaterial = new THREE.MeshBasicMaterial({
color: 0xff6f73,
transparent: true,
opacity: 0.85,
depthTest: false
});
addBox(
travelDimension,
[0.18, 0.025, 0.025],
[2.33, 0.43, 1.20],
cyanMaterial,
null
);
addBox(
travelDimension,
[0.18, 0.025, 0.025],
[2.51, 0.43, 1.20],
coralMaterial,
null
);
addBox(travelDimension, [0.025, 0.15, 0.025], [2.24, 0.43, 1.20], cyanMaterial, null);
addBox(travelDimension, [0.025, 0.15, 0.025], [2.60, 0.43, 1.20], coralMaterial, null);
// Small stepped voxel arrowheads.
for (let i = 0; i < 3; i++) {
addBox(
travelDimension,
[0.032, 0.025, 0.028 + i * 0.035],
[2.40 + i * 0.035, 0.43, 1.20],
cyanMaterial,
null
);
addBox(
travelDimension,
[0.032, 0.025, 0.028 + i * 0.035],
[2.44 - i * 0.035, 0.43, 1.20],
coralMaterial,
null
);
}
// Screen-space annotations tied to world positions.
const annotationItems = [];
function addAnnotation(text, color, getPosition, offset = [0, 0], optional = false) {
const element = document.createElement("div");
element.className = `annotation${optional ? " optional" : ""}`;
element.style.setProperty("--accent", color);
element.innerHTML = `<span class="dot"></span><span>${text}</span>`;
annotationLayer.appendChild(element);
annotationItems.push({ element, getPosition, offset });
}
addAnnotation(
"INSIDE REF · −0.18",
"#39dcff",
() => new THREE.Vector3(insideHook.position.x, 0.92, -0.54),
[-74, 32]
);
addAnnotation(
"OUTSIDE REF · +0.18",
"#ff6f73",
() => new THREE.Vector3(outsideHook.position.x, 1.68, 0.37),
[78, -30]
);
addAnnotation(
"WORKING HOOK",
"#dce8ee",
() => new THREE.Vector3(actualHook.position.x, 1.12, 0.57),
[88, 10],
true
);
addAnnotation(
"BLOCK EDGE",
"#ffad4a",
() => new THREE.Vector3(2.78, 1.88, 0.48),
[47, -30]
);
addAnnotation(
"MARKED RIBBON",
"#f2c23f",
() => new THREE.Vector3(-1.25, 1.62, 0),
[0, -36],
true
);
addAnnotation(
"ALLOWED TRAVEL",
"#dce8ee",
() => new THREE.Vector3(2.42, 0.30, 1.20),
[0, 34]
);
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = host.clientWidth;
const height = host.clientHeight;
for (const item of annotationItems) {
const world = item.getPosition();
projected.copy(world).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15 &&
!(referenceGroup.visible === false &&
(item.element.textContent.includes("INSIDE") ||
item.element.textContent.includes("OUTSIDE") ||
item.element.textContent.includes("TRAVEL")));
item.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * width + item.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + item.offset[1];
item.element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
// Direct camera controls; no external controls module is used.
const cameraTarget = new THREE.Vector3(0.15, 1.0, 0);
const spherical = new THREE.Spherical(13.1, 1.05, -0.62);
const initialTarget = cameraTarget.clone();
const initialSpherical = spherical.clone();
const initialZoom = camera.zoom;
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTarget.copy(initialTarget);
spherical.copy(initialSpherical);
camera.zoom = initialZoom;
camera.updateProjectionMatrix();
updateCamera();
}
let pointerMode = null;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
pointerMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerMode) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (pointerMode === "orbit") {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi + dy * 0.006, 0.38, 1.42);
} else {
const worldPerPixel =
(camera.top - camera.bottom) / camera.zoom / host.clientHeight;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
cameraTarget
.addScaledVector(right, -dx * worldPerPixel)
.addScaledVector(up, dy * worldPerPixel);
}
updateCamera();
});
function endPointer(event) {
pointerMode = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.45
);
camera.updateProjectionMatrix();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
function resize() {
const width = host.clientWidth;
const height = host.clientHeight;
const aspect = width / height;
const verticalSize = Math.max(7.4, 11.7 / aspect);
camera.left = -verticalSize * aspect / 2;
camera.right = verticalSize * aspect / 2;
camera.top = verticalSize / 2;
camera.bottom = -verticalSize / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
function setHookOffset(value) {
const clamped = THREE.MathUtils.clamp(Number(value), -1, 1);
actualHook.position.x = neutralHookX + clamped * referenceTravel;
travelInput.value = String(clamped);
offsetValue.textContent = `${clamped >= 0 ? "+" : ""}${(clamped * referenceTravel).toFixed(2)} u`;
}
travelInput.addEventListener("input", event => {
setHookOffset(event.target.value);
stopPlayback();
});
let playing = false;
let playbackStart = 0;
function stopPlayback() {
playing = false;
playButton.textContent = "PLAY";
playButton.classList.remove("active");
}
playButton.addEventListener("click", () => {
if (playing) {
stopPlayback();
} else {
playing = true;
playbackStart = performance.now();
playButton.textContent = "PAUSE";
playButton.classList.add("active");
}
});
refsButton.addEventListener("click", () => {
referenceGroup.visible = !referenceGroup.visible;
refsButton.textContent = referenceGroup.visible ? "REFS ON" : "REFS OFF";
refsButton.classList.toggle("active", referenceGroup.visible);
refsButton.setAttribute("aria-pressed", String(referenceGroup.visible));
});
resetButton.addEventListener("click", resetCamera);
resize();
updateCamera();
setHookOffset(0);
function render(now) {
requestAnimationFrame(render);
if (playing) {
const phase = (Math.sin((now - playbackStart) * 0.0022) + 1) / 2;
setHookOffset(phase * 2 - 1);
}
updateAnnotations();
renderer.render(scene, camera);
}
requestAnimationFrame(render);
</script>
</body>
</html>
```