Fix galaxy flow motion and lock overlap separation

This commit is contained in:
Tessera Agent
2026-11-09 11:14:15 +00:00
parent 6646c12ab1
commit 32493b640e
3 changed files with 107 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import {
lerpPos, lerpPos,
moonPositions, moonPositions,
positionOnEllipse, positionOnEllipse,
relaxLockedMoons,
} from "../../lib/galaxyLayout"; } from "../../lib/galaxyLayout";
import { import {
layoutLockLabels, layoutLockLabels,
@@ -83,13 +84,28 @@ export function BlackholeGalaxy({
const starOrbits = useMemo(() => orbits.slice(0, MAX_STARS), [orbits]); const starOrbits = useMemo(() => orbits.slice(0, MAX_STARS), [orbits]);
const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]); const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]);
const lockLabels = useMemo(() => { const lockLayout = useMemo(() => {
const positions = starOrbits.map((_, i) => const n = starOrbits.length;
lockedSlot(i, starOrbits.length), if (!n) {
return { stars: [] as { x: number; y: number }[], moons: [] as { x: number; y: number }[][], labels: [] as { x: number; y: number }[] };
}
const stars = Array.from({ length: n }, (_, i) =>
lockedSlot(i, n),
); );
const names = starOrbits.map((o) => o.name); const rawMoons = starOrbits.map((orbit, i) => {
return layoutLockLabels(positions, names, STAR_R_LOCK); const moons = snapsByOrbit.get(orbit.name) ?? [];
}, [starOrbits]); return moonPositions(stars[i].x, stars[i].y, moons.length, 0, false, 36).map(
(p) => ({ x: p.x, y: p.y }),
);
});
const moons = relaxLockedMoons(stars, rawMoons);
const labels = layoutLockLabels(
stars,
starOrbits.map((o) => o.name),
STAR_R_LOCK,
);
return { stars, moons, labels };
}, [starOrbits, snapsByOrbit]);
const showLabels = !flowing || blend < 0.35; const showLabels = !flowing || blend < 0.35;
@@ -167,21 +183,21 @@ export function BlackholeGalaxy({
phys.tiltDeg, phys.tiltDeg,
); );
const lockPos = lockedSlot(i, starOrbits.length); const lockPos = lockedSlot(i, starOrbits.length);
const { x, y } = lerpPos(flowPos, lockPos, 1 - blend); const { x, y } = lerpPos(flowPos, lockPos, blend);
const moons = snapsByOrbit.get(orbit.name) ?? []; const moons = snapsByOrbit.get(orbit.name) ?? [];
const color = statusColor(orbit.last_status); const color = statusColor(orbit.last_status);
const starR = flowing ? STAR_R_FLOW : STAR_R_LOCK; const starR = flowing ? STAR_R_FLOW : STAR_R_LOCK;
const interactive = !flowing || blend < 0.15; const interactive = !flowing || blend < 0.15;
const label = lockLabels[i]; const label = lockLayout.labels[i];
const flowMoons = moonPositions(
const moonPts = moonPositions(
x, x,
y, y,
moons.length, moons.length,
t, t,
flowing && blend > 0.5, true,
34, 36,
); );
const lockMoons = lockLayout.moons[i] ?? [];
return ( return (
<g key={orbit.id}> <g key={orbit.id}>
@@ -212,7 +228,15 @@ export function BlackholeGalaxy({
}} }}
/> />
{moons.map((moon, mi) => { {moons.map((moon, mi) => {
const mp = moonPts[mi]; const flowMp = flowMoons[mi];
const lockMp = lockMoons[mi];
const mp = lockMp
? lerpPos(
{ x: flowMp.x, y: flowMp.y },
lockMp,
blend,
)
: flowMp;
const sel = moon.id === selectedSnapshotId; const sel = moon.id === selectedSnapshotId;
const mr = flowing ? 3.8 : sel ? 7.5 : 6; const mr = flowing ? 3.8 : sel ? 7.5 : 6;
const hit = flowing ? mr : MOON_HIT_LOCK; const hit = flowing ? mr : MOON_HIT_LOCK;

View File

@@ -24,17 +24,17 @@ export function layoutLockLabels(
names: string[], names: string[],
starR: number, starR: number,
): LabelPlacement[] { ): LabelPlacement[] {
const vaultPad = 52; const vaultPad = 108;
const labels: LabelPlacement[] = starPositions.map((p, i) => { const labels: LabelPlacement[] = starPositions.map((p, i) => {
const ang = Math.atan2(p.y, p.x); const ang = Math.atan2(p.y, p.x);
const base = starR + 20; const base = starR + 28;
return { return {
x: p.x + Math.cos(ang) * base, x: p.x + Math.cos(ang) * base,
y: p.y + Math.sin(ang) * base, y: p.y + Math.sin(ang) * base,
}; };
}); });
for (let iter = 0; iter < 28; iter++) { for (let iter = 0; iter < 48; iter++) {
for (let i = 0; i < labels.length; i++) { for (let i = 0; i < labels.length; i++) {
const p = starPositions[i]; const p = starPositions[i];
const r = dist(labels[i], { x: 0, y: 0 }); const r = dist(labels[i], { x: 0, y: 0 });
@@ -65,7 +65,7 @@ export function layoutLockLabels(
labels[i].y - starPositions[i].y, labels[i].y - starPositions[i].y,
labels[i].x - starPositions[i].x, labels[i].x - starPositions[i].x,
); );
const minDist = starR + 16; const minDist = starR + 26;
const dStar = dist(labels[i], starPositions[i]); const dStar = dist(labels[i], starPositions[i]);
if (dStar < minDist) { if (dStar < minDist) {
labels[i].x = starPositions[i].x + Math.cos(outward) * minDist; labels[i].x = starPositions[i].x + Math.cos(outward) * minDist;

View File

@@ -33,7 +33,7 @@ export function flowOrbitPhysics(index: number, total: number): OrbitPhysics {
rx: Math.min(rx, VIEW_R), rx: Math.min(rx, VIEW_R),
ry: Math.min(ry, VIEW_R * 0.88), ry: Math.min(ry, VIEW_R * 0.88),
tiltDeg, tiltDeg,
speed: 0.05 + (index % 9) * 0.009 + band * 0.004, speed: 0.14 + (index % 9) * 0.018 + band * 0.008,
phase: (index / n) * Math.PI * 2 + index * GOLDEN * 0.15, phase: (index / n) * Math.PI * 2 + index * GOLDEN * 0.15,
}; };
} }
@@ -70,17 +70,19 @@ function dist(a: Vec2, b: Vec2): number {
return Math.hypot(dx, dy); return Math.hypot(dx, dy);
} }
const layoutCache = new Map<number, Vec2[]>(); const LAYOUT_VER = 2;
const layoutCache = new Map<string, Vec2[]>();
/** Golden-angle seeds relaxed for minimum star separation (lock mode). */ /** Golden-angle seeds relaxed for minimum star separation (lock mode). */
export function lockedPositions(total: number): Vec2[] { export function lockedPositions(total: number): Vec2[] {
const cached = layoutCache.get(total); const key = `${LAYOUT_VER}:${total}`;
const cached = layoutCache.get(key);
if (cached) return cached; if (cached) return cached;
const pts = Array.from({ length: total }, (_, i) => slotSeed(i, total)); const pts = Array.from({ length: total }, (_, i) => slotSeed(i, total));
const minSep = total > 14 ? 38 : 44; const minSep = total > 12 ? 56 : 62;
for (let iter = 0; iter < 32; iter++) { for (let iter = 0; iter < 56; iter++) {
for (let i = 0; i < total; i++) { for (let i = 0; i < total; i++) {
for (let j = i + 1; j < total; j++) { for (let j = i + 1; j < total; j++) {
const d = dist(pts[i], pts[j]); const d = dist(pts[i], pts[j]);
@@ -95,7 +97,7 @@ export function lockedPositions(total: number): Vec2[] {
} }
} }
const r = dist(pts[i], { x: 0, y: 0 }); const r = dist(pts[i], { x: 0, y: 0 });
const vaultPad = 78; const vaultPad = 96;
if (r < vaultPad && r > 0.001) { if (r < vaultPad && r > 0.001) {
const s = vaultPad / r; const s = vaultPad / r;
pts[i].x *= s; pts[i].x *= s;
@@ -110,7 +112,7 @@ export function lockedPositions(total: number): Vec2[] {
} }
} }
layoutCache.set(total, pts); layoutCache.set(key, pts);
return pts; return pts;
} }
@@ -127,10 +129,19 @@ export function moonPositions(
baseSpread = 32, baseSpread = 32,
): { x: number; y: number; angle: number }[] { ): { x: number; y: number; angle: number }[] {
const out: { x: number; y: number; angle: number }[] = []; const out: { x: number; y: number; angle: number }[] = [];
const outward = Math.atan2(cy, cx);
for (let mi = 0; mi < count; mi++) { for (let mi = 0; mi < count; mi++) {
const slice = (mi / Math.max(count, 1)) * Math.PI * 2; const slice = (mi / Math.max(count, 1)) * Math.PI * 2;
const angle = flowing ? slice + time * (0.4 + mi * 0.06) : slice - Math.PI / 2; const fan =
const dist = flowing ? baseSpread * 0.62 : baseSpread + (mi % 2) * 5; count <= 1
? 0
: (mi - (count - 1) / 2) * (flowing ? 0.55 : 0.42);
const angle = flowing
? slice + time * (0.85 + mi * 0.08)
: outward + fan;
const dist = flowing
? baseSpread * (0.72 + (mi % 3) * 0.08)
: baseSpread + 8 + mi * 6;
out.push({ out.push({
angle, angle,
x: cx + Math.cos(angle) * dist, x: cx + Math.cos(angle) * dist,
@@ -140,6 +151,52 @@ export function moonPositions(
return out; return out;
} }
/** Push overlapping moons apart in lock mode (all stars). */
export function relaxLockedMoons(
stars: Vec2[],
moonsByStar: Vec2[][],
): Vec2[][] {
const flat: { p: Vec2; star: number; moon: number }[] = [];
for (let si = 0; si < moonsByStar.length; si++) {
for (let mi = 0; mi < moonsByStar[si].length; mi++) {
flat.push({ p: { ...moonsByStar[si][mi] }, star: si, moon: mi });
}
}
const minMoon = 22;
const minStarMoon = 28;
for (let iter = 0; iter < 40; iter++) {
for (let i = 0; i < flat.length; i++) {
for (let j = i + 1; j < flat.length; j++) {
const d = dist(flat[i].p, flat[j].p);
if (d < minMoon && d > 0.001) {
const push = (minMoon - d) * 0.55;
const ux = (flat[i].p.x - flat[j].p.x) / d;
const uy = (flat[i].p.y - flat[j].p.y) / d;
flat[i].p.x += ux * push;
flat[i].p.y += uy * push;
flat[j].p.x -= ux * push;
flat[j].p.y -= uy * push;
}
}
const s = stars[flat[i].star];
const ds = dist(flat[i].p, s);
if (ds < minStarMoon && ds > 0.001) {
const ang = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
flat[i].p.x = s.x + Math.cos(ang) * minStarMoon;
flat[i].p.y = s.y + Math.sin(ang) * minStarMoon;
}
}
}
const out = moonsByStar.map((row) => row.map(() => ({ x: 0, y: 0 })));
for (const f of flat) {
out[f.star][f.moon] = f.p;
}
return out;
}
export function lerpPos(a: Vec2, b: Vec2, t: number): Vec2 { export function lerpPos(a: Vec2, b: Vec2, t: number): Vec2 {
return { return {
x: a.x * t + b.x * (1 - t), x: a.x * t + b.x * (1 - t),