-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnebula_particles.js
More file actions
1914 lines (1795 loc) · 80 KB
/
Copy pathnebula_particles.js
File metadata and controls
1914 lines (1795 loc) · 80 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ===== Particle-based nebula builders =====
// builds per-object Three.Group of THREE.Points layers with custom sprite shaders.
// Black hole / wormhole / dyson sphere keep their raymarched shaders.
(function(global){
// shared sprite shader: soft round particle with alpha falloff
const SPRITE_VTX = `
attribute float aSize;
attribute float aAlpha;
attribute float aSeed;
attribute vec3 aColor;
uniform float uTime;
uniform float uPixelRatio;
uniform float uTwinkle;
uniform float uDriftAmp;
varying vec3 vColor;
varying float vAlpha;
void main() {
vColor = aColor;
// gentle per-particle drift so the cloud feels alive
float ph = aSeed * 6.28318;
vec3 pos = position;
pos.x += sin(uTime * 0.05 + ph) * uDriftAmp;
pos.y += cos(uTime * 0.04 + ph * 1.3) * uDriftAmp * 0.7;
pos.z += sin(uTime * 0.06 + ph * 0.7) * uDriftAmp;
// twinkle (mostly for stars)
float tw = mix(1.0, 0.55 + 0.45 * sin(uTime * 1.6 + ph * 5.0), uTwinkle);
vAlpha = aAlpha * tw;
vec4 mv = modelViewMatrix * vec4(pos, 1.0);
gl_Position = projectionMatrix * mv;
gl_PointSize = aSize * uPixelRatio * (180.0 / max(-mv.z, 0.1));
}
`;
// additive emission sprite: bright core + soft halo
const SPRITE_FRAG_EMIT = `
precision highp float;
varying vec3 vColor;
varying float vAlpha;
void main() {
vec2 uv = gl_PointCoord - 0.5;
float d = length(uv) * 2.0;
if (d > 1.0) discard;
float core = exp(-d * d * 3.0);
float halo = exp(-d * 1.5) * 0.16;
float a = (core + halo) * vAlpha;
gl_FragColor = vec4(vColor * (0.18 + core * 0.38), a);
}
`;
// dust sprite: dark, opaque, soft edge - blocks background
const SPRITE_FRAG_DUST = `
precision highp float;
varying vec3 vColor;
varying float vAlpha;
void main() {
vec2 uv = gl_PointCoord - 0.5;
float d = length(uv) * 2.0;
if (d > 1.0) discard;
float core = smoothstep(1.0, 0.0, d);
gl_FragColor = vec4(vColor, core * vAlpha);
}
`;
// bright star sprite with 4-spike diffraction
const SPRITE_FRAG_STAR = `
precision highp float;
varying vec3 vColor;
varying float vAlpha;
void main() {
vec2 uv = gl_PointCoord - 0.5;
float d = length(uv) * 2.0;
if (d > 1.0) discard;
float core = exp(-d * d * 10.0);
float halo = exp(-d * 2.6) * 0.34;
// 4-pointed diffraction spikes
vec2 a = abs(uv) * 2.0;
float spikeH = exp(-a.x * 24.0) * (1.0 - smoothstep(0.0, 1.0, a.y * 2.0));
float spikeV = exp(-a.y * 24.0) * (1.0 - smoothstep(0.0, 1.0, a.x * 2.0));
float spikes = (spikeH + spikeV) * 0.32;
float a2 = (core + halo + spikes) * vAlpha;
vec3 col = mix(vColor, vec3(1.0, 1.0, 1.1), core * 0.3);
gl_FragColor = vec4(col * (0.5 + core * 0.5), a2);
}
`;
let _spriteCache = null;
function getSpriteMaterials(renderer) {
if (_spriteCache) return _spriteCache;
const pr = renderer.getPixelRatio();
const mk = (frag, blending, depthWrite, twinkle, driftAmp) => new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 },
uPixelRatio: { value: pr },
uTwinkle: { value: twinkle },
uDriftAmp: { value: driftAmp }
},
vertexShader: SPRITE_VTX,
fragmentShader: frag,
blending: blending,
depthTest: true,
depthWrite: depthWrite,
transparent: true
});
_spriteCache = {
emit: mk(SPRITE_FRAG_EMIT, THREE.AdditiveBlending, false, 0.0, 0.08),
emitStatic: mk(SPRITE_FRAG_EMIT, THREE.AdditiveBlending, false, 0.0, 0.0),
star: mk(SPRITE_FRAG_STAR, THREE.AdditiveBlending, false, 0.35, 0.0),
dust: mk(SPRITE_FRAG_DUST, THREE.NormalBlending, false, 0.0, 0.04)
};
return _spriteCache;
}
function tickSpriteMaterials(t) {
if (!_spriteCache) return;
for (const k in _spriteCache) {
_spriteCache[k].uniforms.uTime.value = t;
}
}
// helper - build Points from arrays
function makePoints(pos, col, size, alpha, seed, material, renderOrder) {
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
g.setAttribute('aColor', new THREE.Float32BufferAttribute(col, 3));
g.setAttribute('aSize', new THREE.Float32BufferAttribute(size, 1));
g.setAttribute('aAlpha', new THREE.Float32BufferAttribute(alpha, 1));
g.setAttribute('aSeed', new THREE.Float32BufferAttribute(seed, 1));
const p = new THREE.Points(g, material);
p.frustumCulled = false;
if (renderOrder !== undefined) p.renderOrder = renderOrder;
return p;
}
function addChaos(object, cfg) {
object.userData.chaos = Object.assign({ phase: Math.random() * Math.PI * 2 }, cfg);
return object;
}
// ===== noise helpers =====
function hash(x) { x = Math.sin(x) * 43758.5453; return x - Math.floor(x); }
function smoothNoise3(x, y, z) {
const ix = Math.floor(x), iy = Math.floor(y), iz = Math.floor(z);
const fx = x - ix, fy = y - iy, fz = z - iz;
const ux = fx * fx * (3 - 2 * fx);
const uy = fy * fy * (3 - 2 * fy);
const uz = fz * fz * (3 - 2 * fz);
function h(a, b, c) { return hash(a * 127.1 + b * 311.7 + c * 74.7); }
const v000 = h(ix, iy, iz), v100 = h(ix+1, iy, iz);
const v010 = h(ix, iy+1, iz), v110 = h(ix+1, iy+1, iz);
const v001 = h(ix, iy, iz+1), v101 = h(ix+1, iy, iz+1);
const v011 = h(ix, iy+1, iz+1), v111 = h(ix+1, iy+1, iz+1);
return ((v000*(1-ux) + v100*ux)*(1-uy) + (v010*(1-ux) + v110*ux)*uy)*(1-uz)
+ ((v001*(1-ux) + v101*ux)*(1-uy) + (v011*(1-ux) + v111*ux)*uy)*uz;
}
function fbm3(x, y, z) {
let v = 0, a = 0.5, s = 1;
for (let i = 0; i < 4; i++) {
v += a * smoothNoise3(x * s, y * s, z * s);
s *= 2.05; a *= 0.5;
}
return v;
}
// color helpers
function hexToRgb(h) {
const v = parseInt(h.replace('#', ''), 16);
return [((v>>16)&255)/255, ((v>>8)&255)/255, (v&255)/255];
}
function lerp(a, b, t) { return a + (b - a) * t; }
function lerpRgb(c1, c2, t) { return [lerp(c1[0],c2[0],t), lerp(c1[1],c2[1],t), lerp(c1[2],c2[2],t)]; }
function scaleRgb(c, s) { return [c[0]*s, c[1]*s, c[2]*s]; }
function markLocalMaterial(mat) {
mat.userData.local = true;
return mat;
}
function makeGlowRing(radius, tube, color, opacity, rotation, renderOrder) {
const geo = new THREE.TorusGeometry(radius, tube, 8, 192);
const mat = markLocalMaterial(new THREE.MeshBasicMaterial({
color: new THREE.Color(color[0], color[1], color[2]),
transparent: true,
opacity,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide
}));
const mesh = new THREE.Mesh(geo, mat);
if (rotation) mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
if (renderOrder !== undefined) mesh.renderOrder = renderOrder;
return mesh;
}
function makePanelTexture(theme) {
const c = document.createElement('canvas');
c.width = 160; c.height = 96;
const ctx = c.getContext('2d');
const metal = ctx.createLinearGradient(0, 0, c.width, c.height);
metal.addColorStop(0, '#05070d');
metal.addColorStop(0.55, '#111725');
metal.addColorStop(1, '#05070d');
ctx.fillStyle = metal;
ctx.fillRect(0, 0, c.width, c.height);
const accent = theme.c1 || '#ffcc66';
ctx.strokeStyle = accent + '80';
ctx.lineWidth = 2;
ctx.strokeRect(5, 5, c.width - 10, c.height - 10);
ctx.strokeStyle = accent + '30';
for (let x = 28; x < c.width; x += 26) {
ctx.beginPath(); ctx.moveTo(x, 8); ctx.lineTo(x, c.height - 8); ctx.stroke();
}
for (let y = 24; y < c.height; y += 22) {
ctx.beginPath(); ctx.moveTo(8, y); ctx.lineTo(c.width - 8, y); ctx.stroke();
}
ctx.strokeStyle = '#ffffff26';
ctx.beginPath(); ctx.moveTo(10, 12); ctx.lineTo(c.width - 12, 12); ctx.stroke();
const tex = new THREE.CanvasTexture(c);
tex.anisotropy = 4;
return tex;
}
function makeAureliaRingTexture(cA, cB) {
const c = document.createElement('canvas');
c.width = 512; c.height = 512;
const ctx = c.getContext('2d');
const img = ctx.createImageData(c.width, c.height);
const clamp01 = v => Math.max(0, Math.min(1, v));
const smooth = (a, b, x) => {
const t = clamp01((x - a) / (b - a));
return t * t * (3 - 2 * t);
};
for (let y = 0; y < c.height; y++) {
for (let x = 0; x < c.width; x++) {
const nx = (x / (c.width - 1) - 0.5) * 2.0;
const ny = (y / (c.height - 1) - 0.5) * 2.0;
const r = Math.sqrt(nx * nx + ny * ny);
const a = Math.atan2(ny, nx);
const inner = smooth(0.43, 0.49, r);
const outer = 1.0 - smooth(0.94, 1.0, r);
const edge = inner * outer;
if (edge <= 0.0) continue;
const bands = 0.55 + 0.45 * Math.sin(r * 78.0 + Math.sin(a * 6.0) * 0.7);
const fine = 0.70 + 0.30 * Math.sin(r * 210.0 + a * 3.0);
const cassini = 1.0 - smooth(0.635, 0.650, r) * (1.0 - smooth(0.672, 0.688, r));
const spokes = 0.82 + 0.18 * Math.pow(Math.max(0, Math.cos(a * 18.0 + r * 8.0)), 3.0);
const alpha = edge * cassini * spokes * (0.18 + bands * fine * 0.42);
const mixT = clamp01(0.24 + bands * 0.52 + Math.sin(r * 16.0) * 0.10);
const rr = lerp(cB[0], cA[0], mixT);
const gg = lerp(cB[1], cA[1], mixT);
const bb = lerp(cB[2], cA[2], mixT);
const idx = (y * c.width + x) * 4;
img.data[idx] = Math.round(clamp01(rr) * 255);
img.data[idx + 1] = Math.round(clamp01(gg) * 255);
img.data[idx + 2] = Math.round(clamp01(bb) * 255);
img.data[idx + 3] = Math.round(clamp01(alpha) * 255);
}
}
ctx.putImageData(img, 0, 0);
const tex = new THREE.CanvasTexture(c);
tex.anisotropy = 8;
tex.needsUpdate = true;
return tex;
}
// ===== Orion M42 =====
function buildOrion(theme, material) {
const group = new THREE.Group();
const cBright = hexToRgb(theme.c2); // hot stars
const cWarm = hexToRgb(theme.c1); // halpha
const cDark = [0.018, 0.010, 0.030];
// --- Trapezium core stars (4 bright + many small) ---
{
const N = 1300;
const pos=[], col=[], size=[], al=[], se=[];
// 4 dominant trapezium stars
const trap = [[-1.2, 0.5, 0.4], [-1.0, 0.7, 0.1], [-1.3, 0.3, 0.7], [-1.05, 0.55, 0.55]];
for (let i = 0; i < 4; i++) {
pos.push(...trap[i]);
col.push(0.85, 0.85, 0.95);
size.push(6.2);
al.push(0.72);
se.push(Math.random());
}
for (let i = 0; i < N; i++) {
const r = Math.pow(Math.random(), 2.2) * 1.6;
const th = Math.random() * Math.PI * 2;
const ph = Math.acos(Math.random() * 2 - 1);
const x = -1.15 + r * Math.sin(ph) * Math.cos(th);
const y = 0.55 + r * Math.sin(ph) * Math.sin(th);
const z = 0.40 + r * Math.cos(ph);
pos.push(x, y, z);
const t = Math.random();
const c = lerpRgb([0.9, 0.95, 1.05], cBright, t * 0.5);
col.push(...c);
size.push(0.35 + Math.random() * 0.95);
al.push(0.24 + Math.random() * 0.34);
se.push(Math.random());
}
const trapGroup = new THREE.Group();
trapGroup.add(makePoints(pos, col, size, al, se, material.star, 2));
addChaos(trapGroup, { rotY: 0.022, rotZ: 0.016, bob: 0.035, freq: 0.18 });
group.add(trapGroup);
}
// --- Cavity wall emission (the Halpha glow) ---
{
const N = 24000;
const pos=[], col=[], size=[], al=[], se=[];
// shell around offset center with curl-like perturbation
const cx = -1.1, cy = 0.5, cz = 0.3;
for (let i = 0; i < N; i++) {
const th = Math.random() * Math.PI * 2;
const ph = Math.acos(Math.random() * 2 - 1);
// anisotropic radii - stretched bubble
const r = 1.35 + Math.random() * 2.55 + fbm3(th * 2, ph * 2, 0) * 1.15;
let x = cx + r * Math.sin(ph) * Math.cos(th) * 1.15;
let y = cy + r * Math.sin(ph) * Math.sin(th) * 0.95;
let z = cz + r * Math.cos(ph) * 1.1;
// pull outward into wings
x += Math.max(0, x + 1) * 0.34;
y += Math.sin(x * 0.9) * 0.22;
// density-based density: skip if outside fbm threshold
const dens = fbm3(x * 0.6 + 13, y * 0.6 + 7, z * 0.6);
if (dens < 0.42) { i--; continue; }
pos.push(x, y, z);
const t = fbm3(x * 0.3, y * 0.3, z * 0.3);
const c = lerpRgb(cWarm, cBright, t * 0.6);
col.push(c[0] * 0.70, c[1] * 0.52, c[2] * 0.68);
size.push(0.58 + Math.random() * 1.18 + (1 - dens) * 0.82);
al.push(0.052 + dens * 0.096);
se.push(Math.random());
}
const cavity = makePoints(pos, col, size, al, se, material.emit, 1);
addChaos(cavity, { rotY: 0.008, rotX: 0.004, rotZ: -0.006, bob: 0.040, freq: 0.09 });
group.add(cavity);
}
// --- Outer wisps / "wings" of Orion ---
{
const N = 18000;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
// elongated cloud along +x with vertical spread
const t = Math.random();
const x = -2.0 + t * 7.0 + (Math.random() - 0.5) * 1.5;
const y = (Math.random() - 0.5) * 2.6 * (1.0 - t * 0.3);
const z = (Math.random() - 0.5) * 2.2;
const dens = fbm3(x * 0.4 + 3.1, y * 0.4 + 9.2, z * 0.4);
if (dens < 0.36) { i--; continue; }
pos.push(x, y, z);
const tt = fbm3(x * 0.2, y * 0.2, z * 0.2);
const c = lerpRgb(cWarm, [0.55, 0.2, 0.45], tt * 0.7);
col.push(c[0] * 0.66, c[1] * 0.46, c[2] * 0.68);
size.push(0.80 + Math.random() * 1.55);
al.push(0.030 + dens * 0.062);
se.push(Math.random());
}
const wings = makePoints(pos, col, size, al, se, material.emit, 0);
addChaos(wings, { rotY: -0.006, rotZ: 0.010, bob: 0.060, freq: 0.07 });
group.add(wings);
}
// --- Dust lanes (dark cool particles) ---
{
const N = 1800;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
const t = Math.random();
const x = -2.0 + t * 6.5 + (Math.random() - 0.5) * 0.8;
const y = -0.8 + Math.sin(t * 4.0) * 0.5 + (Math.random() - 0.5) * 0.4;
const z = (Math.random() - 0.5) * 1.4;
const dens = fbm3(x * 0.8 + 21, y * 0.8 + 5, z * 0.8);
if (dens < 0.5) { i--; continue; }
pos.push(x, y, z);
col.push(cDark[0], cDark[1], cDark[2]);
size.push(0.85 + Math.random() * 1.25);
al.push(0.10 + dens * 0.12);
se.push(Math.random());
}
const dustLanes = makePoints(pos, col, size, al, se, material.dust, 3);
addChaos(dustLanes, { rotY: 0.004, rotZ: -0.012, bob: 0.025, freq: 0.11 });
group.add(dustLanes);
}
// --- Blue reflection veil around the Trapezium, gives M42 more depth ---
{
const N = 9000;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
const t = Math.random();
const x = -2.55 + t * 4.9 + (Math.random() - 0.5) * 0.95;
const y = 0.05 + Math.sin(t * Math.PI * 1.6) * 1.05 + (Math.random() - 0.5) * 1.1;
const z = 0.2 + (Math.random() - 0.5) * 1.9;
const dens = fbm3(x * 0.72 + 17, y * 0.72 + 4, z * 0.72);
if (dens < 0.43) { i--; continue; }
const c = lerpRgb([0.22, 0.42, 0.96], [0.76, 0.86, 1.1], dens * 0.62);
pos.push(x, y, z);
col.push(c[0] * 0.42, c[1] * 0.52, c[2] * 0.78);
size.push(0.72 + Math.random() * 1.20);
al.push(0.018 + dens * 0.046);
se.push(Math.random());
}
const veil = makePoints(pos, col, size, al, se, material.emit, 2);
addChaos(veil, { rotY: 0.014, rotZ: 0.008, bob: 0.050, freq: 0.13 });
group.add(veil);
}
// --- OIII/Cyan shock ribbons: thin folded arcs instead of a flat pink cloud ---
{
const ribbonGroup = new THREE.Group();
const pos=[], col=[], size=[], al=[], se=[];
const ribbons = [
{ x0: -2.75, y0: 1.25, len: 5.6, sag: -1.35, z: 0.65, hue: 0.10 },
{ x0: -2.15, y0: -0.05, len: 5.2, sag: 0.85, z: -0.55, hue: 0.45 },
{ x0: -0.85, y0: 1.85, len: 3.8, sag: -0.65, z: 0.15, hue: 0.72 },
{ x0: -3.25, y0: -1.25, len: 4.4, sag: 0.55, z: -0.25, hue: 0.30 }
];
for (const rbn of ribbons) {
for (let i = 0; i < 3300; i++) {
const t = Math.random();
const curl = Math.sin(t * Math.PI * 2.0 + rbn.hue * 5.0);
const x = rbn.x0 + t * rbn.len + (Math.random() - 0.5) * 0.16;
const y = rbn.y0 + Math.sin(t * Math.PI) * rbn.sag + curl * 0.12 + (Math.random() - 0.5) * 0.18;
const z = rbn.z + (Math.random() - 0.5) * 0.28;
const dens = fbm3(x * 1.9 + rbn.hue * 8.0, y * 1.9, z * 1.9);
if (dens < 0.40 || Math.random() < t * 0.08) { i--; continue; }
const c = lerpRgb([0.18, 0.82, 1.05], [0.95, 0.45, 0.82], rbn.hue * 0.55);
pos.push(x, y, z);
col.push(c[0] * 0.55, c[1] * 0.66, c[2] * 0.88);
size.push(0.34 + Math.random() * 0.70);
al.push(0.030 + dens * 0.064);
se.push(Math.random());
}
}
ribbonGroup.add(makePoints(pos, col, size, al, se, material.emit, 5));
addChaos(ribbonGroup, { rotY: -0.014, rotZ: 0.018, bob: 0.055, freq: 0.16 });
group.add(ribbonGroup);
}
// --- Bright Bar + M43 companion, following the Hubble mosaic structure ---
{
const pos=[], col=[], size=[], al=[], se=[];
const N = 4600;
for (let i = 0; i < N; i++) {
const t = Math.random();
const along = -1.55 + t * 4.2;
const ridge = -1.05 + along * 0.24 + Math.sin(t * Math.PI) * 0.18;
const x = along + (Math.random() - 0.5) * 0.26;
const y = ridge + (Math.random() - 0.5) * 0.28;
const z = -0.25 + (Math.random() - 0.5) * 0.55;
const dens = fbm3(x * 1.1 + 4, y * 1.1 + 9, z * 1.1);
if (dens < 0.34) { i--; continue; }
const c = lerpRgb([1.0, 0.36, 0.24], [0.92, 0.78, 0.48], t * 0.7);
pos.push(x, y, z);
col.push(c[0] * 0.72, c[1] * 0.54, c[2] * 0.44);
size.push(0.50 + Math.random() * 0.82);
al.push(0.038 + dens * 0.066);
se.push(Math.random());
}
const brightBar = makePoints(pos, col, size, al, se, material.emit, 4);
addChaos(brightBar, { rotY: -0.010, rotZ: 0.014, bob: 0.030, freq: 0.17 });
group.add(brightBar);
}
{
const pos=[], col=[], size=[], al=[], se=[];
const cx2 = -3.1, cy2 = 2.05, cz2 = -0.25;
const N = 3600;
for (let i = 0; i < N; i++) {
const r = Math.pow(Math.random(), 1.4) * 1.55;
const th = Math.random() * Math.PI * 2;
const ph = Math.acos(Math.random() * 2 - 1);
const x = cx2 + r * Math.sin(ph) * Math.cos(th) * 1.1;
const y = cy2 + r * Math.sin(ph) * Math.sin(th) * 0.78;
const z = cz2 + r * Math.cos(ph) * 0.7;
const dens = fbm3(x * 1.2, y * 1.2 + 8, z * 1.2);
if (dens < 0.38) { i--; continue; }
const c = lerpRgb([0.65, 0.30, 0.78], [1.0, 0.58, 0.42], 1.0 - r / 1.55);
pos.push(x, y, z);
col.push(c[0] * 0.52, c[1] * 0.48, c[2] * 0.62);
size.push(0.52 + Math.random() * 0.92);
al.push(0.026 + dens * 0.052);
se.push(Math.random());
}
const m43 = makePoints(pos, col, size, al, se, material.emit, 2);
addChaos(m43, { rotY: 0.010, rotZ: -0.010, bob: 0.035, freq: 0.15 });
group.add(m43);
}
// proplyd-like dark beads near the Trapezium core
{
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < 18; i++) {
const x = -1.15 + (Math.random() - 0.5) * 2.2;
const y = 0.55 + (Math.random() - 0.5) * 1.4;
const z = 0.35 + (Math.random() - 0.5) * 1.2;
pos.push(x, y, z);
col.push(0.025, 0.010, 0.020);
size.push(0.45 + Math.random() * 0.55);
al.push(0.16 + Math.random() * 0.12);
se.push(Math.random());
}
const beads = makePoints(pos, col, size, al, se, material.dust, 5);
addChaos(beads, { rotY: 0.018, rotZ: 0.012, bob: 0.018, freq: 0.22 });
group.add(beads);
}
return group;
}
// ===== Horsehead B33 - cinematic rebuild =====
// Deep crimson IC 434 background + bright Halpha "wall" + dust silhouette with rim glow
// + variety stars + small NGC 2023 reflection companion bottom-left
function buildHorsehead(theme, material) {
const group = new THREE.Group();
// Hubble-palette H-alpha tones (used regardless of theme - this is real-physics color)
const cBackDeep = [0.55, 0.06, 0.18]; // deep crimson far field
const cBackBright = [0.85, 0.18, 0.32]; // brighter Halpha
const cRim = [0.95, 0.25, 0.30]; // edge rim glow
const cDustCore = [0.012, 0.006, 0.018];
const cDustEdge = [0.22, 0.06, 0.10]; // backlight tint on dust edge
// 2D SDF primitives for horse silhouette
function sdCircle(x, y, cx, cy, r) {
const dx = x - cx, dy = y - cy;
return Math.sqrt(dx*dx + dy*dy) - r;
}
function sdEllipse(x, y, cx, cy, rx, ry) {
const dx = (x - cx) / rx, dy = (y - cy) / ry;
return (Math.sqrt(dx * dx + dy * dy) - 1.0) * Math.min(rx, ry);
}
function sdRoundedBox(x, y, cx, cy, hw, hh, r) {
const qx = Math.abs(x - cx) - hw + r;
const qy = Math.abs(y - cy) - hh + r;
const ox = Math.max(qx, 0), oy = Math.max(qy, 0);
return Math.sqrt(ox*ox + oy*oy) + Math.min(Math.max(qx, qy), 0) - r;
}
function smin(a, b, k) {
const h = Math.max(k - Math.abs(a - b), 0) / k;
return Math.min(a, b) - h * h * k * 0.25;
}
// horse profile (xy plane) with multi-frequency edge perturbation for irregular dust look
function sdHorse2D(x, y) {
const warp = (fbm3(x * 1.8, y * 1.8, 0) - 0.5) * 0.35
+ (fbm3(x * 5.0, y * 5.0, 7) - 0.5) * 0.12;
const dNeck = sdEllipse(x, y, -0.42, -1.25, 0.72, 2.10);
const dChest = sdEllipse(x, y, -0.35, -2.55, 1.05, 0.72);
const dHead = sdEllipse(x, y, 0.18, 0.88, 0.86, 0.66);
const dSnout = sdRoundedBox(x, y, 0.95, 0.67, 0.58, 0.30, 0.22);
const ex = x + 0.15, ey = y - 1.72;
const ang = 0.45;
const eX = Math.cos(ang) * ex - Math.sin(ang) * ey;
const eY = Math.sin(ang) * ex + Math.cos(ang) * ey;
const dEar = sdRoundedBox(eX, eY, 0, 0, 0.22, 0.78, 0.16);
let d = smin(dNeck, dChest, 0.42);
d = smin(d, dHead, 0.38);
d = smin(d, dSnout, 0.24);
d = smin(d, dEar, 0.20);
const jawCut = sdEllipse(x, y, 0.66, 0.05, 0.48, 0.46);
const backCut = sdEllipse(x, y, -1.10, 0.74, 0.36, 0.78);
const throatCut = sdEllipse(x, y, 0.18, -0.42, 0.34, 0.56);
d = Math.max(d, -jawCut);
d = Math.max(d, -backCut);
d = Math.max(d, -throatCut);
return d + warp * 0.28;
}
// ===== Background IC 434 diffuse glow (deep crimson far field) =====
{
const N = 42000;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
const r = Math.sqrt(Math.random()) * 26.0;
const ang = Math.random() * Math.PI * 2;
const x = Math.cos(ang) * r;
const y = Math.sin(ang) * r;
const z = -5.0 + (Math.random() - 0.5) * 1.4;
const fall = Math.exp(-(r * r) / 90.0);
const dens = fbm3(x * 0.22 + 5, y * 0.22 + 11, z * 0.3);
if (dens < 0.30) { i--; continue; }
// brightness gradient: more concentrated near horse base
const lo = fbm3(x * 0.5, y * 0.5 + 2.0, 0);
const c = lerpRgb(cBackDeep, cBackBright, Math.min(1, lo * 1.3));
pos.push(x, y, z);
col.push(c[0] * 0.78, c[1] * 0.52, c[2] * 0.56);
size.push(1.9 + Math.random() * 2.25);
al.push(0.018 + dens * 0.045 * fall);
se.push(Math.random());
}
group.add(makePoints(pos, col, size, al, se, material.emit, 0));
}
// ===== Bright H-alpha "wall" along bottom of background (the dramatic glowing horizon) =====
{
const N = 28000;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
const x = (Math.random() - 0.5) * 18.0;
// concentrated in a horizontal band near y=-2..1 (the wall where dust meets light)
const yBand = -1.5 + (Math.random() - 0.5) * 3.0;
// turbulent y offset for ragged cloud top
const yWobble = (fbm3(x * 0.4 + 9, 0, 0) - 0.5) * 1.8;
const y = yBand + yWobble;
const z = -3.8 + (Math.random() - 0.5) * 1.0;
const dens = fbm3(x * 0.5 + 13, y * 0.7, z * 0.4 + 2);
if (dens < 0.42) { i--; continue; }
// distance from y=0 for vertical brightness falloff
const fall = Math.exp(-Math.pow((y + 0.5) / 2.0, 2));
const c = lerpRgb(cBackBright, cRim, fall * 0.4);
pos.push(x, y, z);
col.push(c[0] * 0.78, c[1] * 0.44, c[2] * 0.44);
size.push(1.42 + Math.random() * 1.72);
al.push(0.024 + dens * 0.055 * fall);
se.push(Math.random());
}
const envelope = makePoints(pos, col, size, al, se, material.emit, 1);
addChaos(envelope, { rotY: -0.010, rotX: 0.006, rotZ: 0.012, bob: 0.045, freq: 0.12 });
group.add(envelope);
}
// ===== Horsehead silhouette - DENSE dark dust core =====
{
const N = 95000;
const pos=[], col=[], size=[], al=[], se=[];
let placed = 0, tries = 0;
while (placed < N && tries < N * 18) {
tries++;
const x = -2.2 + Math.random() * 4.3;
const y = -3.4 + Math.random() * 6.4;
const d = sdHorse2D(x, y);
if (d > 0.0) continue;
// organic density variation inside
const dens = fbm3(x * 1.4 + 7, y * 1.4, 0);
if (dens < 0.25) continue;
const z = -0.2 + (Math.random() - 0.5) * 1.0;
const inside = Math.max(0, -d);
// deeper inside = pure dark, near edge = slightly tinted by backlight
const edgeMix = Math.exp(-inside * 2.5);
const c = lerpRgb(cDustCore, cDustEdge, edgeMix * 0.6);
pos.push(x, y, z);
col.push(c[0] * 0.45, c[1] * 0.42, c[2] * 0.48);
size.push(2.2 + Math.random() * 1.75);
al.push(0.88 + (1.0 - edgeMix) * 0.10);
se.push(Math.random());
placed++;
}
group.add(makePoints(pos, col, size, al, se, material.dust, 8));
}
// ===== Rim lighting: bright red-orange halo right at silhouette edge =====
// Sampled in a thin band just OUTSIDE the SDF where light wraps around dust
{
const N = 12000;
const pos=[], col=[], size=[], al=[], se=[];
let placed = 0, tries = 0;
while (placed < N && tries < N * 22) {
tries++;
const x = -2.2 + Math.random() * 4.4;
const y = -3.4 + Math.random() * 6.4;
const d = sdHorse2D(x, y);
// narrow band outside the silhouette (0 < d < 0.18)
if (d <= 0.0 || d > 0.22) continue;
const z = -0.1 + (Math.random() - 0.5) * 0.8;
// brightest right at the edge, fading outward
const edgeBright = Math.exp(-d * 9.0);
// skip random subset to avoid uniform halo
const dens = fbm3(x * 1.8 + 23, y * 1.8, 0);
if (dens < 0.4) continue;
const c = lerpRgb(cRim, [1.0, 0.5, 0.4], edgeBright * 0.5);
pos.push(x, y, z);
col.push(c[0] * 0.78, c[1] * 0.42, c[2] * 0.38);
size.push(0.92 + Math.random() * 1.12);
al.push(0.045 + edgeBright * 0.130);
se.push(Math.random());
placed++;
}
group.add(makePoints(pos, col, size, al, se, material.emit, 4));
}
// ===== Foreground stars (variety: bright spike stars + many small dim) =====
{
const pos=[], col=[], size=[], al=[], se=[];
// a few prominent bright stars (like the iconic one above the horsehead)
const bright = [
{ p: [0.4, 3.0, 1.0], mag: 1.1, c: [0.9, 0.92, 1.1] }, // bright blue-white above horsehead
{ p: [-3.5, 0.2, 1.0], mag: 0.85, c: [0.85, 0.88, 1.05] }, // mid-left
{ p: [4.0, 2.4, 0.8], mag: 0.6, c: [1.0, 0.9, 0.75] }, // upper-right warm
{ p: [2.8, -2.5, 0.6], mag: 0.55, c: [0.9, 0.85, 1.0] }
];
for (const s of bright) {
pos.push(...s.p);
col.push(s.c[0], s.c[1], s.c[2]);
size.push(8 * s.mag);
al.push(0.62);
se.push(Math.random());
}
// ~180 small dim background stars distributed across visible area
for (let i = 0; i < 220; i++) {
const x = (Math.random() - 0.5) * 16.0;
const y = (Math.random() - 0.5) * 12.0;
const z = -1.0 + (Math.random() - 0.5) * 4.0;
// bias colors: HR-diagram-ish mix
const r = Math.random();
let c;
if (r < 0.55) c = [0.85, 0.88, 1.05]; // blue-white (most common in field)
else if (r < 0.78) c = [1.0, 0.95, 0.85]; // white-yellow
else if (r < 0.92) c = [1.0, 0.82, 0.6]; // orange
else c = [0.95, 0.55, 0.4]; // red giant
pos.push(x, y, z);
col.push(c[0], c[1], c[2]);
size.push(1.0 + Math.random() * 1.8);
al.push(0.22 + Math.random() * 0.28);
se.push(Math.random());
}
group.add(makePoints(pos, col, size, al, se, material.star, 5));
}
// ===== NGC 2023 reflection nebula companion (bottom-left of frame) =====
{
// bright central star
const starPos=[], starCol=[], starSize=[], starAl=[], starSe=[];
starPos.push(-4.5, -2.6, -0.2);
starCol.push(0.95, 0.95, 1.05);
starSize.push(6);
starAl.push(0.65);
starSe.push(Math.random());
group.add(makePoints(starPos, starCol, starSize, starAl, starSe, material.star, 6));
// cyan-blue reflection cloud around it
const N = 8000;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
const r = Math.pow(Math.random(), 1.8) * 1.6;
const th = Math.random() * Math.PI * 2;
const ph = Math.acos(Math.random() * 2 - 1);
const lx = r * Math.sin(ph) * Math.cos(th);
const ly = r * Math.sin(ph) * Math.sin(th);
const lz = r * Math.cos(ph);
const x = -4.5 + lx;
const y = -2.6 + ly;
const z = -0.2 + lz;
const dens = fbm3(lx * 1.4 + 19, ly * 1.4, lz * 1.4 + 5);
if (dens < 0.4) { i--; continue; }
const t = 1.0 - r / 1.6;
// teal/cyan reflection
const c = lerpRgb([0.25, 0.5, 0.7], [0.7, 0.85, 1.0], t * 0.5);
pos.push(x, y, z);
col.push(c[0] * 0.45, c[1] * 0.48, c[2] * 0.58);
size.push(0.85 + Math.random() * 1.25);
al.push(0.018 + dens * 0.046);
se.push(Math.random());
}
group.add(makePoints(pos, col, size, al, se, material.emit, 2));
}
// ===== JWST-like mane fibers: blue base, red hydrogen wisps above the ridge =====
{
const pos=[], col=[], size=[], al=[], se=[];
const N = 16000;
for (let i = 0; i < N; i++) {
const t = Math.random();
const x = -1.55 + t * 3.4 + (Math.random() - 0.5) * 0.18;
const yBase = 0.85 + Math.sin(t * Math.PI * 1.25) * 1.0;
const y = yBase + Math.pow(Math.random(), 1.8) * 2.4;
const z = -0.35 + (Math.random() - 0.5) * 0.65;
const fiber = Math.abs(Math.sin((x * 2.5 + y * 0.9) * 2.7));
const dens = fbm3(x * 2.0 + 17, y * 1.5, z * 1.8);
if (fiber < 0.48 || dens < 0.36) { i--; continue; }
const heightMix = Math.min(1, Math.max(0, (y - 0.8) / 3.1));
const c = lerpRgb([0.22, 0.50, 0.86], [1.0, 0.22, 0.14], heightMix);
pos.push(x, y, z);
col.push(c[0] * 0.42, c[1] * 0.36, c[2] * 0.40);
size.push(0.45 + Math.random() * 0.72);
al.push(0.018 + dens * 0.048 * (0.65 + heightMix * 0.4));
se.push(Math.random());
}
const cage = makePoints(pos, col, size, al, se, material.emit, 4);
addChaos(cage, { rotY: 0.018, rotX: -0.008, rotZ: 0.014, bob: 0.040, freq: 0.16 });
group.add(cage);
}
return group;
}
// ===== Crab Nebula M1 =====
function buildCrab(theme, material) {
const group = new THREE.Group();
const cA = hexToRgb(theme.c1);
const cB = hexToRgb(theme.c2);
// --- Central pulsar (bright point) ---
{
const pos=[], col=[], size=[], al=[], se=[];
pos.push(0, 0, 0);
col.push(0.85, 0.88, 1.05);
size.push(10);
al.push(0.64);
se.push(0.5);
const starCore = makePoints(pos, col, size, al, se, material.star, 3);
addChaos(starCore, { rotY: 0.014, rotZ: 0.018, bob: 0.035, freq: 0.18 });
group.add(starCore);
}
// --- Synchrotron envelope (oblate) ---
{
const N = 22000;
const pos=[], col=[], size=[], al=[], se=[];
for (let i = 0; i < N; i++) {
// oblate spheroid surface band
const th = Math.random() * Math.PI * 2;
const ph = Math.acos(Math.random() * 2 - 1);
const baseR = 3.2 + Math.random() * 1.8;
const r = baseR + fbm3(th * 2, ph * 3, 0) * 1.0;
const x = r * Math.sin(ph) * Math.cos(th) * 1.2;
const y = r * Math.cos(ph) * 0.7;
const z = r * Math.sin(ph) * Math.sin(th) * 1.2;
const dens = fbm3(x * 0.55, y * 0.55, z * 0.55);
if (dens < 0.42) { i--; continue; }
pos.push(x, y, z);
const t = fbm3(x * 0.25 + 7, y * 0.25, z * 0.25);
const c = lerpRgb(cA, cB, t);
col.push(c[0] * 0.85, c[1] * 0.85, c[2] * 0.9);
size.push(0.75 + Math.random() * 1.25);
al.push(0.045 + dens * 0.090);
se.push(Math.random());
}
const envelope = makePoints(pos, col, size, al, se, material.emit, 1);
addChaos(envelope, { rotY: -0.010, rotX: 0.006, rotZ: 0.012, bob: 0.045, freq: 0.12 });
group.add(envelope);
}
// --- Radial synchrotron filaments (6 bright chains) ---
{
const N_per = 1800;
const numFil = 8;
const pos=[], col=[], size=[], al=[], se=[];
for (let f = 0; f < numFil; f++) {
const baseAng = (f / numFil) * Math.PI * 2 + Math.random() * 0.4;
const tilt = (Math.random() - 0.5) * 0.5;
for (let i = 0; i < N_per; i++) {
const t = Math.random();
const r = 0.5 + t * 5.0;
// small curl along filament
const wobble = Math.sin(t * 8.0 + f) * 0.25;
const ang = baseAng + wobble * 0.2;
const x = r * Math.cos(ang) * 1.2 + (Math.random() - 0.5) * 0.25;
const y = r * tilt + Math.sin(t * 5.0 + f) * 0.4 + (Math.random() - 0.5) * 0.25;
const z = r * Math.sin(ang) * 1.2 + (Math.random() - 0.5) * 0.25;
pos.push(x, y, z);
const tt = (1.0 - t);
const c = lerpRgb(cB, cA, t * 0.7);
col.push(c[0] * (0.5 + tt * 0.4), c[1] * (0.5 + tt * 0.4), c[2] * 0.85);
size.push(0.85 + (1 - t) * 1.45 + Math.random() * 0.55);
al.push(0.060 + tt * 0.150);
se.push(Math.random());
}
}
const filGroup = new THREE.Group();
filGroup.add(makePoints(pos, col, size, al, se, material.emit, 2));
// slow rotation of synchrotron filaments around pulsar
filGroup.userData.spin = 0.06;
group.add(filGroup);
}
// --- Webb/Hubble cage: red-orange outer loops with blue iron knots ---
{
const pos=[], col=[], size=[], al=[], se=[];
const loopCount = 13;
const N_per = 950;
for (let f = 0; f < loopCount; f++) {
const phase = (f / loopCount) * Math.PI * 2;
const tilt = -0.42 + (f % 5) * 0.20;
const zOff = (Math.random() - 0.5) * 1.1;
for (let i = 0; i < N_per; i++) {
const t = Math.random() * Math.PI * 2;
const wob = Math.sin(t * 3.0 + phase) * 0.28 + (fbm3(t, phase, 1.0) - 0.5) * 0.35;
const rx = 4.8 + Math.sin(phase * 2.0) * 0.45;
const ry = 2.75 + Math.cos(phase) * 0.34;
const x = Math.cos(t + phase * 0.08) * (rx + wob);
const y = Math.sin(t) * (ry + wob * 0.4) + Math.sin(t * 2.0 + phase) * 0.18;
const z = Math.sin(t + phase) * 1.15 + zOff + x * tilt * 0.12;
if (Math.random() < 0.34 && Math.abs(Math.sin(t * 5.0 + phase)) < 0.4) continue;
const hot = Math.random();
const c = hot > 0.78
? [0.18, 0.58, 1.0]
: lerpRgb([1.0, 0.23, 0.08], [0.95, 0.72, 0.18], Math.random() * 0.7);
pos.push(x, y, z);
col.push(c[0] * 0.82, c[1] * 0.75, c[2] * 0.7);
size.push(0.75 + Math.random() * 0.95);
al.push(0.045 + Math.random() * 0.120);
se.push(Math.random());
}
}
const cage = makePoints(pos, col, size, al, se, material.emit, 4);
addChaos(cage, { rotY: 0.018, rotX: -0.008, rotZ: 0.014, bob: 0.040, freq: 0.16 });
group.add(cage);
}
// --- Milky synchrotron interior and ripple pattern around the pulsar ---
{
const pos=[], col=[], size=[], al=[], se=[];
const N = 10500;
for (let i = 0; i < N; i++) {
const th = Math.random() * Math.PI * 2;
const ph = Math.acos(Math.random() * 2 - 1);
const r = Math.pow(Math.random(), 0.85) * 3.4;
const waist = 0.72 + 0.28 * Math.abs(Math.sin(th * 2.0));
const x = r * Math.sin(ph) * Math.cos(th) * 1.25;
const y = r * Math.cos(ph) * 0.55 * waist;
const z = r * Math.sin(ph) * Math.sin(th) * 0.9;
const dens = fbm3(x * 0.9 + 4, y * 0.9 + 7, z * 0.9);
if (dens < 0.33) { i--; continue; }
const c = lerpRgb([0.80, 0.88, 1.0], [0.42, 0.82, 1.0], dens);
pos.push(x, y, z);
col.push(c[0] * 0.55, c[1] * 0.65, c[2] * 0.85);
size.push(0.85 + Math.random() * 1.25);
al.push(0.022 + dens * 0.055);
se.push(Math.random());
}
const interior = makePoints(pos, col, size, al, se, material.emit, 0);
addChaos(interior, { rotY: 0.012, rotX: 0.010, rotZ: -0.010, bob: 0.050, freq: 0.10 });
group.add(interior);
}
{
const pos=[], col=[], size=[], al=[], se=[];
for (let ring = 0; ring < 4; ring++) {
const radius = 0.9 + ring * 0.55;
for (let i = 0; i < 360; i++) {
if (Math.random() < 0.24) continue;
const a = (i / 360) * Math.PI * 2;
const x = Math.cos(a) * radius * 1.55;
const y = Math.sin(a) * radius * 0.42;
const z = Math.sin(a * 2.0) * 0.12;
pos.push(x, y, z);
col.push(0.88, 0.92, 1.1);
size.push(0.62 + ring * 0.12);
al.push(0.105 - ring * 0.016);
se.push(Math.random());
}
}
const ripple = makePoints(pos, col, size, al, se, material.emit, 5);
ripple.userData.pulse = { axis: 'x', base: 1.0, amp: 0.045, freq: 0.35 };
group.add(ripple);
}
return group;
}
// ===== Pleiades M45 =====
function buildPleiades(theme, material) {
const group = new THREE.Group();
const cNeb = hexToRgb(theme.c1); // blue reflection
const cStar = hexToRgb(theme.c2); // star color
// Principal stars, arranged to read like the real M45 grouping rather than a random cluster.
const stars = [
{ pos: [ 0.0, 0.0, 0.0], mag: 1.45, name: 'Alcyone' },
{ pos: [-2.2, 1.0, -0.5], mag: 1.05, name: 'Maia' },
{ pos: [ 2.25, 0.55, 0.35], mag: 1.08, name: 'Atlas' },
{ pos: [ 2.65, 0.95, 0.15], mag: 0.80, name: 'Pleione' },
{ pos: [-1.55, -1.35, 0.9], mag: 0.95, name: 'Electra' },
{ pos: [ 1.05, 1.95,-1.0], mag: 0.96, name: 'Taygeta' },
{ pos: [-3.15, -0.55, 1.25], mag: 1.08, name: 'Merope' },
{ pos: [-0.35, 1.55, 0.85], mag: 0.72, name: 'Celaeno' },
{ pos: [ 0.95, -1.85,-0.45], mag: 0.68, name: 'Asterope' }
];
// --- Bright blue stars with diffraction spikes ---
{
const pos=[], col=[], size=[], al=[], se=[];
for (const s of stars) {
pos.push(...s.pos);
col.push(0.85, 0.9, 1.1);
size.push(8.8 * s.mag);
al.push(0.68);
se.push(Math.random());
}