cortico-world-memory-core 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -9
- package/ENV_PROMPT.md +9 -10
- package/README.md +32 -14
- package/assets/readme/banner.png +0 -0
- package/assets/screenshots/detail.png +0 -0
- package/assets/screenshots/galaxy.png +0 -0
- package/assets/screenshots/health.png +0 -0
- package/assets/screenshots/turns.png +0 -0
- package/describe.json +294 -235
- package/icon.svg +32 -26
- package/package.json +12 -9
- package/src/config.ts +26 -3
- package/src/recall.ts +118 -8
- package/src/review.ts +146 -0
- package/src/site.ts +57 -10
- package/src/store.ts +85 -39
- package/src/tools.ts +6 -8
- package/src/world.ts +225 -47
- package/webui/app.js +590 -1055
- package/webui/atlas.css +116 -0
- package/webui/index.html +24 -18
- package/webui/next.css +158 -8
- package/webui/next.html +31 -29
- package/webui/next.js +5 -14
- package/webui/starfield/atlas.js +168 -0
- package/webui/starfield/film.svg +22 -0
- package/webui/starfield/lucide-LICENSE.txt +15 -0
- package/webui/starfield/pause.svg +16 -0
- package/webui/starfield/play.svg +15 -0
- package/webui/starfield/scene.js +301 -0
- package/webui/starfield/three-LICENSE.txt +21 -0
- package/webui/starfield/three.core.min.js +6 -0
- package/webui/starfield/three.module.min.js +6 -0
- package/webui/style.css +160 -10
- package/webui/turns.css +21 -0
- package/assets/screenshots/graph.png +0 -0
- package/assets/screenshots/maintenance.png +0 -0
- package/assets/screenshots/table.png +0 -0
- package/assets/screenshots/timeline.png +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createGalaxy, orbitFor, overview, sectors } from './scene.js';
|
|
2
|
+
|
|
3
|
+
const sectorById = new Map(sectors.map(sector => [sector.id, sector]));
|
|
4
|
+
|
|
5
|
+
export function createOrbitAtlas(canvas, label, { kinds, onSelect, onZoom, onLost }) {
|
|
6
|
+
const galaxy = createGalaxy(canvas);
|
|
7
|
+
const motion = matchMedia('(prefers-reduced-motion: reduce)');
|
|
8
|
+
const sectorLabels = kinds.map(kind => {
|
|
9
|
+
const element = document.createElement('span');
|
|
10
|
+
element.className = 'orbit-sector';
|
|
11
|
+
element.textContent = kind.label;
|
|
12
|
+
element.dataset.orbitSector = kind.id;
|
|
13
|
+
element.style.setProperty('--signal', sectorById.get(kind.id).color);
|
|
14
|
+
element.setAttribute('aria-hidden', 'true');
|
|
15
|
+
element.hidden = true;
|
|
16
|
+
label.before(element);
|
|
17
|
+
return { id: kind.id, element, card: undefined };
|
|
18
|
+
});
|
|
19
|
+
let cards = [], byId = new Map(), selected, result, hovered, hoverAt, pointer;
|
|
20
|
+
let active = false, lost = false, frame, previous, arrive = 0;
|
|
21
|
+
let clock = Number(sessionStorage.getItem('mcore-orbit-time')) || 0;
|
|
22
|
+
let view = overview;
|
|
23
|
+
const usable = () => active && !lost && !document.hidden && canvas.clientWidth > 0 && canvas.clientHeight > 0;
|
|
24
|
+
|
|
25
|
+
function schedule() {
|
|
26
|
+
if (usable() && !frame) frame = requestAnimationFrame(draw);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function hit(x, y, margin = 15) {
|
|
30
|
+
const bounds = canvas.getBoundingClientRect();
|
|
31
|
+
let found;
|
|
32
|
+
for (const card of cards) {
|
|
33
|
+
const [left, top, depth] = galaxy.project(card);
|
|
34
|
+
const range = Math.hypot(x - bounds.left - left, y - bounds.top - top);
|
|
35
|
+
if (Math.abs(depth) <= 1 && range < margin) { found = card; margin = range; }
|
|
36
|
+
}
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function draw(now) {
|
|
41
|
+
frame = 0;
|
|
42
|
+
if (!usable()) { previous = undefined; return; }
|
|
43
|
+
const elapsed = previous === undefined ? 0 : (now - previous) / 1000;
|
|
44
|
+
previous = now;
|
|
45
|
+
clock += elapsed * (motion.matches ? .55 : 1);
|
|
46
|
+
const trace = motion.matches ? 1 : Math.max(0, now - arrive) / 590;
|
|
47
|
+
galaxy.render(view, clock, selected, trace, result);
|
|
48
|
+
for (const { element, card } of sectorLabels) {
|
|
49
|
+
const [left, top, depth] = galaxy.project(card);
|
|
50
|
+
element.hidden = Math.abs(depth) > 1 || left < 15 || left > canvas.clientWidth - 76 || top < 85 || top > canvas.clientHeight - 64;
|
|
51
|
+
if (!element.hidden) element.style.transform = `translate(${left}px,${top}px)`;
|
|
52
|
+
}
|
|
53
|
+
hovered = hoverAt && !pointer ? hit(...hoverAt) : undefined;
|
|
54
|
+
placeLabel(hovered ?? selected ?? result);
|
|
55
|
+
schedule();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function placeLabel(card) {
|
|
59
|
+
const [left, top, depth] = card ? galaxy.project(card) : [0, 0, Infinity];
|
|
60
|
+
label.hidden = Math.abs(depth) > 1 || left < 8 || left > canvas.clientWidth - 8 || top < 32 || top > canvas.clientHeight - 8;
|
|
61
|
+
canvas.style.cursor = pointer?.dragged ? 'grabbing' : hovered ? 'pointer' : '';
|
|
62
|
+
if (label.hidden) return;
|
|
63
|
+
if (label.textContent !== card.title) label.textContent = card.title;
|
|
64
|
+
label.style.setProperty('--signal', card.sector.color);
|
|
65
|
+
label.style.transform = `translate(${left}px,${top}px)`;
|
|
66
|
+
label.classList.toggle('label-left', left > canvas.clientWidth * .65);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resetTime() {
|
|
70
|
+
previous = undefined;
|
|
71
|
+
if (!usable() && frame) { cancelAnimationFrame(frame); frame = 0; }
|
|
72
|
+
schedule();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function setView(next) { view = next; onZoom(1 / view.distance); schedule(); }
|
|
76
|
+
function zoomBy(factor) {
|
|
77
|
+
setView({ ...view, distance: Math.min(1.8, Math.max(.4, view.distance / factor)) });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
canvas.addEventListener('wheel', event => {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
zoomBy(Math.exp(Math.max(-.30, Math.min(.30, -event.deltaY * .001))));
|
|
83
|
+
}, { passive: false });
|
|
84
|
+
canvas.addEventListener('pointerdown', event => {
|
|
85
|
+
if (event.button !== 0 || pointer) return;
|
|
86
|
+
hoverAt = hovered = undefined;
|
|
87
|
+
pointer = { id: event.pointerId, x: event.clientX, y: event.clientY, view };
|
|
88
|
+
canvas.setPointerCapture(event.pointerId);
|
|
89
|
+
schedule();
|
|
90
|
+
});
|
|
91
|
+
canvas.addEventListener('pointermove', event => {
|
|
92
|
+
if (!pointer) {
|
|
93
|
+
if (event.pointerType !== 'touch') { hoverAt = [event.clientX, event.clientY]; schedule(); }
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (pointer.id !== event.pointerId) return;
|
|
97
|
+
const dx = event.clientX - pointer.x, dy = event.clientY - pointer.y;
|
|
98
|
+
if (!pointer.dragged && Math.hypot(dx, dy) < 5) return;
|
|
99
|
+
pointer.dragged = true;
|
|
100
|
+
canvas.style.cursor = 'grabbing';
|
|
101
|
+
setView({ ...pointer.view, yaw: pointer.view.yaw - dx * .006, pitch: Math.max(.13, Math.min(1.34, pointer.view.pitch + dy * .004)) });
|
|
102
|
+
});
|
|
103
|
+
canvas.addEventListener('pointerup', event => {
|
|
104
|
+
if (pointer?.id !== event.pointerId) return;
|
|
105
|
+
if (!pointer.dragged) {
|
|
106
|
+
const card = hit(event.clientX, event.clientY, event.pointerType === 'touch' ? 21 : 15);
|
|
107
|
+
if (card) onSelect(card.id);
|
|
108
|
+
}
|
|
109
|
+
pointer = undefined;
|
|
110
|
+
schedule();
|
|
111
|
+
});
|
|
112
|
+
canvas.addEventListener('keydown', event => {
|
|
113
|
+
if (event.key !== 'Enter' || !(selected ?? result)) return;
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
event.stopPropagation();
|
|
116
|
+
onSelect((selected ?? result).id);
|
|
117
|
+
});
|
|
118
|
+
canvas.addEventListener('lostpointercapture', () => { pointer = undefined; schedule(); });
|
|
119
|
+
canvas.addEventListener('pointerleave', () => { hoverAt = hovered = undefined; schedule(); });
|
|
120
|
+
canvas.addEventListener('webglcontextlost', () => {
|
|
121
|
+
lost = true;
|
|
122
|
+
resetTime();
|
|
123
|
+
onLost();
|
|
124
|
+
});
|
|
125
|
+
document.addEventListener('visibilitychange', resetTime);
|
|
126
|
+
window.addEventListener('pagehide', () => sessionStorage.setItem('mcore-orbit-time', String(clock)));
|
|
127
|
+
motion.addEventListener('change', resetTime);
|
|
128
|
+
new ResizeObserver(schedule).observe(canvas);
|
|
129
|
+
function watchDensity() {
|
|
130
|
+
matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`).addEventListener('change', () => {
|
|
131
|
+
watchDensity();
|
|
132
|
+
schedule();
|
|
133
|
+
}, { once: true });
|
|
134
|
+
}
|
|
135
|
+
watchDensity();
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
setActive(value) {
|
|
139
|
+
if (active === value) return;
|
|
140
|
+
active = value;
|
|
141
|
+
if (!active) { hoverAt = hovered = undefined; label.hidden = true; }
|
|
142
|
+
else onZoom(1 / view.distance);
|
|
143
|
+
resetTime();
|
|
144
|
+
},
|
|
145
|
+
setCards(nodes) {
|
|
146
|
+
cards = nodes.map(node => {
|
|
147
|
+
const sector = sectorById.get(node.cluster);
|
|
148
|
+
return { ...node, sector, orbit: orbitFor(node.id, sector), title: node.title.replace(/\s+/g, ' ').trim().slice(0, 54) };
|
|
149
|
+
});
|
|
150
|
+
byId = new Map(cards.map(card => [card.id, card]));
|
|
151
|
+
for (const sectorLabel of sectorLabels) {
|
|
152
|
+
const sector = sectorById.get(sectorLabel.id);
|
|
153
|
+
const distance = ({ orbit }) => Math.hypot(orbit.radius - sector.radius, (orbit.angle - sector.angle) * sector.radius);
|
|
154
|
+
sectorLabel.card = cards.reduce((closest, card) => card.sector === sector && (!closest || distance(card) < distance(closest)) ? card : closest, undefined);
|
|
155
|
+
}
|
|
156
|
+
hovered = undefined;
|
|
157
|
+
galaxy.setCards(cards);
|
|
158
|
+
},
|
|
159
|
+
update(id, searching) {
|
|
160
|
+
if (id !== selected?.id) arrive = performance.now();
|
|
161
|
+
selected = byId.get(id);
|
|
162
|
+
result = searching ? cards[0] : undefined;
|
|
163
|
+
schedule();
|
|
164
|
+
},
|
|
165
|
+
reset() { setView(overview); },
|
|
166
|
+
zoomBy,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!-- @license lucide-static v0.468.0 - ISC -->
|
|
2
|
+
<svg
|
|
3
|
+
class="lucide lucide-film"
|
|
4
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
5
|
+
width="24"
|
|
6
|
+
height="24"
|
|
7
|
+
viewBox="0 0 24 24"
|
|
8
|
+
fill="none"
|
|
9
|
+
stroke="currentColor"
|
|
10
|
+
stroke-width="2"
|
|
11
|
+
stroke-linecap="round"
|
|
12
|
+
stroke-linejoin="round"
|
|
13
|
+
>
|
|
14
|
+
<rect width="18" height="18" x="3" y="3" rx="2" />
|
|
15
|
+
<path d="M7 3v18" />
|
|
16
|
+
<path d="M3 7.5h4" />
|
|
17
|
+
<path d="M3 12h18" />
|
|
18
|
+
<path d="M3 16.5h4" />
|
|
19
|
+
<path d="M17 3v18" />
|
|
20
|
+
<path d="M17 7.5h4" />
|
|
21
|
+
<path d="M17 16.5h4" />
|
|
22
|
+
</svg>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!-- @license lucide-static v0.468.0 - ISC -->
|
|
2
|
+
<svg
|
|
3
|
+
class="lucide lucide-pause"
|
|
4
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
5
|
+
width="24"
|
|
6
|
+
height="24"
|
|
7
|
+
viewBox="0 0 24 24"
|
|
8
|
+
fill="none"
|
|
9
|
+
stroke="currentColor"
|
|
10
|
+
stroke-width="2"
|
|
11
|
+
stroke-linecap="round"
|
|
12
|
+
stroke-linejoin="round"
|
|
13
|
+
>
|
|
14
|
+
<rect x="14" y="4" width="4" height="16" rx="1" />
|
|
15
|
+
<rect x="6" y="4" width="4" height="16" rx="1" />
|
|
16
|
+
</svg>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!-- @license lucide-static v0.468.0 - ISC -->
|
|
2
|
+
<svg
|
|
3
|
+
class="lucide lucide-play"
|
|
4
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
5
|
+
width="24"
|
|
6
|
+
height="24"
|
|
7
|
+
viewBox="0 0 24 24"
|
|
8
|
+
fill="none"
|
|
9
|
+
stroke="currentColor"
|
|
10
|
+
stroke-width="2"
|
|
11
|
+
stroke-linecap="round"
|
|
12
|
+
stroke-linejoin="round"
|
|
13
|
+
>
|
|
14
|
+
<polygon points="6 3 20 12 6 21 6 3" />
|
|
15
|
+
</svg>
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import * as THREE from './three.module.min.js';
|
|
2
|
+
|
|
3
|
+
export const sectors = [
|
|
4
|
+
{ id: 'fact', color: '#7ddacb', angle: 2.6, radius: 247 },
|
|
5
|
+
{ id: 'self', color: '#c3acfa', angle: 4.2, radius: 139 },
|
|
6
|
+
{ id: 'episode', color: '#91beff', angle: 5.75, radius: 234 },
|
|
7
|
+
{ id: 'promise', color: '#f0c87f', angle: .34, radius: 165 },
|
|
8
|
+
{ id: 'note', color: '#e5a2b4', angle: 1.34, radius: 286 },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const sceneRadius = 368;
|
|
12
|
+
const tau = Math.PI * 2;
|
|
13
|
+
const orbitRadii = [90, 200, 324];
|
|
14
|
+
const orbitPeriods = [116, 228, 432];
|
|
15
|
+
const armRate = tau / 640;
|
|
16
|
+
const bulgeSize = 1;
|
|
17
|
+
const memoryGlow = .23;
|
|
18
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
19
|
+
const mix = (from, to, fraction) => from + (to - from) * fraction;
|
|
20
|
+
const ease = fraction => {
|
|
21
|
+
const bounded = clamp(fraction, 0, 1);
|
|
22
|
+
return bounded * bounded * (3 - 2 * bounded);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function randomFrom(seed) {
|
|
26
|
+
return () => ((seed = (Math.imul(1664525, seed) + 1013904223) >>> 0) / 4294967296);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function orbitPeriod(radius) {
|
|
30
|
+
const index = radius <= orbitRadii[1] ? 0 : 1;
|
|
31
|
+
const fraction = (radius - orbitRadii[index]) / (orbitRadii[index + 1] - orbitRadii[index]);
|
|
32
|
+
return orbitPeriods[index] * (orbitPeriods[index + 1] / orbitPeriods[index]) ** fraction;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function orbitFor(id, sector) {
|
|
36
|
+
let seed = 2166136261;
|
|
37
|
+
for (const character of id) seed = Math.imul(seed ^ character.charCodeAt(0), 16777619);
|
|
38
|
+
const random = randomFrom(seed);
|
|
39
|
+
random();
|
|
40
|
+
const radius = clamp(sector.radius + (random() - .5) * 191, orbitRadii[0], orbitRadii[2]);
|
|
41
|
+
const angle = sector.angle + (random() - .5) * 1.60;
|
|
42
|
+
const height = (random() + random() - 1) * 21;
|
|
43
|
+
return { radius, angle, height, period: orbitPeriod(radius) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function orbitPosition(orbit, seconds) {
|
|
47
|
+
const angle = orbit.angle + seconds * tau / orbit.period;
|
|
48
|
+
return [Math.cos(angle) * orbit.radius, orbit.height, Math.sin(angle) * orbit.radius];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const overview = { yaw: .17, pitch: .59, distance: 1 };
|
|
52
|
+
|
|
53
|
+
export function linksFor(selected, memories) {
|
|
54
|
+
if (!selected) return [];
|
|
55
|
+
const related = memories.filter(memory => memory !== selected);
|
|
56
|
+
const recorded = related.filter(memory => selected.related.includes(memory.id) || memory.related.includes(selected.id));
|
|
57
|
+
const topical = related.filter(memory => !recorded.includes(memory) && memory.tags.some(tag => selected.tags.includes(tag))).slice(0, 3);
|
|
58
|
+
return [...recorded.map(memory => ({ memory, recorded: true })), ...topical.map(memory => ({ memory, recorded: false }))];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function tint(hex) {
|
|
62
|
+
return new THREE.Color(hex).convertLinearToSRGB().toArray();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function sprites(particles, kind, pixelHeight, density, elapsed) {
|
|
66
|
+
const geometry = new THREE.BufferGeometry();
|
|
67
|
+
for (const field of ['position', 'shade', 'profile']) {
|
|
68
|
+
geometry.setAttribute(field, new THREE.Float32BufferAttribute(particles.flatMap(particle => particle[field]), 3));
|
|
69
|
+
}
|
|
70
|
+
geometry.setAttribute('orbitRate', new THREE.Float32BufferAttribute(particles.map(particle => particle.rate ?? 0), 1));
|
|
71
|
+
const material = new THREE.ShaderMaterial({
|
|
72
|
+
transparent: true, depthTest: false, depthWrite: false, blending: THREE.AdditiveBlending,
|
|
73
|
+
uniforms: { pixelHeight, density, elapsed, armRate: { value: armRate }, kind: { value: kind }, glowAmount: { value: memoryGlow } },
|
|
74
|
+
vertexShader: `
|
|
75
|
+
attribute vec3 shade;
|
|
76
|
+
attribute vec3 profile;
|
|
77
|
+
attribute float orbitRate;
|
|
78
|
+
varying vec3 hue;
|
|
79
|
+
varying vec2 optics;
|
|
80
|
+
uniform float pixelHeight, density, kind, elapsed, armRate;
|
|
81
|
+
vec2 turn(vec2 point, float angle) {
|
|
82
|
+
float c = cos(angle), s = sin(angle);
|
|
83
|
+
return mat2(c, s, -s, c) * point;
|
|
84
|
+
}
|
|
85
|
+
float armAngle(vec2 point) {
|
|
86
|
+
return atan(point.y, point.x + 0.001) - log(max(12.0, length(point)) / 32.0) * 1.27;
|
|
87
|
+
}
|
|
88
|
+
float dust(vec3 at) {
|
|
89
|
+
if (at.y >= 5.0) return 1.0;
|
|
90
|
+
vec3 hit = mix(at, cameraPosition, clamp((5.0 - at.y) / max(1.0, cameraPosition.y - at.y), 0.0, 1.0));
|
|
91
|
+
float r = length(hit.xz);
|
|
92
|
+
vec2 lanePoint = turn(hit.xz, -elapsed * armRate);
|
|
93
|
+
float twist = armAngle(lanePoint);
|
|
94
|
+
float grit = 0.64 + 0.21 * sin(lanePoint.x * 0.12 + sin(lanePoint.y * 0.16)) + 0.14 * sin(lanePoint.y * 0.31 + lanePoint.x * 0.20);
|
|
95
|
+
float ripple = sin((twist - 0.24) * 1.5);
|
|
96
|
+
float lane = exp(-18.0 * ripple * ripple) * smoothstep(23.0, 58.0, r) * (1.0 - smoothstep(246.0, 350.0, r));
|
|
97
|
+
float seam = lanePoint.y - 14.0 + lanePoint.x * 0.17 + 3.2 * sin(lanePoint.x * 0.17);
|
|
98
|
+
float foreground = exp(-seam * seam / 26.0 - lanePoint.x * lanePoint.x / 820.0);
|
|
99
|
+
return 1.0 - min(0.80, (lane * 0.78 + foreground * 0.91) * grit);
|
|
100
|
+
}
|
|
101
|
+
void main() {
|
|
102
|
+
vec3 at = position;
|
|
103
|
+
if (orbitRate > 0.0) at.xz = turn(at.xz, elapsed * orbitRate);
|
|
104
|
+
vec4 view = kind > 2.5 ? vec4(at, 1.0) : modelViewMatrix * vec4(at, 1.0);
|
|
105
|
+
gl_Position = projectionMatrix * view;
|
|
106
|
+
float size = profile.x * pixelHeight / max(1.0, -view.z);
|
|
107
|
+
gl_PointSize = kind > 1.5 && kind < 2.5 ? clamp(size, 11.0 * density, 24.0 * density) : clamp(size, density, 116.0 * density);
|
|
108
|
+
hue = shade;
|
|
109
|
+
float depthShade = kind < 1.5 ? dust(at) * mix(1.0, 0.72, smoothstep(740.0, 1080.0, -view.z)) : 1.0;
|
|
110
|
+
float armLight = 1.0;
|
|
111
|
+
if (kind < 0.5 && orbitRate > 0.0) {
|
|
112
|
+
float phase = armAngle(at.xz) - elapsed * armRate;
|
|
113
|
+
float ripple = sin(phase * 1.5);
|
|
114
|
+
armLight = 0.42 + 0.58 * exp(-4.0 * ripple * ripple);
|
|
115
|
+
}
|
|
116
|
+
optics = vec2(profile.y * depthShade * armLight, profile.z);
|
|
117
|
+
}`,
|
|
118
|
+
fragmentShader: `
|
|
119
|
+
uniform float kind, glowAmount;
|
|
120
|
+
varying vec3 hue;
|
|
121
|
+
varying vec2 optics;
|
|
122
|
+
void main() {
|
|
123
|
+
vec2 uv = gl_PointCoord - 0.5;
|
|
124
|
+
float radius = length(uv);
|
|
125
|
+
if (radius > 0.499) discard;
|
|
126
|
+
float glow = exp(-18.0 * radius * radius);
|
|
127
|
+
float envelope = 1.0 - smoothstep(0.26, 0.5, radius);
|
|
128
|
+
if (kind > 1.5 && kind < 2.5) {
|
|
129
|
+
float edge = fwidth(radius) * 0.72;
|
|
130
|
+
float heart = 1.0 - smoothstep(0.115 - edge, 0.115 + edge, radius);
|
|
131
|
+
float rim = 1.0 - smoothstep(edge, edge * 2.2, abs(radius - 0.34));
|
|
132
|
+
vec3 light = vec3(1.0, 0.99, 0.96) * heart * 0.92 + mix(vec3(0.83, 0.89, 1.0), hue, optics.y) * glow * glowAmount * (0.48 + optics.y) + hue * rim * optics.y * 0.32;
|
|
133
|
+
float coverage = max(light.r, max(light.g, light.b));
|
|
134
|
+
gl_FragColor = vec4(light / max(coverage, 0.001), optics.x * envelope * coverage);
|
|
135
|
+
} else {
|
|
136
|
+
float strength = kind > 0.5 && kind < 1.5 ? glow : exp(-20.0 * radius * radius);
|
|
137
|
+
gl_FragColor = vec4(hue, optics.x * strength * envelope);
|
|
138
|
+
}
|
|
139
|
+
}`,
|
|
140
|
+
});
|
|
141
|
+
const object = new THREE.Points(geometry, material);
|
|
142
|
+
object.frustumCulled = false;
|
|
143
|
+
return object;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function atmosphere(detail) {
|
|
147
|
+
const random = randomFrom(98215);
|
|
148
|
+
const cool = ['#7793b5', '#879cba', '#b5c4d6', '#c6b8ad', '#d7d3cc'].map(tint);
|
|
149
|
+
const warm = ['#d8ad80', '#e8c7a2', '#f5e4c9', '#fff2da'].map(tint);
|
|
150
|
+
const mist = ['#71999f', '#85819b', '#65949e'].map(tint);
|
|
151
|
+
const stars = [], haze = [], sky = [];
|
|
152
|
+
const scatter = () => random() + random() + random() - 1.5;
|
|
153
|
+
for (let index = 0; index < 21000 * detail; index += 1) {
|
|
154
|
+
const radius = 11 + random() ** 1.32 * sceneRadius;
|
|
155
|
+
const arm = index % 3;
|
|
156
|
+
const spine = arm * tau / 3 + Math.log(radius / 32) * 1.27;
|
|
157
|
+
const clump = (.67 + .33 * Math.sin(radius * .057 + arm * 2.1) ** 2) * (arm === 1 ? .65 : 1);
|
|
158
|
+
const loose = index % 7 < 2;
|
|
159
|
+
const angle = spine + (loose ? random() * tau : scatter() * (.29 + 53 / (radius + 70)));
|
|
160
|
+
const position = [Math.cos(angle) * radius, scatter() * (12 + radius * .043), Math.sin(angle) * radius];
|
|
161
|
+
const edge = (1 - ease((radius - 246) / 136)) * clump;
|
|
162
|
+
const palette = radius < 95 && index % 3 ? warm : cool;
|
|
163
|
+
const shade = palette[index % palette.length];
|
|
164
|
+
stars.push({ position, shade, rate: tau / orbitPeriod(radius), profile: [1.3 + random() ** 2.8 * 2.1, edge * (.18 + random() ** 2 * .41) * (loose ? .72 : 1), 0] });
|
|
165
|
+
if (index % 12 === 0 && radius > 45 && !loose) haze.push({ position, shade: mist[arm], rate: armRate, profile: [10 + random() ** 1.4 * 48, edge * (.022 + random() ** 3 * .043) / detail, 0] });
|
|
166
|
+
}
|
|
167
|
+
for (let index = 0; index < 4100 * detail; index += 1) {
|
|
168
|
+
const radius = (4 + random() ** 1.55 * 78) * bulgeSize;
|
|
169
|
+
const angle = random() * tau;
|
|
170
|
+
const position = [Math.cos(angle) * radius * 1.09 + 1.4, scatter() * (5 + radius * .25), Math.sin(angle) * radius * .79];
|
|
171
|
+
const bright = (.053 + .33 * Math.exp(-radius / (23 * bulgeSize)) + random() ** 4 * .17) / detail;
|
|
172
|
+
const shade = warm[index % warm.length];
|
|
173
|
+
stars.push({ position, shade, profile: [1.25 + random() ** 2.8 * 2.65, bright, 0] });
|
|
174
|
+
if (index % 8 === 0) haze.push({ position, shade, profile: [(12 + random() ** 2 * 53) * bulgeSize, bright * (radius < 28 * bulgeSize ? .068 : .044), 0] });
|
|
175
|
+
}
|
|
176
|
+
for (let index = 0; index < 2300 * detail; index += 1) {
|
|
177
|
+
const position = [(random() - .5) * 3030, (random() - .5) * 860, -1100];
|
|
178
|
+
sky.push({ position, shade: cool[index % cool.length], profile: [1.6 + random() ** 5 * 3, .075 + random() ** 2.5 * .24, 0] });
|
|
179
|
+
}
|
|
180
|
+
for (const [radius, angle, shade] of [[104, 1.42, mist[0]], [157, 2.45, mist[2]], [220, 4.16, mist[0]], [263, 5.9, mist[1]]]) {
|
|
181
|
+
const rate = tau / orbitPeriod(radius);
|
|
182
|
+
for (let index = 0; index < 44 * detail; index += 1) {
|
|
183
|
+
const spread = scatter();
|
|
184
|
+
const distance = radius + spread * 26;
|
|
185
|
+
const bearing = angle + spread * .29 + scatter() * .18;
|
|
186
|
+
const position = [Math.cos(bearing) * distance, scatter() * 15 - 5, Math.sin(bearing) * distance];
|
|
187
|
+
haze.push({ position, shade, rate, profile: [12 + random() ** 1.7 * 39, (.032 + random() ** 2 * .064) / detail, 0] });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { stars, haze, sky };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function createGalaxy(canvas) {
|
|
194
|
+
const renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true, powerPreference: 'low-power' });
|
|
195
|
+
renderer.setClearColor(0, 0);
|
|
196
|
+
const camera = new THREE.PerspectiveCamera(40, 1, 2, 3800);
|
|
197
|
+
const scene = new THREE.Scene();
|
|
198
|
+
const ray = new THREE.Vector3();
|
|
199
|
+
const pixelHeight = { value: 1 };
|
|
200
|
+
const density = { value: 1 };
|
|
201
|
+
const elapsed = { value: 0 };
|
|
202
|
+
const detail = (navigator.deviceMemory ?? 8) <= 4 || (navigator.hardwareConcurrency ?? 8) <= 4 ? .53 : 1;
|
|
203
|
+
const { stars, haze, sky } = atmosphere(detail);
|
|
204
|
+
const far = sprites(sky, 3, pixelHeight, density, elapsed), disk = sprites(stars, 0, pixelHeight, density, elapsed), veil = sprites(haze, 1, pixelHeight, density, elapsed);
|
|
205
|
+
let memories = [], dots, positions;
|
|
206
|
+
const projections = new Map();
|
|
207
|
+
const tracer = new THREE.Group();
|
|
208
|
+
disk.renderOrder = 1;
|
|
209
|
+
veil.renderOrder = 1;
|
|
210
|
+
tracer.renderOrder = 3;
|
|
211
|
+
scene.add(far, disk, veil, tracer);
|
|
212
|
+
|
|
213
|
+
let activeKey, width = 0, height = 0;
|
|
214
|
+
function setCards(cards) {
|
|
215
|
+
if (dots) { scene.remove(dots); dots.geometry.dispose(); dots.material.dispose(); }
|
|
216
|
+
memories = cards;
|
|
217
|
+
projections.clear();
|
|
218
|
+
activeKey = undefined;
|
|
219
|
+
dots = sprites(memories.map(memory => ({ position: orbitPosition(memory.orbit, 0), shade: tint(memory.sector.color), profile: [0, 0, 0] })), 2, pixelHeight, density, elapsed);
|
|
220
|
+
positions = dots.geometry.getAttribute('position').setUsage(THREE.DynamicDrawUsage);
|
|
221
|
+
dots.renderOrder = 5;
|
|
222
|
+
scene.add(dots);
|
|
223
|
+
}
|
|
224
|
+
function render(view, time, selected, lineProgress, result) {
|
|
225
|
+
const newWidth = canvas.clientWidth, newHeight = canvas.clientHeight;
|
|
226
|
+
const newDensity = Math.min(window.devicePixelRatio || 1, 2);
|
|
227
|
+
if (!newWidth || !newHeight) return;
|
|
228
|
+
elapsed.value = time;
|
|
229
|
+
if (width !== newWidth || height !== newHeight || newDensity !== density.value) {
|
|
230
|
+
width = newWidth;
|
|
231
|
+
height = newHeight;
|
|
232
|
+
camera.setViewOffset(width, height, 0, width > height ? height * .048 : 0, width, height);
|
|
233
|
+
density.value = newDensity;
|
|
234
|
+
renderer.setDrawingBufferSize(width, height, newDensity);
|
|
235
|
+
pixelHeight.value = height * newDensity / (2 * Math.tan(camera.fov * Math.PI / 360));
|
|
236
|
+
}
|
|
237
|
+
const radius = Math.max(720, (camera.aspect < 1 ? mix(1180, 1410, camera.aspect) : 1410) / camera.aspect) * view.distance;
|
|
238
|
+
const pitch = clamp(view.pitch - clamp((camera.aspect - 1.75) * .21, 0, .14) + clamp(1 - camera.aspect, 0, .7) * .18, .13, 1.34);
|
|
239
|
+
camera.position.set(radius * Math.sin(view.yaw) * Math.cos(pitch), radius * Math.sin(pitch), radius * Math.cos(view.yaw) * Math.cos(pitch));
|
|
240
|
+
camera.lookAt(0, 0, 0);
|
|
241
|
+
camera.rotateZ(.25);
|
|
242
|
+
camera.updateMatrixWorld();
|
|
243
|
+
|
|
244
|
+
const key = `${selected?.id ?? ''}|${result?.id ?? ''}`;
|
|
245
|
+
if (key !== activeKey) {
|
|
246
|
+
activeKey = key;
|
|
247
|
+
for (const line of [...tracer.children]) {
|
|
248
|
+
tracer.remove(line);
|
|
249
|
+
line.geometry.dispose();
|
|
250
|
+
line.material.dispose();
|
|
251
|
+
}
|
|
252
|
+
const links = linksFor(selected, memories);
|
|
253
|
+
const markers = dots.geometry.getAttribute('profile');
|
|
254
|
+
for (const [index, memory] of memories.entries()) {
|
|
255
|
+
const focused = memory === selected || memory === result;
|
|
256
|
+
const brightness = focused ? 1.07 : .83 + .16 * Math.exp(-memory.days / 30);
|
|
257
|
+
markers.setXYZ(index, (12 + memory.weight * 13) * (focused ? 1.36 : 1), brightness, focused ? .82 : .04);
|
|
258
|
+
}
|
|
259
|
+
markers.needsUpdate = true;
|
|
260
|
+
for (const { memory, recorded } of links) {
|
|
261
|
+
const parameters = { color: recorded ? '#c6ddf2' : '#8daab4', opacity: recorded ? .56 : .41, transparent: true, depthWrite: false };
|
|
262
|
+
const geometry = new THREE.BufferGeometry();
|
|
263
|
+
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(23 * 3), 3));
|
|
264
|
+
geometry.setAttribute('lineDistance', new THREE.BufferAttribute(new Float32Array(23), 1));
|
|
265
|
+
const line = new THREE.Line(geometry, recorded ? new THREE.LineBasicMaterial(parameters) : new THREE.LineDashedMaterial({ ...parameters, dashSize: 4, gapSize: 5 }));
|
|
266
|
+
line.frustumCulled = false;
|
|
267
|
+
line.userData.memory = memory;
|
|
268
|
+
tracer.add(line);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (const [index, memory] of memories.entries()) {
|
|
272
|
+
positions.setXYZ(index, ...orbitPosition(memory.orbit, time));
|
|
273
|
+
const position = ray.fromBufferAttribute(positions, index).toArray();
|
|
274
|
+
projections.set(memory, { position, screen: projectPoint(position) });
|
|
275
|
+
}
|
|
276
|
+
positions.needsUpdate = true;
|
|
277
|
+
for (const line of tracer.children) {
|
|
278
|
+
const from = projections.get(selected).position, to = projections.get(line.userData.memory).position;
|
|
279
|
+
const path = line.geometry.getAttribute('position'), distances = line.geometry.getAttribute('lineDistance');
|
|
280
|
+
let previous = from, distance = 0;
|
|
281
|
+
for (let step = 0; step < 23; step += 1) {
|
|
282
|
+
const part = step / 22;
|
|
283
|
+
const point = [mix(from[0], to[0], part), mix(from[1], to[1], part) + 48 * part * (1 - part), mix(from[2], to[2], part)];
|
|
284
|
+
distance += Math.hypot(...point.map((value, index) => value - previous[index]));
|
|
285
|
+
path.setXYZ(step, ...point);
|
|
286
|
+
distances.setX(step, distance);
|
|
287
|
+
previous = point;
|
|
288
|
+
}
|
|
289
|
+
path.needsUpdate = distances.needsUpdate = true;
|
|
290
|
+
line.material.opacity = (line.material.isLineDashedMaterial ? .41 : .56) * ease(lineProgress);
|
|
291
|
+
}
|
|
292
|
+
renderer.render(scene, camera);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function projectPoint(position) {
|
|
296
|
+
ray.set(...position).project(camera);
|
|
297
|
+
return [(ray.x * .5 + .5) * width, (.5 - ray.y * .5) * height, ray.z];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return { setCards, render, project: entry => projections.get(entry)?.screen ?? [0, 0, Infinity] };
|
|
301
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2010-2025 three.js authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|