Prompt specification
Build or customize the Three.js 3D scene "Impact Crater Rim and Central Depression" 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: Impact Crater Rim and Central Depression
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/impact-crater-rim-and-central-depression-x3809
Scene Description Prompt:
Model a schematic impact crater cross-section with rim, bowl, and ejecta region. Label the structure as representative and avoid implying all craters share identical proportions. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (impact-crater-rim-and-central-depression-x3809):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Representative Impact Crater Cross-Section</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(10, 19, 31, 0.84);
--line: rgba(183, 211, 232, 0.18);
--text: #eef6fb;
--muted: #aebdca;
--accent: #e3b171;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #08111c;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.info-panel {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(21px, 3vw, 30px);
font-weight: 650;
line-height: 1.12;
letter-spacing: -0.025em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.disclaimer {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #c4d0da;
font-size: 12px;
line-height: 1.52;
}
.disclaimer strong {
color: var(--accent);
font-weight: 700;
}
.toolbar {
position: fixed;
z-index: 20;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
}
button {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(10, 19, 31, 0.84);
color: var(--text);
font: inherit;
font-size: 12px;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
border-color: rgba(227, 177, 113, 0.65);
color: #ffe1b9;
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
#leaders {
position: fixed;
z-index: 5;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#labels {
position: fixed;
z-index: 6;
inset: 0;
pointer-events: none;
}
.callout {
position: absolute;
width: max-content;
max-width: 190px;
padding: 9px 12px;
border: 1px solid rgba(211, 226, 238, 0.22);
border-radius: 10px;
background: rgba(8, 17, 28, 0.88);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
transform: translate(-50%, -50%);
backdrop-filter: blur(10px);
}
.callout strong {
display: block;
color: #f3f7fa;
font-size: 13px;
font-weight: 700;
}
.callout span {
display: block;
margin-top: 2px;
color: #aebdca;
font-size: 10px;
line-height: 1.35;
}
.hint {
position: fixed;
z-index: 10;
right: 24px;
bottom: 20px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(8, 17, 28, 0.72);
color: #9fb0be;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.scale-note {
position: fixed;
z-index: 10;
bottom: 20px;
left: 24px;
color: #9fb0be;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 680px) {
.info-panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.toolbar {
top: auto;
right: 14px;
bottom: 52px;
}
.hint {
display: none;
}
.scale-note {
left: 14px;
bottom: 14px;
}
.callout {
max-width: 145px;
padding: 7px 9px;
}
.callout strong {
font-size: 11px;
}
.callout span {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional schematic of an impact crater"></canvas>
<header class="info-panel">
<div class="eyebrow">Schematic cutaway · not to scale</div>
<h1>Representative impact crater</h1>
<p class="subtitle">
The near half is removed to expose the raised rim, excavated bowl,
and outer ejecta blanket.
</p>
<div class="disclaimer">
<strong>Representative geometry, not a universal template.</strong>
Crater diameter, depth, wall slope, rim height, layer thickness, and
ejecta extent vary among real impact craters.
</div>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" type="button">Hide labels</button>
</nav>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<div class="scale-note">Schematic · vertical proportions may be exaggerated</div>
<div class="hint">
Drag to orbit · Shift-drag or right-drag to pan · Scroll to zoom
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const leadersLayer = document.querySelector("#leaders");
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111c);
scene.fog = new THREE.Fog(0x08111c, 19, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xd8ecff, 0x352419, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.1);
keyLight.position.set(-4.5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8fb9dc, 0.8);
fillLight.position.set(8, 4, -7);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, and zoom without addons
// -------------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(0, -0.45, -1.7),
radius: 16.0,
theta: 0.48,
phi: 1.12
};
const view = {
target: defaultView.target.clone(),
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
function resetView() {
view.target.copy(defaultView.target);
view.radius = defaultView.radius;
view.theta = defaultView.theta;
view.phi = defaultView.phi;
updateCamera();
}
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
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;
const panning = event.shiftKey || event.buttons === 2;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const scale = view.radius / window.innerHeight * 0.8;
view.target.addScaledVector(right, -dx * scale);
view.target.addScaledVector(up, dy * scale);
} else {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.005,
0.32,
1.47
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
7.5,
24
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", resetView);
let labelsVisible = true;
const toggleButton = document.querySelector("#toggle-labels");
toggleButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsLayer.style.display = labelsVisible ? "block" : "none";
leadersLayer.style.display = labelsVisible ? "block" : "none";
toggleButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
// -------------------------------------------------------------------------
// Crater profile
//
// Only the rear half of a radial crater is modeled. The front face at z=0
// is the exposed cross-section.
// -------------------------------------------------------------------------
const halfWidth = 7.2;
const modelDepth = 6.2;
const bottomY = -3.0;
const xDivisions = 40;
const zDivisions = 30;
function smoothstep(min, max, value) {
const t = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
function radialHeight(radius) {
if (radius < 3.25) {
// Gently curved crater floor.
return -1.25 + 0.09 * radius * radius;
}
if (radius < 4.25) {
// Steep bowl wall rising to the rim.
const t = smoothstep(3.25, 4.25, radius);
return THREE.MathUtils.lerp(-0.299, 0.82, t);
}
if (radius < 6.4) {
// Broad, declining ejecta blanket.
const t = smoothstep(4.25, 6.4, radius);
return THREE.MathUtils.lerp(0.82, 0.03, t);
}
return 0.03;
}
function surfaceHeight(x, z) {
const radius = Math.hypot(x, z);
let height = radialHeight(radius);
const roughness =
Math.sin(x * 2.17 + z * 1.31) * 0.055 +
Math.sin(x * 5.31 - z * 3.77) * 0.025;
if (radius < 3.2) {
height += roughness * 0.03;
} else if (radius < 4.3) {
height += roughness;
} else {
height += roughness * 0.75;
}
return height;
}
const terrainColors = {
floor: new THREE.Color(0x766f67),
bowl: new THREE.Color(0x8b7c6d),
wall: new THREE.Color(0x967554),
rim: new THREE.Color(0xc19a67),
ejecta: new THREE.Color(0x9d805d)
};
function colorForRadius(radius) {
const color = new THREE.Color();
if (radius < 3.25) {
color
.copy(terrainColors.floor)
.lerp(terrainColors.bowl, smoothstep(1.5, 3.25, radius));
} else if (radius < 4.25) {
color
.copy(terrainColors.bowl)
.lerp(terrainColors.wall, smoothstep(3.25, 4.25, radius));
} else {
color
.copy(terrainColors.rim)
.lerp(
terrainColors.ejecta,
smoothstep(4.25, 6.8, radius)
);
}
return color;
}
// -------------------------------------------------------------------------
// Faceted terrain surface
// -------------------------------------------------------------------------
const terrainPositions = [];
const terrainFaceColors = [];
function pushTerrainTriangle(a, b, c, color) {
terrainPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
terrainFaceColors.push(color.r, color.g, color.b);
}
}
const dx = (halfWidth * 2) / xDivisions;
const dz = modelDepth / zDivisions;
for (let ix = 0; ix < xDivisions; ix++) {
const x0 = -halfWidth + ix * dx;
const x1 = x0 + dx;
for (let iz = 0; iz < zDivisions; iz++) {
const z0 = -iz * dz;
const z1 = -(iz + 1) * dz;
const a = new THREE.Vector3(
x0,
surfaceHeight(x0, z0),
z0
);
const b = new THREE.Vector3(
x1,
surfaceHeight(x1, z0),
z0
);
const c = new THREE.Vector3(
x1,
surfaceHeight(x1, z1),
z1
);
const d = new THREE.Vector3(
x0,
surfaceHeight(x0, z1),
z1
);
const centerRadius =
Math.hypot(
(x0 + x1) * 0.5,
(z0 + z1) * 0.5
);
const color = colorForRadius(centerRadius);
color.multiplyScalar(0.91 + Math.random() * 0.16);
// Alternate diagonal directions to enhance the low-poly appearance.
if ((ix + iz) % 2 === 0) {
pushTerrainTriangle(a, b, d, color);
pushTerrainTriangle(b, c, d, color);
} else {
pushTerrainTriangle(a, b, c, color);
pushTerrainTriangle(a, c, d, color);
}
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainFaceColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.98,
metalness: 0
});
const terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
// -------------------------------------------------------------------------
// Exposed cross-section and block sides
// -------------------------------------------------------------------------
const profileX = [];
const profileTop = [];
for (let i = 0; i <= xDivisions; i++) {
const x = -halfWidth + i * dx;
profileX.push(x);
profileTop.push(surfaceHeight(x, 0));
}
function createFrontStrip(lowerValues, upperValues, z, color) {
const positions = [];
const colors = [];
function triangle(a, b, c) {
positions.push(...a, ...b, ...c);
const shade = color.clone().multiplyScalar(
0.94 + Math.random() * 0.09
);
for (let i = 0; i < 3; i++) {
colors.push(shade.r, shade.g, shade.b);
}
}
for (let i = 0; i < profileX.length - 1; i++) {
const x0 = profileX[i];
const x1 = profileX[i + 1];
const a = [x0, lowerValues[i], z];
const b = [x1, lowerValues[i + 1], z];
const c = [x1, upperValues[i + 1], z];
const d = [x0, upperValues[i], z];
triangle(a, b, d);
triangle(b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
const capLower = profileTop.map((value) => value - 0.44);
const bedrockUpper = profileTop.map((value) => value - 0.44);
const bedrockLower = profileTop.map(() => bottomY);
// Upper weathered/regolith strip.
createFrontStrip(
capLower,
profileTop,
0.014,
new THREE.Color(0xb98257)
);
// Underlying country-rock section.
createFrontStrip(
bedrockLower,
bedrockUpper,
0.008,
new THREE.Color(0x625d55)
);
function createVerticalQuad(
p0,
p1,
p2,
p3,
color,
material
) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[...p0, ...p1, ...p2, ...p0, ...p2, ...p3],
3
)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
const sideMaterial = new THREE.MeshStandardMaterial({
color: 0x504b45,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
// Rear wall.
for (let i = 0; i < xDivisions; i++) {
const x0 = profileX[i];
const x1 = profileX[i + 1];
const z = -modelDepth;
createVerticalQuad(
[x0, bottomY, z],
[x1, bottomY, z],
[x1, surfaceHeight(x1, z), z],
[x0, surfaceHeight(x0, z), z],
null,
sideMaterial
);
}
// Left and right side walls.
for (const x of [-halfWidth, halfWidth]) {
for (let i = 0; i < zDivisions; i++) {
const z0 = -i * dz;
const z1 = -(i + 1) * dz;
createVerticalQuad(
[x, bottomY, z0],
[x, bottomY, z1],
[x, surfaceHeight(x, z1), z1],
[x, surfaceHeight(x, z0), z0],
null,
sideMaterial
);
}
}
// Thin base closes the geological block.
const base = new THREE.Mesh(
new THREE.BoxGeometry(
halfWidth * 2,
0.25,
modelDepth
),
new THREE.MeshStandardMaterial({
color: 0x30373b,
roughness: 0.88,
metalness: 0.05
})
);
base.position.set(0, bottomY - 0.125, -modelDepth * 0.5);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// -------------------------------------------------------------------------
// Low-poly ejecta fragments
// -------------------------------------------------------------------------
const rockGeometry = new THREE.IcosahedronGeometry(1, 0);
const rockMaterials = [
new THREE.MeshStandardMaterial({
color: 0x9d754e,
flatShading: true,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0xb18a61,
flatShading: true,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0x806047,
flatShading: true,
roughness: 1
})
];
for (let i = 0; i < 42; i++) {
const angle = Math.PI + Math.random() * Math.PI;
const radius = 4.45 + Math.random() * 2.0;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
if (Math.abs(x) > halfWidth - 0.12 || z < -modelDepth + 0.15) {
continue;
}
const scale = 0.08 + Math.random() * 0.18;
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[i % rockMaterials.length]
);
rock.position.set(
x,
surfaceHeight(x, z) + scale * 0.35,
z
);
rock.scale.set(
scale * (0.8 + Math.random() * 0.8),
scale * (0.5 + Math.random() * 0.7),
scale * (0.8 + Math.random() * 0.8)
);
rock.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// Display ground, shadow catcher, and reference grid
// -------------------------------------------------------------------------
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.ShadowMaterial({
color: 0x000000,
opacity: 0.28
})
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -3.28;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
const grid = new THREE.GridHelper(22, 22, 0x668092, 0x344756);
grid.position.set(0, -3.27, -modelDepth * 0.5);
grid.material.transparent = true;
grid.material.opacity = 0.18;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Projected feature labels
// -------------------------------------------------------------------------
const features = [
{
title: "Rim",
subtitle: "Raised crater crest",
point: new THREE.Vector3(
4.22,
surfaceHeight(4.22, 0) + 0.1,
0.04
),
offset: new THREE.Vector2(145, -88)
},
{
title: "Bowl",
subtitle: "Excavated crater floor",
point: new THREE.Vector3(
0,
surfaceHeight(0, 0) + 0.05,
0.04
),
offset: new THREE.Vector2(-155, 92)
},
{
title: "Ejecta region",
subtitle: "Outer debris blanket",
point: new THREE.Vector3(
5.7,
surfaceHeight(5.7, 0) + 0.12,
0.04
),
offset: new THREE.Vector2(120, 62)
}
];
const svgNamespace = "http://www.w3.org/2000/svg";
for (const feature of features) {
const element = document.createElement("div");
element.className = "callout";
element.innerHTML = `
<strong>${feature.title}</strong>
<span>${feature.subtitle}</span>
`;
labelsLayer.appendChild(element);
const line = document.createElementNS(svgNamespace, "line");
line.setAttribute("stroke", "#d5e1e8");
line.setAttribute("stroke-width", "1.2");
line.setAttribute("stroke-opacity", "0.72");
line.setAttribute("vector-effect", "non-scaling-stroke");
leadersLayer.appendChild(line);
const dot = document.createElementNS(svgNamespace, "circle");
dot.setAttribute("r", "3.2");
dot.setAttribute("fill", "#e3b171");
dot.setAttribute("stroke", "#08111c");
dot.setAttribute("stroke-width", "1.5");
leadersLayer.appendChild(dot);
feature.element = element;
feature.line = line;
feature.dot = dot;
}
function updateLabels() {
if (!labelsVisible) return;
const width = window.innerWidth;
const height = window.innerHeight;
const compactScale = Math.min(1, width / 900);
for (const feature of features) {
const projected = feature.point.clone().project(camera);
const targetX = (projected.x * 0.5 + 0.5) * width;
const targetY = (-projected.y * 0.5 + 0.5) * height;
const cardWidth = feature.element.offsetWidth;
const cardHeight = feature.element.offsetHeight;
const desiredX =
targetX + feature.offset.x * compactScale;
const desiredY =
targetY + feature.offset.y * compactScale;
const centerX = THREE.MathUtils.clamp(
desiredX,
cardWidth * 0.5 + 12,
width - cardWidth * 0.5 - 12
);
const centerY = THREE.MathUtils.clamp(
desiredY,
cardHeight * 0.5 + 12,
height - cardHeight * 0.5 - 12
);
feature.element.style.left = `${centerX}px`;
feature.element.style.top = `${centerY}px`;
const lineEndX = THREE.MathUtils.clamp(
targetX,
centerX - cardWidth * 0.5,
centerX + cardWidth * 0.5
);
const lineEndY = THREE.MathUtils.clamp(
targetY,
centerY - cardHeight * 0.5,
centerY + cardHeight * 0.5
);
feature.line.setAttribute("x1", targetX);
feature.line.setAttribute("y1", targetY);
feature.line.setAttribute("x2", lineEndX);
feature.line.setAttribute("y2", lineEndY);
feature.dot.setAttribute("cx", targetX);
feature.dot.setAttribute("cy", targetY);
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```