rapid-render 1.0.8 → 1.0.10
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 +8 -4
- package/dist/rapid-render.js +233 -246
- package/dist/rapid-render.umd.cjs +6 -6
- package/dist/render.d.ts +1 -1
- package/dist/texture.d.ts +1 -1
- package/dist/webgl/glshader.d.ts +1 -0
- package/package.json +1 -1
package/dist/rapid-render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
class
|
|
1
|
+
var b = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(b || {});
|
|
2
|
+
class _ {
|
|
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. */
|
|
@@ -172,7 +172,7 @@ class C {
|
|
|
172
172
|
this.usedElemNum = 0;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
class et extends
|
|
175
|
+
class et extends _ {
|
|
176
176
|
/** The actual WebGLBuffer object maintained by this instance. */
|
|
177
177
|
buffer;
|
|
178
178
|
/** The related WebGL rendering context. */
|
|
@@ -223,7 +223,7 @@ class et extends C {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
class
|
|
226
|
+
class x {
|
|
227
227
|
_r;
|
|
228
228
|
_g;
|
|
229
229
|
_b;
|
|
@@ -304,7 +304,7 @@ class m {
|
|
|
304
304
|
*/
|
|
305
305
|
updateUint() {
|
|
306
306
|
this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
|
|
307
|
-
const t =
|
|
307
|
+
const t = x.clampByte(this._a), e = x.clampByte(this._r * t / 255), r = x.clampByte(this._g * t / 255), i = x.clampByte(this._b * t / 255);
|
|
308
308
|
this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
|
|
309
309
|
}
|
|
310
310
|
reset() {
|
|
@@ -342,7 +342,7 @@ class m {
|
|
|
342
342
|
* @returns A new `Color` instance with the same RGBA values.
|
|
343
343
|
*/
|
|
344
344
|
clone() {
|
|
345
|
-
return new
|
|
345
|
+
return new x(this._r, this._g, this._b, this._a);
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
348
|
* Converts the color to a hexadecimal string representation (e.g., '#RRGGBBAA').
|
|
@@ -376,13 +376,13 @@ class m {
|
|
|
376
376
|
* Color.fromNorm(0.9, 0.87, 0.55, 0.1) // moon glow
|
|
377
377
|
*/
|
|
378
378
|
static FromHSL(t, e, r) {
|
|
379
|
-
return new
|
|
379
|
+
return new x(0, 0, 0).setHSL(t, e, r);
|
|
380
380
|
}
|
|
381
381
|
static FromRGB(t, e, r) {
|
|
382
|
-
return new
|
|
382
|
+
return new x(t, e, r);
|
|
383
383
|
}
|
|
384
384
|
static fromNorm(t, e, r, i = 1) {
|
|
385
|
-
return new
|
|
385
|
+
return new x(
|
|
386
386
|
Math.round(t * 255),
|
|
387
387
|
Math.round(e * 255),
|
|
388
388
|
Math.round(r * 255),
|
|
@@ -393,7 +393,7 @@ class m {
|
|
|
393
393
|
return t <= 0 ? 0 : t >= 255 ? 255 : Math.round(t);
|
|
394
394
|
}
|
|
395
395
|
static packColor(t, e, r, i, s) {
|
|
396
|
-
const a =
|
|
396
|
+
const a = x.clampColorByte(i), o = s ? a / 255 : 1, h = x.clampColorByte(t * o), c = x.clampColorByte(e * o), u = x.clampColorByte(r * o);
|
|
397
397
|
return (a << 24 | u << 16 | c << 8 | h) >>> 0;
|
|
398
398
|
}
|
|
399
399
|
/**
|
|
@@ -405,7 +405,7 @@ class m {
|
|
|
405
405
|
t.startsWith("#") && (t = t.slice(1));
|
|
406
406
|
const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
|
|
407
407
|
let s = 255;
|
|
408
|
-
return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new
|
|
408
|
+
return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new x(e, r, i, s);
|
|
409
409
|
}
|
|
410
410
|
/**
|
|
411
411
|
* Adds the components of another color to this color, clamping the result to 255.
|
|
@@ -413,7 +413,7 @@ class m {
|
|
|
413
413
|
* @returns A new Color instance with the result of the addition.
|
|
414
414
|
*/
|
|
415
415
|
add(t) {
|
|
416
|
-
return new
|
|
416
|
+
return new x(
|
|
417
417
|
Math.min(this.r + t.r, 255),
|
|
418
418
|
Math.min(this.g + t.g, 255),
|
|
419
419
|
Math.min(this.b + t.b, 255),
|
|
@@ -426,7 +426,7 @@ class m {
|
|
|
426
426
|
* @returns A new Color instance with the result of the subtraction.
|
|
427
427
|
*/
|
|
428
428
|
subtract(t) {
|
|
429
|
-
return new
|
|
429
|
+
return new x(
|
|
430
430
|
this.r - t.r,
|
|
431
431
|
this.g - t.g,
|
|
432
432
|
this.b - t.b,
|
|
@@ -434,12 +434,12 @@ class m {
|
|
|
434
434
|
);
|
|
435
435
|
}
|
|
436
436
|
divide(t) {
|
|
437
|
-
return t instanceof
|
|
437
|
+
return t instanceof x ? new x(
|
|
438
438
|
this.r / t.r,
|
|
439
439
|
this.g / t.g,
|
|
440
440
|
this.b / t.b,
|
|
441
441
|
this.a / t.a
|
|
442
|
-
) : new
|
|
442
|
+
) : new x(
|
|
443
443
|
this.r / t,
|
|
444
444
|
this.g / t,
|
|
445
445
|
this.b / t,
|
|
@@ -447,12 +447,12 @@ class m {
|
|
|
447
447
|
);
|
|
448
448
|
}
|
|
449
449
|
multiply(t) {
|
|
450
|
-
return t instanceof
|
|
450
|
+
return t instanceof x ? new x(
|
|
451
451
|
this.r * t.r,
|
|
452
452
|
this.g * t.g,
|
|
453
453
|
this.b * t.b,
|
|
454
454
|
this.a * t.a
|
|
455
|
-
) : new
|
|
455
|
+
) : new x(
|
|
456
456
|
this.r * t,
|
|
457
457
|
this.g * t,
|
|
458
458
|
this.b * t,
|
|
@@ -462,25 +462,25 @@ class m {
|
|
|
462
462
|
clamp() {
|
|
463
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));
|
|
464
464
|
}
|
|
465
|
-
static Red = new
|
|
466
|
-
static Green = new
|
|
467
|
-
static Blue = new
|
|
468
|
-
static Yellow = new
|
|
469
|
-
static Purple = new
|
|
470
|
-
static Orange = new
|
|
471
|
-
static Pink = new
|
|
472
|
-
static Gray = new
|
|
473
|
-
static Brown = new
|
|
474
|
-
static Cyan = new
|
|
475
|
-
static Magenta = new
|
|
476
|
-
static Lime = new
|
|
477
|
-
static White = new
|
|
478
|
-
static Black = new
|
|
479
|
-
static Transparent = new
|
|
480
|
-
static TRANSPARENT = new
|
|
465
|
+
static Red = new x(255, 0, 0, 255);
|
|
466
|
+
static Green = new x(0, 255, 0, 255);
|
|
467
|
+
static Blue = new x(0, 0, 255, 255);
|
|
468
|
+
static Yellow = new x(255, 255, 0, 255);
|
|
469
|
+
static Purple = new x(128, 0, 128, 255);
|
|
470
|
+
static Orange = new x(255, 165, 0, 255);
|
|
471
|
+
static Pink = new x(255, 192, 203, 255);
|
|
472
|
+
static Gray = new x(128, 128, 128, 255);
|
|
473
|
+
static Brown = new x(139, 69, 19, 255);
|
|
474
|
+
static Cyan = new x(0, 255, 255, 255);
|
|
475
|
+
static Magenta = new x(255, 0, 255, 255);
|
|
476
|
+
static Lime = new x(192, 255, 0, 255);
|
|
477
|
+
static White = new x(255, 255, 255, 255);
|
|
478
|
+
static Black = new x(0, 0, 0, 255);
|
|
479
|
+
static Transparent = new x(0, 0, 0, 0);
|
|
480
|
+
static TRANSPARENT = new x(0, 0, 0, 0);
|
|
481
481
|
}
|
|
482
482
|
const E = 6;
|
|
483
|
-
class
|
|
483
|
+
class wt {
|
|
484
484
|
/** Total number of matrices currently allocated in the store. */
|
|
485
485
|
matrixCount = 0;
|
|
486
486
|
/** The dynamic buffer used to hold matrix data. */
|
|
@@ -493,7 +493,7 @@ class Mt {
|
|
|
493
493
|
* @param capacity - The initial capacity of the matrix store (default is 10).
|
|
494
494
|
*/
|
|
495
495
|
constructor(t = 10) {
|
|
496
|
-
this.buffer = new
|
|
496
|
+
this.buffer = new _(b.Float32), this.buffer.resize(t * E), this.data = this.buffer.getArray(), this.reset();
|
|
497
497
|
}
|
|
498
498
|
/**
|
|
499
499
|
* Allocates a new matrix and initializes it to the identity matrix.
|
|
@@ -596,8 +596,8 @@ class Mt {
|
|
|
596
596
|
* @param bIdx - The index of matrix B.
|
|
597
597
|
*/
|
|
598
598
|
multiplyOut(t, e, r) {
|
|
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],
|
|
600
|
-
o[i] = h *
|
|
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], m = o[a], g = o[a + 1], v = o[a + 2], y = o[a + 3], R = o[a + 4], A = o[a + 5];
|
|
600
|
+
o[i] = h * m + u * g, o[i + 1] = c * m + l * g, o[i + 2] = h * v + u * y, o[i + 3] = c * v + l * y, o[i + 4] = h * R + u * A + d, o[i + 5] = c * R + l * A + f;
|
|
601
601
|
}
|
|
602
602
|
/**
|
|
603
603
|
* Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
|
|
@@ -721,29 +721,29 @@ class Mt {
|
|
|
721
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];
|
|
722
722
|
}
|
|
723
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],
|
|
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 +
|
|
724
|
+
const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = 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 + m, c[h + 5] = l * a + f * o + g;
|
|
726
726
|
}
|
|
727
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],
|
|
729
|
-
l[u] = d * r +
|
|
728
|
+
const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], g = l[c + 3], v = l[c + 4], y = l[c + 5];
|
|
729
|
+
l[u] = d * r + m * i, l[u + 1] = f * r + g * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + g * a, l[u + 4] = d * o + m * h + v, l[u + 5] = f * o + g * h + y;
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
732
|
class At {
|
|
733
733
|
/** The underlying store for matrices. */
|
|
734
|
-
matrix = new
|
|
734
|
+
matrix = new wt();
|
|
735
735
|
/** The current step or depth in the transformation hierarchy. */
|
|
736
736
|
step = 0;
|
|
737
737
|
/** Internal stack maintaining structural information. */
|
|
738
|
-
stack = new
|
|
738
|
+
stack = new _(b.Uint32);
|
|
739
739
|
/** Records the world matrices generated at each step. */
|
|
740
|
-
stepWorldM = new
|
|
740
|
+
stepWorldM = new _(b.Uint32);
|
|
741
741
|
/** Records actions (push/pop) taken during the traversal. */
|
|
742
|
-
stepAction = new
|
|
742
|
+
stepAction = new _(b.Uint32);
|
|
743
743
|
/** Records the parent world matrix for each step (used by updateMatrix). */
|
|
744
|
-
stepParentM = new
|
|
744
|
+
stepParentM = new _(b.Uint32);
|
|
745
745
|
/** Buffer used during hierarchy traversal updates. */
|
|
746
|
-
parentStack = new
|
|
746
|
+
parentStack = new _(b.Uint32);
|
|
747
747
|
/** The index of the current local matrix in the matrix store. */
|
|
748
748
|
curLocalM = -1;
|
|
749
749
|
/** The index of the current world matrix in the matrix store. */
|
|
@@ -763,30 +763,29 @@ class At {
|
|
|
763
763
|
save() {
|
|
764
764
|
this.stack.push(this.curWorldM);
|
|
765
765
|
const t = this.curWorldM;
|
|
766
|
-
return this.
|
|
766
|
+
return this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.allocDirty(), this.stepWorldM.push(this.curWorldM), this.stepParentM.push(t), this.stepAction.push(1), this.matrix.copy(this.curWorldM, t), { world: this.curWorldM, local: this.curLocalM, step: this.step++ };
|
|
767
767
|
}
|
|
768
768
|
/**
|
|
769
769
|
* Restores the matrix state from the top of the stack.
|
|
770
770
|
* Equivalent to context.restore().
|
|
771
771
|
*/
|
|
772
772
|
restore() {
|
|
773
|
-
this.stack.length != 0 && (this.curWorldM = this.stack.pop(), this.curLocalM = this.curWorldM - 1, this.stepAction.push(0));
|
|
773
|
+
this.stack.length != 0 && (this.curWorldM = this.stack.pop(), this.curLocalM = this.curWorldM - 1, this.stepParentM.push(this.stack.get(this.stack.length - 1)), this.stepWorldM.push(this.curWorldM), this.stepAction.push(0), this.step++);
|
|
774
774
|
}
|
|
775
775
|
/**
|
|
776
776
|
* Evaluates and updates matrices from the given step. Used primarily for deferred transformation.
|
|
777
777
|
* @param step - The initial step to update matrices from.
|
|
778
778
|
*/
|
|
779
779
|
updateMatrix(t) {
|
|
780
|
-
const e =
|
|
781
|
-
let
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
} else if (a.pop(), i--, i === 0)
|
|
780
|
+
const e = typeof t == "number" ? t : t.step;
|
|
781
|
+
let r = 0, i = e;
|
|
782
|
+
for (; i < this.step; ) {
|
|
783
|
+
if (this.stepAction.get(i) === 1) {
|
|
784
|
+
const a = this.stepWorldM.get(i), o = a - 1, h = this.stepParentM.get(i);
|
|
785
|
+
this.matrix.multiplyOut(a, h, o), r++;
|
|
786
|
+
} else if (r--, r === 0)
|
|
788
787
|
break;
|
|
789
|
-
|
|
788
|
+
i++;
|
|
790
789
|
}
|
|
791
790
|
}
|
|
792
791
|
/**
|
|
@@ -920,36 +919,36 @@ class At {
|
|
|
920
919
|
t.offset && (l += t.offset.x, d += t.offset.y);
|
|
921
920
|
const f = t.origin;
|
|
922
921
|
f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
|
|
923
|
-
const
|
|
922
|
+
const m = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = m * o, y = g * o, R = -g * h, A = m * h, P = s + v * l + R * d, U = a + y * l + A * d;
|
|
924
923
|
if (i !== -1) {
|
|
925
924
|
this.matrix.multiplyAffine(
|
|
926
925
|
this.curWorldM,
|
|
927
926
|
i,
|
|
928
927
|
v,
|
|
929
|
-
|
|
930
|
-
A,
|
|
928
|
+
y,
|
|
931
929
|
R,
|
|
932
|
-
|
|
933
|
-
P
|
|
930
|
+
A,
|
|
931
|
+
P,
|
|
932
|
+
U
|
|
934
933
|
);
|
|
935
934
|
return;
|
|
936
935
|
}
|
|
937
936
|
this.matrix.multiplyAffineInPlace(
|
|
938
937
|
this.curLocalM,
|
|
939
938
|
v,
|
|
940
|
-
|
|
941
|
-
A,
|
|
939
|
+
y,
|
|
942
940
|
R,
|
|
943
|
-
|
|
944
|
-
P
|
|
941
|
+
A,
|
|
942
|
+
P,
|
|
943
|
+
U
|
|
945
944
|
), this.matrix.multiplyAffineInPlace(
|
|
946
945
|
this.curWorldM,
|
|
947
946
|
v,
|
|
948
|
-
|
|
949
|
-
A,
|
|
947
|
+
y,
|
|
950
948
|
R,
|
|
951
|
-
|
|
952
|
-
P
|
|
949
|
+
A,
|
|
950
|
+
P,
|
|
951
|
+
U
|
|
953
952
|
);
|
|
954
953
|
}
|
|
955
954
|
}
|
|
@@ -969,10 +968,10 @@ class St {
|
|
|
969
968
|
async load(t, e) {
|
|
970
969
|
let r = this.cache.get(t);
|
|
971
970
|
if (r)
|
|
972
|
-
return new
|
|
971
|
+
return new W(r);
|
|
973
972
|
try {
|
|
974
973
|
const i = await this._fetchImage(t);
|
|
975
|
-
return r =
|
|
974
|
+
return r = X.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new W(r);
|
|
976
975
|
} catch (i) {
|
|
977
976
|
throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
|
|
978
977
|
}
|
|
@@ -985,9 +984,9 @@ class St {
|
|
|
985
984
|
*/
|
|
986
985
|
create(t, e) {
|
|
987
986
|
if (e?.key && this.cache.has(e.key))
|
|
988
|
-
return new
|
|
989
|
-
const r =
|
|
990
|
-
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new
|
|
987
|
+
return new W(this.cache.get(e.key));
|
|
988
|
+
const r = X.fromSource(this.render, t, e);
|
|
989
|
+
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new W(r);
|
|
991
990
|
}
|
|
992
991
|
/**
|
|
993
992
|
* Creates a generic Render Texture (FrameBuffer).
|
|
@@ -1016,7 +1015,7 @@ class St {
|
|
|
1016
1015
|
*/
|
|
1017
1016
|
destroy(t, e = !1) {
|
|
1018
1017
|
let r, i;
|
|
1019
|
-
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof
|
|
1018
|
+
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof W ? (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));
|
|
1020
1019
|
}
|
|
1021
1020
|
/**
|
|
1022
1021
|
* Destroys all cached textures and clears the cache, ignoring reference counts.
|
|
@@ -1033,7 +1032,7 @@ class St {
|
|
|
1033
1032
|
});
|
|
1034
1033
|
}
|
|
1035
1034
|
}
|
|
1036
|
-
class
|
|
1035
|
+
class X {
|
|
1037
1036
|
glTexture = null;
|
|
1038
1037
|
width;
|
|
1039
1038
|
height;
|
|
@@ -1051,7 +1050,7 @@ class Y {
|
|
|
1051
1050
|
*/
|
|
1052
1051
|
static fromSource(t, e, r = {}) {
|
|
1053
1052
|
const i = J(t, e, r);
|
|
1054
|
-
return new
|
|
1053
|
+
return new X(i, e.width, e.height);
|
|
1055
1054
|
}
|
|
1056
1055
|
/**
|
|
1057
1056
|
* Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
|
|
@@ -1082,7 +1081,7 @@ class Y {
|
|
|
1082
1081
|
this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
|
|
1083
1082
|
}
|
|
1084
1083
|
}
|
|
1085
|
-
class
|
|
1084
|
+
class W {
|
|
1086
1085
|
base;
|
|
1087
1086
|
uvX = 0;
|
|
1088
1087
|
uvY = 0;
|
|
@@ -1128,7 +1127,7 @@ class F {
|
|
|
1128
1127
|
* @returns The current Texture instance.
|
|
1129
1128
|
*/
|
|
1130
1129
|
setRegion(t, e, r, i) {
|
|
1131
|
-
return this.base ? (this._px = t, this._py = e, this._pw = r, this._ph = i, this.isAtlas = t !== 0 || e !== 0 || r !== this.base.width || i !== this.base.height, this.uvX = t / this.base.width, this.uvY = e / this.base.height, this.uvW = this.uvX + r / this.base.width, this.uvH = this.uvY + i / this.base.height, this.rawWidth = r, this.rawHeight = i, this) : this;
|
|
1130
|
+
return this.base ? (this._px = t, this._py = e, this._pw = r, this._ph = i, this.isAtlas = t !== 0 || e !== 0 || r !== this.base.width || i !== this.base.height, this.uvX = t / this.base.width, this.uvY = e / this.base.height, this.uvW = this.uvX + r / this.base.width, this.uvH = this.uvY + i / this.base.height, this.rawWidth = r * this.scale, this.rawHeight = i * this.scale, this) : this;
|
|
1132
1131
|
}
|
|
1133
1132
|
/**
|
|
1134
1133
|
* Creates a new Texture representing a sub-region of this Texture.
|
|
@@ -1139,7 +1138,7 @@ class F {
|
|
|
1139
1138
|
* @returns A new Texture pointing to the sub-region.
|
|
1140
1139
|
*/
|
|
1141
1140
|
getSubTexture(t, e, r, i) {
|
|
1142
|
-
if (!this.base) return new
|
|
1141
|
+
if (!this.base) return new W();
|
|
1143
1142
|
const s = this.clone(), a = this._px, o = this._py;
|
|
1144
1143
|
return s.setRegion(a + t, o + e, r, i), s;
|
|
1145
1144
|
}
|
|
@@ -1148,7 +1147,7 @@ class F {
|
|
|
1148
1147
|
* @returns A new Texture instance.
|
|
1149
1148
|
*/
|
|
1150
1149
|
clone(t) {
|
|
1151
|
-
const e = t ?? new
|
|
1150
|
+
const e = t ?? new W(this.base);
|
|
1152
1151
|
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;
|
|
1153
1152
|
}
|
|
1154
1153
|
/**
|
|
@@ -1164,9 +1163,9 @@ class F {
|
|
|
1164
1163
|
splitGrid(t, e, r, i, s = 0) {
|
|
1165
1164
|
if (!this.base) return [];
|
|
1166
1165
|
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);
|
|
1167
|
-
for (let
|
|
1166
|
+
for (let m = 0; m < f; m++)
|
|
1168
1167
|
for (let g = 0; g < d; g++)
|
|
1169
|
-
a.push(this.getSubTexture(g * u,
|
|
1168
|
+
a.push(this.getSubTexture(g * u, m * l, t, e));
|
|
1170
1169
|
return a;
|
|
1171
1170
|
}
|
|
1172
1171
|
/**
|
|
@@ -1176,7 +1175,7 @@ class F {
|
|
|
1176
1175
|
*/
|
|
1177
1176
|
static fromImageSource(t, e, r = {}) {
|
|
1178
1177
|
const i = J(t, e, r);
|
|
1179
|
-
return new
|
|
1178
|
+
return new W(new X(i, e.width, e.height));
|
|
1180
1179
|
}
|
|
1181
1180
|
/**
|
|
1182
1181
|
* Marks this Texture as destroyed, decrementing the BaseTexture reference count.
|
|
@@ -1185,7 +1184,7 @@ class F {
|
|
|
1185
1184
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
1186
1185
|
}
|
|
1187
1186
|
}
|
|
1188
|
-
class bt extends
|
|
1187
|
+
class bt extends W {
|
|
1189
1188
|
framebuffer;
|
|
1190
1189
|
renderbuffer;
|
|
1191
1190
|
gl;
|
|
@@ -1195,9 +1194,9 @@ class bt extends F {
|
|
|
1195
1194
|
_allocW = 0;
|
|
1196
1195
|
_allocH = 0;
|
|
1197
1196
|
constructor(t, e) {
|
|
1198
|
-
super(), this.gl = t.gl, this.clearColor = e.clearColor ??
|
|
1197
|
+
super(), this.gl = t.gl, this.clearColor = e.clearColor ?? x.Black;
|
|
1199
1198
|
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
|
|
1199
|
+
if (this.setBase(new X(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
1201
1200
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
1202
1201
|
this.resize(r, i, !0);
|
|
1203
1202
|
}
|
|
@@ -1256,8 +1255,8 @@ class bt extends F {
|
|
|
1256
1255
|
return new Uint8Array(0);
|
|
1257
1256
|
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);
|
|
1258
1257
|
d.bindFramebuffer(d.FRAMEBUFFER, this.framebuffer);
|
|
1259
|
-
const
|
|
1260
|
-
return d.readPixels(s, l, c, u, d.RGBA, d.UNSIGNED_BYTE,
|
|
1258
|
+
const m = new Uint8Array(c * u * 4);
|
|
1259
|
+
return d.readPixels(s, l, c, u, d.RGBA, d.UNSIGNED_BYTE, m), d.bindFramebuffer(d.FRAMEBUFFER, f), m;
|
|
1261
1260
|
}
|
|
1262
1261
|
/**
|
|
1263
1262
|
* Get the color at a pixel in the render texture.
|
|
@@ -1266,7 +1265,7 @@ class bt extends F {
|
|
|
1266
1265
|
*/
|
|
1267
1266
|
GetColorAt(t, e) {
|
|
1268
1267
|
const r = this.GetPixels(t, e, 1, 1);
|
|
1269
|
-
return r.length < 4 ? new
|
|
1268
|
+
return r.length < 4 ? new x(0, 0, 0, 0) : new x(r[0], r[1], r[2], r[3]);
|
|
1270
1269
|
}
|
|
1271
1270
|
/**
|
|
1272
1271
|
* Destroys the framebuffer, renderbuffer, and base texture.
|
|
@@ -1280,11 +1279,11 @@ const Ut = {
|
|
|
1280
1279
|
fontSize: 24,
|
|
1281
1280
|
fontWeight: "normal",
|
|
1282
1281
|
fill: "#000000",
|
|
1283
|
-
strokeThickness:
|
|
1282
|
+
strokeThickness: 0,
|
|
1284
1283
|
align: "left",
|
|
1285
|
-
|
|
1284
|
+
lineHeight: 1
|
|
1286
1285
|
};
|
|
1287
|
-
class Ct extends
|
|
1286
|
+
class Ct extends W {
|
|
1288
1287
|
canvas;
|
|
1289
1288
|
ctx;
|
|
1290
1289
|
render;
|
|
@@ -1298,7 +1297,7 @@ class Ct extends F {
|
|
|
1298
1297
|
if (!r) throw new Error("Failed to get 2d context for TextTexture");
|
|
1299
1298
|
this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
|
|
1300
1299
|
const i = J(t, this.canvas, this.options);
|
|
1301
|
-
this.setBase(new
|
|
1300
|
+
this.setBase(new X(i, 1, 1)), this.update();
|
|
1302
1301
|
}
|
|
1303
1302
|
get text() {
|
|
1304
1303
|
return this._text;
|
|
@@ -1321,51 +1320,36 @@ class Ct extends F {
|
|
|
1321
1320
|
updateOffset(t, e) {
|
|
1322
1321
|
switch (this._style.align) {
|
|
1323
1322
|
case "center":
|
|
1324
|
-
|
|
1325
|
-
break;
|
|
1323
|
+
return t / 2;
|
|
1326
1324
|
case "right":
|
|
1327
|
-
|
|
1328
|
-
break;
|
|
1325
|
+
return t;
|
|
1329
1326
|
default:
|
|
1330
|
-
|
|
1331
|
-
break;
|
|
1332
|
-
}
|
|
1333
|
-
switch (this._style.baseline) {
|
|
1334
|
-
case "middle":
|
|
1335
|
-
this.offsetY = -e / 2;
|
|
1336
|
-
break;
|
|
1337
|
-
case "bottom":
|
|
1338
|
-
this.offsetY = -e;
|
|
1339
|
-
break;
|
|
1340
|
-
default:
|
|
1341
|
-
this.offsetY = 0;
|
|
1342
|
-
break;
|
|
1327
|
+
return e;
|
|
1343
1328
|
}
|
|
1344
1329
|
}
|
|
1345
1330
|
/**
|
|
1346
1331
|
* Updates the internal canvas and uploads it to WebGL
|
|
1347
1332
|
*/
|
|
1348
1333
|
update() {
|
|
1349
|
-
const t = this.ctx, e = this.
|
|
1350
|
-
t.font =
|
|
1351
|
-
const
|
|
1334
|
+
const t = this.ctx, e = this.style, r = e.fontSize, i = e.fontWeight, s = e.fontFamily, a = e.lineHeight, o = `${i} ${r}px ${s}`, h = this.render.dpr;
|
|
1335
|
+
t.font = o, t.textBaseline = "top";
|
|
1336
|
+
const c = this._text.split(`
|
|
1352
1337
|
`);
|
|
1353
|
-
let
|
|
1354
|
-
t.
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
S.width > h && (h = S.width), c += l + d;
|
|
1338
|
+
let u = 0, l = 0;
|
|
1339
|
+
const d = t.measureText(c[0] || "M"), f = (d.fontBoundingBoxAscent || r) + (d.fontBoundingBoxDescent || r * 0.2);
|
|
1340
|
+
for (const D of c) {
|
|
1341
|
+
const N = t.measureText(D);
|
|
1342
|
+
N.width > u && (u = N.width), l += f * a;
|
|
1359
1343
|
}
|
|
1360
|
-
|
|
1361
|
-
const
|
|
1362
|
-
(this.canvas.width !==
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0,
|
|
1344
|
+
l -= f * (a - 1);
|
|
1345
|
+
const m = this._style.strokeThickness || 0, g = Math.ceil(u + m * 2) || 1, v = Math.ceil(l + m * 2) || 1, y = Math.ceil(g * h), R = Math.ceil(v * h);
|
|
1346
|
+
(this.canvas.width !== y || this.canvas.height !== R) && (this.canvas.width = y, this.canvas.height = R), t.setTransform(h, 0, 0, h, 0, 0), t.clearRect(0, 0, g, v), t.font = o, t.textBaseline = "top", t.textAlign = this._style.align;
|
|
1347
|
+
const A = this.updateOffset(g, m), P = e.strokeThickness, U = P > 0;
|
|
1348
|
+
U && (t.lineWidth = P, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
|
|
1349
|
+
let B = m;
|
|
1350
|
+
for (const D of c)
|
|
1351
|
+
U && t.strokeText(D, A, B), e.fill && t.fillText(D, A, B), B += f * a;
|
|
1352
|
+
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, y, R);
|
|
1369
1353
|
}
|
|
1370
1354
|
}
|
|
1371
1355
|
const _t = (n, t = !1, e = !0) => {
|
|
@@ -1420,7 +1404,7 @@ function J(n, t, e) {
|
|
|
1420
1404
|
}
|
|
1421
1405
|
return r.bindTexture(r.TEXTURE_2D, null), i;
|
|
1422
1406
|
}
|
|
1423
|
-
function
|
|
1407
|
+
function V(n, t) {
|
|
1424
1408
|
if (n.includes("%TEXTURE_NUM%") && (n = n.replace("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
|
|
1425
1409
|
let e = "";
|
|
1426
1410
|
for (let r = 0; r < t; r++)
|
|
@@ -1667,6 +1651,9 @@ class ct {
|
|
|
1667
1651
|
const s = t.createShader(r, i);
|
|
1668
1652
|
return s.isCustom = !0, s.padding = this.padding, this.glshader.set(e, s), this.uniformDirty.add(e), s;
|
|
1669
1653
|
}
|
|
1654
|
+
destroy() {
|
|
1655
|
+
this.glshader.forEach((t) => t.destroy());
|
|
1656
|
+
}
|
|
1670
1657
|
}
|
|
1671
1658
|
class Et {
|
|
1672
1659
|
constructor(t) {
|
|
@@ -1881,12 +1868,12 @@ class at extends Et {
|
|
|
1881
1868
|
}
|
|
1882
1869
|
createBuffer() {
|
|
1883
1870
|
const t = this.gl;
|
|
1884
|
-
this.quadBuffer = new et(t,
|
|
1871
|
+
this.quadBuffer = new et(t, b.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1885
1872
|
for (const e of Wt) this.quadBuffer.pushFloat32(e);
|
|
1886
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t,
|
|
1873
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t, b.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1887
1874
|
}
|
|
1888
1875
|
createDefaultShader() {
|
|
1889
|
-
const t = this.rapid, e =
|
|
1876
|
+
const t = this.rapid, e = V(ut, t.maxTextureUnits), r = V(Z, t.maxTextureUnits);
|
|
1890
1877
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
1891
1878
|
}
|
|
1892
1879
|
createShader(t, e) {
|
|
@@ -1902,7 +1889,7 @@ class at extends Et {
|
|
|
1902
1889
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1903
1890
|
}
|
|
1904
1891
|
createCustomShader(t) {
|
|
1905
|
-
const e =
|
|
1892
|
+
const e = V(ut, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = V(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
1906
1893
|
return t.getGLShader(this, this.KEY, r, e);
|
|
1907
1894
|
}
|
|
1908
1895
|
/**
|
|
@@ -1918,15 +1905,15 @@ class at extends Et {
|
|
|
1918
1905
|
* @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
|
|
1919
1906
|
*/
|
|
1920
1907
|
drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, l = !1, d = !1) {
|
|
1921
|
-
const f = e * 6,
|
|
1908
|
+
const f = e * 6, m = this.matrixStore.data;
|
|
1922
1909
|
this.drawSpriteAffine(
|
|
1923
1910
|
t,
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1911
|
+
m[f],
|
|
1912
|
+
m[f + 1],
|
|
1913
|
+
m[f + 2],
|
|
1914
|
+
m[f + 3],
|
|
1915
|
+
m[f + 4],
|
|
1916
|
+
m[f + 5],
|
|
1930
1917
|
r,
|
|
1931
1918
|
i,
|
|
1932
1919
|
s,
|
|
@@ -1939,17 +1926,17 @@ class at extends Et {
|
|
|
1939
1926
|
d
|
|
1940
1927
|
);
|
|
1941
1928
|
}
|
|
1942
|
-
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0,
|
|
1943
|
-
const
|
|
1929
|
+
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, g = !1, v = !1, y = !1) {
|
|
1930
|
+
const R = t.base, A = t.rawWidth, P = t.rawHeight, U = t.offsetX, B = t.offsetY, D = this.useTexture(
|
|
1944
1931
|
t.glTexture,
|
|
1945
|
-
f / R
|
|
1946
|
-
|
|
1947
|
-
), N = this.instanceBuffer,
|
|
1932
|
+
f / R.width,
|
|
1933
|
+
m / R.height
|
|
1934
|
+
), N = this.instanceBuffer, M = N.usedElemNum;
|
|
1948
1935
|
N.resize(12);
|
|
1949
|
-
const
|
|
1950
|
-
|
|
1936
|
+
const C = N.float32, k = N.uint32, G = y ? P : A, H = y ? A : P, I = G + 2 * f, O = H + 2 * m, S = U - f, L = B - m, T = this.localSpriteMatrix;
|
|
1937
|
+
y ? (T[0] = 0, T[1] = v ? O : -O, T[2] = g ? -I : I, T[3] = 0, T[4] = S + (g ? I : 0), T[5] = L + (v ? 0 : O)) : (T[0] = g ? -I : I, T[1] = 0, T[2] = 0, T[3] = v ? -O : O, T[4] = S + (g ? I : 0), T[5] = L + (v ? O : 0));
|
|
1951
1938
|
const w = this.worldSpriteMatrix;
|
|
1952
|
-
w[0] = e *
|
|
1939
|
+
w[0] = e * T[0] + i * T[1], w[1] = r * T[0] + s * T[1], w[2] = e * T[2] + i * T[3], w[3] = r * T[2] + s * T[3], w[4] = a + e * T[4] + i * T[5], w[5] = o + r * T[4] + s * T[5], C[M + 6] = h, C[M + 7] = c, C[M + 8] = u, C[M + 9] = l, k[M + 10] = d, k[M + 11] = D, this.rapid.roundPixels && (w[4] = Math.round(w[4]), w[5] = Math.round(w[5])), C[M] = w[0], C[M + 1] = w[2], C[M + 2] = w[4], C[M + 3] = w[1], C[M + 4] = w[3], C[M + 5] = w[5], N.usedElemNum += 12, N.makeDirty(), this.instanceCount++;
|
|
1953
1940
|
}
|
|
1954
1941
|
render() {
|
|
1955
1942
|
if (this.instanceCount === 0) return;
|
|
@@ -2098,7 +2085,7 @@ class Ht extends Et {
|
|
|
2098
2085
|
}
|
|
2099
2086
|
createBuffer() {
|
|
2100
2087
|
const t = this.gl;
|
|
2101
|
-
this.vertexBuffer = new et(t,
|
|
2088
|
+
this.vertexBuffer = new et(t, b.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
|
|
2102
2089
|
}
|
|
2103
2090
|
createDefaultShader() {
|
|
2104
2091
|
return this.vs = Bt, this.fs = Dt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
@@ -2315,15 +2302,15 @@ const Vt = (n, t) => {
|
|
|
2315
2302
|
}
|
|
2316
2303
|
return e;
|
|
2317
2304
|
};
|
|
2318
|
-
var
|
|
2305
|
+
var zt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(zt || {});
|
|
2319
2306
|
const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
2320
2307
|
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
2308
|
for (let l = 0; l < tt; l++) {
|
|
2322
|
-
const d = l / tt, f = (l + 1) / tt,
|
|
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(
|
|
2309
|
+
const d = l / tt, f = (l + 1) / tt, m = h + d * c, g = h + f * c, v = new p(Math.cos(m) * e, Math.sin(m) * e), y = new p(Math.cos(g) * e, Math.sin(g) * e);
|
|
2310
|
+
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(y)), o.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e));
|
|
2324
2311
|
}
|
|
2325
2312
|
return { vertices: a, uv: o };
|
|
2326
|
-
},
|
|
2313
|
+
}, Xt = (n, t = !1) => {
|
|
2327
2314
|
const e = [];
|
|
2328
2315
|
if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
|
|
2329
2316
|
const r = 4, i = 1e-3, s = n.length;
|
|
@@ -2341,10 +2328,10 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2341
2328
|
if (f < -1 + i)
|
|
2342
2329
|
return { normal: l.perpendicular(), miters: 1 };
|
|
2343
2330
|
{
|
|
2344
|
-
let
|
|
2345
|
-
l.cross(d) < 0 && (
|
|
2331
|
+
let m = d.add(l).normalize();
|
|
2332
|
+
l.cross(d) < 0 && (m = m.multiply(-1));
|
|
2346
2333
|
let g = 1 / Math.sqrt((1 - f) / 2);
|
|
2347
|
-
return { normal:
|
|
2334
|
+
return { normal: m, miters: Math.min(g, r) };
|
|
2348
2335
|
}
|
|
2349
2336
|
};
|
|
2350
2337
|
if (t)
|
|
@@ -2366,21 +2353,21 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2366
2353
|
}, jt = (n) => {
|
|
2367
2354
|
const t = n.points;
|
|
2368
2355
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2369
|
-
const { normals: e, length: r } =
|
|
2356
|
+
const { normals: e, length: r } = Xt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
|
|
2370
2357
|
let c = 0;
|
|
2371
2358
|
const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
|
|
2372
2359
|
for (let d = 0; d < l; d++) {
|
|
2373
|
-
const f = t[d],
|
|
2374
|
-
let
|
|
2375
|
-
h === 0 ? (
|
|
2376
|
-
const
|
|
2377
|
-
s.push(
|
|
2360
|
+
const f = t[d], m = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, y = t[v], R = e[v].normal, A = e[v].miters, P = f.add(m.multiply(g * i)), U = f.subtract(m.multiply(g * i)), B = y.add(R.multiply(A * i)), D = y.subtract(R.multiply(A * i)), N = f.distanceTo(y);
|
|
2361
|
+
let M = 0, C = 0;
|
|
2362
|
+
h === 0 ? (M = c / r, C = (c + N) / r) : (M = c / u, C = M + N / u);
|
|
2363
|
+
const k = new p(M, 0), G = new p(M, 1), H = new p(C, 0), I = new p(C, 1);
|
|
2364
|
+
s.push(P), a.push(k), s.push(U), a.push(G), s.push(B), a.push(H), s.push(B), a.push(H), s.push(D), a.push(I), s.push(U), a.push(G), c += N;
|
|
2378
2365
|
}
|
|
2379
2366
|
if (o && !n.closed) {
|
|
2380
|
-
const d = t[0], f = e[0].normal,
|
|
2367
|
+
const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g = lt(d, f, i, !0, 0, m);
|
|
2381
2368
|
s.push(...g.vertices), a.push(...g.uv);
|
|
2382
|
-
const v = t[t.length - 1],
|
|
2383
|
-
s.push(...
|
|
2369
|
+
const v = t[t.length - 1], y = e[t.length - 1].normal, R = h === 0 ? 1 : c / u, A = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, P = lt(v, y, i, !1, R, A);
|
|
2370
|
+
s.push(...P.vertices), a.push(...P.uv);
|
|
2384
2371
|
}
|
|
2385
2372
|
return { vertices: s, uv: a };
|
|
2386
2373
|
}, Q = (n, t, e, r) => {
|
|
@@ -2569,11 +2556,11 @@ class re extends at {
|
|
|
2569
2556
|
super(t);
|
|
2570
2557
|
}
|
|
2571
2558
|
createCustomShader(t) {
|
|
2572
|
-
const e =
|
|
2559
|
+
const e = V(dt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = V(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
2573
2560
|
return t.getGLShader(this, this.KEY, r, e);
|
|
2574
2561
|
}
|
|
2575
2562
|
createDefaultShader() {
|
|
2576
|
-
const t = this.rapid, e =
|
|
2563
|
+
const t = this.rapid, e = V(dt, t.maxTextureUnits), r = V(Z, t.maxTextureUnits);
|
|
2577
2564
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
2578
2565
|
}
|
|
2579
2566
|
}
|
|
@@ -2634,7 +2621,7 @@ void main(void) {\r
|
|
|
2634
2621
|
\r
|
|
2635
2622
|
// CUSTOM_CODE_CALL\r
|
|
2636
2623
|
}\r
|
|
2637
|
-
`,
|
|
2624
|
+
`, z = 48, xt = z / 4;
|
|
2638
2625
|
class ie extends at {
|
|
2639
2626
|
KEY = "ParticleSprite";
|
|
2640
2627
|
texture;
|
|
@@ -2655,46 +2642,46 @@ class ie extends at {
|
|
|
2655
2642
|
createShader(t, e) {
|
|
2656
2643
|
const r = super.createShader(t, e);
|
|
2657
2644
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
2658
|
-
{ name: "aPosition", size: 2, stride:
|
|
2659
|
-
{ name: "aScale", size: 2, stride:
|
|
2660
|
-
{ name: "aRotation", size: 1, stride:
|
|
2661
|
-
{ name: "aUVRect", size: 4, stride:
|
|
2662
|
-
{ name: "aColor", size: 4, type: st, normalized: !0, stride:
|
|
2663
|
-
{ name: "aOrigin", size: 2, stride:
|
|
2645
|
+
{ name: "aPosition", size: 2, stride: z, offset: 0, divisor: 1 },
|
|
2646
|
+
{ name: "aScale", size: 2, stride: z, offset: 8, divisor: 1 },
|
|
2647
|
+
{ name: "aRotation", size: 1, stride: z, offset: 16, divisor: 1 },
|
|
2648
|
+
{ name: "aUVRect", size: 4, stride: z, offset: 20, divisor: 1 },
|
|
2649
|
+
{ name: "aColor", size: 4, type: st, normalized: !0, stride: z, offset: 36, divisor: 1 },
|
|
2650
|
+
{ name: "aOrigin", size: 2, stride: z, offset: 40, divisor: 1 }
|
|
2664
2651
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
2665
2652
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2666
2653
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2667
2654
|
}
|
|
2668
|
-
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1,
|
|
2655
|
+
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, g = !1, v = 0.5, y = 0.5, R, A = !1, P) {
|
|
2669
2656
|
if (!t.glTexture || a <= 0) return;
|
|
2670
|
-
let
|
|
2671
|
-
const
|
|
2672
|
-
let
|
|
2673
|
-
|
|
2674
|
-
let
|
|
2675
|
-
|
|
2676
|
-
let
|
|
2677
|
-
for (
|
|
2657
|
+
let U = 0;
|
|
2658
|
+
const B = typeof o == "number", D = typeof h == "number", N = typeof i == "number", M = typeof s == "number", C = !M && typeof s[0] == "number";
|
|
2659
|
+
let k = t.rawWidth * (f ? -1 : 1);
|
|
2660
|
+
B && (k *= o);
|
|
2661
|
+
let G = t.rawHeight * (m ? -1 : 1);
|
|
2662
|
+
D && (G *= h);
|
|
2663
|
+
let H = g ? Math.PI / 2 : 0;
|
|
2664
|
+
for (N && (H += i); U < a; ) {
|
|
2678
2665
|
this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2679
|
-
const
|
|
2680
|
-
let
|
|
2681
|
-
|
|
2682
|
-
const L =
|
|
2683
|
-
for (let
|
|
2684
|
-
const
|
|
2685
|
-
if (L[
|
|
2686
|
-
|
|
2687
|
-
else if (
|
|
2688
|
-
|
|
2666
|
+
const I = a - U, O = this.instanceBuffer;
|
|
2667
|
+
let S = O.usedElemNum;
|
|
2668
|
+
O.resize(I * xt);
|
|
2669
|
+
const L = O.float32, T = O.uint32;
|
|
2670
|
+
for (let w = 0; w < I; w++) {
|
|
2671
|
+
const Y = A ? a - 1 - U - w : U + w;
|
|
2672
|
+
if (L[S] = e[Y], L[S + 1] = r[Y], L[S + 2] = B ? k : k * o[Y], L[S + 3] = D ? G : G * h[Y], L[S + 4] = N ? H : i[Y] + H, L[S + 5] = c, L[S + 6] = u, L[S + 7] = l, L[S + 8] = d, M)
|
|
2673
|
+
T[S + 9] = 4294967295;
|
|
2674
|
+
else if (C)
|
|
2675
|
+
T[S + 9] = s[Y];
|
|
2689
2676
|
else {
|
|
2690
|
-
const ht = s[
|
|
2691
|
-
|
|
2677
|
+
const ht = s[Y];
|
|
2678
|
+
T[S + 9] = R ? ht.premultipliedUint32 : ht.uint32;
|
|
2692
2679
|
}
|
|
2693
|
-
L[
|
|
2680
|
+
L[S + 10] = v, L[S + 11] = y, S += xt;
|
|
2694
2681
|
}
|
|
2695
|
-
|
|
2682
|
+
O.usedElemNum = S, O.makeDirty(), this.instanceCount += I, U += I;
|
|
2696
2683
|
}
|
|
2697
|
-
this.customMatrix =
|
|
2684
|
+
this.customMatrix = P, this.flush();
|
|
2698
2685
|
}
|
|
2699
2686
|
render() {
|
|
2700
2687
|
if (this.instanceCount === 0) return;
|
|
@@ -2720,7 +2707,7 @@ class ce {
|
|
|
2720
2707
|
/** The current device pixel ratio. */
|
|
2721
2708
|
dpr;
|
|
2722
2709
|
/** Background clear color [r, g, b, a], values range from 0 to 255. */
|
|
2723
|
-
backgroundColor =
|
|
2710
|
+
backgroundColor = x.Black;
|
|
2724
2711
|
/** Logical width in CSS pixels, used for coordinate system and projection matrix. */
|
|
2725
2712
|
logicWidth = 0;
|
|
2726
2713
|
/** Logical height in CSS pixels, used for coordinate system and projection matrix. */
|
|
@@ -2759,7 +2746,7 @@ class ce {
|
|
|
2759
2746
|
scaleMode;
|
|
2760
2747
|
/** Internal ping-pong RenderTextures for multi-filter chains. */
|
|
2761
2748
|
_filterRT = [null, null];
|
|
2762
|
-
_filterInput = new
|
|
2749
|
+
_filterInput = new W();
|
|
2763
2750
|
get height() {
|
|
2764
2751
|
return this.logicHeight;
|
|
2765
2752
|
}
|
|
@@ -2867,8 +2854,8 @@ class ce {
|
|
|
2867
2854
|
* @param v The V texture coordinate (0 to 1).
|
|
2868
2855
|
* @param color The vertex color as a 32-bit unsigned integer.
|
|
2869
2856
|
*/
|
|
2870
|
-
addGraphicVertex(t, e, r = 0, i = 0, s
|
|
2871
|
-
this.graphicRegion.addVertex(t, e, r, i, s);
|
|
2857
|
+
addGraphicVertex(t, e, r = 0, i = 0, s) {
|
|
2858
|
+
this.graphicRegion.addVertex(t, e, r, i, typeof s == "number" ? s : this.getColorUint32(s));
|
|
2872
2859
|
}
|
|
2873
2860
|
/**
|
|
2874
2861
|
* Ends the current graphics geometry definition, readying it for rendering.
|
|
@@ -2970,7 +2957,7 @@ class ce {
|
|
|
2970
2957
|
* @param rt The render texture to clear.
|
|
2971
2958
|
* @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
|
|
2972
2959
|
*/
|
|
2973
|
-
clearRenderTexture(t = new
|
|
2960
|
+
clearRenderTexture(t = new x(0, 0, 0, 0)) {
|
|
2974
2961
|
this.flush();
|
|
2975
2962
|
const e = this.gl;
|
|
2976
2963
|
t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
|
|
@@ -2992,7 +2979,7 @@ class ce {
|
|
|
2992
2979
|
* rapid.drawSprite({ texture: mySprite });
|
|
2993
2980
|
* });
|
|
2994
2981
|
*/
|
|
2995
|
-
drawToRenderTexture(t, e, r = new
|
|
2982
|
+
drawToRenderTexture(t, e, r = new x(0, 0, 0, 0)) {
|
|
2996
2983
|
this.enterRenderTexture(t);
|
|
2997
2984
|
try {
|
|
2998
2985
|
r !== null && this.clearRenderTexture(r), e();
|
|
@@ -3231,9 +3218,9 @@ class ce {
|
|
|
3231
3218
|
}
|
|
3232
3219
|
}
|
|
3233
3220
|
function he(n) {
|
|
3234
|
-
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof
|
|
3221
|
+
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof x);
|
|
3235
3222
|
}
|
|
3236
|
-
class
|
|
3223
|
+
class F {
|
|
3237
3224
|
/** Random float in [min, max). */
|
|
3238
3225
|
static float(t, e) {
|
|
3239
3226
|
return Math.random() * (e - t) + t;
|
|
@@ -3248,20 +3235,20 @@ class O {
|
|
|
3248
3235
|
}
|
|
3249
3236
|
/** Random Vec2 with components in the supplied per-axis ranges. */
|
|
3250
3237
|
static vector(t, e, r, i) {
|
|
3251
|
-
return new p(
|
|
3238
|
+
return new p(F.float(t, e), F.float(r, i));
|
|
3252
3239
|
}
|
|
3253
3240
|
/** Random Color with each component interpolated between minColor and maxColor. */
|
|
3254
3241
|
static randomColor(t, e) {
|
|
3255
|
-
return new
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3242
|
+
return new x(
|
|
3243
|
+
F.float(t.r, e.r),
|
|
3244
|
+
F.float(t.g, e.g),
|
|
3245
|
+
F.float(t.b, e.b),
|
|
3246
|
+
F.float(t.a, e.a)
|
|
3260
3247
|
);
|
|
3261
3248
|
}
|
|
3262
3249
|
/** Pick a random element from an array with uniform probability. */
|
|
3263
3250
|
static pick(t) {
|
|
3264
|
-
return t[
|
|
3251
|
+
return t[F.int(0, t.length - 1)];
|
|
3265
3252
|
}
|
|
3266
3253
|
/**
|
|
3267
3254
|
* Pick a random element using weighted probability.
|
|
@@ -3287,11 +3274,11 @@ class O {
|
|
|
3287
3274
|
if (Array.isArray(t)) {
|
|
3288
3275
|
const [r, i] = t;
|
|
3289
3276
|
if (typeof r == "number")
|
|
3290
|
-
return
|
|
3277
|
+
return F.float(r, i);
|
|
3291
3278
|
if (r instanceof p)
|
|
3292
|
-
return
|
|
3293
|
-
if (r instanceof
|
|
3294
|
-
return
|
|
3279
|
+
return F.vector(r.x, i.x, r.y, i.y);
|
|
3280
|
+
if (r instanceof x)
|
|
3281
|
+
return F.randomColor(r, i);
|
|
3295
3282
|
}
|
|
3296
3283
|
return typeof t == "number" ? t : t.clone();
|
|
3297
3284
|
}
|
|
@@ -3304,9 +3291,9 @@ class K {
|
|
|
3304
3291
|
if (!Number.isInteger(t) || t <= 0)
|
|
3305
3292
|
throw new RangeError("ParticleAttributeStore size must be a positive integer");
|
|
3306
3293
|
this.components = Array.from({ length: t }, () => ({
|
|
3307
|
-
value: new
|
|
3308
|
-
delta: new
|
|
3309
|
-
damping: new
|
|
3294
|
+
value: new _(b.Float32),
|
|
3295
|
+
delta: new _(b.Float32),
|
|
3296
|
+
damping: new _(b.Float32)
|
|
3310
3297
|
}));
|
|
3311
3298
|
}
|
|
3312
3299
|
getArrayBuffer() {
|
|
@@ -3339,7 +3326,7 @@ class K {
|
|
|
3339
3326
|
}
|
|
3340
3327
|
}
|
|
3341
3328
|
resolveComponent(t, e, r) {
|
|
3342
|
-
return t === void 0 ? r : Array.isArray(t) ?
|
|
3329
|
+
return t === void 0 ? r : Array.isArray(t) ? F.float(
|
|
3343
3330
|
this.getComponent(t[0], e),
|
|
3344
3331
|
this.getComponent(t[1], e)
|
|
3345
3332
|
) : this.getComponent(t, e);
|
|
@@ -3348,13 +3335,13 @@ class K {
|
|
|
3348
3335
|
const i = he(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
|
|
3349
3336
|
let o = 0;
|
|
3350
3337
|
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),
|
|
3352
|
-
c.push(f), u.push(i?.delta === void 0 ? (
|
|
3338
|
+
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), m = i?.end === void 0 ? f : this.resolveComponent(i.end, h, d);
|
|
3339
|
+
c.push(f), u.push(i?.delta === void 0 ? (m - f) / a : this.getComponent(i.delta, h)), l.push(i?.damping ?? 1), h === 0 && (o = f);
|
|
3353
3340
|
}
|
|
3354
3341
|
return o;
|
|
3355
3342
|
}
|
|
3356
3343
|
}
|
|
3357
|
-
class
|
|
3344
|
+
class Mt {
|
|
3358
3345
|
options;
|
|
3359
3346
|
emitting = !1;
|
|
3360
3347
|
emitTimer = 0;
|
|
@@ -3364,12 +3351,12 @@ class wt {
|
|
|
3364
3351
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3365
3352
|
localSpace = vt;
|
|
3366
3353
|
rapid;
|
|
3367
|
-
x = new
|
|
3368
|
-
y = new
|
|
3369
|
-
scaleX = new
|
|
3370
|
-
scaleY = new
|
|
3371
|
-
rotation = new
|
|
3372
|
-
color = new
|
|
3354
|
+
x = new _(b.Float32);
|
|
3355
|
+
y = new _(b.Float32);
|
|
3356
|
+
scaleX = new _(b.Float32);
|
|
3357
|
+
scaleY = new _(b.Float32);
|
|
3358
|
+
rotation = new _(b.Float32);
|
|
3359
|
+
color = new _(b.Uint32);
|
|
3373
3360
|
animations = {
|
|
3374
3361
|
speed: new K(),
|
|
3375
3362
|
rotation: new K(),
|
|
@@ -3406,7 +3393,7 @@ class wt {
|
|
|
3406
3393
|
* Particle state is NOT copied.
|
|
3407
3394
|
*/
|
|
3408
3395
|
clone() {
|
|
3409
|
-
return new
|
|
3396
|
+
return new Mt(this.rapid, { ...this.options });
|
|
3410
3397
|
}
|
|
3411
3398
|
/** Sets particles-per-second emission rate (continuous mode). */
|
|
3412
3399
|
setEmitRate(t) {
|
|
@@ -3440,7 +3427,7 @@ class wt {
|
|
|
3440
3427
|
this.createParticle();
|
|
3441
3428
|
}
|
|
3442
3429
|
createParticle() {
|
|
3443
|
-
const t =
|
|
3430
|
+
const t = F.scalarOrRange(this.options.life, 1);
|
|
3444
3431
|
let e = 0, r = 0;
|
|
3445
3432
|
switch (this.options.emitShape) {
|
|
3446
3433
|
case "circle": {
|
|
@@ -3461,7 +3448,7 @@ class wt {
|
|
|
3461
3448
|
this.x.push(c), this.y.push(u);
|
|
3462
3449
|
}
|
|
3463
3450
|
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,
|
|
3451
|
+
a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, p.ZERO, t), a.color.create(s.color, x.White, t), this.rotation.push(h), this.scaleX.push(o), this.scaleY.push(o), this.color.pushUint32(x.packColor(
|
|
3465
3452
|
a.color.get(this.count, 0),
|
|
3466
3453
|
a.color.get(this.count, 1),
|
|
3467
3454
|
a.color.get(this.count, 2),
|
|
@@ -3486,14 +3473,14 @@ class wt {
|
|
|
3486
3473
|
r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
|
|
3487
3474
|
}
|
|
3488
3475
|
const e = this.updateParticle(t);
|
|
3489
|
-
this.count -= e.length,
|
|
3476
|
+
this.count -= e.length, _.removeAtIndices(e, this.getAllArrayBuffer());
|
|
3490
3477
|
}
|
|
3491
3478
|
updateParticle(t) {
|
|
3492
3479
|
const e = [], r = this.animations;
|
|
3493
3480
|
Object.values(r).forEach((i) => i.update(t));
|
|
3494
3481
|
for (let i = 0; i < this.count; i++) {
|
|
3495
3482
|
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] =
|
|
3483
|
+
this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = x.packColor(
|
|
3497
3484
|
r.color.get(i, 0),
|
|
3498
3485
|
r.color.get(i, 1),
|
|
3499
3486
|
r.color.get(i, 2),
|
|
@@ -3537,20 +3524,20 @@ class wt {
|
|
|
3537
3524
|
}
|
|
3538
3525
|
}
|
|
3539
3526
|
export {
|
|
3540
|
-
|
|
3541
|
-
|
|
3527
|
+
b as ArrayType,
|
|
3528
|
+
X as BaseTexture,
|
|
3542
3529
|
ne as BlendMode,
|
|
3543
3530
|
ae as CanvasScaleMode,
|
|
3544
|
-
|
|
3531
|
+
x as Color,
|
|
3545
3532
|
ct as CustomGlShader,
|
|
3546
|
-
|
|
3533
|
+
_ as DynamicArrayBuffer,
|
|
3547
3534
|
Tt as GLShader,
|
|
3548
3535
|
Ht as GraphicRegion,
|
|
3549
|
-
|
|
3536
|
+
zt as LineTextureMode,
|
|
3550
3537
|
se as MaskType,
|
|
3551
3538
|
At as MatrixStack,
|
|
3552
|
-
|
|
3553
|
-
|
|
3539
|
+
wt as MatrixStore,
|
|
3540
|
+
Mt as ParticleEmitter,
|
|
3554
3541
|
oe as ParticleShape,
|
|
3555
3542
|
Wt as QUAD_VERTICES,
|
|
3556
3543
|
ce as Rapid,
|
|
@@ -3558,7 +3545,7 @@ export {
|
|
|
3558
3545
|
bt as RenderTexture,
|
|
3559
3546
|
at as SpriteRegion,
|
|
3560
3547
|
Ct as TextTexture,
|
|
3561
|
-
|
|
3548
|
+
W as Texture,
|
|
3562
3549
|
nt as TextureFilterMode,
|
|
3563
3550
|
St as TextureManager,
|
|
3564
3551
|
q as TextureWrapMode,
|