feat: animate the vault accretion disk

This commit is contained in:
2026-11-09 22:40:09 +07:00
parent 34154b2ef1
commit 3a0259cbdd
4 changed files with 34 additions and 13 deletions

View File

@@ -26,6 +26,7 @@ const HALF_HEIGHT = SCENE_HEIGHT / 2;
const labelFont = "500 11px ui-monospace, monospace";
const MAX_LABELS = 12;
const METEOR_SECONDS = 1.4;
const ACCRETION_SECONDS = 6.4;
export function BlackholeGalaxy({
orbits, selectedOrbitId, recentSnapshots, flowing, arrival, onSelectOrbit, onSelectSnapshot,
@@ -34,6 +35,7 @@ export function BlackholeGalaxy({
const bodyNodes = useRef(new Map<SVGGElement, { id: string; far: boolean }>());
const slotsBefore = useRef<ReturnType<typeof assignOrbitSlots>>(undefined);
const elapsed = useRef(0);
const core = useRef<SVGGElement>(null);
const meteor = useRef<{ id: string; time: number; source: Vec2 }>(undefined);
const trail = useRef<SVGPathElement>(null);
const head = useRef<SVGCircleElement>(null);
@@ -56,8 +58,11 @@ export function BlackholeGalaxy({
}, []);
const draw = useCallback((delta: number) => {
const moving = flowing && slots.size > 0;
if (moving) elapsed.current += delta;
if (flowing && delta > 0) {
elapsed.current += delta;
const phase = (elapsed.current % ACCRETION_SECONDS) / ACCRETION_SECONDS;
core.current?.style.setProperty("--accretion-offset", String(-100 * phase));
}
for (const [node, { id, far }] of bodyNodes.current) {
const slot = slots.get(id);
if (!slot) continue;
@@ -71,7 +76,7 @@ export function BlackholeGalaxy({
if (!arrival) {
effect.current?.setAttribute("opacity", "0");
return moving;
return flowing;
}
const slot = slots.get(arrival.orbitId);
if (meteor.current?.id !== arrival.snapshotId && slot) {
@@ -81,7 +86,7 @@ export function BlackholeGalaxy({
trail.current?.setAttribute("d", points.map(({ x, y }, i) => `${i ? "L" : "M"} ${x} ${y}`).join(" "));
}
const current = meteor.current;
if (!current || current.id !== arrival.snapshotId) return moving;
if (!current || current.id !== arrival.snapshotId) return flowing;
current.time += delta;
const progress = Math.min(1, current.time / METEOR_SECONDS);
const { x, y } = spiralPoint(current.source, progress);
@@ -89,10 +94,10 @@ export function BlackholeGalaxy({
head.current?.setAttribute("cy", String(y));
trail.current?.setAttribute("stroke-dashoffset", String(0.2 - progress));
effect.current?.setAttribute("opacity", String(progress >= 1 ? 0 : Math.min(1, (1 - progress) * 6)));
return moving || progress < 1;
return flowing || progress < 1;
}, [arrival, flowing, slots]);
useGalaxyMotion((flowing && slots.size > 0) || !!arrival, draw);
useGalaxyMotion(flowing || !!arrival, draw);
const scale = width / SCENE_WIDTH;
const height = SCENE_HEIGHT * scale;
@@ -166,7 +171,7 @@ export function BlackholeGalaxy({
))}
</g>
<g className="orbit-layer orbit-layer--far">{renderOrbits(true)}</g>
<VaultCore />
<VaultCore ref={core} />
<g className="orbit-layer orbit-layer--near">{renderOrbits(false)}</g>
{selectedPosition && moons.map(({ x, y }, index) => {
const snapshot = recentSnapshots[index];