Prompt specification
Build or customize the Three.js 3D scene "One Hex Tile and Six Neighbors" 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: One Hex Tile and Six Neighbors
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/one-hex-tile-and-six-neighbors-x3545
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: one hex tile and six neighbors. Display a central hexagonal tile surrounded by six neighbors with coordinate labels. Keep center spacing consistent and show that corner contact does not add extra neighbors.
Working Three.js Starter (one-hex-tile-and-six-neighbors-x3545):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hex Adjacency — Seven Tiles, Six Neighbors</title>
<style>
:root {
color-scheme: dark;
--ink: #eef7ff;
--muted: #91a8bd;
--panel: rgba(9, 20, 35, 0.72);
--border: rgba(156, 195, 226, 0.18);
--cyan: #4be4c1;
--blue: #7591ff;
--amber: #ffc45c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene-root,
#labels {
position: fixed;
inset: 0;
}
#scene-root {
z-index: 0;
}
#scene-root canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene-root canvas:active {
cursor: grabbing;
}
#labels {
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.hud {
position: fixed;
z-index: 4;
top: 24px;
left: 24px;
width: min(440px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid var(--border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(18, 39, 62, 0.86), rgba(7, 17, 31, 0.78));
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 15px rgba(75, 228, 193, 0.8);
content: "";
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 4vw, 2.35rem);
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 16px;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.55;
}
.count-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 15px;
}
.count-chip {
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #c9d9e8;
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.035em;
}
.count-chip strong {
color: white;
}
.legend {
display: grid;
gap: 9px;
padding-top: 14px;
border-top: 1px solid var(--border);
color: #b9cad9;
font-size: 0.76rem;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
}
.swatch {
display: inline-block;
flex: 0 0 auto;
width: 24px;
height: 5px;
border-radius: 999px;
}
.swatch.edge {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 196, 92, 0.45);
}
.swatch.corner {
width: 13px;
height: 13px;
border: 1px dashed var(--amber);
border-radius: 3px;
background: transparent;
}
.cell-label {
position: absolute;
top: 0;
left: 0;
display: flex;
min-width: 52px;
flex-direction: column;
align-items: center;
gap: 2px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 9px;
background: rgba(5, 15, 28, 0.82);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
color: white;
font-size: 0.74rem;
font-weight: 750;
letter-spacing: 0.035em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.cell-label .kind {
color: #aebfd0;
font-size: 0.55rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.cell-label.center {
border-color: rgba(75, 228, 193, 0.6);
background: rgba(7, 48, 48, 0.88);
}
.cell-label.center .kind {
color: var(--cyan);
}
#corner-note {
position: absolute;
top: 0;
left: 0;
min-width: 132px;
padding: 9px 11px;
border: 1px dashed rgba(255, 196, 92, 0.8);
border-radius: 10px;
background: rgba(46, 31, 12, 0.88);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
color: var(--amber);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.06em;
line-height: 1.35;
text-align: center;
text-transform: uppercase;
}
#corner-note strong {
display: block;
color: #fff0d1;
font-size: 0.72rem;
letter-spacing: 0.015em;
text-transform: none;
}
.controls {
position: fixed;
z-index: 5;
right: 22px;
bottom: 22px;
display: flex;
gap: 8px;
padding: 8px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
.controls button {
width: 40px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
color: white;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
.controls button:hover {
background: rgba(75, 228, 193, 0.14);
transform: translateY(-1px);
}
.controls button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.formula {
position: fixed;
z-index: 4;
left: 24px;
bottom: 24px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(7, 17, 31, 0.6);
color: #849bb0;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 0.68rem;
pointer-events: none;
backdrop-filter: blur(9px);
}
#loading {
position: fixed;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #07111f;
color: var(--cyan);
font-size: 0.75rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
@media (max-width: 700px) {
.hud {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px;
}
.intro {
margin-bottom: 12px;
font-size: 0.8rem;
}
.legend {
display: none;
}
.formula {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="scene-root"></div>
<div id="labels" aria-hidden="true"></div>
<section class="hud">
<div class="eyebrow">Axial coordinates / hex adjacency</div>
<h1>Seven tiles.<br />Six neighbors.</h1>
<p class="intro">
Only edge-sharing cells around the center are counted. The dashed outline
touches one tile at a single vertex, so it does not create an extra neighbor.
</p>
<div class="count-row">
<span class="count-chip"><strong>1</strong> center</span>
<span class="count-chip">+</span>
<span class="count-chip"><strong>6</strong> edge neighbors</span>
<span class="count-chip"><strong>7</strong> counted</span>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch edge"></span>
Gold bands mark shared edges with the center.
</div>
<div class="legend-item">
<span class="swatch corner"></span>
A vertex-only touch is excluded from the count.
</div>
</div>
</section>
<div class="formula">
center(q,r) → (3Rq/2, √3R(r + q/2))
</div>
<div class="controls" aria-label="Camera controls">
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="reset" type="button" aria-label="Reset camera">↺</button>
</div>
<div id="loading">Building hex field…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const root = document.getElementById("scene-root");
const labelLayer = document.getElementById("labels");
const RADIUS = 1.2;
const TILE_HEIGHT = 0.42;
const BASE_HEIGHT = 0.055;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.021);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D hex grid with one center tile and six neighbors"
);
renderer.domElement.tabIndex = 0;
root.appendChild(renderer.domElement);
// ---------------------------------------------------------------------
// Lighting and environment
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc8e8ff, 0x07101b, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x587dff, 1.55);
rimLight.position.set(-7, 4, -5);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(0x38e7c5, 24, 16, 2);
cyanLight.position.set(-4, 3.5, 3);
scene.add(cyanLight);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(7.8, 96),
new THREE.MeshStandardMaterial({
color: 0x091728,
roughness: 0.94,
metalness: 0.04
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.set(0.7, -0.035, 0);
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(16, 32, 0x41627f, 0x24394f);
grid.position.set(0.7, -0.024, 0);
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
// ---------------------------------------------------------------------
// Custom flat-shaded hexagonal prism geometry
// ---------------------------------------------------------------------
function createHexPrismGeometry(radius, height) {
const ring = [];
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
ring.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0,
Math.sin(angle) * radius
)
);
}
const topPositions = [];
const sidePositions = [];
const topCenter = new THREE.Vector3(0, height, 0);
const bottomCenter = new THREE.Vector3(0, 0, 0);
function pushTriangle(target, a, b, c) {
target.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
}
for (let i = 0; i < 6; i++) {
const next = (i + 1) % 6;
// Top cap: upward-facing winding.
pushTriangle(topPositions, topCenter, ring[next], ring[i]);
// Bottom cap.
pushTriangle(sidePositions, bottomCenter, ring[i], ring[next]);
// Two triangles for each vertical side.
const bottomCurrent = ring[i].clone();
const bottomNext = ring[next].clone();
const topCurrent = ring[i].clone().setY(height);
const topNext = ring[next].clone().setY(height);
pushTriangle(sidePositions, bottomCurrent, topCurrent, topNext);
pushTriangle(sidePositions, bottomCurrent, topNext, bottomNext);
}
const positions = new Float32Array([
...topPositions,
...sidePositions
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const topVertexCount = topPositions.length / 3;
const sideVertexCount = sidePositions.length / 3;
geometry.addGroup(0, topVertexCount, 0);
geometry.addGroup(topVertexCount, sideVertexCount, 1);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const prismGeometry = createHexPrismGeometry(RADIUS, TILE_HEIGHT);
const centerTopMaterial = new THREE.MeshStandardMaterial({
color: 0x35d8b5,
emissive: 0x075b4e,
emissiveIntensity: 0.32,
roughness: 0.38,
metalness: 0.18
});
const centerSideMaterial = new THREE.MeshStandardMaterial({
color: 0x0c655e,
emissive: 0x032b2a,
emissiveIntensity: 0.2,
roughness: 0.5,
metalness: 0.22,
flatShading: true
});
const neighborTopMaterials = [
new THREE.MeshStandardMaterial({
color: 0x6685f7,
emissive: 0x17265d,
emissiveIntensity: 0.18,
roughness: 0.42,
metalness: 0.16
}),
new THREE.MeshStandardMaterial({
color: 0x728fff,
emissive: 0x182965,
emissiveIntensity: 0.16,
roughness: 0.42,
metalness: 0.16
})
];
const neighborSideMaterial = new THREE.MeshStandardMaterial({
color: 0x192c54,
emissive: 0x07132a,
emissiveIntensity: 0.14,
roughness: 0.56,
metalness: 0.2,
flatShading: true
});
// Exact flat-top axial layout. Every position comes from the same formula.
function axialToXZ(q, r) {
return {
x: RADIUS * 1.5 * q,
z: RADIUS * Math.sqrt(3) * (r + q / 2)
};
}
const cells = [
{ q: 0, r: 0, center: true },
{ q: 1, r: 0 },
{ q: 0, r: 1 },
{ q: -1, r: 1 },
{ q: -1, r: 0 },
{ q: 0, r: -1 },
{ q: 1, r: -1 }
];
const labelEntries = [];
const centerRimMaterial = new THREE.LineBasicMaterial({
color: 0xb6fff0,
transparent: true,
opacity: 0.95
});
const neighborRimMaterial = new THREE.LineBasicMaterial({
color: 0xb7c8ff,
transparent: true,
opacity: 0.58
});
cells.forEach((cell, index) => {
const { x, z } = axialToXZ(cell.q, cell.r);
const tile = new THREE.Mesh(
prismGeometry,
cell.center
? [centerTopMaterial, centerSideMaterial]
: [
neighborTopMaterials[index % 2],
neighborSideMaterial
]
);
tile.position.set(x, BASE_HEIGHT, z);
tile.castShadow = true;
tile.receiveShadow = true;
scene.add(tile);
// Crisp upper rim.
const rimPoints = [];
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
rimPoints.push(
new THREE.Vector3(
Math.cos(angle) * RADIUS,
TILE_HEIGHT + 0.025,
Math.sin(angle) * RADIUS
)
);
}
const rim = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(rimPoints),
cell.center ? centerRimMaterial : neighborRimMaterial
);
rim.position.set(x, BASE_HEIGHT, z);
scene.add(rim);
// A subtle inset on the upper face.
const inset = new THREE.Mesh(
new THREE.CircleGeometry(RADIUS * 0.76, 6),
new THREE.MeshBasicMaterial({
color: cell.center ? 0xc4fff2 : 0xe1e8ff,
transparent: true,
opacity: cell.center ? 0.1 : 0.055,
depthWrite: false,
side: THREE.DoubleSide
})
);
inset.rotation.x = -Math.PI / 2;
inset.position.set(x, BASE_HEIGHT + TILE_HEIGHT + 0.008, z);
scene.add(inset);
// HTML coordinate label projected from a 3D anchor.
const label = document.createElement("div");
label.className = `cell-label${cell.center ? " center" : ""}`;
label.innerHTML = cell.center
? '<span class="kind">Center</span><b>(0, 0)</b>'
: `<span class="kind">Neighbor</span><b>(${cell.q}, ${cell.r})</b>`;
labelLayer.appendChild(label);
labelEntries.push({
element: label,
anchor: new THREE.Vector3(
x,
BASE_HEIGHT + TILE_HEIGHT + 0.22,
z
)
});
});
// ---------------------------------------------------------------------
// Highlight the six edges shared by the center and its neighbors
// ---------------------------------------------------------------------
const sharedEdgeMaterial = new THREE.MeshBasicMaterial({
color: 0xffc45c
});
cells.slice(1).forEach(({ q, r }) => {
const { x, z } = axialToXZ(q, r);
const direction = Math.atan2(z, x);
const halfEdge = Math.PI / 6;
const start = new THREE.Vector3(
Math.cos(direction - halfEdge) * RADIUS,
BASE_HEIGHT + TILE_HEIGHT + 0.04,
Math.sin(direction - halfEdge) * RADIUS
);
const end = new THREE.Vector3(
Math.cos(direction + halfEdge) * RADIUS,
BASE_HEIGHT + TILE_HEIGHT + 0.04,
Math.sin(direction + halfEdge) * RADIUS
);
const delta = end.clone().sub(start);
const sharedEdge = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, delta.length(), 10),
sharedEdgeMaterial
);
sharedEdge.position.copy(start).add(end).multiplyScalar(0.5);
sharedEdge.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
delta.clone().normalize()
);
scene.add(sharedEdge);
});
// ---------------------------------------------------------------------
// Dashed corner-only candidate: visually touches one tile, but is excluded
// ---------------------------------------------------------------------
const touchedCell = axialToXZ(1, 0);
const ghostCenterX = touchedCell.x + RADIUS * 2;
const ghostCenterZ = touchedCell.z;
const ghostSegments = [];
const ghostRing = [];
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
ghostRing.push(
new THREE.Vector3(
Math.cos(angle) * RADIUS,
0,
Math.sin(angle) * RADIUS
)
);
}
for (let i = 0; i < 6; i++) {
const next = (i + 1) % 6;
const a = ghostRing[i];
const b = ghostRing[next];
// Top outline.
ghostSegments.push(
a.x, TILE_HEIGHT + 0.015, a.z,
b.x, TILE_HEIGHT + 0.015, b.z
);
// Bottom outline.
ghostSegments.push(
a.x, 0.015, a.z,
b.x, 0.015, b.z
);
// Vertical corner struts.
ghostSegments.push(
a.x, 0.015, a.z,
a.x, TILE_HEIGHT + 0.015, a.z
);
}
const ghostGeometry = new THREE.BufferGeometry();
ghostGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(ghostSegments, 3)
);
const ghost = new THREE.LineSegments(
ghostGeometry,
new THREE.LineDashedMaterial({
color: 0xffbd50,
dashSize: 0.11,
gapSize: 0.075,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
ghost.position.set(ghostCenterX, BASE_HEIGHT, ghostCenterZ);
ghost.computeLineDistances();
ghost.renderOrder = 2;
scene.add(ghost);
// The exact single point where the ghost outline touches the neighbor.
const contactPoint = new THREE.Vector3(
touchedCell.x + RADIUS,
BASE_HEIGHT + TILE_HEIGHT + 0.07,
touchedCell.z
);
const contactMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 18, 12),
new THREE.MeshBasicMaterial({ color: 0xffc45c })
);
contactMarker.position.copy(contactPoint);
scene.add(contactMarker);
const cornerNote = document.createElement("div");
cornerNote.id = "corner-note";
cornerNote.innerHTML = "Vertex only<strong>not a neighbor</strong>";
labelLayer.appendChild(cornerNote);
// ---------------------------------------------------------------------
// Camera controls implemented directly, without addons
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0.72, 0.1, 0),
theta: 0.62,
phi: 1.04,
radius: 14.5
};
function defaultRadius() {
if (window.innerWidth < 700) return 20;
if (window.innerWidth < 1000) return 17;
return 14.5;
}
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
controls.radius,
controls.phi,
controls.theta
);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetCamera() {
controls.target.set(0.72, 0.1, 0);
controls.theta = 0.62;
controls.phi = 1.04;
controls.radius = defaultRadius();
updateCamera();
}
function zoom(factor) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * factor,
7,
28
);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.38,
1.42
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (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();
zoom(Math.exp(event.deltaY * 0.001));
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("zoom-in").addEventListener("click", () => {
zoom(0.85);
});
document.getElementById("zoom-out").addEventListener("click", () => {
zoom(1.15);
});
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
controls.theta -= 0.12;
break;
case "ArrowRight":
controls.theta += 0.12;
break;
case "ArrowUp":
controls.phi = Math.max(0.38, controls.phi - 0.08);
break;
case "ArrowDown":
controls.phi = Math.min(1.42, controls.phi + 0.08);
break;
case "+":
case "=":
zoom(0.88);
break;
case "-":
zoom(1.12);
break;
case "0":
resetCamera();
break;
default:
return;
}
event.preventDefault();
});
// ---------------------------------------------------------------------
// Project DOM labels from their Three.js world positions
// ---------------------------------------------------------------------
function positionLabel(element, worldPosition, extraX = 0, extraY = 0) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate3d(${x + extraX}px, ${y + extraY}px, 0) ` +
"translate(-50%, -50%)";
}
function updateLabels() {
labelEntries.forEach(({ element, anchor }) => {
positionLabel(element, anchor);
});
positionLabel(cornerNote, contactPoint, 18, -10);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
controls.radius = defaultRadius();
updateCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.13;
contactMarker.scale.setScalar(pulse);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
const loading = document.getElementById("loading");
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 260);
</script>
</body>
</html>
```