rapid-render 1.0.5 → 1.0.6
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/dist/draw.d.ts +0 -17
- package/dist/rapid-render.js +283 -316
- package/dist/rapid-render.umd.cjs +11 -11
- package/dist/region/particleRegion.d.ts +0 -1
- package/dist/region/region.d.ts +1 -1
- package/dist/render.d.ts +1 -2
- package/package.json +1 -1
package/dist/rapid-render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
class
|
|
1
|
+
var O = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(O || {});
|
|
2
|
+
class B {
|
|
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. */
|
|
@@ -151,7 +151,7 @@ class k {
|
|
|
151
151
|
this.usedElemNum = 0;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
class
|
|
154
|
+
class Q extends B {
|
|
155
155
|
/** The actual WebGLBuffer object maintained by this instance. */
|
|
156
156
|
buffer;
|
|
157
157
|
/** The related WebGL rendering context. */
|
|
@@ -451,8 +451,8 @@ class m {
|
|
|
451
451
|
static Transparent = new m(0, 0, 0, 0);
|
|
452
452
|
static TRANSPARENT = new m(0, 0, 0, 0);
|
|
453
453
|
}
|
|
454
|
-
const
|
|
455
|
-
class
|
|
454
|
+
const v = 6;
|
|
455
|
+
class Mt {
|
|
456
456
|
/** Total number of matrices currently allocated in the store. */
|
|
457
457
|
matrixCount = 0;
|
|
458
458
|
/** The dynamic buffer used to hold matrix data. */
|
|
@@ -464,7 +464,7 @@ class St {
|
|
|
464
464
|
* @param capacity - The initial capacity of the matrix store (default is 10).
|
|
465
465
|
*/
|
|
466
466
|
constructor(t = 10) {
|
|
467
|
-
this.buffer = new
|
|
467
|
+
this.buffer = new B(O.Float32), this.buffer.resize(t * v), this.data = this.buffer.getArray();
|
|
468
468
|
}
|
|
469
469
|
/**
|
|
470
470
|
* Allocates a new matrix and initializes it to the identity matrix.
|
|
@@ -479,7 +479,7 @@ class St {
|
|
|
479
479
|
* @returns The index of the newly allocated matrix.
|
|
480
480
|
*/
|
|
481
481
|
allocDirty() {
|
|
482
|
-
return this.buffer.resize(
|
|
482
|
+
return this.buffer.resize(v) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += v, this.matrixCount++;
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
485
485
|
* Resets the store, clearing all allocated matrices.
|
|
@@ -492,7 +492,7 @@ class St {
|
|
|
492
492
|
* @param index - The index of the matrix to modify.
|
|
493
493
|
*/
|
|
494
494
|
identity(t) {
|
|
495
|
-
const e = t *
|
|
495
|
+
const e = t * v, i = this.data;
|
|
496
496
|
i[e] = 1, i[e + 1] = 0, i[e + 2] = 0, i[e + 3] = 1, i[e + 4] = 0, i[e + 5] = 0;
|
|
497
497
|
}
|
|
498
498
|
/**
|
|
@@ -502,7 +502,7 @@ class St {
|
|
|
502
502
|
* @param y - The y translation.
|
|
503
503
|
*/
|
|
504
504
|
translate(t, e, i) {
|
|
505
|
-
const r = t *
|
|
505
|
+
const r = t * v, n = this.data;
|
|
506
506
|
n[r + 4] = n[r] * e + n[r + 2] * i + n[r + 4], n[r + 5] = n[r + 1] * e + n[r + 3] * i + n[r + 5];
|
|
507
507
|
}
|
|
508
508
|
/**
|
|
@@ -512,7 +512,7 @@ class St {
|
|
|
512
512
|
* @param scaleY - The scale factor along the y-axis.
|
|
513
513
|
*/
|
|
514
514
|
scale(t, e, i) {
|
|
515
|
-
const r = t *
|
|
515
|
+
const r = t * v, n = this.data;
|
|
516
516
|
n[r] *= e, n[r + 1] *= e, n[r + 2] *= i, n[r + 3] *= i;
|
|
517
517
|
}
|
|
518
518
|
/**
|
|
@@ -521,7 +521,7 @@ class St {
|
|
|
521
521
|
* @param radians - The rotation angle in radians.
|
|
522
522
|
*/
|
|
523
523
|
rotate(t, e) {
|
|
524
|
-
const i = t *
|
|
524
|
+
const i = t * v, r = this.data, n = Math.cos(e), a = Math.sin(e), o = r[i], h = r[i + 1], c = r[i + 2], u = r[i + 3];
|
|
525
525
|
r[i] = o * n + c * a, r[i + 1] = h * n + u * a, r[i + 2] = o * -a + c * n, r[i + 3] = h * -a + u * n;
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
@@ -549,7 +549,7 @@ class St {
|
|
|
549
549
|
* @param src - The index of the source matrix.
|
|
550
550
|
*/
|
|
551
551
|
copy(t, e) {
|
|
552
|
-
const i = t *
|
|
552
|
+
const i = t * v, r = e * v, n = this.data;
|
|
553
553
|
n[i] = n[r], n[i + 1] = n[r + 1], n[i + 2] = n[r + 2], n[i + 3] = n[r + 3], n[i + 4] = n[r + 4], n[i + 5] = n[r + 5];
|
|
554
554
|
}
|
|
555
555
|
/**
|
|
@@ -567,15 +567,15 @@ class St {
|
|
|
567
567
|
* @param bIdx - The index of matrix B.
|
|
568
568
|
*/
|
|
569
569
|
multiplyOut(t, e, i) {
|
|
570
|
-
const r = t *
|
|
571
|
-
o[r] = h * x + u *
|
|
570
|
+
const r = t * v, n = e * v, a = i * v, o = this.data, h = o[n], c = o[n + 1], u = o[n + 2], f = o[n + 3], l = o[n + 4], p = o[n + 5], x = o[a], g = o[a + 1], T = o[a + 2], y = o[a + 3], w = o[a + 4], M = o[a + 5];
|
|
571
|
+
o[r] = h * x + u * g, o[r + 1] = c * x + f * g, o[r + 2] = h * T + u * y, o[r + 3] = c * T + f * y, o[r + 4] = h * w + u * M + l, o[r + 5] = c * w + f * M + p;
|
|
572
572
|
}
|
|
573
573
|
/**
|
|
574
574
|
* Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
|
|
575
575
|
* @param index - The index of the matrix to invert.
|
|
576
576
|
*/
|
|
577
577
|
invert(t) {
|
|
578
|
-
const e = t *
|
|
578
|
+
const e = t * v, i = this.data, r = i[e], n = i[e + 1], a = i[e + 2], o = i[e + 3], h = i[e + 4], c = i[e + 5];
|
|
579
579
|
let u = r * o - n * a;
|
|
580
580
|
if (!u) {
|
|
581
581
|
this.identity(t);
|
|
@@ -591,7 +591,7 @@ class St {
|
|
|
591
591
|
* @returns The transformed point {x, y}.
|
|
592
592
|
*/
|
|
593
593
|
transformPoint(t, e, i) {
|
|
594
|
-
const r = t *
|
|
594
|
+
const r = t * v, n = this.data;
|
|
595
595
|
return {
|
|
596
596
|
x: e * n[r] + i * n[r + 2] + n[r + 4],
|
|
597
597
|
y: e * n[r + 1] + i * n[r + 3] + n[r + 5]
|
|
@@ -609,7 +609,7 @@ class St {
|
|
|
609
609
|
const r = this.allocDirty();
|
|
610
610
|
this.copy(r, t), this.invert(r);
|
|
611
611
|
const n = this.transformPoint(r, e, i);
|
|
612
|
-
return this.matrixCount--, this.buffer.usedElemNum -=
|
|
612
|
+
return this.matrixCount--, this.buffer.usedElemNum -= v, n;
|
|
613
613
|
}
|
|
614
614
|
/**
|
|
615
615
|
* Transforms a point from local coordinates to world coordinates.
|
|
@@ -627,7 +627,7 @@ class St {
|
|
|
627
627
|
* @returns An object containing `x` and `y` global coordinates.
|
|
628
628
|
*/
|
|
629
629
|
getPosition(t) {
|
|
630
|
-
const e = t *
|
|
630
|
+
const e = t * v, i = this.data;
|
|
631
631
|
return { x: i[e + 4], y: i[e + 5] };
|
|
632
632
|
}
|
|
633
633
|
/**
|
|
@@ -636,7 +636,7 @@ class St {
|
|
|
636
636
|
* @returns An object containing `x` and `y` global scale factors.
|
|
637
637
|
*/
|
|
638
638
|
getScale(t) {
|
|
639
|
-
const e = t *
|
|
639
|
+
const e = t * v, i = this.data, r = Math.sqrt(i[e] * i[e] + i[e + 1] * i[e + 1]), n = Math.sqrt(i[e + 2] * i[e + 2] + i[e + 3] * i[e + 3]);
|
|
640
640
|
return { x: r, y: n };
|
|
641
641
|
}
|
|
642
642
|
/**
|
|
@@ -645,7 +645,7 @@ class St {
|
|
|
645
645
|
* @returns The global rotation in radians.
|
|
646
646
|
*/
|
|
647
647
|
getRotation(t) {
|
|
648
|
-
const e = t *
|
|
648
|
+
const e = t * v, i = this.data;
|
|
649
649
|
return Math.atan2(i[e + 1], i[e]);
|
|
650
650
|
}
|
|
651
651
|
/**
|
|
@@ -656,7 +656,7 @@ class St {
|
|
|
656
656
|
* @returns A CSS matrix string.
|
|
657
657
|
*/
|
|
658
658
|
toCSSMatrix(t, e = 1, i = 1) {
|
|
659
|
-
const r = t *
|
|
659
|
+
const r = t * v, n = this.data;
|
|
660
660
|
return `matrix(${n[r] * e}, ${n[r + 1] * i}, ${n[r + 2] * e}, ${n[r + 3] * i}, ${n[r + 4] * e}, ${n[r + 5] * i})`;
|
|
661
661
|
}
|
|
662
662
|
/**
|
|
@@ -667,8 +667,8 @@ class St {
|
|
|
667
667
|
* @returns A new Float32Array containing the 6 elements of the matrix.
|
|
668
668
|
*/
|
|
669
669
|
getMatrix(t) {
|
|
670
|
-
const e = t *
|
|
671
|
-
return this.data.slice(e, e +
|
|
670
|
+
const e = t * v;
|
|
671
|
+
return this.data.slice(e, e + v);
|
|
672
672
|
}
|
|
673
673
|
/**
|
|
674
674
|
* Retrieves a direct reference (view) to the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
|
|
@@ -678,8 +678,8 @@ class St {
|
|
|
678
678
|
* @returns A Float32Array view pointing directly to the matrix's data in memory.
|
|
679
679
|
*/
|
|
680
680
|
getMatrixRef(t) {
|
|
681
|
-
const e = t *
|
|
682
|
-
return this.data.subarray(e, e +
|
|
681
|
+
const e = t * v;
|
|
682
|
+
return this.data.subarray(e, e + v);
|
|
683
683
|
}
|
|
684
684
|
/**
|
|
685
685
|
* Overwrites the matrix at the specified index with the provided 6 elements [a, b, c, d, tx, ty].
|
|
@@ -688,29 +688,29 @@ class St {
|
|
|
688
688
|
* @param f - An array (Float32Array or standard number array) containing the 6 new elements.
|
|
689
689
|
*/
|
|
690
690
|
setMatrix(t, e) {
|
|
691
|
-
const i = t *
|
|
691
|
+
const i = t * v, r = this.data;
|
|
692
692
|
r[i] = e[0], r[i + 1] = e[1], r[i + 2] = e[2], r[i + 3] = e[3], r[i + 4] = e[4], r[i + 5] = e[5];
|
|
693
693
|
}
|
|
694
694
|
multiplyAffineInPlace(t, e, i, r, n, a, o) {
|
|
695
|
-
const h = t * 6, c = this.data, u = c[h], f = c[h + 1], l = c[h + 2], p = c[h + 3], x = c[h + 4],
|
|
696
|
-
c[h] = u * e + l * i, c[h + 1] = f * e + p * i, c[h + 2] = u * r + l * n, c[h + 3] = f * r + p * n, c[h + 4] = u * a + l * o + x, c[h + 5] = f * a + p * o +
|
|
695
|
+
const h = t * 6, c = this.data, u = c[h], f = c[h + 1], l = c[h + 2], p = c[h + 3], x = c[h + 4], g = c[h + 5];
|
|
696
|
+
c[h] = u * e + l * i, c[h + 1] = f * e + p * i, c[h + 2] = u * r + l * n, c[h + 3] = f * r + p * n, c[h + 4] = u * a + l * o + x, c[h + 5] = f * a + p * o + g;
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
|
-
class
|
|
699
|
+
class St {
|
|
700
700
|
/** The underlying store for matrices. */
|
|
701
|
-
matrix = new
|
|
701
|
+
matrix = new Mt();
|
|
702
702
|
/** The current step or depth in the transformation hierarchy. */
|
|
703
703
|
step = 0;
|
|
704
704
|
/** Internal stack maintaining structural information. */
|
|
705
|
-
stack = new
|
|
705
|
+
stack = new B(O.Uint32);
|
|
706
706
|
/** Records the world matrices generated at each step. */
|
|
707
|
-
stepWorldM = new
|
|
707
|
+
stepWorldM = new B(O.Uint32);
|
|
708
708
|
/** Records actions (push/pop) taken during the traversal. */
|
|
709
|
-
stepAction = new
|
|
709
|
+
stepAction = new B(O.Uint32);
|
|
710
710
|
/** Records the parent world matrix for each step (used by updateMatrix). */
|
|
711
|
-
stepParentM = new
|
|
711
|
+
stepParentM = new B(O.Uint32);
|
|
712
712
|
/** Buffer used during hierarchy traversal updates. */
|
|
713
|
-
parentStack = new
|
|
713
|
+
parentStack = new B(O.Uint32);
|
|
714
714
|
/** The index of the current local matrix in the matrix store. */
|
|
715
715
|
curLocalM = -1;
|
|
716
716
|
/** The index of the current world matrix in the matrix store. */
|
|
@@ -859,14 +859,14 @@ class bt {
|
|
|
859
859
|
* Returns the current world matrix as Float32Array [a, b, c, d, tx, ty].
|
|
860
860
|
*/
|
|
861
861
|
getTransform() {
|
|
862
|
-
const t = this.curWorldM *
|
|
863
|
-
return this.matrix.data.slice(t, t +
|
|
862
|
+
const t = this.curWorldM * v;
|
|
863
|
+
return this.matrix.data.slice(t, t + v);
|
|
864
864
|
}
|
|
865
865
|
/**
|
|
866
866
|
* Directly overwrites the current world matrix with the given 6-element 2D transform.
|
|
867
867
|
*/
|
|
868
868
|
setTransform(t) {
|
|
869
|
-
const e = this.curWorldM *
|
|
869
|
+
const e = this.curWorldM * v, i = this.matrix.data;
|
|
870
870
|
i[e] = t[0], i[e + 1] = t[1], i[e + 2] = t[2], i[e + 3] = t[3], i[e + 4] = t[4], i[e + 5] = t[5];
|
|
871
871
|
}
|
|
872
872
|
transformPoint(t, e) {
|
|
@@ -888,28 +888,28 @@ class bt {
|
|
|
888
888
|
t.offset && (u += t.offset.x, f += t.offset.y);
|
|
889
889
|
const l = t.origin;
|
|
890
890
|
l !== void 0 && (typeof l == "number" ? (u -= l * e, f -= l * i) : (u -= l.x * e, f -= l.y * i));
|
|
891
|
-
const p = c ? Math.cos(c) : 1, x = c ? Math.sin(c) : 0,
|
|
891
|
+
const p = c ? Math.cos(c) : 1, x = c ? Math.sin(c) : 0, g = p * a, T = x * a, y = -x * o, w = p * o, M = r + g * u + y * f, A = n + T * u + w * f;
|
|
892
892
|
(t.afterSave !== void 0 || t.saveTransform === !1) && this.matrix.multiplyAffineInPlace(
|
|
893
893
|
this.curLocalM,
|
|
894
|
-
v,
|
|
895
|
-
R,
|
|
896
|
-
T,
|
|
897
894
|
g,
|
|
895
|
+
T,
|
|
896
|
+
y,
|
|
898
897
|
w,
|
|
899
|
-
|
|
898
|
+
M,
|
|
899
|
+
A
|
|
900
900
|
), this.matrix.multiplyAffineInPlace(
|
|
901
901
|
this.curWorldM,
|
|
902
|
-
v,
|
|
903
|
-
R,
|
|
904
|
-
T,
|
|
905
902
|
g,
|
|
903
|
+
T,
|
|
904
|
+
y,
|
|
906
905
|
w,
|
|
907
|
-
|
|
906
|
+
M,
|
|
907
|
+
A
|
|
908
908
|
), t.afterSave?.();
|
|
909
909
|
}
|
|
910
910
|
}
|
|
911
|
-
var
|
|
912
|
-
class
|
|
911
|
+
var Y = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(Y || {});
|
|
912
|
+
class bt {
|
|
913
913
|
render;
|
|
914
914
|
cache = /* @__PURE__ */ new Map();
|
|
915
915
|
constructor(t) {
|
|
@@ -927,7 +927,7 @@ class At {
|
|
|
927
927
|
return new P(i);
|
|
928
928
|
try {
|
|
929
929
|
const r = await this._fetchImage(t);
|
|
930
|
-
return i =
|
|
930
|
+
return i = k.fromSource(this.render, r, e), i.uid = t, this.cache.set(t, i), new P(i);
|
|
931
931
|
} catch (r) {
|
|
932
932
|
throw console.error(`[TextureManager] Failed to load: ${t}`, r), r;
|
|
933
933
|
}
|
|
@@ -941,7 +941,7 @@ class At {
|
|
|
941
941
|
create(t, e) {
|
|
942
942
|
if (e?.key && this.cache.has(e.key))
|
|
943
943
|
return new P(this.cache.get(e.key));
|
|
944
|
-
const i =
|
|
944
|
+
const i = k.fromSource(this.render, t, e);
|
|
945
945
|
return e?.key && (i.uid = e.key, this.cache.set(e.key, i)), new P(i);
|
|
946
946
|
}
|
|
947
947
|
/**
|
|
@@ -952,7 +952,7 @@ class At {
|
|
|
952
952
|
* @returns The newly created RenderTexture.
|
|
953
953
|
*/
|
|
954
954
|
createRenderTexture(t) {
|
|
955
|
-
return new
|
|
955
|
+
return new At(this.render, t);
|
|
956
956
|
}
|
|
957
957
|
/**
|
|
958
958
|
* Creates a TextTexture for rendering text.
|
|
@@ -960,7 +960,7 @@ class At {
|
|
|
960
960
|
* @returns The newly created TextTexture.
|
|
961
961
|
*/
|
|
962
962
|
createTextTexture(t) {
|
|
963
|
-
return new
|
|
963
|
+
return new _t(this.render, t);
|
|
964
964
|
}
|
|
965
965
|
/**
|
|
966
966
|
* Destroys a texture and potentially removes its BaseTexture from the cache.
|
|
@@ -988,7 +988,7 @@ class At {
|
|
|
988
988
|
});
|
|
989
989
|
}
|
|
990
990
|
}
|
|
991
|
-
class
|
|
991
|
+
class k {
|
|
992
992
|
glTexture = null;
|
|
993
993
|
width;
|
|
994
994
|
height;
|
|
@@ -1005,8 +1005,8 @@ class G {
|
|
|
1005
1005
|
* @returns The created BaseTexture.
|
|
1006
1006
|
*/
|
|
1007
1007
|
static fromSource(t, e, i = {}) {
|
|
1008
|
-
const r =
|
|
1009
|
-
return new
|
|
1008
|
+
const r = K(t, e, i);
|
|
1009
|
+
return new k(r, e.width, e.height);
|
|
1010
1010
|
}
|
|
1011
1011
|
/**
|
|
1012
1012
|
* Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
|
|
@@ -1015,19 +1015,19 @@ class G {
|
|
|
1015
1015
|
* @param source - The new image source.
|
|
1016
1016
|
*/
|
|
1017
1017
|
updateSource(t, e, i = {}) {
|
|
1018
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 &&
|
|
1018
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 && tt(t, i.textureFilter), i.wrap !== void 0 && J(t, i.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, i.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), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
|
|
1019
1019
|
}
|
|
1020
1020
|
/**
|
|
1021
1021
|
* Dynamically updates the texture filtering mode.
|
|
1022
1022
|
*/
|
|
1023
1023
|
setFilterMode(t, e) {
|
|
1024
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1024
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), tt(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1025
1025
|
}
|
|
1026
1026
|
/**
|
|
1027
1027
|
* Dynamically updates the texture wrap mode.
|
|
1028
1028
|
*/
|
|
1029
1029
|
setWrapMode(t, e) {
|
|
1030
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1030
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), J(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1031
1031
|
}
|
|
1032
1032
|
/**
|
|
1033
1033
|
* Destroys the WebGL texture resource.
|
|
@@ -1120,8 +1120,8 @@ class P {
|
|
|
1120
1120
|
if (!this.base) return [];
|
|
1121
1121
|
const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, n), u = t + c, f = e + c, l = i ?? Math.floor((o + c) / u), p = r ?? Math.floor((h + c) / f);
|
|
1122
1122
|
for (let x = 0; x < p; x++)
|
|
1123
|
-
for (let
|
|
1124
|
-
a.push(this.getSubTexture(
|
|
1123
|
+
for (let g = 0; g < l; g++)
|
|
1124
|
+
a.push(this.getSubTexture(g * u, x * f, t, e));
|
|
1125
1125
|
return a;
|
|
1126
1126
|
}
|
|
1127
1127
|
/**
|
|
@@ -1130,8 +1130,8 @@ class P {
|
|
|
1130
1130
|
* @param options - Optional antialias and wrap mode settings.
|
|
1131
1131
|
*/
|
|
1132
1132
|
static fromImageSource(t, e, i = {}) {
|
|
1133
|
-
const r =
|
|
1134
|
-
return new P(new
|
|
1133
|
+
const r = K(t, e, i);
|
|
1134
|
+
return new P(new k(r, e.width, e.height));
|
|
1135
1135
|
}
|
|
1136
1136
|
/**
|
|
1137
1137
|
* Marks this Texture as destroyed, decrementing the BaseTexture reference count.
|
|
@@ -1140,7 +1140,7 @@ class P {
|
|
|
1140
1140
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
1141
1141
|
}
|
|
1142
1142
|
}
|
|
1143
|
-
class
|
|
1143
|
+
class At extends P {
|
|
1144
1144
|
framebuffer;
|
|
1145
1145
|
renderbuffer;
|
|
1146
1146
|
gl;
|
|
@@ -1151,8 +1151,8 @@ class Ut extends P {
|
|
|
1151
1151
|
_allocH = 0;
|
|
1152
1152
|
constructor(t, e) {
|
|
1153
1153
|
super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
|
|
1154
|
-
const i = Math.max(Math.round(e.width), 1), r = Math.max(Math.round(e.height), 1), a =
|
|
1155
|
-
if (this.setBase(new
|
|
1154
|
+
const i = Math.max(Math.round(e.width), 1), r = Math.max(Math.round(e.height), 1), a = K(t, { width: i, height: r }, { ...e, onlySize: !0 });
|
|
1155
|
+
if (this.setBase(new k(a, i, r)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
1156
1156
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
1157
1157
|
this.resize(i, r, !0);
|
|
1158
1158
|
}
|
|
@@ -1230,7 +1230,7 @@ class Ut extends P {
|
|
|
1230
1230
|
super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
|
|
1231
1231
|
}
|
|
1232
1232
|
}
|
|
1233
|
-
const
|
|
1233
|
+
const Ut = {
|
|
1234
1234
|
fontFamily: "Arial",
|
|
1235
1235
|
fontSize: 24,
|
|
1236
1236
|
fontWeight: "normal",
|
|
@@ -1239,7 +1239,7 @@ const _t = {
|
|
|
1239
1239
|
align: "left",
|
|
1240
1240
|
baseline: "top"
|
|
1241
1241
|
};
|
|
1242
|
-
class
|
|
1242
|
+
class _t extends P {
|
|
1243
1243
|
canvas;
|
|
1244
1244
|
ctx;
|
|
1245
1245
|
render;
|
|
@@ -1248,12 +1248,12 @@ class Ct extends P {
|
|
|
1248
1248
|
options;
|
|
1249
1249
|
flipY = !0;
|
|
1250
1250
|
constructor(t, e) {
|
|
1251
|
-
super(), this.render = t, this._style = { ...
|
|
1251
|
+
super(), this.render = t, this._style = { ...Ut, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
|
|
1252
1252
|
const i = this.canvas.getContext("2d", { willReadFrequently: !0 });
|
|
1253
1253
|
if (!i) throw new Error("Failed to get 2d context for TextTexture");
|
|
1254
1254
|
this.ctx = i, this.canvas.width = 1, this.canvas.height = 1;
|
|
1255
|
-
const r =
|
|
1256
|
-
this.setBase(new
|
|
1255
|
+
const r = K(t, this.canvas, this.options);
|
|
1256
|
+
this.setBase(new k(r, 1, 1)), this.update();
|
|
1257
1257
|
}
|
|
1258
1258
|
get text() {
|
|
1259
1259
|
return this._text;
|
|
@@ -1308,27 +1308,27 @@ class Ct extends P {
|
|
|
1308
1308
|
let h = 0, c = 0;
|
|
1309
1309
|
t.textBaseline = "alphabetic";
|
|
1310
1310
|
const u = t.measureText(o[0]), f = u.fontBoundingBoxAscent, l = u.fontBoundingBoxDescent;
|
|
1311
|
-
for (const
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1311
|
+
for (const M of o) {
|
|
1312
|
+
const A = t.measureText(M);
|
|
1313
|
+
A.width > h && (h = A.width), c += f + l;
|
|
1314
1314
|
}
|
|
1315
1315
|
c -= l;
|
|
1316
|
-
const p = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + p) || 1,
|
|
1317
|
-
(this.canvas.width !==
|
|
1318
|
-
let
|
|
1319
|
-
for (const
|
|
1320
|
-
let
|
|
1321
|
-
this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(
|
|
1316
|
+
const p = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + p) || 1, g = Math.ceil(c + p) || 1, T = x * a, y = g * a;
|
|
1317
|
+
(this.canvas.width !== T || this.canvas.height !== y) && (this.canvas.width = T, this.canvas.height = y), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, g), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, g);
|
|
1318
|
+
let w = p / 2;
|
|
1319
|
+
for (const M of o) {
|
|
1320
|
+
let A = p / 2;
|
|
1321
|
+
this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(M, A, w)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(M, A, w)), w += f + l;
|
|
1322
1322
|
}
|
|
1323
1323
|
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, this.canvas.width, this.canvas.height);
|
|
1324
1324
|
}
|
|
1325
1325
|
}
|
|
1326
|
-
const
|
|
1326
|
+
const Ct = (s, t = !1, e = !0) => {
|
|
1327
1327
|
const i = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
|
|
1328
1328
|
if (!i)
|
|
1329
1329
|
throw new Error("WebGL2 is not supported in this browser.");
|
|
1330
1330
|
return i;
|
|
1331
|
-
},
|
|
1331
|
+
}, ht = (s, t, e) => {
|
|
1332
1332
|
const i = s.createShader(e);
|
|
1333
1333
|
if (!i)
|
|
1334
1334
|
throw new Error("Unable to create webgl shader");
|
|
@@ -1337,8 +1337,8 @@ const Pt = (s, t = !1, e = !0) => {
|
|
|
1337
1337
|
throw console.error("Shader compilation failed:", n), new Error("Unable to compile shader: " + n + t);
|
|
1338
1338
|
}
|
|
1339
1339
|
return i;
|
|
1340
|
-
},
|
|
1341
|
-
var i = s.createProgram(), r =
|
|
1340
|
+
}, Pt = (s, t, e) => {
|
|
1341
|
+
var i = s.createProgram(), r = ht(s, t, 35633), n = ht(s, e, 35632);
|
|
1342
1342
|
if (!i)
|
|
1343
1343
|
throw new Error("Unable to create program shader");
|
|
1344
1344
|
if (s.attachShader(i, r), s.attachShader(i, n), s.linkProgram(i), !s.getProgramParameter(i, s.LINK_STATUS)) {
|
|
@@ -1347,26 +1347,26 @@ const Pt = (s, t = !1, e = !0) => {
|
|
|
1347
1347
|
}
|
|
1348
1348
|
return i;
|
|
1349
1349
|
};
|
|
1350
|
-
function
|
|
1350
|
+
function J(s, t) {
|
|
1351
1351
|
const e = {
|
|
1352
|
-
[
|
|
1353
|
-
[
|
|
1354
|
-
[
|
|
1352
|
+
[Y.CLAMP]: s.CLAMP_TO_EDGE,
|
|
1353
|
+
[Y.REPEAT]: s.REPEAT,
|
|
1354
|
+
[Y.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
|
|
1355
1355
|
}[t] || s.CLAMP_TO_EDGE;
|
|
1356
1356
|
s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, e);
|
|
1357
1357
|
}
|
|
1358
|
-
function
|
|
1358
|
+
function tt(s, t) {
|
|
1359
1359
|
const e = {
|
|
1360
|
-
[
|
|
1361
|
-
[
|
|
1360
|
+
[it.LINEAR]: s.LINEAR,
|
|
1361
|
+
[it.NEAREST]: s.NEAREST
|
|
1362
1362
|
}[t] ?? s.NEAREST;
|
|
1363
1363
|
s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, e);
|
|
1364
1364
|
}
|
|
1365
|
-
function
|
|
1365
|
+
function K(s, t, e) {
|
|
1366
1366
|
const i = s.gl, r = i.createTexture();
|
|
1367
1367
|
if (!r)
|
|
1368
1368
|
throw new Error("Unable to create WebGL texture");
|
|
1369
|
-
if (i.bindTexture(i.TEXTURE_2D, r), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 0), i.pixelStorei(i.UNPACK_ALIGNMENT, 1),
|
|
1369
|
+
if (i.bindTexture(i.TEXTURE_2D, r), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 0), i.pixelStorei(i.UNPACK_ALIGNMENT, 1), J(i, e.wrap ?? Y.CLAMP), tt(i, e.textureFilter ?? s.textureFilter), e.onlySize) {
|
|
1370
1370
|
const n = t;
|
|
1371
1371
|
i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, n.width, n.height, 0, i.RGBA, i.UNSIGNED_BYTE, null);
|
|
1372
1372
|
} else {
|
|
@@ -1375,7 +1375,7 @@ function Q(s, t, e) {
|
|
|
1375
1375
|
}
|
|
1376
1376
|
return i.bindTexture(i.TEXTURE_2D, null), r;
|
|
1377
1377
|
}
|
|
1378
|
-
function
|
|
1378
|
+
function W(s, t) {
|
|
1379
1379
|
if (s.includes("%TEXTURE_NUM%") && (s = s.replace("%TEXTURE_NUM%", t.toString())), s.includes("%GET_COLOR%")) {
|
|
1380
1380
|
let e = "";
|
|
1381
1381
|
for (let i = 0; i < t; i++)
|
|
@@ -1384,15 +1384,15 @@ function F(s, t) {
|
|
|
1384
1384
|
}
|
|
1385
1385
|
return s;
|
|
1386
1386
|
}
|
|
1387
|
-
const
|
|
1388
|
-
function
|
|
1387
|
+
const Nt = 5126, et = 5121;
|
|
1388
|
+
function Lt(s, t, e) {
|
|
1389
1389
|
s.vertexAttribDivisor(t, e);
|
|
1390
1390
|
}
|
|
1391
|
-
function
|
|
1391
|
+
function vt(s, t, e, i, r) {
|
|
1392
1392
|
s.drawArraysInstanced(t, e, i, r);
|
|
1393
1393
|
}
|
|
1394
1394
|
let Ot = 0;
|
|
1395
|
-
class
|
|
1395
|
+
class Tt {
|
|
1396
1396
|
program;
|
|
1397
1397
|
attributeLoc = {};
|
|
1398
1398
|
uniformLoc = {};
|
|
@@ -1408,7 +1408,7 @@ class yt {
|
|
|
1408
1408
|
// for debug
|
|
1409
1409
|
vao;
|
|
1410
1410
|
constructor(t, e, i, r) {
|
|
1411
|
-
this.gl = t, this.program =
|
|
1411
|
+
this.gl = t, this.program = Pt(t, e, i), this.parseShader(e), this.parseShader(i), this.vao = t.createVertexArray(), r && this.setAttributes(r);
|
|
1412
1412
|
}
|
|
1413
1413
|
/** Switch GPU to use this shader program */
|
|
1414
1414
|
use() {
|
|
@@ -1434,7 +1434,7 @@ class yt {
|
|
|
1434
1434
|
const i = this.uniformLoc[t];
|
|
1435
1435
|
if (i === void 0) return;
|
|
1436
1436
|
const r = this.uniformType[t], n = this.uniformIsArray[t];
|
|
1437
|
-
|
|
1437
|
+
It(this.gl, i, r, e, n);
|
|
1438
1438
|
}
|
|
1439
1439
|
/**
|
|
1440
1440
|
* Batch-set uniforms via a plain value map.
|
|
@@ -1461,11 +1461,11 @@ class yt {
|
|
|
1461
1461
|
i.vertexAttribPointer(
|
|
1462
1462
|
e,
|
|
1463
1463
|
t.size,
|
|
1464
|
-
t.type ??
|
|
1464
|
+
t.type ?? Nt,
|
|
1465
1465
|
t.normalized ?? !1,
|
|
1466
1466
|
t.stride,
|
|
1467
1467
|
t.offset ?? 0
|
|
1468
|
-
), i.enableVertexAttribArray(e),
|
|
1468
|
+
), i.enableVertexAttribArray(e), Lt(i, e, t.divisor ?? 0);
|
|
1469
1469
|
}
|
|
1470
1470
|
/** Bind all vertex attribute pointers at once */
|
|
1471
1471
|
setAttributes(t) {
|
|
@@ -1493,7 +1493,7 @@ class yt {
|
|
|
1493
1493
|
}
|
|
1494
1494
|
}
|
|
1495
1495
|
}
|
|
1496
|
-
function
|
|
1496
|
+
function It(s, t, e, i, r = !1) {
|
|
1497
1497
|
switch (e) {
|
|
1498
1498
|
// scalars
|
|
1499
1499
|
case "float":
|
|
@@ -1529,10 +1529,10 @@ function Wt(s, t, e, i, r = !1) {
|
|
|
1529
1529
|
return s.uniformMatrix4fv(t, !1, i);
|
|
1530
1530
|
// fallback: guess by value shape
|
|
1531
1531
|
default:
|
|
1532
|
-
return
|
|
1532
|
+
return Wt(s, t, i);
|
|
1533
1533
|
}
|
|
1534
1534
|
}
|
|
1535
|
-
function
|
|
1535
|
+
function Wt(s, t, e) {
|
|
1536
1536
|
if (typeof e == "number")
|
|
1537
1537
|
return s.uniform1f(t, e);
|
|
1538
1538
|
const i = e;
|
|
@@ -1551,7 +1551,7 @@ function Ft(s, t, e) {
|
|
|
1551
1551
|
return s.uniform1fv(t, i);
|
|
1552
1552
|
}
|
|
1553
1553
|
}
|
|
1554
|
-
class
|
|
1554
|
+
class ot {
|
|
1555
1555
|
/** Custom vertex shader code */
|
|
1556
1556
|
vs;
|
|
1557
1557
|
/** Custom fragment shader code */
|
|
@@ -1623,8 +1623,7 @@ class ut {
|
|
|
1623
1623
|
return n.isCustom = !0, n.padding = this.padding, this.glshader.set(e, n), this.uniformDirty.add(e), n;
|
|
1624
1624
|
}
|
|
1625
1625
|
}
|
|
1626
|
-
|
|
1627
|
-
class Rt {
|
|
1626
|
+
class yt {
|
|
1628
1627
|
constructor(t) {
|
|
1629
1628
|
this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
|
|
1630
1629
|
}
|
|
@@ -1667,7 +1666,7 @@ class Rt {
|
|
|
1667
1666
|
return r == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(i), this.usedTextures.length - 1) : r;
|
|
1668
1667
|
}
|
|
1669
1668
|
createShader(t, e) {
|
|
1670
|
-
return new
|
|
1669
|
+
return new Tt(this.gl, t, e);
|
|
1671
1670
|
}
|
|
1672
1671
|
createCustomShader(t) {
|
|
1673
1672
|
return t.getGLShader(this, this.KEY, this.vs, this.fs);
|
|
@@ -1675,7 +1674,7 @@ class Rt {
|
|
|
1675
1674
|
getCustomShader(t) {
|
|
1676
1675
|
if (!t)
|
|
1677
1676
|
return this.defaultShader;
|
|
1678
|
-
if (t instanceof
|
|
1677
|
+
if (t instanceof ot) {
|
|
1679
1678
|
const e = this.createCustomShader(t);
|
|
1680
1679
|
return e ?? this.defaultShader;
|
|
1681
1680
|
}
|
|
@@ -1690,7 +1689,7 @@ class Rt {
|
|
|
1690
1689
|
return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
|
|
1691
1690
|
}
|
|
1692
1691
|
enter(t) {
|
|
1693
|
-
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof
|
|
1692
|
+
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ot ? (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);
|
|
1694
1693
|
}
|
|
1695
1694
|
exit() {
|
|
1696
1695
|
this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
|
|
@@ -1699,6 +1698,9 @@ class Rt {
|
|
|
1699
1698
|
this.render(), this.resetRender();
|
|
1700
1699
|
}
|
|
1701
1700
|
render() {
|
|
1701
|
+
this.prepareRender();
|
|
1702
|
+
}
|
|
1703
|
+
prepareRender() {
|
|
1702
1704
|
const t = this.currentShader;
|
|
1703
1705
|
if (t.use(), this.customShader) {
|
|
1704
1706
|
const i = this.customShader, r = {};
|
|
@@ -1724,7 +1726,7 @@ class Rt {
|
|
|
1724
1726
|
return !1;
|
|
1725
1727
|
}
|
|
1726
1728
|
}
|
|
1727
|
-
const
|
|
1729
|
+
const $ = `#version 300 es\r
|
|
1728
1730
|
precision mediump float;\r
|
|
1729
1731
|
\r
|
|
1730
1732
|
// per-vertex\r
|
|
@@ -1772,7 +1774,7 @@ void main(void) {\r
|
|
|
1772
1774
|
\r
|
|
1773
1775
|
gl_Position = u_projection * position;\r
|
|
1774
1776
|
}\r
|
|
1775
|
-
`,
|
|
1777
|
+
`, ct = `#version 300 es\r
|
|
1776
1778
|
precision mediump float;\r
|
|
1777
1779
|
\r
|
|
1778
1780
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -1821,8 +1823,8 @@ void main(void) {\r
|
|
|
1821
1823
|
\r
|
|
1822
1824
|
// CUSTOM_CODE_CALL\r
|
|
1823
1825
|
}\r
|
|
1824
|
-
`,
|
|
1825
|
-
class
|
|
1826
|
+
`, V = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
1827
|
+
class rt extends yt {
|
|
1826
1828
|
instanceBuffer;
|
|
1827
1829
|
quadBuffer;
|
|
1828
1830
|
instanceCount = 0;
|
|
@@ -1834,28 +1836,28 @@ class at extends Rt {
|
|
|
1834
1836
|
}
|
|
1835
1837
|
createBuffer() {
|
|
1836
1838
|
const t = this.gl;
|
|
1837
|
-
this.quadBuffer = new
|
|
1838
|
-
for (const e of
|
|
1839
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new
|
|
1839
|
+
this.quadBuffer = new Q(t, O.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1840
|
+
for (const e of Ft) this.quadBuffer.pushFloat32(e);
|
|
1841
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, O.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1840
1842
|
}
|
|
1841
1843
|
createDefaultShader() {
|
|
1842
|
-
const t = this.rapid, e =
|
|
1844
|
+
const t = this.rapid, e = W(ct, t.maxTextureUnits), i = W($, t.maxTextureUnits);
|
|
1843
1845
|
return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
|
|
1844
1846
|
}
|
|
1845
1847
|
createShader(t, e) {
|
|
1846
1848
|
const i = super.createShader(t, e);
|
|
1847
1849
|
return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
|
|
1848
|
-
{ name: "aMatrixRow0", size: 3, stride:
|
|
1849
|
-
{ name: "aMatrixRow1", size: 3, stride:
|
|
1850
|
-
{ name: "aUVRect", size: 4, stride:
|
|
1851
|
-
{ name: "aColor", size: 4, type:
|
|
1852
|
-
{ name: "aTextureId", size: 1, type:
|
|
1850
|
+
{ name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
|
|
1851
|
+
{ name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
|
|
1852
|
+
{ name: "aUVRect", size: 4, stride: V, offset: 24, divisor: 1 },
|
|
1853
|
+
{ name: "aColor", size: 4, type: et, normalized: !0, stride: V, offset: 40, divisor: 1 },
|
|
1854
|
+
{ name: "aTextureId", size: 1, type: et, stride: V, offset: 44, divisor: 1 }
|
|
1853
1855
|
]), this.quadBuffer.bindBuffer(), i.setAttributes([
|
|
1854
1856
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1855
1857
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
1856
1858
|
}
|
|
1857
1859
|
createCustomShader(t) {
|
|
1858
|
-
const e =
|
|
1860
|
+
const e = W(ct, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
1859
1861
|
return t.getGLShader(this, this.KEY, i, e);
|
|
1860
1862
|
}
|
|
1861
1863
|
/**
|
|
@@ -1892,24 +1894,23 @@ class at extends Rt {
|
|
|
1892
1894
|
l
|
|
1893
1895
|
);
|
|
1894
1896
|
}
|
|
1895
|
-
drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0,
|
|
1896
|
-
|
|
1897
|
-
const g = t.base, w = t.scale ?? 1, b = t.rawWidth, A = t.rawHeight, I = t.offsetX, Y = t.offsetY, N = this.useTexture(
|
|
1897
|
+
drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0, g = !1, T = !1, y = !1) {
|
|
1898
|
+
const w = t.base, M = t.scale ?? 1, A = t.rawWidth, F = t.rawHeight, I = t.offsetX, N = t.offsetY, S = this.useTexture(
|
|
1898
1899
|
t.glTexture,
|
|
1899
|
-
p /
|
|
1900
|
-
x /
|
|
1901
|
-
),
|
|
1902
|
-
|
|
1903
|
-
const
|
|
1904
|
-
|
|
1900
|
+
p / M / w.width,
|
|
1901
|
+
x / M / w.height
|
|
1902
|
+
), R = this.instanceBuffer, b = R.usedElemNum;
|
|
1903
|
+
R.resize(12);
|
|
1904
|
+
const U = R.float32, L = R.uint32, j = (y ? F : A) * M, q = (y ? A : F) * M, G = j + 2 * p, H = q + 2 * x, nt = I - p, at = N - x, E = this.localSpriteMatrix;
|
|
1905
|
+
y ? (E[0] = 0, E[1] = T ? H : -H, E[2] = g ? -G : G, E[3] = 0, E[4] = nt + (g ? G : 0), E[5] = at + (T ? 0 : H)) : (E[0] = g ? -G : G, E[1] = 0, E[2] = 0, E[3] = T ? -H : H, E[4] = nt + (g ? G : 0), E[5] = at + (T ? H : 0));
|
|
1905
1906
|
const _ = this.worldSpriteMatrix;
|
|
1906
|
-
_[0] = e *
|
|
1907
|
+
_[0] = e * E[0] + r * E[1], _[1] = i * E[0] + n * E[1], _[2] = e * E[2] + r * E[3], _[3] = i * E[2] + n * E[3], _[4] = a + e * E[4] + r * E[5], _[5] = o + i * E[4] + n * E[5], U[b + 6] = h, U[b + 7] = c, U[b + 8] = u, U[b + 9] = f, L[b + 10] = l, L[b + 11] = S, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), U[b] = _[0], U[b + 1] = _[2], U[b + 2] = _[4], U[b + 3] = _[1], U[b + 4] = _[3], U[b + 5] = _[5], R.usedElemNum += 12, R.makeDirty(), this.instanceCount++;
|
|
1907
1908
|
}
|
|
1908
1909
|
render() {
|
|
1909
1910
|
if (this.instanceCount === 0) return;
|
|
1910
|
-
|
|
1911
|
+
this.prepareRender();
|
|
1911
1912
|
const t = this.gl, e = this.currentShader;
|
|
1912
|
-
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(),
|
|
1913
|
+
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
|
|
1913
1914
|
}
|
|
1914
1915
|
resetRender() {
|
|
1915
1916
|
super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
|
|
@@ -1918,7 +1919,7 @@ class at extends Rt {
|
|
|
1918
1919
|
return this.instanceCount > 0;
|
|
1919
1920
|
}
|
|
1920
1921
|
}
|
|
1921
|
-
const
|
|
1922
|
+
const Dt = `#version 300 es\r
|
|
1922
1923
|
precision mediump float;\r
|
|
1923
1924
|
\r
|
|
1924
1925
|
in vec2 aPosition;\r
|
|
@@ -1949,7 +1950,7 @@ void main(void) {\r
|
|
|
1949
1950
|
// CUSTOM_CODE_CALL\r
|
|
1950
1951
|
gl_Position = u_projection * position;\r
|
|
1951
1952
|
}\r
|
|
1952
|
-
`,
|
|
1953
|
+
`, Bt = `#version 300 es\r
|
|
1953
1954
|
precision mediump float;\r
|
|
1954
1955
|
\r
|
|
1955
1956
|
in vec4 vColor;\r
|
|
@@ -1995,7 +1996,7 @@ void main(void) {\r
|
|
|
1995
1996
|
fragColor = sampleTexture(vRegion);\r
|
|
1996
1997
|
// CUSTOM_CODE_CALL\r
|
|
1997
1998
|
}\r
|
|
1998
|
-
`,
|
|
1999
|
+
`, kt = `#version 300 es\r
|
|
1999
2000
|
precision mediump float;\r
|
|
2000
2001
|
\r
|
|
2001
2002
|
in vec2 aPosition;\r
|
|
@@ -2018,7 +2019,7 @@ void main(void) {\r
|
|
|
2018
2019
|
);\r
|
|
2019
2020
|
gl_Position = u_projection * position;\r
|
|
2020
2021
|
}\r
|
|
2021
|
-
`,
|
|
2022
|
+
`, Gt = `#version 300 es\r
|
|
2022
2023
|
precision mediump float;\r
|
|
2023
2024
|
\r
|
|
2024
2025
|
in vec2 vRegion;\r
|
|
@@ -2038,8 +2039,8 @@ void main(void) {\r
|
|
|
2038
2039
|
discard;\r
|
|
2039
2040
|
}\r
|
|
2040
2041
|
}\r
|
|
2041
|
-
`,
|
|
2042
|
-
class
|
|
2042
|
+
`, z = 20;
|
|
2043
|
+
class Ht extends yt {
|
|
2043
2044
|
vertexBuffer;
|
|
2044
2045
|
vertexCount = 0;
|
|
2045
2046
|
matrixIndex = -1;
|
|
@@ -2052,24 +2053,24 @@ class Vt extends Rt {
|
|
|
2052
2053
|
}
|
|
2053
2054
|
createBuffer() {
|
|
2054
2055
|
const t = this.gl;
|
|
2055
|
-
this.vertexBuffer = new
|
|
2056
|
+
this.vertexBuffer = new Q(t, O.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
|
|
2056
2057
|
}
|
|
2057
2058
|
createDefaultShader() {
|
|
2058
|
-
return this.vs =
|
|
2059
|
+
return this.vs = Dt, this.fs = Bt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
2059
2060
|
}
|
|
2060
2061
|
createMaskShader(t, e) {
|
|
2061
|
-
const i = this.gl, r = new
|
|
2062
|
+
const i = this.gl, r = new Tt(i, t, e);
|
|
2062
2063
|
return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
|
|
2063
|
-
{ name: "aPosition", size: 2, type: i.FLOAT, stride:
|
|
2064
|
-
{ name: "aUV", size: 2, type: i.FLOAT, stride:
|
|
2064
|
+
{ name: "aPosition", size: 2, type: i.FLOAT, stride: z - 4, offset: 0, divisor: 0 },
|
|
2065
|
+
{ name: "aUV", size: 2, type: i.FLOAT, stride: z - 4, offset: 8, divisor: 0 }
|
|
2065
2066
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2066
2067
|
}
|
|
2067
2068
|
createShader(t, e) {
|
|
2068
2069
|
const i = this.gl, r = super.createShader(t, e);
|
|
2069
2070
|
return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
|
|
2070
|
-
{ name: "aPosition", size: 2, type: i.FLOAT, stride:
|
|
2071
|
-
{ name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride:
|
|
2072
|
-
{ name: "aUV", size: 2, type: i.FLOAT, stride:
|
|
2071
|
+
{ name: "aPosition", size: 2, type: i.FLOAT, stride: z, offset: 0, divisor: 0 },
|
|
2072
|
+
{ name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: z, offset: 8, divisor: 0 },
|
|
2073
|
+
{ name: "aUV", size: 2, type: i.FLOAT, stride: z, offset: 12, divisor: 0 }
|
|
2073
2074
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2074
2075
|
}
|
|
2075
2076
|
/**
|
|
@@ -2101,7 +2102,7 @@ class Vt extends Rt {
|
|
|
2101
2102
|
}
|
|
2102
2103
|
render() {
|
|
2103
2104
|
if (this.vertexCount === 0) return;
|
|
2104
|
-
|
|
2105
|
+
this.prepareRender();
|
|
2105
2106
|
const t = this.gl, e = this.currentShader, i = this.matrixIndex * 6, r = this.matrixStore.data;
|
|
2106
2107
|
let n = r[i + 4], a = r[i + 5];
|
|
2107
2108
|
this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [r[i], r[i + 2], n]), e.setUniform("uMatrixRow1", [r[i + 1], r[i + 3], a]), e.setUniform(
|
|
@@ -2238,7 +2239,7 @@ class d {
|
|
|
2238
2239
|
return new d(Math.cos(t), Math.sin(t));
|
|
2239
2240
|
}
|
|
2240
2241
|
}
|
|
2241
|
-
const
|
|
2242
|
+
const Vt = (s, t) => {
|
|
2242
2243
|
const [e, i, r, n, a, o] = t, h = new Float32Array([
|
|
2243
2244
|
e,
|
|
2244
2245
|
n,
|
|
@@ -2269,15 +2270,15 @@ const Yt = (s, t) => {
|
|
|
2269
2270
|
}
|
|
2270
2271
|
return e;
|
|
2271
2272
|
};
|
|
2272
|
-
var
|
|
2273
|
-
const
|
|
2273
|
+
var Yt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Yt || {});
|
|
2274
|
+
const Z = 10, ut = (s, t, e, i, r, n) => {
|
|
2274
2275
|
const a = [], o = [], h = i ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new d(t.y, -t.x);
|
|
2275
|
-
for (let f = 0; f <
|
|
2276
|
-
const l = f /
|
|
2277
|
-
a.push(s), o.push(new d(r, 0.5)), a.push(s.add(
|
|
2276
|
+
for (let f = 0; f < Z; f++) {
|
|
2277
|
+
const l = f / Z, p = (f + 1) / Z, x = h + l * c, g = h + p * c, T = new d(Math.cos(x) * e, Math.sin(x) * e), y = new d(Math.cos(g) * e, Math.sin(g) * e);
|
|
2278
|
+
a.push(s), o.push(new d(r, 0.5)), a.push(s.add(T)), o.push(new d(r + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e)), a.push(s.add(y)), o.push(new d(r + y.dot(u) * n, 0.5 - 0.5 * y.dot(t) / e));
|
|
2278
2279
|
}
|
|
2279
2280
|
return { vertices: a, uv: o };
|
|
2280
|
-
},
|
|
2281
|
+
}, Xt = (s, t = !1) => {
|
|
2281
2282
|
const e = [];
|
|
2282
2283
|
if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
|
|
2283
2284
|
const i = 4, r = 1e-3, n = s.length;
|
|
@@ -2297,8 +2298,8 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2297
2298
|
{
|
|
2298
2299
|
let x = l.add(f).normalize();
|
|
2299
2300
|
f.cross(l) < 0 && (x = x.multiply(-1));
|
|
2300
|
-
let
|
|
2301
|
-
return { normal: x, miters: Math.min(
|
|
2301
|
+
let g = 1 / Math.sqrt((1 - p) / 2);
|
|
2302
|
+
return { normal: x, miters: Math.min(g, i) };
|
|
2302
2303
|
}
|
|
2303
2304
|
};
|
|
2304
2305
|
if (t)
|
|
@@ -2320,31 +2321,31 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2320
2321
|
}, jt = (s) => {
|
|
2321
2322
|
const t = s.points;
|
|
2322
2323
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2323
|
-
const { normals: e, length: i } =
|
|
2324
|
+
const { normals: e, length: i } = Xt(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
|
|
2324
2325
|
let c = 0;
|
|
2325
2326
|
const u = s.texture?.rawWidth || 1, f = s.closed ? t.length : t.length - 1;
|
|
2326
2327
|
for (let l = 0; l < f; l++) {
|
|
2327
|
-
const p = t[l], x = e[l].normal,
|
|
2328
|
-
let
|
|
2329
|
-
h === 0 ? (
|
|
2330
|
-
const
|
|
2331
|
-
n.push(
|
|
2328
|
+
const p = t[l], x = e[l].normal, g = e[l].miters, T = (l + 1) % t.length, y = t[T], w = e[T].normal, M = e[T].miters, A = p.add(x.multiply(g * r)), F = p.subtract(x.multiply(g * r)), I = y.add(w.multiply(M * r)), N = y.subtract(w.multiply(M * r)), S = p.distanceTo(y);
|
|
2329
|
+
let R = 0, b = 0;
|
|
2330
|
+
h === 0 ? (R = c / i, b = (c + S) / i) : (R = c / u, b = R + S / u);
|
|
2331
|
+
const U = new d(R, 0), L = new d(R, 1), j = new d(b, 0), q = new d(b, 1);
|
|
2332
|
+
n.push(A), a.push(U), n.push(F), a.push(L), n.push(I), a.push(j), n.push(I), a.push(j), n.push(N), a.push(q), n.push(F), a.push(L), c += S;
|
|
2332
2333
|
}
|
|
2333
2334
|
if (o && !s.closed) {
|
|
2334
|
-
const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u,
|
|
2335
|
-
n.push(...
|
|
2336
|
-
const
|
|
2337
|
-
n.push(...
|
|
2335
|
+
const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, g = ut(l, p, r, !0, 0, x);
|
|
2336
|
+
n.push(...g.vertices), a.push(...g.uv);
|
|
2337
|
+
const T = t[t.length - 1], y = e[t.length - 1].normal, w = h === 0 ? 1 : c / u, M = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, A = ut(T, y, r, !1, w, M);
|
|
2338
|
+
n.push(...A.vertices), a.push(...A.uv);
|
|
2338
2339
|
}
|
|
2339
2340
|
return { vertices: n, uv: a };
|
|
2340
|
-
},
|
|
2341
|
+
}, X = (s, t, e, i, r) => {
|
|
2341
2342
|
s.matrixStack.applyTransform(t, e, i);
|
|
2342
2343
|
try {
|
|
2343
2344
|
r();
|
|
2344
2345
|
} finally {
|
|
2345
2346
|
t.saveTransform !== !1 && s.matrixStack.restore();
|
|
2346
2347
|
}
|
|
2347
|
-
},
|
|
2348
|
+
}, st = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, $t = 2, Rt = (s, t) => {
|
|
2348
2349
|
const e = t.texture;
|
|
2349
2350
|
if (!e?.base || s.inCreateMask)
|
|
2350
2351
|
return;
|
|
@@ -2353,7 +2354,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2353
2354
|
let r = e.uvX, n = e.uvY, a = e.uvW, o = e.uvH;
|
|
2354
2355
|
const h = !!t.flipX, c = !!t.flipY != !!e.flipY;
|
|
2355
2356
|
let u = t.padding ?? i.currentShader.padding;
|
|
2356
|
-
e.isAtlas && (u +=
|
|
2357
|
+
e.isAtlas && (u += $t);
|
|
2357
2358
|
const f = r <= a ? u : -u, l = n <= o ? u : -u;
|
|
2358
2359
|
i.drawSprite(
|
|
2359
2360
|
e,
|
|
@@ -2362,40 +2363,18 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2362
2363
|
n,
|
|
2363
2364
|
a,
|
|
2364
2365
|
o,
|
|
2365
|
-
|
|
2366
|
+
st(s, t.color),
|
|
2366
2367
|
f,
|
|
2367
2368
|
l,
|
|
2368
2369
|
h,
|
|
2369
2370
|
c,
|
|
2370
2371
|
e.isRotated
|
|
2371
2372
|
);
|
|
2372
|
-
},
|
|
2373
|
-
|
|
2374
|
-
|
|
2373
|
+
}, Kt = (s, t) => {
|
|
2374
|
+
X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
|
|
2375
|
+
Rt(s, t);
|
|
2375
2376
|
});
|
|
2376
|
-
},
|
|
2377
|
-
const e = s.particleRegion;
|
|
2378
|
-
s.enterRegion(e, t.shader);
|
|
2379
|
-
const i = t.texture, r = i.uvX, n = i.uvY, a = i.uvW, o = i.uvH;
|
|
2380
|
-
e.drawParticle(
|
|
2381
|
-
i,
|
|
2382
|
-
t.x,
|
|
2383
|
-
t.y,
|
|
2384
|
-
t.scaleX,
|
|
2385
|
-
t.scaleY,
|
|
2386
|
-
t.rotation,
|
|
2387
|
-
r,
|
|
2388
|
-
n,
|
|
2389
|
-
a,
|
|
2390
|
-
o,
|
|
2391
|
-
J(s, t.color),
|
|
2392
|
-
t.flipX,
|
|
2393
|
-
t.flipY,
|
|
2394
|
-
t.isRotated,
|
|
2395
|
-
t.originX,
|
|
2396
|
-
t.originY
|
|
2397
|
-
);
|
|
2398
|
-
}, Qt = (s, t) => {
|
|
2377
|
+
}, qt = (s, t) => {
|
|
2399
2378
|
const e = s.particleRegion;
|
|
2400
2379
|
s.enterRegion(e, t.shader);
|
|
2401
2380
|
const i = t.texture, r = t.count ?? t.x.length, n = t.color, a = n.length, o = new Array(a);
|
|
@@ -2424,8 +2403,8 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2424
2403
|
t.originX,
|
|
2425
2404
|
t.originY
|
|
2426
2405
|
);
|
|
2427
|
-
},
|
|
2428
|
-
t.points.length !== 0 &&
|
|
2406
|
+
}, Et = (s, t) => {
|
|
2407
|
+
t.points.length !== 0 && X(s, t, 0, 0, () => {
|
|
2429
2408
|
s.startGraphic(
|
|
2430
2409
|
t.drawMode ?? s.gl.TRIANGLES,
|
|
2431
2410
|
t.texture,
|
|
@@ -2439,31 +2418,31 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2439
2418
|
i.y,
|
|
2440
2419
|
r?.x ?? 0,
|
|
2441
2420
|
r?.y ?? 0,
|
|
2442
|
-
|
|
2421
|
+
st(s, n)
|
|
2443
2422
|
);
|
|
2444
2423
|
}
|
|
2445
2424
|
s.endGraphic();
|
|
2446
2425
|
});
|
|
2447
|
-
},
|
|
2426
|
+
}, Zt = (s, t) => {
|
|
2448
2427
|
if (s.inCreateMask)
|
|
2449
2428
|
return;
|
|
2450
2429
|
const { vertices: e, uv: i } = jt(t);
|
|
2451
|
-
|
|
2430
|
+
Et(s, {
|
|
2452
2431
|
...t,
|
|
2453
2432
|
points: e,
|
|
2454
2433
|
uv: i,
|
|
2455
2434
|
drawMode: s.gl.TRIANGLES
|
|
2456
2435
|
});
|
|
2457
|
-
},
|
|
2458
|
-
|
|
2436
|
+
}, Qt = (s, t) => {
|
|
2437
|
+
X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
|
|
2459
2438
|
s.startMaskGraphic(
|
|
2460
2439
|
s.gl.TRIANGLE_FAN,
|
|
2461
2440
|
t.texture,
|
|
2462
2441
|
t.customMatrix
|
|
2463
2442
|
), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
|
|
2464
2443
|
});
|
|
2465
|
-
},
|
|
2466
|
-
|
|
2444
|
+
}, Jt = (s, t) => {
|
|
2445
|
+
X(s, t, t.width, t.height, () => {
|
|
2467
2446
|
s.startGraphic(
|
|
2468
2447
|
s.gl.TRIANGLE_FAN,
|
|
2469
2448
|
t.texture,
|
|
@@ -2471,19 +2450,19 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
|
|
|
2471
2450
|
t.customMatrix
|
|
2472
2451
|
), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
|
|
2473
2452
|
});
|
|
2474
|
-
},
|
|
2453
|
+
}, te = (s, t) => {
|
|
2475
2454
|
const e = t.segments ?? 32;
|
|
2476
|
-
|
|
2455
|
+
X(s, t, 0, 0, () => {
|
|
2477
2456
|
s.startGraphic(
|
|
2478
2457
|
s.gl.TRIANGLE_FAN,
|
|
2479
2458
|
void 0,
|
|
2480
2459
|
t.shader,
|
|
2481
2460
|
t.customMatrix
|
|
2482
2461
|
);
|
|
2483
|
-
const i =
|
|
2462
|
+
const i = st(s, t.color);
|
|
2484
2463
|
s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
|
|
2485
2464
|
});
|
|
2486
|
-
},
|
|
2465
|
+
}, lt = `#version 300 es\r
|
|
2487
2466
|
precision mediump float;\r
|
|
2488
2467
|
\r
|
|
2489
2468
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -2533,21 +2512,21 @@ void main(void) {\r
|
|
|
2533
2512
|
// CUSTOM_CODE_CALL\r
|
|
2534
2513
|
}\r
|
|
2535
2514
|
`;
|
|
2536
|
-
class
|
|
2515
|
+
class ee extends rt {
|
|
2537
2516
|
KEY = "AtlasSprite";
|
|
2538
2517
|
constructor(t) {
|
|
2539
2518
|
super(t);
|
|
2540
2519
|
}
|
|
2541
2520
|
createCustomShader(t) {
|
|
2542
|
-
const e =
|
|
2521
|
+
const e = W(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
2543
2522
|
return t.getGLShader(this, this.KEY, i, e);
|
|
2544
2523
|
}
|
|
2545
2524
|
createDefaultShader() {
|
|
2546
|
-
const t = this.rapid, e =
|
|
2525
|
+
const t = this.rapid, e = W(lt, t.maxTextureUnits), i = W($, t.maxTextureUnits);
|
|
2547
2526
|
return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
|
|
2548
2527
|
}
|
|
2549
2528
|
}
|
|
2550
|
-
const
|
|
2529
|
+
const dt = `#version 300 es\r
|
|
2551
2530
|
precision mediump float;\r
|
|
2552
2531
|
\r
|
|
2553
2532
|
// per-vertex\r
|
|
@@ -2588,7 +2567,7 @@ void main(void) {\r
|
|
|
2588
2567
|
\r
|
|
2589
2568
|
gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
|
|
2590
2569
|
}\r
|
|
2591
|
-
`,
|
|
2570
|
+
`, ft = `#version 300 es\r
|
|
2592
2571
|
precision mediump float;\r
|
|
2593
2572
|
\r
|
|
2594
2573
|
uniform sampler2D uTexture;\r
|
|
@@ -2604,18 +2583,18 @@ void main(void) {\r
|
|
|
2604
2583
|
\r
|
|
2605
2584
|
// CUSTOM_CODE_CALL\r
|
|
2606
2585
|
}\r
|
|
2607
|
-
`,
|
|
2608
|
-
class
|
|
2586
|
+
`, D = 48, mt = D / 4;
|
|
2587
|
+
class ie extends rt {
|
|
2609
2588
|
KEY = "ParticleSprite";
|
|
2610
2589
|
texture;
|
|
2611
2590
|
constructor(t) {
|
|
2612
2591
|
super(t);
|
|
2613
2592
|
}
|
|
2614
2593
|
createCustomShader(t) {
|
|
2615
|
-
return t.getGLShader(this, this.KEY,
|
|
2594
|
+
return t.getGLShader(this, this.KEY, dt, ft);
|
|
2616
2595
|
}
|
|
2617
2596
|
createDefaultShader() {
|
|
2618
|
-
const t =
|
|
2597
|
+
const t = ft, e = dt;
|
|
2619
2598
|
return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
|
|
2620
2599
|
}
|
|
2621
2600
|
enter(t) {
|
|
@@ -2624,53 +2603,46 @@ class se extends at {
|
|
|
2624
2603
|
createShader(t, e) {
|
|
2625
2604
|
const i = super.createShader(t, e);
|
|
2626
2605
|
return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
|
|
2627
|
-
{ name: "aPosition", size: 2, stride:
|
|
2628
|
-
{ name: "aScale", size: 2, stride:
|
|
2629
|
-
{ name: "aRotation", size: 1, stride:
|
|
2630
|
-
{ name: "aUVRect", size: 4, stride:
|
|
2631
|
-
{ name: "aColor", size: 4, type:
|
|
2632
|
-
{ name: "aOrigin", size: 2, stride:
|
|
2606
|
+
{ name: "aPosition", size: 2, stride: D, offset: 0, divisor: 1 },
|
|
2607
|
+
{ name: "aScale", size: 2, stride: D, offset: 8, divisor: 1 },
|
|
2608
|
+
{ name: "aRotation", size: 1, stride: D, offset: 16, divisor: 1 },
|
|
2609
|
+
{ name: "aUVRect", size: 4, stride: D, offset: 20, divisor: 1 },
|
|
2610
|
+
{ name: "aColor", size: 4, type: et, normalized: !0, stride: D, offset: 36, divisor: 1 },
|
|
2611
|
+
{ name: "aOrigin", size: 2, stride: D, offset: 40, divisor: 1 }
|
|
2633
2612
|
]), this.quadBuffer.bindBuffer(), i.setAttributes([
|
|
2634
2613
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2635
2614
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2636
2615
|
}
|
|
2637
|
-
|
|
2638
|
-
(this.instanceCount >= q || this.texture && t != this.texture) && this.flush(), t.glTexture && (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2639
|
-
const T = this.instanceBuffer, g = T.usedElemNum, w = t.rawWidth, b = t.rawHeight;
|
|
2640
|
-
T.resize(K);
|
|
2641
|
-
const A = T.float32, I = T.uint32;
|
|
2642
|
-
A[g] = e, A[g + 1] = i, A[g + 2] = r * (l ? -1 : 1) * w, A[g + 3] = n * (p ? -1 : 1) * b, A[g + 4] = a, x && (A[g + 4] += Math.PI / 2), A[g + 5] = o, A[g + 6] = h, A[g + 7] = c, A[g + 8] = u, I[g + 9] = f, A[g + 10] = v, A[g + 11] = R, T.usedElemNum += K, T.makeDirty(), this.instanceCount++;
|
|
2643
|
-
}
|
|
2644
|
-
drawParticles(t, e, i, r, n, a, o = 1, h = 1, c = 0, u = 0, f = 1, l = 1, p = !1, x = !1, v = !1, R = 0.5, T = 0.5) {
|
|
2616
|
+
drawParticles(t, e, i, r, n, a, o = 1, h = 1, c = 0, u = 0, f = 1, l = 1, p = !1, x = !1, g = !1, T = 0.5, y = 0.5) {
|
|
2645
2617
|
if (!t.glTexture || a <= 0) return;
|
|
2646
|
-
let
|
|
2647
|
-
const
|
|
2648
|
-
for (;
|
|
2618
|
+
let w = 0;
|
|
2619
|
+
const M = t.rawWidth * o * (p ? -1 : 1), A = t.rawHeight * h * (x ? -1 : 1), F = g ? Math.PI / 2 : 0;
|
|
2620
|
+
for (; w < a; ) {
|
|
2649
2621
|
this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2650
|
-
const I = a -
|
|
2651
|
-
let
|
|
2652
|
-
|
|
2653
|
-
const
|
|
2654
|
-
for (let
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2622
|
+
const I = a - w, N = this.instanceBuffer;
|
|
2623
|
+
let S = N.usedElemNum;
|
|
2624
|
+
N.resize(I * mt);
|
|
2625
|
+
const R = N.float32, b = N.uint32;
|
|
2626
|
+
for (let U = 0; U < I; U++) {
|
|
2627
|
+
const L = w + U;
|
|
2628
|
+
R[S] = e[L], R[S + 1] = i[L], R[S + 2] = M, R[S + 3] = A, R[S + 4] = r[L] + F, R[S + 5] = c, R[S + 6] = u, R[S + 7] = f, R[S + 8] = l, b[S + 9] = n[L], R[S + 10] = T, R[S + 11] = y, S += mt;
|
|
2657
2629
|
}
|
|
2658
|
-
|
|
2630
|
+
N.usedElemNum = S, N.makeDirty(), this.instanceCount += I, w += I;
|
|
2659
2631
|
}
|
|
2660
2632
|
}
|
|
2661
2633
|
render() {
|
|
2662
2634
|
if (this.instanceCount === 0) return;
|
|
2663
|
-
|
|
2635
|
+
this.prepareRender();
|
|
2664
2636
|
const t = this.gl;
|
|
2665
2637
|
this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
|
|
2666
2638
|
const e = this.currentShader;
|
|
2667
2639
|
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
|
|
2668
|
-
const i =
|
|
2669
|
-
this.currentShader.setUniform("u_projection",
|
|
2640
|
+
const i = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(i.curWorldM), a = Vt(this.rapid.projection, n);
|
|
2641
|
+
this.currentShader.setUniform("u_projection", a), this.currentShader.setUniform("u_projection", this.rapid.projection), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0;
|
|
2670
2642
|
}
|
|
2671
2643
|
}
|
|
2672
|
-
var
|
|
2673
|
-
class
|
|
2644
|
+
var re = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(re || {}), se = /* @__PURE__ */ ((s) => (s[s.NORMAL = 0] = "NORMAL", s[s.ADD = 1] = "ADD", s[s.MULTIPLY = 2] = "MULTIPLY", s[s.SCREEN = 3] = "SCREEN", s[s.ERASE = 4] = "ERASE", s))(se || {}), it = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(it || {}), ne = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(ne || {});
|
|
2645
|
+
class ce {
|
|
2674
2646
|
/** The active WebGL context. */
|
|
2675
2647
|
gl;
|
|
2676
2648
|
/** The target HTMLCanvasElement. */
|
|
@@ -2696,7 +2668,7 @@ class le {
|
|
|
2696
2668
|
/** Maximum number of texture units supported by the device. */
|
|
2697
2669
|
maxTextureUnits = 0;
|
|
2698
2670
|
/** Matrix stack for hierarchical transformations. */
|
|
2699
|
-
matrixStack = new
|
|
2671
|
+
matrixStack = new St(this);
|
|
2700
2672
|
/** Direct access to the underlying matrix store. */
|
|
2701
2673
|
matrix;
|
|
2702
2674
|
/** Region dedicated to fast sprite rendering. */
|
|
@@ -2734,10 +2706,10 @@ class le {
|
|
|
2734
2706
|
*/
|
|
2735
2707
|
constructor(t) {
|
|
2736
2708
|
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;
|
|
2737
|
-
const e =
|
|
2738
|
-
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new
|
|
2709
|
+
const e = Ct(this.canvas, this.antialias, this.premultipliedAlpha);
|
|
2710
|
+
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new rt(this), this.graphicRegion = new Ht(this), this.atlasSpriteRegion = new ee(this), this.particleRegion = new ie(this);
|
|
2739
2711
|
const i = this.canvas.clientWidth || this.canvas.width, r = this.canvas.clientHeight || this.canvas.height;
|
|
2740
|
-
this.physicsWidth = t.physicsWidth || Math.round(i * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(r * 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
|
|
2712
|
+
this.physicsWidth = t.physicsWidth || Math.round(i * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(r * 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 bt(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);
|
|
2741
2713
|
}
|
|
2742
2714
|
setTextureFilter(t) {
|
|
2743
2715
|
this.textureFilter = t;
|
|
@@ -2756,26 +2728,23 @@ class le {
|
|
|
2756
2728
|
enterRegion(t, e) {
|
|
2757
2729
|
this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
|
|
2758
2730
|
}
|
|
2759
|
-
drawParticle(t) {
|
|
2760
|
-
Zt(this, t);
|
|
2761
|
-
}
|
|
2762
2731
|
drawParticles(t) {
|
|
2763
|
-
|
|
2732
|
+
qt(this, t), this.flush();
|
|
2764
2733
|
}
|
|
2765
2734
|
drawSprite(t) {
|
|
2766
|
-
|
|
2735
|
+
Kt(this, t);
|
|
2767
2736
|
}
|
|
2768
2737
|
drawLine(t) {
|
|
2769
|
-
|
|
2738
|
+
Zt(this, t);
|
|
2770
2739
|
}
|
|
2771
2740
|
drawGraphic(t) {
|
|
2772
|
-
|
|
2741
|
+
Et(this, t);
|
|
2773
2742
|
}
|
|
2774
2743
|
drawRect(t) {
|
|
2775
|
-
|
|
2744
|
+
Jt(this, t);
|
|
2776
2745
|
}
|
|
2777
2746
|
drawCircle(t) {
|
|
2778
|
-
|
|
2747
|
+
te(this, t);
|
|
2779
2748
|
}
|
|
2780
2749
|
/**
|
|
2781
2750
|
* Starts rendering arbitrary graphics geometries.
|
|
@@ -2799,7 +2768,7 @@ class le {
|
|
|
2799
2768
|
* @param texture The texture to be used as a mask.
|
|
2800
2769
|
*/
|
|
2801
2770
|
drawMaskImage(t) {
|
|
2802
|
-
|
|
2771
|
+
Qt(this, t);
|
|
2803
2772
|
}
|
|
2804
2773
|
/**
|
|
2805
2774
|
* Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
|
|
@@ -3204,7 +3173,7 @@ class le {
|
|
|
3204
3173
|
return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, i);
|
|
3205
3174
|
}
|
|
3206
3175
|
}
|
|
3207
|
-
function
|
|
3176
|
+
function ae(s) {
|
|
3208
3177
|
return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof d || s instanceof m);
|
|
3209
3178
|
}
|
|
3210
3179
|
class C {
|
|
@@ -3270,9 +3239,9 @@ class C {
|
|
|
3270
3239
|
return typeof t == "number" ? t : t.clone();
|
|
3271
3240
|
}
|
|
3272
3241
|
}
|
|
3273
|
-
var
|
|
3274
|
-
const
|
|
3275
|
-
class
|
|
3242
|
+
var he = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(he || {});
|
|
3243
|
+
const xt = 10, pt = 0, gt = !0;
|
|
3244
|
+
class oe {
|
|
3276
3245
|
life = 0;
|
|
3277
3246
|
maxLife;
|
|
3278
3247
|
texture;
|
|
@@ -3292,7 +3261,7 @@ class ue {
|
|
|
3292
3261
|
processAttribute(t, e) {
|
|
3293
3262
|
if (t == null)
|
|
3294
3263
|
return { value: e };
|
|
3295
|
-
if (
|
|
3264
|
+
if (ae(t)) {
|
|
3296
3265
|
const i = t, r = C.scalarOrRange(i.start, e), n = i.end === void 0 ? r : C.scalarOrRange(i.end, e);
|
|
3297
3266
|
return {
|
|
3298
3267
|
delta: i.delta ?? this.getDelta(r, n, this.maxLife),
|
|
@@ -3336,7 +3305,7 @@ class ue {
|
|
|
3336
3305
|
const t = this.rapid.matrixStack, e = this.datas.scale.value, i = this.datas.rotation.value, r = this.datas.color.value;
|
|
3337
3306
|
t.save(), t.translate(this.position.x, this.position.y), i !== 0 && t.rotate(i), e !== 1 && t.scale(e, e);
|
|
3338
3307
|
const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
|
|
3339
|
-
(n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight),
|
|
3308
|
+
(n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(this.rapid, { texture: this.texture, color: r }), t.restore();
|
|
3340
3309
|
}
|
|
3341
3310
|
initializePosition() {
|
|
3342
3311
|
switch (this.options.emitShape) {
|
|
@@ -3359,16 +3328,16 @@ class ue {
|
|
|
3359
3328
|
!this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
|
|
3360
3329
|
}
|
|
3361
3330
|
}
|
|
3362
|
-
class
|
|
3331
|
+
class wt {
|
|
3363
3332
|
particles = [];
|
|
3364
3333
|
options;
|
|
3365
3334
|
emitting = !1;
|
|
3366
3335
|
emitTimer = 0;
|
|
3367
|
-
emitRate =
|
|
3368
|
-
emitTime =
|
|
3336
|
+
emitRate = xt;
|
|
3337
|
+
emitTime = pt;
|
|
3369
3338
|
emitTimeCounter = 0;
|
|
3370
3339
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3371
|
-
localSpace =
|
|
3340
|
+
localSpace = gt;
|
|
3372
3341
|
/** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
|
|
3373
3342
|
position = d.ZERO;
|
|
3374
3343
|
rapid;
|
|
@@ -3379,7 +3348,7 @@ class Mt {
|
|
|
3379
3348
|
* @param options - Emitter configuration options
|
|
3380
3349
|
*/
|
|
3381
3350
|
constructor(t, e) {
|
|
3382
|
-
this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate :
|
|
3351
|
+
this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : xt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : pt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : gt, this.position = e.position ?? d.ZERO;
|
|
3383
3352
|
}
|
|
3384
3353
|
/** Replaces the emitter's texture at runtime. */
|
|
3385
3354
|
setTexture(t) {
|
|
@@ -3390,7 +3359,7 @@ class Mt {
|
|
|
3390
3359
|
* Particle state is NOT copied.
|
|
3391
3360
|
*/
|
|
3392
3361
|
clone() {
|
|
3393
|
-
return new
|
|
3362
|
+
return new wt(this.rapid, { ...this.options });
|
|
3394
3363
|
}
|
|
3395
3364
|
/** Sets particles-per-second emission rate (continuous mode). */
|
|
3396
3365
|
setEmitRate(t) {
|
|
@@ -3419,7 +3388,7 @@ class Mt {
|
|
|
3419
3388
|
emit(t) {
|
|
3420
3389
|
const e = this.options.maxParticles ?? 1 / 0, i = Math.min(t, e - this.particles.length);
|
|
3421
3390
|
for (let r = 0; r < i; r++)
|
|
3422
|
-
this.particles.push(new
|
|
3391
|
+
this.particles.push(new oe(this.rapid, { ...this.options, position: this.position }));
|
|
3423
3392
|
}
|
|
3424
3393
|
/**
|
|
3425
3394
|
* Updates the emitter and all live particles.
|
|
@@ -3467,44 +3436,42 @@ class Mt {
|
|
|
3467
3436
|
}
|
|
3468
3437
|
}
|
|
3469
3438
|
export {
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3439
|
+
O as ArrayType,
|
|
3440
|
+
k as BaseTexture,
|
|
3441
|
+
se as BlendMode,
|
|
3442
|
+
ne as CanvasScaleMode,
|
|
3474
3443
|
m as Color,
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
Ct as TextTexture,
|
|
3444
|
+
ot as CustomGlShader,
|
|
3445
|
+
B as DynamicArrayBuffer,
|
|
3446
|
+
Tt as GLShader,
|
|
3447
|
+
Ht as GraphicRegion,
|
|
3448
|
+
Yt as LineTextureMode,
|
|
3449
|
+
re as MaskType,
|
|
3450
|
+
St as MatrixStack,
|
|
3451
|
+
Mt as MatrixStore,
|
|
3452
|
+
oe as Particle,
|
|
3453
|
+
wt as ParticleEmitter,
|
|
3454
|
+
he as ParticleShape,
|
|
3455
|
+
Ft as QUAD_VERTICES,
|
|
3456
|
+
ce as Rapid,
|
|
3457
|
+
yt as Region,
|
|
3458
|
+
At as RenderTexture,
|
|
3459
|
+
rt as SpriteRegion,
|
|
3460
|
+
_t as TextTexture,
|
|
3493
3461
|
P as Texture,
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3462
|
+
it as TextureFilterMode,
|
|
3463
|
+
bt as TextureManager,
|
|
3464
|
+
Y as TextureWrapMode,
|
|
3497
3465
|
d as Vec2,
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
Et as drawSpriteRaw,
|
|
3466
|
+
Q as WebglBufferArray,
|
|
3467
|
+
Vt as composeProjectionWithAffine,
|
|
3468
|
+
te as drawCircle,
|
|
3469
|
+
Et as drawGraphic,
|
|
3470
|
+
Zt as drawLine,
|
|
3471
|
+
Qt as drawMaskImage,
|
|
3472
|
+
qt as drawParticles,
|
|
3473
|
+
Jt as drawRect,
|
|
3474
|
+
Kt as drawSprite,
|
|
3475
|
+
Rt as drawSpriteRaw,
|
|
3509
3476
|
zt as multiplyMat4
|
|
3510
3477
|
};
|