rapid-render 1.0.7 → 1.0.8
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/README.md +2 -2
- package/dist/buffer.d.ts +1 -0
- package/dist/color.d.ts +2 -0
- package/dist/draw.d.ts +12 -11
- package/dist/particle.d.ts +38 -39
- package/dist/rapid-render.js +747 -667
- package/dist/rapid-render.umd.cjs +9 -9
- package/dist/region/particleRegion.d.ts +3 -1
- package/dist/render.d.ts +1 -1
- package/package.json +1 -1
package/dist/rapid-render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
class
|
|
1
|
+
var U = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(U || {});
|
|
2
|
+
class C {
|
|
3
3
|
/** The number of elements currently used in the buffer. */
|
|
4
4
|
usedElemNum;
|
|
5
5
|
/** The main typed array view corresponding to the specified ArrayType. */
|
|
@@ -63,6 +63,27 @@ class B {
|
|
|
63
63
|
clear() {
|
|
64
64
|
this.usedElemNum = 0;
|
|
65
65
|
}
|
|
66
|
+
static removeAtIndices(t, e) {
|
|
67
|
+
const r = Math.max(...e.map((o) => o.usedElemNum)), i = [...new Set(t)].filter(
|
|
68
|
+
(o) => o >= 0 && o < r
|
|
69
|
+
).sort((o, h) => o - h);
|
|
70
|
+
if (i.length === 0)
|
|
71
|
+
return 0;
|
|
72
|
+
let s = 0, a = 0;
|
|
73
|
+
for (let o = 0; o < r; o++) {
|
|
74
|
+
if (a < i.length && o === i[a]) {
|
|
75
|
+
a++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (s !== o)
|
|
79
|
+
for (const h of e)
|
|
80
|
+
h.typedArray[s] = h.typedArray[o];
|
|
81
|
+
s++;
|
|
82
|
+
}
|
|
83
|
+
for (const o of e)
|
|
84
|
+
o.usedElemNum = s;
|
|
85
|
+
return r - s;
|
|
86
|
+
}
|
|
66
87
|
/**
|
|
67
88
|
* Checks if the buffer has enough space for additional elements and resizes the buffer if necessary.
|
|
68
89
|
* @param size - The number of new elements that need to be accommodated.
|
|
@@ -151,7 +172,7 @@ class B {
|
|
|
151
172
|
this.usedElemNum = 0;
|
|
152
173
|
}
|
|
153
174
|
}
|
|
154
|
-
class
|
|
175
|
+
class et extends C {
|
|
155
176
|
/** The actual WebGLBuffer object maintained by this instance. */
|
|
156
177
|
buffer;
|
|
157
178
|
/** The related WebGL rendering context. */
|
|
@@ -202,7 +223,7 @@ class Q extends B {
|
|
|
202
223
|
}
|
|
203
224
|
}
|
|
204
225
|
}
|
|
205
|
-
class
|
|
226
|
+
class m {
|
|
206
227
|
_r;
|
|
207
228
|
_g;
|
|
208
229
|
_b;
|
|
@@ -283,7 +304,7 @@ class p {
|
|
|
283
304
|
*/
|
|
284
305
|
updateUint() {
|
|
285
306
|
this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
|
|
286
|
-
const t =
|
|
307
|
+
const t = m.clampByte(this._a), e = m.clampByte(this._r * t / 255), r = m.clampByte(this._g * t / 255), i = m.clampByte(this._b * t / 255);
|
|
287
308
|
this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
|
|
288
309
|
}
|
|
289
310
|
reset() {
|
|
@@ -301,9 +322,9 @@ class p {
|
|
|
301
322
|
}
|
|
302
323
|
setHSL(t, e, r) {
|
|
303
324
|
t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100, r = Math.max(0, Math.min(100, r)) / 100;
|
|
304
|
-
const i = (1 - Math.abs(2 * r - 1)) * e,
|
|
305
|
-
let
|
|
306
|
-
return t < 60 ? [
|
|
325
|
+
const i = (1 - Math.abs(2 * r - 1)) * e, s = i * (1 - Math.abs(t / 60 % 2 - 1)), a = r - i / 2;
|
|
326
|
+
let o = 0, h = 0, c = 0;
|
|
327
|
+
return t < 60 ? [o, h, c] = [i, s, 0] : t < 120 ? [o, h, c] = [s, i, 0] : t < 180 ? [o, h, c] = [0, i, s] : t < 240 ? [o, h, c] = [0, s, i] : t < 300 ? [o, h, c] = [s, 0, i] : [o, h, c] = [i, 0, s], this.setRGBA((o + a) * 255, (h + a) * 255, (c + a) * 255, 255), this;
|
|
307
328
|
}
|
|
308
329
|
toHex() {
|
|
309
330
|
const t = (e) => Math.max(0, Math.min(255, Math.round(e))).toString(16).padStart(2, "0");
|
|
@@ -321,7 +342,7 @@ class p {
|
|
|
321
342
|
* @returns A new `Color` instance with the same RGBA values.
|
|
322
343
|
*/
|
|
323
344
|
clone() {
|
|
324
|
-
return new
|
|
345
|
+
return new m(this._r, this._g, this._b, this._a);
|
|
325
346
|
}
|
|
326
347
|
/**
|
|
327
348
|
* Converts the color to a hexadecimal string representation (e.g., '#RRGGBBAA').
|
|
@@ -329,8 +350,8 @@ class p {
|
|
|
329
350
|
* @returns The hexadecimal string representation of the color.
|
|
330
351
|
*/
|
|
331
352
|
toHexString(t = !0) {
|
|
332
|
-
const e = this.r.toString(16).padStart(2, "0"), r = this.g.toString(16).padStart(2, "0"), i = this.b.toString(16).padStart(2, "0"),
|
|
333
|
-
return `#${e}${r}${i}${t ?
|
|
353
|
+
const e = this.r.toString(16).padStart(2, "0"), r = this.g.toString(16).padStart(2, "0"), i = this.b.toString(16).padStart(2, "0"), s = this.a.toString(16).padStart(2, "0");
|
|
354
|
+
return `#${e}${r}${i}${t ? s : ""}`;
|
|
334
355
|
}
|
|
335
356
|
/**
|
|
336
357
|
* Checks if the current color is equal to another color.
|
|
@@ -355,19 +376,26 @@ class p {
|
|
|
355
376
|
* Color.fromNorm(0.9, 0.87, 0.55, 0.1) // moon glow
|
|
356
377
|
*/
|
|
357
378
|
static FromHSL(t, e, r) {
|
|
358
|
-
return new
|
|
379
|
+
return new m(0, 0, 0).setHSL(t, e, r);
|
|
359
380
|
}
|
|
360
381
|
static FromRGB(t, e, r) {
|
|
361
|
-
return new
|
|
382
|
+
return new m(t, e, r);
|
|
362
383
|
}
|
|
363
384
|
static fromNorm(t, e, r, i = 1) {
|
|
364
|
-
return new
|
|
385
|
+
return new m(
|
|
365
386
|
Math.round(t * 255),
|
|
366
387
|
Math.round(e * 255),
|
|
367
388
|
Math.round(r * 255),
|
|
368
389
|
Math.round(i * 255)
|
|
369
390
|
);
|
|
370
391
|
}
|
|
392
|
+
static clampColorByte(t) {
|
|
393
|
+
return t <= 0 ? 0 : t >= 255 ? 255 : Math.round(t);
|
|
394
|
+
}
|
|
395
|
+
static packColor(t, e, r, i, s) {
|
|
396
|
+
const a = m.clampColorByte(i), o = s ? a / 255 : 1, h = m.clampColorByte(t * o), c = m.clampColorByte(e * o), u = m.clampColorByte(r * o);
|
|
397
|
+
return (a << 24 | u << 16 | c << 8 | h) >>> 0;
|
|
398
|
+
}
|
|
371
399
|
/**
|
|
372
400
|
* Creates a Color instance from a hexadecimal color string.
|
|
373
401
|
* @param hexString - The hexadecimal color string, e.g., '#RRGGBB' or '#RRGGBBAA'.
|
|
@@ -376,8 +404,8 @@ class p {
|
|
|
376
404
|
static fromHex(t) {
|
|
377
405
|
t.startsWith("#") && (t = t.slice(1));
|
|
378
406
|
const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
|
|
379
|
-
let
|
|
380
|
-
return t.length >= 8 && (
|
|
407
|
+
let s = 255;
|
|
408
|
+
return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new m(e, r, i, s);
|
|
381
409
|
}
|
|
382
410
|
/**
|
|
383
411
|
* Adds the components of another color to this color, clamping the result to 255.
|
|
@@ -385,7 +413,7 @@ class p {
|
|
|
385
413
|
* @returns A new Color instance with the result of the addition.
|
|
386
414
|
*/
|
|
387
415
|
add(t) {
|
|
388
|
-
return new
|
|
416
|
+
return new m(
|
|
389
417
|
Math.min(this.r + t.r, 255),
|
|
390
418
|
Math.min(this.g + t.g, 255),
|
|
391
419
|
Math.min(this.b + t.b, 255),
|
|
@@ -398,7 +426,7 @@ class p {
|
|
|
398
426
|
* @returns A new Color instance with the result of the subtraction.
|
|
399
427
|
*/
|
|
400
428
|
subtract(t) {
|
|
401
|
-
return new
|
|
429
|
+
return new m(
|
|
402
430
|
this.r - t.r,
|
|
403
431
|
this.g - t.g,
|
|
404
432
|
this.b - t.b,
|
|
@@ -406,12 +434,12 @@ class p {
|
|
|
406
434
|
);
|
|
407
435
|
}
|
|
408
436
|
divide(t) {
|
|
409
|
-
return t instanceof
|
|
437
|
+
return t instanceof m ? new m(
|
|
410
438
|
this.r / t.r,
|
|
411
439
|
this.g / t.g,
|
|
412
440
|
this.b / t.b,
|
|
413
441
|
this.a / t.a
|
|
414
|
-
) : new
|
|
442
|
+
) : new m(
|
|
415
443
|
this.r / t,
|
|
416
444
|
this.g / t,
|
|
417
445
|
this.b / t,
|
|
@@ -419,12 +447,12 @@ class p {
|
|
|
419
447
|
);
|
|
420
448
|
}
|
|
421
449
|
multiply(t) {
|
|
422
|
-
return t instanceof
|
|
450
|
+
return t instanceof m ? new m(
|
|
423
451
|
this.r * t.r,
|
|
424
452
|
this.g * t.g,
|
|
425
453
|
this.b * t.b,
|
|
426
454
|
this.a * t.a
|
|
427
|
-
) : new
|
|
455
|
+
) : new m(
|
|
428
456
|
this.r * t,
|
|
429
457
|
this.g * t,
|
|
430
458
|
this.b * t,
|
|
@@ -434,24 +462,24 @@ class p {
|
|
|
434
462
|
clamp() {
|
|
435
463
|
this.r = Math.max(0, Math.min(255, this.r)), this.g = Math.max(0, Math.min(255, this.g)), this.b = Math.max(0, Math.min(255, this.b)), this.a = Math.max(0, Math.min(255, this.a));
|
|
436
464
|
}
|
|
437
|
-
static Red = new
|
|
438
|
-
static Green = new
|
|
439
|
-
static Blue = new
|
|
440
|
-
static Yellow = new
|
|
441
|
-
static Purple = new
|
|
442
|
-
static Orange = new
|
|
443
|
-
static Pink = new
|
|
444
|
-
static Gray = new
|
|
445
|
-
static Brown = new
|
|
446
|
-
static Cyan = new
|
|
447
|
-
static Magenta = new
|
|
448
|
-
static Lime = new
|
|
449
|
-
static White = new
|
|
450
|
-
static Black = new
|
|
451
|
-
static Transparent = new
|
|
452
|
-
static TRANSPARENT = new
|
|
465
|
+
static Red = new m(255, 0, 0, 255);
|
|
466
|
+
static Green = new m(0, 255, 0, 255);
|
|
467
|
+
static Blue = new m(0, 0, 255, 255);
|
|
468
|
+
static Yellow = new m(255, 255, 0, 255);
|
|
469
|
+
static Purple = new m(128, 0, 128, 255);
|
|
470
|
+
static Orange = new m(255, 165, 0, 255);
|
|
471
|
+
static Pink = new m(255, 192, 203, 255);
|
|
472
|
+
static Gray = new m(128, 128, 128, 255);
|
|
473
|
+
static Brown = new m(139, 69, 19, 255);
|
|
474
|
+
static Cyan = new m(0, 255, 255, 255);
|
|
475
|
+
static Magenta = new m(255, 0, 255, 255);
|
|
476
|
+
static Lime = new m(192, 255, 0, 255);
|
|
477
|
+
static White = new m(255, 255, 255, 255);
|
|
478
|
+
static Black = new m(0, 0, 0, 255);
|
|
479
|
+
static Transparent = new m(0, 0, 0, 0);
|
|
480
|
+
static TRANSPARENT = new m(0, 0, 0, 0);
|
|
453
481
|
}
|
|
454
|
-
const
|
|
482
|
+
const E = 6;
|
|
455
483
|
class Mt {
|
|
456
484
|
/** Total number of matrices currently allocated in the store. */
|
|
457
485
|
matrixCount = 0;
|
|
@@ -465,7 +493,7 @@ class Mt {
|
|
|
465
493
|
* @param capacity - The initial capacity of the matrix store (default is 10).
|
|
466
494
|
*/
|
|
467
495
|
constructor(t = 10) {
|
|
468
|
-
this.buffer = new
|
|
496
|
+
this.buffer = new C(U.Float32), this.buffer.resize(t * E), this.data = this.buffer.getArray(), this.reset();
|
|
469
497
|
}
|
|
470
498
|
/**
|
|
471
499
|
* Allocates a new matrix and initializes it to the identity matrix.
|
|
@@ -480,7 +508,7 @@ class Mt {
|
|
|
480
508
|
* @returns The index of the newly allocated matrix.
|
|
481
509
|
*/
|
|
482
510
|
allocDirty() {
|
|
483
|
-
return this.buffer.resize(
|
|
511
|
+
return this.buffer.resize(E) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += E, this.matrixCount++;
|
|
484
512
|
}
|
|
485
513
|
/**
|
|
486
514
|
* Resets the store, clearing all allocated matrices.
|
|
@@ -493,7 +521,7 @@ class Mt {
|
|
|
493
521
|
* @param index - The index of the matrix to modify.
|
|
494
522
|
*/
|
|
495
523
|
identity(t) {
|
|
496
|
-
const e = t *
|
|
524
|
+
const e = t * E, r = this.data;
|
|
497
525
|
r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
|
|
498
526
|
}
|
|
499
527
|
/**
|
|
@@ -503,8 +531,8 @@ class Mt {
|
|
|
503
531
|
* @param y - The y translation.
|
|
504
532
|
*/
|
|
505
533
|
translate(t, e, r) {
|
|
506
|
-
const i = t *
|
|
507
|
-
|
|
534
|
+
const i = t * E, s = this.data;
|
|
535
|
+
s[i + 4] = s[i] * e + s[i + 2] * r + s[i + 4], s[i + 5] = s[i + 1] * e + s[i + 3] * r + s[i + 5];
|
|
508
536
|
}
|
|
509
537
|
/**
|
|
510
538
|
* Scales the matrix at the given index by scaleX and scaleY.
|
|
@@ -513,8 +541,8 @@ class Mt {
|
|
|
513
541
|
* @param scaleY - The scale factor along the y-axis.
|
|
514
542
|
*/
|
|
515
543
|
scale(t, e, r) {
|
|
516
|
-
const i = t *
|
|
517
|
-
|
|
544
|
+
const i = t * E, s = this.data;
|
|
545
|
+
s[i] *= e, s[i + 1] *= e, s[i + 2] *= r, s[i + 3] *= r;
|
|
518
546
|
}
|
|
519
547
|
/**
|
|
520
548
|
* Rotates the matrix at the given index by the specified radians.
|
|
@@ -522,8 +550,8 @@ class Mt {
|
|
|
522
550
|
* @param radians - The rotation angle in radians.
|
|
523
551
|
*/
|
|
524
552
|
rotate(t, e) {
|
|
525
|
-
const r = t *
|
|
526
|
-
i[r] =
|
|
553
|
+
const r = t * E, i = this.data, s = Math.cos(e), a = Math.sin(e), o = i[r], h = i[r + 1], c = i[r + 2], u = i[r + 3];
|
|
554
|
+
i[r] = o * s + c * a, i[r + 1] = h * s + u * a, i[r + 2] = o * -a + c * s, i[r + 3] = h * -a + u * s;
|
|
527
555
|
}
|
|
528
556
|
/**
|
|
529
557
|
* Rotates the matrix at the given index around a local offset point (pivot).
|
|
@@ -550,8 +578,8 @@ class Mt {
|
|
|
550
578
|
* @param src - The index of the source matrix.
|
|
551
579
|
*/
|
|
552
580
|
copy(t, e) {
|
|
553
|
-
const r = t *
|
|
554
|
-
|
|
581
|
+
const r = t * E, i = e * E, s = this.data;
|
|
582
|
+
s[r] = s[i], s[r + 1] = s[i + 1], s[r + 2] = s[i + 2], s[r + 3] = s[i + 3], s[r + 4] = s[i + 4], s[r + 5] = s[i + 5];
|
|
555
583
|
}
|
|
556
584
|
/**
|
|
557
585
|
* Multiplies the destination matrix by the source matrix and stores the result in the destination.
|
|
@@ -568,21 +596,21 @@ class Mt {
|
|
|
568
596
|
* @param bIdx - The index of matrix B.
|
|
569
597
|
*/
|
|
570
598
|
multiplyOut(t, e, r) {
|
|
571
|
-
const i = t *
|
|
572
|
-
|
|
599
|
+
const i = t * E, s = e * E, a = r * E, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], x = o[a], g = o[a + 1], v = o[a + 2], T = o[a + 3], A = o[a + 4], R = o[a + 5];
|
|
600
|
+
o[i] = h * x + u * g, o[i + 1] = c * x + l * g, o[i + 2] = h * v + u * T, o[i + 3] = c * v + l * T, o[i + 4] = h * A + u * R + d, o[i + 5] = c * A + l * R + f;
|
|
573
601
|
}
|
|
574
602
|
/**
|
|
575
603
|
* Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
|
|
576
604
|
* @param index - The index of the matrix to invert.
|
|
577
605
|
*/
|
|
578
606
|
invert(t) {
|
|
579
|
-
const e = t *
|
|
580
|
-
let u = i *
|
|
607
|
+
const e = t * E, r = this.data, i = r[e], s = r[e + 1], a = r[e + 2], o = r[e + 3], h = r[e + 4], c = r[e + 5];
|
|
608
|
+
let u = i * o - s * a;
|
|
581
609
|
if (!u) {
|
|
582
610
|
this.identity(t);
|
|
583
611
|
return;
|
|
584
612
|
}
|
|
585
|
-
u = 1 / u, r[e] =
|
|
613
|
+
u = 1 / u, r[e] = o * u, r[e + 1] = -s * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * c - o * h) * u, r[e + 5] = (s * h - i * c) * u;
|
|
586
614
|
}
|
|
587
615
|
/**
|
|
588
616
|
* Transforms a point by the matrix at the given index.
|
|
@@ -592,10 +620,10 @@ class Mt {
|
|
|
592
620
|
* @returns The transformed point {x, y}.
|
|
593
621
|
*/
|
|
594
622
|
transformPoint(t, e, r) {
|
|
595
|
-
const i = t *
|
|
623
|
+
const i = t * E, s = this.data;
|
|
596
624
|
return {
|
|
597
|
-
x: e *
|
|
598
|
-
y: e *
|
|
625
|
+
x: e * s[i] + r * s[i + 2] + s[i + 4],
|
|
626
|
+
y: e * s[i + 1] + r * s[i + 3] + s[i + 5]
|
|
599
627
|
};
|
|
600
628
|
}
|
|
601
629
|
/**
|
|
@@ -609,8 +637,8 @@ class Mt {
|
|
|
609
637
|
worldToLocal(t, e, r) {
|
|
610
638
|
const i = this.allocDirty();
|
|
611
639
|
this.copy(i, t), this.invert(i);
|
|
612
|
-
const
|
|
613
|
-
return this.matrixCount--, this.buffer.usedElemNum -=
|
|
640
|
+
const s = this.transformPoint(i, e, r);
|
|
641
|
+
return this.matrixCount--, this.buffer.usedElemNum -= E, s;
|
|
614
642
|
}
|
|
615
643
|
/**
|
|
616
644
|
* Transforms a point from local coordinates to world coordinates.
|
|
@@ -628,7 +656,7 @@ class Mt {
|
|
|
628
656
|
* @returns An object containing `x` and `y` global coordinates.
|
|
629
657
|
*/
|
|
630
658
|
getPosition(t) {
|
|
631
|
-
const e = t *
|
|
659
|
+
const e = t * E, r = this.data;
|
|
632
660
|
return { x: r[e + 4], y: r[e + 5] };
|
|
633
661
|
}
|
|
634
662
|
/**
|
|
@@ -637,8 +665,8 @@ class Mt {
|
|
|
637
665
|
* @returns An object containing `x` and `y` global scale factors.
|
|
638
666
|
*/
|
|
639
667
|
getScale(t) {
|
|
640
|
-
const e = t *
|
|
641
|
-
return { x: i, y:
|
|
668
|
+
const e = t * E, r = this.data, i = Math.sqrt(r[e] * r[e] + r[e + 1] * r[e + 1]), s = Math.sqrt(r[e + 2] * r[e + 2] + r[e + 3] * r[e + 3]);
|
|
669
|
+
return { x: i, y: s };
|
|
642
670
|
}
|
|
643
671
|
/**
|
|
644
672
|
* Extracts the global rotation (in radians) from the matrix at the given index.
|
|
@@ -646,7 +674,7 @@ class Mt {
|
|
|
646
674
|
* @returns The global rotation in radians.
|
|
647
675
|
*/
|
|
648
676
|
getRotation(t) {
|
|
649
|
-
const e = t *
|
|
677
|
+
const e = t * E, r = this.data;
|
|
650
678
|
return Math.atan2(r[e + 1], r[e]);
|
|
651
679
|
}
|
|
652
680
|
/**
|
|
@@ -657,8 +685,8 @@ class Mt {
|
|
|
657
685
|
* @returns A CSS matrix string.
|
|
658
686
|
*/
|
|
659
687
|
toCSSMatrix(t, e = 1, r = 1) {
|
|
660
|
-
const i = t *
|
|
661
|
-
return `matrix(${
|
|
688
|
+
const i = t * E, s = this.data;
|
|
689
|
+
return `matrix(${s[i] * e}, ${s[i + 1] * r}, ${s[i + 2] * e}, ${s[i + 3] * r}, ${s[i + 4] * e}, ${s[i + 5] * r})`;
|
|
662
690
|
}
|
|
663
691
|
/**
|
|
664
692
|
* Retrieves a copy of the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
|
|
@@ -668,8 +696,8 @@ class Mt {
|
|
|
668
696
|
* @returns A new Float32Array containing the 6 elements of the matrix.
|
|
669
697
|
*/
|
|
670
698
|
getMatrix(t) {
|
|
671
|
-
const e = t *
|
|
672
|
-
return this.data.slice(e, e +
|
|
699
|
+
const e = t * E;
|
|
700
|
+
return this.data.slice(e, e + E);
|
|
673
701
|
}
|
|
674
702
|
/**
|
|
675
703
|
* Retrieves a direct reference (view) to the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
|
|
@@ -679,8 +707,8 @@ class Mt {
|
|
|
679
707
|
* @returns A Float32Array view pointing directly to the matrix's data in memory.
|
|
680
708
|
*/
|
|
681
709
|
getMatrixRef(t) {
|
|
682
|
-
const e = t *
|
|
683
|
-
return this.data.subarray(e, e +
|
|
710
|
+
const e = t * E;
|
|
711
|
+
return this.data.subarray(e, e + E);
|
|
684
712
|
}
|
|
685
713
|
/**
|
|
686
714
|
* Overwrites the matrix at the specified index with the provided 6 elements [a, b, c, d, tx, ty].
|
|
@@ -689,33 +717,33 @@ class Mt {
|
|
|
689
717
|
* @param f - An array (Float32Array or standard number array) containing the 6 new elements.
|
|
690
718
|
*/
|
|
691
719
|
setMatrix(t, e) {
|
|
692
|
-
const r = t *
|
|
720
|
+
const r = t * E, i = this.data;
|
|
693
721
|
i[r] = e[0], i[r + 1] = e[1], i[r + 2] = e[2], i[r + 3] = e[3], i[r + 4] = e[4], i[r + 5] = e[5];
|
|
694
722
|
}
|
|
695
|
-
multiplyAffineInPlace(t, e, r, i,
|
|
696
|
-
const h = t * 6,
|
|
697
|
-
|
|
723
|
+
multiplyAffineInPlace(t, e, r, i, s, a, o) {
|
|
724
|
+
const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], x = c[h + 4], g = c[h + 5];
|
|
725
|
+
c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + x, c[h + 5] = l * a + f * o + g;
|
|
698
726
|
}
|
|
699
|
-
multiplyAffine(t, e, r, i,
|
|
700
|
-
const
|
|
701
|
-
l[u] = d * r + x * i, l[u + 1] = f * r + g * i, l[u + 2] = d *
|
|
727
|
+
multiplyAffine(t, e, r, i, s, a, o, h) {
|
|
728
|
+
const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], x = l[c + 2], g = l[c + 3], v = l[c + 4], T = l[c + 5];
|
|
729
|
+
l[u] = d * r + x * i, l[u + 1] = f * r + g * i, l[u + 2] = d * s + x * a, l[u + 3] = f * s + g * a, l[u + 4] = d * o + x * h + v, l[u + 5] = f * o + g * h + T;
|
|
702
730
|
}
|
|
703
731
|
}
|
|
704
|
-
class
|
|
732
|
+
class At {
|
|
705
733
|
/** The underlying store for matrices. */
|
|
706
734
|
matrix = new Mt();
|
|
707
735
|
/** The current step or depth in the transformation hierarchy. */
|
|
708
736
|
step = 0;
|
|
709
737
|
/** Internal stack maintaining structural information. */
|
|
710
|
-
stack = new
|
|
738
|
+
stack = new C(U.Uint32);
|
|
711
739
|
/** Records the world matrices generated at each step. */
|
|
712
|
-
stepWorldM = new
|
|
740
|
+
stepWorldM = new C(U.Uint32);
|
|
713
741
|
/** Records actions (push/pop) taken during the traversal. */
|
|
714
|
-
stepAction = new
|
|
742
|
+
stepAction = new C(U.Uint32);
|
|
715
743
|
/** Records the parent world matrix for each step (used by updateMatrix). */
|
|
716
|
-
stepParentM = new
|
|
744
|
+
stepParentM = new C(U.Uint32);
|
|
717
745
|
/** Buffer used during hierarchy traversal updates. */
|
|
718
|
-
parentStack = new
|
|
746
|
+
parentStack = new C(U.Uint32);
|
|
719
747
|
/** The index of the current local matrix in the matrix store. */
|
|
720
748
|
curLocalM = -1;
|
|
721
749
|
/** The index of the current world matrix in the matrix store. */
|
|
@@ -750,15 +778,15 @@ class St {
|
|
|
750
778
|
*/
|
|
751
779
|
updateMatrix(t) {
|
|
752
780
|
const e = (typeof t == "number" ? t : t.step) - 1, r = this.stepParentM.get(e);
|
|
753
|
-
let i = 0,
|
|
781
|
+
let i = 0, s = e;
|
|
754
782
|
const a = this.parentStack;
|
|
755
|
-
for (a.reset(), a.push(r);
|
|
756
|
-
if (this.stepAction.get(
|
|
757
|
-
const h = this.stepWorldM.get(
|
|
758
|
-
this.matrix.multiplyOut(h, u,
|
|
783
|
+
for (a.reset(), a.push(r); s < this.stepAction.length; ) {
|
|
784
|
+
if (this.stepAction.get(s) === 1) {
|
|
785
|
+
const h = this.stepWorldM.get(s), c = h - 1, u = a.top();
|
|
786
|
+
this.matrix.multiplyOut(h, u, c), a.push(h), i++;
|
|
759
787
|
} else if (a.pop(), i--, i === 0)
|
|
760
788
|
break;
|
|
761
|
-
|
|
789
|
+
s++;
|
|
762
790
|
}
|
|
763
791
|
}
|
|
764
792
|
/**
|
|
@@ -864,14 +892,14 @@ class St {
|
|
|
864
892
|
* Returns the current world matrix as Float32Array [a, b, c, d, tx, ty].
|
|
865
893
|
*/
|
|
866
894
|
getTransform() {
|
|
867
|
-
const t = this.curWorldM *
|
|
868
|
-
return this.matrix.data.slice(t, t +
|
|
895
|
+
const t = this.curWorldM * E;
|
|
896
|
+
return this.matrix.data.slice(t, t + E);
|
|
869
897
|
}
|
|
870
898
|
/**
|
|
871
899
|
* Directly overwrites the current world matrix with the given 6-element 2D transform.
|
|
872
900
|
*/
|
|
873
901
|
setTransform(t) {
|
|
874
|
-
const e = this.curWorldM *
|
|
902
|
+
const e = this.curWorldM * E, r = this.matrix.data;
|
|
875
903
|
r[e] = t[0], r[e + 1] = t[1], r[e + 2] = t[2], r[e + 3] = t[3], r[e + 4] = t[4], r[e + 5] = t[5];
|
|
876
904
|
}
|
|
877
905
|
transformPoint(t, e) {
|
|
@@ -882,27 +910,27 @@ class St {
|
|
|
882
910
|
* Optionally saves the matrix first
|
|
883
911
|
*/
|
|
884
912
|
applyTransform(t, e = 0, r = 0, i = -1) {
|
|
885
|
-
let
|
|
886
|
-
t.position && (
|
|
887
|
-
let
|
|
888
|
-
const
|
|
889
|
-
|
|
913
|
+
let s = t.x ?? 0, a = t.y ?? 0;
|
|
914
|
+
t.position && (s += t.position.x, a += t.position.y);
|
|
915
|
+
let o = 1, h = 1;
|
|
916
|
+
const c = t.scale;
|
|
917
|
+
c && (typeof c == "number" ? (o = c, h = c) : (o = c.x, h = c.y));
|
|
890
918
|
const u = t.rotation ?? 0;
|
|
891
919
|
let l = t.offsetX ?? 0, d = t.offsetY ?? 0;
|
|
892
920
|
t.offset && (l += t.offset.x, d += t.offset.y);
|
|
893
921
|
const f = t.origin;
|
|
894
922
|
f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
|
|
895
|
-
const x = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = x *
|
|
923
|
+
const x = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = x * o, T = g * o, A = -g * h, R = x * h, S = s + v * l + A * d, P = a + T * l + R * d;
|
|
896
924
|
if (i !== -1) {
|
|
897
925
|
this.matrix.multiplyAffine(
|
|
898
926
|
this.curWorldM,
|
|
899
927
|
i,
|
|
900
928
|
v,
|
|
901
929
|
T,
|
|
930
|
+
A,
|
|
902
931
|
R,
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
N
|
|
932
|
+
S,
|
|
933
|
+
P
|
|
906
934
|
);
|
|
907
935
|
return;
|
|
908
936
|
}
|
|
@@ -910,23 +938,23 @@ class St {
|
|
|
910
938
|
this.curLocalM,
|
|
911
939
|
v,
|
|
912
940
|
T,
|
|
941
|
+
A,
|
|
913
942
|
R,
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
N
|
|
943
|
+
S,
|
|
944
|
+
P
|
|
917
945
|
), this.matrix.multiplyAffineInPlace(
|
|
918
946
|
this.curWorldM,
|
|
919
947
|
v,
|
|
920
948
|
T,
|
|
949
|
+
A,
|
|
921
950
|
R,
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
N
|
|
951
|
+
S,
|
|
952
|
+
P
|
|
925
953
|
);
|
|
926
954
|
}
|
|
927
955
|
}
|
|
928
|
-
var
|
|
929
|
-
class
|
|
956
|
+
var q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(q || {});
|
|
957
|
+
class St {
|
|
930
958
|
render;
|
|
931
959
|
cache = /* @__PURE__ */ new Map();
|
|
932
960
|
constructor(t) {
|
|
@@ -941,10 +969,10 @@ class bt {
|
|
|
941
969
|
async load(t, e) {
|
|
942
970
|
let r = this.cache.get(t);
|
|
943
971
|
if (r)
|
|
944
|
-
return new
|
|
972
|
+
return new F(r);
|
|
945
973
|
try {
|
|
946
974
|
const i = await this._fetchImage(t);
|
|
947
|
-
return r =
|
|
975
|
+
return r = Y.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new F(r);
|
|
948
976
|
} catch (i) {
|
|
949
977
|
throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
|
|
950
978
|
}
|
|
@@ -957,9 +985,9 @@ class bt {
|
|
|
957
985
|
*/
|
|
958
986
|
create(t, e) {
|
|
959
987
|
if (e?.key && this.cache.has(e.key))
|
|
960
|
-
return new
|
|
961
|
-
const r =
|
|
962
|
-
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new
|
|
988
|
+
return new F(this.cache.get(e.key));
|
|
989
|
+
const r = Y.fromSource(this.render, t, e);
|
|
990
|
+
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new F(r);
|
|
963
991
|
}
|
|
964
992
|
/**
|
|
965
993
|
* Creates a generic Render Texture (FrameBuffer).
|
|
@@ -969,7 +997,7 @@ class bt {
|
|
|
969
997
|
* @returns The newly created RenderTexture.
|
|
970
998
|
*/
|
|
971
999
|
createRenderTexture(t) {
|
|
972
|
-
return new
|
|
1000
|
+
return new bt(this.render, t);
|
|
973
1001
|
}
|
|
974
1002
|
/**
|
|
975
1003
|
* Creates a TextTexture for rendering text.
|
|
@@ -977,7 +1005,7 @@ class bt {
|
|
|
977
1005
|
* @returns The newly created TextTexture.
|
|
978
1006
|
*/
|
|
979
1007
|
createTextTexture(t) {
|
|
980
|
-
return new
|
|
1008
|
+
return new Ct(this.render, t);
|
|
981
1009
|
}
|
|
982
1010
|
/**
|
|
983
1011
|
* Destroys a texture and potentially removes its BaseTexture from the cache.
|
|
@@ -988,7 +1016,7 @@ class bt {
|
|
|
988
1016
|
*/
|
|
989
1017
|
destroy(t, e = !1) {
|
|
990
1018
|
let r, i;
|
|
991
|
-
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof
|
|
1019
|
+
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof F ? (r = t.base, i = r?.uid, t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
|
|
992
1020
|
}
|
|
993
1021
|
/**
|
|
994
1022
|
* Destroys all cached textures and clears the cache, ignoring reference counts.
|
|
@@ -1005,7 +1033,7 @@ class bt {
|
|
|
1005
1033
|
});
|
|
1006
1034
|
}
|
|
1007
1035
|
}
|
|
1008
|
-
class
|
|
1036
|
+
class Y {
|
|
1009
1037
|
glTexture = null;
|
|
1010
1038
|
width;
|
|
1011
1039
|
height;
|
|
@@ -1022,8 +1050,8 @@ class k {
|
|
|
1022
1050
|
* @returns The created BaseTexture.
|
|
1023
1051
|
*/
|
|
1024
1052
|
static fromSource(t, e, r = {}) {
|
|
1025
|
-
const i =
|
|
1026
|
-
return new
|
|
1053
|
+
const i = J(t, e, r);
|
|
1054
|
+
return new Y(i, e.width, e.height);
|
|
1027
1055
|
}
|
|
1028
1056
|
/**
|
|
1029
1057
|
* Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
|
|
@@ -1032,19 +1060,19 @@ class k {
|
|
|
1032
1060
|
* @param source - The new image source.
|
|
1033
1061
|
*/
|
|
1034
1062
|
updateSource(t, e, r = {}) {
|
|
1035
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 &&
|
|
1063
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && it(t, r.textureFilter), r.wrap !== void 0 && rt(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
|
|
1036
1064
|
}
|
|
1037
1065
|
/**
|
|
1038
1066
|
* Dynamically updates the texture filtering mode.
|
|
1039
1067
|
*/
|
|
1040
1068
|
setFilterMode(t, e) {
|
|
1041
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1069
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), it(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1042
1070
|
}
|
|
1043
1071
|
/**
|
|
1044
1072
|
* Dynamically updates the texture wrap mode.
|
|
1045
1073
|
*/
|
|
1046
1074
|
setWrapMode(t, e) {
|
|
1047
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1075
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), rt(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1048
1076
|
}
|
|
1049
1077
|
/**
|
|
1050
1078
|
* Destroys the WebGL texture resource.
|
|
@@ -1054,7 +1082,7 @@ class k {
|
|
|
1054
1082
|
this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
|
|
1055
1083
|
}
|
|
1056
1084
|
}
|
|
1057
|
-
class
|
|
1085
|
+
class F {
|
|
1058
1086
|
base;
|
|
1059
1087
|
uvX = 0;
|
|
1060
1088
|
uvY = 0;
|
|
@@ -1111,16 +1139,16 @@ class P {
|
|
|
1111
1139
|
* @returns A new Texture pointing to the sub-region.
|
|
1112
1140
|
*/
|
|
1113
1141
|
getSubTexture(t, e, r, i) {
|
|
1114
|
-
if (!this.base) return new
|
|
1115
|
-
const
|
|
1116
|
-
return
|
|
1142
|
+
if (!this.base) return new F();
|
|
1143
|
+
const s = this.clone(), a = this._px, o = this._py;
|
|
1144
|
+
return s.setRegion(a + t, o + e, r, i), s;
|
|
1117
1145
|
}
|
|
1118
1146
|
/**
|
|
1119
1147
|
* Creates a shallow copy of this Texture, sharing the same BaseTexture.
|
|
1120
1148
|
* @returns A new Texture instance.
|
|
1121
1149
|
*/
|
|
1122
1150
|
clone(t) {
|
|
1123
|
-
const e = t ?? new
|
|
1151
|
+
const e = t ?? new F(this.base);
|
|
1124
1152
|
return t && this.base && t.setBase(this.base), e.scale = this.scale, e.uvX = this.uvX, e.uvY = this.uvY, e.uvW = this.uvW, e.uvH = this.uvH, e.rawWidth = this.rawWidth, e.rawHeight = this.rawHeight, e.offsetX = this.offsetX, e.offsetY = this.offsetY, e.flipY = this.flipY, e.isRotated = this.isRotated, e.isAtlas = this.isAtlas, e._px = this._px, e._py = this._py, e._pw = this._pw, e._ph = this._ph, e;
|
|
1125
1153
|
}
|
|
1126
1154
|
/**
|
|
@@ -1133,9 +1161,9 @@ class P {
|
|
|
1133
1161
|
* @param gap - Optional pixel gap between cells.
|
|
1134
1162
|
* @returns An array of split Textures.
|
|
1135
1163
|
*/
|
|
1136
|
-
splitGrid(t, e, r, i,
|
|
1164
|
+
splitGrid(t, e, r, i, s = 0) {
|
|
1137
1165
|
if (!this.base) return [];
|
|
1138
|
-
const a = [],
|
|
1166
|
+
const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((o + c) / u), f = i ?? Math.floor((h + c) / l);
|
|
1139
1167
|
for (let x = 0; x < f; x++)
|
|
1140
1168
|
for (let g = 0; g < d; g++)
|
|
1141
1169
|
a.push(this.getSubTexture(g * u, x * l, t, e));
|
|
@@ -1147,8 +1175,8 @@ class P {
|
|
|
1147
1175
|
* @param options - Optional antialias and wrap mode settings.
|
|
1148
1176
|
*/
|
|
1149
1177
|
static fromImageSource(t, e, r = {}) {
|
|
1150
|
-
const i =
|
|
1151
|
-
return new
|
|
1178
|
+
const i = J(t, e, r);
|
|
1179
|
+
return new F(new Y(i, e.width, e.height));
|
|
1152
1180
|
}
|
|
1153
1181
|
/**
|
|
1154
1182
|
* Marks this Texture as destroyed, decrementing the BaseTexture reference count.
|
|
@@ -1157,7 +1185,7 @@ class P {
|
|
|
1157
1185
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
1158
1186
|
}
|
|
1159
1187
|
}
|
|
1160
|
-
class
|
|
1188
|
+
class bt extends F {
|
|
1161
1189
|
framebuffer;
|
|
1162
1190
|
renderbuffer;
|
|
1163
1191
|
gl;
|
|
@@ -1167,9 +1195,9 @@ class At extends P {
|
|
|
1167
1195
|
_allocW = 0;
|
|
1168
1196
|
_allocH = 0;
|
|
1169
1197
|
constructor(t, e) {
|
|
1170
|
-
super(), this.gl = t.gl, this.clearColor = e.clearColor ??
|
|
1171
|
-
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a =
|
|
1172
|
-
if (this.setBase(new
|
|
1198
|
+
super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
|
|
1199
|
+
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = J(t, { width: r, height: i }, { ...e, onlySize: !0 });
|
|
1200
|
+
if (this.setBase(new Y(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
1173
1201
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
1174
1202
|
this.resize(r, i, !0);
|
|
1175
1203
|
}
|
|
@@ -1189,8 +1217,8 @@ class At extends P {
|
|
|
1189
1217
|
t = Math.max(Math.round(t), 1), e = Math.max(Math.round(e), 1);
|
|
1190
1218
|
const i = this.rawWidth === t && this.rawHeight === e;
|
|
1191
1219
|
if (!r && i) return;
|
|
1192
|
-
const
|
|
1193
|
-
(r || t > this._allocW || e > this._allocH) && this.base && (this._allocW = Math.max(this._allocW, t), this._allocH = Math.max(this._allocH, e), this.base.width = this._allocW, this.base.height = this._allocH,
|
|
1220
|
+
const s = this.gl;
|
|
1221
|
+
(r || t > this._allocW || e > this._allocH) && this.base && (this._allocW = Math.max(this._allocW, t), this._allocH = Math.max(this._allocH, e), this.base.width = this._allocW, this.base.height = this._allocH, s.bindTexture(s.TEXTURE_2D, this.base.glTexture), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, this._allocW, this._allocH, 0, s.RGBA, s.UNSIGNED_BYTE, null), s.bindRenderbuffer(s.RENDERBUFFER, this.renderbuffer), s.renderbufferStorage(s.RENDERBUFFER, s.STENCIL_INDEX8, this._allocW, this._allocH), s.bindFramebuffer(s.FRAMEBUFFER, this.framebuffer), s.framebufferTexture2D(s.FRAMEBUFFER, s.COLOR_ATTACHMENT0, s.TEXTURE_2D, this.base.glTexture, 0), s.framebufferRenderbuffer(s.FRAMEBUFFER, s.STENCIL_ATTACHMENT, s.RENDERBUFFER, this.renderbuffer), s.bindFramebuffer(s.FRAMEBUFFER, null), s.bindRenderbuffer(s.RENDERBUFFER, null), s.bindTexture(s.TEXTURE_2D, null)), this.rawWidth = t, this.rawHeight = e, this.uvX = 0, this.uvW = t / this._allocW, this.uvY = 0, this.uvH = e / this._allocH;
|
|
1194
1222
|
}
|
|
1195
1223
|
/**
|
|
1196
1224
|
* Activates this texture as the current render target.
|
|
@@ -1222,14 +1250,14 @@ class At extends P {
|
|
|
1222
1250
|
*/
|
|
1223
1251
|
GetPixels(t = 0, e = 0, r = this.rawWidth, i = this.rawHeight) {
|
|
1224
1252
|
if (!this.framebuffer) return new Uint8Array(0);
|
|
1225
|
-
const
|
|
1226
|
-
if (
|
|
1227
|
-
if (
|
|
1253
|
+
const s = Math.floor(t), a = Math.floor(e), o = Math.floor(r), h = Math.floor(i);
|
|
1254
|
+
if (o <= 0 || h <= 0) return new Uint8Array(0);
|
|
1255
|
+
if (s < 0 || a < 0 || s >= this.rawWidth || a >= this.rawHeight)
|
|
1228
1256
|
return new Uint8Array(0);
|
|
1229
|
-
const
|
|
1257
|
+
const c = Math.min(o, this.rawWidth - s), u = Math.min(h, this.rawHeight - a), l = this.rawHeight - a - u, d = this.gl, f = d.getParameter(d.FRAMEBUFFER_BINDING);
|
|
1230
1258
|
d.bindFramebuffer(d.FRAMEBUFFER, this.framebuffer);
|
|
1231
|
-
const x = new Uint8Array(
|
|
1232
|
-
return d.readPixels(
|
|
1259
|
+
const x = new Uint8Array(c * u * 4);
|
|
1260
|
+
return d.readPixels(s, l, c, u, d.RGBA, d.UNSIGNED_BYTE, x), d.bindFramebuffer(d.FRAMEBUFFER, f), x;
|
|
1233
1261
|
}
|
|
1234
1262
|
/**
|
|
1235
1263
|
* Get the color at a pixel in the render texture.
|
|
@@ -1238,7 +1266,7 @@ class At extends P {
|
|
|
1238
1266
|
*/
|
|
1239
1267
|
GetColorAt(t, e) {
|
|
1240
1268
|
const r = this.GetPixels(t, e, 1, 1);
|
|
1241
|
-
return r.length < 4 ? new
|
|
1269
|
+
return r.length < 4 ? new m(0, 0, 0, 0) : new m(r[0], r[1], r[2], r[3]);
|
|
1242
1270
|
}
|
|
1243
1271
|
/**
|
|
1244
1272
|
* Destroys the framebuffer, renderbuffer, and base texture.
|
|
@@ -1256,7 +1284,7 @@ const Ut = {
|
|
|
1256
1284
|
align: "left",
|
|
1257
1285
|
baseline: "top"
|
|
1258
1286
|
};
|
|
1259
|
-
class
|
|
1287
|
+
class Ct extends F {
|
|
1260
1288
|
canvas;
|
|
1261
1289
|
ctx;
|
|
1262
1290
|
render;
|
|
@@ -1269,8 +1297,8 @@ class _t extends P {
|
|
|
1269
1297
|
const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
|
|
1270
1298
|
if (!r) throw new Error("Failed to get 2d context for TextTexture");
|
|
1271
1299
|
this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
|
|
1272
|
-
const i =
|
|
1273
|
-
this.setBase(new
|
|
1300
|
+
const i = J(t, this.canvas, this.options);
|
|
1301
|
+
this.setBase(new Y(i, 1, 1)), this.update();
|
|
1274
1302
|
}
|
|
1275
1303
|
get text() {
|
|
1276
1304
|
return this._text;
|
|
@@ -1318,97 +1346,97 @@ class _t extends P {
|
|
|
1318
1346
|
* Updates the internal canvas and uploads it to WebGL
|
|
1319
1347
|
*/
|
|
1320
1348
|
update() {
|
|
1321
|
-
const t = this.ctx, e = this._style.fontSize, r = this._style.fontWeight, i = this._style.fontFamily,
|
|
1322
|
-
t.font =
|
|
1323
|
-
const
|
|
1349
|
+
const t = this.ctx, e = this._style.fontSize, r = this._style.fontWeight, i = this._style.fontFamily, s = `${r} ${e}px ${i}`, a = this.render.dpr;
|
|
1350
|
+
t.font = s;
|
|
1351
|
+
const o = this._text.split(`
|
|
1324
1352
|
`);
|
|
1325
|
-
let h = 0,
|
|
1353
|
+
let h = 0, c = 0;
|
|
1326
1354
|
t.textBaseline = "alphabetic";
|
|
1327
|
-
const u = t.measureText(
|
|
1328
|
-
for (const
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1355
|
+
const u = t.measureText(o[0]), l = u.fontBoundingBoxAscent, d = u.fontBoundingBoxDescent;
|
|
1356
|
+
for (const R of o) {
|
|
1357
|
+
const S = t.measureText(R);
|
|
1358
|
+
S.width > h && (h = S.width), c += l + d;
|
|
1331
1359
|
}
|
|
1332
|
-
|
|
1333
|
-
const f = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + f) || 1, g = Math.ceil(
|
|
1334
|
-
(this.canvas.width !== v || this.canvas.height !== T) && (this.canvas.width = v, this.canvas.height = T), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, g), t.font =
|
|
1335
|
-
let
|
|
1336
|
-
for (const
|
|
1337
|
-
let
|
|
1338
|
-
this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(
|
|
1360
|
+
c -= d;
|
|
1361
|
+
const f = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + f) || 1, g = Math.ceil(c + f) || 1, v = x * a, T = g * a;
|
|
1362
|
+
(this.canvas.width !== v || this.canvas.height !== T) && (this.canvas.width = v, this.canvas.height = T), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, g), t.font = s, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, g);
|
|
1363
|
+
let A = f / 2;
|
|
1364
|
+
for (const R of o) {
|
|
1365
|
+
let S = f / 2;
|
|
1366
|
+
this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(R, S, A)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(R, S, A)), A += l + d;
|
|
1339
1367
|
}
|
|
1340
1368
|
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, this.canvas.width, this.canvas.height);
|
|
1341
1369
|
}
|
|
1342
1370
|
}
|
|
1343
|
-
const
|
|
1344
|
-
const r =
|
|
1371
|
+
const _t = (n, t = !1, e = !0) => {
|
|
1372
|
+
const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
|
|
1345
1373
|
if (!r)
|
|
1346
1374
|
throw new Error("WebGL2 is not supported in this browser.");
|
|
1347
1375
|
return r;
|
|
1348
|
-
},
|
|
1349
|
-
const r =
|
|
1376
|
+
}, ot = (n, t, e) => {
|
|
1377
|
+
const r = n.createShader(e);
|
|
1350
1378
|
if (!r)
|
|
1351
1379
|
throw new Error("Unable to create webgl shader");
|
|
1352
|
-
if (
|
|
1353
|
-
const
|
|
1354
|
-
throw console.error("Shader compilation failed:",
|
|
1380
|
+
if (n.shaderSource(r, t), n.compileShader(r), !n.getShaderParameter(r, n.COMPILE_STATUS)) {
|
|
1381
|
+
const s = n.getShaderInfoLog(r);
|
|
1382
|
+
throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
|
|
1355
1383
|
}
|
|
1356
1384
|
return r;
|
|
1357
|
-
}, Pt = (
|
|
1358
|
-
var r =
|
|
1385
|
+
}, Pt = (n, t, e) => {
|
|
1386
|
+
var r = n.createProgram(), i = ot(n, t, 35633), s = ot(n, e, 35632);
|
|
1359
1387
|
if (!r)
|
|
1360
1388
|
throw new Error("Unable to create program shader");
|
|
1361
|
-
if (
|
|
1362
|
-
const
|
|
1363
|
-
throw new Error("Unable to link shader program: " +
|
|
1389
|
+
if (n.attachShader(r, i), n.attachShader(r, s), n.linkProgram(r), !n.getProgramParameter(r, n.LINK_STATUS)) {
|
|
1390
|
+
const o = n.getProgramInfoLog(r);
|
|
1391
|
+
throw new Error("Unable to link shader program: " + o);
|
|
1364
1392
|
}
|
|
1365
1393
|
return r;
|
|
1366
1394
|
};
|
|
1367
|
-
function
|
|
1395
|
+
function rt(n, t) {
|
|
1368
1396
|
const e = {
|
|
1369
|
-
[
|
|
1370
|
-
[
|
|
1371
|
-
[
|
|
1372
|
-
}[t] ||
|
|
1373
|
-
|
|
1397
|
+
[q.CLAMP]: n.CLAMP_TO_EDGE,
|
|
1398
|
+
[q.REPEAT]: n.REPEAT,
|
|
1399
|
+
[q.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
|
|
1400
|
+
}[t] || n.CLAMP_TO_EDGE;
|
|
1401
|
+
n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, e);
|
|
1374
1402
|
}
|
|
1375
|
-
function
|
|
1403
|
+
function it(n, t) {
|
|
1376
1404
|
const e = {
|
|
1377
|
-
[
|
|
1378
|
-
[
|
|
1379
|
-
}[t] ??
|
|
1380
|
-
|
|
1405
|
+
[nt.LINEAR]: n.LINEAR,
|
|
1406
|
+
[nt.NEAREST]: n.NEAREST
|
|
1407
|
+
}[t] ?? n.NEAREST;
|
|
1408
|
+
n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e);
|
|
1381
1409
|
}
|
|
1382
|
-
function
|
|
1383
|
-
const r =
|
|
1410
|
+
function J(n, t, e) {
|
|
1411
|
+
const r = n.gl, i = r.createTexture();
|
|
1384
1412
|
if (!i)
|
|
1385
1413
|
throw new Error("Unable to create WebGL texture");
|
|
1386
|
-
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1),
|
|
1387
|
-
const
|
|
1388
|
-
r.texImage2D(r.TEXTURE_2D, 0, r.RGBA,
|
|
1414
|
+
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), rt(r, e.wrap ?? q.CLAMP), it(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
|
|
1415
|
+
const s = t;
|
|
1416
|
+
r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, s.width, s.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
|
|
1389
1417
|
} else {
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1418
|
+
const s = e.premultipliedAlpha ?? n.premultipliedAlpha;
|
|
1419
|
+
s && r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, r.RGBA, r.UNSIGNED_BYTE, t), s && r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
|
|
1392
1420
|
}
|
|
1393
1421
|
return r.bindTexture(r.TEXTURE_2D, null), i;
|
|
1394
1422
|
}
|
|
1395
|
-
function
|
|
1396
|
-
if (
|
|
1423
|
+
function G(n, t) {
|
|
1424
|
+
if (n.includes("%TEXTURE_NUM%") && (n = n.replace("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
|
|
1397
1425
|
let e = "";
|
|
1398
1426
|
for (let r = 0; r < t; r++)
|
|
1399
1427
|
r == 0 ? e += `if(vTextureId == ${r})` : r == t - 1 ? e += "else" : e += `else if(vTextureId == ${r})`, e += `{return texture(uTextures[${r}], uv);}`;
|
|
1400
|
-
|
|
1428
|
+
n = n.replace("%GET_COLOR%", e);
|
|
1401
1429
|
}
|
|
1402
|
-
return
|
|
1430
|
+
return n;
|
|
1403
1431
|
}
|
|
1404
|
-
const Nt = 5126,
|
|
1405
|
-
function Lt(
|
|
1406
|
-
|
|
1432
|
+
const Nt = 5126, st = 5121;
|
|
1433
|
+
function Lt(n, t, e) {
|
|
1434
|
+
n.vertexAttribDivisor(t, e);
|
|
1407
1435
|
}
|
|
1408
|
-
function
|
|
1409
|
-
|
|
1436
|
+
function yt(n, t, e, r, i) {
|
|
1437
|
+
n.drawArraysInstanced(t, e, r, i);
|
|
1410
1438
|
}
|
|
1411
|
-
let
|
|
1439
|
+
let It = 0;
|
|
1412
1440
|
class Tt {
|
|
1413
1441
|
program;
|
|
1414
1442
|
attributeLoc = {};
|
|
@@ -1421,7 +1449,7 @@ class Tt {
|
|
|
1421
1449
|
/** Whether the uniform is an array (e.g. sampler2D uTextures[8]) */
|
|
1422
1450
|
uniformIsArray = {};
|
|
1423
1451
|
gl;
|
|
1424
|
-
shaderId =
|
|
1452
|
+
shaderId = It++;
|
|
1425
1453
|
// for debug
|
|
1426
1454
|
vao;
|
|
1427
1455
|
constructor(t, e, r, i) {
|
|
@@ -1450,8 +1478,8 @@ class Tt {
|
|
|
1450
1478
|
setUniform(t, e) {
|
|
1451
1479
|
const r = this.uniformLoc[t];
|
|
1452
1480
|
if (r === void 0) return;
|
|
1453
|
-
const i = this.uniformType[t],
|
|
1454
|
-
|
|
1481
|
+
const i = this.uniformType[t], s = this.uniformIsArray[t];
|
|
1482
|
+
Ot(this.gl, r, i, e, s);
|
|
1455
1483
|
}
|
|
1456
1484
|
/**
|
|
1457
1485
|
* Batch-set uniforms via a plain value map.
|
|
@@ -1498,77 +1526,77 @@ class Tt {
|
|
|
1498
1526
|
parseShader(t) {
|
|
1499
1527
|
const e = this.gl, r = t.match(/(?:in|attribute)\s+\w+\s+\w+/g);
|
|
1500
1528
|
if (r)
|
|
1501
|
-
for (const
|
|
1502
|
-
const
|
|
1503
|
-
h !== -1 && (this.attributeLoc[
|
|
1529
|
+
for (const s of r) {
|
|
1530
|
+
const o = s.split(/\s+/)[2], h = e.getAttribLocation(this.program, o);
|
|
1531
|
+
h !== -1 && (this.attributeLoc[o] = h);
|
|
1504
1532
|
}
|
|
1505
1533
|
const i = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
|
|
1506
1534
|
if (i)
|
|
1507
|
-
for (const
|
|
1508
|
-
const a =
|
|
1509
|
-
|
|
1535
|
+
for (const s of i) {
|
|
1536
|
+
const a = s.split(/\s+/), o = a[1], h = a[2].replace(/\[\d+\]$/, ""), c = e.getUniformLocation(this.program, h);
|
|
1537
|
+
c !== null && (this.uniformLoc[h] = c, this.uniformType[h] = o, this.uniformIsArray[h] = /\[\d+\]$/.test(a[2]));
|
|
1510
1538
|
}
|
|
1511
1539
|
}
|
|
1512
1540
|
}
|
|
1513
|
-
function
|
|
1541
|
+
function Ot(n, t, e, r, i = !1) {
|
|
1514
1542
|
switch (e) {
|
|
1515
1543
|
// scalars
|
|
1516
1544
|
case "float":
|
|
1517
|
-
return
|
|
1545
|
+
return n.uniform1f(t, r);
|
|
1518
1546
|
case "int":
|
|
1519
1547
|
case "bool":
|
|
1520
1548
|
case "sampler2D":
|
|
1521
1549
|
case "samplerCube":
|
|
1522
|
-
return i ?
|
|
1550
|
+
return i ? n.uniform1iv(t, r) : n.uniform1i(t, r);
|
|
1523
1551
|
// float vectors
|
|
1524
1552
|
case "vec2":
|
|
1525
|
-
return
|
|
1553
|
+
return n.uniform2fv(t, r);
|
|
1526
1554
|
case "vec3":
|
|
1527
|
-
return
|
|
1555
|
+
return n.uniform3fv(t, r);
|
|
1528
1556
|
case "vec4":
|
|
1529
|
-
return
|
|
1557
|
+
return n.uniform4fv(t, r);
|
|
1530
1558
|
// int / bool vectors
|
|
1531
1559
|
case "ivec2":
|
|
1532
1560
|
case "bvec2":
|
|
1533
|
-
return
|
|
1561
|
+
return n.uniform2iv(t, r);
|
|
1534
1562
|
case "ivec3":
|
|
1535
1563
|
case "bvec3":
|
|
1536
|
-
return
|
|
1564
|
+
return n.uniform3iv(t, r);
|
|
1537
1565
|
case "ivec4":
|
|
1538
1566
|
case "bvec4":
|
|
1539
|
-
return
|
|
1567
|
+
return n.uniform4iv(t, r);
|
|
1540
1568
|
// matrices (column-major, transpose = false)
|
|
1541
1569
|
case "mat2":
|
|
1542
|
-
return
|
|
1570
|
+
return n.uniformMatrix2fv(t, !1, r);
|
|
1543
1571
|
case "mat3":
|
|
1544
|
-
return
|
|
1572
|
+
return n.uniformMatrix3fv(t, !1, r);
|
|
1545
1573
|
case "mat4":
|
|
1546
|
-
return
|
|
1574
|
+
return n.uniformMatrix4fv(t, !1, r);
|
|
1547
1575
|
// fallback: guess by value shape
|
|
1548
1576
|
default:
|
|
1549
|
-
return
|
|
1577
|
+
return Ft(n, t, r);
|
|
1550
1578
|
}
|
|
1551
1579
|
}
|
|
1552
|
-
function
|
|
1580
|
+
function Ft(n, t, e) {
|
|
1553
1581
|
if (typeof e == "number")
|
|
1554
|
-
return
|
|
1582
|
+
return n.uniform1f(t, e);
|
|
1555
1583
|
const r = e;
|
|
1556
1584
|
switch (r.length) {
|
|
1557
1585
|
case 2:
|
|
1558
|
-
return
|
|
1586
|
+
return n.uniform2fv(t, r);
|
|
1559
1587
|
case 3:
|
|
1560
|
-
return
|
|
1588
|
+
return n.uniform3fv(t, r);
|
|
1561
1589
|
case 4:
|
|
1562
|
-
return
|
|
1590
|
+
return n.uniform4fv(t, r);
|
|
1563
1591
|
case 9:
|
|
1564
|
-
return
|
|
1592
|
+
return n.uniformMatrix3fv(t, !1, r);
|
|
1565
1593
|
case 16:
|
|
1566
|
-
return
|
|
1594
|
+
return n.uniformMatrix4fv(t, !1, r);
|
|
1567
1595
|
default:
|
|
1568
|
-
return
|
|
1596
|
+
return n.uniform1fv(t, r);
|
|
1569
1597
|
}
|
|
1570
1598
|
}
|
|
1571
|
-
class
|
|
1599
|
+
class ct {
|
|
1572
1600
|
/** Custom vertex shader code */
|
|
1573
1601
|
vs;
|
|
1574
1602
|
/** Custom fragment shader code */
|
|
@@ -1586,8 +1614,8 @@ class ot {
|
|
|
1586
1614
|
/** Padding in pixels this shader needs beyond the sprite bounds (for outline/glow effects) */
|
|
1587
1615
|
padding = 0;
|
|
1588
1616
|
rapid;
|
|
1589
|
-
constructor(t, e, r, i = 0,
|
|
1590
|
-
this.vs = e, this.fs = r, this.rapid = t, this.uniforms =
|
|
1617
|
+
constructor(t, e, r, i = 0, s) {
|
|
1618
|
+
this.vs = e, this.fs = r, this.rapid = t, this.uniforms = s ?? {}, this.usedTextureUnitNum = i;
|
|
1591
1619
|
}
|
|
1592
1620
|
/**
|
|
1593
1621
|
* Updates uniform values or textures for the custom shader.
|
|
@@ -1596,8 +1624,8 @@ class ot {
|
|
|
1596
1624
|
setUniforms(t) {
|
|
1597
1625
|
this.rapid.flush();
|
|
1598
1626
|
const e = {}, r = {};
|
|
1599
|
-
for (const [i,
|
|
1600
|
-
|
|
1627
|
+
for (const [i, s] of Object.entries(t))
|
|
1628
|
+
s instanceof WebGLTexture ? r[i] = s : e[i] = s;
|
|
1601
1629
|
Object.assign(this.uniforms, e), Object.assign(this.uniformTextures, r);
|
|
1602
1630
|
for (const i of this.glshader.keys())
|
|
1603
1631
|
this.uniformDirty.add(i);
|
|
@@ -1636,11 +1664,11 @@ class ot {
|
|
|
1636
1664
|
if (i == null || r == null)
|
|
1637
1665
|
return console.warn("CustomGlShader: missing base shader for " + e), null;
|
|
1638
1666
|
r = r.replace("// CUSTOM_CODE_CALL", "vertex(position, vRegion);"), i = i.replace("// CUSTOM_CODE_CALL", "fragment(fragColor);"), r = r.replace("// CUSTOM_CODE", this.vs), i = i.replace("// CUSTOM_CODE", this.fs);
|
|
1639
|
-
const
|
|
1640
|
-
return
|
|
1667
|
+
const s = t.createShader(r, i);
|
|
1668
|
+
return s.isCustom = !0, s.padding = this.padding, this.glshader.set(e, s), this.uniformDirty.add(e), s;
|
|
1641
1669
|
}
|
|
1642
1670
|
}
|
|
1643
|
-
class
|
|
1671
|
+
class Et {
|
|
1644
1672
|
constructor(t) {
|
|
1645
1673
|
this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
|
|
1646
1674
|
}
|
|
@@ -1672,8 +1700,8 @@ class yt {
|
|
|
1672
1700
|
}
|
|
1673
1701
|
findTextureUnit(t, e = 0, r = 0) {
|
|
1674
1702
|
for (let i = 0; i < this.usedTextures.length; i++) {
|
|
1675
|
-
const
|
|
1676
|
-
if (this.usedTextures[i] === t && this.usedTexturePadding[
|
|
1703
|
+
const s = i * 2;
|
|
1704
|
+
if (this.usedTextures[i] === t && this.usedTexturePadding[s] === e && this.usedTexturePadding[s + 1] === r)
|
|
1677
1705
|
return i;
|
|
1678
1706
|
}
|
|
1679
1707
|
return -1;
|
|
@@ -1691,7 +1719,7 @@ class yt {
|
|
|
1691
1719
|
getCustomShader(t) {
|
|
1692
1720
|
if (!t)
|
|
1693
1721
|
return this.defaultShader;
|
|
1694
|
-
if (t instanceof
|
|
1722
|
+
if (t instanceof ct) {
|
|
1695
1723
|
const e = this.createCustomShader(t);
|
|
1696
1724
|
return e ?? this.defaultShader;
|
|
1697
1725
|
}
|
|
@@ -1706,7 +1734,7 @@ class yt {
|
|
|
1706
1734
|
return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
|
|
1707
1735
|
}
|
|
1708
1736
|
enter(t) {
|
|
1709
|
-
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof
|
|
1737
|
+
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ct ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
|
|
1710
1738
|
}
|
|
1711
1739
|
exit() {
|
|
1712
1740
|
this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
|
|
@@ -1721,8 +1749,8 @@ class yt {
|
|
|
1721
1749
|
const t = this.currentShader;
|
|
1722
1750
|
if (t.use(), this.customShader) {
|
|
1723
1751
|
const r = this.customShader, i = {};
|
|
1724
|
-
for (const
|
|
1725
|
-
i[
|
|
1752
|
+
for (const s in r.uniformTextures)
|
|
1753
|
+
i[s] = this.useTexture(r.uniformTextures[s]);
|
|
1726
1754
|
this.customShader.applyUniform(this.KEY, i);
|
|
1727
1755
|
}
|
|
1728
1756
|
const e = this.gl;
|
|
@@ -1743,7 +1771,7 @@ class yt {
|
|
|
1743
1771
|
return !1;
|
|
1744
1772
|
}
|
|
1745
1773
|
}
|
|
1746
|
-
const
|
|
1774
|
+
const Z = `#version 300 es\r
|
|
1747
1775
|
precision highp float;\r
|
|
1748
1776
|
\r
|
|
1749
1777
|
// per-vertex\r
|
|
@@ -1791,7 +1819,7 @@ void main(void) {\r
|
|
|
1791
1819
|
\r
|
|
1792
1820
|
gl_Position = u_projection * position;\r
|
|
1793
1821
|
}\r
|
|
1794
|
-
`,
|
|
1822
|
+
`, ut = `#version 300 es\r
|
|
1795
1823
|
precision mediump float;\r
|
|
1796
1824
|
\r
|
|
1797
1825
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -1840,8 +1868,8 @@ void main(void) {\r
|
|
|
1840
1868
|
\r
|
|
1841
1869
|
// CUSTOM_CODE_CALL\r
|
|
1842
1870
|
}\r
|
|
1843
|
-
`,
|
|
1844
|
-
class
|
|
1871
|
+
`, j = 48, Wt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
1872
|
+
class at extends Et {
|
|
1845
1873
|
instanceBuffer;
|
|
1846
1874
|
quadBuffer;
|
|
1847
1875
|
instanceCount = 0;
|
|
@@ -1853,28 +1881,28 @@ class it extends yt {
|
|
|
1853
1881
|
}
|
|
1854
1882
|
createBuffer() {
|
|
1855
1883
|
const t = this.gl;
|
|
1856
|
-
this.quadBuffer = new
|
|
1857
|
-
for (const e of
|
|
1858
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new
|
|
1884
|
+
this.quadBuffer = new et(t, U.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1885
|
+
for (const e of Wt) this.quadBuffer.pushFloat32(e);
|
|
1886
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t, U.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1859
1887
|
}
|
|
1860
1888
|
createDefaultShader() {
|
|
1861
|
-
const t = this.rapid, e =
|
|
1889
|
+
const t = this.rapid, e = G(ut, t.maxTextureUnits), r = G(Z, t.maxTextureUnits);
|
|
1862
1890
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
1863
1891
|
}
|
|
1864
1892
|
createShader(t, e) {
|
|
1865
1893
|
const r = super.createShader(t, e);
|
|
1866
1894
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
1867
|
-
{ name: "aMatrixRow0", size: 3, stride:
|
|
1868
|
-
{ name: "aMatrixRow1", size: 3, stride:
|
|
1869
|
-
{ name: "aUVRect", size: 4, stride:
|
|
1870
|
-
{ name: "aColor", size: 4, type:
|
|
1871
|
-
{ name: "aTextureId", size: 1, type:
|
|
1895
|
+
{ name: "aMatrixRow0", size: 3, stride: j, offset: 0, divisor: 1 },
|
|
1896
|
+
{ name: "aMatrixRow1", size: 3, stride: j, offset: 12, divisor: 1 },
|
|
1897
|
+
{ name: "aUVRect", size: 4, stride: j, offset: 24, divisor: 1 },
|
|
1898
|
+
{ name: "aColor", size: 4, type: st, normalized: !0, stride: j, offset: 40, divisor: 1 },
|
|
1899
|
+
{ name: "aTextureId", size: 1, type: st, stride: j, offset: 44, divisor: 1 }
|
|
1872
1900
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
1873
1901
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1874
1902
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1875
1903
|
}
|
|
1876
1904
|
createCustomShader(t) {
|
|
1877
|
-
const e =
|
|
1905
|
+
const e = G(ut, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = G(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
1878
1906
|
return t.getGLShader(this, this.KEY, r, e);
|
|
1879
1907
|
}
|
|
1880
1908
|
/**
|
|
@@ -1889,7 +1917,7 @@ class it extends yt {
|
|
|
1889
1917
|
* @param v1 Bottom UV mapped coordinate (default 1).
|
|
1890
1918
|
* @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
|
|
1891
1919
|
*/
|
|
1892
|
-
drawSprite(t, e, r = 0, i = 0,
|
|
1920
|
+
drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, l = !1, d = !1) {
|
|
1893
1921
|
const f = e * 6, x = this.matrixStore.data;
|
|
1894
1922
|
this.drawSpriteAffine(
|
|
1895
1923
|
t,
|
|
@@ -1901,33 +1929,33 @@ class it extends yt {
|
|
|
1901
1929
|
x[f + 5],
|
|
1902
1930
|
r,
|
|
1903
1931
|
i,
|
|
1904
|
-
|
|
1932
|
+
s,
|
|
1905
1933
|
a,
|
|
1906
|
-
c,
|
|
1907
|
-
h,
|
|
1908
1934
|
o,
|
|
1935
|
+
h,
|
|
1936
|
+
c,
|
|
1909
1937
|
u,
|
|
1910
1938
|
l,
|
|
1911
1939
|
d
|
|
1912
1940
|
);
|
|
1913
1941
|
}
|
|
1914
|
-
drawSpriteAffine(t, e, r, i,
|
|
1915
|
-
const
|
|
1942
|
+
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, x = 0, g = !1, v = !1, T = !1) {
|
|
1943
|
+
const A = t.base, R = t.scale ?? 1, S = t.rawWidth, P = t.rawHeight, H = t.offsetX, X = t.offsetY, B = this.useTexture(
|
|
1916
1944
|
t.glTexture,
|
|
1917
|
-
f /
|
|
1918
|
-
x /
|
|
1919
|
-
),
|
|
1920
|
-
|
|
1921
|
-
const
|
|
1922
|
-
T ? (
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1945
|
+
f / R / A.width,
|
|
1946
|
+
x / R / A.height
|
|
1947
|
+
), N = this.instanceBuffer, b = N.usedElemNum;
|
|
1948
|
+
N.resize(12);
|
|
1949
|
+
const _ = N.float32, W = N.uint32, D = (T ? P : S) * R, k = (T ? S : P) * R, I = D + 2 * f, M = k + 2 * x, L = H - f, z = X - x, y = this.localSpriteMatrix;
|
|
1950
|
+
T ? (y[0] = 0, y[1] = v ? M : -M, y[2] = g ? -I : I, y[3] = 0, y[4] = L + (g ? I : 0), y[5] = z + (v ? 0 : M)) : (y[0] = g ? -I : I, y[1] = 0, y[2] = 0, y[3] = v ? -M : M, y[4] = L + (g ? I : 0), y[5] = z + (v ? M : 0));
|
|
1951
|
+
const w = this.worldSpriteMatrix;
|
|
1952
|
+
w[0] = e * y[0] + i * y[1], w[1] = r * y[0] + s * y[1], w[2] = e * y[2] + i * y[3], w[3] = r * y[2] + s * y[3], w[4] = a + e * y[4] + i * y[5], w[5] = o + r * y[4] + s * y[5], _[b + 6] = h, _[b + 7] = c, _[b + 8] = u, _[b + 9] = l, W[b + 10] = d, W[b + 11] = B, this.rapid.roundPixels && (w[4] = Math.round(w[4]), w[5] = Math.round(w[5])), _[b] = w[0], _[b + 1] = w[2], _[b + 2] = w[4], _[b + 3] = w[1], _[b + 4] = w[3], _[b + 5] = w[5], N.usedElemNum += 12, N.makeDirty(), this.instanceCount++;
|
|
1925
1953
|
}
|
|
1926
1954
|
render() {
|
|
1927
1955
|
if (this.instanceCount === 0) return;
|
|
1928
1956
|
this.prepareRender();
|
|
1929
1957
|
const t = this.gl, e = this.currentShader;
|
|
1930
|
-
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(),
|
|
1958
|
+
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
|
|
1931
1959
|
}
|
|
1932
1960
|
resetRender() {
|
|
1933
1961
|
super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
|
|
@@ -1936,7 +1964,7 @@ class it extends yt {
|
|
|
1936
1964
|
return this.instanceCount > 0;
|
|
1937
1965
|
}
|
|
1938
1966
|
}
|
|
1939
|
-
const
|
|
1967
|
+
const Bt = `#version 300 es\r
|
|
1940
1968
|
precision highp float;\r
|
|
1941
1969
|
\r
|
|
1942
1970
|
in vec2 aPosition;\r
|
|
@@ -1967,7 +1995,7 @@ void main(void) {\r
|
|
|
1967
1995
|
// CUSTOM_CODE_CALL\r
|
|
1968
1996
|
gl_Position = u_projection * position;\r
|
|
1969
1997
|
}\r
|
|
1970
|
-
`,
|
|
1998
|
+
`, Dt = `#version 300 es\r
|
|
1971
1999
|
precision mediump float;\r
|
|
1972
2000
|
\r
|
|
1973
2001
|
in vec4 vColor;\r
|
|
@@ -2056,8 +2084,8 @@ void main(void) {\r
|
|
|
2056
2084
|
discard;\r
|
|
2057
2085
|
}\r
|
|
2058
2086
|
}\r
|
|
2059
|
-
`,
|
|
2060
|
-
class Ht extends
|
|
2087
|
+
`, $ = 20;
|
|
2088
|
+
class Ht extends Et {
|
|
2061
2089
|
vertexBuffer;
|
|
2062
2090
|
vertexCount = 0;
|
|
2063
2091
|
matrixIndex = -1;
|
|
@@ -2070,24 +2098,24 @@ class Ht extends yt {
|
|
|
2070
2098
|
}
|
|
2071
2099
|
createBuffer() {
|
|
2072
2100
|
const t = this.gl;
|
|
2073
|
-
this.vertexBuffer = new
|
|
2101
|
+
this.vertexBuffer = new et(t, U.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
|
|
2074
2102
|
}
|
|
2075
2103
|
createDefaultShader() {
|
|
2076
|
-
return this.vs =
|
|
2104
|
+
return this.vs = Bt, this.fs = Dt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
2077
2105
|
}
|
|
2078
2106
|
createMaskShader(t, e) {
|
|
2079
2107
|
const r = this.gl, i = new Tt(r, t, e);
|
|
2080
2108
|
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
2081
|
-
{ name: "aPosition", size: 2, type: r.FLOAT, stride:
|
|
2082
|
-
{ name: "aUV", size: 2, type: r.FLOAT, stride:
|
|
2109
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: $ - 4, offset: 0, divisor: 0 },
|
|
2110
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: $ - 4, offset: 8, divisor: 0 }
|
|
2083
2111
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2084
2112
|
}
|
|
2085
2113
|
createShader(t, e) {
|
|
2086
2114
|
const r = this.gl, i = super.createShader(t, e);
|
|
2087
2115
|
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
2088
|
-
{ name: "aPosition", size: 2, type: r.FLOAT, stride:
|
|
2089
|
-
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride:
|
|
2090
|
-
{ name: "aUV", size: 2, type: r.FLOAT, stride:
|
|
2116
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: $, offset: 0, divisor: 0 },
|
|
2117
|
+
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: $, offset: 8, divisor: 0 },
|
|
2118
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: $, offset: 12, divisor: 0 }
|
|
2091
2119
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2092
2120
|
}
|
|
2093
2121
|
/**
|
|
@@ -2107,22 +2135,22 @@ class Ht extends yt {
|
|
|
2107
2135
|
* @param v UV mapped Y value (0-1, default 0).
|
|
2108
2136
|
* @param color Pre-multiplied hex color combined using ABGR byte order (default 0xFFFFFFFF).
|
|
2109
2137
|
*/
|
|
2110
|
-
addVertex(t, e, r = 0, i = 0,
|
|
2138
|
+
addVertex(t, e, r = 0, i = 0, s = 4294967295) {
|
|
2111
2139
|
const a = this.vertexBuffer;
|
|
2112
|
-
a.pushFloat32(t), a.pushFloat32(e), this.currentShader != this.maskShader && a.pushUint32(
|
|
2140
|
+
a.pushFloat32(t), a.pushFloat32(e), this.currentShader != this.maskShader && a.pushUint32(s), a.pushFloat32(r), a.pushFloat32(i), this.vertexCount++, this.vertexBuffer.makeDirty();
|
|
2113
2141
|
}
|
|
2114
2142
|
/**
|
|
2115
2143
|
* Finishes the graphic construction and dispatches the rendering call immediately.
|
|
2116
2144
|
*/
|
|
2117
2145
|
endGraphic() {
|
|
2118
|
-
this.
|
|
2146
|
+
this.flush();
|
|
2119
2147
|
}
|
|
2120
2148
|
render() {
|
|
2121
2149
|
if (this.vertexCount === 0) return;
|
|
2122
2150
|
this.prepareRender();
|
|
2123
2151
|
const t = this.gl, e = this.currentShader, r = this.matrixIndex * 6, i = this.matrixStore.data;
|
|
2124
|
-
let
|
|
2125
|
-
this.rapid.roundPixels && (
|
|
2152
|
+
let s = i[r + 4], a = i[r + 5];
|
|
2153
|
+
this.rapid.roundPixels && (s = Math.round(s), a = Math.round(a)), e.setUniform("uMatrixRow0", [i[r], i[r + 2], s]), e.setUniform("uMatrixRow1", [i[r + 1], i[r + 3], a]), e.setUniform(
|
|
2126
2154
|
"uUVRect",
|
|
2127
2155
|
this.texture ? [this.texture.uvX, this.texture.uvY, this.texture.uvW, this.texture.uvH] : [0, 0, 1, 1]
|
|
2128
2156
|
), this.texture?.glTexture ? (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture), e.setUniform("uTexture", 0), e.setUniform("uUseTexture", 1)) : e.setUniform("uUseTexture", 0), this.vertexBuffer.bindBuffer(), this.vertexBuffer.bufferData(), e.bindVAO(), t.drawArrays(this.drawMode, 0, this.vertexCount), this.rapid.drawcallCount++, this.texture = void 0;
|
|
@@ -2131,15 +2159,15 @@ class Ht extends yt {
|
|
|
2131
2159
|
return !1;
|
|
2132
2160
|
}
|
|
2133
2161
|
}
|
|
2134
|
-
class
|
|
2162
|
+
class p {
|
|
2135
2163
|
x;
|
|
2136
2164
|
y;
|
|
2137
|
-
static ZERO = new
|
|
2138
|
-
static ONE = new
|
|
2139
|
-
static UP = new
|
|
2140
|
-
static DOWN = new
|
|
2141
|
-
static LEFT = new
|
|
2142
|
-
static RIGHT = new
|
|
2165
|
+
static ZERO = new p(0, 0);
|
|
2166
|
+
static ONE = new p(1, 1);
|
|
2167
|
+
static UP = new p(0, 1);
|
|
2168
|
+
static DOWN = new p(0, -1);
|
|
2169
|
+
static LEFT = new p(-1, 0);
|
|
2170
|
+
static RIGHT = new p(1, 0);
|
|
2143
2171
|
constructor(t, e) {
|
|
2144
2172
|
this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
|
|
2145
2173
|
}
|
|
@@ -2147,22 +2175,22 @@ class m {
|
|
|
2147
2175
|
return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
|
|
2148
2176
|
}
|
|
2149
2177
|
add(t) {
|
|
2150
|
-
return new
|
|
2178
|
+
return new p(this.x + t.x, this.y + t.y);
|
|
2151
2179
|
}
|
|
2152
2180
|
subtract(t) {
|
|
2153
|
-
return new
|
|
2181
|
+
return new p(this.x - t.x, this.y - t.y);
|
|
2154
2182
|
}
|
|
2155
2183
|
sub(t) {
|
|
2156
|
-
return new
|
|
2184
|
+
return new p(this.x - t.x, this.y - t.y);
|
|
2157
2185
|
}
|
|
2158
2186
|
multiply(t) {
|
|
2159
|
-
return t instanceof
|
|
2187
|
+
return t instanceof p ? new p(this.x * t.x, this.y * t.y) : new p(this.x * t, this.y * t);
|
|
2160
2188
|
}
|
|
2161
2189
|
mul(t) {
|
|
2162
2190
|
return this.multiply(t);
|
|
2163
2191
|
}
|
|
2164
2192
|
divide(t) {
|
|
2165
|
-
return t instanceof
|
|
2193
|
+
return t instanceof p ? new p(this.x / t.x, this.y / t.y) : new p(this.x / t, this.y / t);
|
|
2166
2194
|
}
|
|
2167
2195
|
dot(t) {
|
|
2168
2196
|
return this.x * t.x + this.y * t.y;
|
|
@@ -2175,13 +2203,13 @@ class m {
|
|
|
2175
2203
|
return Math.sqrt(e * e + r * r);
|
|
2176
2204
|
}
|
|
2177
2205
|
clone() {
|
|
2178
|
-
return new
|
|
2206
|
+
return new p(this.x, this.y);
|
|
2179
2207
|
}
|
|
2180
2208
|
to(t) {
|
|
2181
2209
|
this.x = t.x, this.y = t.y;
|
|
2182
2210
|
}
|
|
2183
2211
|
copy() {
|
|
2184
|
-
return new
|
|
2212
|
+
return new p(this.x, this.y);
|
|
2185
2213
|
}
|
|
2186
2214
|
equals(t) {
|
|
2187
2215
|
return t.x == this.x && t.y == this.y;
|
|
@@ -2194,7 +2222,7 @@ class m {
|
|
|
2194
2222
|
return this.x = -this.x, this.y = -this.y, this;
|
|
2195
2223
|
}
|
|
2196
2224
|
inverted() {
|
|
2197
|
-
return new
|
|
2225
|
+
return new p(this.x * -1, this.y * -1);
|
|
2198
2226
|
}
|
|
2199
2227
|
length() {
|
|
2200
2228
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
@@ -2208,13 +2236,13 @@ class m {
|
|
|
2208
2236
|
}
|
|
2209
2237
|
normalized() {
|
|
2210
2238
|
const t = this.length();
|
|
2211
|
-
return new
|
|
2239
|
+
return new p(this.x / t || 0, this.y / t || 0);
|
|
2212
2240
|
}
|
|
2213
2241
|
fix(t = 1e-13) {
|
|
2214
2242
|
this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
|
|
2215
2243
|
}
|
|
2216
2244
|
fixed(t = 1e-13) {
|
|
2217
|
-
return new
|
|
2245
|
+
return new p(
|
|
2218
2246
|
Math.abs(this.x) < t ? 0 : this.x,
|
|
2219
2247
|
Math.abs(this.y) < t ? 0 : this.y
|
|
2220
2248
|
);
|
|
@@ -2223,13 +2251,13 @@ class m {
|
|
|
2223
2251
|
return Math.atan2(this.y, this.x);
|
|
2224
2252
|
}
|
|
2225
2253
|
abs() {
|
|
2226
|
-
return new
|
|
2254
|
+
return new p(Math.abs(this.x), Math.abs(this.y));
|
|
2227
2255
|
}
|
|
2228
2256
|
floor() {
|
|
2229
|
-
return new
|
|
2257
|
+
return new p(Math.floor(this.x), Math.floor(this.y));
|
|
2230
2258
|
}
|
|
2231
2259
|
ceil() {
|
|
2232
|
-
return new
|
|
2260
|
+
return new p(Math.ceil(this.x), Math.ceil(this.y));
|
|
2233
2261
|
}
|
|
2234
2262
|
stringify() {
|
|
2235
2263
|
return `Vec2(${this.x}, ${this.y})`;
|
|
@@ -2250,66 +2278,66 @@ class m {
|
|
|
2250
2278
|
return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
|
|
2251
2279
|
}
|
|
2252
2280
|
static FromArray(t) {
|
|
2253
|
-
return t.map((e) => new
|
|
2281
|
+
return t.map((e) => new p(e[0], e[1]));
|
|
2254
2282
|
}
|
|
2255
2283
|
static fromAngle(t) {
|
|
2256
|
-
return new
|
|
2284
|
+
return new p(Math.cos(t), Math.sin(t));
|
|
2257
2285
|
}
|
|
2258
2286
|
}
|
|
2259
|
-
const Vt = (
|
|
2260
|
-
const [e, r, i,
|
|
2287
|
+
const Vt = (n, t) => {
|
|
2288
|
+
const [e, r, i, s, a, o] = t, h = new Float32Array([
|
|
2261
2289
|
e,
|
|
2262
|
-
|
|
2290
|
+
i,
|
|
2263
2291
|
0,
|
|
2264
2292
|
0,
|
|
2265
2293
|
r,
|
|
2266
|
-
|
|
2294
|
+
s,
|
|
2267
2295
|
0,
|
|
2268
2296
|
0,
|
|
2269
|
-
i,
|
|
2270
|
-
c,
|
|
2271
|
-
1,
|
|
2272
2297
|
0,
|
|
2273
2298
|
0,
|
|
2299
|
+
1,
|
|
2274
2300
|
0,
|
|
2301
|
+
a,
|
|
2302
|
+
o,
|
|
2275
2303
|
0,
|
|
2276
2304
|
1
|
|
2277
2305
|
]);
|
|
2278
|
-
return
|
|
2279
|
-
},
|
|
2306
|
+
return Yt(h, n);
|
|
2307
|
+
}, Yt = (n, t) => {
|
|
2280
2308
|
const e = new Float32Array(16);
|
|
2281
2309
|
for (let r = 0; r < 4; r++)
|
|
2282
2310
|
for (let i = 0; i < 4; i++) {
|
|
2283
|
-
let
|
|
2311
|
+
let s = 0;
|
|
2284
2312
|
for (let a = 0; a < 4; a++)
|
|
2285
|
-
|
|
2286
|
-
e[i * 4 + r] =
|
|
2313
|
+
s += n[i * 4 + a] * t[a * 4 + r];
|
|
2314
|
+
e[i * 4 + r] = s;
|
|
2287
2315
|
}
|
|
2288
2316
|
return e;
|
|
2289
2317
|
};
|
|
2290
|
-
var
|
|
2291
|
-
const
|
|
2292
|
-
const a = [],
|
|
2293
|
-
for (let l = 0; l <
|
|
2294
|
-
const d = l /
|
|
2295
|
-
a.push(
|
|
2296
|
-
}
|
|
2297
|
-
return { vertices: a, uv:
|
|
2298
|
-
},
|
|
2318
|
+
var Xt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(Xt || {});
|
|
2319
|
+
const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
2320
|
+
const a = [], o = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new p(t.y, -t.x);
|
|
2321
|
+
for (let l = 0; l < tt; l++) {
|
|
2322
|
+
const d = l / tt, f = (l + 1) / tt, x = h + d * c, g = h + f * c, v = new p(Math.cos(x) * e, Math.sin(x) * e), T = new p(Math.cos(g) * e, Math.sin(g) * e);
|
|
2323
|
+
a.push(n), o.push(new p(i, 0.5)), a.push(n.add(v)), o.push(new p(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e)), a.push(n.add(T)), o.push(new p(i + T.dot(u) * s, 0.5 - 0.5 * T.dot(t) / e));
|
|
2324
|
+
}
|
|
2325
|
+
return { vertices: a, uv: o };
|
|
2326
|
+
}, zt = (n, t = !1) => {
|
|
2299
2327
|
const e = [];
|
|
2300
|
-
if (
|
|
2301
|
-
const r = 4, i = 1e-3,
|
|
2328
|
+
if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
|
|
2329
|
+
const r = 4, i = 1e-3, s = n.length;
|
|
2302
2330
|
let a = 0;
|
|
2303
2331
|
if (t)
|
|
2304
|
-
for (let h = 0; h <
|
|
2305
|
-
const
|
|
2306
|
-
a +=
|
|
2332
|
+
for (let h = 0; h < s; h++) {
|
|
2333
|
+
const c = n[h], u = n[(h + 1) % s];
|
|
2334
|
+
a += c.distanceTo(u);
|
|
2307
2335
|
}
|
|
2308
2336
|
else
|
|
2309
|
-
for (let h = 0; h <
|
|
2310
|
-
a +=
|
|
2311
|
-
const
|
|
2312
|
-
const l =
|
|
2337
|
+
for (let h = 0; h < s - 1; h++)
|
|
2338
|
+
a += n[h].distanceTo(n[h + 1]);
|
|
2339
|
+
const o = (h, c, u) => {
|
|
2340
|
+
const l = c.subtract(h).normalize(), d = c.subtract(u).normalize(), f = d.dot(l);
|
|
2313
2341
|
if (f < -1 + i)
|
|
2314
2342
|
return { normal: l.perpendicular(), miters: 1 };
|
|
2315
2343
|
{
|
|
@@ -2320,104 +2348,95 @@ const Z = 10, ut = (s, t, e, r, i, n) => {
|
|
|
2320
2348
|
}
|
|
2321
2349
|
};
|
|
2322
2350
|
if (t)
|
|
2323
|
-
for (let h = 0; h <
|
|
2324
|
-
const
|
|
2325
|
-
e.push(c
|
|
2351
|
+
for (let h = 0; h < s; h++) {
|
|
2352
|
+
const c = h === 0 ? n[s - 1] : n[h - 1], u = n[h], l = h === s - 1 ? n[0] : n[h + 1];
|
|
2353
|
+
e.push(o(c, u, l));
|
|
2326
2354
|
}
|
|
2327
2355
|
else
|
|
2328
|
-
for (let h = 0; h <
|
|
2356
|
+
for (let h = 0; h < s; h++)
|
|
2329
2357
|
if (h === 0) {
|
|
2330
|
-
const
|
|
2331
|
-
e.push({ normal:
|
|
2332
|
-
} else if (h ===
|
|
2333
|
-
const
|
|
2334
|
-
e.push({ normal:
|
|
2358
|
+
const c = n[1].subtract(n[0]).normalize();
|
|
2359
|
+
e.push({ normal: c.perpendicular(), miters: 1 });
|
|
2360
|
+
} else if (h === s - 1) {
|
|
2361
|
+
const c = n[h].subtract(n[h - 1]).normalize();
|
|
2362
|
+
e.push({ normal: c.perpendicular(), miters: 1 });
|
|
2335
2363
|
} else
|
|
2336
|
-
e.push(
|
|
2364
|
+
e.push(o(n[h - 1], n[h], n[h + 1]));
|
|
2337
2365
|
return { normals: e, length: a };
|
|
2338
|
-
}, jt = (
|
|
2339
|
-
const t =
|
|
2366
|
+
}, jt = (n) => {
|
|
2367
|
+
const t = n.points;
|
|
2340
2368
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2341
|
-
const { normals: e, length: r } =
|
|
2342
|
-
let
|
|
2343
|
-
const u =
|
|
2369
|
+
const { normals: e, length: r } = zt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
|
|
2370
|
+
let c = 0;
|
|
2371
|
+
const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
|
|
2344
2372
|
for (let d = 0; d < l; d++) {
|
|
2345
|
-
const f = t[d], x = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, T = t[v],
|
|
2346
|
-
let
|
|
2347
|
-
h === 0 ? (
|
|
2348
|
-
const
|
|
2349
|
-
|
|
2350
|
-
}
|
|
2351
|
-
if (
|
|
2352
|
-
const d = t[0], f = e[0].normal, x = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g =
|
|
2353
|
-
|
|
2354
|
-
const v = t[t.length - 1], T = e[t.length - 1].normal,
|
|
2355
|
-
|
|
2356
|
-
}
|
|
2357
|
-
return { vertices:
|
|
2358
|
-
},
|
|
2373
|
+
const f = t[d], x = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, T = t[v], A = e[v].normal, R = e[v].miters, S = f.add(x.multiply(g * i)), P = f.subtract(x.multiply(g * i)), H = T.add(A.multiply(R * i)), X = T.subtract(A.multiply(R * i)), B = f.distanceTo(T);
|
|
2374
|
+
let N = 0, b = 0;
|
|
2375
|
+
h === 0 ? (N = c / r, b = (c + B) / r) : (N = c / u, b = N + B / u);
|
|
2376
|
+
const _ = new p(N, 0), W = new p(N, 1), D = new p(b, 0), k = new p(b, 1);
|
|
2377
|
+
s.push(S), a.push(_), s.push(P), a.push(W), s.push(H), a.push(D), s.push(H), a.push(D), s.push(X), a.push(k), s.push(P), a.push(W), c += B;
|
|
2378
|
+
}
|
|
2379
|
+
if (o && !n.closed) {
|
|
2380
|
+
const d = t[0], f = e[0].normal, x = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g = lt(d, f, i, !0, 0, x);
|
|
2381
|
+
s.push(...g.vertices), a.push(...g.uv);
|
|
2382
|
+
const v = t[t.length - 1], T = e[t.length - 1].normal, A = h === 0 ? 1 : c / u, R = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, S = lt(v, T, i, !1, A, R);
|
|
2383
|
+
s.push(...S.vertices), a.push(...S.uv);
|
|
2384
|
+
}
|
|
2385
|
+
return { vertices: s, uv: a };
|
|
2386
|
+
}, Q = (n, t, e, r) => {
|
|
2359
2387
|
if (t.customMatrix !== void 0)
|
|
2360
2388
|
return t.customMatrix;
|
|
2361
2389
|
if (t.modifyStack) {
|
|
2362
|
-
|
|
2390
|
+
n.matrixStack.applyTransform(
|
|
2363
2391
|
t,
|
|
2364
2392
|
e,
|
|
2365
2393
|
r
|
|
2366
2394
|
);
|
|
2367
2395
|
return;
|
|
2368
2396
|
} else {
|
|
2369
|
-
const i =
|
|
2370
|
-
return
|
|
2397
|
+
const i = n.matrix.temporary;
|
|
2398
|
+
return n.matrixStack.applyTransform(
|
|
2371
2399
|
t,
|
|
2372
2400
|
e,
|
|
2373
2401
|
r,
|
|
2374
2402
|
i
|
|
2375
2403
|
), i;
|
|
2376
2404
|
}
|
|
2377
|
-
},
|
|
2378
|
-
const r = t.texture;
|
|
2379
|
-
if (!r?.base ||
|
|
2405
|
+
}, $t = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Kt = 2, qt = (n, t) => {
|
|
2406
|
+
const e = Q(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
|
|
2407
|
+
if (!r?.base || n.inCreateMask)
|
|
2380
2408
|
return;
|
|
2381
|
-
const i = r.isAtlas ?
|
|
2382
|
-
|
|
2383
|
-
let
|
|
2384
|
-
const
|
|
2409
|
+
const i = r.isAtlas ? n.atlasSpriteRegion : n.spriteRegion;
|
|
2410
|
+
n.enterRegion(i, t.shader);
|
|
2411
|
+
let s = r.uvX, a = r.uvY, o = r.uvW, h = r.uvH;
|
|
2412
|
+
const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
|
|
2385
2413
|
let l = t.padding ?? i.currentShader.padding;
|
|
2386
|
-
r.isAtlas && (l +=
|
|
2387
|
-
const d =
|
|
2414
|
+
r.isAtlas && (l += Kt);
|
|
2415
|
+
const d = s <= o ? l : -l, f = a <= h ? l : -l;
|
|
2388
2416
|
i.drawSprite(
|
|
2389
2417
|
r,
|
|
2390
|
-
e ?? t.customMatrix ??
|
|
2391
|
-
|
|
2418
|
+
e ?? t.customMatrix ?? n.matrixStack.curWorldM,
|
|
2419
|
+
s,
|
|
2392
2420
|
a,
|
|
2393
|
-
|
|
2421
|
+
o,
|
|
2394
2422
|
h,
|
|
2395
|
-
|
|
2423
|
+
n.getColorUint32(t.color),
|
|
2396
2424
|
d,
|
|
2397
2425
|
f,
|
|
2398
|
-
|
|
2426
|
+
c,
|
|
2399
2427
|
u,
|
|
2400
2428
|
r.isRotated
|
|
2401
2429
|
);
|
|
2402
|
-
},
|
|
2403
|
-
const e =
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
const e = s.particleRegion;
|
|
2407
|
-
s.enterRegion(e, t.shader);
|
|
2408
|
-
const r = t.texture, i = t.count ?? t.x.length, n = t.color, a = n.length, c = new Array(a);
|
|
2409
|
-
if (s.premultipliedAlpha)
|
|
2410
|
-
for (let h = 0; h < a; h++)
|
|
2411
|
-
c[h] = n[h].premultipliedUint32;
|
|
2412
|
-
else
|
|
2413
|
-
for (let h = 0; h < a; h++)
|
|
2414
|
-
c[h] = n[h].uint32;
|
|
2430
|
+
}, Qt = (n, t) => {
|
|
2431
|
+
const e = n.particleRegion;
|
|
2432
|
+
n.enterRegion(e, t.shader);
|
|
2433
|
+
const r = t.texture, i = t.count ?? t.x.length, s = t.color;
|
|
2415
2434
|
e.drawParticles(
|
|
2416
2435
|
r,
|
|
2417
2436
|
t.x,
|
|
2418
2437
|
t.y,
|
|
2419
2438
|
t.rotation,
|
|
2420
|
-
|
|
2439
|
+
s,
|
|
2421
2440
|
i,
|
|
2422
2441
|
t.scaleX,
|
|
2423
2442
|
t.scaleY,
|
|
@@ -2427,71 +2446,74 @@ const Z = 10, ut = (s, t, e, r, i, n) => {
|
|
|
2427
2446
|
r.uvH,
|
|
2428
2447
|
t.flipX,
|
|
2429
2448
|
t.flipY,
|
|
2430
|
-
|
|
2449
|
+
r.isRotated,
|
|
2431
2450
|
t.originX,
|
|
2432
|
-
t.originY
|
|
2451
|
+
t.originY,
|
|
2452
|
+
n.premultipliedAlpha,
|
|
2453
|
+
t.reverseOrder,
|
|
2454
|
+
t.customMatrix
|
|
2433
2455
|
);
|
|
2434
|
-
},
|
|
2456
|
+
}, Rt = (n, t) => {
|
|
2435
2457
|
if (t.points.length === 0) return;
|
|
2436
|
-
const e =
|
|
2437
|
-
|
|
2438
|
-
t.drawMode ??
|
|
2458
|
+
const e = Q(n, t, 0, 0);
|
|
2459
|
+
n.startGraphic(
|
|
2460
|
+
t.drawMode ?? n.gl.TRIANGLES,
|
|
2439
2461
|
t.texture,
|
|
2440
2462
|
t.shader,
|
|
2441
2463
|
e ?? t.customMatrix
|
|
2442
2464
|
);
|
|
2443
2465
|
for (let r = 0; r < t.points.length; r++) {
|
|
2444
|
-
const i = t.points[r],
|
|
2445
|
-
|
|
2466
|
+
const i = t.points[r], s = t.uv?.[r], a = Array.isArray(t.color) ? t.color[r] : t.color;
|
|
2467
|
+
n.addGraphicVertex(
|
|
2446
2468
|
i.x,
|
|
2447
2469
|
i.y,
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2470
|
+
s?.x ?? 0,
|
|
2471
|
+
s?.y ?? 0,
|
|
2472
|
+
n.getColorUint32(a)
|
|
2451
2473
|
);
|
|
2452
2474
|
}
|
|
2453
|
-
|
|
2454
|
-
}, Zt = (
|
|
2455
|
-
if (
|
|
2475
|
+
n.endGraphic();
|
|
2476
|
+
}, Zt = (n, t) => {
|
|
2477
|
+
if (n.inCreateMask)
|
|
2456
2478
|
return;
|
|
2457
2479
|
const { vertices: e, uv: r } = jt(t);
|
|
2458
|
-
|
|
2480
|
+
Rt(n, {
|
|
2459
2481
|
...t,
|
|
2460
2482
|
points: e,
|
|
2461
2483
|
uv: r,
|
|
2462
|
-
drawMode:
|
|
2484
|
+
drawMode: n.gl.TRIANGLES
|
|
2463
2485
|
});
|
|
2464
|
-
},
|
|
2465
|
-
const e =
|
|
2466
|
-
|
|
2486
|
+
}, Jt = (n, t) => {
|
|
2487
|
+
const e = Q(
|
|
2488
|
+
n,
|
|
2467
2489
|
t,
|
|
2468
2490
|
t.texture.rawWidth,
|
|
2469
2491
|
t.texture.rawHeight
|
|
2470
2492
|
);
|
|
2471
|
-
|
|
2472
|
-
|
|
2493
|
+
n.startMaskGraphic(
|
|
2494
|
+
n.gl.TRIANGLE_FAN,
|
|
2473
2495
|
t.texture,
|
|
2474
2496
|
e ?? t.customMatrix
|
|
2475
|
-
),
|
|
2476
|
-
},
|
|
2477
|
-
const e =
|
|
2478
|
-
|
|
2479
|
-
|
|
2497
|
+
), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
|
|
2498
|
+
}, te = (n, t) => {
|
|
2499
|
+
const e = Q(n, t, t.width, t.height);
|
|
2500
|
+
n.startGraphic(
|
|
2501
|
+
n.gl.TRIANGLE_FAN,
|
|
2480
2502
|
t.texture,
|
|
2481
2503
|
t.shader,
|
|
2482
2504
|
e ?? t.customMatrix
|
|
2483
|
-
),
|
|
2484
|
-
},
|
|
2485
|
-
const e = t.segments ?? 32, r =
|
|
2486
|
-
|
|
2487
|
-
|
|
2505
|
+
), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
|
|
2506
|
+
}, ee = (n, t) => {
|
|
2507
|
+
const e = t.segments ?? 32, r = Q(n, t, 0, 0);
|
|
2508
|
+
n.startGraphic(
|
|
2509
|
+
n.gl.TRIANGLE_FAN,
|
|
2488
2510
|
void 0,
|
|
2489
2511
|
t.shader,
|
|
2490
2512
|
r ?? t.customMatrix
|
|
2491
2513
|
);
|
|
2492
|
-
const i =
|
|
2493
|
-
|
|
2494
|
-
},
|
|
2514
|
+
const i = n.getColorUint32(t.color);
|
|
2515
|
+
n.addGraphicVertex(0, 0, 0.5, 0.5, i), n.addCircleVertex(t.radius, t.color, e), n.addGraphicVertex(t.radius, 0, 1, 0.5, i), n.endGraphic();
|
|
2516
|
+
}, dt = `#version 300 es\r
|
|
2495
2517
|
precision mediump float;\r
|
|
2496
2518
|
\r
|
|
2497
2519
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -2541,21 +2563,21 @@ void main(void) {\r
|
|
|
2541
2563
|
// CUSTOM_CODE_CALL\r
|
|
2542
2564
|
}\r
|
|
2543
2565
|
`;
|
|
2544
|
-
class
|
|
2566
|
+
class re extends at {
|
|
2545
2567
|
KEY = "AtlasSprite";
|
|
2546
2568
|
constructor(t) {
|
|
2547
2569
|
super(t);
|
|
2548
2570
|
}
|
|
2549
2571
|
createCustomShader(t) {
|
|
2550
|
-
const e =
|
|
2572
|
+
const e = G(dt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = G(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
2551
2573
|
return t.getGLShader(this, this.KEY, r, e);
|
|
2552
2574
|
}
|
|
2553
2575
|
createDefaultShader() {
|
|
2554
|
-
const t = this.rapid, e =
|
|
2576
|
+
const t = this.rapid, e = G(dt, t.maxTextureUnits), r = G(Z, t.maxTextureUnits);
|
|
2555
2577
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
2556
2578
|
}
|
|
2557
2579
|
}
|
|
2558
|
-
const
|
|
2580
|
+
const ft = `#version 300 es\r
|
|
2559
2581
|
precision highp float;\r
|
|
2560
2582
|
\r
|
|
2561
2583
|
// per-vertex\r
|
|
@@ -2596,7 +2618,7 @@ void main(void) {\r
|
|
|
2596
2618
|
\r
|
|
2597
2619
|
gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
|
|
2598
2620
|
}\r
|
|
2599
|
-
`,
|
|
2621
|
+
`, mt = `#version 300 es\r
|
|
2600
2622
|
precision mediump float;\r
|
|
2601
2623
|
\r
|
|
2602
2624
|
uniform sampler2D uTexture;\r
|
|
@@ -2612,18 +2634,19 @@ void main(void) {\r
|
|
|
2612
2634
|
\r
|
|
2613
2635
|
// CUSTOM_CODE_CALL\r
|
|
2614
2636
|
}\r
|
|
2615
|
-
`,
|
|
2616
|
-
class
|
|
2637
|
+
`, V = 48, xt = V / 4;
|
|
2638
|
+
class ie extends at {
|
|
2617
2639
|
KEY = "ParticleSprite";
|
|
2618
2640
|
texture;
|
|
2641
|
+
customMatrix;
|
|
2619
2642
|
constructor(t) {
|
|
2620
2643
|
super(t);
|
|
2621
2644
|
}
|
|
2622
2645
|
createCustomShader(t) {
|
|
2623
|
-
return t.getGLShader(this, this.KEY,
|
|
2646
|
+
return t.getGLShader(this, this.KEY, ft, mt);
|
|
2624
2647
|
}
|
|
2625
2648
|
createDefaultShader() {
|
|
2626
|
-
const t =
|
|
2649
|
+
const t = mt, e = ft;
|
|
2627
2650
|
return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
|
|
2628
2651
|
}
|
|
2629
2652
|
enter(t) {
|
|
@@ -2632,32 +2655,46 @@ class re extends it {
|
|
|
2632
2655
|
createShader(t, e) {
|
|
2633
2656
|
const r = super.createShader(t, e);
|
|
2634
2657
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
2635
|
-
{ name: "aPosition", size: 2, stride:
|
|
2636
|
-
{ name: "aScale", size: 2, stride:
|
|
2637
|
-
{ name: "aRotation", size: 1, stride:
|
|
2638
|
-
{ name: "aUVRect", size: 4, stride:
|
|
2639
|
-
{ name: "aColor", size: 4, type:
|
|
2640
|
-
{ name: "aOrigin", size: 2, stride:
|
|
2658
|
+
{ name: "aPosition", size: 2, stride: V, offset: 0, divisor: 1 },
|
|
2659
|
+
{ name: "aScale", size: 2, stride: V, offset: 8, divisor: 1 },
|
|
2660
|
+
{ name: "aRotation", size: 1, stride: V, offset: 16, divisor: 1 },
|
|
2661
|
+
{ name: "aUVRect", size: 4, stride: V, offset: 20, divisor: 1 },
|
|
2662
|
+
{ name: "aColor", size: 4, type: st, normalized: !0, stride: V, offset: 36, divisor: 1 },
|
|
2663
|
+
{ name: "aOrigin", size: 2, stride: V, offset: 40, divisor: 1 }
|
|
2641
2664
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
2642
2665
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2643
2666
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2644
2667
|
}
|
|
2645
|
-
drawParticles(t, e, r, i,
|
|
2668
|
+
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, x = !1, g = !1, v = 0.5, T = 0.5, A, R = !1, S) {
|
|
2646
2669
|
if (!t.glTexture || a <= 0) return;
|
|
2647
|
-
let
|
|
2648
|
-
const
|
|
2649
|
-
|
|
2670
|
+
let P = 0;
|
|
2671
|
+
const H = typeof o == "number", X = typeof h == "number", B = typeof i == "number", N = typeof s == "number", b = !N && typeof s[0] == "number";
|
|
2672
|
+
let _ = t.rawWidth * (f ? -1 : 1);
|
|
2673
|
+
H && (_ *= o);
|
|
2674
|
+
let W = t.rawHeight * (x ? -1 : 1);
|
|
2675
|
+
X && (W *= h);
|
|
2676
|
+
let D = g ? Math.PI / 2 : 0;
|
|
2677
|
+
for (B && (D += i); P < a; ) {
|
|
2650
2678
|
this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2651
|
-
const
|
|
2652
|
-
let
|
|
2653
|
-
|
|
2654
|
-
const
|
|
2655
|
-
for (let
|
|
2656
|
-
const
|
|
2657
|
-
|
|
2679
|
+
const k = a - P, I = this.instanceBuffer;
|
|
2680
|
+
let M = I.usedElemNum;
|
|
2681
|
+
I.resize(k * xt);
|
|
2682
|
+
const L = I.float32, z = I.uint32;
|
|
2683
|
+
for (let y = 0; y < k; y++) {
|
|
2684
|
+
const w = R ? a - 1 - P - y : P + y;
|
|
2685
|
+
if (L[M] = e[w], L[M + 1] = r[w], L[M + 2] = H ? _ : _ * o[w], L[M + 3] = X ? W : W * h[w], L[M + 4] = B ? D : i[w] + D, L[M + 5] = c, L[M + 6] = u, L[M + 7] = l, L[M + 8] = d, N)
|
|
2686
|
+
z[M + 9] = 4294967295;
|
|
2687
|
+
else if (b)
|
|
2688
|
+
z[M + 9] = s[w];
|
|
2689
|
+
else {
|
|
2690
|
+
const ht = s[w];
|
|
2691
|
+
z[M + 9] = A ? ht.premultipliedUint32 : ht.uint32;
|
|
2692
|
+
}
|
|
2693
|
+
L[M + 10] = v, L[M + 11] = T, M += xt;
|
|
2658
2694
|
}
|
|
2659
|
-
|
|
2695
|
+
I.usedElemNum = M, I.makeDirty(), this.instanceCount += k, P += k;
|
|
2660
2696
|
}
|
|
2697
|
+
this.customMatrix = S, this.flush();
|
|
2661
2698
|
}
|
|
2662
2699
|
render() {
|
|
2663
2700
|
if (this.instanceCount === 0) return;
|
|
@@ -2666,11 +2703,11 @@ class re extends it {
|
|
|
2666
2703
|
this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
|
|
2667
2704
|
const e = this.currentShader;
|
|
2668
2705
|
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
|
|
2669
|
-
const r = this.rapid.matrixStack,
|
|
2670
|
-
this.currentShader.setUniform("u_projection", a),
|
|
2706
|
+
const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = Vt(this.rapid.projection, s);
|
|
2707
|
+
this.currentShader.setUniform("u_projection", a), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
|
|
2671
2708
|
}
|
|
2672
2709
|
}
|
|
2673
|
-
var
|
|
2710
|
+
var se = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(se || {}), ne = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(ne || {}), nt = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(nt || {}), ae = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(ae || {});
|
|
2674
2711
|
class ce {
|
|
2675
2712
|
/** The active WebGL context. */
|
|
2676
2713
|
gl;
|
|
@@ -2683,7 +2720,7 @@ class ce {
|
|
|
2683
2720
|
/** The current device pixel ratio. */
|
|
2684
2721
|
dpr;
|
|
2685
2722
|
/** Background clear color [r, g, b, a], values range from 0 to 255. */
|
|
2686
|
-
backgroundColor =
|
|
2723
|
+
backgroundColor = m.Black;
|
|
2687
2724
|
/** Logical width in CSS pixels, used for coordinate system and projection matrix. */
|
|
2688
2725
|
logicWidth = 0;
|
|
2689
2726
|
/** Logical height in CSS pixels, used for coordinate system and projection matrix. */
|
|
@@ -2697,7 +2734,7 @@ class ce {
|
|
|
2697
2734
|
/** Maximum number of texture units supported by the device. */
|
|
2698
2735
|
maxTextureUnits = 0;
|
|
2699
2736
|
/** Matrix stack for hierarchical transformations. */
|
|
2700
|
-
matrixStack = new
|
|
2737
|
+
matrixStack = new At(this);
|
|
2701
2738
|
/** Direct access to the underlying matrix store. */
|
|
2702
2739
|
matrix;
|
|
2703
2740
|
/** Region dedicated to fast sprite rendering. */
|
|
@@ -2722,7 +2759,7 @@ class ce {
|
|
|
2722
2759
|
scaleMode;
|
|
2723
2760
|
/** Internal ping-pong RenderTextures for multi-filter chains. */
|
|
2724
2761
|
_filterRT = [null, null];
|
|
2725
|
-
_filterInput = new
|
|
2762
|
+
_filterInput = new F();
|
|
2726
2763
|
get height() {
|
|
2727
2764
|
return this.logicHeight;
|
|
2728
2765
|
}
|
|
@@ -2735,10 +2772,10 @@ class ce {
|
|
|
2735
2772
|
*/
|
|
2736
2773
|
constructor(t) {
|
|
2737
2774
|
this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? 1, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
|
|
2738
|
-
const e =
|
|
2739
|
-
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new
|
|
2775
|
+
const e = _t(this.canvas, this.antialias, this.premultipliedAlpha);
|
|
2776
|
+
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new at(this), this.graphicRegion = new Ht(this), this.atlasSpriteRegion = new re(this), this.particleRegion = new ie(this);
|
|
2740
2777
|
const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
|
|
2741
|
-
this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new
|
|
2778
|
+
this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new St(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
|
|
2742
2779
|
}
|
|
2743
2780
|
setTextureFilter(t) {
|
|
2744
2781
|
this.textureFilter = t;
|
|
@@ -2747,7 +2784,7 @@ class ce {
|
|
|
2747
2784
|
this.antialias = t;
|
|
2748
2785
|
}
|
|
2749
2786
|
getColorUint32(t) {
|
|
2750
|
-
return t
|
|
2787
|
+
return $t(this.premultipliedAlpha, t);
|
|
2751
2788
|
}
|
|
2752
2789
|
/**
|
|
2753
2790
|
* Enters a specific rendering region, flushing the previous one if necessary.
|
|
@@ -2758,22 +2795,22 @@ class ce {
|
|
|
2758
2795
|
this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
|
|
2759
2796
|
}
|
|
2760
2797
|
drawParticles(t) {
|
|
2761
|
-
|
|
2798
|
+
Qt(this, t);
|
|
2762
2799
|
}
|
|
2763
2800
|
drawSprite(t) {
|
|
2764
|
-
|
|
2801
|
+
qt(this, t);
|
|
2765
2802
|
}
|
|
2766
2803
|
drawLine(t) {
|
|
2767
2804
|
Zt(this, t);
|
|
2768
2805
|
}
|
|
2769
2806
|
drawGraphic(t) {
|
|
2770
|
-
|
|
2807
|
+
Rt(this, t);
|
|
2771
2808
|
}
|
|
2772
2809
|
drawRect(t) {
|
|
2773
|
-
|
|
2810
|
+
te(this, t);
|
|
2774
2811
|
}
|
|
2775
2812
|
drawCircle(t) {
|
|
2776
|
-
|
|
2813
|
+
ee(this, t);
|
|
2777
2814
|
}
|
|
2778
2815
|
/**
|
|
2779
2816
|
* Starts rendering arbitrary graphics geometries.
|
|
@@ -2797,7 +2834,7 @@ class ce {
|
|
|
2797
2834
|
* @param texture The texture to be used as a mask.
|
|
2798
2835
|
*/
|
|
2799
2836
|
drawMaskImage(t) {
|
|
2800
|
-
|
|
2837
|
+
Jt(this, t);
|
|
2801
2838
|
}
|
|
2802
2839
|
/**
|
|
2803
2840
|
* Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
|
|
@@ -2816,10 +2853,10 @@ class ce {
|
|
|
2816
2853
|
* @param segments The number of segments (polygons) used to approximate the circle.
|
|
2817
2854
|
*/
|
|
2818
2855
|
addCircleVertex(t, e, r = 32) {
|
|
2819
|
-
const i = Math.PI * 2 / r,
|
|
2856
|
+
const i = Math.PI * 2 / r, s = this.getColorUint32(e);
|
|
2820
2857
|
for (let a = 0; a < r; a++) {
|
|
2821
|
-
const
|
|
2822
|
-
this.addGraphicVertex(h,
|
|
2858
|
+
const o = i * a, h = Math.cos(o) * t, c = Math.sin(o) * t, u = 0.5 + Math.cos(o) * 0.5, l = 0.5 + Math.sin(o) * 0.5;
|
|
2859
|
+
this.addGraphicVertex(h, c, u, l, s);
|
|
2823
2860
|
}
|
|
2824
2861
|
}
|
|
2825
2862
|
/**
|
|
@@ -2830,8 +2867,8 @@ class ce {
|
|
|
2830
2867
|
* @param v The V texture coordinate (0 to 1).
|
|
2831
2868
|
* @param color The vertex color as a 32-bit unsigned integer.
|
|
2832
2869
|
*/
|
|
2833
|
-
addGraphicVertex(t, e, r = 0, i = 0,
|
|
2834
|
-
this.graphicRegion.addVertex(t, e, r, i,
|
|
2870
|
+
addGraphicVertex(t, e, r = 0, i = 0, s = 4294967295) {
|
|
2871
|
+
this.graphicRegion.addVertex(t, e, r, i, s);
|
|
2835
2872
|
}
|
|
2836
2873
|
/**
|
|
2837
2874
|
* Ends the current graphics geometry definition, readying it for rendering.
|
|
@@ -2848,8 +2885,8 @@ class ce {
|
|
|
2848
2885
|
*/
|
|
2849
2886
|
resize(t, e, r, i) {
|
|
2850
2887
|
this.flush();
|
|
2851
|
-
const
|
|
2852
|
-
switch (r !== void 0 && (this.canvas.style.width =
|
|
2888
|
+
const s = r ?? this.canvas.clientWidth ?? this.canvas.width, a = i ?? this.canvas.clientHeight ?? this.canvas.height;
|
|
2889
|
+
switch (r !== void 0 && (this.canvas.style.width = s + "px"), i !== void 0 && (this.canvas.style.height = a + "px"), this.physicsWidth = s * this.dpr, this.physicsHeight = a * this.dpr, this.logicWidth = t, this.logicHeight = e, this.scaleMode) {
|
|
2853
2890
|
case 1:
|
|
2854
2891
|
this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
|
|
2855
2892
|
break;
|
|
@@ -2879,8 +2916,8 @@ class ce {
|
|
|
2879
2916
|
* Populates an orthographic projection matrix in place.
|
|
2880
2917
|
* Avoids continuous Float32Array allocations for performance reasons.
|
|
2881
2918
|
*/
|
|
2882
|
-
updateOrthMatrix(t, e, r, i,
|
|
2883
|
-
t[0] = 2 / (r - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (
|
|
2919
|
+
updateOrthMatrix(t, e, r, i, s) {
|
|
2920
|
+
t[0] = 2 / (r - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (s - i), t[6] = 0, t[7] = 0, t[8] = 0, t[9] = 0, t[10] = -1, t[11] = 0, t[12] = -(r + e) / (r - e), t[13] = -(s + i) / (s - i), t[14] = 0, t[15] = 1;
|
|
2884
2921
|
}
|
|
2885
2922
|
/**
|
|
2886
2923
|
* Flushes currently buffered rendering operations across all active regions.
|
|
@@ -2905,23 +2942,23 @@ class ce {
|
|
|
2905
2942
|
applyFilters(t, e) {
|
|
2906
2943
|
if (e.length === 0)
|
|
2907
2944
|
throw new Error("applyFilters: shaders array must not be empty.");
|
|
2908
|
-
const r = Math.max(...e.map((
|
|
2909
|
-
for (let
|
|
2910
|
-
this._filterRT[
|
|
2911
|
-
let
|
|
2945
|
+
const r = Math.max(...e.map((c) => c.padding)), i = r, s = t.rawWidth + r * 2, a = t.rawHeight + r * 2;
|
|
2946
|
+
for (let c = 0; c < 2; c++)
|
|
2947
|
+
this._filterRT[c] ? this._filterRT[c].resize(s, a) : this._filterRT[c] = this.texture.createRenderTexture({ width: s, height: a });
|
|
2948
|
+
let o = t.clone(this._filterInput), h = 0;
|
|
2912
2949
|
this.matrixStack.save(), this.matrixStack.identity();
|
|
2913
|
-
for (let
|
|
2950
|
+
for (let c = 0; c < e.length; c++) {
|
|
2914
2951
|
const u = this._filterRT[h % 2];
|
|
2915
2952
|
u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
|
|
2916
|
-
texture:
|
|
2917
|
-
shader: e[
|
|
2918
|
-
offsetX:
|
|
2953
|
+
texture: o,
|
|
2954
|
+
shader: e[c],
|
|
2955
|
+
offsetX: c == 0 ? i : 0,
|
|
2919
2956
|
// padding back
|
|
2920
|
-
offsetY:
|
|
2957
|
+
offsetY: c == 0 ? i : 0,
|
|
2921
2958
|
padding: r
|
|
2922
|
-
}), this.leaveRenderTexture(),
|
|
2959
|
+
}), this.leaveRenderTexture(), o = u, h++;
|
|
2923
2960
|
}
|
|
2924
|
-
return this.matrixStack.restore(),
|
|
2961
|
+
return this.matrixStack.restore(), o.offsetX = -i, o.offsetY = -i, o;
|
|
2925
2962
|
}
|
|
2926
2963
|
enterRenderTexture(t) {
|
|
2927
2964
|
this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, t.rawHeight, 0);
|
|
@@ -2933,7 +2970,7 @@ class ce {
|
|
|
2933
2970
|
* @param rt The render texture to clear.
|
|
2934
2971
|
* @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
|
|
2935
2972
|
*/
|
|
2936
|
-
clearRenderTexture(t = new
|
|
2973
|
+
clearRenderTexture(t = new m(0, 0, 0, 0)) {
|
|
2937
2974
|
this.flush();
|
|
2938
2975
|
const e = this.gl;
|
|
2939
2976
|
t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
|
|
@@ -2955,7 +2992,7 @@ class ce {
|
|
|
2955
2992
|
* rapid.drawSprite({ texture: mySprite });
|
|
2956
2993
|
* });
|
|
2957
2994
|
*/
|
|
2958
|
-
drawToRenderTexture(t, e, r = new
|
|
2995
|
+
drawToRenderTexture(t, e, r = new m(0, 0, 0, 0)) {
|
|
2959
2996
|
this.enterRenderTexture(t);
|
|
2960
2997
|
try {
|
|
2961
2998
|
r !== null && this.clearRenderTexture(r), e();
|
|
@@ -3033,10 +3070,10 @@ class ce {
|
|
|
3033
3070
|
* rapid.drawSprite({ texture: myTexture });
|
|
3034
3071
|
* });
|
|
3035
3072
|
*/
|
|
3036
|
-
withScissor(t, e, r, i,
|
|
3073
|
+
withScissor(t, e, r, i, s) {
|
|
3037
3074
|
this.startScissor(t, e, r, i);
|
|
3038
3075
|
try {
|
|
3039
|
-
|
|
3076
|
+
s();
|
|
3040
3077
|
} finally {
|
|
3041
3078
|
this.endScissor();
|
|
3042
3079
|
}
|
|
@@ -3144,8 +3181,8 @@ class ce {
|
|
|
3144
3181
|
*/
|
|
3145
3182
|
startScissor(t, e, r, i) {
|
|
3146
3183
|
this.flush();
|
|
3147
|
-
const
|
|
3148
|
-
|
|
3184
|
+
const s = this.gl, a = this.physicsWidth / this.logicWidth, o = this.physicsHeight / this.logicHeight, h = Math.round(t * a), c = Math.round(this.physicsHeight - (e + i) * o), u = Math.round(r * a), l = Math.round(i * o);
|
|
3185
|
+
s.enable(s.SCISSOR_TEST), s.scissor(h, c, u, l);
|
|
3149
3186
|
}
|
|
3150
3187
|
/**
|
|
3151
3188
|
* Disables scissor clipping, restoring full-canvas rendering.
|
|
@@ -3159,13 +3196,13 @@ class ce {
|
|
|
3159
3196
|
this.matrix.invert(e);
|
|
3160
3197
|
}
|
|
3161
3198
|
logicToPhysics(t) {
|
|
3162
|
-
return t.multiply(new
|
|
3199
|
+
return t.multiply(new p(
|
|
3163
3200
|
this.physicsWidth / this.logicWidth,
|
|
3164
3201
|
this.physicsHeight / this.logicHeight
|
|
3165
3202
|
));
|
|
3166
3203
|
}
|
|
3167
3204
|
physicsToLogic(t) {
|
|
3168
|
-
return t.multiply(new
|
|
3205
|
+
return t.multiply(new p(
|
|
3169
3206
|
this.logicWidth / this.physicsWidth,
|
|
3170
3207
|
this.logicHeight / this.physicsHeight
|
|
3171
3208
|
));
|
|
@@ -3193,10 +3230,10 @@ class ce {
|
|
|
3193
3230
|
return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
|
|
3194
3231
|
}
|
|
3195
3232
|
}
|
|
3196
|
-
function
|
|
3197
|
-
return !(
|
|
3233
|
+
function he(n) {
|
|
3234
|
+
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof m);
|
|
3198
3235
|
}
|
|
3199
|
-
class
|
|
3236
|
+
class O {
|
|
3200
3237
|
/** Random float in [min, max). */
|
|
3201
3238
|
static float(t, e) {
|
|
3202
3239
|
return Math.random() * (e - t) + t;
|
|
@@ -3211,20 +3248,20 @@ class C {
|
|
|
3211
3248
|
}
|
|
3212
3249
|
/** Random Vec2 with components in the supplied per-axis ranges. */
|
|
3213
3250
|
static vector(t, e, r, i) {
|
|
3214
|
-
return new
|
|
3251
|
+
return new p(O.float(t, e), O.float(r, i));
|
|
3215
3252
|
}
|
|
3216
3253
|
/** Random Color with each component interpolated between minColor and maxColor. */
|
|
3217
3254
|
static randomColor(t, e) {
|
|
3218
|
-
return new
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3255
|
+
return new m(
|
|
3256
|
+
O.float(t.r, e.r),
|
|
3257
|
+
O.float(t.g, e.g),
|
|
3258
|
+
O.float(t.b, e.b),
|
|
3259
|
+
O.float(t.a, e.a)
|
|
3223
3260
|
);
|
|
3224
3261
|
}
|
|
3225
3262
|
/** Pick a random element from an array with uniform probability. */
|
|
3226
3263
|
static pick(t) {
|
|
3227
|
-
return t[
|
|
3264
|
+
return t[O.int(0, t.length - 1)];
|
|
3228
3265
|
}
|
|
3229
3266
|
/**
|
|
3230
3267
|
* Pick a random element using weighted probability.
|
|
@@ -3235,8 +3272,8 @@ class C {
|
|
|
3235
3272
|
let e = 0;
|
|
3236
3273
|
for (const [, i] of t) e += i;
|
|
3237
3274
|
let r = Math.random() * e;
|
|
3238
|
-
for (const [i,
|
|
3239
|
-
if (r -=
|
|
3275
|
+
for (const [i, s] of t)
|
|
3276
|
+
if (r -= s, r <= 0) return i;
|
|
3240
3277
|
return t[t.length - 1][0];
|
|
3241
3278
|
}
|
|
3242
3279
|
/**
|
|
@@ -3250,125 +3287,115 @@ class C {
|
|
|
3250
3287
|
if (Array.isArray(t)) {
|
|
3251
3288
|
const [r, i] = t;
|
|
3252
3289
|
if (typeof r == "number")
|
|
3253
|
-
return
|
|
3254
|
-
if (r instanceof m)
|
|
3255
|
-
return C.vector(r.x, i.x, r.y, i.y);
|
|
3290
|
+
return O.float(r, i);
|
|
3256
3291
|
if (r instanceof p)
|
|
3257
|
-
return
|
|
3292
|
+
return O.vector(r.x, i.x, r.y, i.y);
|
|
3293
|
+
if (r instanceof m)
|
|
3294
|
+
return O.randomColor(r, i);
|
|
3258
3295
|
}
|
|
3259
3296
|
return typeof t == "number" ? t : t.clone();
|
|
3260
3297
|
}
|
|
3261
3298
|
}
|
|
3262
|
-
var
|
|
3263
|
-
const
|
|
3264
|
-
class
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
color: this.processAttribute(e.animation.color, p.White.clone()),
|
|
3278
|
-
velocity: this.processAttribute(e.animation.velocity, m.ZERO)
|
|
3279
|
-
}, this.position = m.ZERO, this.initializePosition();
|
|
3280
|
-
}
|
|
3281
|
-
processAttribute(t, e) {
|
|
3282
|
-
if (t == null)
|
|
3283
|
-
return { value: e };
|
|
3284
|
-
if (ae(t)) {
|
|
3285
|
-
const r = t, i = C.scalarOrRange(r.start, e), n = r.end === void 0 ? i : C.scalarOrRange(r.end, e);
|
|
3286
|
-
return {
|
|
3287
|
-
delta: r.delta ?? this.getDelta(i, n, this.maxLife),
|
|
3288
|
-
value: i,
|
|
3289
|
-
damping: r.damping
|
|
3290
|
-
};
|
|
3291
|
-
} else
|
|
3292
|
-
return this.processAttribute({ start: t }, e);
|
|
3293
|
-
}
|
|
3294
|
-
updateNumberAttribute(t, e) {
|
|
3295
|
-
t.damping !== void 0 && (t.value *= Math.pow(t.damping, e)), t.delta !== void 0 && (t.value += t.delta * e);
|
|
3296
|
-
}
|
|
3297
|
-
updateVec2Attribute(t, e) {
|
|
3298
|
-
t.damping !== void 0 && (t.value = t.value.multiply(Math.pow(t.damping, e))), t.delta !== void 0 && (t.value = t.value.add(t.delta.multiply(e)));
|
|
3299
|
-
}
|
|
3300
|
-
updateColorAttribute(t, e) {
|
|
3301
|
-
t.damping !== void 0 && (t.value = t.value.multiply(Math.pow(t.damping, e))), t.delta !== void 0 && (t.value = t.value.add(t.delta.multiply(e))), t.value.clamp();
|
|
3302
|
-
}
|
|
3303
|
-
updateAttributes(t) {
|
|
3304
|
-
const e = this.datas;
|
|
3305
|
-
this.updateNumberAttribute(e.speed, t), this.updateNumberAttribute(e.rotation, t), this.updateNumberAttribute(e.scale, t), this.updateColorAttribute(e.color, t), this.updateVec2Attribute(e.velocity, t);
|
|
3306
|
-
const i = m.fromAngle(e.rotation.value).multiply(e.speed.value * t);
|
|
3307
|
-
this.position = this.position.add(i).add(e.velocity.value.multiply(t));
|
|
3308
|
-
}
|
|
3309
|
-
getDelta(t, e, r) {
|
|
3310
|
-
return typeof t == "number" && typeof e == "number" ? (e - t) / r : t instanceof m && e instanceof m || t instanceof p && e instanceof p ? e.subtract(t).divide(r) : t;
|
|
3311
|
-
}
|
|
3312
|
-
/**
|
|
3313
|
-
* Updates particle state.
|
|
3314
|
-
* @param deltaTime - Seconds elapsed since last frame
|
|
3315
|
-
* @returns `true` while the particle is alive, `false` when it should be removed
|
|
3316
|
-
*/
|
|
3317
|
-
update(t) {
|
|
3318
|
-
return this.life += t, this.life >= this.maxLife ? !1 : (this.updateAttributes(t), !0);
|
|
3319
|
-
}
|
|
3320
|
-
/**
|
|
3321
|
-
* Renders the particle using the Rapid engine's matrixStack + drawSprite.
|
|
3322
|
-
* The emitter is responsible for calling save/restore around a batch of particles.
|
|
3323
|
-
*/
|
|
3324
|
-
render() {
|
|
3325
|
-
const t = this.rapid.matrixStack, e = this.datas.scale.value, r = this.datas.rotation.value, i = this.datas.color.value;
|
|
3326
|
-
t.save(), t.translate(this.position.x, this.position.y), r !== 0 && t.rotate(r), e !== 1 && t.scale(e, e);
|
|
3327
|
-
const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
|
|
3328
|
-
(n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(this.rapid, { texture: this.texture, color: i }), t.restore();
|
|
3299
|
+
var oe = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(oe || {});
|
|
3300
|
+
const pt = 10, gt = 0, vt = !0;
|
|
3301
|
+
class K {
|
|
3302
|
+
components;
|
|
3303
|
+
constructor(t = 1) {
|
|
3304
|
+
if (!Number.isInteger(t) || t <= 0)
|
|
3305
|
+
throw new RangeError("ParticleAttributeStore size must be a positive integer");
|
|
3306
|
+
this.components = Array.from({ length: t }, () => ({
|
|
3307
|
+
value: new C(U.Float32),
|
|
3308
|
+
delta: new C(U.Float32),
|
|
3309
|
+
damping: new C(U.Float32)
|
|
3310
|
+
}));
|
|
3311
|
+
}
|
|
3312
|
+
getArrayBuffer() {
|
|
3313
|
+
return this.components.flatMap(({ value: t, delta: e, damping: r }) => [t, e, r]);
|
|
3329
3314
|
}
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3315
|
+
update(t) {
|
|
3316
|
+
for (const { value: e, delta: r, damping: i } of this.components)
|
|
3317
|
+
for (let s = 0; s < e.usedElemNum; s++)
|
|
3318
|
+
e.typedArray[s] *= Math.pow(i.get(s), t), e.typedArray[s] += r.get(s) * t;
|
|
3319
|
+
}
|
|
3320
|
+
get(t, e = 0) {
|
|
3321
|
+
return this.components[e].value.get(t);
|
|
3322
|
+
}
|
|
3323
|
+
getComponent(t, e) {
|
|
3324
|
+
if (typeof t == "number")
|
|
3325
|
+
return t;
|
|
3326
|
+
if (t instanceof p)
|
|
3327
|
+
return e === 0 ? t.x : t.y;
|
|
3328
|
+
switch (e) {
|
|
3329
|
+
case 0:
|
|
3330
|
+
return t.r;
|
|
3331
|
+
case 1:
|
|
3332
|
+
return t.g;
|
|
3333
|
+
case 2:
|
|
3334
|
+
return t.b;
|
|
3335
|
+
case 3:
|
|
3336
|
+
return t.a;
|
|
3344
3337
|
default:
|
|
3345
|
-
|
|
3346
|
-
|
|
3338
|
+
return 0;
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
resolveComponent(t, e, r) {
|
|
3342
|
+
return t === void 0 ? r : Array.isArray(t) ? O.float(
|
|
3343
|
+
this.getComponent(t[0], e),
|
|
3344
|
+
this.getComponent(t[1], e)
|
|
3345
|
+
) : this.getComponent(t, e);
|
|
3346
|
+
}
|
|
3347
|
+
create(t, e, r = 1) {
|
|
3348
|
+
const i = he(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
|
|
3349
|
+
let o = 0;
|
|
3350
|
+
for (let h = 0; h < this.components.length; h++) {
|
|
3351
|
+
const { value: c, delta: u, damping: l } = this.components[h], d = this.getComponent(e, h), f = s === void 0 ? this.resolveComponent(i?.start, h, d) : this.getComponent(s, h), x = i?.end === void 0 ? f : this.resolveComponent(i.end, h, d);
|
|
3352
|
+
c.push(f), u.push(i?.delta === void 0 ? (x - f) / a : this.getComponent(i.delta, h)), l.push(i?.damping ?? 1), h === 0 && (o = f);
|
|
3347
3353
|
}
|
|
3348
|
-
|
|
3354
|
+
return o;
|
|
3349
3355
|
}
|
|
3350
3356
|
}
|
|
3351
3357
|
class wt {
|
|
3352
|
-
particles = [];
|
|
3353
3358
|
options;
|
|
3354
3359
|
emitting = !1;
|
|
3355
3360
|
emitTimer = 0;
|
|
3356
|
-
emitRate =
|
|
3357
|
-
emitTime =
|
|
3361
|
+
emitRate = pt;
|
|
3362
|
+
emitTime = gt;
|
|
3358
3363
|
emitTimeCounter = 0;
|
|
3359
3364
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3360
|
-
localSpace =
|
|
3361
|
-
/** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
|
|
3362
|
-
position = m.ZERO;
|
|
3365
|
+
localSpace = vt;
|
|
3363
3366
|
rapid;
|
|
3364
|
-
|
|
3367
|
+
x = new C(U.Float32);
|
|
3368
|
+
y = new C(U.Float32);
|
|
3369
|
+
scaleX = new C(U.Float32);
|
|
3370
|
+
scaleY = new C(U.Float32);
|
|
3371
|
+
rotation = new C(U.Float32);
|
|
3372
|
+
color = new C(U.Uint32);
|
|
3373
|
+
animations = {
|
|
3374
|
+
speed: new K(),
|
|
3375
|
+
rotation: new K(),
|
|
3376
|
+
scale: new K(),
|
|
3377
|
+
color: new K(4),
|
|
3378
|
+
velocity: new K(2)
|
|
3379
|
+
};
|
|
3380
|
+
count = 0;
|
|
3365
3381
|
/**
|
|
3366
3382
|
* Creates a new particle emitter.
|
|
3367
3383
|
* @param rapid - The Rapid renderer instance
|
|
3368
3384
|
* @param options - Emitter configuration options
|
|
3369
3385
|
*/
|
|
3370
3386
|
constructor(t, e) {
|
|
3371
|
-
this.rapid = t, this.options = e, this.emitRate = e.emitRate
|
|
3387
|
+
this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? pt, this.emitTime = e.emitTime ?? gt, this.localSpace = e.localSpace ?? vt;
|
|
3388
|
+
}
|
|
3389
|
+
getAllArrayBuffer() {
|
|
3390
|
+
return [
|
|
3391
|
+
this.x,
|
|
3392
|
+
this.y,
|
|
3393
|
+
this.scaleX,
|
|
3394
|
+
this.scaleY,
|
|
3395
|
+
this.rotation,
|
|
3396
|
+
this.color,
|
|
3397
|
+
...Object.values(this.animations).flatMap((t) => t.getArrayBuffer())
|
|
3398
|
+
];
|
|
3372
3399
|
}
|
|
3373
3400
|
/** Replaces the emitter's texture at runtime. */
|
|
3374
3401
|
setTexture(t) {
|
|
@@ -3399,16 +3426,48 @@ class wt {
|
|
|
3399
3426
|
}
|
|
3400
3427
|
/** Removes all particles and resets timers. */
|
|
3401
3428
|
clear() {
|
|
3402
|
-
|
|
3429
|
+
for (const t of this.getAllArrayBuffer())
|
|
3430
|
+
t.clear();
|
|
3431
|
+
this.count = 0, this.emitTimeCounter = 0;
|
|
3403
3432
|
}
|
|
3404
3433
|
/**
|
|
3405
3434
|
* Spawns `count` particles immediately.
|
|
3406
3435
|
* Respects `maxParticles` if set.
|
|
3407
3436
|
*/
|
|
3408
3437
|
emit(t) {
|
|
3409
|
-
const e = this.options.maxParticles ?? 1 / 0, r = Math.min(t, e - this.
|
|
3438
|
+
const e = this.options.maxParticles ?? 1 / 0, r = Math.min(t, e - this.count);
|
|
3410
3439
|
for (let i = 0; i < r; i++)
|
|
3411
|
-
this.
|
|
3440
|
+
this.createParticle();
|
|
3441
|
+
}
|
|
3442
|
+
createParticle() {
|
|
3443
|
+
const t = O.scalarOrRange(this.options.life, 1);
|
|
3444
|
+
let e = 0, r = 0;
|
|
3445
|
+
switch (this.options.emitShape) {
|
|
3446
|
+
case "circle": {
|
|
3447
|
+
const c = Math.random() * Math.PI * 2, u = (this.options.emitRadius ?? 0) * Math.sqrt(Math.random());
|
|
3448
|
+
e = Math.cos(c) * u, r = Math.sin(c) * u;
|
|
3449
|
+
break;
|
|
3450
|
+
}
|
|
3451
|
+
case "rect": {
|
|
3452
|
+
e = (Math.random() - 0.5) * (this.options.emitRect?.width ?? 0), r = (Math.random() - 0.5) * (this.options.emitRect?.height ?? 0);
|
|
3453
|
+
break;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
const i = this.rapid.matrixStack;
|
|
3457
|
+
if (this.localSpace)
|
|
3458
|
+
this.x.push(e), this.y.push(r);
|
|
3459
|
+
else {
|
|
3460
|
+
const { x: c, y: u } = i.localToWorld(e, r);
|
|
3461
|
+
this.x.push(c), this.y.push(u);
|
|
3462
|
+
}
|
|
3463
|
+
const s = this.options.animation, a = this.animations, o = a.scale.create(s.scale, 1, t), h = a.rotation.create(s.rotation, 0, t);
|
|
3464
|
+
a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, p.ZERO, t), a.color.create(s.color, m.White, t), this.rotation.push(h), this.scaleX.push(o), this.scaleY.push(o), this.color.pushUint32(m.packColor(
|
|
3465
|
+
a.color.get(this.count, 0),
|
|
3466
|
+
a.color.get(this.count, 1),
|
|
3467
|
+
a.color.get(this.count, 2),
|
|
3468
|
+
a.color.get(this.count, 3),
|
|
3469
|
+
this.rapid.premultipliedAlpha
|
|
3470
|
+
)), this.count += 1;
|
|
3412
3471
|
}
|
|
3413
3472
|
/**
|
|
3414
3473
|
* Updates the emitter and all live particles.
|
|
@@ -3418,35 +3477,57 @@ class wt {
|
|
|
3418
3477
|
if (this.emitting && this.emitRate > 0)
|
|
3419
3478
|
if (this.emitTime > 0) {
|
|
3420
3479
|
if (this.emitTimeCounter += t, this.emitTimeCounter >= this.emitTime) {
|
|
3421
|
-
const
|
|
3422
|
-
this.emit(this.emitRate *
|
|
3480
|
+
const r = Math.floor(this.emitTimeCounter / this.emitTime);
|
|
3481
|
+
this.emit(this.emitRate * r), this.emitTimeCounter -= r * this.emitTime;
|
|
3423
3482
|
}
|
|
3424
3483
|
} else {
|
|
3425
3484
|
this.emitTimer += t;
|
|
3426
|
-
const
|
|
3427
|
-
|
|
3485
|
+
const r = Math.floor(this.emitTimer * this.emitRate);
|
|
3486
|
+
r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
|
|
3428
3487
|
}
|
|
3429
|
-
|
|
3430
|
-
|
|
3488
|
+
const e = this.updateParticle(t);
|
|
3489
|
+
this.count -= e.length, C.removeAtIndices(e, this.getAllArrayBuffer());
|
|
3490
|
+
}
|
|
3491
|
+
updateParticle(t) {
|
|
3492
|
+
const e = [], r = this.animations;
|
|
3493
|
+
Object.values(r).forEach((i) => i.update(t));
|
|
3494
|
+
for (let i = 0; i < this.count; i++) {
|
|
3495
|
+
const s = r.rotation.get(i), a = r.scale.get(i), o = r.speed.get(i);
|
|
3496
|
+
this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = m.packColor(
|
|
3497
|
+
r.color.get(i, 0),
|
|
3498
|
+
r.color.get(i, 1),
|
|
3499
|
+
r.color.get(i, 2),
|
|
3500
|
+
r.color.get(i, 3),
|
|
3501
|
+
this.rapid.premultipliedAlpha
|
|
3502
|
+
), this.x.typedArray[i] += (o * Math.cos(s) + r.velocity.get(i, 0)) * t, this.y.typedArray[i] += (o * Math.sin(s) + r.velocity.get(i, 1)) * t;
|
|
3503
|
+
}
|
|
3504
|
+
return e;
|
|
3431
3505
|
}
|
|
3432
3506
|
/**
|
|
3433
3507
|
* Renders all live particles.
|
|
3434
3508
|
* In local-space mode the emitter's own transform is applied around the batch.
|
|
3435
3509
|
*/
|
|
3436
3510
|
render() {
|
|
3437
|
-
const t = this.rapid.
|
|
3438
|
-
this.
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3511
|
+
const t = this.options, e = this.localSpace ? void 0 : this.rapid.matrix.alloc();
|
|
3512
|
+
this.rapid.drawParticles({
|
|
3513
|
+
texture: t.texture,
|
|
3514
|
+
shader: t.shader,
|
|
3515
|
+
x: this.x.typedArray,
|
|
3516
|
+
y: this.y.typedArray,
|
|
3517
|
+
scaleX: this.scaleX.typedArray,
|
|
3518
|
+
scaleY: this.scaleY.typedArray,
|
|
3519
|
+
rotation: this.rotation.typedArray,
|
|
3520
|
+
color: this.color.typedArray,
|
|
3521
|
+
count: this.count,
|
|
3522
|
+
reverseOrder: !0,
|
|
3523
|
+
originX: t.origin?.x ?? 0.5,
|
|
3524
|
+
originY: t.origin?.y ?? 0.5,
|
|
3525
|
+
customMatrix: e
|
|
3526
|
+
});
|
|
3446
3527
|
}
|
|
3447
3528
|
/** Returns `true` if the emitter is running or still has live particles. */
|
|
3448
3529
|
isActive() {
|
|
3449
|
-
return this.emitting || this.
|
|
3530
|
+
return this.emitting || this.count > 0;
|
|
3450
3531
|
}
|
|
3451
3532
|
/**
|
|
3452
3533
|
* Convenience: emit `emitRate` particles in one shot (fire-and-forget burst).
|
|
@@ -3456,42 +3537,41 @@ class wt {
|
|
|
3456
3537
|
}
|
|
3457
3538
|
}
|
|
3458
3539
|
export {
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3540
|
+
U as ArrayType,
|
|
3541
|
+
Y as BaseTexture,
|
|
3542
|
+
ne as BlendMode,
|
|
3543
|
+
ae as CanvasScaleMode,
|
|
3544
|
+
m as Color,
|
|
3545
|
+
ct as CustomGlShader,
|
|
3546
|
+
C as DynamicArrayBuffer,
|
|
3466
3547
|
Tt as GLShader,
|
|
3467
3548
|
Ht as GraphicRegion,
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3549
|
+
Xt as LineTextureMode,
|
|
3550
|
+
se as MaskType,
|
|
3551
|
+
At as MatrixStack,
|
|
3471
3552
|
Mt as MatrixStore,
|
|
3472
|
-
oe as Particle,
|
|
3473
3553
|
wt as ParticleEmitter,
|
|
3474
|
-
|
|
3475
|
-
|
|
3554
|
+
oe as ParticleShape,
|
|
3555
|
+
Wt as QUAD_VERTICES,
|
|
3476
3556
|
ce as Rapid,
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3557
|
+
Et as Region,
|
|
3558
|
+
bt as RenderTexture,
|
|
3559
|
+
at as SpriteRegion,
|
|
3560
|
+
Ct as TextTexture,
|
|
3561
|
+
F as Texture,
|
|
3562
|
+
nt as TextureFilterMode,
|
|
3563
|
+
St as TextureManager,
|
|
3564
|
+
q as TextureWrapMode,
|
|
3565
|
+
p as Vec2,
|
|
3566
|
+
et as WebglBufferArray,
|
|
3487
3567
|
Vt as composeProjectionWithAffine,
|
|
3488
|
-
|
|
3489
|
-
|
|
3568
|
+
ee as drawCircle,
|
|
3569
|
+
Rt as drawGraphic,
|
|
3490
3570
|
Zt as drawLine,
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3571
|
+
Jt as drawMaskImage,
|
|
3572
|
+
Qt as drawParticles,
|
|
3573
|
+
te as drawRect,
|
|
3574
|
+
qt as drawSprite,
|
|
3575
|
+
$t as getColorUint32,
|
|
3576
|
+
Yt as multiplyMat4
|
|
3497
3577
|
};
|