Prompt specification
Build or customize the Three.js 3D scene "Droplet on a solid pedestal" 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: Droplet on a solid pedestal
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/droplet-on-a-solid-pedestal-x1501
Scene Description Prompt:
Create a rounded droplet resting on a surface with a labeled contact angle; distinguish the schematic shape from a complete wetting calculation. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (droplet-on-a-solid-pedestal-x1501):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Droplet Contact Angle — Schematic</title>
<style>
:root {
--ink: #17313d;
--muted: #617680;
--panel: rgba(255, 255, 255, 0.88);
--border: rgba(41, 76, 88, 0.14);
--accent: #f39a3d;
--cyan: #24b6d2;
--shadow: 0 18px 50px rgba(40, 67, 78, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #eaf2f5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
max-width: 460px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #55727e;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1.05;
}
.subtitle {
max-width: 390px;
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.status-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(243, 154, 61, 0.28);
border-radius: 999px;
color: #94551d;
background: rgba(255, 247, 235, 0.82);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.status-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
content: "";
background: var(--accent);
box-shadow: 0 0 0 4px rgba(243, 154, 61, 0.14);
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(130%);
}
.controls {
bottom: 24px;
left: 24px;
width: 330px;
padding: 17px;
}
.panel-title {
margin: 0 0 14px;
color: #46616c;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
margin-bottom: 8px;
}
.control-row label {
font-size: 13px;
font-weight: 720;
}
.angle-output {
color: #b76518;
font-size: 24px;
font-weight: 800;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 24px;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 1px;
color: #82929a;
font-size: 10px;
font-weight: 650;
}
.divider {
height: 1px;
margin: 15px 0;
background: var(--border);
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: #526b75;
font-size: 12px;
}
.check-label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.check-label input {
width: 15px;
height: 15px;
accent-color: var(--cyan);
}
.fixed-note {
margin-top: 11px;
color: #7b8d95;
font-size: 10.5px;
line-height: 1.45;
}
.reset-button {
width: 100%;
margin-top: 13px;
padding: 10px 12px;
border: 1px solid rgba(38, 91, 105, 0.15);
border-radius: 10px;
color: #285563;
background: rgba(228, 242, 246, 0.8);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
.reset-button:hover {
background: rgba(211, 235, 241, 0.95);
transform: translateY(-1px);
}
.info {
top: 24px;
right: 24px;
width: 340px;
padding: 16px 18px;
}
.info summary {
color: #395762;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.08em;
list-style: none;
text-transform: uppercase;
cursor: pointer;
}
.info summary::-webkit-details-marker {
display: none;
}
.info summary::after {
float: right;
content: "+";
color: var(--accent);
font-size: 18px;
line-height: 12px;
}
.info[open] summary::after {
content: "−";
}
.info p {
margin: 13px 0 0;
color: #647983;
font-size: 12px;
line-height: 1.55;
}
.info strong {
color: #31515d;
}
.formula {
margin-top: 12px;
padding: 11px 12px;
border: 1px solid rgba(36, 182, 210, 0.15);
border-radius: 10px;
color: #275665;
background: rgba(226, 244, 248, 0.65);
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
text-align: center;
}
.scope-list {
margin: 11px 0 0;
padding-left: 17px;
color: #647983;
font-size: 11.5px;
line-height: 1.55;
}
.scope-list li + li {
margin-top: 4px;
}
#overlay {
position: fixed;
z-index: 5;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leader {
fill: none;
stroke: rgba(231, 132, 42, 0.72);
stroke-width: 1.3;
stroke-dasharray: 4 4;
}
#contact-dot {
fill: #f39a3d;
stroke: rgba(255, 255, 255, 0.95);
stroke-width: 2.5;
}
.angle-tag {
position: fixed;
z-index: 6;
min-width: 112px;
padding: 8px 11px 9px;
border: 1px solid rgba(238, 139, 43, 0.28);
border-radius: 12px;
color: #87501d;
background: rgba(255, 251, 244, 0.94);
box-shadow: 0 9px 28px rgba(94, 67, 38, 0.14);
text-align: center;
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.angle-tag small {
display: block;
margin-bottom: 1px;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.angle-tag strong {
display: block;
font-size: 21px;
line-height: 1.1;
font-variant-numeric: tabular-nums;
}
.hint {
position: fixed;
z-index: 8;
right: 24px;
bottom: 24px;
padding: 8px 11px;
border: 1px solid rgba(41, 76, 88, 0.1);
border-radius: 999px;
color: #71858e;
background: rgba(255, 255, 255, 0.66);
font-size: 10px;
font-weight: 700;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 760px) {
.header {
top: 14px;
left: 14px;
max-width: calc(100% - 28px);
}
h1 {
font-size: 27px;
}
.subtitle {
max-width: 310px;
font-size: 12px;
}
.info {
top: 154px;
right: 12px;
width: min(315px, calc(100% - 24px));
}
.info p,
.scope-list,
.formula {
font-size: 11px;
}
.controls {
bottom: 12px;
left: 12px;
width: min(330px, calc(100% - 24px));
padding: 14px;
}
.hint {
display: none;
}
}
@media (max-height: 680px) {
.subtitle {
display: none;
}
.info {
width: 300px;
}
}
</style>
</head>
<body>
<header class="header">
<div class="eyebrow">Surface interaction study</div>
<h1>Droplet contact angle</h1>
<p class="subtitle">
An imposed, low-poly spherical-cap illustration of a liquid droplet
meeting a solid surface.
</p>
<div class="status-badge">Schematic — not a wetting solver</div>
</header>
<details class="panel info" open>
<summary>Model scope</summary>
<p>
<strong>The angle and footprint are imposed geometrically.</strong>
This visualization does not solve for a real equilibrium wetting state.
The footprint radius is intentionally held fixed while the angle changes.
</p>
<div class="formula">
cos θ = (γ<sub>SV</sub> − γ<sub>SL</sub>) / γ<sub>LV</sub>
</div>
<ul class="scope-list">
<li>A physical prediction requires measurable interfacial tensions.</li>
<li>Droplet volume, pressure, curvature, and gravity may matter.</li>
<li>Roughness and contact-angle hysteresis can shift the observed value.</li>
<li>Near complete wetting, a film/spreading model may be required.</li>
</ul>
</details>
<section class="panel controls" aria-label="Droplet controls">
<h2 class="panel-title">Imposed geometry</h2>
<div class="control-row">
<label for="angle">Contact angle</label>
<output class="angle-output" id="angle-output" for="angle">62°</output>
</div>
<input
id="angle"
type="range"
min="20"
max="160"
step="1"
value="62"
aria-label="Schematic contact angle"
/>
<div class="range-labels">
<span>20° / shallow</span>
<span>160° / tall</span>
</div>
<div class="divider"></div>
<div class="check-row">
<label class="check-label" for="show-guide">
<input id="show-guide" type="checkbox" checked />
Show angle construction
</label>
<span>θ</span>
</div>
<div class="fixed-note">
Footprint radius: fixed at 1.08 scene units. This is an illustrative cap,
not a volume-conserving wetting solution.
</div>
<button class="reset-button" id="reset" type="button">
Reset scene
</button>
</section>
<svg id="overlay" aria-hidden="true">
<path id="leader"></path>
<circle id="contact-dot" r="4.5"></circle>
</svg>
<div class="angle-tag" id="angle-tag" aria-hidden="true">
<small>Contact angle</small>
<strong id="angle-value">θ = 62°</strong>
</div>
<div class="hint">Drag to orbit · 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";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf2f5);
scene.fog = new THREE.Fog(0xeaf2f5, 11, 24);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
renderer.setSize(window.innerWidth, window.innerHeight);
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional schematic droplet"
);
document.body.prepend(renderer.domElement);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x79919a, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.PointLight(0x76ddf2, 26, 18, 2);
fillLight.position.set(4, 3.2, -3.5);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffd8ac, 12, 12, 2);
warmLight.position.set(-4, 2, -1);
scene.add(warmLight);
// ------------------------------------------------------------
// Surface and low-poly presentation
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
new THREE.MeshStandardMaterial({
color: 0xe4edf0,
roughness: 0.96,
metalness: 0,
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.135;
floor.receiveShadow = true;
scene.add(floor);
const surface = new THREE.Mesh(
new THREE.BoxGeometry(6, 0.12, 4.8),
new THREE.MeshStandardMaterial({
color: 0xcbd9df,
roughness: 0.76,
metalness: 0.02,
flatShading: true,
})
);
surface.position.y = -0.06;
surface.receiveShadow = true;
surface.castShadow = true;
scene.add(surface);
const grid = new THREE.GridHelper(6, 12, 0x819da8, 0xaebfc7);
grid.scale.z = 0.8;
grid.position.y = 0.004;
grid.material.transparent = true;
grid.material.opacity = 0.42;
grid.material.depthWrite = false;
scene.add(grid);
// Small corner markers add a technical, low-poly scene character.
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x7e9aa5,
transparent: true,
opacity: 0.5,
});
for (const x of [-2.72, 2.72]) {
for (const z of [-2.12, 2.12]) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.012, 0.025),
markerMaterial
);
marker.position.set(x, 0.012, z);
scene.add(marker);
}
}
// ------------------------------------------------------------
// Droplet geometry
// ------------------------------------------------------------
const FOOTPRINT_RADIUS = 1.08;
const CONTACT_Y = 0.012;
const RADIAL_SEGMENTS = 40;
const PROFILE_SEGMENTS = 18;
const dropletMaterial = new THREE.MeshPhysicalMaterial({
color: 0x28b8d3,
roughness: 0.27,
metalness: 0,
clearcoat: 0.9,
clearcoatRoughness: 0.22,
ior: 1.333,
emissive: 0x062b35,
emissiveIntensity: 0.09,
flatShading: true,
});
const droplet = new THREE.Mesh(
new THREE.BufferGeometry(),
dropletMaterial
);
droplet.castShadow = true;
droplet.receiveShadow = true;
scene.add(droplet);
// The footprint circle makes the fixed contact radius explicit.
const footprint = new THREE.Mesh(
new THREE.RingGeometry(
FOOTPRINT_RADIUS - 0.014,
FOOTPRINT_RADIUS + 0.014,
48
),
new THREE.MeshBasicMaterial({
color: 0x139eb7,
transparent: true,
opacity: 0.42,
side: THREE.DoubleSide,
depthWrite: false,
})
);
footprint.rotation.x = -Math.PI / 2;
footprint.position.y = 0.01;
footprint.renderOrder = 2;
scene.add(footprint);
/*
Spherical-cap construction:
R = a / sin(theta)
r(phi) = R sin(phi)
y(phi) = R [cos(phi) - cos(theta)]
phi runs from theta at the contact perimeter to zero at the apex.
This is imposed geometry, not a wetting-equilibrium solver.
*/
function createDropletGeometry(angleDegrees) {
const angle = THREE.MathUtils.degToRad(angleDegrees);
const radius = FOOTPRINT_RADIUS / Math.sin(angle);
const points = [];
for (let i = 0; i <= PROFILE_SEGMENTS; i++) {
const phi = angle * (1 - i / PROFILE_SEGMENTS);
const radial = radius * Math.sin(phi);
const height = radius * (Math.cos(phi) - Math.cos(angle));
points.push(
new THREE.Vector2(
Math.max(0.00001, radial),
CONTACT_Y + height
)
);
}
return new THREE.LatheGeometry(
points,
RADIAL_SEGMENTS,
0,
Math.PI * 2
);
}
// ------------------------------------------------------------
// Contact-angle construction
// ------------------------------------------------------------
const guideGroup = new THREE.Group();
scene.add(guideGroup);
const tangentMaterial = new THREE.LineBasicMaterial({
color: 0xf39a3d,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false,
});
const baselineMaterial = new THREE.LineDashedMaterial({
color: 0xf39a3d,
transparent: true,
opacity: 0.72,
dashSize: 0.075,
gapSize: 0.055,
depthTest: false,
depthWrite: false,
});
const arcMaterial = new THREE.LineBasicMaterial({
color: 0xf39a3d,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false,
});
const GUIDE_RADIUS = 0.72;
function guidePoint(angle, polarAngle, radius = GUIDE_RADIUS) {
return new THREE.Vector3(
0,
CONTACT_Y + 0.012 + Math.sin(polarAngle) * radius,
FOOTPRINT_RADIUS + Math.cos(polarAngle) * radius
);
}
function clearGuideGeometry() {
for (const child of guideGroup.children) {
if (child.geometry) {
child.geometry.dispose();
}
}
guideGroup.clear();
}
function rebuildGuide(angleDegrees) {
clearGuideGeometry();
const angle = THREE.MathUtils.degToRad(angleDegrees);
const contact = new THREE.Vector3(0, CONTACT_Y + 0.012, FOOTPRINT_RADIUS);
// Tangent direction into the droplet at the front contact point.
const tangentAngle = Math.PI - angle;
const tangentEnd = new THREE.Vector3(
0,
contact.y + Math.sin(tangentAngle) * GUIDE_RADIUS,
FOOTPRINT_RADIUS + Math.cos(tangentAngle) * GUIDE_RADIUS
);
const tangentLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([contact, tangentEnd]),
tangentMaterial
);
tangentLine.renderOrder = 20;
guideGroup.add(tangentLine);
// Solid-surface ray pointing into the liquid footprint.
const baselineEnd = new THREE.Vector3(
0,
contact.y,
FOOTPRINT_RADIUS - GUIDE_RADIUS
);
const baselineLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([contact, baselineEnd]),
baselineMaterial
);
baselineLine.computeLineDistances();
baselineLine.renderOrder = 20;
guideGroup.add(baselineLine);
// Arc between the interface tangent and the solid ray.
const arcPoints = [];
const arcSteps = 40;
for (let i = 0; i <= arcSteps; i++) {
const t = i / arcSteps;
const polarAngle = tangentAngle + t * angle;
arcPoints.push(guidePoint(angleDegrees, polarAngle));
}
const arcLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
arcMaterial
);
arcLine.renderOrder = 21;
guideGroup.add(arcLine);
}
let currentAngle = 62;
let targetAngle = 62;
let lastBuiltAngle = NaN;
function rebuild(angle) {
const geometry = createDropletGeometry(angle);
droplet.geometry.dispose();
droplet.geometry = geometry;
rebuildGuide(angle);
lastBuiltAngle = angle;
}
rebuild(currentAngle);
// ------------------------------------------------------------
// Direct camera controls — no Three.js examples/addons
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.72, 0),
radius: 7.4,
azimuth: 0.59,
polar: 1.15,
};
function updateCamera() {
const { target, radius, azimuth, polar } = cameraState;
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) {
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.48,
1.43
);
});
function endDrag(event) {
if (event.pointerId !== activePointerId) {
return;
}
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
activePointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.4,
11
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
resetScene();
});
// ------------------------------------------------------------
// Interface elements
// ------------------------------------------------------------
const angleInput = document.querySelector("#angle");
const angleOutput = document.querySelector("#angle-output");
const angleValue = document.querySelector("#angle-value");
const angleTag = document.querySelector("#angle-tag");
const showGuide = document.querySelector("#show-guide");
const resetButton = document.querySelector("#reset");
const leader = document.querySelector("#leader");
const contactDot = document.querySelector("#contact-dot");
angleInput.addEventListener("input", () => {
targetAngle = Number(angleInput.value);
angleOutput.value = `${targetAngle}°`;
});
showGuide.addEventListener("change", () => {
guideGroup.visible = showGuide.checked;
angleTag.style.display = showGuide.checked ? "block" : "none";
leader.style.display = showGuide.checked ? "block" : "none";
contactDot.style.display = showGuide.checked ? "block" : "none";
});
function resetScene() {
targetAngle = 62;
angleInput.value = "62";
angleOutput.value = "62°";
cameraState.target.set(0, 0.72, 0);
cameraState.radius = 7.4;
cameraState.azimuth = 0.59;
cameraState.polar = 1.15;
showGuide.checked = true;
guideGroup.visible = true;
angleTag.style.display = "block";
leader.style.display = "block";
contactDot.style.display = "block";
}
resetButton.addEventListener("click", resetScene);
// ------------------------------------------------------------
// Screen-space annotation
// ------------------------------------------------------------
function projectToScreen(worldPoint) {
const projected = worldPoint.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
z: projected.z,
};
}
function updateAnnotation() {
if (!showGuide.checked) {
return;
}
const angle = THREE.MathUtils.degToRad(currentAngle);
const tangentAngle = Math.PI - angle;
const midAngle = tangentAngle + angle * 0.5;
const arcMid = guidePoint(currentAngle, midAngle);
const contact = new THREE.Vector3(
0,
CONTACT_Y + 0.012,
FOOTPRINT_RADIUS
);
const arcScreen = projectToScreen(arcMid);
const contactScreen = projectToScreen(contact);
let labelX = arcScreen.x + 34;
let labelY = arcScreen.y - 31;
labelX = THREE.MathUtils.clamp(labelX, 76, window.innerWidth - 76);
labelY = THREE.MathUtils.clamp(labelY, 60, window.innerHeight - 60);
angleTag.style.left = `${labelX}px`;
angleTag.style.top = `${labelY}px`;
angleValue.textContent = `θ = ${Math.round(currentAngle)}°`;
leader.setAttribute(
"d",
`M ${arcScreen.x.toFixed(1)} ${arcScreen.y.toFixed(1)}
Q ${((arcScreen.x + labelX) / 2).toFixed(1)}
${Math.min(arcScreen.y, labelY) - 15}
${labelX.toFixed(1)} ${labelY.toFixed(1)}`
);
contactDot.setAttribute("cx", contactScreen.x.toFixed(1));
contactDot.setAttribute("cy", contactScreen.y.toFixed(1));
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-13 * dt);
currentAngle += (targetAngle - currentAngle) * damping;
if (Math.abs(targetAngle - currentAngle) < 0.015) {
currentAngle = targetAngle;
}
if (!Number.isFinite(lastBuiltAngle) ||
Math.abs(currentAngle - lastBuiltAngle) > 0.012) {
rebuild(currentAngle);
}
updateCamera();
updateAnnotation();
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```