spi3der 0.0.0-stage → 0.1.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/APP.md +40 -0
- package/Dockerfile +4 -0
- package/MCP.md +149 -0
- package/PLAYER.md +136 -0
- package/README.md +35 -2
- package/api/mcp.mjs +31 -0
- package/api/store.mjs +158 -0
- package/bin/spi3der.mjs +20 -0
- package/emulator.html +17 -0
- package/engine/8fa668821759/bevel.js +265 -0
- package/engine/8fa668821759/camera.js +76 -0
- package/engine/8fa668821759/character.js +1019 -0
- package/engine/8fa668821759/check.js +83 -0
- package/engine/8fa668821759/csg.js +342 -0
- package/engine/8fa668821759/edit.js +48 -0
- package/engine/8fa668821759/galaxy.js +265 -0
- package/engine/8fa668821759/gl.js +798 -0
- package/engine/8fa668821759/gpu.js +1356 -0
- package/engine/8fa668821759/index.js +48 -0
- package/engine/8fa668821759/instances.js +41 -0
- package/engine/8fa668821759/joints.js +355 -0
- package/engine/8fa668821759/kernel-bytes.js +2 -0
- package/engine/8fa668821759/kernel.js +82 -0
- package/engine/8fa668821759/lathe.js +87 -0
- package/engine/8fa668821759/material.js +19 -0
- package/engine/8fa668821759/mesh.js +131 -0
- package/engine/8fa668821759/order.js +125 -0
- package/engine/8fa668821759/pick.js +85 -0
- package/engine/8fa668821759/place.js +17 -0
- package/engine/8fa668821759/planet.js +376 -0
- package/engine/8fa668821759/rig.js +417 -0
- package/engine/8fa668821759/saw.js +121 -0
- package/engine/8fa668821759/sky.js +428 -0
- package/engine/8fa668821759/svg.js +239 -0
- package/engine/8fa668821759/text.js +231 -0
- package/engine/8fa668821759/triangulate.js +72 -0
- package/engine/8fa668821759/types.js +2 -0
- package/engine/8fa668821759/vec.js +22 -0
- package/engine/8fa668821759/version.js +7 -0
- package/engine/8fa668821759/vrtsh.js +354 -0
- package/engine/8fa668821759/wire.js +346 -0
- package/favicon.svg +15 -0
- package/help.md +289 -0
- package/icons/apple-touch-icon.png +0 -0
- package/icons/favicon-32.png +0 -0
- package/icons/icon-192.png +0 -0
- package/icons/icon-512.png +0 -0
- package/icons/icon-maskable-512.png +0 -0
- package/icons/icon-maskable.svg +13 -0
- package/icons/icon.svg +15 -0
- package/index.html +13730 -0
- package/manifest.webmanifest +37 -0
- package/mcp/engine/bevel.js +265 -0
- package/mcp/engine/camera.js +76 -0
- package/mcp/engine/character.js +1019 -0
- package/mcp/engine/check.js +83 -0
- package/mcp/engine/csg.js +342 -0
- package/mcp/engine/edit.js +48 -0
- package/mcp/engine/galaxy.js +265 -0
- package/mcp/engine/gl.js +798 -0
- package/mcp/engine/gpu.js +1356 -0
- package/mcp/engine/index.js +48 -0
- package/mcp/engine/instances.js +41 -0
- package/mcp/engine/joints.js +355 -0
- package/mcp/engine/kernel-bytes.js +2 -0
- package/mcp/engine/kernel.js +82 -0
- package/mcp/engine/lathe.js +87 -0
- package/mcp/engine/material.js +19 -0
- package/mcp/engine/mesh.js +131 -0
- package/mcp/engine/order.js +125 -0
- package/mcp/engine/pick.js +85 -0
- package/mcp/engine/place.js +17 -0
- package/mcp/engine/planet.js +376 -0
- package/mcp/engine/rig.js +417 -0
- package/mcp/engine/saw.js +121 -0
- package/mcp/engine/sky.js +428 -0
- package/mcp/engine/svg.js +239 -0
- package/mcp/engine/text.js +231 -0
- package/mcp/engine/triangulate.js +72 -0
- package/mcp/engine/types.js +2 -0
- package/mcp/engine/vec.js +22 -0
- package/mcp/engine/version.js +7 -0
- package/mcp/engine/vrtsh.js +354 -0
- package/mcp/engine/wire.js +346 -0
- package/mcp/http.js +292 -0
- package/mcp/live.js +95 -0
- package/mcp/package.json +10 -0
- package/mcp/scene.js +1027 -0
- package/mcp/serve.js +87 -0
- package/mcp/server.js +97 -0
- package/media/face-of-spider.png +0 -0
- package/media/spider-paint-2015.png +0 -0
- package/media/spider-web.png +0 -0
- package/models/deepsky-lark.scene.json +1 -0
- package/models/deepsky.scene.json +1 -0
- package/models/globe.scene.json +1 -0
- package/models/lark-4.scene.json +1 -0
- package/models/lark.game.json +14 -0
- package/models/spider-build-v2.md +215 -0
- package/models/spider-build-v2.mjs +355 -0
- package/models/spider-build-v2.schema.json +1001 -0
- package/nginx.conf +12 -0
- package/package.json +45 -4
- package/player.html +274 -0
- package/sky.html +133 -0
- package/sky.md +285 -0
- package/src/demo.js +92 -0
- package/src/emulator/devices.js +22 -0
- package/src/emulator/xr.js +362 -0
- package/src/math.js +77 -0
- package/sw.js +37 -0
- package/xr-compare.html +332 -0
- package/xr-test.html +248 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// A galaxy as a recipe instead of a stored point set: a few numbers (kind, seed, shape) from which the same points are sampled
|
|
2
|
+
// every time, on the fly, when the viewer needs them (the galaxy is big enough on screen). The frame is the unit one: radius 1,
|
|
3
|
+
// the disc in the x-z plane (normal = y). Every point stands for millions of stars.
|
|
4
|
+
const BLUE = [170, 195, 255], WHITE = [255, 240, 225], GOLD = [255, 205, 140], RED = [255, 170, 105], PINK = [255, 190, 215];
|
|
5
|
+
const DEFAULT_N = { S: 1800, E: 1400, I: 700, D: 350, P: 2400, H: 900 };
|
|
6
|
+
const UV = [150, 165, 255], TEAL = [140, 255, 215];
|
|
7
|
+
export const galaxyPoints = (g) => {
|
|
8
|
+
let seed = (Math.abs(Math.floor(g.seed)) % 2147483646) + 1;
|
|
9
|
+
const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
|
|
10
|
+
const gauss = () => Math.sqrt(-2 * Math.log(1 - rnd())) * Math.cos(2 * Math.PI * rnd());
|
|
11
|
+
const expo = (s) => -s * Math.log(1 - rnd());
|
|
12
|
+
const mix = (a, b, t) => ((Math.round(a[0] + (b[0] - a[0]) * t) << 16) | (Math.round(a[1] + (b[1] - a[1]) * t) << 8) | Math.round(a[2] + (b[2] - a[2]) * t)) >>> 0;
|
|
13
|
+
const n = Math.max(1, Math.round(g.n ?? DEFAULT_N[g.kind]));
|
|
14
|
+
const out = { n, p: new Float32Array(n * 3), r: new Float32Array(n), c: new Uint32Array(n), l: new Float32Array(n) };
|
|
15
|
+
let i = 0;
|
|
16
|
+
const add = (x, y, z, r, c, l) => {
|
|
17
|
+
if (i >= n)
|
|
18
|
+
return;
|
|
19
|
+
out.p[3 * i] = x;
|
|
20
|
+
out.p[3 * i + 1] = y;
|
|
21
|
+
out.p[3 * i + 2] = z;
|
|
22
|
+
out.r[i] = r;
|
|
23
|
+
out.c[i] = c;
|
|
24
|
+
out.l[i] = l;
|
|
25
|
+
i++;
|
|
26
|
+
};
|
|
27
|
+
const inside = (x, y, z) => x * x + y * y + z * z <= 1;
|
|
28
|
+
let guard = n * 50; // rejection sampling never loops forever
|
|
29
|
+
if (g.kind === 'S') {
|
|
30
|
+
const arms = Math.max(1, Math.round(g.arms ?? 2));
|
|
31
|
+
const tan = Math.tan((((g.pitch ?? 17) * Math.PI) / 180));
|
|
32
|
+
const share = g.armShare ?? 0.6;
|
|
33
|
+
const bar = g.bar ?? 0;
|
|
34
|
+
const bulge = Math.round(n * 0.16);
|
|
35
|
+
const barN = bar > 0 ? Math.round(n * 0.08) : 0;
|
|
36
|
+
while (i < bulge && guard--)
|
|
37
|
+
add(gauss() * 0.1, gauss() * 0.06, gauss() * 0.1, 0.04, mix(GOLD, RED, rnd() * 0.5), 1.4);
|
|
38
|
+
while (i < bulge + barN && guard--)
|
|
39
|
+
add((rnd() * 2 - 1) * bar, gauss() * 0.03, gauss() * bar * 0.18, 0.04, mix(GOLD, WHITE, rnd() * 0.4), 1.2);
|
|
40
|
+
const r0 = Math.max(0.2, bar || 0.35); // the arms start at the end of the bar
|
|
41
|
+
while (i < n && guard--) {
|
|
42
|
+
const r = 0.06 + expo(0.3);
|
|
43
|
+
if (r > 1)
|
|
44
|
+
continue;
|
|
45
|
+
const y = gauss() * 0.02;
|
|
46
|
+
if (rnd() < share && r > r0 * 0.6) {
|
|
47
|
+
const k = Math.floor(rnd() * arms);
|
|
48
|
+
const th = Math.log(r / r0) / tan + (k * 2 * Math.PI) / arms + (gauss() * (0.04 + 0.07 * r)) / r;
|
|
49
|
+
add(r * Math.cos(th), y, r * Math.sin(th), 0.035, rnd() < 0.55 ? mix(BLUE, WHITE, rnd() * 0.5) : mix(WHITE, GOLD, rnd() * 0.5), 1.1);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const th = rnd() * 2 * Math.PI;
|
|
53
|
+
add(r * Math.cos(th), y, r * Math.sin(th), 0.037, mix(WHITE, GOLD, rnd() * 0.7), 0.8);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (g.kind === 'E') {
|
|
58
|
+
const b = g.b ?? 0.8, c = g.c ?? 0.9;
|
|
59
|
+
while (i < n && guard--) {
|
|
60
|
+
const u = Math.max(rnd() ** (1 / 3), 1e-3);
|
|
61
|
+
const s = 0.3 / Math.sqrt(Math.max(1e-6, u ** -2 - 1)); // the radius of a Plummer sphere (scale 0.3)
|
|
62
|
+
if (s > 1)
|
|
63
|
+
continue;
|
|
64
|
+
const v = [gauss(), gauss(), gauss()], l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
65
|
+
add((v[0] / l) * s, (v[1] / l) * s * b, (v[2] / l) * s * c, 0.04, mix(GOLD, RED, rnd() * 0.7), 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (g.kind === 'I') {
|
|
69
|
+
const clumps = Math.max(1, Math.round(g.clumps ?? 6));
|
|
70
|
+
const centres = Array.from({ length: clumps }, () => [gauss() * 0.3, gauss() * 0.08, gauss() * 0.3, 0.07 + rnd() * 0.12]);
|
|
71
|
+
while (i < n && guard--) {
|
|
72
|
+
const [cx, cy, cz, s] = centres[Math.floor(rnd() * clumps)];
|
|
73
|
+
const x = cx + gauss() * s, y = cy + gauss() * s * 0.5, z = cz + gauss() * s;
|
|
74
|
+
if (!inside(x, y, z))
|
|
75
|
+
continue;
|
|
76
|
+
add(x, y, z, 0.05, rnd() < 0.2 ? mix(PINK, WHITE, rnd()) : mix(BLUE, WHITE, rnd() * 0.6), 1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (g.kind === 'H') {
|
|
80
|
+
const b = g.b ?? 0.75;
|
|
81
|
+
const turn = rnd() * Math.PI; // the long axis in the plane
|
|
82
|
+
const ct = Math.cos(turn), st = Math.sin(turn);
|
|
83
|
+
const put = (x, y, z, r, c, l) => {
|
|
84
|
+
const X = x * ct - z * st, Z = x * st + z * ct;
|
|
85
|
+
if (inside(X, y, Z))
|
|
86
|
+
add(X, y, Z, r, c, l);
|
|
87
|
+
};
|
|
88
|
+
const young = () => (rnd() < 0.2 ? mix(UV, BLUE, rnd()) : mix(BLUE, WHITE, rnd() * 0.8));
|
|
89
|
+
const gas = () => (rnd() < 0.6 ? mix(PINK, WHITE, rnd() * 0.3) : mix(TEAL, WHITE, rnd() * 0.3));
|
|
90
|
+
// the black hole's light first (a few points, very bright, in the very middle)
|
|
91
|
+
if (g.agn) {
|
|
92
|
+
add(0, 0, 0, 0.06, mix(WHITE, BLUE, 0.2), 6);
|
|
93
|
+
for (let k = 0; k < Math.max(3, Math.round(n * 0.015)); k++)
|
|
94
|
+
add(gauss() * 0.012, gauss() * 0.012, gauss() * 0.012, 0.03, mix(WHITE, UV, rnd() * 0.5), 2.5);
|
|
95
|
+
}
|
|
96
|
+
// the starburst knots
|
|
97
|
+
const clumps = Math.max(0, Math.round(g.clumps ?? 3));
|
|
98
|
+
const knots = Array.from({ length: clumps }, () => {
|
|
99
|
+
const r = 0.1 + rnd() * 0.3, a = rnd() * 2 * Math.PI;
|
|
100
|
+
return [r * Math.cos(a), gauss() * 0.05, r * Math.sin(a) * b, 0.025 + rnd() * 0.04];
|
|
101
|
+
});
|
|
102
|
+
const knotN = clumps ? Math.round(n * 0.22) : 0;
|
|
103
|
+
const haloN = Math.round(n * (g.halo ?? 0.15));
|
|
104
|
+
const start = i;
|
|
105
|
+
while (i < start + knotN && guard--) {
|
|
106
|
+
const [kx, ky, kz, ks] = knots[Math.floor(rnd() * clumps)];
|
|
107
|
+
put(kx + gauss() * ks, ky + gauss() * ks, kz + gauss() * ks, 0.03, rnd() < 0.3 ? gas() : young(), 1.6);
|
|
108
|
+
}
|
|
109
|
+
// the faint envelope
|
|
110
|
+
while (i < start + knotN + haloN && guard--) {
|
|
111
|
+
const r = expo(0.3), v = [gauss(), gauss(), gauss()], l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
112
|
+
put((v[0] / l) * r, (v[1] / l) * r * 0.7, (v[2] / l) * r * b, 0.05, rnd() < 0.25 ? gas() : young(), 0.45);
|
|
113
|
+
}
|
|
114
|
+
// the bright compact body: exponential, puffy
|
|
115
|
+
while (i < n && guard--) {
|
|
116
|
+
const r = expo(0.13), v = [gauss(), gauss(), gauss()], l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
117
|
+
put((v[0] / l) * r, (v[1] / l) * r * 0.55, (v[2] / l) * r * b, 0.035, rnd() < 0.12 ? gas() : young(), 1.2 + Math.max(0, 0.3 - r) * 3);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (g.kind === 'P') {
|
|
121
|
+
const ratio = Math.max(1e-4, g.ratio ?? 0.5);
|
|
122
|
+
const peri = Math.max(0.05, g.peri ?? 1);
|
|
123
|
+
const ecc = g.ecc ?? 1;
|
|
124
|
+
const T = g.time ?? 3;
|
|
125
|
+
const R2 = g.size2 ?? Math.max(0.2, Math.sqrt(ratio));
|
|
126
|
+
const first = g.first !== false;
|
|
127
|
+
const M1 = 1, M2 = ratio, Mt = M1 + M2, eps2 = 0.15 * 0.15;
|
|
128
|
+
// the relative orbit (2 - 1) in the x-y plane
|
|
129
|
+
let rx, ry, vx, vy, total;
|
|
130
|
+
if (ecc < 1) {
|
|
131
|
+
const ra = (peri * (1 + ecc)) / (1 - ecc);
|
|
132
|
+
[rx, ry, vx, vy] = [ra, 0, 0, Math.sqrt((Mt * (1 - ecc)) / ra)];
|
|
133
|
+
total = T;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const pp = 2 * peri, r0 = Math.max(4 * peri, 4);
|
|
137
|
+
const f0 = -Math.acos(Math.max(-1, Math.min(1, pp / r0 - 1)));
|
|
138
|
+
const k = Math.sqrt(Mt / pp), vr = k * Math.sin(f0), vt = k * (1 + Math.cos(f0));
|
|
139
|
+
[rx, ry] = [r0 * Math.cos(f0), r0 * Math.sin(f0)];
|
|
140
|
+
[vx, vy] = [vr * Math.cos(f0) - vt * Math.sin(f0), vr * Math.sin(f0) + vt * Math.cos(f0)];
|
|
141
|
+
const D = Math.tan(f0 / 2);
|
|
142
|
+
total = -(Math.sqrt(pp ** 3 / Mt) / 2) * (D + D ** 3 / 3) + T; // Barker: from the start to the closest approach, then T
|
|
143
|
+
}
|
|
144
|
+
const B = [
|
|
145
|
+
{ x: [(-rx * M2) / Mt, (-ry * M2) / Mt, 0], v: [(-vx * M2) / Mt, (-vy * M2) / Mt, 0], m: M1 },
|
|
146
|
+
{ x: [(rx * M1) / Mt, (ry * M1) / Mt, 0], v: [(vx * M1) / Mt, (vy * M1) / Mt, 0], m: M2 },
|
|
147
|
+
];
|
|
148
|
+
const tilt = (v, inclDeg, nodeDeg) => {
|
|
149
|
+
const a = (inclDeg * Math.PI) / 180, b = (nodeDeg * Math.PI) / 180;
|
|
150
|
+
const y1 = v[1] * Math.cos(a) - v[2] * Math.sin(a), z1 = v[1] * Math.sin(a) + v[2] * Math.cos(a);
|
|
151
|
+
return [v[0] * Math.cos(b) - y1 * Math.sin(b), v[0] * Math.sin(b) + y1 * Math.cos(b), z1];
|
|
152
|
+
};
|
|
153
|
+
const nb = Math.round(n * 0.12); // bulge points, placed round the masses at the end
|
|
154
|
+
const share2 = first ? g.share2 ?? Math.min(0.5, 0.15 + 0.35 * Math.sqrt(ratio)) : 1;
|
|
155
|
+
const nPart = n - nb;
|
|
156
|
+
const P = [];
|
|
157
|
+
for (let k = 0; k < nPart; k++) {
|
|
158
|
+
const who = rnd() < share2 ? 1 : 0;
|
|
159
|
+
const body = B[who], R = who ? R2 : 1, M = body.m;
|
|
160
|
+
let pos, vel;
|
|
161
|
+
if (who === 1 && g.kind2 === 'E') {
|
|
162
|
+
const r = R * (0.1 + 0.9 * Math.sqrt(rnd()));
|
|
163
|
+
const u = [gauss(), gauss(), gauss()], ul = Math.hypot(u[0], u[1], u[2]) || 1;
|
|
164
|
+
pos = u.map((c) => (c / ul) * r);
|
|
165
|
+
const w = [gauss(), gauss(), gauss()]; // a random direction across the radius
|
|
166
|
+
const d = (w[0] * pos[0] + w[1] * pos[1] + w[2] * pos[2]) / (r * r);
|
|
167
|
+
const t = w.map((c, j) => c - d * pos[j]), tl = Math.hypot(t[0], t[1], t[2]) || 1;
|
|
168
|
+
const sp = Math.sqrt((M * r * r) / (r * r + eps2) ** 1.5);
|
|
169
|
+
vel = t.map((c) => (c / tl) * sp);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const r = R * (0.12 + 0.88 * Math.sqrt(rnd()));
|
|
173
|
+
const th = rnd() * 2 * Math.PI;
|
|
174
|
+
const sp = Math.sqrt((M * r * r) / (r * r + eps2) ** 1.5);
|
|
175
|
+
const inc = who ? g.incl2 ?? 45 : g.incl1 ?? 20, node = who ? g.node2 ?? 0 : g.node1 ?? 0;
|
|
176
|
+
pos = tilt([r * Math.cos(th), r * Math.sin(th), 0], inc, node);
|
|
177
|
+
vel = tilt([-sp * Math.sin(th), sp * Math.cos(th), 0], inc, node);
|
|
178
|
+
}
|
|
179
|
+
P.push({ x: pos.map((c, j) => c + body.x[j]), v: vel.map((c, j) => c + body.v[j]), who, r0: Math.hypot(pos[0], pos[1], pos[2]) / R });
|
|
180
|
+
}
|
|
181
|
+
// leapfrog: the particles feel the two masses, the masses each other
|
|
182
|
+
const dt = 0.02;
|
|
183
|
+
const steps = Math.max(1, Math.ceil(total / dt));
|
|
184
|
+
const acc = (x, out, skip = -1) => {
|
|
185
|
+
out[0] = out[1] = out[2] = 0;
|
|
186
|
+
for (let b = 0; b < 2; b++) {
|
|
187
|
+
if (b === skip)
|
|
188
|
+
continue;
|
|
189
|
+
const o = B[b], dx = o.x[0] - x[0], dy = o.x[1] - x[1], dz = o.x[2] - x[2];
|
|
190
|
+
const q = o.m / (dx * dx + dy * dy + dz * dz + eps2) ** 1.5;
|
|
191
|
+
out[0] += dx * q;
|
|
192
|
+
out[1] += dy * q;
|
|
193
|
+
out[2] += dz * q;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const a = [0, 0, 0];
|
|
197
|
+
for (let s = 0; s < steps; s++) {
|
|
198
|
+
const h = Math.min(dt, total - s * dt);
|
|
199
|
+
for (const p of P) {
|
|
200
|
+
acc(p.x, a);
|
|
201
|
+
for (let j = 0; j < 3; j++)
|
|
202
|
+
((p.v[j] += a[j] * h), (p.x[j] += p.v[j] * h));
|
|
203
|
+
}
|
|
204
|
+
const ab = B.map((o, b) => (acc(o.x, a, b), [...a]));
|
|
205
|
+
if (g.merge) {
|
|
206
|
+
// dynamical friction: the relative motion is damped while the two overlap, so they spiral in and become one
|
|
207
|
+
const d = [0, 1, 2].map((j) => B[1].x[j] - B[0].x[j]), dv = [0, 1, 2].map((j) => B[1].v[j] - B[0].v[j]);
|
|
208
|
+
const k = g.merge / (1 + (d[0] ** 2 + d[1] ** 2 + d[2] ** 2) / 0.5);
|
|
209
|
+
for (let j = 0; j < 3; j++)
|
|
210
|
+
((ab[1][j] -= (k * dv[j] * M1) / Mt), (ab[0][j] += (k * dv[j] * M2) / Mt));
|
|
211
|
+
}
|
|
212
|
+
B.forEach((o, b) => { for (let j = 0; j < 3; j++)
|
|
213
|
+
((o.v[j] += ab[b][j] * h), (o.x[j] += o.v[j] * h)); });
|
|
214
|
+
}
|
|
215
|
+
// the frame: the centre of mass (or the first mass); the orbit plane becomes the x-z plane
|
|
216
|
+
const c = first ? [0, 1, 2].map((j) => (B[0].x[j] * M1 + B[1].x[j] * M2) / Mt) : B[0].x;
|
|
217
|
+
const pts = P.map((p) => ({
|
|
218
|
+
x: p.x.map((v, j) => v - c[j]),
|
|
219
|
+
col: p.who ? (g.kind2 === 'E' ? mix(GOLD, RED, rnd() * 0.6) : mix(WHITE, BLUE, Math.min(1, p.r0))) : mix(GOLD, BLUE, Math.min(1, p.r0 * 1.2)),
|
|
220
|
+
l: p.r0 > 0.7 ? 0.8 : 1.1,
|
|
221
|
+
r: 0.035,
|
|
222
|
+
}));
|
|
223
|
+
for (let k = 0; k < nb; k++) {
|
|
224
|
+
const who = first ? (rnd() < share2 ? 1 : 0) : 1;
|
|
225
|
+
const o = B[who], R = who ? R2 : 1;
|
|
226
|
+
pts.push({ x: [0, 1, 2].map((j) => o.x[j] - c[j] + gauss() * 0.08 * R), col: mix(GOLD, RED, rnd() * 0.5), l: 1.4, r: 0.04 });
|
|
227
|
+
}
|
|
228
|
+
const radii = pts.map((q) => Math.hypot(q.x[0], q.x[1], q.x[2])).sort((u, v) => u - v);
|
|
229
|
+
const scale = 1 / Math.max(1e-6, radii[Math.floor(radii.length * 0.99)]);
|
|
230
|
+
for (const q of pts) {
|
|
231
|
+
const x = q.x[0] * scale, y = q.x[2] * scale, z = q.x[1] * scale; // (orbit plane x-y -> x-z)
|
|
232
|
+
if (x * x + y * y + z * z > 1)
|
|
233
|
+
continue;
|
|
234
|
+
add(x, y, z, q.r, q.col, q.l);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
while (i < n && guard--) {
|
|
239
|
+
const x = gauss() * 0.28, y = gauss() * 0.22, z = gauss() * 0.28;
|
|
240
|
+
if (!inside(x, y, z))
|
|
241
|
+
continue;
|
|
242
|
+
add(x, y, z, 0.07, mix(WHITE, GOLD, rnd()), 0.7);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const q = i < n ? { n: i, p: out.p.slice(0, 3 * i), r: out.r.slice(0, i), c: out.c.slice(0, i), l: out.l.slice(0, i) } : out;
|
|
246
|
+
// shuffled (with the same seed): any first part of the list is an even sample of the whole galaxy, so a viewer may draw only
|
|
247
|
+
// the first m points of a galaxy that is small on screen
|
|
248
|
+
for (let a = q.n - 1; a > 0; a--) {
|
|
249
|
+
const b = Math.floor(rnd() * (a + 1));
|
|
250
|
+
const t = [q.p[3 * a], q.p[3 * a + 1], q.p[3 * a + 2], q.r[a], q.c[a], q.l[a]];
|
|
251
|
+
q.p[3 * a] = q.p[3 * b];
|
|
252
|
+
q.p[3 * a + 1] = q.p[3 * b + 1];
|
|
253
|
+
q.p[3 * a + 2] = q.p[3 * b + 2];
|
|
254
|
+
q.r[a] = q.r[b];
|
|
255
|
+
q.c[a] = q.c[b];
|
|
256
|
+
q.l[a] = q.l[b];
|
|
257
|
+
q.p[3 * b] = t[0];
|
|
258
|
+
q.p[3 * b + 1] = t[1];
|
|
259
|
+
q.p[3 * b + 2] = t[2];
|
|
260
|
+
q.r[b] = t[3];
|
|
261
|
+
q.c[b] = t[4];
|
|
262
|
+
q.l[b] = t[5];
|
|
263
|
+
}
|
|
264
|
+
return q;
|
|
265
|
+
};
|