Prompt specification
Build or customize the Three.js 3D scene "Basket Hoop With Launch Vector Guide" 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: Basket Hoop With Launch Vector Guide
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/basket-hoop-with-launch-vector-guide-x3625
Scene Description Prompt:
Show a low-poly basketball hoop, backboard, and launch point with velocity arrow, target height, and distance. One HTML file using Three.js from cdnjs.
Working Three.js Starter (basket-hoop-with-launch-vector-guide-x3625):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Low-Poly Basketball Shot Analyzer</title>
<style>
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1220;
font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
#app { position: fixed; inset: 0; }
canvas { display: block; }
.panel {
position: fixed; padding: 16px 18px; border-radius: 14px;
background: rgba(13, 22, 40, .72); backdrop-filter: blur(9px);
border: 1px solid rgba(148, 163, 184, .22); color: #e2e8f0;
box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
#hud { top: 18px; left: 18px; min-width: 236px; }
#hud h1 { margin: 0 0 2px; font-size: 15px; letter-spacing: .12em; text-transform: uppercase; }
#hud h1 span { color: #f97316; }
#hud .sub { font-size: 11px; color: #94a3b8; letter-spacing: .06em; margin-bottom: 12px; }
.row { display: flex; align-items: center; justify-content: space-between;
font-size: 12.5px; padding: 4px 0; border-top: 1px solid rgba(148,163,184,.12); }
.row b { font-variant-numeric: tabular-nums; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; display: inline-block; }
.lbl { display: flex; align-items: center; color: #cbd5e1; }
.c-cyan { background: #22d3ee; } .c-vio { background: #a78bfa; }
.c-yel { background: #facc15; } .c-org { background: #fb923c; } .c-wht { background: #f8fafc; }
#hint { bottom: 16px; right: 18px; font-size: 11.5px; color: #94a3b8; letter-spacing: .04em; }
#hint kbd { background: rgba(148,163,184,.18); border-radius: 5px; padding: 2px 6px;
border: 1px solid rgba(148,163,184,.25); font-size: 11px; color: #e2e8f0; }
@media (max-width: 620px) { #hud { transform: scale(.86); transform-origin: top left; } }
</style>
</head>
<body>
<div id="app"></div>
<div id="hud" class="panel">
<h1>Low-Poly <span>Hoop</span> Lab</h1>
<div class="sub">SHOT VECTOR & DIMENSION ANALYSIS</div>
<div class="row"><span class="lbl"><i class="dot c-cyan"></i>Target height</span><b id="vH">—</b></div>
<div class="row"><span class="lbl"><i class="dot c-vio"></i>Horizontal distance</span><b id="vD">—</b></div>
<div class="row"><span class="lbl"><i class="dot c-yel"></i>Release speed</span><b id="vV">—</b></div>
<div class="row"><span class="lbl"><i class="dot c-org"></i>Launch angle</span><b id="vA">—</b></div>
<div class="row"><span class="lbl"><i class="dot c-wht"></i>Flight time</span><b id="vT">—</b></div>
<div class="row"><span class="lbl"><i class="dot c-org"></i>Apex height</span><b id="vX">—</b></div>
</div>
<div id="hint" class="panel">
<kbd>Drag</kbd> orbit · <kbd>Wheel</kbd> zoom · <kbd>Shift+Drag</kbd> / <kbd>Right-Drag</kbd> pan
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================
0. RENDERER / SCENE
============================================================ */
const app = document.getElementById('app');
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1220);
scene.fog = new THREE.Fog(0x0b1220, 34, 78);
const camera = new THREE.PerspectiveCamera(48, innerWidth / innerHeight, 0.1, 250);
/* ============================================================
1. LIGHTS
============================================================ */
scene.add(new THREE.HemisphereLight(0xbfe3ff, 0x53412c, 0.9));
const sun = new THREE.DirectionalLight(0xfff3e0, 2.1);
sun.position.set(9, 16, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16; sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16; sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 2; sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0006;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x7dd3fc, 0.55);
rimLight.position.set(-8, 6, -9);
scene.add(rimLight);
/* ============================================================
2. COURT
============================================================ */
const courtMat = new THREE.MeshStandardMaterial({ color: 0xc2874a, roughness: 0.92, metalness: 0.0 });
const slab = new THREE.Mesh(new THREE.BoxGeometry(26, 0.2, 22), courtMat);
slab.position.set(0, -0.1, 4);
slab.receiveShadow = true;
scene.add(slab);
// faint grid for scale
const grid = new THREE.GridHelper(26, 26, 0x334155, 0x243349);
grid.position.y = 0.012;
grid.material.transparent = true; grid.material.opacity = 0.30;
scene.add(grid);
const lineMat = new THREE.LineBasicMaterial({ color: 0xf5f1e6, transparent: true, opacity: 0.92 });
function courtLine(pts, closed = false) {
const g = new THREE.BufferGeometry().setFromPoints(pts.map(p => new THREE.Vector3(...p)));
const l = closed ? new THREE.LineLoop(g, lineMat) : new THREE.Line(g, lineMat);
l.position.y = 0.02;
scene.add(l);
return l;
}
function circleLine(cx, cz, r, seg = 56, y = 0.02) {
const p = [];
for (let i = 0; i < seg; i++) { const a = i / seg * Math.PI * 2; p.push([cx + Math.cos(a) * r, y, cz + Math.sin(a) * r]); }
return courtLine(p, true);
}
// painted key
const keyMat = new THREE.MeshStandardMaterial({ color: 0x2f5f96, roughness: 0.95 });
const key = new THREE.Mesh(new THREE.PlaneGeometry(4.9, 5.0), keyMat);
key.rotation.x = -Math.PI / 2; key.position.set(0, 0.015, 2.2);
key.receiveShadow = true; scene.add(key);
courtLine([[-2.45, 0, -0.3], [-2.45, 0, 4.7]]);
courtLine([[ 2.45, 0, -0.3], [ 2.45, 0, 4.7]]);
courtLine([[-2.45, 0, 4.7], [ 2.45, 0, 4.7]]);
courtLine([[-2.45, 0, -0.3], [ 2.45, 0, -0.3]]);
circleLine(0, 4.7, 1.8);
// free-throw semicircle (filled)
const ftDisc = new THREE.Mesh(new THREE.CircleGeometry(1.8, 40, Math.PI / 2, Math.PI),
new THREE.MeshStandardMaterial({ color: 0x2f5f96, roughness: 0.95 }));
ftDisc.rotation.x = -Math.PI / 2; ftDisc.position.set(0, 0.016, 4.7); scene.add(ftDisc);
// 3-point arc
{
const p = [], R = 6.75, cz = 0.32;
for (let i = 0; i <= 60; i++) {
const a = (-72 + i * 144 / 60) * Math.PI / 180;
p.push([Math.sin(a) * R, 0.02, cz + Math.cos(a) * R]);
}
courtLine(p);
}
/* ============================================================
3. HOOP: pole, arm, backboard, rim, net
============================================================ */
const H = 3.05; // rim height (m)
const RIM_R = 0.225; // rim radius
const BOARD_Z = 0.0; // backboard plane
const RIM_Z = 0.32; // rim centre (in front of board)
const steel = new THREE.MeshStandardMaterial({ color: 0x3b4a5f, roughness: 0.55, metalness: 0.55, flatShading: true });
const dark = new THREE.MeshStandardMaterial({ color: 0x1f2937, roughness: 0.85, flatShading: true });
const orange = new THREE.MeshStandardMaterial({ color: 0xf97316, roughness: 0.42, metalness: 0.25, flatShading: true });
const white = new THREE.MeshStandardMaterial({ color: 0xf8fafc, roughness: 0.6 });
// base + padding
const pad = new THREE.Mesh(new THREE.BoxGeometry(2.0, 0.55, 1.35), dark);
pad.position.set(0, 0.28, -1.95); pad.castShadow = pad.receiveShadow = true; scene.add(pad);
const plate = new THREE.Mesh(new THREE.CylinderGeometry(0.42, 0.5, 0.16, 10), steel);
plate.position.set(0, 0.08, -1.85); plate.castShadow = true; scene.add(plate);
// pole
const pole = new THREE.Mesh(new THREE.CylinderGeometry(0.09, 0.11, 3.95, 10), steel);
pole.position.set(0, 1.95, -1.85); pole.castShadow = true; scene.add(pole);
// boom arm + brace
const boom = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.16, 1.85), steel);
boom.position.set(0, 3.32, -0.95); boom.castShadow = true; scene.add(boom);
const brace = new THREE.Mesh(new THREE.CylinderGeometry(0.055, 0.055, 2.35, 8), steel);
brace.position.set(0, 2.62, -1.0);
brace.rotation.x = Math.PI / 2 + Math.PI * 0.19;
brace.castShadow = true; scene.add(brace);
// backboard (transparent low-poly glass)
const glass = new THREE.Mesh(new THREE.BoxGeometry(1.8, 1.05, 0.07),
new THREE.MeshStandardMaterial({ color: 0xbfe3f2, transparent: true, opacity: 0.26, roughness: 0.12, metalness: 0.1 }));
glass.position.set(0, 3.36, BOARD_Z); glass.castShadow = true; scene.add(glass);
// board frame
const frameParts = [
[1.84, 0.06, 0.10, 0, 3.885, 0], [1.84, 0.06, 0.10, 0, 2.835, 0],
[0.06, 1.11, 0.10, -0.89, 3.36, 0], [0.06, 1.11, 0.10, 0.89, 3.36, 0]
];
frameParts.forEach(([w, h, d, x, y, z]) => {
const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), white);
m.position.set(x, y, z); m.castShadow = true; scene.add(m);
});
// target square on board
const sqW = 0.60, sqH = 0.46, sqY = H + sqH / 2;
[[sqW, 0.035, 0, sqY + sqH / 2], [sqW, 0.035, 0, sqY - sqH / 2],
[0.035, sqH, -sqW / 2, sqY], [0.035, sqH, sqW / 2, sqY]].forEach(([w, h, x, y]) => {
const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, 0.035), white);
m.position.set(x, y, 0.06); scene.add(m);
});
// rim (low-poly torus)
const rim = new THREE.Mesh(new THREE.TorusGeometry(RIM_R, 0.023, 8, 22), orange);
rim.rotation.x = Math.PI / 2; rim.position.set(0, H, RIM_Z);
rim.castShadow = true; scene.add(rim);
// rim bracket to board
const bracket = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.05, 0.30), orange);
bracket.position.set(0, H, 0.14); scene.add(bracket);
// net (diamond mesh)
{
const N = 14, rt = RIM_R, rb = 0.125, top = H, bot = H - 0.42, step = Math.PI * 2 / N;
const pts = [];
const T = (a, r, y) => new THREE.Vector3(Math.cos(a) * r, y, Math.sin(a) * r);
for (let i = 0; i < N; i++) {
const a = i * step, ap = (i + 0.5) * step, am = (i - 0.5 + N) * step;
pts.push(T(a, rt, top), T(ap, rb, bot));
pts.push(T(a, rt, top), T(am, rb, bot));
}
for (let i = 0; i < N; i++) { // bottom ring
const a = i * step, b = (i + 1) * step;
pts.push(T(a, rb, bot), T(b, rb, bot));
}
const g = new THREE.BufferGeometry().setFromPoints(pts);
const net = new THREE.LineSegments(g, new THREE.LineBasicMaterial({ color: 0xe8eef7, transparent: true, opacity: 0.95 }));
net.position.z = RIM_Z; scene.add(net);
}
/* ============================================================
4. BALL
============================================================ */
function makeBall() {
const grp = new THREE.Group();
const b = new THREE.Mesh(new THREE.IcosahedronGeometry(0.13, 1),
new THREE.MeshStandardMaterial({ color: 0xea580c, roughness: 0.65, flatShading: true }));
b.castShadow = true; grp.add(b);
const seamMat = new THREE.MeshBasicMaterial({ color: 0x431407 });
const s1 = new THREE.Mesh(new THREE.TorusGeometry(0.131, 0.006, 4, 22), seamMat);
const s2 = new THREE.Mesh(new THREE.TorusGeometry(0.131, 0.006, 4, 22), seamMat);
s2.rotation.y = Math.PI / 2;
const s3 = new THREE.Mesh(new THREE.TorusGeometry(0.131, 0.006, 4, 22), seamMat);
s3.rotation.x = Math.PI / 2; s3.rotation.y = Math.PI / 3;
grp.add(s1, s2, s3);
return grp;
}
/* ============================================================
5. SHOT SOLUTION (release point -> rim front)
============================================================ */
const G = 9.81, T = 1.35; // flight time
const P0 = new THREE.Vector3(5.0, 2.0, 2.0); // release point
const P1 = new THREE.Vector3(0.0, H, RIM_Z); // target (rim centre)
const dh = Math.hypot(P1.x - P0.x, P1.z - P0.z);
const vh = dh / T;
const vy = (P1.y - P0.y + 0.5 * G * T * T) / T;
const ux = (P1.x - P0.x) / dh, uz = (P1.z - P0.z) / dh;
const vel = new THREE.Vector3(ux * vh, vy, uz * vh); // m/s
const speed = vel.length();
const angle = THREE.MathUtils.radToDeg(Math.atan2(vy, vh));
const apexY = P0.y + vy * vy / (2 * G);
const dir = vel.clone().normalize();
const traj = t => new THREE.Vector3(
P0.x + vel.x * t,
P0.y + vel.y * t - 0.5 * G * t * t,
P0.z + vel.z * t);
/* release marker + ball */
const spotMat = new THREE.MeshStandardMaterial({ color: 0xfb923c, emissive: 0xfb923c, emissiveIntensity: 0.35, roughness: 0.5 });
const spot = new THREE.Mesh(new THREE.CylinderGeometry(0.36, 0.36, 0.05, 12), spotMat);
spot.position.set(P0.x, 0.03, P0.z); spot.receiveShadow = true; scene.add(spot);
const spotRing = new THREE.Mesh(new THREE.TorusGeometry(0.5, 0.02, 6, 24), spotMat);
spotRing.rotation.x = Math.PI / 2; spotRing.position.set(P0.x, 0.04, P0.z); scene.add(spotRing);
const ball = makeBall(); ball.position.copy(P0); scene.add(ball);
const ghost = makeBall(); ghost.scale.setScalar(0.92); scene.add(ghost);
/* ============================================================
6. HELPERS: labels, dashed lines, arrows
============================================================ */
function roundRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(text, {
height = 0.55, color = '#e2e8f0', bg = 'rgba(9,15,28,0.82)',
accent = '#f97316', border = 'rgba(148,163,184,0.45)', pad = 20, fs = 44
} = {}) {
const c = document.createElement('canvas');
let ctx = c.getContext('2d');
ctx.font = `600 ${fs}px "Segoe UI", Roboto, Arial, sans-serif`;
const w = Math.ceil(ctx.measureText(text).width);
c.width = w + pad * 2; c.height = fs + pad * 2;
ctx = c.getContext('2d');
ctx.font = `600 ${fs}px "Segoe UI", Roboto, Arial, sans-serif`;
ctx.textBaseline = 'alphabetic';
roundRect(ctx, 3, 3, c.width - 6, c.height - 6, 16);
ctx.fillStyle = bg; ctx.fill();
ctx.lineWidth = 5; ctx.strokeStyle = accent; ctx.stroke();
ctx.fillStyle = color;
ctx.fillText(text, pad, pad + fs * 0.78);
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
tex.anisotropy = 4;
const spr = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, transparent: true, depthTest: false, fog: false }));
spr.scale.set(c.width / c.height * height, height, 1);
spr.renderOrder = 20;
return spr;
}
function dashedLine(points, color, dash = 0.28, gap = 0.18, opacity = 1) {
const g = new THREE.BufferGeometry().setFromPoints(points);
const m = new THREE.LineDashedMaterial({ color, dashSize: dash, gapSize: gap, transparent: true, opacity });
const l = new THREE.Line(g, m); l.computeLineDistances(); scene.add(l); return l;
}
function arrowMesh(len, color, doubleEnded = false) {
const grp = new THREE.Group();
const mat = new THREE.MeshStandardMaterial({ color, emissive: color, emissiveIntensity: 0.45, roughness: 0.35, metalness: 0.1 });
const r = Math.min(0.085, len * 0.12);
const headLen = len * 0.26, shaftLen = len - headLen;
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(r * 0.42, r * 0.42, shaftLen, 8), mat);
shaft.position.y = shaftLen / 2; grp.add(shaft);
const head = new THREE.Mesh(new THREE.ConeGeometry(r, headLen, 10), mat);
head.position.y = shaftLen + headLen / 2; grp.add(head);
if (doubleEnded) {
const s2 = shaft.clone(); s2.position.y = -shaftLen / 2; grp.add(s2);
const h2 = new THREE.Mesh(new THREE.ConeGeometry(r, headLen, 10), mat);
h2.position.y = -headLen / 2; h2.rotation.z = Math.PI; grp.add(h2);
}
grp.userData.head = head; grp.userData.shaft = shaft;
return grp;
}
function orientArrow(grp, from, direction) {
grp.position.copy(from);
grp.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.clone().normalize());
}
/* ============================================================
7. VELOCITY ARROW (yellow)
============================================================ */
const lateral = new THREE.Vector3(-dir.z, 0, dir.x).normalize();
const vArrowFrom = P0.clone().add(dir.clone().multiplyScalar(0.30)).add(lateral.clone().multiplyScalar(0.55));
const vArrow = arrowMesh(2.1, 0xfacc15);
orientArrow(vArrow, vArrowFrom, dir); scene.add(vArrow);
const vTip = vArrowFrom.clone().add(dir.clone().multiplyScalar(2.1));
const vLabel = makeLabel(`v = ${speed.toFixed(2)} m/s`, { accent: '#facc15' });
vLabel.position.copy(vTip).add(new THREE.Vector3(0.1, 0.34, 0)); scene.add(vLabel);
const aLabel = makeLabel(`θ = ${angle.toFixed(1)}°`, { accent: '#facc15', height: 0.45 });
aLabel.position.copy(vArrowFrom).add(dir.clone().multiplyScalar(1.0)).add(new THREE.Vector3(0, 0.28, 0)); scene.add(aLabel);
/* ============================================================
8. TRAJECTORY ARC + apex marker
============================================================ */
const arcPts = [];
for (let i = 0; i <= 70; i++) arcPts.push(traj(T * i / 70));
const arc = dashedLine(arcPts, 0xfb923c, 0.26, 0.14, 0.95);
scene.add(arc);
const apexT = vy / G, apex = traj(apexT);
const apexMark = new THREE.Mesh(new THREE.OctahedronGeometry(0.11),
new THREE.MeshStandardMaterial({ color: 0xfb923c, emissive: 0xfb923c, emissiveIntensity: 0.5, flatShading: true }));
apexMark.position.copy(apex); scene.add(apexMark);
const apexLabel = makeLabel(`APEX ${apexY.toFixed(2)} m`, { accent: '#fb923c', height: 0.45 });
apexLabel.position.copy(apex).add(new THREE.Vector3(0.25, 0.28, 0)); scene.add(apexLabel);
/* ============================================================
9. TARGET HEIGHT dimension (cyan)
============================================================ */
const CYAN = 0x22d3ee;
const hX = 1.55, hZ = RIM_Z;
// extension lines from board & ground
dashedLine([new THREE.Vector3(0.9, H, hZ), new THREE.Vector3(1.95, H, hZ)], CYAN, 0.18, 0.12, 0.8);
dashedLine([new THREE.Vector3(0.9, 0.02, hZ), new THREE.Vector3(1.95, 0.02, hZ)], CYAN, 0.18, 0.12, 0.8);
const hArrow = arrowMesh(H, CYAN, true);
orientArrow(hArrow, new THREE.Vector3(hX, 0, hZ), new THREE.Vector3(0, 1, 0));
scene.add(hArrow);
// horizontal target line through the rim
dashedLine([new THREE.Vector3(-1.5, H, hZ), new THREE.Vector3(1.5, H, hZ)], CYAN, 0.22, 0.14, 0.9);
[-1.5, 1.5].forEach(x => {
const t = new THREE.Mesh(new THREE.BoxGeometry(0.035, 0.22, 0.035),
new THREE.MeshStandardMaterial({ color: CYAN, emissive: CYAN, emissiveIntensity: 0.4 }));
t.position.set(x, H, hZ); scene.add(t);
});
const hLabel = makeLabel(`TARGET HEIGHT ${H.toFixed(2)} m`, { accent: '#22d3ee' });
hLabel.position.set(0, 4.35, 0.15); scene.add(hLabel);
/* ============================================================
10. GROUND DISTANCE dimension (violet)
============================================================ */
const VIO = 0xa78bfa;
const A = new THREE.Vector3(P0.x, 0.03, P0.z);
const B = new THREE.Vector3(0, 0.03, RIM_Z);
const dGround = Math.hypot(A.x - B.x, A.z - B.z);
const gdir = new THREE.Vector3(B.x - A.x, 0, B.z - A.z).normalize();
const gperp = new THREE.Vector3(-gdir.z, 0, gdir.x);
dashedLine([A, B], VIO, 0.3, 0.18, 0.95);
[ A, B ].forEach(p => {
const t = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
p.clone().add(gperp.clone().multiplyScalar(0.28)),
p.clone().add(gperp.clone().multiplyScalar(-0.28))]),
new THREE.LineBasicMaterial({ color: VIO }));
scene.add(t);
});
const dLabel = makeLabel(`DISTANCE ${dGround.toFixed(2)} m`, { accent: '#a78bfa' });
dLabel.position.copy(A.clone().lerp(B, 0.5)).add(new THREE.Vector3(0, 0.55, 0)); scene.add(dLabel);
/* release label */
const relLabel = makeLabel('RELEASE POINT', { accent: '#fb923c', height: 0.45 });
relLabel.position.set(P0.x, 2.62, P0.z); scene.add(relLabel);
const relLine = dashedLine([new THREE.Vector3(P0.x, 0.06, P0.z), new THREE.Vector3(P0.x, 1.92, P0.z)], 0xfb923c, 0.16, 0.12, 0.7);
scene.add(relLine);
/* rim pulse ring */
const pulse = new THREE.Mesh(new THREE.TorusGeometry(RIM_R + 0.02, 0.012, 6, 28),
new THREE.MeshBasicMaterial({ color: 0xfbbf24, transparent: true, opacity: 0.9 }));
pulse.rotation.x = Math.PI / 2; pulse.position.set(0, H, RIM_Z); scene.add(pulse);
/* ============================================================
11. HUD values
============================================================ */
document.getElementById('vH').textContent = H.toFixed(2) + ' m';
document.getElementById('vD').textContent = dGround.toFixed(2) + ' m';
document.getElementById('vV').textContent = speed.toFixed(2) + ' m/s';
document.getElementById('vA').textContent = angle.toFixed(1) + '°';
document.getElementById('vT').textContent = T.toFixed(2) + ' s';
document.getElementById('vX').textContent = apexY.toFixed(2) + ' m';
/* ============================================================
12. CUSTOM ORBIT CAMERA (no addons)
============================================================ */
const cam = {
theta: 0.92, phi: 1.12, radius: 17.5,
target: new THREE.Vector3(1.2, 2.0, 1.2),
// smoothed values
sTheta: 0.92, sPhi: 1.12, sRadius: 17.5, sTarget: new THREE.Vector3(1.2, 2.0, 1.2)
};
let dragging = false, panning = false, lastX = 0, lastY = 0, idle = 0;
const pointers = new Map();
let pinchDist = 0;
const dom = renderer.domElement;
dom.addEventListener('contextmenu', e => e.preventDefault());
dom.addEventListener('pointerdown', e => {
dom.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
if (pointers.size === 1) {
dragging = true;
panning = (e.button === 2 || e.shiftKey);
lastX = e.clientX; lastY = e.clientY;
} else if (pointers.size === 2) {
const p = [...pointers.values()];
pinchDist = Math.hypot(p[0].x - p[1].x, p[0].y - p[1].y);
}
idle = 0;
});
dom.addEventListener('pointermove', e => {
if (!pointers.has(e.pointerId)) return;
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
if (pointers.size === 2) {
const p = [...pointers.values()];
const d = Math.hypot(p[0].x - p[1].x, p[0].y - p[1].y);
if (pinchDist) cam.radius = THREE.MathUtils.clamp(cam.radius * (pinchDist / d), 4, 48);
pinchDist = d; idle = 0; return;
}
if (!dragging) return;
const dx = e.clientX - lastX, dy = e.clientY - lastY;
lastX = e.clientX; lastY = e.clientY;
idle = 0;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const k = cam.radius * 0.0016;
cam.target.addScaledVector(right, -dx * k).addScaledVector(up, dy * k);
cam.target.y = THREE.MathUtils.clamp(cam.target.y, -1, 10);
} else {
cam.theta -= dx * 0.0055;
cam.phi = THREE.MathUtils.clamp(cam.phi - dy * 0.0045, 0.16, 1.48);
}
});
function endPointer(e) {
pointers.delete(e.pointerId);
if (pointers.size === 0) { dragging = false; panning = false; pinchDist = 0; }
}
dom.addEventListener('pointerup', endPointer);
dom.addEventListener('pointercancel', endPointer);
dom.addEventListener('pointerleave', endPointer);
dom.addEventListener('wheel', e => {
e.preventDefault();
cam.radius = THREE.MathUtils.clamp(cam.radius * (1 + Math.sign(e.deltaY) * 0.09), 4, 48);
idle = 0;
}, { passive: false });
/* ============================================================
13. ANIMATION LOOP
============================================================ */
const clock = new THREE.Clock();
let pulseT = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const t = clock.elapsedTime;
// gentle idle orbit
idle += dt;
if (idle > 6 && !dragging) cam.theta += dt * 0.055;
// smooth camera
const k = 1 - Math.pow(0.0015, dt);
cam.sTheta += (cam.theta - cam.sTheta) * k;
cam.sPhi += (cam.phi - cam.sPhi) * k;
cam.sRadius += (cam.radius - cam.sRadius) * k;
cam.sTarget.lerp(cam.target, k);
camera.position.set(
cam.sTarget.x + cam.sRadius * Math.sin(cam.sPhi) * Math.cos(cam.sTheta),
cam.sTarget.y + cam.sRadius * Math.cos(cam.sPhi),
cam.sTarget.z + cam.sRadius * Math.sin(cam.sPhi) * Math.sin(cam.sTheta));
camera.lookAt(cam.sTarget);
// ghost ball travels the arc
const cycle = T + 0.45;
const tt = t % cycle;
if (tt <= T) {
ghost.visible = true;
ghost.position.copy(traj(tt));
ghost.rotation.x += dt * 6; ghost.rotation.z += dt * 3.4;
} else {
ghost.visible = false;
}
// rim pulse when the ghost reaches the rim
const near = Math.abs(tt - T) < 0.12;
if (near && pulseT <= 0) pulseT = 1;
if (pulseT > 0) {
pulseT = Math.max(0, pulseT - dt * 2.4);
const s = 1 + (1 - pulseT) * 0.55;
pulse.scale.setScalar(s);
pulse.material.opacity = pulseT * 0.9;
}
// velocity arrow breathes
const pulseS = 1 + Math.sin(t * 3.1) * 0.035;
vArrow.scale.set(pulseS, pulseS, pulseS);
apexMark.rotation.y += dt * 1.2;
renderer.render(scene, camera);
}
animate();
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```