Layer inclined orbits in flow and even-ring lock spacing

This commit is contained in:
Tessera Agent
2026-11-09 11:18:30 +00:00
parent 32493b640e
commit 5b40536e37
2 changed files with 315 additions and 172 deletions

View File

@@ -1,10 +1,12 @@
import { useEffect, useMemo, useRef, useState } from "react"; import { useEffect, useMemo, useRef, useState } from "react";
import type { Orbit, Snapshot } from "../../api"; import type { Orbit, Snapshot } from "../../api";
import { import {
flowMoonOffsets,
flowOrbitPhysics, flowOrbitPhysics,
lockedSlot, lockedSlot,
lerpPos, lerpPos,
moonPositions, moonPositions,
orbitArcs,
positionOnEllipse, positionOnEllipse,
relaxLockedMoons, relaxLockedMoons,
} from "../../lib/galaxyLayout"; } from "../../lib/galaxyLayout";
@@ -154,124 +156,200 @@ export function BlackholeGalaxy({
{starOrbits.map((orbit, i) => { {starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length); const phys = flowOrbitPhysics(i, starOrbits.length);
const arcs = orbitArcs(phys);
return ( return (
<ellipse <path
key={`path-${orbit.id}`} key={`path-back-${orbit.id}`}
cx="0" d={arcs.back}
cy="0"
rx={phys.rx}
ry={phys.ry}
fill="none" fill="none"
stroke="#4a5f9e" stroke="#6d84c4"
strokeOpacity={flowing ? 0.07 : 0.16} strokeOpacity={flowing ? 0.08 : 0.1}
strokeWidth="0.7" strokeWidth={0.7}
strokeDasharray="3 10" strokeDasharray="2 10"
transform={`rotate(${phys.tiltDeg})`}
/> />
); );
})} })}
<StarLayer
which="back"
t={t}
blend={blend}
flowing={flowing}
starOrbits={starOrbits}
snapsByOrbit={snapsByOrbit}
lockLayout={lockLayout}
selectedSnapshotId={selectedSnapshotId}
showLabels={showLabels}
onSelectOrbit={onSelectOrbit}
onSelectSnapshot={onSelectSnapshot}
/>
<BlackHoleCore t={t} flowing={flowing} onToggle={onToggleFlow} /> <BlackHoleCore t={t} flowing={flowing} onToggle={onToggleFlow} />
{starOrbits.map((orbit, i) => { {starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length); const phys = flowOrbitPhysics(i, starOrbits.length);
const flowAngle = phys.phase + t * phys.speed; const arcs = orbitArcs(phys);
const flowPos = positionOnEllipse(
flowAngle,
phys.rx,
phys.ry,
phys.tiltDeg,
);
const lockPos = lockedSlot(i, starOrbits.length);
const { x, y } = lerpPos(flowPos, lockPos, blend);
const moons = snapsByOrbit.get(orbit.name) ?? [];
const color = statusColor(orbit.last_status);
const starR = flowing ? STAR_R_FLOW : STAR_R_LOCK;
const interactive = !flowing || blend < 0.15;
const label = lockLayout.labels[i];
const flowMoons = moonPositions(
x,
y,
moons.length,
t,
true,
36,
);
const lockMoons = lockLayout.moons[i] ?? [];
return ( return (
<g key={orbit.id}> <path
{!flowing && ( key={`path-front-${orbit.id}`}
<circle d={arcs.front}
cx={x} fill="none"
cy={y} stroke="#9aafdf"
r={HIT_R_LOCK} strokeOpacity={flowing ? 0.2 : 0.12}
fill="transparent" strokeWidth={0.9}
className="cursor-pointer" strokeDasharray="2 8"
onClick={(e) => { />
e.stopPropagation();
onSelectOrbit(orbit.id);
}}
/>
)}
<StarBody
id={orbit.id}
x={x}
y={y}
r={starR}
color={color}
locked={!flowing}
interactive={interactive}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(orbit.id);
}}
/>
{moons.map((moon, 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 mr = flowing ? 3.8 : sel ? 7.5 : 6;
const hit = flowing ? mr : MOON_HIT_LOCK;
return (
<MoonBody
key={moon.id}
x={mp.x}
y={mp.y}
r={mr}
hitR={hit}
rim={color}
selected={sel}
locked={!flowing}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectSnapshot(moon.id);
}}
/>
);
})}
{showLabels && (
<LockLabel
x={label.x}
y={label.y}
text={shortenOrbitName(orbit.name)}
/>
)}
</g>
); );
})} })}
<StarLayer
which="front"
t={t}
blend={blend}
flowing={flowing}
starOrbits={starOrbits}
snapsByOrbit={snapsByOrbit}
lockLayout={lockLayout}
selectedSnapshotId={selectedSnapshotId}
showLabels={showLabels}
onSelectOrbit={onSelectOrbit}
onSelectSnapshot={onSelectSnapshot}
/>
</svg> </svg>
</div> </div>
); );
} }
function StarLayer({
which,
t,
blend,
flowing,
starOrbits,
snapsByOrbit,
lockLayout,
selectedSnapshotId,
showLabels,
onSelectOrbit,
onSelectSnapshot,
}: {
which: "back" | "front";
t: number;
blend: number;
flowing: boolean;
starOrbits: Orbit[];
snapsByOrbit: Map<string, Snapshot[]>;
lockLayout: {
moons: { x: number; y: number }[][];
labels: { x: number; y: number }[];
};
selectedSnapshotId?: string | null;
showLabels: boolean;
onSelectOrbit: (id: string) => void;
onSelectSnapshot: (id: string) => void;
}) {
const drawn = starOrbits
.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
const pose = positionOnEllipse(phys.phase + t * phys.speed, phys);
const depth = pose.z * blend;
const inFront = blend < 0.35 || depth >= 0;
return { orbit, i, pose, depth, inFront };
})
.filter((row) => (which === "front" ? row.inFront : !row.inFront))
.sort((a, b) => a.depth - b.depth);
return drawn.map(({ orbit, i, pose }) => {
const lockPos = lockedSlot(i, starOrbits.length);
const { x, y } = lerpPos(pose, lockPos, blend);
const moons = snapsByOrbit.get(orbit.name) ?? [];
const color = statusColor(orbit.last_status);
const depthScale = pose.scale * blend + (1 - blend);
const starR = (flowing ? STAR_R_FLOW : STAR_R_LOCK) * depthScale;
const dim = 0.55 + ((pose.z + 1) / 2) * 0.45;
const opacity = dim * blend + (1 - blend);
const interactive = !flowing || blend < 0.15;
const label = lockLayout.labels[i];
const flowOff = flowMoonOffsets(moons.length, t, 32);
const lockMoons = lockLayout.moons[i] ?? [];
const moonNodes = moons.map((moon, mi) => {
const off = flowOff[mi];
const lockMp = lockMoons[mi];
const flowMp = { x: x + off.x * depthScale, y: y + off.y * depthScale };
const mp = lockMp ? lerpPos(flowMp, lockMp, blend) : flowMp;
const localZ = off.z;
return { moon, mp, localZ, off };
});
const moonsBehind = moonNodes.filter((m) => m.localZ < 0 || blend < 0.5);
const moonsAhead = blend < 0.5 ? [] : moonNodes.filter((m) => m.localZ >= 0);
const paintMoon = (node: (typeof moonNodes)[number]) => {
const sel = node.moon.id === selectedSnapshotId;
const mr =
((flowing ? 3.8 : sel ? 7.5 : 6) *
(blend < 0.5 ? 1 : node.off.scale) *
depthScale);
return (
<MoonBody
key={node.moon.id}
x={node.mp.x}
y={node.mp.y}
r={mr}
hitR={flowing ? mr : MOON_HIT_LOCK}
rim={color}
selected={sel}
locked={!flowing}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectSnapshot(node.moon.id);
}}
/>
);
};
return (
<g key={orbit.id} opacity={opacity}>
{moonsBehind.map(paintMoon)}
{!flowing && (
<circle
cx={x}
cy={y}
r={HIT_R_LOCK}
fill="transparent"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
onSelectOrbit(orbit.id);
}}
/>
)}
<StarBody
id={orbit.id}
x={x}
y={y}
r={starR}
color={color}
locked={!flowing}
interactive={interactive}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(orbit.id);
}}
/>
{moonsAhead.map(paintMoon)}
{showLabels && which === "front" && label && (
<LockLabel
x={label.x}
y={label.y}
text={shortenOrbitName(orbit.name)}
/>
)}
</g>
);
});
}
function StarBody({ function StarBody({
id, id,
x, x,
@@ -357,6 +435,7 @@ function MoonBody({
rim, rim,
selected, selected,
locked, locked,
opacity = 1,
onClick, onClick,
}: { }: {
x: number; x: number;
@@ -366,10 +445,15 @@ function MoonBody({
rim: string; rim: string;
selected: boolean; selected: boolean;
locked: boolean; locked: boolean;
opacity?: number;
onClick: (e: React.MouseEvent<SVGGElement>) => void; onClick: (e: React.MouseEvent<SVGGElement>) => void;
}) { }) {
return ( return (
<g className={locked ? "cursor-pointer" : "pointer-events-none"} onClick={onClick}> <g
opacity={opacity}
className={locked ? "cursor-pointer" : "pointer-events-none"}
onClick={onClick}
>
{locked && ( {locked && (
<circle cx={x} cy={y} r={hitR} fill="transparent" /> <circle cx={x} cy={y} r={hitR} fill="transparent" />
)} )}

View File

@@ -3,65 +3,74 @@
export type OrbitPhysics = { export type OrbitPhysics = {
rx: number; rx: number;
ry: number; ry: number;
tiltDeg: number; nodeDeg: number;
inclination: number;
speed: number; speed: number;
phase: number; phase: number;
layer: number;
}; };
export type Vec2 = { x: number; y: number }; export type Vec2 = { x: number; y: number };
const GOLDEN = 2.399963229728653; export type Pose3 = Vec2 & { z: number; scale: number };
const VIEW_R = 258; const VIEW_R = 258;
/** Per-star ellipses from inner rim to ~90% of viewport radius. */ /** Inclined shells: each star has its own node, tilt, and radius. */
export function flowOrbitPhysics(index: number, total: number): OrbitPhysics { export function flowOrbitPhysics(index: number, total: number): OrbitPhysics {
const n = Math.max(total, 1); const n = Math.max(total, 1);
const layer = index % 3;
const lane = index / Math.max(n - 1, 1); const lane = index / Math.max(n - 1, 1);
const band = index % 5; const rx = Math.min(108 + lane * (VIEW_R - 108), VIEW_R);
const rx =
92 +
lane * (VIEW_R - 92) +
band * 7 +
((index * 11) % 5) * 4;
const ry =
68 +
((index * 13) % 9) * 14 +
lane * 72 +
(index % 3) * 9;
const tiltDeg = -42 + ((index * 23 + band * 17) % 84);
return { return {
rx: Math.min(rx, VIEW_R), rx,
ry: Math.min(ry, VIEW_R * 0.88), ry: rx * (0.96 - layer * 0.03),
tiltDeg, nodeDeg: (index * 53) % 360,
speed: 0.14 + (index % 9) * 0.018 + band * 0.008, inclination: 0.42 + layer * 0.32,
phase: (index / n) * Math.PI * 2 + index * GOLDEN * 0.15, speed: 0.18 + layer * 0.06 + (index % 5) * 0.015,
phase: (index / n) * Math.PI * 2 + index * 0.35,
layer,
}; };
} }
export function positionOnEllipse( /** Orbital plane → screen, with line-of-sight depth for scale and paint order. */
angle: number, export function positionOnEllipse(angle: number, phys: OrbitPhysics): Pose3 {
rx: number, const lx = Math.cos(angle) * phys.rx;
ry: number, const ly = Math.sin(angle) * phys.ry;
tiltDeg: number, const yInc = ly * Math.cos(phys.inclination);
): Vec2 { const zRaw = ly * Math.sin(phys.inclination);
const ex = Math.cos(angle) * rx; const node = (phys.nodeDeg * Math.PI) / 180;
const ey = Math.sin(angle) * ry; const x = lx * Math.cos(node) - yInc * Math.sin(node);
const rad = (tiltDeg * Math.PI) / 180; const y = lx * Math.sin(node) + yInc * Math.cos(node);
const depth = zRaw / Math.max(phys.rx, 1);
return { return {
x: ex * Math.cos(rad) - ey * Math.sin(rad), x,
y: ex * Math.sin(rad) + ey * Math.cos(rad), y,
z: depth,
scale: 0.7 + (depth + 1) * 0.3,
}; };
} }
function slotSeed(index: number, total: number): Vec2 { /** Split an inclined orbit into the arc behind the vault and the arc in front. */
const angle = -Math.PI / 2 + index * GOLDEN; export function orbitArcs(
const band = index % 4; phys: OrbitPhysics,
const radius = 118 + band * 46 + Math.floor(index / 4) * 10; samples = 80,
const squash = 0.9 + (index % 3) * 0.05; ): { back: string; front: string } {
return { let back = "";
x: Math.cos(angle) * Math.min(radius, VIEW_R), let front = "";
y: Math.sin(angle) * Math.min(radius, VIEW_R) * squash, let prev: boolean | null = null;
}; for (let i = 0; i <= samples; i++) {
const p = positionOnEllipse((i / samples) * Math.PI * 2, phys);
const near = p.z >= 0;
const cmd = `${p.x.toFixed(1)} ${p.y.toFixed(1)}`;
if (near) {
front += prev === true ? `L ${cmd} ` : `M ${cmd} `;
} else {
back += prev === false ? `L ${cmd} ` : `M ${cmd} `;
}
prev = near;
}
return { back, front };
} }
function dist(a: Vec2, b: Vec2): number { function dist(a: Vec2, b: Vec2): number {
@@ -70,45 +79,68 @@ function dist(a: Vec2, b: Vec2): number {
return Math.hypot(dx, dy); return Math.hypot(dx, dy);
} }
const LAYOUT_VER = 2; const LAYOUT_VER = 3;
const layoutCache = new Map<string, Vec2[]>(); const layoutCache = new Map<string, Vec2[]>();
/** Golden-angle seeds relaxed for minimum star separation (lock mode). */ /**
* Lock layout: concentric rings, counts proportional to radius so
* neighbor chord length stays nearly constant on every ring.
*/
export function lockedPositions(total: number): Vec2[] { export function lockedPositions(total: number): Vec2[] {
const key = `${LAYOUT_VER}:${total}`; const key = `${LAYOUT_VER}:${total}`;
const cached = layoutCache.get(key); 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: Vec2[] = [];
const minSep = total > 12 ? 56 : 62; if (total <= 0) {
layoutCache.set(key, pts);
return pts;
}
for (let iter = 0; iter < 56; iter++) { const inner = 124;
const outer = 246;
if (total <= 7) {
const radius = (inner + outer) / 2;
for (let i = 0; i < total; i++) { for (let i = 0; i < total; i++) {
for (let j = i + 1; j < total; j++) { const a = -Math.PI / 2 + (i / total) * Math.PI * 2;
const d = dist(pts[i], pts[j]); pts.push({ x: Math.cos(a) * radius, y: Math.sin(a) * radius });
if (d < minSep && d > 0.001) { }
const push = (minSep - d) * 0.55; layoutCache.set(key, pts);
const ux = (pts[i].x - pts[j].x) / d; return pts;
const uy = (pts[i].y - pts[j].y) / d; }
pts[i].x += ux * push;
pts[i].y += uy * push; const rings = total <= 14 ? 2 : 3;
pts[j].x -= ux * push; const radii = Array.from({ length: rings }, (_, i) =>
pts[j].y -= uy * push; rings === 1 ? (inner + outer) / 2 : inner + ((outer - inner) * i) / (rings - 1),
} );
} const wsum = radii.reduce((a, b) => a + b, 0);
const r = dist(pts[i], { x: 0, y: 0 }); const counts = radii.map((r) => Math.max(1, Math.round((r / wsum) * total)));
const vaultPad = 96; let sum = counts.reduce((a, b) => a + b, 0);
if (r < vaultPad && r > 0.001) { while (sum > total) {
const s = vaultPad / r; let idx = 0;
pts[i].x *= s; for (let i = 1; i < counts.length; i++) {
pts[i].y *= s; if (counts[i] > counts[idx]) idx = i;
} }
const edge = dist(pts[i], { x: 0, y: 0 }); if (counts[idx] <= 1) break;
if (edge > VIEW_R) { counts[idx] -= 1;
const s = VIEW_R / edge; sum -= 1;
pts[i].x *= s; }
pts[i].y *= s; while (sum < total) {
} let idx = 0;
for (let i = 1; i < counts.length; i++) {
if (counts[i] < counts[idx]) idx = i;
}
counts[idx] += 1;
sum += 1;
}
for (let ri = 0; ri < rings; ri++) {
const count = counts[ri];
const radius = radii[ri];
const twist = (ri % 2) * (Math.PI / count);
for (let i = 0; i < count; i++) {
const a = -Math.PI / 2 + twist + (i / count) * Math.PI * 2;
pts.push({ x: Math.cos(a) * radius, y: Math.sin(a) * radius });
} }
} }
@@ -117,7 +149,34 @@ export function lockedPositions(total: number): Vec2[] {
} }
export function lockedSlot(index: number, total: number): Vec2 { export function lockedSlot(index: number, total: number): Vec2 {
return lockedPositions(total)[index] ?? slotSeed(index, total); const pts = lockedPositions(total);
return pts[index] ?? { x: 0, y: 0 };
}
/** Small inclined moon orbits around a parent, in parent-local space. */
export function flowMoonOffsets(
count: number,
time: number,
spread = 30,
): Pose3[] {
const out: Pose3[] = [];
const inc = 0.85;
for (let mi = 0; mi < count; mi++) {
const ang =
(mi / Math.max(count, 1)) * Math.PI * 2 + time * (1.05 + mi * 0.08);
const rad = spread * (0.82 + (mi % 3) * 0.1);
const lx = Math.cos(ang) * rad;
const ly = Math.sin(ang) * rad;
const y = ly * Math.cos(inc);
const z = Math.sin(ang) * Math.sin(inc);
out.push({
x: lx,
y,
z,
scale: 0.82 + (z + 1) * 0.12,
});
}
return out;
} }
export function moonPositions( export function moonPositions(