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 type { Orbit, Snapshot } from "../../api";
import {
flowMoonOffsets,
flowOrbitPhysics,
lockedSlot,
lerpPos,
moonPositions,
orbitArcs,
positionOnEllipse,
relaxLockedMoons,
} from "../../lib/galaxyLayout";
@@ -154,124 +156,200 @@ export function BlackholeGalaxy({
{starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
const arcs = orbitArcs(phys);
return (
<ellipse
key={`path-${orbit.id}`}
cx="0"
cy="0"
rx={phys.rx}
ry={phys.ry}
<path
key={`path-back-${orbit.id}`}
d={arcs.back}
fill="none"
stroke="#4a5f9e"
strokeOpacity={flowing ? 0.07 : 0.16}
strokeWidth="0.7"
strokeDasharray="3 10"
transform={`rotate(${phys.tiltDeg})`}
stroke="#6d84c4"
strokeOpacity={flowing ? 0.08 : 0.1}
strokeWidth={0.7}
strokeDasharray="2 10"
/>
);
})}
<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} />
{starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
const flowAngle = phys.phase + t * phys.speed;
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] ?? [];
const arcs = orbitArcs(phys);
return (
<g key={orbit.id}>
{!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);
}}
/>
{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>
<path
key={`path-front-${orbit.id}`}
d={arcs.front}
fill="none"
stroke="#9aafdf"
strokeOpacity={flowing ? 0.2 : 0.12}
strokeWidth={0.9}
strokeDasharray="2 8"
/>
);
})}
<StarLayer
which="front"
t={t}
blend={blend}
flowing={flowing}
starOrbits={starOrbits}
snapsByOrbit={snapsByOrbit}
lockLayout={lockLayout}
selectedSnapshotId={selectedSnapshotId}
showLabels={showLabels}
onSelectOrbit={onSelectOrbit}
onSelectSnapshot={onSelectSnapshot}
/>
</svg>
</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({
id,
x,
@@ -357,6 +435,7 @@ function MoonBody({
rim,
selected,
locked,
opacity = 1,
onClick,
}: {
x: number;
@@ -366,10 +445,15 @@ function MoonBody({
rim: string;
selected: boolean;
locked: boolean;
opacity?: number;
onClick: (e: React.MouseEvent<SVGGElement>) => void;
}) {
return (
<g className={locked ? "cursor-pointer" : "pointer-events-none"} onClick={onClick}>
<g
opacity={opacity}
className={locked ? "cursor-pointer" : "pointer-events-none"}
onClick={onClick}
>
{locked && (
<circle cx={x} cy={y} r={hitR} fill="transparent" />
)}