rapid-render 1.0.6 → 1.0.7
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 +0 -1
- package/dist/draw.d.ts +1 -1
- package/dist/matrix-engine.d.ts +5 -5
- package/dist/rapid-render.js +690 -670
- package/dist/rapid-render.umd.cjs +19 -19
- package/package.json +5 -4
package/dist/rapid-render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(I || {});
|
|
2
2
|
class B {
|
|
3
3
|
/** The number of elements currently used in the buffer. */
|
|
4
4
|
usedElemNum;
|
|
@@ -171,8 +171,8 @@ class Q extends B {
|
|
|
171
171
|
* @param type - Determines the type of WebGLBuffer (defaults to gl.ARRAY_BUFFER).
|
|
172
172
|
* @param usage - Determines the data usage pattern (defaults to gl.DYNAMIC_DRAW).
|
|
173
173
|
*/
|
|
174
|
-
constructor(t, e,
|
|
175
|
-
super(e), this.gl = t, this.buffer = t.createBuffer(), this.type =
|
|
174
|
+
constructor(t, e, r = t.ARRAY_BUFFER, i = t.DYNAMIC_DRAW) {
|
|
175
|
+
super(e), this.gl = t, this.buffer = t.createBuffer(), this.type = r, this.usage = i;
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
178
|
* Flags the buffer as dirty, marking it for future data synchronization.
|
|
@@ -202,7 +202,7 @@ class Q extends B {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
class
|
|
205
|
+
class p {
|
|
206
206
|
_r;
|
|
207
207
|
_g;
|
|
208
208
|
_b;
|
|
@@ -219,8 +219,8 @@ class m {
|
|
|
219
219
|
* @param b - The blue component (0-255).
|
|
220
220
|
* @param a - The alpha component (0-255).
|
|
221
221
|
*/
|
|
222
|
-
constructor(t, e,
|
|
223
|
-
this._r = t, this._g = e, this._b =
|
|
222
|
+
constructor(t, e, r, i = 255) {
|
|
223
|
+
this._r = t, this._g = e, this._b = r, this._a = i, this.updateUint();
|
|
224
224
|
}
|
|
225
225
|
setClearColor(t) {
|
|
226
226
|
t.clearColor(this.r / 255, this.g / 255, this.b / 255, this.a / 255);
|
|
@@ -283,8 +283,8 @@ class m {
|
|
|
283
283
|
*/
|
|
284
284
|
updateUint() {
|
|
285
285
|
this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
|
|
286
|
-
const t =
|
|
287
|
-
this.premultipliedUint32 = (t << 24 |
|
|
286
|
+
const t = p.clampByte(this._a), e = p.clampByte(this._r * t / 255), r = p.clampByte(this._g * t / 255), i = p.clampByte(this._b * t / 255);
|
|
287
|
+
this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
|
|
288
288
|
}
|
|
289
289
|
reset() {
|
|
290
290
|
this._r = 0, this._g = 0, this._b = 0, this._a = 255, this.updateUint();
|
|
@@ -296,14 +296,14 @@ class m {
|
|
|
296
296
|
* @param b - The blue component (0-255).
|
|
297
297
|
* @param a - The alpha component (0-255).
|
|
298
298
|
*/
|
|
299
|
-
setRGBA(t, e,
|
|
300
|
-
this.r = t, this.g = e, this.b =
|
|
299
|
+
setRGBA(t, e, r, i) {
|
|
300
|
+
this.r = t, this.g = e, this.b = r, this.a = i, this.updateUint();
|
|
301
301
|
}
|
|
302
|
-
setHSL(t, e,
|
|
303
|
-
t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100,
|
|
304
|
-
const
|
|
305
|
-
let
|
|
306
|
-
return t < 60 ? [
|
|
302
|
+
setHSL(t, e, r) {
|
|
303
|
+
t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100, r = Math.max(0, Math.min(100, r)) / 100;
|
|
304
|
+
const i = (1 - Math.abs(2 * r - 1)) * e, n = i * (1 - Math.abs(t / 60 % 2 - 1)), a = r - i / 2;
|
|
305
|
+
let c = 0, h = 0, o = 0;
|
|
306
|
+
return t < 60 ? [c, h, o] = [i, n, 0] : t < 120 ? [c, h, o] = [n, i, 0] : t < 180 ? [c, h, o] = [0, i, n] : t < 240 ? [c, h, o] = [0, n, i] : t < 300 ? [c, h, o] = [n, 0, i] : [c, h, o] = [i, 0, n], this.setRGBA((c + a) * 255, (h + a) * 255, (o + a) * 255, 255), this;
|
|
307
307
|
}
|
|
308
308
|
toHex() {
|
|
309
309
|
const t = (e) => Math.max(0, Math.min(255, Math.round(e))).toString(16).padStart(2, "0");
|
|
@@ -321,7 +321,7 @@ class m {
|
|
|
321
321
|
* @returns A new `Color` instance with the same RGBA values.
|
|
322
322
|
*/
|
|
323
323
|
clone() {
|
|
324
|
-
return new
|
|
324
|
+
return new p(this._r, this._g, this._b, this._a);
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
327
327
|
* Converts the color to a hexadecimal string representation (e.g., '#RRGGBBAA').
|
|
@@ -329,8 +329,8 @@ class m {
|
|
|
329
329
|
* @returns The hexadecimal string representation of the color.
|
|
330
330
|
*/
|
|
331
331
|
toHexString(t = !0) {
|
|
332
|
-
const e = this.r.toString(16).padStart(2, "0"),
|
|
333
|
-
return `#${e}${
|
|
332
|
+
const e = this.r.toString(16).padStart(2, "0"), r = this.g.toString(16).padStart(2, "0"), i = this.b.toString(16).padStart(2, "0"), n = this.a.toString(16).padStart(2, "0");
|
|
333
|
+
return `#${e}${r}${i}${t ? n : ""}`;
|
|
334
334
|
}
|
|
335
335
|
/**
|
|
336
336
|
* Checks if the current color is equal to another color.
|
|
@@ -354,18 +354,18 @@ class m {
|
|
|
354
354
|
* @example
|
|
355
355
|
* Color.fromNorm(0.9, 0.87, 0.55, 0.1) // moon glow
|
|
356
356
|
*/
|
|
357
|
-
static FromHSL(t, e,
|
|
358
|
-
return new
|
|
357
|
+
static FromHSL(t, e, r) {
|
|
358
|
+
return new p(0, 0, 0).setHSL(t, e, r);
|
|
359
359
|
}
|
|
360
|
-
static FromRGB(t, e,
|
|
361
|
-
return new
|
|
360
|
+
static FromRGB(t, e, r) {
|
|
361
|
+
return new p(t, e, r);
|
|
362
362
|
}
|
|
363
|
-
static fromNorm(t, e,
|
|
364
|
-
return new
|
|
363
|
+
static fromNorm(t, e, r, i = 1) {
|
|
364
|
+
return new p(
|
|
365
365
|
Math.round(t * 255),
|
|
366
366
|
Math.round(e * 255),
|
|
367
|
-
Math.round(
|
|
368
|
-
Math.round(
|
|
367
|
+
Math.round(r * 255),
|
|
368
|
+
Math.round(i * 255)
|
|
369
369
|
);
|
|
370
370
|
}
|
|
371
371
|
/**
|
|
@@ -375,9 +375,9 @@ class m {
|
|
|
375
375
|
*/
|
|
376
376
|
static fromHex(t) {
|
|
377
377
|
t.startsWith("#") && (t = t.slice(1));
|
|
378
|
-
const e = parseInt(t.slice(0, 2), 16),
|
|
378
|
+
const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
|
|
379
379
|
let n = 255;
|
|
380
|
-
return t.length >= 8 && (n = parseInt(t.slice(6, 8), 16)), new
|
|
380
|
+
return t.length >= 8 && (n = parseInt(t.slice(6, 8), 16)), new p(e, r, i, n);
|
|
381
381
|
}
|
|
382
382
|
/**
|
|
383
383
|
* Adds the components of another color to this color, clamping the result to 255.
|
|
@@ -385,7 +385,7 @@ class m {
|
|
|
385
385
|
* @returns A new Color instance with the result of the addition.
|
|
386
386
|
*/
|
|
387
387
|
add(t) {
|
|
388
|
-
return new
|
|
388
|
+
return new p(
|
|
389
389
|
Math.min(this.r + t.r, 255),
|
|
390
390
|
Math.min(this.g + t.g, 255),
|
|
391
391
|
Math.min(this.b + t.b, 255),
|
|
@@ -398,7 +398,7 @@ class m {
|
|
|
398
398
|
* @returns A new Color instance with the result of the subtraction.
|
|
399
399
|
*/
|
|
400
400
|
subtract(t) {
|
|
401
|
-
return new
|
|
401
|
+
return new p(
|
|
402
402
|
this.r - t.r,
|
|
403
403
|
this.g - t.g,
|
|
404
404
|
this.b - t.b,
|
|
@@ -406,12 +406,12 @@ class m {
|
|
|
406
406
|
);
|
|
407
407
|
}
|
|
408
408
|
divide(t) {
|
|
409
|
-
return t instanceof
|
|
409
|
+
return t instanceof p ? new p(
|
|
410
410
|
this.r / t.r,
|
|
411
411
|
this.g / t.g,
|
|
412
412
|
this.b / t.b,
|
|
413
413
|
this.a / t.a
|
|
414
|
-
) : new
|
|
414
|
+
) : new p(
|
|
415
415
|
this.r / t,
|
|
416
416
|
this.g / t,
|
|
417
417
|
this.b / t,
|
|
@@ -419,12 +419,12 @@ class m {
|
|
|
419
419
|
);
|
|
420
420
|
}
|
|
421
421
|
multiply(t) {
|
|
422
|
-
return t instanceof
|
|
422
|
+
return t instanceof p ? new p(
|
|
423
423
|
this.r * t.r,
|
|
424
424
|
this.g * t.g,
|
|
425
425
|
this.b * t.b,
|
|
426
426
|
this.a * t.a
|
|
427
|
-
) : new
|
|
427
|
+
) : new p(
|
|
428
428
|
this.r * t,
|
|
429
429
|
this.g * t,
|
|
430
430
|
this.b * t,
|
|
@@ -434,24 +434,24 @@ class m {
|
|
|
434
434
|
clamp() {
|
|
435
435
|
this.r = Math.max(0, Math.min(255, this.r)), this.g = Math.max(0, Math.min(255, this.g)), this.b = Math.max(0, Math.min(255, this.b)), this.a = Math.max(0, Math.min(255, this.a));
|
|
436
436
|
}
|
|
437
|
-
static Red = new
|
|
438
|
-
static Green = new
|
|
439
|
-
static Blue = new
|
|
440
|
-
static Yellow = new
|
|
441
|
-
static Purple = new
|
|
442
|
-
static Orange = new
|
|
443
|
-
static Pink = new
|
|
444
|
-
static Gray = new
|
|
445
|
-
static Brown = new
|
|
446
|
-
static Cyan = new
|
|
447
|
-
static Magenta = new
|
|
448
|
-
static Lime = new
|
|
449
|
-
static White = new
|
|
450
|
-
static Black = new
|
|
451
|
-
static Transparent = new
|
|
452
|
-
static TRANSPARENT = new
|
|
437
|
+
static Red = new p(255, 0, 0, 255);
|
|
438
|
+
static Green = new p(0, 255, 0, 255);
|
|
439
|
+
static Blue = new p(0, 0, 255, 255);
|
|
440
|
+
static Yellow = new p(255, 255, 0, 255);
|
|
441
|
+
static Purple = new p(128, 0, 128, 255);
|
|
442
|
+
static Orange = new p(255, 165, 0, 255);
|
|
443
|
+
static Pink = new p(255, 192, 203, 255);
|
|
444
|
+
static Gray = new p(128, 128, 128, 255);
|
|
445
|
+
static Brown = new p(139, 69, 19, 255);
|
|
446
|
+
static Cyan = new p(0, 255, 255, 255);
|
|
447
|
+
static Magenta = new p(255, 0, 255, 255);
|
|
448
|
+
static Lime = new p(192, 255, 0, 255);
|
|
449
|
+
static White = new p(255, 255, 255, 255);
|
|
450
|
+
static Black = new p(0, 0, 0, 255);
|
|
451
|
+
static Transparent = new p(0, 0, 0, 0);
|
|
452
|
+
static TRANSPARENT = new p(0, 0, 0, 0);
|
|
453
453
|
}
|
|
454
|
-
const
|
|
454
|
+
const y = 6;
|
|
455
455
|
class Mt {
|
|
456
456
|
/** Total number of matrices currently allocated in the store. */
|
|
457
457
|
matrixCount = 0;
|
|
@@ -459,12 +459,13 @@ class Mt {
|
|
|
459
459
|
buffer;
|
|
460
460
|
/** The raw floating-point data of all matrices. */
|
|
461
461
|
data;
|
|
462
|
+
temporary = -1;
|
|
462
463
|
/**
|
|
463
464
|
* Creates a new MatrixStore.
|
|
464
465
|
* @param capacity - The initial capacity of the matrix store (default is 10).
|
|
465
466
|
*/
|
|
466
467
|
constructor(t = 10) {
|
|
467
|
-
this.buffer = new B(
|
|
468
|
+
this.buffer = new B(I.Float32), this.buffer.resize(t * y), this.data = this.buffer.getArray(), this.reset();
|
|
468
469
|
}
|
|
469
470
|
/**
|
|
470
471
|
* Allocates a new matrix and initializes it to the identity matrix.
|
|
@@ -479,21 +480,21 @@ class Mt {
|
|
|
479
480
|
* @returns The index of the newly allocated matrix.
|
|
480
481
|
*/
|
|
481
482
|
allocDirty() {
|
|
482
|
-
return this.buffer.resize(
|
|
483
|
+
return this.buffer.resize(y) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += y, this.matrixCount++;
|
|
483
484
|
}
|
|
484
485
|
/**
|
|
485
486
|
* Resets the store, clearing all allocated matrices.
|
|
486
487
|
*/
|
|
487
488
|
reset() {
|
|
488
|
-
this.matrixCount = 0, this.buffer.usedElemNum = 0;
|
|
489
|
+
this.matrixCount = 0, this.buffer.usedElemNum = 0, this.temporary = this.alloc();
|
|
489
490
|
}
|
|
490
491
|
/**
|
|
491
492
|
* Sets the matrix at the given index to the identity matrix.
|
|
492
493
|
* @param index - The index of the matrix to modify.
|
|
493
494
|
*/
|
|
494
495
|
identity(t) {
|
|
495
|
-
const e = t *
|
|
496
|
-
|
|
496
|
+
const e = t * y, r = this.data;
|
|
497
|
+
r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
|
|
497
498
|
}
|
|
498
499
|
/**
|
|
499
500
|
* Translates the matrix at the given index by x and y.
|
|
@@ -501,9 +502,9 @@ class Mt {
|
|
|
501
502
|
* @param x - The x translation.
|
|
502
503
|
* @param y - The y translation.
|
|
503
504
|
*/
|
|
504
|
-
translate(t, e,
|
|
505
|
-
const
|
|
506
|
-
n[
|
|
505
|
+
translate(t, e, r) {
|
|
506
|
+
const i = t * y, n = this.data;
|
|
507
|
+
n[i + 4] = n[i] * e + n[i + 2] * r + n[i + 4], n[i + 5] = n[i + 1] * e + n[i + 3] * r + n[i + 5];
|
|
507
508
|
}
|
|
508
509
|
/**
|
|
509
510
|
* Scales the matrix at the given index by scaleX and scaleY.
|
|
@@ -511,9 +512,9 @@ class Mt {
|
|
|
511
512
|
* @param scaleX - The scale factor along the x-axis.
|
|
512
513
|
* @param scaleY - The scale factor along the y-axis.
|
|
513
514
|
*/
|
|
514
|
-
scale(t, e,
|
|
515
|
-
const
|
|
516
|
-
n[
|
|
515
|
+
scale(t, e, r) {
|
|
516
|
+
const i = t * y, n = this.data;
|
|
517
|
+
n[i] *= e, n[i + 1] *= e, n[i + 2] *= r, n[i + 3] *= r;
|
|
517
518
|
}
|
|
518
519
|
/**
|
|
519
520
|
* Rotates the matrix at the given index by the specified radians.
|
|
@@ -521,8 +522,8 @@ class Mt {
|
|
|
521
522
|
* @param radians - The rotation angle in radians.
|
|
522
523
|
*/
|
|
523
524
|
rotate(t, e) {
|
|
524
|
-
const
|
|
525
|
-
r
|
|
525
|
+
const r = t * y, i = this.data, n = Math.cos(e), a = Math.sin(e), c = i[r], h = i[r + 1], o = i[r + 2], u = i[r + 3];
|
|
526
|
+
i[r] = c * n + o * a, i[r + 1] = h * n + u * a, i[r + 2] = c * -a + o * n, i[r + 3] = h * -a + u * n;
|
|
526
527
|
}
|
|
527
528
|
/**
|
|
528
529
|
* Rotates the matrix at the given index around a local offset point (pivot).
|
|
@@ -540,8 +541,8 @@ class Mt {
|
|
|
540
541
|
* @param offsetX - The x component of the pivot point in local space.
|
|
541
542
|
* @param offsetY - The y component of the pivot point in local space.
|
|
542
543
|
*/
|
|
543
|
-
rotateWithOffset(t, e,
|
|
544
|
-
this.translate(t,
|
|
544
|
+
rotateWithOffset(t, e, r, i) {
|
|
545
|
+
this.translate(t, r, i), this.rotate(t, e), this.translate(t, -r, -i);
|
|
545
546
|
}
|
|
546
547
|
/**
|
|
547
548
|
* Copies the elements from the source matrix to the destination matrix.
|
|
@@ -549,8 +550,8 @@ class Mt {
|
|
|
549
550
|
* @param src - The index of the source matrix.
|
|
550
551
|
*/
|
|
551
552
|
copy(t, e) {
|
|
552
|
-
const
|
|
553
|
-
n[
|
|
553
|
+
const r = t * y, i = e * y, n = this.data;
|
|
554
|
+
n[r] = n[i], n[r + 1] = n[i + 1], n[r + 2] = n[i + 2], n[r + 3] = n[i + 3], n[r + 4] = n[i + 4], n[r + 5] = n[i + 5];
|
|
554
555
|
}
|
|
555
556
|
/**
|
|
556
557
|
* Multiplies the destination matrix by the source matrix and stores the result in the destination.
|
|
@@ -566,22 +567,22 @@ class Mt {
|
|
|
566
567
|
* @param aIdx - The index of matrix A.
|
|
567
568
|
* @param bIdx - The index of matrix B.
|
|
568
569
|
*/
|
|
569
|
-
multiplyOut(t, e,
|
|
570
|
-
const
|
|
571
|
-
|
|
570
|
+
multiplyOut(t, e, r) {
|
|
571
|
+
const i = t * y, n = e * y, a = r * y, c = this.data, h = c[n], o = c[n + 1], u = c[n + 2], l = c[n + 3], d = c[n + 4], f = c[n + 5], x = c[a], g = c[a + 1], v = c[a + 2], T = c[a + 3], R = c[a + 4], E = c[a + 5];
|
|
572
|
+
c[i] = h * x + u * g, c[i + 1] = o * x + l * g, c[i + 2] = h * v + u * T, c[i + 3] = o * v + l * T, c[i + 4] = h * R + u * E + d, c[i + 5] = o * R + l * E + f;
|
|
572
573
|
}
|
|
573
574
|
/**
|
|
574
575
|
* Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
|
|
575
576
|
* @param index - The index of the matrix to invert.
|
|
576
577
|
*/
|
|
577
578
|
invert(t) {
|
|
578
|
-
const e = t *
|
|
579
|
-
let u =
|
|
579
|
+
const e = t * y, r = this.data, i = r[e], n = r[e + 1], a = r[e + 2], c = r[e + 3], h = r[e + 4], o = r[e + 5];
|
|
580
|
+
let u = i * c - n * a;
|
|
580
581
|
if (!u) {
|
|
581
582
|
this.identity(t);
|
|
582
583
|
return;
|
|
583
584
|
}
|
|
584
|
-
u = 1 / u,
|
|
585
|
+
u = 1 / u, r[e] = c * u, r[e + 1] = -n * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * o - c * h) * u, r[e + 5] = (n * h - i * o) * u;
|
|
585
586
|
}
|
|
586
587
|
/**
|
|
587
588
|
* Transforms a point by the matrix at the given index.
|
|
@@ -590,11 +591,11 @@ class Mt {
|
|
|
590
591
|
* @param y - The y coordinate of the point.
|
|
591
592
|
* @returns The transformed point {x, y}.
|
|
592
593
|
*/
|
|
593
|
-
transformPoint(t, e,
|
|
594
|
-
const
|
|
594
|
+
transformPoint(t, e, r) {
|
|
595
|
+
const i = t * y, n = this.data;
|
|
595
596
|
return {
|
|
596
|
-
x: e * n[
|
|
597
|
-
y: e * n[
|
|
597
|
+
x: e * n[i] + r * n[i + 2] + n[i + 4],
|
|
598
|
+
y: e * n[i + 1] + r * n[i + 3] + n[i + 5]
|
|
598
599
|
};
|
|
599
600
|
}
|
|
600
601
|
/**
|
|
@@ -605,11 +606,11 @@ class Mt {
|
|
|
605
606
|
* @param y - World y coordinate.
|
|
606
607
|
* @returns The transformed point in local coordinates.
|
|
607
608
|
*/
|
|
608
|
-
worldToLocal(t, e,
|
|
609
|
-
const
|
|
610
|
-
this.copy(
|
|
611
|
-
const n = this.transformPoint(
|
|
612
|
-
return this.matrixCount--, this.buffer.usedElemNum -=
|
|
609
|
+
worldToLocal(t, e, r) {
|
|
610
|
+
const i = this.allocDirty();
|
|
611
|
+
this.copy(i, t), this.invert(i);
|
|
612
|
+
const n = this.transformPoint(i, e, r);
|
|
613
|
+
return this.matrixCount--, this.buffer.usedElemNum -= y, n;
|
|
613
614
|
}
|
|
614
615
|
/**
|
|
615
616
|
* Transforms a point from local coordinates to world coordinates.
|
|
@@ -618,8 +619,8 @@ class Mt {
|
|
|
618
619
|
* @param y - Local y coordinate.
|
|
619
620
|
* @returns The transformed point in world coordinates.
|
|
620
621
|
*/
|
|
621
|
-
localToWorld(t, e,
|
|
622
|
-
return this.transformPoint(t, e,
|
|
622
|
+
localToWorld(t, e, r) {
|
|
623
|
+
return this.transformPoint(t, e, r);
|
|
623
624
|
}
|
|
624
625
|
/**
|
|
625
626
|
* Extracts the global position (translation) from the matrix at the given index.
|
|
@@ -627,8 +628,8 @@ class Mt {
|
|
|
627
628
|
* @returns An object containing `x` and `y` global coordinates.
|
|
628
629
|
*/
|
|
629
630
|
getPosition(t) {
|
|
630
|
-
const e = t *
|
|
631
|
-
return { x:
|
|
631
|
+
const e = t * y, r = this.data;
|
|
632
|
+
return { x: r[e + 4], y: r[e + 5] };
|
|
632
633
|
}
|
|
633
634
|
/**
|
|
634
635
|
* Extracts the global scale from the matrix at the given index.
|
|
@@ -636,8 +637,8 @@ class Mt {
|
|
|
636
637
|
* @returns An object containing `x` and `y` global scale factors.
|
|
637
638
|
*/
|
|
638
639
|
getScale(t) {
|
|
639
|
-
const e = t *
|
|
640
|
-
return { x:
|
|
640
|
+
const e = t * y, r = this.data, i = Math.sqrt(r[e] * r[e] + r[e + 1] * r[e + 1]), n = Math.sqrt(r[e + 2] * r[e + 2] + r[e + 3] * r[e + 3]);
|
|
641
|
+
return { x: i, y: n };
|
|
641
642
|
}
|
|
642
643
|
/**
|
|
643
644
|
* Extracts the global rotation (in radians) from the matrix at the given index.
|
|
@@ -645,8 +646,8 @@ class Mt {
|
|
|
645
646
|
* @returns The global rotation in radians.
|
|
646
647
|
*/
|
|
647
648
|
getRotation(t) {
|
|
648
|
-
const e = t *
|
|
649
|
-
return Math.atan2(
|
|
649
|
+
const e = t * y, r = this.data;
|
|
650
|
+
return Math.atan2(r[e + 1], r[e]);
|
|
650
651
|
}
|
|
651
652
|
/**
|
|
652
653
|
* Converts the matrix at the given index to a CSS matrix string.
|
|
@@ -655,9 +656,9 @@ class Mt {
|
|
|
655
656
|
* @param scaleY - Extra scale applied to the b/d/ty components.
|
|
656
657
|
* @returns A CSS matrix string.
|
|
657
658
|
*/
|
|
658
|
-
toCSSMatrix(t, e = 1,
|
|
659
|
-
const
|
|
660
|
-
return `matrix(${n[
|
|
659
|
+
toCSSMatrix(t, e = 1, r = 1) {
|
|
660
|
+
const i = t * y, n = this.data;
|
|
661
|
+
return `matrix(${n[i] * e}, ${n[i + 1] * r}, ${n[i + 2] * e}, ${n[i + 3] * r}, ${n[i + 4] * e}, ${n[i + 5] * r})`;
|
|
661
662
|
}
|
|
662
663
|
/**
|
|
663
664
|
* Retrieves a copy of the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
|
|
@@ -667,8 +668,8 @@ class Mt {
|
|
|
667
668
|
* @returns A new Float32Array containing the 6 elements of the matrix.
|
|
668
669
|
*/
|
|
669
670
|
getMatrix(t) {
|
|
670
|
-
const e = t *
|
|
671
|
-
return this.data.slice(e, e +
|
|
671
|
+
const e = t * y;
|
|
672
|
+
return this.data.slice(e, e + y);
|
|
672
673
|
}
|
|
673
674
|
/**
|
|
674
675
|
* Retrieves a direct reference (view) to the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
|
|
@@ -678,8 +679,8 @@ class Mt {
|
|
|
678
679
|
* @returns A Float32Array view pointing directly to the matrix's data in memory.
|
|
679
680
|
*/
|
|
680
681
|
getMatrixRef(t) {
|
|
681
|
-
const e = t *
|
|
682
|
-
return this.data.subarray(e, e +
|
|
682
|
+
const e = t * y;
|
|
683
|
+
return this.data.subarray(e, e + y);
|
|
683
684
|
}
|
|
684
685
|
/**
|
|
685
686
|
* Overwrites the matrix at the specified index with the provided 6 elements [a, b, c, d, tx, ty].
|
|
@@ -688,12 +689,16 @@ class Mt {
|
|
|
688
689
|
* @param f - An array (Float32Array or standard number array) containing the 6 new elements.
|
|
689
690
|
*/
|
|
690
691
|
setMatrix(t, e) {
|
|
691
|
-
const
|
|
692
|
-
r
|
|
692
|
+
const r = t * y, i = this.data;
|
|
693
|
+
i[r] = e[0], i[r + 1] = e[1], i[r + 2] = e[2], i[r + 3] = e[3], i[r + 4] = e[4], i[r + 5] = e[5];
|
|
694
|
+
}
|
|
695
|
+
multiplyAffineInPlace(t, e, r, i, n, a, c) {
|
|
696
|
+
const h = t * 6, o = this.data, u = o[h], l = o[h + 1], d = o[h + 2], f = o[h + 3], x = o[h + 4], g = o[h + 5];
|
|
697
|
+
o[h] = u * e + d * r, o[h + 1] = l * e + f * r, o[h + 2] = u * i + d * n, o[h + 3] = l * i + f * n, o[h + 4] = u * a + d * c + x, o[h + 5] = l * a + f * c + g;
|
|
693
698
|
}
|
|
694
|
-
|
|
695
|
-
const
|
|
696
|
-
|
|
699
|
+
multiplyAffine(t, e, r, i, n, a, c, h) {
|
|
700
|
+
const o = t * 6, u = e * 6, l = this.data, d = l[o], f = l[o + 1], x = l[o + 2], g = l[o + 3], v = l[o + 4], T = l[o + 5];
|
|
701
|
+
l[u] = d * r + x * i, l[u + 1] = f * r + g * i, l[u + 2] = d * n + x * a, l[u + 3] = f * n + g * a, l[u + 4] = d * c + x * h + v, l[u + 5] = f * c + g * h + T;
|
|
697
702
|
}
|
|
698
703
|
}
|
|
699
704
|
class St {
|
|
@@ -702,15 +707,15 @@ class St {
|
|
|
702
707
|
/** The current step or depth in the transformation hierarchy. */
|
|
703
708
|
step = 0;
|
|
704
709
|
/** Internal stack maintaining structural information. */
|
|
705
|
-
stack = new B(
|
|
710
|
+
stack = new B(I.Uint32);
|
|
706
711
|
/** Records the world matrices generated at each step. */
|
|
707
|
-
stepWorldM = new B(
|
|
712
|
+
stepWorldM = new B(I.Uint32);
|
|
708
713
|
/** Records actions (push/pop) taken during the traversal. */
|
|
709
|
-
stepAction = new B(
|
|
714
|
+
stepAction = new B(I.Uint32);
|
|
710
715
|
/** Records the parent world matrix for each step (used by updateMatrix). */
|
|
711
|
-
stepParentM = new B(
|
|
716
|
+
stepParentM = new B(I.Uint32);
|
|
712
717
|
/** Buffer used during hierarchy traversal updates. */
|
|
713
|
-
parentStack = new B(
|
|
718
|
+
parentStack = new B(I.Uint32);
|
|
714
719
|
/** The index of the current local matrix in the matrix store. */
|
|
715
720
|
curLocalM = -1;
|
|
716
721
|
/** The index of the current world matrix in the matrix store. */
|
|
@@ -744,14 +749,14 @@ class St {
|
|
|
744
749
|
* @param step - The initial step to update matrices from.
|
|
745
750
|
*/
|
|
746
751
|
updateMatrix(t) {
|
|
747
|
-
const e = (typeof t == "number" ? t : t.step) - 1,
|
|
748
|
-
let
|
|
752
|
+
const e = (typeof t == "number" ? t : t.step) - 1, r = this.stepParentM.get(e);
|
|
753
|
+
let i = 0, n = e;
|
|
749
754
|
const a = this.parentStack;
|
|
750
|
-
for (a.reset(), a.push(
|
|
755
|
+
for (a.reset(), a.push(r); n < this.stepAction.length; ) {
|
|
751
756
|
if (this.stepAction.get(n) === 1) {
|
|
752
|
-
const h = this.stepWorldM.get(n),
|
|
753
|
-
this.matrix.multiplyOut(h, u,
|
|
754
|
-
} else if (a.pop(),
|
|
757
|
+
const h = this.stepWorldM.get(n), o = h - 1, u = a.top();
|
|
758
|
+
this.matrix.multiplyOut(h, u, o), a.push(h), i++;
|
|
759
|
+
} else if (a.pop(), i--, i === 0)
|
|
755
760
|
break;
|
|
756
761
|
n++;
|
|
757
762
|
}
|
|
@@ -796,8 +801,8 @@ class St {
|
|
|
796
801
|
* @param offsetX - The x component of the pivot point in local space.
|
|
797
802
|
* @param offsetY - The y component of the pivot point in local space.
|
|
798
803
|
*/
|
|
799
|
-
rotateWithOffset(t, e,
|
|
800
|
-
this.matrix.rotateWithOffset(this.curLocalM, t, e,
|
|
804
|
+
rotateWithOffset(t, e, r) {
|
|
805
|
+
this.matrix.rotateWithOffset(this.curLocalM, t, e, r), this.matrix.rotateWithOffset(this.curWorldM, t, e, r);
|
|
801
806
|
}
|
|
802
807
|
/**
|
|
803
808
|
* Sets the current local and world matrices to the identity matrix.
|
|
@@ -859,53 +864,65 @@ class St {
|
|
|
859
864
|
* Returns the current world matrix as Float32Array [a, b, c, d, tx, ty].
|
|
860
865
|
*/
|
|
861
866
|
getTransform() {
|
|
862
|
-
const t = this.curWorldM *
|
|
863
|
-
return this.matrix.data.slice(t, t +
|
|
867
|
+
const t = this.curWorldM * y;
|
|
868
|
+
return this.matrix.data.slice(t, t + y);
|
|
864
869
|
}
|
|
865
870
|
/**
|
|
866
871
|
* Directly overwrites the current world matrix with the given 6-element 2D transform.
|
|
867
872
|
*/
|
|
868
873
|
setTransform(t) {
|
|
869
|
-
const e = this.curWorldM *
|
|
870
|
-
|
|
874
|
+
const e = this.curWorldM * y, r = this.matrix.data;
|
|
875
|
+
r[e] = t[0], r[e + 1] = t[1], r[e + 2] = t[2], r[e + 3] = t[3], r[e + 4] = t[4], r[e + 5] = t[5];
|
|
871
876
|
}
|
|
872
877
|
transformPoint(t, e) {
|
|
873
878
|
return this.matrix.transformPoint(this.curLocalM, t, e);
|
|
874
879
|
}
|
|
875
880
|
/**
|
|
876
881
|
* Applies a transform options object to the current matrix state.
|
|
877
|
-
* Optionally saves the matrix first
|
|
878
|
-
*/
|
|
879
|
-
applyTransform(t, e = 0, i =
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
882
|
+
* Optionally saves the matrix first
|
|
883
|
+
*/
|
|
884
|
+
applyTransform(t, e = 0, r = 0, i = -1) {
|
|
885
|
+
let n = t.x ?? 0, a = t.y ?? 0;
|
|
886
|
+
t.position && (n += t.position.x, a += t.position.y);
|
|
887
|
+
let c = 1, h = 1;
|
|
888
|
+
const o = t.scale;
|
|
889
|
+
o && (typeof o == "number" ? (c = o, h = o) : (c = o.x, h = o.y));
|
|
890
|
+
const u = t.rotation ?? 0;
|
|
891
|
+
let l = t.offsetX ?? 0, d = t.offsetY ?? 0;
|
|
892
|
+
t.offset && (l += t.offset.x, d += t.offset.y);
|
|
893
|
+
const f = t.origin;
|
|
894
|
+
f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
|
|
895
|
+
const x = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = x * c, T = g * c, R = -g * h, E = x * h, b = n + v * l + R * d, N = a + T * l + E * d;
|
|
896
|
+
if (i !== -1) {
|
|
897
|
+
this.matrix.multiplyAffine(
|
|
898
|
+
this.curWorldM,
|
|
899
|
+
i,
|
|
900
|
+
v,
|
|
901
|
+
T,
|
|
902
|
+
R,
|
|
903
|
+
E,
|
|
904
|
+
b,
|
|
905
|
+
N
|
|
906
|
+
);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
this.matrix.multiplyAffineInPlace(
|
|
893
910
|
this.curLocalM,
|
|
894
|
-
|
|
911
|
+
v,
|
|
895
912
|
T,
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
913
|
+
R,
|
|
914
|
+
E,
|
|
915
|
+
b,
|
|
916
|
+
N
|
|
900
917
|
), this.matrix.multiplyAffineInPlace(
|
|
901
918
|
this.curWorldM,
|
|
902
|
-
|
|
919
|
+
v,
|
|
903
920
|
T,
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
)
|
|
921
|
+
R,
|
|
922
|
+
E,
|
|
923
|
+
b,
|
|
924
|
+
N
|
|
925
|
+
);
|
|
909
926
|
}
|
|
910
927
|
}
|
|
911
928
|
var Y = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(Y || {});
|
|
@@ -922,14 +939,14 @@ class bt {
|
|
|
922
939
|
* @returns A promise that resolves to the loaded Texture.
|
|
923
940
|
*/
|
|
924
941
|
async load(t, e) {
|
|
925
|
-
let
|
|
926
|
-
if (
|
|
927
|
-
return new P(
|
|
942
|
+
let r = this.cache.get(t);
|
|
943
|
+
if (r)
|
|
944
|
+
return new P(r);
|
|
928
945
|
try {
|
|
929
|
-
const
|
|
930
|
-
return
|
|
931
|
-
} catch (
|
|
932
|
-
throw console.error(`[TextureManager] Failed to load: ${t}`,
|
|
946
|
+
const i = await this._fetchImage(t);
|
|
947
|
+
return r = k.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new P(r);
|
|
948
|
+
} catch (i) {
|
|
949
|
+
throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
|
|
933
950
|
}
|
|
934
951
|
}
|
|
935
952
|
/**
|
|
@@ -941,8 +958,8 @@ class bt {
|
|
|
941
958
|
create(t, e) {
|
|
942
959
|
if (e?.key && this.cache.has(e.key))
|
|
943
960
|
return new P(this.cache.get(e.key));
|
|
944
|
-
const
|
|
945
|
-
return e?.key && (
|
|
961
|
+
const r = k.fromSource(this.render, t, e);
|
|
962
|
+
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new P(r);
|
|
946
963
|
}
|
|
947
964
|
/**
|
|
948
965
|
* Creates a generic Render Texture (FrameBuffer).
|
|
@@ -970,8 +987,8 @@ class bt {
|
|
|
970
987
|
* @param force - If true, destroys the underlying BaseTexture immediately regardless of reference count.
|
|
971
988
|
*/
|
|
972
989
|
destroy(t, e = !1) {
|
|
973
|
-
let
|
|
974
|
-
typeof t == "string" ? (
|
|
990
|
+
let r, i;
|
|
991
|
+
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof P ? (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));
|
|
975
992
|
}
|
|
976
993
|
/**
|
|
977
994
|
* Destroys all cached textures and clears the cache, ignoring reference counts.
|
|
@@ -982,9 +999,9 @@ class bt {
|
|
|
982
999
|
this.cache.clear();
|
|
983
1000
|
}
|
|
984
1001
|
_fetchImage(t) {
|
|
985
|
-
return new Promise((e,
|
|
986
|
-
const
|
|
987
|
-
|
|
1002
|
+
return new Promise((e, r) => {
|
|
1003
|
+
const i = new Image();
|
|
1004
|
+
i.crossOrigin = "anonymous", i.onload = () => e(i), i.onerror = () => r(new Error(`Failed to load image resource: ${t}`)), i.src = t;
|
|
988
1005
|
});
|
|
989
1006
|
}
|
|
990
1007
|
}
|
|
@@ -994,8 +1011,8 @@ class k {
|
|
|
994
1011
|
height;
|
|
995
1012
|
uid;
|
|
996
1013
|
refCount = 0;
|
|
997
|
-
constructor(t, e,
|
|
998
|
-
this.glTexture = t, this.width = e, this.height =
|
|
1014
|
+
constructor(t, e, r) {
|
|
1015
|
+
this.glTexture = t, this.width = e, this.height = r;
|
|
999
1016
|
}
|
|
1000
1017
|
/**
|
|
1001
1018
|
* Creates a BaseTexture from an image source.
|
|
@@ -1004,9 +1021,9 @@ class k {
|
|
|
1004
1021
|
* @param options - Optional configuration.
|
|
1005
1022
|
* @returns The created BaseTexture.
|
|
1006
1023
|
*/
|
|
1007
|
-
static fromSource(t, e,
|
|
1008
|
-
const
|
|
1009
|
-
return new k(
|
|
1024
|
+
static fromSource(t, e, r = {}) {
|
|
1025
|
+
const i = K(t, e, r);
|
|
1026
|
+
return new k(i, e.width, e.height);
|
|
1010
1027
|
}
|
|
1011
1028
|
/**
|
|
1012
1029
|
* Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
|
|
@@ -1014,8 +1031,8 @@ class k {
|
|
|
1014
1031
|
* @param gl - The WebGL rendering context.
|
|
1015
1032
|
* @param source - The new image source.
|
|
1016
1033
|
*/
|
|
1017
|
-
updateSource(t, e,
|
|
1018
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1034
|
+
updateSource(t, e, r = {}) {
|
|
1035
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && tt(t, r.textureFilter), r.wrap !== void 0 && J(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
|
|
1019
1036
|
}
|
|
1020
1037
|
/**
|
|
1021
1038
|
* Dynamically updates the texture filtering mode.
|
|
@@ -1082,8 +1099,8 @@ class P {
|
|
|
1082
1099
|
* @param h - The height in pixels.
|
|
1083
1100
|
* @returns The current Texture instance.
|
|
1084
1101
|
*/
|
|
1085
|
-
setRegion(t, e,
|
|
1086
|
-
return this.base ? (this._px = t, this._py = e, this._pw =
|
|
1102
|
+
setRegion(t, e, r, i) {
|
|
1103
|
+
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;
|
|
1087
1104
|
}
|
|
1088
1105
|
/**
|
|
1089
1106
|
* Creates a new Texture representing a sub-region of this Texture.
|
|
@@ -1093,10 +1110,10 @@ class P {
|
|
|
1093
1110
|
* @param height - The height of the sub-texture in pixels.
|
|
1094
1111
|
* @returns A new Texture pointing to the sub-region.
|
|
1095
1112
|
*/
|
|
1096
|
-
getSubTexture(t, e,
|
|
1113
|
+
getSubTexture(t, e, r, i) {
|
|
1097
1114
|
if (!this.base) return new P();
|
|
1098
|
-
const n = this.clone(), a = this._px,
|
|
1099
|
-
return n.setRegion(a + t,
|
|
1115
|
+
const n = this.clone(), a = this._px, c = this._py;
|
|
1116
|
+
return n.setRegion(a + t, c + e, r, i), n;
|
|
1100
1117
|
}
|
|
1101
1118
|
/**
|
|
1102
1119
|
* Creates a shallow copy of this Texture, sharing the same BaseTexture.
|
|
@@ -1116,12 +1133,12 @@ class P {
|
|
|
1116
1133
|
* @param gap - Optional pixel gap between cells.
|
|
1117
1134
|
* @returns An array of split Textures.
|
|
1118
1135
|
*/
|
|
1119
|
-
splitGrid(t, e,
|
|
1136
|
+
splitGrid(t, e, r, i, n = 0) {
|
|
1120
1137
|
if (!this.base) return [];
|
|
1121
|
-
const a = [],
|
|
1122
|
-
for (let x = 0; x <
|
|
1123
|
-
for (let g = 0; g <
|
|
1124
|
-
a.push(this.getSubTexture(g * u, x *
|
|
1138
|
+
const a = [], c = this.rawWidth, h = this.rawHeight, o = Math.max(0, n), u = t + o, l = e + o, d = r ?? Math.floor((c + o) / u), f = i ?? Math.floor((h + o) / l);
|
|
1139
|
+
for (let x = 0; x < f; x++)
|
|
1140
|
+
for (let g = 0; g < d; g++)
|
|
1141
|
+
a.push(this.getSubTexture(g * u, x * l, t, e));
|
|
1125
1142
|
return a;
|
|
1126
1143
|
}
|
|
1127
1144
|
/**
|
|
@@ -1129,9 +1146,9 @@ class P {
|
|
|
1129
1146
|
* @param source - The image element, canvas, video, or bitmap.
|
|
1130
1147
|
* @param options - Optional antialias and wrap mode settings.
|
|
1131
1148
|
*/
|
|
1132
|
-
static fromImageSource(t, e,
|
|
1133
|
-
const
|
|
1134
|
-
return new P(new k(
|
|
1149
|
+
static fromImageSource(t, e, r = {}) {
|
|
1150
|
+
const i = K(t, e, r);
|
|
1151
|
+
return new P(new k(i, e.width, e.height));
|
|
1135
1152
|
}
|
|
1136
1153
|
/**
|
|
1137
1154
|
* Marks this Texture as destroyed, decrementing the BaseTexture reference count.
|
|
@@ -1150,11 +1167,11 @@ class At extends P {
|
|
|
1150
1167
|
_allocW = 0;
|
|
1151
1168
|
_allocH = 0;
|
|
1152
1169
|
constructor(t, e) {
|
|
1153
|
-
super(), this.gl = t.gl, this.clearColor = e.clearColor ??
|
|
1154
|
-
const
|
|
1155
|
-
if (this.setBase(new k(a,
|
|
1170
|
+
super(), this.gl = t.gl, this.clearColor = e.clearColor ?? p.Black;
|
|
1171
|
+
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = K(t, { width: r, height: i }, { ...e, onlySize: !0 });
|
|
1172
|
+
if (this.setBase(new k(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
1156
1173
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
1157
|
-
this.resize(
|
|
1174
|
+
this.resize(r, i, !0);
|
|
1158
1175
|
}
|
|
1159
1176
|
/**
|
|
1160
1177
|
* Resizes the render texture using a grow-only GPU allocation strategy.
|
|
@@ -1168,12 +1185,12 @@ class At extends P {
|
|
|
1168
1185
|
* @param height - New logical height.
|
|
1169
1186
|
* @param force - Force full GPU reallocation regardless of current allocation size.
|
|
1170
1187
|
*/
|
|
1171
|
-
resize(t, e,
|
|
1188
|
+
resize(t, e, r = !1) {
|
|
1172
1189
|
t = Math.max(Math.round(t), 1), e = Math.max(Math.round(e), 1);
|
|
1173
|
-
const
|
|
1174
|
-
if (!
|
|
1190
|
+
const i = this.rawWidth === t && this.rawHeight === e;
|
|
1191
|
+
if (!r && i) return;
|
|
1175
1192
|
const n = this.gl;
|
|
1176
|
-
(
|
|
1193
|
+
(r || t > this._allocW || e > this._allocH) && this.base && (this._allocW = Math.max(this._allocW, t), this._allocH = Math.max(this._allocH, e), this.base.width = this._allocW, this.base.height = this._allocH, n.bindTexture(n.TEXTURE_2D, this.base.glTexture), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, this._allocW, this._allocH, 0, n.RGBA, n.UNSIGNED_BYTE, null), n.bindRenderbuffer(n.RENDERBUFFER, this.renderbuffer), n.renderbufferStorage(n.RENDERBUFFER, n.STENCIL_INDEX8, this._allocW, this._allocH), n.bindFramebuffer(n.FRAMEBUFFER, this.framebuffer), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, this.base.glTexture, 0), n.framebufferRenderbuffer(n.FRAMEBUFFER, n.STENCIL_ATTACHMENT, n.RENDERBUFFER, this.renderbuffer), n.bindFramebuffer(n.FRAMEBUFFER, null), n.bindRenderbuffer(n.RENDERBUFFER, null), n.bindTexture(n.TEXTURE_2D, null)), this.rawWidth = t, this.rawHeight = e, this.uvX = 0, this.uvW = t / this._allocW, this.uvY = 0, this.uvH = e / this._allocH;
|
|
1177
1194
|
}
|
|
1178
1195
|
/**
|
|
1179
1196
|
* Activates this texture as the current render target.
|
|
@@ -1186,8 +1203,8 @@ class At extends P {
|
|
|
1186
1203
|
}
|
|
1187
1204
|
clear(t) {
|
|
1188
1205
|
if (!this.framebuffer) return;
|
|
1189
|
-
const e = this.gl,
|
|
1190
|
-
|
|
1206
|
+
const e = this.gl, r = t ?? this.clearColor;
|
|
1207
|
+
r && (r.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
|
|
1191
1208
|
}
|
|
1192
1209
|
/**
|
|
1193
1210
|
* Deactivates this texture, returning rendering to the default frame buffer.
|
|
@@ -1203,16 +1220,16 @@ class At extends P {
|
|
|
1203
1220
|
* @param width - Width of the region to read.
|
|
1204
1221
|
* @param height - Height of the region to read.
|
|
1205
1222
|
*/
|
|
1206
|
-
GetPixels(t = 0, e = 0,
|
|
1223
|
+
GetPixels(t = 0, e = 0, r = this.rawWidth, i = this.rawHeight) {
|
|
1207
1224
|
if (!this.framebuffer) return new Uint8Array(0);
|
|
1208
|
-
const n = Math.floor(t), a = Math.floor(e),
|
|
1209
|
-
if (
|
|
1225
|
+
const n = Math.floor(t), a = Math.floor(e), c = Math.floor(r), h = Math.floor(i);
|
|
1226
|
+
if (c <= 0 || h <= 0) return new Uint8Array(0);
|
|
1210
1227
|
if (n < 0 || a < 0 || n >= this.rawWidth || a >= this.rawHeight)
|
|
1211
1228
|
return new Uint8Array(0);
|
|
1212
|
-
const
|
|
1213
|
-
|
|
1214
|
-
const x = new Uint8Array(
|
|
1215
|
-
return
|
|
1229
|
+
const o = Math.min(c, this.rawWidth - n), u = Math.min(h, this.rawHeight - a), l = this.rawHeight - a - u, d = this.gl, f = d.getParameter(d.FRAMEBUFFER_BINDING);
|
|
1230
|
+
d.bindFramebuffer(d.FRAMEBUFFER, this.framebuffer);
|
|
1231
|
+
const x = new Uint8Array(o * u * 4);
|
|
1232
|
+
return d.readPixels(n, l, o, u, d.RGBA, d.UNSIGNED_BYTE, x), d.bindFramebuffer(d.FRAMEBUFFER, f), x;
|
|
1216
1233
|
}
|
|
1217
1234
|
/**
|
|
1218
1235
|
* Get the color at a pixel in the render texture.
|
|
@@ -1220,8 +1237,8 @@ class At extends P {
|
|
|
1220
1237
|
* @param y - Y coordinate in logical pixel space (top-left origin).
|
|
1221
1238
|
*/
|
|
1222
1239
|
GetColorAt(t, e) {
|
|
1223
|
-
const
|
|
1224
|
-
return
|
|
1240
|
+
const r = this.GetPixels(t, e, 1, 1);
|
|
1241
|
+
return r.length < 4 ? new p(0, 0, 0, 0) : new p(r[0], r[1], r[2], r[3]);
|
|
1225
1242
|
}
|
|
1226
1243
|
/**
|
|
1227
1244
|
* Destroys the framebuffer, renderbuffer, and base texture.
|
|
@@ -1249,11 +1266,11 @@ class _t extends P {
|
|
|
1249
1266
|
flipY = !0;
|
|
1250
1267
|
constructor(t, e) {
|
|
1251
1268
|
super(), this.render = t, this._style = { ...Ut, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
|
|
1252
|
-
const
|
|
1253
|
-
if (!
|
|
1254
|
-
this.ctx =
|
|
1255
|
-
const
|
|
1256
|
-
this.setBase(new k(
|
|
1269
|
+
const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
|
|
1270
|
+
if (!r) throw new Error("Failed to get 2d context for TextTexture");
|
|
1271
|
+
this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
|
|
1272
|
+
const i = K(t, this.canvas, this.options);
|
|
1273
|
+
this.setBase(new k(i, 1, 1)), this.update();
|
|
1257
1274
|
}
|
|
1258
1275
|
get text() {
|
|
1259
1276
|
return this._text;
|
|
@@ -1301,51 +1318,51 @@ class _t extends P {
|
|
|
1301
1318
|
* Updates the internal canvas and uploads it to WebGL
|
|
1302
1319
|
*/
|
|
1303
1320
|
update() {
|
|
1304
|
-
const t = this.ctx, e = this._style.fontSize,
|
|
1321
|
+
const t = this.ctx, e = this._style.fontSize, r = this._style.fontWeight, i = this._style.fontFamily, n = `${r} ${e}px ${i}`, a = this.render.dpr;
|
|
1305
1322
|
t.font = n;
|
|
1306
|
-
const
|
|
1323
|
+
const c = this._text.split(`
|
|
1307
1324
|
`);
|
|
1308
|
-
let h = 0,
|
|
1325
|
+
let h = 0, o = 0;
|
|
1309
1326
|
t.textBaseline = "alphabetic";
|
|
1310
|
-
const u = t.measureText(
|
|
1311
|
-
for (const
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1327
|
+
const u = t.measureText(c[0]), l = u.fontBoundingBoxAscent, d = u.fontBoundingBoxDescent;
|
|
1328
|
+
for (const E of c) {
|
|
1329
|
+
const b = t.measureText(E);
|
|
1330
|
+
b.width > h && (h = b.width), o += l + d;
|
|
1314
1331
|
}
|
|
1315
|
-
|
|
1316
|
-
const
|
|
1317
|
-
(this.canvas.width !==
|
|
1318
|
-
let
|
|
1319
|
-
for (const
|
|
1320
|
-
let
|
|
1321
|
-
this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(
|
|
1332
|
+
o -= d;
|
|
1333
|
+
const f = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + f) || 1, g = Math.ceil(o + f) || 1, v = x * a, T = g * a;
|
|
1334
|
+
(this.canvas.width !== v || this.canvas.height !== T) && (this.canvas.width = v, this.canvas.height = T), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, g), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, g);
|
|
1335
|
+
let R = f / 2;
|
|
1336
|
+
for (const E of c) {
|
|
1337
|
+
let b = f / 2;
|
|
1338
|
+
this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(E, b, R)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(E, b, R)), R += l + d;
|
|
1322
1339
|
}
|
|
1323
1340
|
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, this.canvas.width, this.canvas.height);
|
|
1324
1341
|
}
|
|
1325
1342
|
}
|
|
1326
1343
|
const Ct = (s, t = !1, e = !0) => {
|
|
1327
|
-
const
|
|
1328
|
-
if (!
|
|
1344
|
+
const r = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
|
|
1345
|
+
if (!r)
|
|
1329
1346
|
throw new Error("WebGL2 is not supported in this browser.");
|
|
1330
|
-
return
|
|
1347
|
+
return r;
|
|
1331
1348
|
}, ht = (s, t, e) => {
|
|
1332
|
-
const
|
|
1333
|
-
if (!
|
|
1349
|
+
const r = s.createShader(e);
|
|
1350
|
+
if (!r)
|
|
1334
1351
|
throw new Error("Unable to create webgl shader");
|
|
1335
|
-
if (s.shaderSource(
|
|
1336
|
-
const n = s.getShaderInfoLog(
|
|
1352
|
+
if (s.shaderSource(r, t), s.compileShader(r), !s.getShaderParameter(r, s.COMPILE_STATUS)) {
|
|
1353
|
+
const n = s.getShaderInfoLog(r);
|
|
1337
1354
|
throw console.error("Shader compilation failed:", n), new Error("Unable to compile shader: " + n + t);
|
|
1338
1355
|
}
|
|
1339
|
-
return
|
|
1356
|
+
return r;
|
|
1340
1357
|
}, Pt = (s, t, e) => {
|
|
1341
|
-
var
|
|
1342
|
-
if (!
|
|
1358
|
+
var r = s.createProgram(), i = ht(s, t, 35633), n = ht(s, e, 35632);
|
|
1359
|
+
if (!r)
|
|
1343
1360
|
throw new Error("Unable to create program shader");
|
|
1344
|
-
if (s.attachShader(
|
|
1345
|
-
const
|
|
1346
|
-
throw new Error("Unable to link shader program: " +
|
|
1361
|
+
if (s.attachShader(r, i), s.attachShader(r, n), s.linkProgram(r), !s.getProgramParameter(r, s.LINK_STATUS)) {
|
|
1362
|
+
const c = s.getProgramInfoLog(r);
|
|
1363
|
+
throw new Error("Unable to link shader program: " + c);
|
|
1347
1364
|
}
|
|
1348
|
-
return
|
|
1365
|
+
return r;
|
|
1349
1366
|
};
|
|
1350
1367
|
function J(s, t) {
|
|
1351
1368
|
const e = {
|
|
@@ -1357,29 +1374,29 @@ function J(s, t) {
|
|
|
1357
1374
|
}
|
|
1358
1375
|
function tt(s, t) {
|
|
1359
1376
|
const e = {
|
|
1360
|
-
[
|
|
1361
|
-
[
|
|
1377
|
+
[rt.LINEAR]: s.LINEAR,
|
|
1378
|
+
[rt.NEAREST]: s.NEAREST
|
|
1362
1379
|
}[t] ?? s.NEAREST;
|
|
1363
1380
|
s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, e);
|
|
1364
1381
|
}
|
|
1365
1382
|
function K(s, t, e) {
|
|
1366
|
-
const
|
|
1367
|
-
if (!
|
|
1383
|
+
const r = s.gl, i = r.createTexture();
|
|
1384
|
+
if (!i)
|
|
1368
1385
|
throw new Error("Unable to create WebGL texture");
|
|
1369
|
-
if (
|
|
1386
|
+
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), J(r, e.wrap ?? Y.CLAMP), tt(r, e.textureFilter ?? s.textureFilter), e.onlySize) {
|
|
1370
1387
|
const n = t;
|
|
1371
|
-
|
|
1388
|
+
r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, n.width, n.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
|
|
1372
1389
|
} else {
|
|
1373
1390
|
const n = e.premultipliedAlpha ?? s.premultipliedAlpha;
|
|
1374
|
-
n &&
|
|
1391
|
+
n && r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, r.RGBA, r.UNSIGNED_BYTE, t), n && r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
|
|
1375
1392
|
}
|
|
1376
|
-
return
|
|
1393
|
+
return r.bindTexture(r.TEXTURE_2D, null), i;
|
|
1377
1394
|
}
|
|
1378
|
-
function
|
|
1395
|
+
function F(s, t) {
|
|
1379
1396
|
if (s.includes("%TEXTURE_NUM%") && (s = s.replace("%TEXTURE_NUM%", t.toString())), s.includes("%GET_COLOR%")) {
|
|
1380
1397
|
let e = "";
|
|
1381
|
-
for (let
|
|
1382
|
-
|
|
1398
|
+
for (let r = 0; r < t; r++)
|
|
1399
|
+
r == 0 ? e += `if(vTextureId == ${r})` : r == t - 1 ? e += "else" : e += `else if(vTextureId == ${r})`, e += `{return texture(uTextures[${r}], uv);}`;
|
|
1383
1400
|
s = s.replace("%GET_COLOR%", e);
|
|
1384
1401
|
}
|
|
1385
1402
|
return s;
|
|
@@ -1388,8 +1405,8 @@ const Nt = 5126, et = 5121;
|
|
|
1388
1405
|
function Lt(s, t, e) {
|
|
1389
1406
|
s.vertexAttribDivisor(t, e);
|
|
1390
1407
|
}
|
|
1391
|
-
function vt(s, t, e,
|
|
1392
|
-
s.drawArraysInstanced(t, e,
|
|
1408
|
+
function vt(s, t, e, r, i) {
|
|
1409
|
+
s.drawArraysInstanced(t, e, r, i);
|
|
1393
1410
|
}
|
|
1394
1411
|
let Ot = 0;
|
|
1395
1412
|
class Tt {
|
|
@@ -1407,8 +1424,8 @@ class Tt {
|
|
|
1407
1424
|
shaderId = Ot++;
|
|
1408
1425
|
// for debug
|
|
1409
1426
|
vao;
|
|
1410
|
-
constructor(t, e,
|
|
1411
|
-
this.gl = t, this.program = Pt(t, e,
|
|
1427
|
+
constructor(t, e, r, i) {
|
|
1428
|
+
this.gl = t, this.program = Pt(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
|
|
1412
1429
|
}
|
|
1413
1430
|
/** Switch GPU to use this shader program */
|
|
1414
1431
|
use() {
|
|
@@ -1431,10 +1448,10 @@ class Tt {
|
|
|
1431
1448
|
* shader.setUniform("uMVP", mat4array);
|
|
1432
1449
|
*/
|
|
1433
1450
|
setUniform(t, e) {
|
|
1434
|
-
const
|
|
1435
|
-
if (
|
|
1436
|
-
const
|
|
1437
|
-
It(this.gl,
|
|
1451
|
+
const r = this.uniformLoc[t];
|
|
1452
|
+
if (r === void 0) return;
|
|
1453
|
+
const i = this.uniformType[t], n = this.uniformIsArray[t];
|
|
1454
|
+
It(this.gl, r, i, e, n);
|
|
1438
1455
|
}
|
|
1439
1456
|
/**
|
|
1440
1457
|
* Batch-set uniforms via a plain value map.
|
|
@@ -1457,15 +1474,15 @@ class Tt {
|
|
|
1457
1474
|
setAttribute(t) {
|
|
1458
1475
|
const e = this.attributeLoc[t.name];
|
|
1459
1476
|
if (e === void 0) return;
|
|
1460
|
-
const
|
|
1461
|
-
|
|
1477
|
+
const r = this.gl;
|
|
1478
|
+
r.vertexAttribPointer(
|
|
1462
1479
|
e,
|
|
1463
1480
|
t.size,
|
|
1464
1481
|
t.type ?? Nt,
|
|
1465
1482
|
t.normalized ?? !1,
|
|
1466
1483
|
t.stride,
|
|
1467
1484
|
t.offset ?? 0
|
|
1468
|
-
),
|
|
1485
|
+
), r.enableVertexAttribArray(e), Lt(r, e, t.divisor ?? 0);
|
|
1469
1486
|
}
|
|
1470
1487
|
/** Bind all vertex attribute pointers at once */
|
|
1471
1488
|
setAttributes(t) {
|
|
@@ -1479,76 +1496,76 @@ class Tt {
|
|
|
1479
1496
|
}
|
|
1480
1497
|
/** Parse attribute/uniform names and GLSL types from raw shader source */
|
|
1481
1498
|
parseShader(t) {
|
|
1482
|
-
const e = this.gl,
|
|
1483
|
-
if (i)
|
|
1484
|
-
for (const n of i) {
|
|
1485
|
-
const o = n.split(/\s+/)[2], h = e.getAttribLocation(this.program, o);
|
|
1486
|
-
h !== -1 && (this.attributeLoc[o] = h);
|
|
1487
|
-
}
|
|
1488
|
-
const r = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
|
|
1499
|
+
const e = this.gl, r = t.match(/(?:in|attribute)\s+\w+\s+\w+/g);
|
|
1489
1500
|
if (r)
|
|
1490
1501
|
for (const n of r) {
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1502
|
+
const c = n.split(/\s+/)[2], h = e.getAttribLocation(this.program, c);
|
|
1503
|
+
h !== -1 && (this.attributeLoc[c] = h);
|
|
1504
|
+
}
|
|
1505
|
+
const i = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
|
|
1506
|
+
if (i)
|
|
1507
|
+
for (const n of i) {
|
|
1508
|
+
const a = n.split(/\s+/), c = a[1], h = a[2].replace(/\[\d+\]$/, ""), o = e.getUniformLocation(this.program, h);
|
|
1509
|
+
o !== null && (this.uniformLoc[h] = o, this.uniformType[h] = c, this.uniformIsArray[h] = /\[\d+\]$/.test(a[2]));
|
|
1493
1510
|
}
|
|
1494
1511
|
}
|
|
1495
1512
|
}
|
|
1496
|
-
function It(s, t, e,
|
|
1513
|
+
function It(s, t, e, r, i = !1) {
|
|
1497
1514
|
switch (e) {
|
|
1498
1515
|
// scalars
|
|
1499
1516
|
case "float":
|
|
1500
|
-
return s.uniform1f(t,
|
|
1517
|
+
return s.uniform1f(t, r);
|
|
1501
1518
|
case "int":
|
|
1502
1519
|
case "bool":
|
|
1503
1520
|
case "sampler2D":
|
|
1504
1521
|
case "samplerCube":
|
|
1505
|
-
return
|
|
1522
|
+
return i ? s.uniform1iv(t, r) : s.uniform1i(t, r);
|
|
1506
1523
|
// float vectors
|
|
1507
1524
|
case "vec2":
|
|
1508
|
-
return s.uniform2fv(t,
|
|
1525
|
+
return s.uniform2fv(t, r);
|
|
1509
1526
|
case "vec3":
|
|
1510
|
-
return s.uniform3fv(t,
|
|
1527
|
+
return s.uniform3fv(t, r);
|
|
1511
1528
|
case "vec4":
|
|
1512
|
-
return s.uniform4fv(t,
|
|
1529
|
+
return s.uniform4fv(t, r);
|
|
1513
1530
|
// int / bool vectors
|
|
1514
1531
|
case "ivec2":
|
|
1515
1532
|
case "bvec2":
|
|
1516
|
-
return s.uniform2iv(t,
|
|
1533
|
+
return s.uniform2iv(t, r);
|
|
1517
1534
|
case "ivec3":
|
|
1518
1535
|
case "bvec3":
|
|
1519
|
-
return s.uniform3iv(t,
|
|
1536
|
+
return s.uniform3iv(t, r);
|
|
1520
1537
|
case "ivec4":
|
|
1521
1538
|
case "bvec4":
|
|
1522
|
-
return s.uniform4iv(t,
|
|
1539
|
+
return s.uniform4iv(t, r);
|
|
1523
1540
|
// matrices (column-major, transpose = false)
|
|
1524
1541
|
case "mat2":
|
|
1525
|
-
return s.uniformMatrix2fv(t, !1,
|
|
1542
|
+
return s.uniformMatrix2fv(t, !1, r);
|
|
1526
1543
|
case "mat3":
|
|
1527
|
-
return s.uniformMatrix3fv(t, !1,
|
|
1544
|
+
return s.uniformMatrix3fv(t, !1, r);
|
|
1528
1545
|
case "mat4":
|
|
1529
|
-
return s.uniformMatrix4fv(t, !1,
|
|
1546
|
+
return s.uniformMatrix4fv(t, !1, r);
|
|
1530
1547
|
// fallback: guess by value shape
|
|
1531
1548
|
default:
|
|
1532
|
-
return Wt(s, t,
|
|
1549
|
+
return Wt(s, t, r);
|
|
1533
1550
|
}
|
|
1534
1551
|
}
|
|
1535
1552
|
function Wt(s, t, e) {
|
|
1536
1553
|
if (typeof e == "number")
|
|
1537
1554
|
return s.uniform1f(t, e);
|
|
1538
|
-
const
|
|
1539
|
-
switch (
|
|
1555
|
+
const r = e;
|
|
1556
|
+
switch (r.length) {
|
|
1540
1557
|
case 2:
|
|
1541
|
-
return s.uniform2fv(t,
|
|
1558
|
+
return s.uniform2fv(t, r);
|
|
1542
1559
|
case 3:
|
|
1543
|
-
return s.uniform3fv(t,
|
|
1560
|
+
return s.uniform3fv(t, r);
|
|
1544
1561
|
case 4:
|
|
1545
|
-
return s.uniform4fv(t,
|
|
1562
|
+
return s.uniform4fv(t, r);
|
|
1546
1563
|
case 9:
|
|
1547
|
-
return s.uniformMatrix3fv(t, !1,
|
|
1564
|
+
return s.uniformMatrix3fv(t, !1, r);
|
|
1548
1565
|
case 16:
|
|
1549
|
-
return s.uniformMatrix4fv(t, !1,
|
|
1566
|
+
return s.uniformMatrix4fv(t, !1, r);
|
|
1550
1567
|
default:
|
|
1551
|
-
return s.uniform1fv(t,
|
|
1568
|
+
return s.uniform1fv(t, r);
|
|
1552
1569
|
}
|
|
1553
1570
|
}
|
|
1554
1571
|
class ot {
|
|
@@ -1569,8 +1586,8 @@ class ot {
|
|
|
1569
1586
|
/** Padding in pixels this shader needs beyond the sprite bounds (for outline/glow effects) */
|
|
1570
1587
|
padding = 0;
|
|
1571
1588
|
rapid;
|
|
1572
|
-
constructor(t, e,
|
|
1573
|
-
this.vs = e, this.fs =
|
|
1589
|
+
constructor(t, e, r, i = 0, n) {
|
|
1590
|
+
this.vs = e, this.fs = r, this.rapid = t, this.uniforms = n ?? {}, this.usedTextureUnitNum = i;
|
|
1574
1591
|
}
|
|
1575
1592
|
/**
|
|
1576
1593
|
* Updates uniform values or textures for the custom shader.
|
|
@@ -1578,12 +1595,12 @@ class ot {
|
|
|
1578
1595
|
*/
|
|
1579
1596
|
setUniforms(t) {
|
|
1580
1597
|
this.rapid.flush();
|
|
1581
|
-
const e = {},
|
|
1582
|
-
for (const [
|
|
1583
|
-
n instanceof WebGLTexture ? i
|
|
1584
|
-
Object.assign(this.uniforms, e), Object.assign(this.uniformTextures,
|
|
1585
|
-
for (const
|
|
1586
|
-
this.uniformDirty.add(
|
|
1598
|
+
const e = {}, r = {};
|
|
1599
|
+
for (const [i, n] of Object.entries(t))
|
|
1600
|
+
n instanceof WebGLTexture ? r[i] = n : e[i] = n;
|
|
1601
|
+
Object.assign(this.uniforms, e), Object.assign(this.uniformTextures, r);
|
|
1602
|
+
for (const i of this.glshader.keys())
|
|
1603
|
+
this.uniformDirty.add(i);
|
|
1587
1604
|
}
|
|
1588
1605
|
/**
|
|
1589
1606
|
* Sets the padding (in pixels) for this shader and propagates to all compiled GLShaders.
|
|
@@ -1602,8 +1619,8 @@ class ot {
|
|
|
1602
1619
|
* @param textureUniforms Map of texture uniform names to assigned texture unit indices.
|
|
1603
1620
|
*/
|
|
1604
1621
|
applyUniform(t, e) {
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1622
|
+
const r = this.glshader.get(t);
|
|
1623
|
+
r && (Object.keys(e).length > 0 && r.setUniforms(e), this.uniformDirty.has(t) && (r.setUniforms(this.uniforms), this.uniformDirty.delete(t)));
|
|
1607
1624
|
}
|
|
1608
1625
|
/**
|
|
1609
1626
|
* Retrieves or compiles a customized GLShader for a specific region.
|
|
@@ -1613,13 +1630,13 @@ class ot {
|
|
|
1613
1630
|
* @param baseFS The base fragment shader template.
|
|
1614
1631
|
* @returns The combined and compiled GLShader.
|
|
1615
1632
|
*/
|
|
1616
|
-
getGLShader(t, e,
|
|
1633
|
+
getGLShader(t, e, r, i) {
|
|
1617
1634
|
if (this.glshader.has(e))
|
|
1618
1635
|
return this.glshader.get(e);
|
|
1619
|
-
if (
|
|
1636
|
+
if (i == null || r == null)
|
|
1620
1637
|
return console.warn("CustomGlShader: missing base shader for " + e), null;
|
|
1621
|
-
|
|
1622
|
-
const n = t.createShader(
|
|
1638
|
+
r = r.replace("// CUSTOM_CODE_CALL", "vertex(position, vRegion);"), i = i.replace("// CUSTOM_CODE_CALL", "fragment(fragColor);"), r = r.replace("// CUSTOM_CODE", this.vs), i = i.replace("// CUSTOM_CODE", this.fs);
|
|
1639
|
+
const n = t.createShader(r, i);
|
|
1623
1640
|
return n.isCustom = !0, n.padding = this.padding, this.glshader.set(e, n), this.uniformDirty.add(e), n;
|
|
1624
1641
|
}
|
|
1625
1642
|
}
|
|
@@ -1653,17 +1670,17 @@ class yt {
|
|
|
1653
1670
|
(t, e) => e
|
|
1654
1671
|
);
|
|
1655
1672
|
}
|
|
1656
|
-
findTextureUnit(t, e = 0,
|
|
1657
|
-
for (let
|
|
1658
|
-
const n =
|
|
1659
|
-
if (this.usedTextures[
|
|
1660
|
-
return
|
|
1673
|
+
findTextureUnit(t, e = 0, r = 0) {
|
|
1674
|
+
for (let i = 0; i < this.usedTextures.length; i++) {
|
|
1675
|
+
const n = i * 2;
|
|
1676
|
+
if (this.usedTextures[i] === t && this.usedTexturePadding[n] === e && this.usedTexturePadding[n + 1] === r)
|
|
1677
|
+
return i;
|
|
1661
1678
|
}
|
|
1662
1679
|
return -1;
|
|
1663
1680
|
}
|
|
1664
|
-
useTexture(t, e = 0,
|
|
1665
|
-
const
|
|
1666
|
-
return
|
|
1681
|
+
useTexture(t, e = 0, r = 0) {
|
|
1682
|
+
const i = this.findTextureUnit(t, e, r);
|
|
1683
|
+
return i == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(r), this.usedTextures.length - 1) : i;
|
|
1667
1684
|
}
|
|
1668
1685
|
createShader(t, e) {
|
|
1669
1686
|
return new Tt(this.gl, t, e);
|
|
@@ -1703,20 +1720,20 @@ class yt {
|
|
|
1703
1720
|
prepareRender() {
|
|
1704
1721
|
const t = this.currentShader;
|
|
1705
1722
|
if (t.use(), this.customShader) {
|
|
1706
|
-
const
|
|
1707
|
-
for (const n in
|
|
1708
|
-
|
|
1709
|
-
this.customShader.applyUniform(this.KEY,
|
|
1723
|
+
const r = this.customShader, i = {};
|
|
1724
|
+
for (const n in r.uniformTextures)
|
|
1725
|
+
i[n] = this.useTexture(r.uniformTextures[n]);
|
|
1726
|
+
this.customShader.applyUniform(this.KEY, i);
|
|
1710
1727
|
}
|
|
1711
1728
|
const e = this.gl;
|
|
1712
|
-
for (let
|
|
1713
|
-
e.activeTexture(e.TEXTURE0 +
|
|
1729
|
+
for (let r = 0; r < this.usedTextures.length; r++)
|
|
1730
|
+
e.activeTexture(e.TEXTURE0 + r), e.bindTexture(e.TEXTURE_2D, this.usedTextures[r]);
|
|
1714
1731
|
t.setUniform("uTextures", Int32Array.from(
|
|
1715
1732
|
{ length: this.usedTextures.length },
|
|
1716
|
-
(
|
|
1733
|
+
(r, i) => i
|
|
1717
1734
|
)), t.setUniform("uPadding", Float32Array.from(
|
|
1718
1735
|
{ length: this.usedTexturePadding.length },
|
|
1719
|
-
(
|
|
1736
|
+
(r, i) => this.usedTexturePadding[i]
|
|
1720
1737
|
));
|
|
1721
1738
|
}
|
|
1722
1739
|
resetRender() {
|
|
@@ -1727,7 +1744,7 @@ class yt {
|
|
|
1727
1744
|
}
|
|
1728
1745
|
}
|
|
1729
1746
|
const $ = `#version 300 es\r
|
|
1730
|
-
precision
|
|
1747
|
+
precision highp float;\r
|
|
1731
1748
|
\r
|
|
1732
1749
|
// per-vertex\r
|
|
1733
1750
|
in vec2 aVertex;\r
|
|
@@ -1814,7 +1831,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
|
|
|
1814
1831
|
// CUSTOM_CODE\r
|
|
1815
1832
|
\r
|
|
1816
1833
|
void main(void) {\r
|
|
1817
|
-
fragColor = sampleTexture(vRegion);\r
|
|
1834
|
+
fragColor = sampleTexture(vRegion) * vColor;\r
|
|
1818
1835
|
// if (vPadding.x != 0.0) {\r
|
|
1819
1836
|
// if (clampUV(vRegion)) {\r
|
|
1820
1837
|
// fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
|
|
@@ -1824,7 +1841,7 @@ void main(void) {\r
|
|
|
1824
1841
|
// CUSTOM_CODE_CALL\r
|
|
1825
1842
|
}\r
|
|
1826
1843
|
`, V = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
1827
|
-
class
|
|
1844
|
+
class it extends yt {
|
|
1828
1845
|
instanceBuffer;
|
|
1829
1846
|
quadBuffer;
|
|
1830
1847
|
instanceCount = 0;
|
|
@@ -1836,29 +1853,29 @@ class rt extends yt {
|
|
|
1836
1853
|
}
|
|
1837
1854
|
createBuffer() {
|
|
1838
1855
|
const t = this.gl;
|
|
1839
|
-
this.quadBuffer = new Q(t,
|
|
1856
|
+
this.quadBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1840
1857
|
for (const e of Ft) this.quadBuffer.pushFloat32(e);
|
|
1841
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t,
|
|
1858
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, I.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1842
1859
|
}
|
|
1843
1860
|
createDefaultShader() {
|
|
1844
|
-
const t = this.rapid, e =
|
|
1845
|
-
return this.vs =
|
|
1861
|
+
const t = this.rapid, e = F(ct, t.maxTextureUnits), r = F($, t.maxTextureUnits);
|
|
1862
|
+
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
1846
1863
|
}
|
|
1847
1864
|
createShader(t, e) {
|
|
1848
|
-
const
|
|
1849
|
-
return
|
|
1865
|
+
const r = super.createShader(t, e);
|
|
1866
|
+
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
1850
1867
|
{ name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
|
|
1851
1868
|
{ name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
|
|
1852
1869
|
{ name: "aUVRect", size: 4, stride: V, offset: 24, divisor: 1 },
|
|
1853
1870
|
{ name: "aColor", size: 4, type: et, normalized: !0, stride: V, offset: 40, divisor: 1 },
|
|
1854
1871
|
{ name: "aTextureId", size: 1, type: et, stride: V, offset: 44, divisor: 1 }
|
|
1855
|
-
]), this.quadBuffer.bindBuffer(),
|
|
1872
|
+
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
1856
1873
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1857
|
-
]),
|
|
1874
|
+
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1858
1875
|
}
|
|
1859
1876
|
createCustomShader(t) {
|
|
1860
|
-
const e =
|
|
1861
|
-
return t.getGLShader(this, this.KEY,
|
|
1877
|
+
const e = F(ct, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = F($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
1878
|
+
return t.getGLShader(this, this.KEY, r, e);
|
|
1862
1879
|
}
|
|
1863
1880
|
/**
|
|
1864
1881
|
* Draws a textured sprite via instanced rendering to significantly improve performance.
|
|
@@ -1872,39 +1889,39 @@ class rt extends yt {
|
|
|
1872
1889
|
* @param v1 Bottom UV mapped coordinate (default 1).
|
|
1873
1890
|
* @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
|
|
1874
1891
|
*/
|
|
1875
|
-
drawSprite(t, e,
|
|
1876
|
-
const
|
|
1892
|
+
drawSprite(t, e, r = 0, i = 0, n = 1, a = 1, c = 4294967295, h = 0, o = 0, u = !1, l = !1, d = !1) {
|
|
1893
|
+
const f = e * 6, x = this.matrixStore.data;
|
|
1877
1894
|
this.drawSpriteAffine(
|
|
1878
1895
|
t,
|
|
1879
|
-
x[
|
|
1880
|
-
x[
|
|
1881
|
-
x[
|
|
1882
|
-
x[
|
|
1883
|
-
x[
|
|
1884
|
-
x[
|
|
1885
|
-
i,
|
|
1896
|
+
x[f],
|
|
1897
|
+
x[f + 1],
|
|
1898
|
+
x[f + 2],
|
|
1899
|
+
x[f + 3],
|
|
1900
|
+
x[f + 4],
|
|
1901
|
+
x[f + 5],
|
|
1886
1902
|
r,
|
|
1903
|
+
i,
|
|
1887
1904
|
n,
|
|
1888
1905
|
a,
|
|
1889
|
-
o,
|
|
1890
|
-
h,
|
|
1891
1906
|
c,
|
|
1907
|
+
h,
|
|
1908
|
+
o,
|
|
1892
1909
|
u,
|
|
1893
|
-
|
|
1894
|
-
|
|
1910
|
+
l,
|
|
1911
|
+
d
|
|
1895
1912
|
);
|
|
1896
1913
|
}
|
|
1897
|
-
drawSpriteAffine(t, e,
|
|
1898
|
-
const
|
|
1914
|
+
drawSpriteAffine(t, e, r, i, n, a, c, h = 0, o = 0, u = 1, l = 1, d = 4294967295, f = 0, x = 0, g = !1, v = !1, T = !1) {
|
|
1915
|
+
const R = t.base, E = t.scale ?? 1, b = t.rawWidth, N = t.rawHeight, W = t.offsetX, L = t.offsetY, S = this.useTexture(
|
|
1899
1916
|
t.glTexture,
|
|
1900
|
-
|
|
1901
|
-
x /
|
|
1902
|
-
),
|
|
1903
|
-
|
|
1904
|
-
const U =
|
|
1905
|
-
|
|
1917
|
+
f / E / R.width,
|
|
1918
|
+
x / E / R.height
|
|
1919
|
+
), w = this.instanceBuffer, A = w.usedElemNum;
|
|
1920
|
+
w.resize(12);
|
|
1921
|
+
const U = w.float32, O = w.uint32, j = (T ? N : b) * E, q = (T ? b : N) * E, G = j + 2 * f, H = q + 2 * x, nt = W - f, at = L - x, M = this.localSpriteMatrix;
|
|
1922
|
+
T ? (M[0] = 0, M[1] = v ? H : -H, M[2] = g ? -G : G, M[3] = 0, M[4] = nt + (g ? G : 0), M[5] = at + (v ? 0 : H)) : (M[0] = g ? -G : G, M[1] = 0, M[2] = 0, M[3] = v ? -H : H, M[4] = nt + (g ? G : 0), M[5] = at + (v ? H : 0));
|
|
1906
1923
|
const _ = this.worldSpriteMatrix;
|
|
1907
|
-
_[0] = e *
|
|
1924
|
+
_[0] = e * M[0] + i * M[1], _[1] = r * M[0] + n * M[1], _[2] = e * M[2] + i * M[3], _[3] = r * M[2] + n * M[3], _[4] = a + e * M[4] + i * M[5], _[5] = c + r * M[4] + n * M[5], U[A + 6] = h, U[A + 7] = o, U[A + 8] = u, U[A + 9] = l, O[A + 10] = d, O[A + 11] = S, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), U[A] = _[0], U[A + 1] = _[2], U[A + 2] = _[4], U[A + 3] = _[1], U[A + 4] = _[3], U[A + 5] = _[5], w.usedElemNum += 12, w.makeDirty(), this.instanceCount++;
|
|
1908
1925
|
}
|
|
1909
1926
|
render() {
|
|
1910
1927
|
if (this.instanceCount === 0) return;
|
|
@@ -1920,7 +1937,7 @@ class rt extends yt {
|
|
|
1920
1937
|
}
|
|
1921
1938
|
}
|
|
1922
1939
|
const Dt = `#version 300 es\r
|
|
1923
|
-
precision
|
|
1940
|
+
precision highp float;\r
|
|
1924
1941
|
\r
|
|
1925
1942
|
in vec2 aPosition;\r
|
|
1926
1943
|
in vec4 aColor;\r
|
|
@@ -1970,9 +1987,9 @@ bool clampUV(vec2 uv) {\r
|
|
|
1970
1987
|
\r
|
|
1971
1988
|
vec4 sampleTexture(vec2 uv) {\r
|
|
1972
1989
|
if (uUseTexture > 0) {\r
|
|
1973
|
-
return texture(uTexture, uv)
|
|
1990
|
+
return texture(uTexture, uv);\r
|
|
1974
1991
|
}\r
|
|
1975
|
-
return
|
|
1992
|
+
return vec4(1,1,1,1);\r
|
|
1976
1993
|
}\r
|
|
1977
1994
|
\r
|
|
1978
1995
|
vec4 sampleClampTexture(vec2 uv) {\r
|
|
@@ -1993,11 +2010,11 @@ vec4 sampleTextureLocal(vec2 uv) {\r
|
|
|
1993
2010
|
// CUSTOM_CODE\r
|
|
1994
2011
|
\r
|
|
1995
2012
|
void main(void) {\r
|
|
1996
|
-
fragColor = sampleTexture(vRegion);\r
|
|
2013
|
+
fragColor = sampleTexture(vRegion) * vColor;\r
|
|
1997
2014
|
// CUSTOM_CODE_CALL\r
|
|
1998
2015
|
}\r
|
|
1999
2016
|
`, kt = `#version 300 es\r
|
|
2000
|
-
precision
|
|
2017
|
+
precision highp float;\r
|
|
2001
2018
|
\r
|
|
2002
2019
|
in vec2 aPosition;\r
|
|
2003
2020
|
in vec2 aUV;\r
|
|
@@ -2053,25 +2070,25 @@ class Ht extends yt {
|
|
|
2053
2070
|
}
|
|
2054
2071
|
createBuffer() {
|
|
2055
2072
|
const t = this.gl;
|
|
2056
|
-
this.vertexBuffer = new Q(t,
|
|
2073
|
+
this.vertexBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
|
|
2057
2074
|
}
|
|
2058
2075
|
createDefaultShader() {
|
|
2059
2076
|
return this.vs = Dt, this.fs = Bt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
2060
2077
|
}
|
|
2061
2078
|
createMaskShader(t, e) {
|
|
2062
|
-
const
|
|
2063
|
-
return
|
|
2064
|
-
{ name: "aPosition", size: 2, type:
|
|
2065
|
-
{ name: "aUV", size: 2, type:
|
|
2066
|
-
]),
|
|
2079
|
+
const r = this.gl, i = new Tt(r, t, e);
|
|
2080
|
+
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
2081
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: z - 4, offset: 0, divisor: 0 },
|
|
2082
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: z - 4, offset: 8, divisor: 0 }
|
|
2083
|
+
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2067
2084
|
}
|
|
2068
2085
|
createShader(t, e) {
|
|
2069
|
-
const
|
|
2070
|
-
return
|
|
2071
|
-
{ name: "aPosition", size: 2, type:
|
|
2072
|
-
{ name: "aColor", size: 4, type:
|
|
2073
|
-
{ name: "aUV", size: 2, type:
|
|
2074
|
-
]),
|
|
2086
|
+
const r = this.gl, i = super.createShader(t, e);
|
|
2087
|
+
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
2088
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: z, offset: 0, divisor: 0 },
|
|
2089
|
+
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: z, offset: 8, divisor: 0 },
|
|
2090
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: z, offset: 12, divisor: 0 }
|
|
2091
|
+
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
2075
2092
|
}
|
|
2076
2093
|
/**
|
|
2077
2094
|
* Begins a new polygon drawing sequence. Must be followed by addVertex() calls and endGraphic().
|
|
@@ -2079,8 +2096,8 @@ class Ht extends yt {
|
|
|
2079
2096
|
* @param drawMode The WebGL drawing primitive mode (e.g., gl.TRIANGLES).
|
|
2080
2097
|
* @param texture Optional texture to apply over the polygon.
|
|
2081
2098
|
*/
|
|
2082
|
-
startGraphic(t, e = this.gl.TRIANGLES,
|
|
2083
|
-
this.vertexBuffer.clear(), this.vertexCount = 0, this.matrixIndex = t, this.drawMode = e, this.texture =
|
|
2099
|
+
startGraphic(t, e = this.gl.TRIANGLES, r) {
|
|
2100
|
+
this.vertexBuffer.clear(), this.vertexCount = 0, this.matrixIndex = t, this.drawMode = e, this.texture = r, this.texture?.glTexture && this.useTexture(this.texture.glTexture, 0, 0);
|
|
2084
2101
|
}
|
|
2085
2102
|
/**
|
|
2086
2103
|
* Adds a vertex to the current polygon. Local coordinates and color settings.
|
|
@@ -2090,9 +2107,9 @@ class Ht extends yt {
|
|
|
2090
2107
|
* @param v UV mapped Y value (0-1, default 0).
|
|
2091
2108
|
* @param color Pre-multiplied hex color combined using ABGR byte order (default 0xFFFFFFFF).
|
|
2092
2109
|
*/
|
|
2093
|
-
addVertex(t, e,
|
|
2110
|
+
addVertex(t, e, r = 0, i = 0, n = 4294967295) {
|
|
2094
2111
|
const a = this.vertexBuffer;
|
|
2095
|
-
a.pushFloat32(t), a.pushFloat32(e), this.currentShader != this.maskShader && a.pushUint32(n), a.pushFloat32(
|
|
2112
|
+
a.pushFloat32(t), a.pushFloat32(e), this.currentShader != this.maskShader && a.pushUint32(n), a.pushFloat32(r), a.pushFloat32(i), this.vertexCount++, this.vertexBuffer.makeDirty();
|
|
2096
2113
|
}
|
|
2097
2114
|
/**
|
|
2098
2115
|
* Finishes the graphic construction and dispatches the rendering call immediately.
|
|
@@ -2103,9 +2120,9 @@ class Ht extends yt {
|
|
|
2103
2120
|
render() {
|
|
2104
2121
|
if (this.vertexCount === 0) return;
|
|
2105
2122
|
this.prepareRender();
|
|
2106
|
-
const t = this.gl, e = this.currentShader,
|
|
2107
|
-
let n = r
|
|
2108
|
-
this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [r
|
|
2123
|
+
const t = this.gl, e = this.currentShader, r = this.matrixIndex * 6, i = this.matrixStore.data;
|
|
2124
|
+
let n = i[r + 4], a = i[r + 5];
|
|
2125
|
+
this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [i[r], i[r + 2], n]), e.setUniform("uMatrixRow1", [i[r + 1], i[r + 3], a]), e.setUniform(
|
|
2109
2126
|
"uUVRect",
|
|
2110
2127
|
this.texture ? [this.texture.uvX, this.texture.uvY, this.texture.uvW, this.texture.uvH] : [0, 0, 1, 1]
|
|
2111
2128
|
), this.texture?.glTexture ? (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture), e.setUniform("uTexture", 0), e.setUniform("uUseTexture", 1)) : e.setUniform("uUseTexture", 0), this.vertexBuffer.bindBuffer(), this.vertexBuffer.bufferData(), e.bindVAO(), t.drawArrays(this.drawMode, 0, this.vertexCount), this.rapid.drawcallCount++, this.texture = void 0;
|
|
@@ -2114,15 +2131,15 @@ class Ht extends yt {
|
|
|
2114
2131
|
return !1;
|
|
2115
2132
|
}
|
|
2116
2133
|
}
|
|
2117
|
-
class
|
|
2134
|
+
class m {
|
|
2118
2135
|
x;
|
|
2119
2136
|
y;
|
|
2120
|
-
static ZERO = new
|
|
2121
|
-
static ONE = new
|
|
2122
|
-
static UP = new
|
|
2123
|
-
static DOWN = new
|
|
2124
|
-
static LEFT = new
|
|
2125
|
-
static RIGHT = new
|
|
2137
|
+
static ZERO = new m(0, 0);
|
|
2138
|
+
static ONE = new m(1, 1);
|
|
2139
|
+
static UP = new m(0, 1);
|
|
2140
|
+
static DOWN = new m(0, -1);
|
|
2141
|
+
static LEFT = new m(-1, 0);
|
|
2142
|
+
static RIGHT = new m(1, 0);
|
|
2126
2143
|
constructor(t, e) {
|
|
2127
2144
|
this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
|
|
2128
2145
|
}
|
|
@@ -2130,22 +2147,22 @@ class d {
|
|
|
2130
2147
|
return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
|
|
2131
2148
|
}
|
|
2132
2149
|
add(t) {
|
|
2133
|
-
return new
|
|
2150
|
+
return new m(this.x + t.x, this.y + t.y);
|
|
2134
2151
|
}
|
|
2135
2152
|
subtract(t) {
|
|
2136
|
-
return new
|
|
2153
|
+
return new m(this.x - t.x, this.y - t.y);
|
|
2137
2154
|
}
|
|
2138
2155
|
sub(t) {
|
|
2139
|
-
return new
|
|
2156
|
+
return new m(this.x - t.x, this.y - t.y);
|
|
2140
2157
|
}
|
|
2141
2158
|
multiply(t) {
|
|
2142
|
-
return t instanceof
|
|
2159
|
+
return t instanceof m ? new m(this.x * t.x, this.y * t.y) : new m(this.x * t, this.y * t);
|
|
2143
2160
|
}
|
|
2144
2161
|
mul(t) {
|
|
2145
2162
|
return this.multiply(t);
|
|
2146
2163
|
}
|
|
2147
2164
|
divide(t) {
|
|
2148
|
-
return t instanceof
|
|
2165
|
+
return t instanceof m ? new m(this.x / t.x, this.y / t.y) : new m(this.x / t, this.y / t);
|
|
2149
2166
|
}
|
|
2150
2167
|
dot(t) {
|
|
2151
2168
|
return this.x * t.x + this.y * t.y;
|
|
@@ -2154,17 +2171,17 @@ class d {
|
|
|
2154
2171
|
return this.x * t.y - this.y * t.x;
|
|
2155
2172
|
}
|
|
2156
2173
|
distanceTo(t) {
|
|
2157
|
-
const e = this.x - t.x,
|
|
2158
|
-
return Math.sqrt(e * e +
|
|
2174
|
+
const e = this.x - t.x, r = this.y - t.y;
|
|
2175
|
+
return Math.sqrt(e * e + r * r);
|
|
2159
2176
|
}
|
|
2160
2177
|
clone() {
|
|
2161
|
-
return new
|
|
2178
|
+
return new m(this.x, this.y);
|
|
2162
2179
|
}
|
|
2163
2180
|
to(t) {
|
|
2164
2181
|
this.x = t.x, this.y = t.y;
|
|
2165
2182
|
}
|
|
2166
2183
|
copy() {
|
|
2167
|
-
return new
|
|
2184
|
+
return new m(this.x, this.y);
|
|
2168
2185
|
}
|
|
2169
2186
|
equals(t) {
|
|
2170
2187
|
return t.x == this.x && t.y == this.y;
|
|
@@ -2177,7 +2194,7 @@ class d {
|
|
|
2177
2194
|
return this.x = -this.x, this.y = -this.y, this;
|
|
2178
2195
|
}
|
|
2179
2196
|
inverted() {
|
|
2180
|
-
return new
|
|
2197
|
+
return new m(this.x * -1, this.y * -1);
|
|
2181
2198
|
}
|
|
2182
2199
|
length() {
|
|
2183
2200
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
@@ -2191,13 +2208,13 @@ class d {
|
|
|
2191
2208
|
}
|
|
2192
2209
|
normalized() {
|
|
2193
2210
|
const t = this.length();
|
|
2194
|
-
return new
|
|
2211
|
+
return new m(this.x / t || 0, this.y / t || 0);
|
|
2195
2212
|
}
|
|
2196
2213
|
fix(t = 1e-13) {
|
|
2197
2214
|
this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
|
|
2198
2215
|
}
|
|
2199
2216
|
fixed(t = 1e-13) {
|
|
2200
|
-
return new
|
|
2217
|
+
return new m(
|
|
2201
2218
|
Math.abs(this.x) < t ? 0 : this.x,
|
|
2202
2219
|
Math.abs(this.y) < t ? 0 : this.y
|
|
2203
2220
|
);
|
|
@@ -2206,13 +2223,13 @@ class d {
|
|
|
2206
2223
|
return Math.atan2(this.y, this.x);
|
|
2207
2224
|
}
|
|
2208
2225
|
abs() {
|
|
2209
|
-
return new
|
|
2226
|
+
return new m(Math.abs(this.x), Math.abs(this.y));
|
|
2210
2227
|
}
|
|
2211
2228
|
floor() {
|
|
2212
|
-
return new
|
|
2229
|
+
return new m(Math.floor(this.x), Math.floor(this.y));
|
|
2213
2230
|
}
|
|
2214
2231
|
ceil() {
|
|
2215
|
-
return new
|
|
2232
|
+
return new m(Math.ceil(this.x), Math.ceil(this.y));
|
|
2216
2233
|
}
|
|
2217
2234
|
stringify() {
|
|
2218
2235
|
return `Vec2(${this.x}, ${this.y})`;
|
|
@@ -2233,24 +2250,24 @@ class d {
|
|
|
2233
2250
|
return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
|
|
2234
2251
|
}
|
|
2235
2252
|
static FromArray(t) {
|
|
2236
|
-
return t.map((e) => new
|
|
2253
|
+
return t.map((e) => new m(e[0], e[1]));
|
|
2237
2254
|
}
|
|
2238
2255
|
static fromAngle(t) {
|
|
2239
|
-
return new
|
|
2256
|
+
return new m(Math.cos(t), Math.sin(t));
|
|
2240
2257
|
}
|
|
2241
2258
|
}
|
|
2242
2259
|
const Vt = (s, t) => {
|
|
2243
|
-
const [e,
|
|
2260
|
+
const [e, r, i, n, a, c] = t, h = new Float32Array([
|
|
2244
2261
|
e,
|
|
2245
2262
|
n,
|
|
2246
2263
|
0,
|
|
2247
2264
|
0,
|
|
2248
|
-
|
|
2265
|
+
r,
|
|
2249
2266
|
a,
|
|
2250
2267
|
0,
|
|
2251
2268
|
0,
|
|
2252
|
-
|
|
2253
|
-
|
|
2269
|
+
i,
|
|
2270
|
+
c,
|
|
2254
2271
|
1,
|
|
2255
2272
|
0,
|
|
2256
2273
|
0,
|
|
@@ -2261,142 +2278,153 @@ const Vt = (s, t) => {
|
|
|
2261
2278
|
return zt(s, h);
|
|
2262
2279
|
}, zt = (s, t) => {
|
|
2263
2280
|
const e = new Float32Array(16);
|
|
2264
|
-
for (let
|
|
2265
|
-
for (let
|
|
2281
|
+
for (let r = 0; r < 4; r++)
|
|
2282
|
+
for (let i = 0; i < 4; i++) {
|
|
2266
2283
|
let n = 0;
|
|
2267
2284
|
for (let a = 0; a < 4; a++)
|
|
2268
|
-
n += s[
|
|
2269
|
-
e[
|
|
2285
|
+
n += s[i * 4 + a] * t[a * 4 + r];
|
|
2286
|
+
e[i * 4 + r] = n;
|
|
2270
2287
|
}
|
|
2271
2288
|
return e;
|
|
2272
2289
|
};
|
|
2273
2290
|
var Yt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Yt || {});
|
|
2274
|
-
const Z = 10, ut = (s, t, e,
|
|
2275
|
-
const a = [],
|
|
2276
|
-
for (let
|
|
2277
|
-
const
|
|
2278
|
-
a.push(s),
|
|
2291
|
+
const Z = 10, ut = (s, t, e, r, i, n) => {
|
|
2292
|
+
const a = [], c = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), o = Math.PI, u = new m(t.y, -t.x);
|
|
2293
|
+
for (let l = 0; l < Z; l++) {
|
|
2294
|
+
const d = l / Z, f = (l + 1) / Z, x = h + d * o, g = h + f * o, v = new m(Math.cos(x) * e, Math.sin(x) * e), T = new m(Math.cos(g) * e, Math.sin(g) * e);
|
|
2295
|
+
a.push(s), c.push(new m(i, 0.5)), a.push(s.add(v)), c.push(new m(i + v.dot(u) * n, 0.5 - 0.5 * v.dot(t) / e)), a.push(s.add(T)), c.push(new m(i + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e));
|
|
2279
2296
|
}
|
|
2280
|
-
return { vertices: a, uv:
|
|
2297
|
+
return { vertices: a, uv: c };
|
|
2281
2298
|
}, Xt = (s, t = !1) => {
|
|
2282
2299
|
const e = [];
|
|
2283
2300
|
if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
|
|
2284
|
-
const
|
|
2301
|
+
const r = 4, i = 1e-3, n = s.length;
|
|
2285
2302
|
let a = 0;
|
|
2286
2303
|
if (t)
|
|
2287
2304
|
for (let h = 0; h < n; h++) {
|
|
2288
|
-
const
|
|
2289
|
-
a +=
|
|
2305
|
+
const o = s[h], u = s[(h + 1) % n];
|
|
2306
|
+
a += o.distanceTo(u);
|
|
2290
2307
|
}
|
|
2291
2308
|
else
|
|
2292
2309
|
for (let h = 0; h < n - 1; h++)
|
|
2293
2310
|
a += s[h].distanceTo(s[h + 1]);
|
|
2294
|
-
const
|
|
2295
|
-
const
|
|
2296
|
-
if (
|
|
2297
|
-
return { normal:
|
|
2311
|
+
const c = (h, o, u) => {
|
|
2312
|
+
const l = o.subtract(h).normalize(), d = o.subtract(u).normalize(), f = d.dot(l);
|
|
2313
|
+
if (f < -1 + i)
|
|
2314
|
+
return { normal: l.perpendicular(), miters: 1 };
|
|
2298
2315
|
{
|
|
2299
|
-
let x =
|
|
2300
|
-
|
|
2301
|
-
let g = 1 / Math.sqrt((1 -
|
|
2302
|
-
return { normal: x, miters: Math.min(g,
|
|
2316
|
+
let x = d.add(l).normalize();
|
|
2317
|
+
l.cross(d) < 0 && (x = x.multiply(-1));
|
|
2318
|
+
let g = 1 / Math.sqrt((1 - f) / 2);
|
|
2319
|
+
return { normal: x, miters: Math.min(g, r) };
|
|
2303
2320
|
}
|
|
2304
2321
|
};
|
|
2305
2322
|
if (t)
|
|
2306
2323
|
for (let h = 0; h < n; h++) {
|
|
2307
|
-
const
|
|
2308
|
-
e.push(o
|
|
2324
|
+
const o = h === 0 ? s[n - 1] : s[h - 1], u = s[h], l = h === n - 1 ? s[0] : s[h + 1];
|
|
2325
|
+
e.push(c(o, u, l));
|
|
2309
2326
|
}
|
|
2310
2327
|
else
|
|
2311
2328
|
for (let h = 0; h < n; h++)
|
|
2312
2329
|
if (h === 0) {
|
|
2313
|
-
const
|
|
2314
|
-
e.push({ normal:
|
|
2330
|
+
const o = s[1].subtract(s[0]).normalize();
|
|
2331
|
+
e.push({ normal: o.perpendicular(), miters: 1 });
|
|
2315
2332
|
} else if (h === n - 1) {
|
|
2316
|
-
const
|
|
2317
|
-
e.push({ normal:
|
|
2333
|
+
const o = s[h].subtract(s[h - 1]).normalize();
|
|
2334
|
+
e.push({ normal: o.perpendicular(), miters: 1 });
|
|
2318
2335
|
} else
|
|
2319
|
-
e.push(
|
|
2336
|
+
e.push(c(s[h - 1], s[h], s[h + 1]));
|
|
2320
2337
|
return { normals: e, length: a };
|
|
2321
2338
|
}, jt = (s) => {
|
|
2322
2339
|
const t = s.points;
|
|
2323
2340
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2324
|
-
const { normals: e, length:
|
|
2325
|
-
let
|
|
2326
|
-
const u = s.texture?.rawWidth || 1,
|
|
2327
|
-
for (let
|
|
2328
|
-
const
|
|
2329
|
-
let
|
|
2330
|
-
h === 0 ? (
|
|
2331
|
-
const U = new
|
|
2332
|
-
n.push(
|
|
2333
|
-
}
|
|
2334
|
-
if (
|
|
2335
|
-
const
|
|
2341
|
+
const { normals: e, length: r } = Xt(t, s.closed), i = (s.width || 1) / 2, n = [], a = [], c = s.roundCap || !1, h = s.textureMode || 0;
|
|
2342
|
+
let o = 0;
|
|
2343
|
+
const u = s.texture?.rawWidth || 1, l = s.closed ? t.length : t.length - 1;
|
|
2344
|
+
for (let d = 0; d < l; d++) {
|
|
2345
|
+
const f = t[d], x = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, T = t[v], R = e[v].normal, E = e[v].miters, b = f.add(x.multiply(g * i)), N = f.subtract(x.multiply(g * i)), W = T.add(R.multiply(E * i)), L = T.subtract(R.multiply(E * i)), S = f.distanceTo(T);
|
|
2346
|
+
let w = 0, A = 0;
|
|
2347
|
+
h === 0 ? (w = o / r, A = (o + S) / r) : (w = o / u, A = w + S / u);
|
|
2348
|
+
const U = new m(w, 0), O = new m(w, 1), j = new m(A, 0), q = new m(A, 1);
|
|
2349
|
+
n.push(b), a.push(U), n.push(N), a.push(O), n.push(W), a.push(j), n.push(W), a.push(j), n.push(L), a.push(q), n.push(N), a.push(O), o += S;
|
|
2350
|
+
}
|
|
2351
|
+
if (c && !s.closed) {
|
|
2352
|
+
const d = t[0], f = e[0].normal, x = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g = ut(d, f, i, !0, 0, x);
|
|
2336
2353
|
n.push(...g.vertices), a.push(...g.uv);
|
|
2337
|
-
const
|
|
2338
|
-
n.push(...
|
|
2354
|
+
const v = t[t.length - 1], T = e[t.length - 1].normal, R = h === 0 ? 1 : o / u, E = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, b = ut(v, T, i, !1, R, E);
|
|
2355
|
+
n.push(...b.vertices), a.push(...b.uv);
|
|
2339
2356
|
}
|
|
2340
2357
|
return { vertices: n, uv: a };
|
|
2341
|
-
}, X = (s, t, e,
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2358
|
+
}, X = (s, t, e, r) => {
|
|
2359
|
+
if (t.customMatrix !== void 0)
|
|
2360
|
+
return t.customMatrix;
|
|
2361
|
+
if (t.modifyStack) {
|
|
2362
|
+
s.matrixStack.applyTransform(
|
|
2363
|
+
t,
|
|
2364
|
+
e,
|
|
2365
|
+
r
|
|
2366
|
+
);
|
|
2367
|
+
return;
|
|
2368
|
+
} else {
|
|
2369
|
+
const i = s.matrix.temporary;
|
|
2370
|
+
return s.matrixStack.applyTransform(
|
|
2371
|
+
t,
|
|
2372
|
+
e,
|
|
2373
|
+
r,
|
|
2374
|
+
i
|
|
2375
|
+
), i;
|
|
2376
|
+
}
|
|
2377
|
+
}, st = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, $t = 2, Rt = (s, t, e) => {
|
|
2378
|
+
const r = t.texture;
|
|
2379
|
+
if (!r?.base || s.inCreateMask)
|
|
2351
2380
|
return;
|
|
2352
|
-
const i =
|
|
2381
|
+
const i = r.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
|
|
2353
2382
|
s.enterRegion(i, t.shader);
|
|
2354
|
-
let
|
|
2355
|
-
const
|
|
2356
|
-
let
|
|
2357
|
-
|
|
2358
|
-
const
|
|
2383
|
+
let n = r.uvX, a = r.uvY, c = r.uvW, h = r.uvH;
|
|
2384
|
+
const o = !!t.flipX, u = !!t.flipY != !!r.flipY;
|
|
2385
|
+
let l = t.padding ?? i.currentShader.padding;
|
|
2386
|
+
r.isAtlas && (l += $t);
|
|
2387
|
+
const d = n <= c ? l : -l, f = a <= h ? l : -l;
|
|
2359
2388
|
i.drawSprite(
|
|
2360
|
-
e,
|
|
2361
|
-
t.customMatrix ?? s.matrixStack.curWorldM,
|
|
2362
2389
|
r,
|
|
2390
|
+
e ?? t.customMatrix ?? s.matrixStack.curWorldM,
|
|
2363
2391
|
n,
|
|
2364
2392
|
a,
|
|
2365
|
-
|
|
2393
|
+
c,
|
|
2394
|
+
h,
|
|
2366
2395
|
st(s, t.color),
|
|
2396
|
+
d,
|
|
2367
2397
|
f,
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
e.isRotated
|
|
2398
|
+
o,
|
|
2399
|
+
u,
|
|
2400
|
+
r.isRotated
|
|
2372
2401
|
);
|
|
2373
2402
|
}, Kt = (s, t) => {
|
|
2374
|
-
X(s, t, t.texture.rawWidth, t.texture.rawHeight
|
|
2375
|
-
|
|
2376
|
-
});
|
|
2403
|
+
const e = X(s, t, t.texture.rawWidth, t.texture.rawHeight);
|
|
2404
|
+
Rt(s, t, e);
|
|
2377
2405
|
}, qt = (s, t) => {
|
|
2378
2406
|
const e = s.particleRegion;
|
|
2379
2407
|
s.enterRegion(e, t.shader);
|
|
2380
|
-
const
|
|
2408
|
+
const r = t.texture, i = t.count ?? t.x.length, n = t.color, a = n.length, c = new Array(a);
|
|
2381
2409
|
if (s.premultipliedAlpha)
|
|
2382
2410
|
for (let h = 0; h < a; h++)
|
|
2383
|
-
|
|
2411
|
+
c[h] = n[h].premultipliedUint32;
|
|
2384
2412
|
else
|
|
2385
2413
|
for (let h = 0; h < a; h++)
|
|
2386
|
-
|
|
2414
|
+
c[h] = n[h].uint32;
|
|
2387
2415
|
e.drawParticles(
|
|
2388
|
-
|
|
2416
|
+
r,
|
|
2389
2417
|
t.x,
|
|
2390
2418
|
t.y,
|
|
2391
2419
|
t.rotation,
|
|
2392
|
-
|
|
2393
|
-
|
|
2420
|
+
c,
|
|
2421
|
+
i,
|
|
2394
2422
|
t.scaleX,
|
|
2395
2423
|
t.scaleY,
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2424
|
+
r.uvX,
|
|
2425
|
+
r.uvY,
|
|
2426
|
+
r.uvW,
|
|
2427
|
+
r.uvH,
|
|
2400
2428
|
t.flipX,
|
|
2401
2429
|
t.flipY,
|
|
2402
2430
|
t.isRotated,
|
|
@@ -2404,64 +2432,65 @@ const Z = 10, ut = (s, t, e, i, r, n) => {
|
|
|
2404
2432
|
t.originY
|
|
2405
2433
|
);
|
|
2406
2434
|
}, Et = (s, t) => {
|
|
2407
|
-
t.points.length
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2435
|
+
if (t.points.length === 0) return;
|
|
2436
|
+
const e = X(s, t, 0, 0);
|
|
2437
|
+
s.startGraphic(
|
|
2438
|
+
t.drawMode ?? s.gl.TRIANGLES,
|
|
2439
|
+
t.texture,
|
|
2440
|
+
t.shader,
|
|
2441
|
+
e ?? t.customMatrix
|
|
2442
|
+
);
|
|
2443
|
+
for (let r = 0; r < t.points.length; r++) {
|
|
2444
|
+
const i = t.points[r], n = t.uv?.[r], a = Array.isArray(t.color) ? t.color[r] : t.color;
|
|
2445
|
+
s.addGraphicVertex(
|
|
2446
|
+
i.x,
|
|
2447
|
+
i.y,
|
|
2448
|
+
n?.x ?? 0,
|
|
2449
|
+
n?.y ?? 0,
|
|
2450
|
+
st(s, a)
|
|
2413
2451
|
);
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
s.addGraphicVertex(
|
|
2417
|
-
i.x,
|
|
2418
|
-
i.y,
|
|
2419
|
-
r?.x ?? 0,
|
|
2420
|
-
r?.y ?? 0,
|
|
2421
|
-
st(s, n)
|
|
2422
|
-
);
|
|
2423
|
-
}
|
|
2424
|
-
s.endGraphic();
|
|
2425
|
-
});
|
|
2452
|
+
}
|
|
2453
|
+
s.endGraphic();
|
|
2426
2454
|
}, Zt = (s, t) => {
|
|
2427
2455
|
if (s.inCreateMask)
|
|
2428
2456
|
return;
|
|
2429
|
-
const { vertices: e, uv:
|
|
2457
|
+
const { vertices: e, uv: r } = jt(t);
|
|
2430
2458
|
Et(s, {
|
|
2431
2459
|
...t,
|
|
2432
2460
|
points: e,
|
|
2433
|
-
uv:
|
|
2461
|
+
uv: r,
|
|
2434
2462
|
drawMode: s.gl.TRIANGLES
|
|
2435
2463
|
});
|
|
2436
2464
|
}, Qt = (s, t) => {
|
|
2437
|
-
|
|
2438
|
-
s
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2465
|
+
const e = X(
|
|
2466
|
+
s,
|
|
2467
|
+
t,
|
|
2468
|
+
t.texture.rawWidth,
|
|
2469
|
+
t.texture.rawHeight
|
|
2470
|
+
);
|
|
2471
|
+
s.startMaskGraphic(
|
|
2472
|
+
s.gl.TRIANGLE_FAN,
|
|
2473
|
+
t.texture,
|
|
2474
|
+
e ?? t.customMatrix
|
|
2475
|
+
), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
|
|
2444
2476
|
}, Jt = (s, t) => {
|
|
2445
|
-
X(s, t, t.width, t.height
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
});
|
|
2477
|
+
const e = X(s, t, t.width, t.height);
|
|
2478
|
+
s.startGraphic(
|
|
2479
|
+
s.gl.TRIANGLE_FAN,
|
|
2480
|
+
t.texture,
|
|
2481
|
+
t.shader,
|
|
2482
|
+
e ?? t.customMatrix
|
|
2483
|
+
), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
|
|
2453
2484
|
}, te = (s, t) => {
|
|
2454
|
-
const e = t.segments ?? 32;
|
|
2455
|
-
|
|
2456
|
-
s.
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
|
|
2464
|
-
});
|
|
2485
|
+
const e = t.segments ?? 32, r = X(s, t, 0, 0);
|
|
2486
|
+
s.startGraphic(
|
|
2487
|
+
s.gl.TRIANGLE_FAN,
|
|
2488
|
+
void 0,
|
|
2489
|
+
t.shader,
|
|
2490
|
+
r ?? t.customMatrix
|
|
2491
|
+
);
|
|
2492
|
+
const i = st(s, t.color);
|
|
2493
|
+
s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
|
|
2465
2494
|
}, lt = `#version 300 es\r
|
|
2466
2495
|
precision mediump float;\r
|
|
2467
2496
|
\r
|
|
@@ -2502,7 +2531,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
|
|
|
2502
2531
|
// CUSTOM_CODE\r
|
|
2503
2532
|
\r
|
|
2504
2533
|
void main(void) {\r
|
|
2505
|
-
fragColor = sampleClampTexture(vRegion);\r
|
|
2534
|
+
fragColor = sampleClampTexture(vRegion) * vColor;\r
|
|
2506
2535
|
// if (vPadding.x != 0.0) {\r
|
|
2507
2536
|
// if (clampUV(vRegion)) {\r
|
|
2508
2537
|
// fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
|
|
@@ -2512,31 +2541,31 @@ void main(void) {\r
|
|
|
2512
2541
|
// CUSTOM_CODE_CALL\r
|
|
2513
2542
|
}\r
|
|
2514
2543
|
`;
|
|
2515
|
-
class ee extends
|
|
2544
|
+
class ee extends it {
|
|
2516
2545
|
KEY = "AtlasSprite";
|
|
2517
2546
|
constructor(t) {
|
|
2518
2547
|
super(t);
|
|
2519
2548
|
}
|
|
2520
2549
|
createCustomShader(t) {
|
|
2521
|
-
const e =
|
|
2522
|
-
return t.getGLShader(this, this.KEY,
|
|
2550
|
+
const e = F(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = F($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
|
|
2551
|
+
return t.getGLShader(this, this.KEY, r, e);
|
|
2523
2552
|
}
|
|
2524
2553
|
createDefaultShader() {
|
|
2525
|
-
const t = this.rapid, e =
|
|
2526
|
-
return this.vs =
|
|
2554
|
+
const t = this.rapid, e = F(lt, t.maxTextureUnits), r = F($, t.maxTextureUnits);
|
|
2555
|
+
return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
|
|
2527
2556
|
}
|
|
2528
2557
|
}
|
|
2529
2558
|
const dt = `#version 300 es\r
|
|
2530
|
-
precision
|
|
2559
|
+
precision highp float;\r
|
|
2531
2560
|
\r
|
|
2532
2561
|
// per-vertex\r
|
|
2533
2562
|
in vec2 aVertex;\r
|
|
2534
2563
|
\r
|
|
2535
2564
|
// per-instance: 变换\r
|
|
2536
2565
|
in vec2 aPosition;\r
|
|
2537
|
-
in vec2 aScale
|
|
2538
|
-
in float aRotation
|
|
2539
|
-
in vec2 aOrigin
|
|
2566
|
+
in vec2 aScale;\r
|
|
2567
|
+
in float aRotation;\r
|
|
2568
|
+
in vec2 aOrigin;\r
|
|
2540
2569
|
\r
|
|
2541
2570
|
// per-instance:UV 区域 (u0, v0, u1, v1)\r
|
|
2542
2571
|
in vec4 aUVRect;\r
|
|
@@ -2556,7 +2585,7 @@ void main(void) {\r
|
|
|
2556
2585
|
vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
|
|
2557
2586
|
// CUSTOM_CODE_CALL\r
|
|
2558
2587
|
\r
|
|
2559
|
-
vec2 scaled = (aVertex - aOrigin) * aScale
|
|
2588
|
+
vec2 scaled = (aVertex - aOrigin) * aScale;\r
|
|
2560
2589
|
float c = cos(aRotation);\r
|
|
2561
2590
|
float s = sin(aRotation);\r
|
|
2562
2591
|
\r
|
|
@@ -2584,7 +2613,7 @@ void main(void) {\r
|
|
|
2584
2613
|
// CUSTOM_CODE_CALL\r
|
|
2585
2614
|
}\r
|
|
2586
2615
|
`, D = 48, mt = D / 4;
|
|
2587
|
-
class
|
|
2616
|
+
class re extends it {
|
|
2588
2617
|
KEY = "ParticleSprite";
|
|
2589
2618
|
texture;
|
|
2590
2619
|
constructor(t) {
|
|
@@ -2601,33 +2630,33 @@ class ie extends rt {
|
|
|
2601
2630
|
super.enter(t), this.currentShader.setUniform("u_projection", this.rapid.projection);
|
|
2602
2631
|
}
|
|
2603
2632
|
createShader(t, e) {
|
|
2604
|
-
const
|
|
2605
|
-
return
|
|
2633
|
+
const r = super.createShader(t, e);
|
|
2634
|
+
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
2606
2635
|
{ name: "aPosition", size: 2, stride: D, offset: 0, divisor: 1 },
|
|
2607
2636
|
{ name: "aScale", size: 2, stride: D, offset: 8, divisor: 1 },
|
|
2608
2637
|
{ name: "aRotation", size: 1, stride: D, offset: 16, divisor: 1 },
|
|
2609
2638
|
{ name: "aUVRect", size: 4, stride: D, offset: 20, divisor: 1 },
|
|
2610
2639
|
{ name: "aColor", size: 4, type: et, normalized: !0, stride: D, offset: 36, divisor: 1 },
|
|
2611
2640
|
{ name: "aOrigin", size: 2, stride: D, offset: 40, divisor: 1 }
|
|
2612
|
-
]), this.quadBuffer.bindBuffer(),
|
|
2641
|
+
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
2613
2642
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2614
|
-
]),
|
|
2643
|
+
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2615
2644
|
}
|
|
2616
|
-
drawParticles(t, e,
|
|
2645
|
+
drawParticles(t, e, r, i, n, a, c = 1, h = 1, o = 0, u = 0, l = 1, d = 1, f = !1, x = !1, g = !1, v = 0.5, T = 0.5) {
|
|
2617
2646
|
if (!t.glTexture || a <= 0) return;
|
|
2618
|
-
let
|
|
2619
|
-
const
|
|
2620
|
-
for (;
|
|
2647
|
+
let R = 0;
|
|
2648
|
+
const E = t.rawWidth * c * (f ? -1 : 1), b = t.rawHeight * h * (x ? -1 : 1), N = g ? Math.PI / 2 : 0;
|
|
2649
|
+
for (; R < a; ) {
|
|
2621
2650
|
this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2622
|
-
const
|
|
2623
|
-
let S =
|
|
2624
|
-
|
|
2625
|
-
const
|
|
2626
|
-
for (let U = 0; U <
|
|
2627
|
-
const
|
|
2628
|
-
|
|
2651
|
+
const W = a - R, L = this.instanceBuffer;
|
|
2652
|
+
let S = L.usedElemNum;
|
|
2653
|
+
L.resize(W * mt);
|
|
2654
|
+
const w = L.float32, A = L.uint32;
|
|
2655
|
+
for (let U = 0; U < W; U++) {
|
|
2656
|
+
const O = R + U;
|
|
2657
|
+
w[S] = e[O], w[S + 1] = r[O], w[S + 2] = E, w[S + 3] = b, w[S + 4] = i[O] + N, w[S + 5] = o, w[S + 6] = u, w[S + 7] = l, w[S + 8] = d, A[S + 9] = n[O], w[S + 10] = v, w[S + 11] = T, S += mt;
|
|
2629
2658
|
}
|
|
2630
|
-
|
|
2659
|
+
L.usedElemNum = S, L.makeDirty(), this.instanceCount += W, R += W;
|
|
2631
2660
|
}
|
|
2632
2661
|
}
|
|
2633
2662
|
render() {
|
|
@@ -2637,11 +2666,11 @@ class ie extends rt {
|
|
|
2637
2666
|
this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
|
|
2638
2667
|
const e = this.currentShader;
|
|
2639
2668
|
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
|
|
2640
|
-
const
|
|
2669
|
+
const r = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(r.curWorldM), a = Vt(this.rapid.projection, n);
|
|
2641
2670
|
this.currentShader.setUniform("u_projection", a), this.currentShader.setUniform("u_projection", this.rapid.projection), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0;
|
|
2642
2671
|
}
|
|
2643
2672
|
}
|
|
2644
|
-
var
|
|
2673
|
+
var ie = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(ie || {}), se = /* @__PURE__ */ ((s) => (s[s.NORMAL = 0] = "NORMAL", s[s.ADD = 1] = "ADD", s[s.MULTIPLY = 2] = "MULTIPLY", s[s.SCREEN = 3] = "SCREEN", s[s.ERASE = 4] = "ERASE", s))(se || {}), rt = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(rt || {}), ne = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(ne || {});
|
|
2645
2674
|
class ce {
|
|
2646
2675
|
/** The active WebGL context. */
|
|
2647
2676
|
gl;
|
|
@@ -2654,7 +2683,7 @@ class ce {
|
|
|
2654
2683
|
/** The current device pixel ratio. */
|
|
2655
2684
|
dpr;
|
|
2656
2685
|
/** Background clear color [r, g, b, a], values range from 0 to 255. */
|
|
2657
|
-
backgroundColor =
|
|
2686
|
+
backgroundColor = p.Black;
|
|
2658
2687
|
/** Logical width in CSS pixels, used for coordinate system and projection matrix. */
|
|
2659
2688
|
logicWidth = 0;
|
|
2660
2689
|
/** Logical height in CSS pixels, used for coordinate system and projection matrix. */
|
|
@@ -2707,9 +2736,9 @@ class ce {
|
|
|
2707
2736
|
constructor(t) {
|
|
2708
2737
|
this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? 1, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
|
|
2709
2738
|
const e = Ct(this.canvas, this.antialias, this.premultipliedAlpha);
|
|
2710
|
-
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new
|
|
2711
|
-
const
|
|
2712
|
-
this.physicsWidth = t.physicsWidth || Math.round(
|
|
2739
|
+
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new it(this), this.graphicRegion = new Ht(this), this.atlasSpriteRegion = new ee(this), this.particleRegion = new re(this);
|
|
2740
|
+
const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
|
|
2741
|
+
this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new bt(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
|
|
2713
2742
|
}
|
|
2714
2743
|
setTextureFilter(t) {
|
|
2715
2744
|
this.textureFilter = t;
|
|
@@ -2752,16 +2781,16 @@ class ce {
|
|
|
2752
2781
|
* @param texture An optional texture applied to the graphic vertices.
|
|
2753
2782
|
* @param customShader An optional custom shader overriding the region's default shader.
|
|
2754
2783
|
*/
|
|
2755
|
-
startGraphic(t = this.gl.TRIANGLES, e,
|
|
2756
|
-
this.enterRegion(this.graphicRegion,
|
|
2784
|
+
startGraphic(t = this.gl.TRIANGLES, e, r, i) {
|
|
2785
|
+
this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
|
|
2757
2786
|
}
|
|
2758
2787
|
/**
|
|
2759
2788
|
* Starts rendering graphics explicitly for use as a mask, overriding the shader.
|
|
2760
2789
|
* @param drawMode The WebGL drawing mode (e.g., gl.TRIANGLES).
|
|
2761
2790
|
* @param texture An optional texture whose alpha channel may dictate masking rules.
|
|
2762
2791
|
*/
|
|
2763
|
-
startMaskGraphic(t = this.gl.TRIANGLES, e,
|
|
2764
|
-
this.startGraphic(t, e, this.graphicRegion.maskShader,
|
|
2792
|
+
startMaskGraphic(t = this.gl.TRIANGLES, e, r) {
|
|
2793
|
+
this.startGraphic(t, e, this.graphicRegion.maskShader, r);
|
|
2765
2794
|
}
|
|
2766
2795
|
/**
|
|
2767
2796
|
* Utility method: Draws an image directly as a mask using a generic rectangle geometry.
|
|
@@ -2776,9 +2805,9 @@ class ce {
|
|
|
2776
2805
|
* @param h The height of the rectangle.
|
|
2777
2806
|
* @param color An optional tint color.
|
|
2778
2807
|
*/
|
|
2779
|
-
addRectVertex(t, e,
|
|
2780
|
-
const
|
|
2781
|
-
this.addGraphicVertex(0, 0, 0, 0,
|
|
2808
|
+
addRectVertex(t, e, r) {
|
|
2809
|
+
const i = this.getColorUint32(r);
|
|
2810
|
+
this.addGraphicVertex(0, 0, 0, 0, i), this.addGraphicVertex(t, 0, 1, 0, i), this.addGraphicVertex(t, e, 1, 1, i), this.addGraphicVertex(0, e, 0, 1, i);
|
|
2782
2811
|
}
|
|
2783
2812
|
/**
|
|
2784
2813
|
* Pushes vertices for a circle geometry using TRIANGLES or similar primitives.
|
|
@@ -2786,11 +2815,11 @@ class ce {
|
|
|
2786
2815
|
* @param color An optional tint color.
|
|
2787
2816
|
* @param segments The number of segments (polygons) used to approximate the circle.
|
|
2788
2817
|
*/
|
|
2789
|
-
addCircleVertex(t, e,
|
|
2790
|
-
const
|
|
2791
|
-
for (let a = 0; a <
|
|
2792
|
-
const
|
|
2793
|
-
this.addGraphicVertex(h,
|
|
2818
|
+
addCircleVertex(t, e, r = 32) {
|
|
2819
|
+
const i = Math.PI * 2 / r, n = this.getColorUint32(e);
|
|
2820
|
+
for (let a = 0; a < r; a++) {
|
|
2821
|
+
const c = i * a, h = Math.cos(c) * t, o = Math.sin(c) * t, u = 0.5 + Math.cos(c) * 0.5, l = 0.5 + Math.sin(c) * 0.5;
|
|
2822
|
+
this.addGraphicVertex(h, o, u, l, n);
|
|
2794
2823
|
}
|
|
2795
2824
|
}
|
|
2796
2825
|
/**
|
|
@@ -2801,8 +2830,8 @@ class ce {
|
|
|
2801
2830
|
* @param v The V texture coordinate (0 to 1).
|
|
2802
2831
|
* @param color The vertex color as a 32-bit unsigned integer.
|
|
2803
2832
|
*/
|
|
2804
|
-
addGraphicVertex(t, e,
|
|
2805
|
-
this.graphicRegion.addVertex(t, e,
|
|
2833
|
+
addGraphicVertex(t, e, r = 0, i = 0, n = 4294967295) {
|
|
2834
|
+
this.graphicRegion.addVertex(t, e, r, i, n);
|
|
2806
2835
|
}
|
|
2807
2836
|
/**
|
|
2808
2837
|
* Ends the current graphics geometry definition, readying it for rendering.
|
|
@@ -2817,10 +2846,10 @@ class ce {
|
|
|
2817
2846
|
* @param cssWidth Optional CSS display width.
|
|
2818
2847
|
* @param cssHeight Optional CSS display height.
|
|
2819
2848
|
*/
|
|
2820
|
-
resize(t, e,
|
|
2849
|
+
resize(t, e, r, i) {
|
|
2821
2850
|
this.flush();
|
|
2822
|
-
const n =
|
|
2823
|
-
switch (
|
|
2851
|
+
const n = r ?? this.canvas.clientWidth ?? this.canvas.width, a = i ?? this.canvas.clientHeight ?? this.canvas.height;
|
|
2852
|
+
switch (r !== void 0 && (this.canvas.style.width = n + "px"), i !== void 0 && (this.canvas.style.height = a + "px"), this.physicsWidth = n * this.dpr, this.physicsHeight = a * this.dpr, this.logicWidth = t, this.logicHeight = e, this.scaleMode) {
|
|
2824
2853
|
case 1:
|
|
2825
2854
|
this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
|
|
2826
2855
|
break;
|
|
@@ -2836,8 +2865,8 @@ class ce {
|
|
|
2836
2865
|
* Updates the projection matrix using an orthographic mapping.
|
|
2837
2866
|
* Automatically sets local flag projectionDirty.
|
|
2838
2867
|
*/
|
|
2839
|
-
updateProjection(t, e,
|
|
2840
|
-
this.updateOrthMatrix(this.projection, t, e,
|
|
2868
|
+
updateProjection(t, e, r, i) {
|
|
2869
|
+
this.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
|
|
2841
2870
|
}
|
|
2842
2871
|
/**
|
|
2843
2872
|
* Clears the active framebuffer applying the default background color.
|
|
@@ -2850,8 +2879,8 @@ class ce {
|
|
|
2850
2879
|
* Populates an orthographic projection matrix in place.
|
|
2851
2880
|
* Avoids continuous Float32Array allocations for performance reasons.
|
|
2852
2881
|
*/
|
|
2853
|
-
updateOrthMatrix(t, e,
|
|
2854
|
-
t[0] = 2 / (
|
|
2882
|
+
updateOrthMatrix(t, e, r, i, n) {
|
|
2883
|
+
t[0] = 2 / (r - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (n - i), t[6] = 0, t[7] = 0, t[8] = 0, t[9] = 0, t[10] = -1, t[11] = 0, t[12] = -(r + e) / (r - e), t[13] = -(n + i) / (n - i), t[14] = 0, t[15] = 1;
|
|
2855
2884
|
}
|
|
2856
2885
|
/**
|
|
2857
2886
|
* Flushes currently buffered rendering operations across all active regions.
|
|
@@ -2876,23 +2905,23 @@ class ce {
|
|
|
2876
2905
|
applyFilters(t, e) {
|
|
2877
2906
|
if (e.length === 0)
|
|
2878
2907
|
throw new Error("applyFilters: shaders array must not be empty.");
|
|
2879
|
-
const
|
|
2880
|
-
for (let
|
|
2881
|
-
this._filterRT[
|
|
2882
|
-
let
|
|
2908
|
+
const r = Math.max(...e.map((o) => o.padding)), i = r, n = t.rawWidth + r * 2, a = t.rawHeight + r * 2;
|
|
2909
|
+
for (let o = 0; o < 2; o++)
|
|
2910
|
+
this._filterRT[o] ? this._filterRT[o].resize(n, a) : this._filterRT[o] = this.texture.createRenderTexture({ width: n, height: a });
|
|
2911
|
+
let c = t.clone(this._filterInput), h = 0;
|
|
2883
2912
|
this.matrixStack.save(), this.matrixStack.identity();
|
|
2884
|
-
for (let
|
|
2913
|
+
for (let o = 0; o < e.length; o++) {
|
|
2885
2914
|
const u = this._filterRT[h % 2];
|
|
2886
2915
|
u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
|
|
2887
|
-
texture:
|
|
2888
|
-
shader: e[
|
|
2889
|
-
offsetX:
|
|
2916
|
+
texture: c,
|
|
2917
|
+
shader: e[o],
|
|
2918
|
+
offsetX: o == 0 ? i : 0,
|
|
2890
2919
|
// padding back
|
|
2891
|
-
offsetY:
|
|
2892
|
-
padding:
|
|
2893
|
-
}), this.leaveRenderTexture(),
|
|
2920
|
+
offsetY: o == 0 ? i : 0,
|
|
2921
|
+
padding: r
|
|
2922
|
+
}), this.leaveRenderTexture(), c = u, h++;
|
|
2894
2923
|
}
|
|
2895
|
-
return this.matrixStack.restore(),
|
|
2924
|
+
return this.matrixStack.restore(), c.offsetX = -i, c.offsetY = -i, c;
|
|
2896
2925
|
}
|
|
2897
2926
|
enterRenderTexture(t) {
|
|
2898
2927
|
this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, t.rawHeight, 0);
|
|
@@ -2904,7 +2933,7 @@ class ce {
|
|
|
2904
2933
|
* @param rt The render texture to clear.
|
|
2905
2934
|
* @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
|
|
2906
2935
|
*/
|
|
2907
|
-
clearRenderTexture(t = new
|
|
2936
|
+
clearRenderTexture(t = new p(0, 0, 0, 0)) {
|
|
2908
2937
|
this.flush();
|
|
2909
2938
|
const e = this.gl;
|
|
2910
2939
|
t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
|
|
@@ -2926,10 +2955,10 @@ class ce {
|
|
|
2926
2955
|
* rapid.drawSprite({ texture: mySprite });
|
|
2927
2956
|
* });
|
|
2928
2957
|
*/
|
|
2929
|
-
drawToRenderTexture(t, e,
|
|
2958
|
+
drawToRenderTexture(t, e, r = new p(0, 0, 0, 0)) {
|
|
2930
2959
|
this.enterRenderTexture(t);
|
|
2931
2960
|
try {
|
|
2932
|
-
|
|
2961
|
+
r !== null && this.clearRenderTexture(r), e();
|
|
2933
2962
|
} finally {
|
|
2934
2963
|
this.leaveRenderTexture();
|
|
2935
2964
|
}
|
|
@@ -2947,14 +2976,14 @@ class ce {
|
|
|
2947
2976
|
* () => rapid.drawSprite({ texture: myTexture }),
|
|
2948
2977
|
* );
|
|
2949
2978
|
*/
|
|
2950
|
-
withMask(t, e,
|
|
2951
|
-
this.clearMask(), this.startDrawMask(
|
|
2979
|
+
withMask(t, e, r = 0, i = 1) {
|
|
2980
|
+
this.clearMask(), this.startDrawMask(i);
|
|
2952
2981
|
try {
|
|
2953
2982
|
t();
|
|
2954
2983
|
} finally {
|
|
2955
2984
|
this.endDrawMask();
|
|
2956
2985
|
}
|
|
2957
|
-
this.enterMask(
|
|
2986
|
+
this.enterMask(r, i);
|
|
2958
2987
|
try {
|
|
2959
2988
|
e();
|
|
2960
2989
|
} finally {
|
|
@@ -2983,21 +3012,12 @@ class ce {
|
|
|
2983
3012
|
* rapid.drawSprite({ texture: myTexture });
|
|
2984
3013
|
* }, { x: 100, y: 50, rotation: Math.PI / 4, origin: 0.5 }, myTexture.width, myTexture.height);
|
|
2985
3014
|
*/
|
|
2986
|
-
withTransform(t, e,
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
n && this.matrixStack.restore();
|
|
2993
|
-
}
|
|
2994
|
-
} else {
|
|
2995
|
-
this.matrixStack.save();
|
|
2996
|
-
try {
|
|
2997
|
-
t();
|
|
2998
|
-
} finally {
|
|
2999
|
-
this.matrixStack.restore();
|
|
3000
|
-
}
|
|
3015
|
+
withTransform(t, e, r = 0, i = 0) {
|
|
3016
|
+
this.matrixStack.save();
|
|
3017
|
+
try {
|
|
3018
|
+
e && this.matrixStack.applyTransform(e, r, i), t();
|
|
3019
|
+
} finally {
|
|
3020
|
+
this.matrixStack.restore();
|
|
3001
3021
|
}
|
|
3002
3022
|
}
|
|
3003
3023
|
/**
|
|
@@ -3013,8 +3033,8 @@ class ce {
|
|
|
3013
3033
|
* rapid.drawSprite({ texture: myTexture });
|
|
3014
3034
|
* });
|
|
3015
3035
|
*/
|
|
3016
|
-
withScissor(t, e,
|
|
3017
|
-
this.startScissor(t, e,
|
|
3036
|
+
withScissor(t, e, r, i, n) {
|
|
3037
|
+
this.startScissor(t, e, r, i);
|
|
3018
3038
|
try {
|
|
3019
3039
|
n();
|
|
3020
3040
|
} finally {
|
|
@@ -3049,8 +3069,8 @@ class ce {
|
|
|
3049
3069
|
*/
|
|
3050
3070
|
startDrawMask(t = 1, e = 255) {
|
|
3051
3071
|
this.flush();
|
|
3052
|
-
const
|
|
3053
|
-
|
|
3072
|
+
const r = this.gl;
|
|
3073
|
+
r.stencilMask(e), r.colorMask(!1, !1, !1, !1), r.stencilFunc(r.ALWAYS, t, e), r.stencilOp(r.KEEP, r.KEEP, r.REPLACE), this.enterRegion(this.graphicRegion, this.graphicRegion.maskShader), this.inCreateMask = !0;
|
|
3054
3074
|
}
|
|
3055
3075
|
/**
|
|
3056
3076
|
* Finishes the mask drawing phase and restores color buffer writing.
|
|
@@ -3075,10 +3095,10 @@ class ce {
|
|
|
3075
3095
|
* @param ref The reference value to test against.
|
|
3076
3096
|
* @param mask The bitmask specifying which stencil bits to consider.
|
|
3077
3097
|
*/
|
|
3078
|
-
enterMask(t, e = 1,
|
|
3098
|
+
enterMask(t, e = 1, r = 255) {
|
|
3079
3099
|
this.flush();
|
|
3080
|
-
const
|
|
3081
|
-
|
|
3100
|
+
const i = this.gl;
|
|
3101
|
+
i.colorMask(!0, !0, !0, !0), i.stencilMask(0), i.stencilFunc(t === 0 ? i.EQUAL : i.NOTEQUAL, e, r), i.stencilOp(i.KEEP, i.KEEP, i.KEEP), this.inCreateMask = !1;
|
|
3082
3102
|
}
|
|
3083
3103
|
/**
|
|
3084
3104
|
* Exits the masked rendering phase, restoring default full-screen stencil values tests.
|
|
@@ -3122,10 +3142,10 @@ class ce {
|
|
|
3122
3142
|
* @param width Width in logical pixels.
|
|
3123
3143
|
* @param height Height in logical pixels.
|
|
3124
3144
|
*/
|
|
3125
|
-
startScissor(t, e,
|
|
3145
|
+
startScissor(t, e, r, i) {
|
|
3126
3146
|
this.flush();
|
|
3127
|
-
const n = this.gl, a = this.physicsWidth / this.logicWidth,
|
|
3128
|
-
n.enable(n.SCISSOR_TEST), n.scissor(h,
|
|
3147
|
+
const n = this.gl, a = this.physicsWidth / this.logicWidth, c = this.physicsHeight / this.logicHeight, h = Math.round(t * a), o = Math.round(this.physicsHeight - (e + i) * c), u = Math.round(r * a), l = Math.round(i * c);
|
|
3148
|
+
n.enable(n.SCISSOR_TEST), n.scissor(h, o, u, l);
|
|
3129
3149
|
}
|
|
3130
3150
|
/**
|
|
3131
3151
|
* Disables scissor clipping, restoring full-canvas rendering.
|
|
@@ -3139,13 +3159,13 @@ class ce {
|
|
|
3139
3159
|
this.matrix.invert(e);
|
|
3140
3160
|
}
|
|
3141
3161
|
logicToPhysics(t) {
|
|
3142
|
-
return t.multiply(new
|
|
3162
|
+
return t.multiply(new m(
|
|
3143
3163
|
this.physicsWidth / this.logicWidth,
|
|
3144
3164
|
this.physicsHeight / this.logicHeight
|
|
3145
3165
|
));
|
|
3146
3166
|
}
|
|
3147
3167
|
physicsToLogic(t) {
|
|
3148
|
-
return t.multiply(new
|
|
3168
|
+
return t.multiply(new m(
|
|
3149
3169
|
this.logicWidth / this.physicsWidth,
|
|
3150
3170
|
this.logicHeight / this.physicsHeight
|
|
3151
3171
|
));
|
|
@@ -3169,12 +3189,12 @@ class ce {
|
|
|
3169
3189
|
* @param index - Matrix index to export. Defaults to the current world matrix.
|
|
3170
3190
|
*/
|
|
3171
3191
|
toCSSMatrix(t) {
|
|
3172
|
-
const e = this.physicsWidth / this.dpr / this.logicWidth,
|
|
3173
|
-
return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e,
|
|
3192
|
+
const e = this.physicsWidth / this.dpr / this.logicWidth, r = this.physicsHeight / this.dpr / this.logicHeight;
|
|
3193
|
+
return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
|
|
3174
3194
|
}
|
|
3175
3195
|
}
|
|
3176
3196
|
function ae(s) {
|
|
3177
|
-
return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof
|
|
3197
|
+
return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof m || s instanceof p);
|
|
3178
3198
|
}
|
|
3179
3199
|
class C {
|
|
3180
3200
|
/** Random float in [min, max). */
|
|
@@ -3190,12 +3210,12 @@ class C {
|
|
|
3190
3210
|
return Math.random() * Math.PI * 2;
|
|
3191
3211
|
}
|
|
3192
3212
|
/** Random Vec2 with components in the supplied per-axis ranges. */
|
|
3193
|
-
static vector(t, e,
|
|
3194
|
-
return new
|
|
3213
|
+
static vector(t, e, r, i) {
|
|
3214
|
+
return new m(C.float(t, e), C.float(r, i));
|
|
3195
3215
|
}
|
|
3196
3216
|
/** Random Color with each component interpolated between minColor and maxColor. */
|
|
3197
3217
|
static randomColor(t, e) {
|
|
3198
|
-
return new
|
|
3218
|
+
return new p(
|
|
3199
3219
|
C.float(t.r, e.r),
|
|
3200
3220
|
C.float(t.g, e.g),
|
|
3201
3221
|
C.float(t.b, e.b),
|
|
@@ -3213,10 +3233,10 @@ class C {
|
|
|
3213
3233
|
static pickWeight(t) {
|
|
3214
3234
|
if (!t || t.length === 0) return null;
|
|
3215
3235
|
let e = 0;
|
|
3216
|
-
for (const [,
|
|
3217
|
-
let
|
|
3218
|
-
for (const [
|
|
3219
|
-
if (
|
|
3236
|
+
for (const [, i] of t) e += i;
|
|
3237
|
+
let r = Math.random() * e;
|
|
3238
|
+
for (const [i, n] of t)
|
|
3239
|
+
if (r -= n, r <= 0) return i;
|
|
3220
3240
|
return t[t.length - 1][0];
|
|
3221
3241
|
}
|
|
3222
3242
|
/**
|
|
@@ -3228,13 +3248,13 @@ class C {
|
|
|
3228
3248
|
static scalarOrRange(t, e) {
|
|
3229
3249
|
if (t == null) return e;
|
|
3230
3250
|
if (Array.isArray(t)) {
|
|
3231
|
-
const [
|
|
3232
|
-
if (typeof
|
|
3233
|
-
return C.float(
|
|
3234
|
-
if (
|
|
3235
|
-
return C.vector(
|
|
3236
|
-
if (
|
|
3237
|
-
return C.randomColor(
|
|
3251
|
+
const [r, i] = t;
|
|
3252
|
+
if (typeof r == "number")
|
|
3253
|
+
return C.float(r, i);
|
|
3254
|
+
if (r instanceof m)
|
|
3255
|
+
return C.vector(r.x, i.x, r.y, i.y);
|
|
3256
|
+
if (r instanceof p)
|
|
3257
|
+
return C.randomColor(r, i);
|
|
3238
3258
|
}
|
|
3239
3259
|
return typeof t == "number" ? t : t.clone();
|
|
3240
3260
|
}
|
|
@@ -3254,19 +3274,19 @@ class oe {
|
|
|
3254
3274
|
speed: this.processAttribute(e.animation.speed, 0),
|
|
3255
3275
|
rotation: this.processAttribute(e.animation.rotation, 0),
|
|
3256
3276
|
scale: this.processAttribute(e.animation.scale, 1),
|
|
3257
|
-
color: this.processAttribute(e.animation.color,
|
|
3258
|
-
velocity: this.processAttribute(e.animation.velocity,
|
|
3259
|
-
}, this.position =
|
|
3277
|
+
color: this.processAttribute(e.animation.color, p.White.clone()),
|
|
3278
|
+
velocity: this.processAttribute(e.animation.velocity, m.ZERO)
|
|
3279
|
+
}, this.position = m.ZERO, this.initializePosition();
|
|
3260
3280
|
}
|
|
3261
3281
|
processAttribute(t, e) {
|
|
3262
3282
|
if (t == null)
|
|
3263
3283
|
return { value: e };
|
|
3264
3284
|
if (ae(t)) {
|
|
3265
|
-
const
|
|
3285
|
+
const r = t, i = C.scalarOrRange(r.start, e), n = r.end === void 0 ? i : C.scalarOrRange(r.end, e);
|
|
3266
3286
|
return {
|
|
3267
|
-
delta:
|
|
3268
|
-
value:
|
|
3269
|
-
damping:
|
|
3287
|
+
delta: r.delta ?? this.getDelta(i, n, this.maxLife),
|
|
3288
|
+
value: i,
|
|
3289
|
+
damping: r.damping
|
|
3270
3290
|
};
|
|
3271
3291
|
} else
|
|
3272
3292
|
return this.processAttribute({ start: t }, e);
|
|
@@ -3283,11 +3303,11 @@ class oe {
|
|
|
3283
3303
|
updateAttributes(t) {
|
|
3284
3304
|
const e = this.datas;
|
|
3285
3305
|
this.updateNumberAttribute(e.speed, t), this.updateNumberAttribute(e.rotation, t), this.updateNumberAttribute(e.scale, t), this.updateColorAttribute(e.color, t), this.updateVec2Attribute(e.velocity, t);
|
|
3286
|
-
const
|
|
3287
|
-
this.position = this.position.add(
|
|
3306
|
+
const i = m.fromAngle(e.rotation.value).multiply(e.speed.value * t);
|
|
3307
|
+
this.position = this.position.add(i).add(e.velocity.value.multiply(t));
|
|
3288
3308
|
}
|
|
3289
|
-
getDelta(t, e,
|
|
3290
|
-
return typeof t == "number" && typeof e == "number" ? (e - t) /
|
|
3309
|
+
getDelta(t, e, r) {
|
|
3310
|
+
return typeof t == "number" && typeof e == "number" ? (e - t) / r : t instanceof m && e instanceof m || t instanceof p && e instanceof p ? e.subtract(t).divide(r) : t;
|
|
3291
3311
|
}
|
|
3292
3312
|
/**
|
|
3293
3313
|
* Updates particle state.
|
|
@@ -3302,27 +3322,27 @@ class oe {
|
|
|
3302
3322
|
* The emitter is responsible for calling save/restore around a batch of particles.
|
|
3303
3323
|
*/
|
|
3304
3324
|
render() {
|
|
3305
|
-
const t = this.rapid.matrixStack, e = this.datas.scale.value,
|
|
3306
|
-
t.save(), t.translate(this.position.x, this.position.y),
|
|
3325
|
+
const t = this.rapid.matrixStack, e = this.datas.scale.value, r = this.datas.rotation.value, i = this.datas.color.value;
|
|
3326
|
+
t.save(), t.translate(this.position.x, this.position.y), r !== 0 && t.rotate(r), e !== 1 && t.scale(e, e);
|
|
3307
3327
|
const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
|
|
3308
|
-
(n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(this.rapid, { texture: this.texture, color:
|
|
3328
|
+
(n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(this.rapid, { texture: this.texture, color: i }), t.restore();
|
|
3309
3329
|
}
|
|
3310
3330
|
initializePosition() {
|
|
3311
3331
|
switch (this.options.emitShape) {
|
|
3312
3332
|
case "circle": {
|
|
3313
3333
|
const t = Math.random() * Math.PI * 2, e = (this.options.emitRadius ?? 0) * Math.sqrt(Math.random());
|
|
3314
|
-
this.position = new
|
|
3334
|
+
this.position = new m(Math.cos(t) * e, Math.sin(t) * e);
|
|
3315
3335
|
break;
|
|
3316
3336
|
}
|
|
3317
3337
|
case "rect": {
|
|
3318
|
-
this.position = new
|
|
3338
|
+
this.position = new m(
|
|
3319
3339
|
(Math.random() - 0.5) * (this.options.emitRect?.width ?? 0),
|
|
3320
3340
|
(Math.random() - 0.5) * (this.options.emitRect?.height ?? 0)
|
|
3321
3341
|
);
|
|
3322
3342
|
break;
|
|
3323
3343
|
}
|
|
3324
3344
|
default:
|
|
3325
|
-
this.position =
|
|
3345
|
+
this.position = m.ZERO;
|
|
3326
3346
|
break;
|
|
3327
3347
|
}
|
|
3328
3348
|
!this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
|
|
@@ -3339,7 +3359,7 @@ class wt {
|
|
|
3339
3359
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3340
3360
|
localSpace = gt;
|
|
3341
3361
|
/** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
|
|
3342
|
-
position =
|
|
3362
|
+
position = m.ZERO;
|
|
3343
3363
|
rapid;
|
|
3344
3364
|
gameObject;
|
|
3345
3365
|
/**
|
|
@@ -3348,7 +3368,7 @@ class wt {
|
|
|
3348
3368
|
* @param options - Emitter configuration options
|
|
3349
3369
|
*/
|
|
3350
3370
|
constructor(t, e) {
|
|
3351
|
-
this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : xt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : pt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : gt, this.position = e.position ??
|
|
3371
|
+
this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : xt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : pt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : gt, this.position = e.position ?? m.ZERO;
|
|
3352
3372
|
}
|
|
3353
3373
|
/** Replaces the emitter's texture at runtime. */
|
|
3354
3374
|
setTexture(t) {
|
|
@@ -3386,8 +3406,8 @@ class wt {
|
|
|
3386
3406
|
* Respects `maxParticles` if set.
|
|
3387
3407
|
*/
|
|
3388
3408
|
emit(t) {
|
|
3389
|
-
const e = this.options.maxParticles ?? 1 / 0,
|
|
3390
|
-
for (let
|
|
3409
|
+
const e = this.options.maxParticles ?? 1 / 0, r = Math.min(t, e - this.particles.length);
|
|
3410
|
+
for (let i = 0; i < r; i++)
|
|
3391
3411
|
this.particles.push(new oe(this.rapid, { ...this.options, position: this.position }));
|
|
3392
3412
|
}
|
|
3393
3413
|
/**
|
|
@@ -3436,17 +3456,17 @@ class wt {
|
|
|
3436
3456
|
}
|
|
3437
3457
|
}
|
|
3438
3458
|
export {
|
|
3439
|
-
|
|
3459
|
+
I as ArrayType,
|
|
3440
3460
|
k as BaseTexture,
|
|
3441
3461
|
se as BlendMode,
|
|
3442
3462
|
ne as CanvasScaleMode,
|
|
3443
|
-
|
|
3463
|
+
p as Color,
|
|
3444
3464
|
ot as CustomGlShader,
|
|
3445
3465
|
B as DynamicArrayBuffer,
|
|
3446
3466
|
Tt as GLShader,
|
|
3447
3467
|
Ht as GraphicRegion,
|
|
3448
3468
|
Yt as LineTextureMode,
|
|
3449
|
-
|
|
3469
|
+
ie as MaskType,
|
|
3450
3470
|
St as MatrixStack,
|
|
3451
3471
|
Mt as MatrixStore,
|
|
3452
3472
|
oe as Particle,
|
|
@@ -3456,13 +3476,13 @@ export {
|
|
|
3456
3476
|
ce as Rapid,
|
|
3457
3477
|
yt as Region,
|
|
3458
3478
|
At as RenderTexture,
|
|
3459
|
-
|
|
3479
|
+
it as SpriteRegion,
|
|
3460
3480
|
_t as TextTexture,
|
|
3461
3481
|
P as Texture,
|
|
3462
|
-
|
|
3482
|
+
rt as TextureFilterMode,
|
|
3463
3483
|
bt as TextureManager,
|
|
3464
3484
|
Y as TextureWrapMode,
|
|
3465
|
-
|
|
3485
|
+
m as Vec2,
|
|
3466
3486
|
Q as WebglBufferArray,
|
|
3467
3487
|
Vt as composeProjectionWithAffine,
|
|
3468
3488
|
te as drawCircle,
|