rapid-render 1.0.8 → 1.0.9
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 +210 -224
- package/dist/rapid-render.umd.cjs +6 -6
- package/dist/render.d.ts +1 -1
- package/dist/texture.d.ts +1 -1
- package/package.json +1 -1
package/dist/rapid-render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var U = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(U || {});
|
|
2
|
-
class
|
|
2
|
+
class P {
|
|
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 P {
|
|
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,22 +462,22 @@ 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
483
|
class Mt {
|
|
@@ -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 P(U.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,12 +721,12 @@ 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 {
|
|
@@ -735,15 +735,15 @@ class At {
|
|
|
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 P(U.Uint32);
|
|
739
739
|
/** Records the world matrices generated at each step. */
|
|
740
|
-
stepWorldM = new
|
|
740
|
+
stepWorldM = new P(U.Uint32);
|
|
741
741
|
/** Records actions (push/pop) taken during the traversal. */
|
|
742
|
-
stepAction = new
|
|
742
|
+
stepAction = new P(U.Uint32);
|
|
743
743
|
/** Records the parent world matrix for each step (used by updateMatrix). */
|
|
744
|
-
stepParentM = new
|
|
744
|
+
stepParentM = new P(U.Uint32);
|
|
745
745
|
/** Buffer used during hierarchy traversal updates. */
|
|
746
|
-
parentStack = new
|
|
746
|
+
parentStack = new P(U.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. */
|
|
@@ -920,36 +920,36 @@ class At {
|
|
|
920
920
|
t.offset && (l += t.offset.x, d += t.offset.y);
|
|
921
921
|
const f = t.origin;
|
|
922
922
|
f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
|
|
923
|
-
const
|
|
923
|
+
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, C = s + v * l + R * d, S = a + y * l + A * d;
|
|
924
924
|
if (i !== -1) {
|
|
925
925
|
this.matrix.multiplyAffine(
|
|
926
926
|
this.curWorldM,
|
|
927
927
|
i,
|
|
928
928
|
v,
|
|
929
|
-
|
|
930
|
-
A,
|
|
929
|
+
y,
|
|
931
930
|
R,
|
|
932
|
-
|
|
933
|
-
|
|
931
|
+
A,
|
|
932
|
+
C,
|
|
933
|
+
S
|
|
934
934
|
);
|
|
935
935
|
return;
|
|
936
936
|
}
|
|
937
937
|
this.matrix.multiplyAffineInPlace(
|
|
938
938
|
this.curLocalM,
|
|
939
939
|
v,
|
|
940
|
-
|
|
941
|
-
A,
|
|
940
|
+
y,
|
|
942
941
|
R,
|
|
943
|
-
|
|
944
|
-
|
|
942
|
+
A,
|
|
943
|
+
C,
|
|
944
|
+
S
|
|
945
945
|
), this.matrix.multiplyAffineInPlace(
|
|
946
946
|
this.curWorldM,
|
|
947
947
|
v,
|
|
948
|
-
|
|
949
|
-
A,
|
|
948
|
+
y,
|
|
950
949
|
R,
|
|
951
|
-
|
|
952
|
-
|
|
950
|
+
A,
|
|
951
|
+
C,
|
|
952
|
+
S
|
|
953
953
|
);
|
|
954
954
|
}
|
|
955
955
|
}
|
|
@@ -969,10 +969,10 @@ class St {
|
|
|
969
969
|
async load(t, e) {
|
|
970
970
|
let r = this.cache.get(t);
|
|
971
971
|
if (r)
|
|
972
|
-
return new
|
|
972
|
+
return new B(r);
|
|
973
973
|
try {
|
|
974
974
|
const i = await this._fetchImage(t);
|
|
975
|
-
return r =
|
|
975
|
+
return r = z.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new B(r);
|
|
976
976
|
} catch (i) {
|
|
977
977
|
throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
|
|
978
978
|
}
|
|
@@ -985,9 +985,9 @@ class St {
|
|
|
985
985
|
*/
|
|
986
986
|
create(t, e) {
|
|
987
987
|
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
|
|
988
|
+
return new B(this.cache.get(e.key));
|
|
989
|
+
const r = z.fromSource(this.render, t, e);
|
|
990
|
+
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new B(r);
|
|
991
991
|
}
|
|
992
992
|
/**
|
|
993
993
|
* Creates a generic Render Texture (FrameBuffer).
|
|
@@ -1016,7 +1016,7 @@ class St {
|
|
|
1016
1016
|
*/
|
|
1017
1017
|
destroy(t, e = !1) {
|
|
1018
1018
|
let r, i;
|
|
1019
|
-
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof
|
|
1019
|
+
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof B ? (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
1020
|
}
|
|
1021
1021
|
/**
|
|
1022
1022
|
* Destroys all cached textures and clears the cache, ignoring reference counts.
|
|
@@ -1033,7 +1033,7 @@ class St {
|
|
|
1033
1033
|
});
|
|
1034
1034
|
}
|
|
1035
1035
|
}
|
|
1036
|
-
class
|
|
1036
|
+
class z {
|
|
1037
1037
|
glTexture = null;
|
|
1038
1038
|
width;
|
|
1039
1039
|
height;
|
|
@@ -1051,7 +1051,7 @@ class Y {
|
|
|
1051
1051
|
*/
|
|
1052
1052
|
static fromSource(t, e, r = {}) {
|
|
1053
1053
|
const i = J(t, e, r);
|
|
1054
|
-
return new
|
|
1054
|
+
return new z(i, e.width, e.height);
|
|
1055
1055
|
}
|
|
1056
1056
|
/**
|
|
1057
1057
|
* Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
|
|
@@ -1082,7 +1082,7 @@ class Y {
|
|
|
1082
1082
|
this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
|
-
class
|
|
1085
|
+
class B {
|
|
1086
1086
|
base;
|
|
1087
1087
|
uvX = 0;
|
|
1088
1088
|
uvY = 0;
|
|
@@ -1128,7 +1128,7 @@ class F {
|
|
|
1128
1128
|
* @returns The current Texture instance.
|
|
1129
1129
|
*/
|
|
1130
1130
|
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;
|
|
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.scale, this.rawHeight = i * this.scale, this) : this;
|
|
1132
1132
|
}
|
|
1133
1133
|
/**
|
|
1134
1134
|
* Creates a new Texture representing a sub-region of this Texture.
|
|
@@ -1139,7 +1139,7 @@ class F {
|
|
|
1139
1139
|
* @returns A new Texture pointing to the sub-region.
|
|
1140
1140
|
*/
|
|
1141
1141
|
getSubTexture(t, e, r, i) {
|
|
1142
|
-
if (!this.base) return new
|
|
1142
|
+
if (!this.base) return new B();
|
|
1143
1143
|
const s = this.clone(), a = this._px, o = this._py;
|
|
1144
1144
|
return s.setRegion(a + t, o + e, r, i), s;
|
|
1145
1145
|
}
|
|
@@ -1148,7 +1148,7 @@ class F {
|
|
|
1148
1148
|
* @returns A new Texture instance.
|
|
1149
1149
|
*/
|
|
1150
1150
|
clone(t) {
|
|
1151
|
-
const e = t ?? new
|
|
1151
|
+
const e = t ?? new B(this.base);
|
|
1152
1152
|
return t && this.base && t.setBase(this.base), e.scale = this.scale, e.uvX = this.uvX, e.uvY = this.uvY, e.uvW = this.uvW, e.uvH = this.uvH, e.rawWidth = this.rawWidth, e.rawHeight = this.rawHeight, e.offsetX = this.offsetX, e.offsetY = this.offsetY, e.flipY = this.flipY, e.isRotated = this.isRotated, e.isAtlas = this.isAtlas, e._px = this._px, e._py = this._py, e._pw = this._pw, e._ph = this._ph, e;
|
|
1153
1153
|
}
|
|
1154
1154
|
/**
|
|
@@ -1164,9 +1164,9 @@ class F {
|
|
|
1164
1164
|
splitGrid(t, e, r, i, s = 0) {
|
|
1165
1165
|
if (!this.base) return [];
|
|
1166
1166
|
const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((o + c) / u), f = i ?? Math.floor((h + c) / l);
|
|
1167
|
-
for (let
|
|
1167
|
+
for (let m = 0; m < f; m++)
|
|
1168
1168
|
for (let g = 0; g < d; g++)
|
|
1169
|
-
a.push(this.getSubTexture(g * u,
|
|
1169
|
+
a.push(this.getSubTexture(g * u, m * l, t, e));
|
|
1170
1170
|
return a;
|
|
1171
1171
|
}
|
|
1172
1172
|
/**
|
|
@@ -1176,7 +1176,7 @@ class F {
|
|
|
1176
1176
|
*/
|
|
1177
1177
|
static fromImageSource(t, e, r = {}) {
|
|
1178
1178
|
const i = J(t, e, r);
|
|
1179
|
-
return new
|
|
1179
|
+
return new B(new z(i, e.width, e.height));
|
|
1180
1180
|
}
|
|
1181
1181
|
/**
|
|
1182
1182
|
* Marks this Texture as destroyed, decrementing the BaseTexture reference count.
|
|
@@ -1185,7 +1185,7 @@ class F {
|
|
|
1185
1185
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
1186
1186
|
}
|
|
1187
1187
|
}
|
|
1188
|
-
class bt extends
|
|
1188
|
+
class bt extends B {
|
|
1189
1189
|
framebuffer;
|
|
1190
1190
|
renderbuffer;
|
|
1191
1191
|
gl;
|
|
@@ -1195,9 +1195,9 @@ class bt extends F {
|
|
|
1195
1195
|
_allocW = 0;
|
|
1196
1196
|
_allocH = 0;
|
|
1197
1197
|
constructor(t, e) {
|
|
1198
|
-
super(), this.gl = t.gl, this.clearColor = e.clearColor ??
|
|
1198
|
+
super(), this.gl = t.gl, this.clearColor = e.clearColor ?? x.Black;
|
|
1199
1199
|
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = J(t, { width: r, height: i }, { ...e, onlySize: !0 });
|
|
1200
|
-
if (this.setBase(new
|
|
1200
|
+
if (this.setBase(new z(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
1201
1201
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
1202
1202
|
this.resize(r, i, !0);
|
|
1203
1203
|
}
|
|
@@ -1256,8 +1256,8 @@ class bt extends F {
|
|
|
1256
1256
|
return new Uint8Array(0);
|
|
1257
1257
|
const c = Math.min(o, this.rawWidth - s), u = Math.min(h, this.rawHeight - a), l = this.rawHeight - a - u, d = this.gl, f = d.getParameter(d.FRAMEBUFFER_BINDING);
|
|
1258
1258
|
d.bindFramebuffer(d.FRAMEBUFFER, this.framebuffer);
|
|
1259
|
-
const
|
|
1260
|
-
return d.readPixels(s, l, c, u, d.RGBA, d.UNSIGNED_BYTE,
|
|
1259
|
+
const m = new Uint8Array(c * u * 4);
|
|
1260
|
+
return d.readPixels(s, l, c, u, d.RGBA, d.UNSIGNED_BYTE, m), d.bindFramebuffer(d.FRAMEBUFFER, f), m;
|
|
1261
1261
|
}
|
|
1262
1262
|
/**
|
|
1263
1263
|
* Get the color at a pixel in the render texture.
|
|
@@ -1266,7 +1266,7 @@ class bt extends F {
|
|
|
1266
1266
|
*/
|
|
1267
1267
|
GetColorAt(t, e) {
|
|
1268
1268
|
const r = this.GetPixels(t, e, 1, 1);
|
|
1269
|
-
return r.length < 4 ? new
|
|
1269
|
+
return r.length < 4 ? new x(0, 0, 0, 0) : new x(r[0], r[1], r[2], r[3]);
|
|
1270
1270
|
}
|
|
1271
1271
|
/**
|
|
1272
1272
|
* Destroys the framebuffer, renderbuffer, and base texture.
|
|
@@ -1282,9 +1282,9 @@ const Ut = {
|
|
|
1282
1282
|
fill: "#000000",
|
|
1283
1283
|
strokeThickness: 1,
|
|
1284
1284
|
align: "left",
|
|
1285
|
-
|
|
1285
|
+
lineHeight: 1
|
|
1286
1286
|
};
|
|
1287
|
-
class Ct extends
|
|
1287
|
+
class Ct extends B {
|
|
1288
1288
|
canvas;
|
|
1289
1289
|
ctx;
|
|
1290
1290
|
render;
|
|
@@ -1298,7 +1298,7 @@ class Ct extends F {
|
|
|
1298
1298
|
if (!r) throw new Error("Failed to get 2d context for TextTexture");
|
|
1299
1299
|
this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
|
|
1300
1300
|
const i = J(t, this.canvas, this.options);
|
|
1301
|
-
this.setBase(new
|
|
1301
|
+
this.setBase(new z(i, 1, 1)), this.update();
|
|
1302
1302
|
}
|
|
1303
1303
|
get text() {
|
|
1304
1304
|
return this._text;
|
|
@@ -1321,51 +1321,37 @@ class Ct extends F {
|
|
|
1321
1321
|
updateOffset(t, e) {
|
|
1322
1322
|
switch (this._style.align) {
|
|
1323
1323
|
case "center":
|
|
1324
|
-
|
|
1325
|
-
break;
|
|
1324
|
+
return t / 2;
|
|
1326
1325
|
case "right":
|
|
1327
|
-
|
|
1328
|
-
break;
|
|
1326
|
+
return t;
|
|
1329
1327
|
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;
|
|
1328
|
+
return e;
|
|
1343
1329
|
}
|
|
1344
1330
|
}
|
|
1345
1331
|
/**
|
|
1346
1332
|
* Updates the internal canvas and uploads it to WebGL
|
|
1347
1333
|
*/
|
|
1348
1334
|
update() {
|
|
1349
|
-
const t = this.ctx, e = this.
|
|
1350
|
-
t.font =
|
|
1351
|
-
const
|
|
1335
|
+
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;
|
|
1336
|
+
t.font = o, t.textBaseline = "top";
|
|
1337
|
+
const c = this._text.split(`
|
|
1352
1338
|
`);
|
|
1353
|
-
let
|
|
1354
|
-
t.
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
S.width > h && (h = S.width), c += l + d;
|
|
1339
|
+
let u = 0, l = 0;
|
|
1340
|
+
const d = t.measureText(c[0]), f = d.fontBoundingBoxAscent + d.fontBoundingBoxDescent;
|
|
1341
|
+
for (const S of c) {
|
|
1342
|
+
const L = t.measureText(S);
|
|
1343
|
+
L.width > u && (u = L.width), l += f * a;
|
|
1359
1344
|
}
|
|
1360
|
-
|
|
1361
|
-
const
|
|
1362
|
-
(this.canvas.width !==
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1345
|
+
l -= f * (a - 1);
|
|
1346
|
+
const m = this._style.strokeThickness || 0, g = Math.ceil(u + m * 2) || 1, v = Math.ceil(l + m * 2) || 1, y = g * h, R = v * h;
|
|
1347
|
+
(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;
|
|
1348
|
+
const A = this.updateOffset(g, m);
|
|
1349
|
+
let C = m;
|
|
1350
|
+
for (const S of c) {
|
|
1351
|
+
let L = A;
|
|
1352
|
+
e.stroke && e.strokeThickness > 0 && (t.lineWidth = e.strokeThickness, t.strokeStyle = e.stroke, t.strokeText(S, L, C)), e.fill && (t.fillStyle = e.fill, t.fillText(S, L, C)), C += f * a;
|
|
1367
1353
|
}
|
|
1368
|
-
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0,
|
|
1354
|
+
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, y, R);
|
|
1369
1355
|
}
|
|
1370
1356
|
}
|
|
1371
1357
|
const _t = (n, t = !1, e = !0) => {
|
|
@@ -1420,7 +1406,7 @@ function J(n, t, e) {
|
|
|
1420
1406
|
}
|
|
1421
1407
|
return r.bindTexture(r.TEXTURE_2D, null), i;
|
|
1422
1408
|
}
|
|
1423
|
-
function
|
|
1409
|
+
function H(n, t) {
|
|
1424
1410
|
if (n.includes("%TEXTURE_NUM%") && (n = n.replace("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
|
|
1425
1411
|
let e = "";
|
|
1426
1412
|
for (let r = 0; r < t; r++)
|
|
@@ -1886,7 +1872,7 @@ class at extends Et {
|
|
|
1886
1872
|
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t, U.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1887
1873
|
}
|
|
1888
1874
|
createDefaultShader() {
|
|
1889
|
-
const t = this.rapid, e =
|
|
1875
|
+
const t = this.rapid, e = H(ut, t.maxTextureUnits), r = H(Z, t.maxTextureUnits);
|
|
1890
1876
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
1891
1877
|
}
|
|
1892
1878
|
createShader(t, e) {
|
|
@@ -1902,7 +1888,7 @@ class at extends Et {
|
|
|
1902
1888
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1903
1889
|
}
|
|
1904
1890
|
createCustomShader(t) {
|
|
1905
|
-
const e =
|
|
1891
|
+
const e = H(ut, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = H(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
1906
1892
|
return t.getGLShader(this, this.KEY, r, e);
|
|
1907
1893
|
}
|
|
1908
1894
|
/**
|
|
@@ -1918,15 +1904,15 @@ class at extends Et {
|
|
|
1918
1904
|
* @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
|
|
1919
1905
|
*/
|
|
1920
1906
|
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,
|
|
1907
|
+
const f = e * 6, m = this.matrixStore.data;
|
|
1922
1908
|
this.drawSpriteAffine(
|
|
1923
1909
|
t,
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1910
|
+
m[f],
|
|
1911
|
+
m[f + 1],
|
|
1912
|
+
m[f + 2],
|
|
1913
|
+
m[f + 3],
|
|
1914
|
+
m[f + 4],
|
|
1915
|
+
m[f + 5],
|
|
1930
1916
|
r,
|
|
1931
1917
|
i,
|
|
1932
1918
|
s,
|
|
@@ -1939,17 +1925,17 @@ class at extends Et {
|
|
|
1939
1925
|
d
|
|
1940
1926
|
);
|
|
1941
1927
|
}
|
|
1942
|
-
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0,
|
|
1943
|
-
const
|
|
1928
|
+
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) {
|
|
1929
|
+
const R = t.base, A = t.rawWidth, C = t.rawHeight, S = t.offsetX, L = t.offsetY, X = this.useTexture(
|
|
1944
1930
|
t.glTexture,
|
|
1945
|
-
f / R
|
|
1946
|
-
|
|
1947
|
-
),
|
|
1948
|
-
|
|
1949
|
-
const _ =
|
|
1950
|
-
|
|
1951
|
-
const
|
|
1952
|
-
|
|
1931
|
+
f / R.width,
|
|
1932
|
+
m / R.height
|
|
1933
|
+
), I = this.instanceBuffer, w = I.usedElemNum;
|
|
1934
|
+
I.resize(12);
|
|
1935
|
+
const _ = I.float32, D = I.uint32, k = y ? C : A, G = y ? A : C, O = k + 2 * f, F = G + 2 * m, b = S - f, N = L - m, T = this.localSpriteMatrix;
|
|
1936
|
+
y ? (T[0] = 0, T[1] = v ? F : -F, T[2] = g ? -O : O, T[3] = 0, T[4] = b + (g ? O : 0), T[5] = N + (v ? 0 : F)) : (T[0] = g ? -O : O, T[1] = 0, T[2] = 0, T[3] = v ? -F : F, T[4] = b + (g ? O : 0), T[5] = N + (v ? F : 0));
|
|
1937
|
+
const M = this.worldSpriteMatrix;
|
|
1938
|
+
M[0] = e * T[0] + i * T[1], M[1] = r * T[0] + s * T[1], M[2] = e * T[2] + i * T[3], M[3] = r * T[2] + s * T[3], M[4] = a + e * T[4] + i * T[5], M[5] = o + r * T[4] + s * T[5], _[w + 6] = h, _[w + 7] = c, _[w + 8] = u, _[w + 9] = l, D[w + 10] = d, D[w + 11] = X, this.rapid.roundPixels && (M[4] = Math.round(M[4]), M[5] = Math.round(M[5])), _[w] = M[0], _[w + 1] = M[2], _[w + 2] = M[4], _[w + 3] = M[1], _[w + 4] = M[3], _[w + 5] = M[5], I.usedElemNum += 12, I.makeDirty(), this.instanceCount++;
|
|
1953
1939
|
}
|
|
1954
1940
|
render() {
|
|
1955
1941
|
if (this.instanceCount === 0) return;
|
|
@@ -2315,15 +2301,15 @@ const Vt = (n, t) => {
|
|
|
2315
2301
|
}
|
|
2316
2302
|
return e;
|
|
2317
2303
|
};
|
|
2318
|
-
var
|
|
2304
|
+
var zt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(zt || {});
|
|
2319
2305
|
const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
2320
2306
|
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
2307
|
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(
|
|
2308
|
+
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);
|
|
2309
|
+
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
2310
|
}
|
|
2325
2311
|
return { vertices: a, uv: o };
|
|
2326
|
-
},
|
|
2312
|
+
}, Xt = (n, t = !1) => {
|
|
2327
2313
|
const e = [];
|
|
2328
2314
|
if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
|
|
2329
2315
|
const r = 4, i = 1e-3, s = n.length;
|
|
@@ -2341,10 +2327,10 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2341
2327
|
if (f < -1 + i)
|
|
2342
2328
|
return { normal: l.perpendicular(), miters: 1 };
|
|
2343
2329
|
{
|
|
2344
|
-
let
|
|
2345
|
-
l.cross(d) < 0 && (
|
|
2330
|
+
let m = d.add(l).normalize();
|
|
2331
|
+
l.cross(d) < 0 && (m = m.multiply(-1));
|
|
2346
2332
|
let g = 1 / Math.sqrt((1 - f) / 2);
|
|
2347
|
-
return { normal:
|
|
2333
|
+
return { normal: m, miters: Math.min(g, r) };
|
|
2348
2334
|
}
|
|
2349
2335
|
};
|
|
2350
2336
|
if (t)
|
|
@@ -2366,21 +2352,21 @@ const tt = 10, lt = (n, t, e, r, i, s) => {
|
|
|
2366
2352
|
}, jt = (n) => {
|
|
2367
2353
|
const t = n.points;
|
|
2368
2354
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2369
|
-
const { normals: e, length: r } =
|
|
2355
|
+
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
2356
|
let c = 0;
|
|
2371
2357
|
const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
|
|
2372
2358
|
for (let d = 0; d < l; d++) {
|
|
2373
|
-
const f = t[d],
|
|
2374
|
-
let
|
|
2375
|
-
h === 0 ? (
|
|
2376
|
-
const
|
|
2377
|
-
s.push(
|
|
2359
|
+
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, C = f.add(m.multiply(g * i)), S = f.subtract(m.multiply(g * i)), L = y.add(R.multiply(A * i)), X = y.subtract(R.multiply(A * i)), I = f.distanceTo(y);
|
|
2360
|
+
let w = 0, _ = 0;
|
|
2361
|
+
h === 0 ? (w = c / r, _ = (c + I) / r) : (w = c / u, _ = w + I / u);
|
|
2362
|
+
const D = new p(w, 0), k = new p(w, 1), G = new p(_, 0), O = new p(_, 1);
|
|
2363
|
+
s.push(C), a.push(D), s.push(S), a.push(k), s.push(L), a.push(G), s.push(L), a.push(G), s.push(X), a.push(O), s.push(S), a.push(k), c += I;
|
|
2378
2364
|
}
|
|
2379
2365
|
if (o && !n.closed) {
|
|
2380
|
-
const d = t[0], f = e[0].normal,
|
|
2366
|
+
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
2367
|
s.push(...g.vertices), a.push(...g.uv);
|
|
2382
|
-
const v = t[t.length - 1],
|
|
2383
|
-
s.push(...
|
|
2368
|
+
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, C = lt(v, y, i, !1, R, A);
|
|
2369
|
+
s.push(...C.vertices), a.push(...C.uv);
|
|
2384
2370
|
}
|
|
2385
2371
|
return { vertices: s, uv: a };
|
|
2386
2372
|
}, Q = (n, t, e, r) => {
|
|
@@ -2569,11 +2555,11 @@ class re extends at {
|
|
|
2569
2555
|
super(t);
|
|
2570
2556
|
}
|
|
2571
2557
|
createCustomShader(t) {
|
|
2572
|
-
const e =
|
|
2558
|
+
const e = H(dt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = H(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
2573
2559
|
return t.getGLShader(this, this.KEY, r, e);
|
|
2574
2560
|
}
|
|
2575
2561
|
createDefaultShader() {
|
|
2576
|
-
const t = this.rapid, e =
|
|
2562
|
+
const t = this.rapid, e = H(dt, t.maxTextureUnits), r = H(Z, t.maxTextureUnits);
|
|
2577
2563
|
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
2578
2564
|
}
|
|
2579
2565
|
}
|
|
@@ -2634,7 +2620,7 @@ void main(void) {\r
|
|
|
2634
2620
|
\r
|
|
2635
2621
|
// CUSTOM_CODE_CALL\r
|
|
2636
2622
|
}\r
|
|
2637
|
-
`,
|
|
2623
|
+
`, Y = 48, xt = Y / 4;
|
|
2638
2624
|
class ie extends at {
|
|
2639
2625
|
KEY = "ParticleSprite";
|
|
2640
2626
|
texture;
|
|
@@ -2655,46 +2641,46 @@ class ie extends at {
|
|
|
2655
2641
|
createShader(t, e) {
|
|
2656
2642
|
const r = super.createShader(t, e);
|
|
2657
2643
|
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:
|
|
2644
|
+
{ name: "aPosition", size: 2, stride: Y, offset: 0, divisor: 1 },
|
|
2645
|
+
{ name: "aScale", size: 2, stride: Y, offset: 8, divisor: 1 },
|
|
2646
|
+
{ name: "aRotation", size: 1, stride: Y, offset: 16, divisor: 1 },
|
|
2647
|
+
{ name: "aUVRect", size: 4, stride: Y, offset: 20, divisor: 1 },
|
|
2648
|
+
{ name: "aColor", size: 4, type: st, normalized: !0, stride: Y, offset: 36, divisor: 1 },
|
|
2649
|
+
{ name: "aOrigin", size: 2, stride: Y, offset: 40, divisor: 1 }
|
|
2664
2650
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
2665
2651
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2666
2652
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2667
2653
|
}
|
|
2668
|
-
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1,
|
|
2654
|
+
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, C) {
|
|
2669
2655
|
if (!t.glTexture || a <= 0) return;
|
|
2670
|
-
let
|
|
2671
|
-
const
|
|
2672
|
-
let
|
|
2673
|
-
|
|
2674
|
-
let
|
|
2675
|
-
X && (
|
|
2676
|
-
let
|
|
2677
|
-
for (
|
|
2656
|
+
let S = 0;
|
|
2657
|
+
const L = typeof o == "number", X = typeof h == "number", I = typeof i == "number", w = typeof s == "number", _ = !w && typeof s[0] == "number";
|
|
2658
|
+
let D = t.rawWidth * (f ? -1 : 1);
|
|
2659
|
+
L && (D *= o);
|
|
2660
|
+
let k = t.rawHeight * (m ? -1 : 1);
|
|
2661
|
+
X && (k *= h);
|
|
2662
|
+
let G = g ? Math.PI / 2 : 0;
|
|
2663
|
+
for (I && (G += i); S < a; ) {
|
|
2678
2664
|
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
|
|
2683
|
-
for (let
|
|
2684
|
-
const
|
|
2685
|
-
if (
|
|
2686
|
-
|
|
2687
|
-
else if (
|
|
2688
|
-
|
|
2665
|
+
const O = a - S, F = this.instanceBuffer;
|
|
2666
|
+
let b = F.usedElemNum;
|
|
2667
|
+
F.resize(O * xt);
|
|
2668
|
+
const N = F.float32, T = F.uint32;
|
|
2669
|
+
for (let M = 0; M < O; M++) {
|
|
2670
|
+
const V = A ? a - 1 - S - M : S + M;
|
|
2671
|
+
if (N[b] = e[V], N[b + 1] = r[V], N[b + 2] = L ? D : D * o[V], N[b + 3] = X ? k : k * h[V], N[b + 4] = I ? G : i[V] + G, N[b + 5] = c, N[b + 6] = u, N[b + 7] = l, N[b + 8] = d, w)
|
|
2672
|
+
T[b + 9] = 4294967295;
|
|
2673
|
+
else if (_)
|
|
2674
|
+
T[b + 9] = s[V];
|
|
2689
2675
|
else {
|
|
2690
|
-
const ht = s[
|
|
2691
|
-
|
|
2676
|
+
const ht = s[V];
|
|
2677
|
+
T[b + 9] = R ? ht.premultipliedUint32 : ht.uint32;
|
|
2692
2678
|
}
|
|
2693
|
-
|
|
2679
|
+
N[b + 10] = v, N[b + 11] = y, b += xt;
|
|
2694
2680
|
}
|
|
2695
|
-
|
|
2681
|
+
F.usedElemNum = b, F.makeDirty(), this.instanceCount += O, S += O;
|
|
2696
2682
|
}
|
|
2697
|
-
this.customMatrix =
|
|
2683
|
+
this.customMatrix = C, this.flush();
|
|
2698
2684
|
}
|
|
2699
2685
|
render() {
|
|
2700
2686
|
if (this.instanceCount === 0) return;
|
|
@@ -2720,7 +2706,7 @@ class ce {
|
|
|
2720
2706
|
/** The current device pixel ratio. */
|
|
2721
2707
|
dpr;
|
|
2722
2708
|
/** Background clear color [r, g, b, a], values range from 0 to 255. */
|
|
2723
|
-
backgroundColor =
|
|
2709
|
+
backgroundColor = x.Black;
|
|
2724
2710
|
/** Logical width in CSS pixels, used for coordinate system and projection matrix. */
|
|
2725
2711
|
logicWidth = 0;
|
|
2726
2712
|
/** Logical height in CSS pixels, used for coordinate system and projection matrix. */
|
|
@@ -2759,7 +2745,7 @@ class ce {
|
|
|
2759
2745
|
scaleMode;
|
|
2760
2746
|
/** Internal ping-pong RenderTextures for multi-filter chains. */
|
|
2761
2747
|
_filterRT = [null, null];
|
|
2762
|
-
_filterInput = new
|
|
2748
|
+
_filterInput = new B();
|
|
2763
2749
|
get height() {
|
|
2764
2750
|
return this.logicHeight;
|
|
2765
2751
|
}
|
|
@@ -2867,8 +2853,8 @@ class ce {
|
|
|
2867
2853
|
* @param v The V texture coordinate (0 to 1).
|
|
2868
2854
|
* @param color The vertex color as a 32-bit unsigned integer.
|
|
2869
2855
|
*/
|
|
2870
|
-
addGraphicVertex(t, e, r = 0, i = 0, s
|
|
2871
|
-
this.graphicRegion.addVertex(t, e, r, i, s);
|
|
2856
|
+
addGraphicVertex(t, e, r = 0, i = 0, s) {
|
|
2857
|
+
this.graphicRegion.addVertex(t, e, r, i, typeof s == "number" ? s : this.getColorUint32(s));
|
|
2872
2858
|
}
|
|
2873
2859
|
/**
|
|
2874
2860
|
* Ends the current graphics geometry definition, readying it for rendering.
|
|
@@ -2970,7 +2956,7 @@ class ce {
|
|
|
2970
2956
|
* @param rt The render texture to clear.
|
|
2971
2957
|
* @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
|
|
2972
2958
|
*/
|
|
2973
|
-
clearRenderTexture(t = new
|
|
2959
|
+
clearRenderTexture(t = new x(0, 0, 0, 0)) {
|
|
2974
2960
|
this.flush();
|
|
2975
2961
|
const e = this.gl;
|
|
2976
2962
|
t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
|
|
@@ -2992,7 +2978,7 @@ class ce {
|
|
|
2992
2978
|
* rapid.drawSprite({ texture: mySprite });
|
|
2993
2979
|
* });
|
|
2994
2980
|
*/
|
|
2995
|
-
drawToRenderTexture(t, e, r = new
|
|
2981
|
+
drawToRenderTexture(t, e, r = new x(0, 0, 0, 0)) {
|
|
2996
2982
|
this.enterRenderTexture(t);
|
|
2997
2983
|
try {
|
|
2998
2984
|
r !== null && this.clearRenderTexture(r), e();
|
|
@@ -3231,9 +3217,9 @@ class ce {
|
|
|
3231
3217
|
}
|
|
3232
3218
|
}
|
|
3233
3219
|
function he(n) {
|
|
3234
|
-
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof
|
|
3220
|
+
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof x);
|
|
3235
3221
|
}
|
|
3236
|
-
class
|
|
3222
|
+
class W {
|
|
3237
3223
|
/** Random float in [min, max). */
|
|
3238
3224
|
static float(t, e) {
|
|
3239
3225
|
return Math.random() * (e - t) + t;
|
|
@@ -3248,20 +3234,20 @@ class O {
|
|
|
3248
3234
|
}
|
|
3249
3235
|
/** Random Vec2 with components in the supplied per-axis ranges. */
|
|
3250
3236
|
static vector(t, e, r, i) {
|
|
3251
|
-
return new p(
|
|
3237
|
+
return new p(W.float(t, e), W.float(r, i));
|
|
3252
3238
|
}
|
|
3253
3239
|
/** Random Color with each component interpolated between minColor and maxColor. */
|
|
3254
3240
|
static randomColor(t, e) {
|
|
3255
|
-
return new
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3241
|
+
return new x(
|
|
3242
|
+
W.float(t.r, e.r),
|
|
3243
|
+
W.float(t.g, e.g),
|
|
3244
|
+
W.float(t.b, e.b),
|
|
3245
|
+
W.float(t.a, e.a)
|
|
3260
3246
|
);
|
|
3261
3247
|
}
|
|
3262
3248
|
/** Pick a random element from an array with uniform probability. */
|
|
3263
3249
|
static pick(t) {
|
|
3264
|
-
return t[
|
|
3250
|
+
return t[W.int(0, t.length - 1)];
|
|
3265
3251
|
}
|
|
3266
3252
|
/**
|
|
3267
3253
|
* Pick a random element using weighted probability.
|
|
@@ -3287,11 +3273,11 @@ class O {
|
|
|
3287
3273
|
if (Array.isArray(t)) {
|
|
3288
3274
|
const [r, i] = t;
|
|
3289
3275
|
if (typeof r == "number")
|
|
3290
|
-
return
|
|
3276
|
+
return W.float(r, i);
|
|
3291
3277
|
if (r instanceof p)
|
|
3292
|
-
return
|
|
3293
|
-
if (r instanceof
|
|
3294
|
-
return
|
|
3278
|
+
return W.vector(r.x, i.x, r.y, i.y);
|
|
3279
|
+
if (r instanceof x)
|
|
3280
|
+
return W.randomColor(r, i);
|
|
3295
3281
|
}
|
|
3296
3282
|
return typeof t == "number" ? t : t.clone();
|
|
3297
3283
|
}
|
|
@@ -3304,9 +3290,9 @@ class K {
|
|
|
3304
3290
|
if (!Number.isInteger(t) || t <= 0)
|
|
3305
3291
|
throw new RangeError("ParticleAttributeStore size must be a positive integer");
|
|
3306
3292
|
this.components = Array.from({ length: t }, () => ({
|
|
3307
|
-
value: new
|
|
3308
|
-
delta: new
|
|
3309
|
-
damping: new
|
|
3293
|
+
value: new P(U.Float32),
|
|
3294
|
+
delta: new P(U.Float32),
|
|
3295
|
+
damping: new P(U.Float32)
|
|
3310
3296
|
}));
|
|
3311
3297
|
}
|
|
3312
3298
|
getArrayBuffer() {
|
|
@@ -3339,7 +3325,7 @@ class K {
|
|
|
3339
3325
|
}
|
|
3340
3326
|
}
|
|
3341
3327
|
resolveComponent(t, e, r) {
|
|
3342
|
-
return t === void 0 ? r : Array.isArray(t) ?
|
|
3328
|
+
return t === void 0 ? r : Array.isArray(t) ? W.float(
|
|
3343
3329
|
this.getComponent(t[0], e),
|
|
3344
3330
|
this.getComponent(t[1], e)
|
|
3345
3331
|
) : this.getComponent(t, e);
|
|
@@ -3348,8 +3334,8 @@ class K {
|
|
|
3348
3334
|
const i = he(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
|
|
3349
3335
|
let o = 0;
|
|
3350
3336
|
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 ? (
|
|
3337
|
+
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);
|
|
3338
|
+
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
3339
|
}
|
|
3354
3340
|
return o;
|
|
3355
3341
|
}
|
|
@@ -3364,12 +3350,12 @@ class wt {
|
|
|
3364
3350
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3365
3351
|
localSpace = vt;
|
|
3366
3352
|
rapid;
|
|
3367
|
-
x = new
|
|
3368
|
-
y = new
|
|
3369
|
-
scaleX = new
|
|
3370
|
-
scaleY = new
|
|
3371
|
-
rotation = new
|
|
3372
|
-
color = new
|
|
3353
|
+
x = new P(U.Float32);
|
|
3354
|
+
y = new P(U.Float32);
|
|
3355
|
+
scaleX = new P(U.Float32);
|
|
3356
|
+
scaleY = new P(U.Float32);
|
|
3357
|
+
rotation = new P(U.Float32);
|
|
3358
|
+
color = new P(U.Uint32);
|
|
3373
3359
|
animations = {
|
|
3374
3360
|
speed: new K(),
|
|
3375
3361
|
rotation: new K(),
|
|
@@ -3440,7 +3426,7 @@ class wt {
|
|
|
3440
3426
|
this.createParticle();
|
|
3441
3427
|
}
|
|
3442
3428
|
createParticle() {
|
|
3443
|
-
const t =
|
|
3429
|
+
const t = W.scalarOrRange(this.options.life, 1);
|
|
3444
3430
|
let e = 0, r = 0;
|
|
3445
3431
|
switch (this.options.emitShape) {
|
|
3446
3432
|
case "circle": {
|
|
@@ -3461,7 +3447,7 @@ class wt {
|
|
|
3461
3447
|
this.x.push(c), this.y.push(u);
|
|
3462
3448
|
}
|
|
3463
3449
|
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,
|
|
3450
|
+
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
3451
|
a.color.get(this.count, 0),
|
|
3466
3452
|
a.color.get(this.count, 1),
|
|
3467
3453
|
a.color.get(this.count, 2),
|
|
@@ -3486,14 +3472,14 @@ class wt {
|
|
|
3486
3472
|
r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
|
|
3487
3473
|
}
|
|
3488
3474
|
const e = this.updateParticle(t);
|
|
3489
|
-
this.count -= e.length,
|
|
3475
|
+
this.count -= e.length, P.removeAtIndices(e, this.getAllArrayBuffer());
|
|
3490
3476
|
}
|
|
3491
3477
|
updateParticle(t) {
|
|
3492
3478
|
const e = [], r = this.animations;
|
|
3493
3479
|
Object.values(r).forEach((i) => i.update(t));
|
|
3494
3480
|
for (let i = 0; i < this.count; i++) {
|
|
3495
3481
|
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] =
|
|
3482
|
+
this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = x.packColor(
|
|
3497
3483
|
r.color.get(i, 0),
|
|
3498
3484
|
r.color.get(i, 1),
|
|
3499
3485
|
r.color.get(i, 2),
|
|
@@ -3538,15 +3524,15 @@ class wt {
|
|
|
3538
3524
|
}
|
|
3539
3525
|
export {
|
|
3540
3526
|
U as ArrayType,
|
|
3541
|
-
|
|
3527
|
+
z as BaseTexture,
|
|
3542
3528
|
ne as BlendMode,
|
|
3543
3529
|
ae as CanvasScaleMode,
|
|
3544
|
-
|
|
3530
|
+
x as Color,
|
|
3545
3531
|
ct as CustomGlShader,
|
|
3546
|
-
|
|
3532
|
+
P as DynamicArrayBuffer,
|
|
3547
3533
|
Tt as GLShader,
|
|
3548
3534
|
Ht as GraphicRegion,
|
|
3549
|
-
|
|
3535
|
+
zt as LineTextureMode,
|
|
3550
3536
|
se as MaskType,
|
|
3551
3537
|
At as MatrixStack,
|
|
3552
3538
|
Mt as MatrixStore,
|
|
@@ -3558,7 +3544,7 @@ export {
|
|
|
3558
3544
|
bt as RenderTexture,
|
|
3559
3545
|
at as SpriteRegion,
|
|
3560
3546
|
Ct as TextTexture,
|
|
3561
|
-
|
|
3547
|
+
B as Texture,
|
|
3562
3548
|
nt as TextureFilterMode,
|
|
3563
3549
|
St as TextureManager,
|
|
3564
3550
|
q as TextureWrapMode,
|