rapid-render 1.0.5 → 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 -18
- package/dist/matrix-engine.d.ts +5 -5
- package/dist/rapid-render.js +820 -833
- package/dist/rapid-render.umd.cjs +24 -24
- package/dist/region/particleRegion.d.ts +0 -1
- package/dist/region/region.d.ts +1 -1
- package/dist/render.d.ts +1 -2
- package/package.json +5 -4
package/dist/rapid-render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
class
|
|
1
|
+
var I = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(I || {});
|
|
2
|
+
class B {
|
|
3
3
|
/** The number of elements currently used in the buffer. */
|
|
4
4
|
usedElemNum;
|
|
5
5
|
/** The main typed array view corresponding to the specified ArrayType. */
|
|
@@ -151,7 +151,7 @@ class k {
|
|
|
151
151
|
this.usedElemNum = 0;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
class
|
|
154
|
+
class Q extends B {
|
|
155
155
|
/** The actual WebGLBuffer object maintained by this instance. */
|
|
156
156
|
buffer;
|
|
157
157
|
/** The related WebGL rendering context. */
|
|
@@ -171,8 +171,8 @@ class et extends k {
|
|
|
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 et extends k {
|
|
|
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,37 +434,38 @@ 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
|
|
455
|
-
class
|
|
454
|
+
const y = 6;
|
|
455
|
+
class Mt {
|
|
456
456
|
/** Total number of matrices currently allocated in the store. */
|
|
457
457
|
matrixCount = 0;
|
|
458
458
|
/** The dynamic buffer used to hold matrix data. */
|
|
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
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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 St {
|
|
|
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,29 +689,33 @@ class St {
|
|
|
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
|
-
class
|
|
704
|
+
class St {
|
|
700
705
|
/** The underlying store for matrices. */
|
|
701
|
-
matrix = new
|
|
706
|
+
matrix = new Mt();
|
|
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
|
|
710
|
+
stack = new B(I.Uint32);
|
|
706
711
|
/** Records the world matrices generated at each step. */
|
|
707
|
-
stepWorldM = new
|
|
712
|
+
stepWorldM = new B(I.Uint32);
|
|
708
713
|
/** Records actions (push/pop) taken during the traversal. */
|
|
709
|
-
stepAction = new
|
|
714
|
+
stepAction = new B(I.Uint32);
|
|
710
715
|
/** Records the parent world matrix for each step (used by updateMatrix). */
|
|
711
|
-
stepParentM = new
|
|
716
|
+
stepParentM = new B(I.Uint32);
|
|
712
717
|
/** Buffer used during hierarchy traversal updates. */
|
|
713
|
-
parentStack = new
|
|
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 bt {
|
|
|
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 bt {
|
|
|
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,57 +864,69 @@ class bt {
|
|
|
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
|
-
R,
|
|
896
912
|
T,
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
b
|
|
913
|
+
R,
|
|
914
|
+
E,
|
|
915
|
+
b,
|
|
916
|
+
N
|
|
900
917
|
), this.matrix.multiplyAffineInPlace(
|
|
901
918
|
this.curWorldM,
|
|
902
919
|
v,
|
|
903
|
-
R,
|
|
904
920
|
T,
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
b
|
|
908
|
-
|
|
921
|
+
R,
|
|
922
|
+
E,
|
|
923
|
+
b,
|
|
924
|
+
N
|
|
925
|
+
);
|
|
909
926
|
}
|
|
910
927
|
}
|
|
911
|
-
var
|
|
912
|
-
class
|
|
928
|
+
var Y = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(Y || {});
|
|
929
|
+
class bt {
|
|
913
930
|
render;
|
|
914
931
|
cache = /* @__PURE__ */ new Map();
|
|
915
932
|
constructor(t) {
|
|
@@ -922,14 +939,14 @@ class At {
|
|
|
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 At {
|
|
|
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).
|
|
@@ -952,7 +969,7 @@ class At {
|
|
|
952
969
|
* @returns The newly created RenderTexture.
|
|
953
970
|
*/
|
|
954
971
|
createRenderTexture(t) {
|
|
955
|
-
return new
|
|
972
|
+
return new At(this.render, t);
|
|
956
973
|
}
|
|
957
974
|
/**
|
|
958
975
|
* Creates a TextTexture for rendering text.
|
|
@@ -960,7 +977,7 @@ class At {
|
|
|
960
977
|
* @returns The newly created TextTexture.
|
|
961
978
|
*/
|
|
962
979
|
createTextTexture(t) {
|
|
963
|
-
return new
|
|
980
|
+
return new _t(this.render, t);
|
|
964
981
|
}
|
|
965
982
|
/**
|
|
966
983
|
* Destroys a texture and potentially removes its BaseTexture from the cache.
|
|
@@ -970,8 +987,8 @@ class At {
|
|
|
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,20 +999,20 @@ class At {
|
|
|
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
|
}
|
|
991
|
-
class
|
|
1008
|
+
class k {
|
|
992
1009
|
glTexture = null;
|
|
993
1010
|
width;
|
|
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 G {
|
|
|
1004
1021
|
* @param options - Optional configuration.
|
|
1005
1022
|
* @returns The created BaseTexture.
|
|
1006
1023
|
*/
|
|
1007
|
-
static fromSource(t, e,
|
|
1008
|
-
const
|
|
1009
|
-
return new
|
|
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,20 +1031,20 @@ class G {
|
|
|
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.
|
|
1022
1039
|
*/
|
|
1023
1040
|
setFilterMode(t, e) {
|
|
1024
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1041
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), tt(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1025
1042
|
}
|
|
1026
1043
|
/**
|
|
1027
1044
|
* Dynamically updates the texture wrap mode.
|
|
1028
1045
|
*/
|
|
1029
1046
|
setWrapMode(t, e) {
|
|
1030
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
1047
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), J(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
1031
1048
|
}
|
|
1032
1049
|
/**
|
|
1033
1050
|
* Destroys the WebGL texture resource.
|
|
@@ -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
|
|
1124
|
-
a.push(this.getSubTexture(
|
|
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
|
|
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.
|
|
@@ -1140,7 +1157,7 @@ class P {
|
|
|
1140
1157
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
1141
1158
|
}
|
|
1142
1159
|
}
|
|
1143
|
-
class
|
|
1160
|
+
class At extends P {
|
|
1144
1161
|
framebuffer;
|
|
1145
1162
|
renderbuffer;
|
|
1146
1163
|
gl;
|
|
@@ -1150,11 +1167,11 @@ class Ut 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
|
|
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 Ut 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 Ut 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 Ut 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 Ut 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.
|
|
@@ -1230,7 +1247,7 @@ class Ut extends P {
|
|
|
1230
1247
|
super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
|
|
1231
1248
|
}
|
|
1232
1249
|
}
|
|
1233
|
-
const
|
|
1250
|
+
const Ut = {
|
|
1234
1251
|
fontFamily: "Arial",
|
|
1235
1252
|
fontSize: 24,
|
|
1236
1253
|
fontWeight: "normal",
|
|
@@ -1239,7 +1256,7 @@ const _t = {
|
|
|
1239
1256
|
align: "left",
|
|
1240
1257
|
baseline: "top"
|
|
1241
1258
|
};
|
|
1242
|
-
class
|
|
1259
|
+
class _t extends P {
|
|
1243
1260
|
canvas;
|
|
1244
1261
|
ctx;
|
|
1245
1262
|
render;
|
|
@@ -1248,12 +1265,12 @@ class Ct extends P {
|
|
|
1248
1265
|
options;
|
|
1249
1266
|
flipY = !0;
|
|
1250
1267
|
constructor(t, e) {
|
|
1251
|
-
super(), this.render = t, this._style = { ...
|
|
1252
|
-
const
|
|
1253
|
-
if (!
|
|
1254
|
-
this.ctx =
|
|
1255
|
-
const
|
|
1256
|
-
this.setBase(new
|
|
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");
|
|
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,98 +1318,98 @@ class Ct 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 b = t.measureText(
|
|
1313
|
-
b.width > h && (h = b.width),
|
|
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 b =
|
|
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
|
-
const
|
|
1327
|
-
const
|
|
1328
|
-
if (!
|
|
1343
|
+
const Ct = (s, t = !1, e = !0) => {
|
|
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
|
|
1331
|
-
},
|
|
1332
|
-
const
|
|
1333
|
-
if (!
|
|
1347
|
+
return r;
|
|
1348
|
+
}, ht = (s, t, e) => {
|
|
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
|
|
1340
|
-
},
|
|
1341
|
-
var
|
|
1342
|
-
if (!
|
|
1356
|
+
return r;
|
|
1357
|
+
}, Pt = (s, t, e) => {
|
|
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
|
-
function
|
|
1367
|
+
function J(s, t) {
|
|
1351
1368
|
const e = {
|
|
1352
|
-
[
|
|
1353
|
-
[
|
|
1354
|
-
[
|
|
1369
|
+
[Y.CLAMP]: s.CLAMP_TO_EDGE,
|
|
1370
|
+
[Y.REPEAT]: s.REPEAT,
|
|
1371
|
+
[Y.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
|
|
1355
1372
|
}[t] || s.CLAMP_TO_EDGE;
|
|
1356
1373
|
s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, e);
|
|
1357
1374
|
}
|
|
1358
|
-
function
|
|
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
|
-
function
|
|
1366
|
-
const
|
|
1367
|
-
if (!
|
|
1382
|
+
function K(s, t, e) {
|
|
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
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;
|
|
1386
1403
|
}
|
|
1387
|
-
const
|
|
1388
|
-
function
|
|
1404
|
+
const Nt = 5126, et = 5121;
|
|
1405
|
+
function Lt(s, t, e) {
|
|
1389
1406
|
s.vertexAttribDivisor(t, e);
|
|
1390
1407
|
}
|
|
1391
|
-
function
|
|
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
|
-
class
|
|
1412
|
+
class Tt {
|
|
1396
1413
|
program;
|
|
1397
1414
|
attributeLoc = {};
|
|
1398
1415
|
uniformLoc = {};
|
|
@@ -1407,8 +1424,8 @@ class yt {
|
|
|
1407
1424
|
shaderId = Ot++;
|
|
1408
1425
|
// for debug
|
|
1409
1426
|
vao;
|
|
1410
|
-
constructor(t, e,
|
|
1411
|
-
this.gl = t, this.program =
|
|
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 yt {
|
|
|
1431
1448
|
* shader.setUniform("uMVP", mat4array);
|
|
1432
1449
|
*/
|
|
1433
1450
|
setUniform(t, e) {
|
|
1434
|
-
const
|
|
1435
|
-
if (
|
|
1436
|
-
const
|
|
1437
|
-
|
|
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 yt {
|
|
|
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
|
-
t.type ??
|
|
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,79 +1496,79 @@ class yt {
|
|
|
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
|
|
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
|
|
1549
|
+
return Wt(s, t, r);
|
|
1533
1550
|
}
|
|
1534
1551
|
}
|
|
1535
|
-
function
|
|
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
|
-
class
|
|
1571
|
+
class ot {
|
|
1555
1572
|
/** Custom vertex shader code */
|
|
1556
1573
|
vs;
|
|
1557
1574
|
/** Custom fragment shader code */
|
|
@@ -1569,8 +1586,8 @@ class ut {
|
|
|
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 ut {
|
|
|
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 ut {
|
|
|
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,18 +1630,17 @@ class ut {
|
|
|
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
|
}
|
|
1626
|
-
|
|
1627
|
-
class Rt {
|
|
1643
|
+
class yt {
|
|
1628
1644
|
constructor(t) {
|
|
1629
1645
|
this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
|
|
1630
1646
|
}
|
|
@@ -1654,20 +1670,20 @@ class Rt {
|
|
|
1654
1670
|
(t, e) => e
|
|
1655
1671
|
);
|
|
1656
1672
|
}
|
|
1657
|
-
findTextureUnit(t, e = 0,
|
|
1658
|
-
for (let
|
|
1659
|
-
const n =
|
|
1660
|
-
if (this.usedTextures[
|
|
1661
|
-
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;
|
|
1662
1678
|
}
|
|
1663
1679
|
return -1;
|
|
1664
1680
|
}
|
|
1665
|
-
useTexture(t, e = 0,
|
|
1666
|
-
const
|
|
1667
|
-
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;
|
|
1668
1684
|
}
|
|
1669
1685
|
createShader(t, e) {
|
|
1670
|
-
return new
|
|
1686
|
+
return new Tt(this.gl, t, e);
|
|
1671
1687
|
}
|
|
1672
1688
|
createCustomShader(t) {
|
|
1673
1689
|
return t.getGLShader(this, this.KEY, this.vs, this.fs);
|
|
@@ -1675,7 +1691,7 @@ class Rt {
|
|
|
1675
1691
|
getCustomShader(t) {
|
|
1676
1692
|
if (!t)
|
|
1677
1693
|
return this.defaultShader;
|
|
1678
|
-
if (t instanceof
|
|
1694
|
+
if (t instanceof ot) {
|
|
1679
1695
|
const e = this.createCustomShader(t);
|
|
1680
1696
|
return e ?? this.defaultShader;
|
|
1681
1697
|
}
|
|
@@ -1690,7 +1706,7 @@ class Rt {
|
|
|
1690
1706
|
return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
|
|
1691
1707
|
}
|
|
1692
1708
|
enter(t) {
|
|
1693
|
-
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof
|
|
1709
|
+
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ot ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
|
|
1694
1710
|
}
|
|
1695
1711
|
exit() {
|
|
1696
1712
|
this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
|
|
@@ -1699,22 +1715,25 @@ class Rt {
|
|
|
1699
1715
|
this.render(), this.resetRender();
|
|
1700
1716
|
}
|
|
1701
1717
|
render() {
|
|
1718
|
+
this.prepareRender();
|
|
1719
|
+
}
|
|
1720
|
+
prepareRender() {
|
|
1702
1721
|
const t = this.currentShader;
|
|
1703
1722
|
if (t.use(), this.customShader) {
|
|
1704
|
-
const
|
|
1705
|
-
for (const n in
|
|
1706
|
-
|
|
1707
|
-
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);
|
|
1708
1727
|
}
|
|
1709
1728
|
const e = this.gl;
|
|
1710
|
-
for (let
|
|
1711
|
-
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]);
|
|
1712
1731
|
t.setUniform("uTextures", Int32Array.from(
|
|
1713
1732
|
{ length: this.usedTextures.length },
|
|
1714
|
-
(
|
|
1733
|
+
(r, i) => i
|
|
1715
1734
|
)), t.setUniform("uPadding", Float32Array.from(
|
|
1716
1735
|
{ length: this.usedTexturePadding.length },
|
|
1717
|
-
(
|
|
1736
|
+
(r, i) => this.usedTexturePadding[i]
|
|
1718
1737
|
));
|
|
1719
1738
|
}
|
|
1720
1739
|
resetRender() {
|
|
@@ -1724,8 +1743,8 @@ class Rt {
|
|
|
1724
1743
|
return !1;
|
|
1725
1744
|
}
|
|
1726
1745
|
}
|
|
1727
|
-
const
|
|
1728
|
-
precision
|
|
1746
|
+
const $ = `#version 300 es\r
|
|
1747
|
+
precision highp float;\r
|
|
1729
1748
|
\r
|
|
1730
1749
|
// per-vertex\r
|
|
1731
1750
|
in vec2 aVertex;\r
|
|
@@ -1772,7 +1791,7 @@ void main(void) {\r
|
|
|
1772
1791
|
\r
|
|
1773
1792
|
gl_Position = u_projection * position;\r
|
|
1774
1793
|
}\r
|
|
1775
|
-
`,
|
|
1794
|
+
`, ct = `#version 300 es\r
|
|
1776
1795
|
precision mediump float;\r
|
|
1777
1796
|
\r
|
|
1778
1797
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -1812,7 +1831,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
|
|
|
1812
1831
|
// CUSTOM_CODE\r
|
|
1813
1832
|
\r
|
|
1814
1833
|
void main(void) {\r
|
|
1815
|
-
fragColor = sampleTexture(vRegion);\r
|
|
1834
|
+
fragColor = sampleTexture(vRegion) * vColor;\r
|
|
1816
1835
|
// if (vPadding.x != 0.0) {\r
|
|
1817
1836
|
// if (clampUV(vRegion)) {\r
|
|
1818
1837
|
// fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
|
|
@@ -1821,8 +1840,8 @@ void main(void) {\r
|
|
|
1821
1840
|
\r
|
|
1822
1841
|
// CUSTOM_CODE_CALL\r
|
|
1823
1842
|
}\r
|
|
1824
|
-
`,
|
|
1825
|
-
class
|
|
1843
|
+
`, V = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
1844
|
+
class it extends yt {
|
|
1826
1845
|
instanceBuffer;
|
|
1827
1846
|
quadBuffer;
|
|
1828
1847
|
instanceCount = 0;
|
|
@@ -1834,29 +1853,29 @@ class at extends Rt {
|
|
|
1834
1853
|
}
|
|
1835
1854
|
createBuffer() {
|
|
1836
1855
|
const t = this.gl;
|
|
1837
|
-
this.quadBuffer = new
|
|
1838
|
-
for (const e of
|
|
1839
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new
|
|
1856
|
+
this.quadBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1857
|
+
for (const e of Ft) this.quadBuffer.pushFloat32(e);
|
|
1858
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, I.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1840
1859
|
}
|
|
1841
1860
|
createDefaultShader() {
|
|
1842
|
-
const t = this.rapid, e = F(
|
|
1843
|
-
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;
|
|
1844
1863
|
}
|
|
1845
1864
|
createShader(t, e) {
|
|
1846
|
-
const
|
|
1847
|
-
return
|
|
1848
|
-
{ name: "aMatrixRow0", size: 3, stride:
|
|
1849
|
-
{ name: "aMatrixRow1", size: 3, stride:
|
|
1850
|
-
{ name: "aUVRect", size: 4, stride:
|
|
1851
|
-
{ name: "aColor", size: 4, type:
|
|
1852
|
-
{ name: "aTextureId", size: 1, type:
|
|
1853
|
-
]), this.quadBuffer.bindBuffer(),
|
|
1865
|
+
const r = super.createShader(t, e);
|
|
1866
|
+
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
1867
|
+
{ name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
|
|
1868
|
+
{ name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
|
|
1869
|
+
{ name: "aUVRect", size: 4, stride: V, offset: 24, divisor: 1 },
|
|
1870
|
+
{ name: "aColor", size: 4, type: et, normalized: !0, stride: V, offset: 40, divisor: 1 },
|
|
1871
|
+
{ name: "aTextureId", size: 1, type: et, stride: V, offset: 44, divisor: 1 }
|
|
1872
|
+
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
1854
1873
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1855
|
-
]),
|
|
1874
|
+
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1856
1875
|
}
|
|
1857
1876
|
createCustomShader(t) {
|
|
1858
|
-
const e = F(
|
|
1859
|
-
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);
|
|
1860
1879
|
}
|
|
1861
1880
|
/**
|
|
1862
1881
|
* Draws a textured sprite via instanced rendering to significantly improve performance.
|
|
@@ -1870,46 +1889,45 @@ class at extends Rt {
|
|
|
1870
1889
|
* @param v1 Bottom UV mapped coordinate (default 1).
|
|
1871
1890
|
* @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
|
|
1872
1891
|
*/
|
|
1873
|
-
drawSprite(t, e,
|
|
1874
|
-
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;
|
|
1875
1894
|
this.drawSpriteAffine(
|
|
1876
1895
|
t,
|
|
1877
|
-
x[
|
|
1878
|
-
x[
|
|
1879
|
-
x[
|
|
1880
|
-
x[
|
|
1881
|
-
x[
|
|
1882
|
-
x[
|
|
1883
|
-
i,
|
|
1896
|
+
x[f],
|
|
1897
|
+
x[f + 1],
|
|
1898
|
+
x[f + 2],
|
|
1899
|
+
x[f + 3],
|
|
1900
|
+
x[f + 4],
|
|
1901
|
+
x[f + 5],
|
|
1884
1902
|
r,
|
|
1903
|
+
i,
|
|
1885
1904
|
n,
|
|
1886
1905
|
a,
|
|
1887
|
-
o,
|
|
1888
|
-
h,
|
|
1889
1906
|
c,
|
|
1907
|
+
h,
|
|
1908
|
+
o,
|
|
1890
1909
|
u,
|
|
1891
|
-
|
|
1892
|
-
|
|
1910
|
+
l,
|
|
1911
|
+
d
|
|
1893
1912
|
);
|
|
1894
1913
|
}
|
|
1895
|
-
drawSpriteAffine(t, e,
|
|
1896
|
-
|
|
1897
|
-
const g = t.base, w = t.scale ?? 1, b = t.rawWidth, A = t.rawHeight, I = t.offsetX, Y = t.offsetY, N = this.useTexture(
|
|
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(
|
|
1898
1916
|
t.glTexture,
|
|
1899
|
-
|
|
1900
|
-
x /
|
|
1901
|
-
),
|
|
1902
|
-
|
|
1903
|
-
const
|
|
1904
|
-
T ? (
|
|
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));
|
|
1905
1923
|
const _ = this.worldSpriteMatrix;
|
|
1906
|
-
_[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++;
|
|
1907
1925
|
}
|
|
1908
1926
|
render() {
|
|
1909
1927
|
if (this.instanceCount === 0) return;
|
|
1910
|
-
|
|
1928
|
+
this.prepareRender();
|
|
1911
1929
|
const t = this.gl, e = this.currentShader;
|
|
1912
|
-
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(),
|
|
1930
|
+
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
|
|
1913
1931
|
}
|
|
1914
1932
|
resetRender() {
|
|
1915
1933
|
super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
|
|
@@ -1918,8 +1936,8 @@ class at extends Rt {
|
|
|
1918
1936
|
return this.instanceCount > 0;
|
|
1919
1937
|
}
|
|
1920
1938
|
}
|
|
1921
|
-
const
|
|
1922
|
-
precision
|
|
1939
|
+
const Dt = `#version 300 es\r
|
|
1940
|
+
precision highp float;\r
|
|
1923
1941
|
\r
|
|
1924
1942
|
in vec2 aPosition;\r
|
|
1925
1943
|
in vec4 aColor;\r
|
|
@@ -1949,7 +1967,7 @@ void main(void) {\r
|
|
|
1949
1967
|
// CUSTOM_CODE_CALL\r
|
|
1950
1968
|
gl_Position = u_projection * position;\r
|
|
1951
1969
|
}\r
|
|
1952
|
-
`,
|
|
1970
|
+
`, Bt = `#version 300 es\r
|
|
1953
1971
|
precision mediump float;\r
|
|
1954
1972
|
\r
|
|
1955
1973
|
in vec4 vColor;\r
|
|
@@ -1969,9 +1987,9 @@ bool clampUV(vec2 uv) {\r
|
|
|
1969
1987
|
\r
|
|
1970
1988
|
vec4 sampleTexture(vec2 uv) {\r
|
|
1971
1989
|
if (uUseTexture > 0) {\r
|
|
1972
|
-
return texture(uTexture, uv)
|
|
1990
|
+
return texture(uTexture, uv);\r
|
|
1973
1991
|
}\r
|
|
1974
|
-
return
|
|
1992
|
+
return vec4(1,1,1,1);\r
|
|
1975
1993
|
}\r
|
|
1976
1994
|
\r
|
|
1977
1995
|
vec4 sampleClampTexture(vec2 uv) {\r
|
|
@@ -1992,11 +2010,11 @@ vec4 sampleTextureLocal(vec2 uv) {\r
|
|
|
1992
2010
|
// CUSTOM_CODE\r
|
|
1993
2011
|
\r
|
|
1994
2012
|
void main(void) {\r
|
|
1995
|
-
fragColor = sampleTexture(vRegion);\r
|
|
2013
|
+
fragColor = sampleTexture(vRegion) * vColor;\r
|
|
1996
2014
|
// CUSTOM_CODE_CALL\r
|
|
1997
2015
|
}\r
|
|
1998
|
-
`,
|
|
1999
|
-
precision
|
|
2016
|
+
`, kt = `#version 300 es\r
|
|
2017
|
+
precision highp float;\r
|
|
2000
2018
|
\r
|
|
2001
2019
|
in vec2 aPosition;\r
|
|
2002
2020
|
in vec2 aUV;\r
|
|
@@ -2018,7 +2036,7 @@ void main(void) {\r
|
|
|
2018
2036
|
);\r
|
|
2019
2037
|
gl_Position = u_projection * position;\r
|
|
2020
2038
|
}\r
|
|
2021
|
-
`,
|
|
2039
|
+
`, Gt = `#version 300 es\r
|
|
2022
2040
|
precision mediump float;\r
|
|
2023
2041
|
\r
|
|
2024
2042
|
in vec2 vRegion;\r
|
|
@@ -2038,8 +2056,8 @@ void main(void) {\r
|
|
|
2038
2056
|
discard;\r
|
|
2039
2057
|
}\r
|
|
2040
2058
|
}\r
|
|
2041
|
-
`,
|
|
2042
|
-
class
|
|
2059
|
+
`, z = 20;
|
|
2060
|
+
class Ht extends yt {
|
|
2043
2061
|
vertexBuffer;
|
|
2044
2062
|
vertexCount = 0;
|
|
2045
2063
|
matrixIndex = -1;
|
|
@@ -2052,25 +2070,25 @@ class Vt extends Rt {
|
|
|
2052
2070
|
}
|
|
2053
2071
|
createBuffer() {
|
|
2054
2072
|
const t = this.gl;
|
|
2055
|
-
this.vertexBuffer = new
|
|
2073
|
+
this.vertexBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
|
|
2056
2074
|
}
|
|
2057
2075
|
createDefaultShader() {
|
|
2058
|
-
return this.vs =
|
|
2076
|
+
return this.vs = Dt, this.fs = Bt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
2059
2077
|
}
|
|
2060
2078
|
createMaskShader(t, e) {
|
|
2061
|
-
const
|
|
2062
|
-
return
|
|
2063
|
-
{ name: "aPosition", size: 2, type:
|
|
2064
|
-
{ name: "aUV", size: 2, type:
|
|
2065
|
-
]),
|
|
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;
|
|
2066
2084
|
}
|
|
2067
2085
|
createShader(t, e) {
|
|
2068
|
-
const
|
|
2069
|
-
return
|
|
2070
|
-
{ name: "aPosition", size: 2, type:
|
|
2071
|
-
{ name: "aColor", size: 4, type:
|
|
2072
|
-
{ name: "aUV", size: 2, type:
|
|
2073
|
-
]),
|
|
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;
|
|
2074
2092
|
}
|
|
2075
2093
|
/**
|
|
2076
2094
|
* Begins a new polygon drawing sequence. Must be followed by addVertex() calls and endGraphic().
|
|
@@ -2078,8 +2096,8 @@ class Vt extends Rt {
|
|
|
2078
2096
|
* @param drawMode The WebGL drawing primitive mode (e.g., gl.TRIANGLES).
|
|
2079
2097
|
* @param texture Optional texture to apply over the polygon.
|
|
2080
2098
|
*/
|
|
2081
|
-
startGraphic(t, e = this.gl.TRIANGLES,
|
|
2082
|
-
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);
|
|
2083
2101
|
}
|
|
2084
2102
|
/**
|
|
2085
2103
|
* Adds a vertex to the current polygon. Local coordinates and color settings.
|
|
@@ -2089,9 +2107,9 @@ class Vt extends Rt {
|
|
|
2089
2107
|
* @param v UV mapped Y value (0-1, default 0).
|
|
2090
2108
|
* @param color Pre-multiplied hex color combined using ABGR byte order (default 0xFFFFFFFF).
|
|
2091
2109
|
*/
|
|
2092
|
-
addVertex(t, e,
|
|
2110
|
+
addVertex(t, e, r = 0, i = 0, n = 4294967295) {
|
|
2093
2111
|
const a = this.vertexBuffer;
|
|
2094
|
-
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();
|
|
2095
2113
|
}
|
|
2096
2114
|
/**
|
|
2097
2115
|
* Finishes the graphic construction and dispatches the rendering call immediately.
|
|
@@ -2101,10 +2119,10 @@ class Vt extends Rt {
|
|
|
2101
2119
|
}
|
|
2102
2120
|
render() {
|
|
2103
2121
|
if (this.vertexCount === 0) return;
|
|
2104
|
-
|
|
2105
|
-
const t = this.gl, e = this.currentShader,
|
|
2106
|
-
let n = r
|
|
2107
|
-
this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [r
|
|
2122
|
+
this.prepareRender();
|
|
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(
|
|
2108
2126
|
"uUVRect",
|
|
2109
2127
|
this.texture ? [this.texture.uvX, this.texture.uvY, this.texture.uvW, this.texture.uvH] : [0, 0, 1, 1]
|
|
2110
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;
|
|
@@ -2113,15 +2131,15 @@ class Vt extends Rt {
|
|
|
2113
2131
|
return !1;
|
|
2114
2132
|
}
|
|
2115
2133
|
}
|
|
2116
|
-
class
|
|
2134
|
+
class m {
|
|
2117
2135
|
x;
|
|
2118
2136
|
y;
|
|
2119
|
-
static ZERO = new
|
|
2120
|
-
static ONE = new
|
|
2121
|
-
static UP = new
|
|
2122
|
-
static DOWN = new
|
|
2123
|
-
static LEFT = new
|
|
2124
|
-
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);
|
|
2125
2143
|
constructor(t, e) {
|
|
2126
2144
|
this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
|
|
2127
2145
|
}
|
|
@@ -2129,22 +2147,22 @@ class d {
|
|
|
2129
2147
|
return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
|
|
2130
2148
|
}
|
|
2131
2149
|
add(t) {
|
|
2132
|
-
return new
|
|
2150
|
+
return new m(this.x + t.x, this.y + t.y);
|
|
2133
2151
|
}
|
|
2134
2152
|
subtract(t) {
|
|
2135
|
-
return new
|
|
2153
|
+
return new m(this.x - t.x, this.y - t.y);
|
|
2136
2154
|
}
|
|
2137
2155
|
sub(t) {
|
|
2138
|
-
return new
|
|
2156
|
+
return new m(this.x - t.x, this.y - t.y);
|
|
2139
2157
|
}
|
|
2140
2158
|
multiply(t) {
|
|
2141
|
-
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);
|
|
2142
2160
|
}
|
|
2143
2161
|
mul(t) {
|
|
2144
2162
|
return this.multiply(t);
|
|
2145
2163
|
}
|
|
2146
2164
|
divide(t) {
|
|
2147
|
-
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);
|
|
2148
2166
|
}
|
|
2149
2167
|
dot(t) {
|
|
2150
2168
|
return this.x * t.x + this.y * t.y;
|
|
@@ -2153,17 +2171,17 @@ class d {
|
|
|
2153
2171
|
return this.x * t.y - this.y * t.x;
|
|
2154
2172
|
}
|
|
2155
2173
|
distanceTo(t) {
|
|
2156
|
-
const e = this.x - t.x,
|
|
2157
|
-
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);
|
|
2158
2176
|
}
|
|
2159
2177
|
clone() {
|
|
2160
|
-
return new
|
|
2178
|
+
return new m(this.x, this.y);
|
|
2161
2179
|
}
|
|
2162
2180
|
to(t) {
|
|
2163
2181
|
this.x = t.x, this.y = t.y;
|
|
2164
2182
|
}
|
|
2165
2183
|
copy() {
|
|
2166
|
-
return new
|
|
2184
|
+
return new m(this.x, this.y);
|
|
2167
2185
|
}
|
|
2168
2186
|
equals(t) {
|
|
2169
2187
|
return t.x == this.x && t.y == this.y;
|
|
@@ -2176,7 +2194,7 @@ class d {
|
|
|
2176
2194
|
return this.x = -this.x, this.y = -this.y, this;
|
|
2177
2195
|
}
|
|
2178
2196
|
inverted() {
|
|
2179
|
-
return new
|
|
2197
|
+
return new m(this.x * -1, this.y * -1);
|
|
2180
2198
|
}
|
|
2181
2199
|
length() {
|
|
2182
2200
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
@@ -2190,13 +2208,13 @@ class d {
|
|
|
2190
2208
|
}
|
|
2191
2209
|
normalized() {
|
|
2192
2210
|
const t = this.length();
|
|
2193
|
-
return new
|
|
2211
|
+
return new m(this.x / t || 0, this.y / t || 0);
|
|
2194
2212
|
}
|
|
2195
2213
|
fix(t = 1e-13) {
|
|
2196
2214
|
this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
|
|
2197
2215
|
}
|
|
2198
2216
|
fixed(t = 1e-13) {
|
|
2199
|
-
return new
|
|
2217
|
+
return new m(
|
|
2200
2218
|
Math.abs(this.x) < t ? 0 : this.x,
|
|
2201
2219
|
Math.abs(this.y) < t ? 0 : this.y
|
|
2202
2220
|
);
|
|
@@ -2205,13 +2223,13 @@ class d {
|
|
|
2205
2223
|
return Math.atan2(this.y, this.x);
|
|
2206
2224
|
}
|
|
2207
2225
|
abs() {
|
|
2208
|
-
return new
|
|
2226
|
+
return new m(Math.abs(this.x), Math.abs(this.y));
|
|
2209
2227
|
}
|
|
2210
2228
|
floor() {
|
|
2211
|
-
return new
|
|
2229
|
+
return new m(Math.floor(this.x), Math.floor(this.y));
|
|
2212
2230
|
}
|
|
2213
2231
|
ceil() {
|
|
2214
|
-
return new
|
|
2232
|
+
return new m(Math.ceil(this.x), Math.ceil(this.y));
|
|
2215
2233
|
}
|
|
2216
2234
|
stringify() {
|
|
2217
2235
|
return `Vec2(${this.x}, ${this.y})`;
|
|
@@ -2232,24 +2250,24 @@ class d {
|
|
|
2232
2250
|
return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
|
|
2233
2251
|
}
|
|
2234
2252
|
static FromArray(t) {
|
|
2235
|
-
return t.map((e) => new
|
|
2253
|
+
return t.map((e) => new m(e[0], e[1]));
|
|
2236
2254
|
}
|
|
2237
2255
|
static fromAngle(t) {
|
|
2238
|
-
return new
|
|
2256
|
+
return new m(Math.cos(t), Math.sin(t));
|
|
2239
2257
|
}
|
|
2240
2258
|
}
|
|
2241
|
-
const
|
|
2242
|
-
const [e,
|
|
2259
|
+
const Vt = (s, t) => {
|
|
2260
|
+
const [e, r, i, n, a, c] = t, h = new Float32Array([
|
|
2243
2261
|
e,
|
|
2244
2262
|
n,
|
|
2245
2263
|
0,
|
|
2246
2264
|
0,
|
|
2247
|
-
|
|
2265
|
+
r,
|
|
2248
2266
|
a,
|
|
2249
2267
|
0,
|
|
2250
2268
|
0,
|
|
2251
|
-
|
|
2252
|
-
|
|
2269
|
+
i,
|
|
2270
|
+
c,
|
|
2253
2271
|
1,
|
|
2254
2272
|
0,
|
|
2255
2273
|
0,
|
|
@@ -2260,230 +2278,220 @@ const Yt = (s, t) => {
|
|
|
2260
2278
|
return zt(s, h);
|
|
2261
2279
|
}, zt = (s, t) => {
|
|
2262
2280
|
const e = new Float32Array(16);
|
|
2263
|
-
for (let
|
|
2264
|
-
for (let
|
|
2281
|
+
for (let r = 0; r < 4; r++)
|
|
2282
|
+
for (let i = 0; i < 4; i++) {
|
|
2265
2283
|
let n = 0;
|
|
2266
2284
|
for (let a = 0; a < 4; a++)
|
|
2267
|
-
n += s[
|
|
2268
|
-
e[
|
|
2285
|
+
n += s[i * 4 + a] * t[a * 4 + r];
|
|
2286
|
+
e[i * 4 + r] = n;
|
|
2269
2287
|
}
|
|
2270
2288
|
return e;
|
|
2271
2289
|
};
|
|
2272
|
-
var
|
|
2273
|
-
const
|
|
2274
|
-
const a = [],
|
|
2275
|
-
for (let
|
|
2276
|
-
const
|
|
2277
|
-
a.push(s),
|
|
2278
|
-
}
|
|
2279
|
-
return { vertices: a, uv:
|
|
2280
|
-
},
|
|
2290
|
+
var Yt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Yt || {});
|
|
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));
|
|
2296
|
+
}
|
|
2297
|
+
return { vertices: a, uv: c };
|
|
2298
|
+
}, Xt = (s, t = !1) => {
|
|
2281
2299
|
const e = [];
|
|
2282
2300
|
if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
|
|
2283
|
-
const
|
|
2301
|
+
const r = 4, i = 1e-3, n = s.length;
|
|
2284
2302
|
let a = 0;
|
|
2285
2303
|
if (t)
|
|
2286
2304
|
for (let h = 0; h < n; h++) {
|
|
2287
|
-
const
|
|
2288
|
-
a +=
|
|
2305
|
+
const o = s[h], u = s[(h + 1) % n];
|
|
2306
|
+
a += o.distanceTo(u);
|
|
2289
2307
|
}
|
|
2290
2308
|
else
|
|
2291
2309
|
for (let h = 0; h < n - 1; h++)
|
|
2292
2310
|
a += s[h].distanceTo(s[h + 1]);
|
|
2293
|
-
const
|
|
2294
|
-
const
|
|
2295
|
-
if (
|
|
2296
|
-
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 };
|
|
2297
2315
|
{
|
|
2298
|
-
let x =
|
|
2299
|
-
|
|
2300
|
-
let
|
|
2301
|
-
return { normal: x, miters: Math.min(
|
|
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) };
|
|
2302
2320
|
}
|
|
2303
2321
|
};
|
|
2304
2322
|
if (t)
|
|
2305
2323
|
for (let h = 0; h < n; h++) {
|
|
2306
|
-
const
|
|
2307
|
-
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));
|
|
2308
2326
|
}
|
|
2309
2327
|
else
|
|
2310
2328
|
for (let h = 0; h < n; h++)
|
|
2311
2329
|
if (h === 0) {
|
|
2312
|
-
const
|
|
2313
|
-
e.push({ normal:
|
|
2330
|
+
const o = s[1].subtract(s[0]).normalize();
|
|
2331
|
+
e.push({ normal: o.perpendicular(), miters: 1 });
|
|
2314
2332
|
} else if (h === n - 1) {
|
|
2315
|
-
const
|
|
2316
|
-
e.push({ normal:
|
|
2333
|
+
const o = s[h].subtract(s[h - 1]).normalize();
|
|
2334
|
+
e.push({ normal: o.perpendicular(), miters: 1 });
|
|
2317
2335
|
} else
|
|
2318
|
-
e.push(
|
|
2336
|
+
e.push(c(s[h - 1], s[h], s[h + 1]));
|
|
2319
2337
|
return { normals: e, length: a };
|
|
2320
2338
|
}, jt = (s) => {
|
|
2321
2339
|
const t = s.points;
|
|
2322
2340
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
2323
|
-
const { normals: e, length:
|
|
2324
|
-
let
|
|
2325
|
-
const u = s.texture?.rawWidth || 1,
|
|
2326
|
-
for (let
|
|
2327
|
-
const
|
|
2328
|
-
let
|
|
2329
|
-
h === 0 ? (
|
|
2330
|
-
const
|
|
2331
|
-
n.push(b), a.push(
|
|
2332
|
-
}
|
|
2333
|
-
if (
|
|
2334
|
-
const
|
|
2335
|
-
n.push(...
|
|
2336
|
-
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);
|
|
2353
|
+
n.push(...g.vertices), a.push(...g.uv);
|
|
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);
|
|
2337
2355
|
n.push(...b.vertices), a.push(...b.uv);
|
|
2338
2356
|
}
|
|
2339
2357
|
return { vertices: n, uv: a };
|
|
2340
|
-
},
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
if (!e?.base || s.inCreateMask)
|
|
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
|
+
);
|
|
2350
2367
|
return;
|
|
2351
|
-
|
|
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)
|
|
2380
|
+
return;
|
|
2381
|
+
const i = r.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
|
|
2352
2382
|
s.enterRegion(i, t.shader);
|
|
2353
|
-
let
|
|
2354
|
-
const
|
|
2355
|
-
let
|
|
2356
|
-
|
|
2357
|
-
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;
|
|
2358
2388
|
i.drawSprite(
|
|
2359
|
-
e,
|
|
2360
|
-
t.customMatrix ?? s.matrixStack.curWorldM,
|
|
2361
2389
|
r,
|
|
2390
|
+
e ?? t.customMatrix ?? s.matrixStack.curWorldM,
|
|
2362
2391
|
n,
|
|
2363
2392
|
a,
|
|
2364
|
-
o,
|
|
2365
|
-
J(s, t.color),
|
|
2366
|
-
f,
|
|
2367
|
-
l,
|
|
2368
|
-
h,
|
|
2369
2393
|
c,
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
Et(s, t);
|
|
2375
|
-
});
|
|
2376
|
-
}, Zt = (s, t) => {
|
|
2377
|
-
const e = s.particleRegion;
|
|
2378
|
-
s.enterRegion(e, t.shader);
|
|
2379
|
-
const i = t.texture, r = i.uvX, n = i.uvY, a = i.uvW, o = i.uvH;
|
|
2380
|
-
e.drawParticle(
|
|
2381
|
-
i,
|
|
2382
|
-
t.x,
|
|
2383
|
-
t.y,
|
|
2384
|
-
t.scaleX,
|
|
2385
|
-
t.scaleY,
|
|
2386
|
-
t.rotation,
|
|
2387
|
-
r,
|
|
2388
|
-
n,
|
|
2389
|
-
a,
|
|
2394
|
+
h,
|
|
2395
|
+
st(s, t.color),
|
|
2396
|
+
d,
|
|
2397
|
+
f,
|
|
2390
2398
|
o,
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
t.flipY,
|
|
2394
|
-
t.isRotated,
|
|
2395
|
-
t.originX,
|
|
2396
|
-
t.originY
|
|
2399
|
+
u,
|
|
2400
|
+
r.isRotated
|
|
2397
2401
|
);
|
|
2398
|
-
},
|
|
2402
|
+
}, Kt = (s, t) => {
|
|
2403
|
+
const e = X(s, t, t.texture.rawWidth, t.texture.rawHeight);
|
|
2404
|
+
Rt(s, t, e);
|
|
2405
|
+
}, qt = (s, t) => {
|
|
2399
2406
|
const e = s.particleRegion;
|
|
2400
2407
|
s.enterRegion(e, t.shader);
|
|
2401
|
-
const
|
|
2408
|
+
const r = t.texture, i = t.count ?? t.x.length, n = t.color, a = n.length, c = new Array(a);
|
|
2402
2409
|
if (s.premultipliedAlpha)
|
|
2403
2410
|
for (let h = 0; h < a; h++)
|
|
2404
|
-
|
|
2411
|
+
c[h] = n[h].premultipliedUint32;
|
|
2405
2412
|
else
|
|
2406
2413
|
for (let h = 0; h < a; h++)
|
|
2407
|
-
|
|
2414
|
+
c[h] = n[h].uint32;
|
|
2408
2415
|
e.drawParticles(
|
|
2409
|
-
|
|
2416
|
+
r,
|
|
2410
2417
|
t.x,
|
|
2411
2418
|
t.y,
|
|
2412
2419
|
t.rotation,
|
|
2413
|
-
|
|
2414
|
-
|
|
2420
|
+
c,
|
|
2421
|
+
i,
|
|
2415
2422
|
t.scaleX,
|
|
2416
2423
|
t.scaleY,
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2424
|
+
r.uvX,
|
|
2425
|
+
r.uvY,
|
|
2426
|
+
r.uvW,
|
|
2427
|
+
r.uvH,
|
|
2421
2428
|
t.flipX,
|
|
2422
2429
|
t.flipY,
|
|
2423
2430
|
t.isRotated,
|
|
2424
2431
|
t.originX,
|
|
2425
2432
|
t.originY
|
|
2426
2433
|
);
|
|
2427
|
-
},
|
|
2428
|
-
t.points.length
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
+
}, Et = (s, t) => {
|
|
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)
|
|
2434
2451
|
);
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
i.x,
|
|
2439
|
-
i.y,
|
|
2440
|
-
r?.x ?? 0,
|
|
2441
|
-
r?.y ?? 0,
|
|
2442
|
-
J(s, n)
|
|
2443
|
-
);
|
|
2444
|
-
}
|
|
2445
|
-
s.endGraphic();
|
|
2446
|
-
});
|
|
2447
|
-
}, Jt = (s, t) => {
|
|
2452
|
+
}
|
|
2453
|
+
s.endGraphic();
|
|
2454
|
+
}, Zt = (s, t) => {
|
|
2448
2455
|
if (s.inCreateMask)
|
|
2449
2456
|
return;
|
|
2450
|
-
const { vertices: e, uv:
|
|
2451
|
-
|
|
2457
|
+
const { vertices: e, uv: r } = jt(t);
|
|
2458
|
+
Et(s, {
|
|
2452
2459
|
...t,
|
|
2453
2460
|
points: e,
|
|
2454
|
-
uv:
|
|
2461
|
+
uv: r,
|
|
2455
2462
|
drawMode: s.gl.TRIANGLES
|
|
2456
2463
|
});
|
|
2464
|
+
}, Qt = (s, t) => {
|
|
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();
|
|
2476
|
+
}, Jt = (s, t) => {
|
|
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();
|
|
2457
2484
|
}, te = (s, t) => {
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
s.gl.TRIANGLE_FAN,
|
|
2469
|
-
t.texture,
|
|
2470
|
-
t.shader,
|
|
2471
|
-
t.customMatrix
|
|
2472
|
-
), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
|
|
2473
|
-
});
|
|
2474
|
-
}, ie = (s, t) => {
|
|
2475
|
-
const e = t.segments ?? 32;
|
|
2476
|
-
j(s, t, 0, 0, () => {
|
|
2477
|
-
s.startGraphic(
|
|
2478
|
-
s.gl.TRIANGLE_FAN,
|
|
2479
|
-
void 0,
|
|
2480
|
-
t.shader,
|
|
2481
|
-
t.customMatrix
|
|
2482
|
-
);
|
|
2483
|
-
const i = J(s, t.color);
|
|
2484
|
-
s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
|
|
2485
|
-
});
|
|
2486
|
-
}, ft = `#version 300 es\r
|
|
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();
|
|
2494
|
+
}, lt = `#version 300 es\r
|
|
2487
2495
|
precision mediump float;\r
|
|
2488
2496
|
\r
|
|
2489
2497
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -2523,7 +2531,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
|
|
|
2523
2531
|
// CUSTOM_CODE\r
|
|
2524
2532
|
\r
|
|
2525
2533
|
void main(void) {\r
|
|
2526
|
-
fragColor = sampleClampTexture(vRegion);\r
|
|
2534
|
+
fragColor = sampleClampTexture(vRegion) * vColor;\r
|
|
2527
2535
|
// if (vPadding.x != 0.0) {\r
|
|
2528
2536
|
// if (clampUV(vRegion)) {\r
|
|
2529
2537
|
// fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
|
|
@@ -2533,31 +2541,31 @@ void main(void) {\r
|
|
|
2533
2541
|
// CUSTOM_CODE_CALL\r
|
|
2534
2542
|
}\r
|
|
2535
2543
|
`;
|
|
2536
|
-
class
|
|
2544
|
+
class ee extends it {
|
|
2537
2545
|
KEY = "AtlasSprite";
|
|
2538
2546
|
constructor(t) {
|
|
2539
2547
|
super(t);
|
|
2540
2548
|
}
|
|
2541
2549
|
createCustomShader(t) {
|
|
2542
|
-
const e = F(
|
|
2543
|
-
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);
|
|
2544
2552
|
}
|
|
2545
2553
|
createDefaultShader() {
|
|
2546
|
-
const t = this.rapid, e = F(
|
|
2547
|
-
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;
|
|
2548
2556
|
}
|
|
2549
2557
|
}
|
|
2550
|
-
const
|
|
2551
|
-
precision
|
|
2558
|
+
const dt = `#version 300 es\r
|
|
2559
|
+
precision highp float;\r
|
|
2552
2560
|
\r
|
|
2553
2561
|
// per-vertex\r
|
|
2554
2562
|
in vec2 aVertex;\r
|
|
2555
2563
|
\r
|
|
2556
2564
|
// per-instance: 变换\r
|
|
2557
2565
|
in vec2 aPosition;\r
|
|
2558
|
-
in vec2 aScale
|
|
2559
|
-
in float aRotation
|
|
2560
|
-
in vec2 aOrigin
|
|
2566
|
+
in vec2 aScale;\r
|
|
2567
|
+
in float aRotation;\r
|
|
2568
|
+
in vec2 aOrigin;\r
|
|
2561
2569
|
\r
|
|
2562
2570
|
// per-instance:UV 区域 (u0, v0, u1, v1)\r
|
|
2563
2571
|
in vec4 aUVRect;\r
|
|
@@ -2577,7 +2585,7 @@ void main(void) {\r
|
|
|
2577
2585
|
vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
|
|
2578
2586
|
// CUSTOM_CODE_CALL\r
|
|
2579
2587
|
\r
|
|
2580
|
-
vec2 scaled = (aVertex - aOrigin) * aScale
|
|
2588
|
+
vec2 scaled = (aVertex - aOrigin) * aScale;\r
|
|
2581
2589
|
float c = cos(aRotation);\r
|
|
2582
2590
|
float s = sin(aRotation);\r
|
|
2583
2591
|
\r
|
|
@@ -2588,7 +2596,7 @@ void main(void) {\r
|
|
|
2588
2596
|
\r
|
|
2589
2597
|
gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
|
|
2590
2598
|
}\r
|
|
2591
|
-
`,
|
|
2599
|
+
`, ft = `#version 300 es\r
|
|
2592
2600
|
precision mediump float;\r
|
|
2593
2601
|
\r
|
|
2594
2602
|
uniform sampler2D uTexture;\r
|
|
@@ -2604,73 +2612,66 @@ void main(void) {\r
|
|
|
2604
2612
|
\r
|
|
2605
2613
|
// CUSTOM_CODE_CALL\r
|
|
2606
2614
|
}\r
|
|
2607
|
-
`,
|
|
2608
|
-
class
|
|
2615
|
+
`, D = 48, mt = D / 4;
|
|
2616
|
+
class re extends it {
|
|
2609
2617
|
KEY = "ParticleSprite";
|
|
2610
2618
|
texture;
|
|
2611
2619
|
constructor(t) {
|
|
2612
2620
|
super(t);
|
|
2613
2621
|
}
|
|
2614
2622
|
createCustomShader(t) {
|
|
2615
|
-
return t.getGLShader(this, this.KEY,
|
|
2623
|
+
return t.getGLShader(this, this.KEY, dt, ft);
|
|
2616
2624
|
}
|
|
2617
2625
|
createDefaultShader() {
|
|
2618
|
-
const t =
|
|
2626
|
+
const t = ft, e = dt;
|
|
2619
2627
|
return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
|
|
2620
2628
|
}
|
|
2621
2629
|
enter(t) {
|
|
2622
2630
|
super.enter(t), this.currentShader.setUniform("u_projection", this.rapid.projection);
|
|
2623
2631
|
}
|
|
2624
2632
|
createShader(t, e) {
|
|
2625
|
-
const
|
|
2626
|
-
return
|
|
2627
|
-
{ name: "aPosition", size: 2, stride:
|
|
2628
|
-
{ name: "aScale", size: 2, stride:
|
|
2629
|
-
{ name: "aRotation", size: 1, stride:
|
|
2630
|
-
{ name: "aUVRect", size: 4, stride:
|
|
2631
|
-
{ name: "aColor", size: 4, type:
|
|
2632
|
-
{ name: "aOrigin", size: 2, stride:
|
|
2633
|
-
]), this.quadBuffer.bindBuffer(),
|
|
2633
|
+
const r = super.createShader(t, e);
|
|
2634
|
+
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
2635
|
+
{ name: "aPosition", size: 2, stride: D, offset: 0, divisor: 1 },
|
|
2636
|
+
{ name: "aScale", size: 2, stride: D, offset: 8, divisor: 1 },
|
|
2637
|
+
{ name: "aRotation", size: 1, stride: D, offset: 16, divisor: 1 },
|
|
2638
|
+
{ name: "aUVRect", size: 4, stride: D, offset: 20, divisor: 1 },
|
|
2639
|
+
{ name: "aColor", size: 4, type: et, normalized: !0, stride: D, offset: 36, divisor: 1 },
|
|
2640
|
+
{ name: "aOrigin", size: 2, stride: D, offset: 40, divisor: 1 }
|
|
2641
|
+
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
2634
2642
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
2635
|
-
]),
|
|
2636
|
-
}
|
|
2637
|
-
drawParticle(t, e = 0, i = 0, r = 1, n = 1, a = 0, o = 0, h = 0, c = 1, u = 1, f = 4294967295, l = !1, p = !1, x = !1, v = 0.5, R = 0.5) {
|
|
2638
|
-
(this.instanceCount >= q || this.texture && t != this.texture) && this.flush(), t.glTexture && (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2639
|
-
const T = this.instanceBuffer, g = T.usedElemNum, w = t.rawWidth, b = t.rawHeight;
|
|
2640
|
-
T.resize(K);
|
|
2641
|
-
const A = T.float32, I = T.uint32;
|
|
2642
|
-
A[g] = e, A[g + 1] = i, A[g + 2] = r * (l ? -1 : 1) * w, A[g + 3] = n * (p ? -1 : 1) * b, A[g + 4] = a, x && (A[g + 4] += Math.PI / 2), A[g + 5] = o, A[g + 6] = h, A[g + 7] = c, A[g + 8] = u, I[g + 9] = f, A[g + 10] = v, A[g + 11] = R, T.usedElemNum += K, T.makeDirty(), this.instanceCount++;
|
|
2643
|
+
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2643
2644
|
}
|
|
2644
|
-
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) {
|
|
2645
2646
|
if (!t.glTexture || a <= 0) return;
|
|
2646
|
-
let
|
|
2647
|
-
const
|
|
2648
|
-
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; ) {
|
|
2649
2650
|
this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2650
|
-
const
|
|
2651
|
-
let
|
|
2652
|
-
|
|
2653
|
-
const
|
|
2654
|
-
for (let
|
|
2655
|
-
const
|
|
2656
|
-
|
|
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;
|
|
2657
2658
|
}
|
|
2658
|
-
|
|
2659
|
+
L.usedElemNum = S, L.makeDirty(), this.instanceCount += W, R += W;
|
|
2659
2660
|
}
|
|
2660
2661
|
}
|
|
2661
2662
|
render() {
|
|
2662
2663
|
if (this.instanceCount === 0) return;
|
|
2663
|
-
|
|
2664
|
+
this.prepareRender();
|
|
2664
2665
|
const t = this.gl;
|
|
2665
2666
|
this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
|
|
2666
2667
|
const e = this.currentShader;
|
|
2667
2668
|
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
|
|
2668
|
-
const
|
|
2669
|
-
this.currentShader.setUniform("u_projection",
|
|
2669
|
+
const r = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(r.curWorldM), a = Vt(this.rapid.projection, n);
|
|
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;
|
|
2670
2671
|
}
|
|
2671
2672
|
}
|
|
2672
|
-
var
|
|
2673
|
-
class
|
|
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 || {});
|
|
2674
|
+
class ce {
|
|
2674
2675
|
/** The active WebGL context. */
|
|
2675
2676
|
gl;
|
|
2676
2677
|
/** The target HTMLCanvasElement. */
|
|
@@ -2682,7 +2683,7 @@ class le {
|
|
|
2682
2683
|
/** The current device pixel ratio. */
|
|
2683
2684
|
dpr;
|
|
2684
2685
|
/** Background clear color [r, g, b, a], values range from 0 to 255. */
|
|
2685
|
-
backgroundColor =
|
|
2686
|
+
backgroundColor = p.Black;
|
|
2686
2687
|
/** Logical width in CSS pixels, used for coordinate system and projection matrix. */
|
|
2687
2688
|
logicWidth = 0;
|
|
2688
2689
|
/** Logical height in CSS pixels, used for coordinate system and projection matrix. */
|
|
@@ -2696,7 +2697,7 @@ class le {
|
|
|
2696
2697
|
/** Maximum number of texture units supported by the device. */
|
|
2697
2698
|
maxTextureUnits = 0;
|
|
2698
2699
|
/** Matrix stack for hierarchical transformations. */
|
|
2699
|
-
matrixStack = new
|
|
2700
|
+
matrixStack = new St(this);
|
|
2700
2701
|
/** Direct access to the underlying matrix store. */
|
|
2701
2702
|
matrix;
|
|
2702
2703
|
/** Region dedicated to fast sprite rendering. */
|
|
@@ -2734,10 +2735,10 @@ class le {
|
|
|
2734
2735
|
*/
|
|
2735
2736
|
constructor(t) {
|
|
2736
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;
|
|
2737
|
-
const e =
|
|
2738
|
-
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new
|
|
2739
|
-
const
|
|
2740
|
-
this.physicsWidth = t.physicsWidth || Math.round(
|
|
2738
|
+
const e = Ct(this.canvas, this.antialias, this.premultipliedAlpha);
|
|
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);
|
|
2741
2742
|
}
|
|
2742
2743
|
setTextureFilter(t) {
|
|
2743
2744
|
this.textureFilter = t;
|
|
@@ -2756,26 +2757,23 @@ class le {
|
|
|
2756
2757
|
enterRegion(t, e) {
|
|
2757
2758
|
this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
|
|
2758
2759
|
}
|
|
2759
|
-
drawParticle(t) {
|
|
2760
|
-
Zt(this, t);
|
|
2761
|
-
}
|
|
2762
2760
|
drawParticles(t) {
|
|
2763
|
-
|
|
2761
|
+
qt(this, t), this.flush();
|
|
2764
2762
|
}
|
|
2765
2763
|
drawSprite(t) {
|
|
2766
|
-
|
|
2764
|
+
Kt(this, t);
|
|
2767
2765
|
}
|
|
2768
2766
|
drawLine(t) {
|
|
2769
|
-
|
|
2767
|
+
Zt(this, t);
|
|
2770
2768
|
}
|
|
2771
2769
|
drawGraphic(t) {
|
|
2772
|
-
|
|
2770
|
+
Et(this, t);
|
|
2773
2771
|
}
|
|
2774
2772
|
drawRect(t) {
|
|
2775
|
-
|
|
2773
|
+
Jt(this, t);
|
|
2776
2774
|
}
|
|
2777
2775
|
drawCircle(t) {
|
|
2778
|
-
|
|
2776
|
+
te(this, t);
|
|
2779
2777
|
}
|
|
2780
2778
|
/**
|
|
2781
2779
|
* Starts rendering arbitrary graphics geometries.
|
|
@@ -2783,23 +2781,23 @@ class le {
|
|
|
2783
2781
|
* @param texture An optional texture applied to the graphic vertices.
|
|
2784
2782
|
* @param customShader An optional custom shader overriding the region's default shader.
|
|
2785
2783
|
*/
|
|
2786
|
-
startGraphic(t = this.gl.TRIANGLES, e,
|
|
2787
|
-
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);
|
|
2788
2786
|
}
|
|
2789
2787
|
/**
|
|
2790
2788
|
* Starts rendering graphics explicitly for use as a mask, overriding the shader.
|
|
2791
2789
|
* @param drawMode The WebGL drawing mode (e.g., gl.TRIANGLES).
|
|
2792
2790
|
* @param texture An optional texture whose alpha channel may dictate masking rules.
|
|
2793
2791
|
*/
|
|
2794
|
-
startMaskGraphic(t = this.gl.TRIANGLES, e,
|
|
2795
|
-
this.startGraphic(t, e, this.graphicRegion.maskShader,
|
|
2792
|
+
startMaskGraphic(t = this.gl.TRIANGLES, e, r) {
|
|
2793
|
+
this.startGraphic(t, e, this.graphicRegion.maskShader, r);
|
|
2796
2794
|
}
|
|
2797
2795
|
/**
|
|
2798
2796
|
* Utility method: Draws an image directly as a mask using a generic rectangle geometry.
|
|
2799
2797
|
* @param texture The texture to be used as a mask.
|
|
2800
2798
|
*/
|
|
2801
2799
|
drawMaskImage(t) {
|
|
2802
|
-
|
|
2800
|
+
Qt(this, t);
|
|
2803
2801
|
}
|
|
2804
2802
|
/**
|
|
2805
2803
|
* Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
|
|
@@ -2807,9 +2805,9 @@ class le {
|
|
|
2807
2805
|
* @param h The height of the rectangle.
|
|
2808
2806
|
* @param color An optional tint color.
|
|
2809
2807
|
*/
|
|
2810
|
-
addRectVertex(t, e,
|
|
2811
|
-
const
|
|
2812
|
-
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);
|
|
2813
2811
|
}
|
|
2814
2812
|
/**
|
|
2815
2813
|
* Pushes vertices for a circle geometry using TRIANGLES or similar primitives.
|
|
@@ -2817,11 +2815,11 @@ class le {
|
|
|
2817
2815
|
* @param color An optional tint color.
|
|
2818
2816
|
* @param segments The number of segments (polygons) used to approximate the circle.
|
|
2819
2817
|
*/
|
|
2820
|
-
addCircleVertex(t, e,
|
|
2821
|
-
const
|
|
2822
|
-
for (let a = 0; a <
|
|
2823
|
-
const
|
|
2824
|
-
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);
|
|
2825
2823
|
}
|
|
2826
2824
|
}
|
|
2827
2825
|
/**
|
|
@@ -2832,8 +2830,8 @@ class le {
|
|
|
2832
2830
|
* @param v The V texture coordinate (0 to 1).
|
|
2833
2831
|
* @param color The vertex color as a 32-bit unsigned integer.
|
|
2834
2832
|
*/
|
|
2835
|
-
addGraphicVertex(t, e,
|
|
2836
|
-
this.graphicRegion.addVertex(t, e,
|
|
2833
|
+
addGraphicVertex(t, e, r = 0, i = 0, n = 4294967295) {
|
|
2834
|
+
this.graphicRegion.addVertex(t, e, r, i, n);
|
|
2837
2835
|
}
|
|
2838
2836
|
/**
|
|
2839
2837
|
* Ends the current graphics geometry definition, readying it for rendering.
|
|
@@ -2848,10 +2846,10 @@ class le {
|
|
|
2848
2846
|
* @param cssWidth Optional CSS display width.
|
|
2849
2847
|
* @param cssHeight Optional CSS display height.
|
|
2850
2848
|
*/
|
|
2851
|
-
resize(t, e,
|
|
2849
|
+
resize(t, e, r, i) {
|
|
2852
2850
|
this.flush();
|
|
2853
|
-
const n =
|
|
2854
|
-
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) {
|
|
2855
2853
|
case 1:
|
|
2856
2854
|
this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
|
|
2857
2855
|
break;
|
|
@@ -2867,8 +2865,8 @@ class le {
|
|
|
2867
2865
|
* Updates the projection matrix using an orthographic mapping.
|
|
2868
2866
|
* Automatically sets local flag projectionDirty.
|
|
2869
2867
|
*/
|
|
2870
|
-
updateProjection(t, e,
|
|
2871
|
-
this.updateOrthMatrix(this.projection, t, e,
|
|
2868
|
+
updateProjection(t, e, r, i) {
|
|
2869
|
+
this.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
|
|
2872
2870
|
}
|
|
2873
2871
|
/**
|
|
2874
2872
|
* Clears the active framebuffer applying the default background color.
|
|
@@ -2881,8 +2879,8 @@ class le {
|
|
|
2881
2879
|
* Populates an orthographic projection matrix in place.
|
|
2882
2880
|
* Avoids continuous Float32Array allocations for performance reasons.
|
|
2883
2881
|
*/
|
|
2884
|
-
updateOrthMatrix(t, e,
|
|
2885
|
-
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;
|
|
2886
2884
|
}
|
|
2887
2885
|
/**
|
|
2888
2886
|
* Flushes currently buffered rendering operations across all active regions.
|
|
@@ -2907,23 +2905,23 @@ class le {
|
|
|
2907
2905
|
applyFilters(t, e) {
|
|
2908
2906
|
if (e.length === 0)
|
|
2909
2907
|
throw new Error("applyFilters: shaders array must not be empty.");
|
|
2910
|
-
const
|
|
2911
|
-
for (let
|
|
2912
|
-
this._filterRT[
|
|
2913
|
-
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;
|
|
2914
2912
|
this.matrixStack.save(), this.matrixStack.identity();
|
|
2915
|
-
for (let
|
|
2913
|
+
for (let o = 0; o < e.length; o++) {
|
|
2916
2914
|
const u = this._filterRT[h % 2];
|
|
2917
2915
|
u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
|
|
2918
|
-
texture:
|
|
2919
|
-
shader: e[
|
|
2920
|
-
offsetX:
|
|
2916
|
+
texture: c,
|
|
2917
|
+
shader: e[o],
|
|
2918
|
+
offsetX: o == 0 ? i : 0,
|
|
2921
2919
|
// padding back
|
|
2922
|
-
offsetY:
|
|
2923
|
-
padding:
|
|
2924
|
-
}), this.leaveRenderTexture(),
|
|
2920
|
+
offsetY: o == 0 ? i : 0,
|
|
2921
|
+
padding: r
|
|
2922
|
+
}), this.leaveRenderTexture(), c = u, h++;
|
|
2925
2923
|
}
|
|
2926
|
-
return this.matrixStack.restore(),
|
|
2924
|
+
return this.matrixStack.restore(), c.offsetX = -i, c.offsetY = -i, c;
|
|
2927
2925
|
}
|
|
2928
2926
|
enterRenderTexture(t) {
|
|
2929
2927
|
this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, t.rawHeight, 0);
|
|
@@ -2935,7 +2933,7 @@ class le {
|
|
|
2935
2933
|
* @param rt The render texture to clear.
|
|
2936
2934
|
* @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
|
|
2937
2935
|
*/
|
|
2938
|
-
clearRenderTexture(t = new
|
|
2936
|
+
clearRenderTexture(t = new p(0, 0, 0, 0)) {
|
|
2939
2937
|
this.flush();
|
|
2940
2938
|
const e = this.gl;
|
|
2941
2939
|
t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
|
|
@@ -2957,10 +2955,10 @@ class le {
|
|
|
2957
2955
|
* rapid.drawSprite({ texture: mySprite });
|
|
2958
2956
|
* });
|
|
2959
2957
|
*/
|
|
2960
|
-
drawToRenderTexture(t, e,
|
|
2958
|
+
drawToRenderTexture(t, e, r = new p(0, 0, 0, 0)) {
|
|
2961
2959
|
this.enterRenderTexture(t);
|
|
2962
2960
|
try {
|
|
2963
|
-
|
|
2961
|
+
r !== null && this.clearRenderTexture(r), e();
|
|
2964
2962
|
} finally {
|
|
2965
2963
|
this.leaveRenderTexture();
|
|
2966
2964
|
}
|
|
@@ -2978,14 +2976,14 @@ class le {
|
|
|
2978
2976
|
* () => rapid.drawSprite({ texture: myTexture }),
|
|
2979
2977
|
* );
|
|
2980
2978
|
*/
|
|
2981
|
-
withMask(t, e,
|
|
2982
|
-
this.clearMask(), this.startDrawMask(
|
|
2979
|
+
withMask(t, e, r = 0, i = 1) {
|
|
2980
|
+
this.clearMask(), this.startDrawMask(i);
|
|
2983
2981
|
try {
|
|
2984
2982
|
t();
|
|
2985
2983
|
} finally {
|
|
2986
2984
|
this.endDrawMask();
|
|
2987
2985
|
}
|
|
2988
|
-
this.enterMask(
|
|
2986
|
+
this.enterMask(r, i);
|
|
2989
2987
|
try {
|
|
2990
2988
|
e();
|
|
2991
2989
|
} finally {
|
|
@@ -3014,21 +3012,12 @@ class le {
|
|
|
3014
3012
|
* rapid.drawSprite({ texture: myTexture });
|
|
3015
3013
|
* }, { x: 100, y: 50, rotation: Math.PI / 4, origin: 0.5 }, myTexture.width, myTexture.height);
|
|
3016
3014
|
*/
|
|
3017
|
-
withTransform(t, e,
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
n && this.matrixStack.restore();
|
|
3024
|
-
}
|
|
3025
|
-
} else {
|
|
3026
|
-
this.matrixStack.save();
|
|
3027
|
-
try {
|
|
3028
|
-
t();
|
|
3029
|
-
} finally {
|
|
3030
|
-
this.matrixStack.restore();
|
|
3031
|
-
}
|
|
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();
|
|
3032
3021
|
}
|
|
3033
3022
|
}
|
|
3034
3023
|
/**
|
|
@@ -3044,8 +3033,8 @@ class le {
|
|
|
3044
3033
|
* rapid.drawSprite({ texture: myTexture });
|
|
3045
3034
|
* });
|
|
3046
3035
|
*/
|
|
3047
|
-
withScissor(t, e,
|
|
3048
|
-
this.startScissor(t, e,
|
|
3036
|
+
withScissor(t, e, r, i, n) {
|
|
3037
|
+
this.startScissor(t, e, r, i);
|
|
3049
3038
|
try {
|
|
3050
3039
|
n();
|
|
3051
3040
|
} finally {
|
|
@@ -3080,8 +3069,8 @@ class le {
|
|
|
3080
3069
|
*/
|
|
3081
3070
|
startDrawMask(t = 1, e = 255) {
|
|
3082
3071
|
this.flush();
|
|
3083
|
-
const
|
|
3084
|
-
|
|
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;
|
|
3085
3074
|
}
|
|
3086
3075
|
/**
|
|
3087
3076
|
* Finishes the mask drawing phase and restores color buffer writing.
|
|
@@ -3106,10 +3095,10 @@ class le {
|
|
|
3106
3095
|
* @param ref The reference value to test against.
|
|
3107
3096
|
* @param mask The bitmask specifying which stencil bits to consider.
|
|
3108
3097
|
*/
|
|
3109
|
-
enterMask(t, e = 1,
|
|
3098
|
+
enterMask(t, e = 1, r = 255) {
|
|
3110
3099
|
this.flush();
|
|
3111
|
-
const
|
|
3112
|
-
|
|
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;
|
|
3113
3102
|
}
|
|
3114
3103
|
/**
|
|
3115
3104
|
* Exits the masked rendering phase, restoring default full-screen stencil values tests.
|
|
@@ -3153,10 +3142,10 @@ class le {
|
|
|
3153
3142
|
* @param width Width in logical pixels.
|
|
3154
3143
|
* @param height Height in logical pixels.
|
|
3155
3144
|
*/
|
|
3156
|
-
startScissor(t, e,
|
|
3145
|
+
startScissor(t, e, r, i) {
|
|
3157
3146
|
this.flush();
|
|
3158
|
-
const n = this.gl, a = this.physicsWidth / this.logicWidth,
|
|
3159
|
-
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);
|
|
3160
3149
|
}
|
|
3161
3150
|
/**
|
|
3162
3151
|
* Disables scissor clipping, restoring full-canvas rendering.
|
|
@@ -3170,13 +3159,13 @@ class le {
|
|
|
3170
3159
|
this.matrix.invert(e);
|
|
3171
3160
|
}
|
|
3172
3161
|
logicToPhysics(t) {
|
|
3173
|
-
return t.multiply(new
|
|
3162
|
+
return t.multiply(new m(
|
|
3174
3163
|
this.physicsWidth / this.logicWidth,
|
|
3175
3164
|
this.physicsHeight / this.logicHeight
|
|
3176
3165
|
));
|
|
3177
3166
|
}
|
|
3178
3167
|
physicsToLogic(t) {
|
|
3179
|
-
return t.multiply(new
|
|
3168
|
+
return t.multiply(new m(
|
|
3180
3169
|
this.logicWidth / this.physicsWidth,
|
|
3181
3170
|
this.logicHeight / this.physicsHeight
|
|
3182
3171
|
));
|
|
@@ -3200,12 +3189,12 @@ class le {
|
|
|
3200
3189
|
* @param index - Matrix index to export. Defaults to the current world matrix.
|
|
3201
3190
|
*/
|
|
3202
3191
|
toCSSMatrix(t) {
|
|
3203
|
-
const e = this.physicsWidth / this.dpr / this.logicWidth,
|
|
3204
|
-
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);
|
|
3205
3194
|
}
|
|
3206
3195
|
}
|
|
3207
|
-
function
|
|
3208
|
-
return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof
|
|
3196
|
+
function ae(s) {
|
|
3197
|
+
return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof m || s instanceof p);
|
|
3209
3198
|
}
|
|
3210
3199
|
class C {
|
|
3211
3200
|
/** Random float in [min, max). */
|
|
@@ -3221,12 +3210,12 @@ class C {
|
|
|
3221
3210
|
return Math.random() * Math.PI * 2;
|
|
3222
3211
|
}
|
|
3223
3212
|
/** Random Vec2 with components in the supplied per-axis ranges. */
|
|
3224
|
-
static vector(t, e,
|
|
3225
|
-
return new
|
|
3213
|
+
static vector(t, e, r, i) {
|
|
3214
|
+
return new m(C.float(t, e), C.float(r, i));
|
|
3226
3215
|
}
|
|
3227
3216
|
/** Random Color with each component interpolated between minColor and maxColor. */
|
|
3228
3217
|
static randomColor(t, e) {
|
|
3229
|
-
return new
|
|
3218
|
+
return new p(
|
|
3230
3219
|
C.float(t.r, e.r),
|
|
3231
3220
|
C.float(t.g, e.g),
|
|
3232
3221
|
C.float(t.b, e.b),
|
|
@@ -3244,10 +3233,10 @@ class C {
|
|
|
3244
3233
|
static pickWeight(t) {
|
|
3245
3234
|
if (!t || t.length === 0) return null;
|
|
3246
3235
|
let e = 0;
|
|
3247
|
-
for (const [,
|
|
3248
|
-
let
|
|
3249
|
-
for (const [
|
|
3250
|
-
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;
|
|
3251
3240
|
return t[t.length - 1][0];
|
|
3252
3241
|
}
|
|
3253
3242
|
/**
|
|
@@ -3259,20 +3248,20 @@ class C {
|
|
|
3259
3248
|
static scalarOrRange(t, e) {
|
|
3260
3249
|
if (t == null) return e;
|
|
3261
3250
|
if (Array.isArray(t)) {
|
|
3262
|
-
const [
|
|
3263
|
-
if (typeof
|
|
3264
|
-
return C.float(
|
|
3265
|
-
if (
|
|
3266
|
-
return C.vector(
|
|
3267
|
-
if (
|
|
3268
|
-
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);
|
|
3269
3258
|
}
|
|
3270
3259
|
return typeof t == "number" ? t : t.clone();
|
|
3271
3260
|
}
|
|
3272
3261
|
}
|
|
3273
|
-
var
|
|
3274
|
-
const
|
|
3275
|
-
class
|
|
3262
|
+
var he = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(he || {});
|
|
3263
|
+
const xt = 10, pt = 0, gt = !0;
|
|
3264
|
+
class oe {
|
|
3276
3265
|
life = 0;
|
|
3277
3266
|
maxLife;
|
|
3278
3267
|
texture;
|
|
@@ -3285,19 +3274,19 @@ class ue {
|
|
|
3285
3274
|
speed: this.processAttribute(e.animation.speed, 0),
|
|
3286
3275
|
rotation: this.processAttribute(e.animation.rotation, 0),
|
|
3287
3276
|
scale: this.processAttribute(e.animation.scale, 1),
|
|
3288
|
-
color: this.processAttribute(e.animation.color,
|
|
3289
|
-
velocity: this.processAttribute(e.animation.velocity,
|
|
3290
|
-
}, 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();
|
|
3291
3280
|
}
|
|
3292
3281
|
processAttribute(t, e) {
|
|
3293
3282
|
if (t == null)
|
|
3294
3283
|
return { value: e };
|
|
3295
|
-
if (
|
|
3296
|
-
const
|
|
3284
|
+
if (ae(t)) {
|
|
3285
|
+
const r = t, i = C.scalarOrRange(r.start, e), n = r.end === void 0 ? i : C.scalarOrRange(r.end, e);
|
|
3297
3286
|
return {
|
|
3298
|
-
delta:
|
|
3299
|
-
value:
|
|
3300
|
-
damping:
|
|
3287
|
+
delta: r.delta ?? this.getDelta(i, n, this.maxLife),
|
|
3288
|
+
value: i,
|
|
3289
|
+
damping: r.damping
|
|
3301
3290
|
};
|
|
3302
3291
|
} else
|
|
3303
3292
|
return this.processAttribute({ start: t }, e);
|
|
@@ -3314,11 +3303,11 @@ class ue {
|
|
|
3314
3303
|
updateAttributes(t) {
|
|
3315
3304
|
const e = this.datas;
|
|
3316
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);
|
|
3317
|
-
const
|
|
3318
|
-
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));
|
|
3319
3308
|
}
|
|
3320
|
-
getDelta(t, e,
|
|
3321
|
-
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;
|
|
3322
3311
|
}
|
|
3323
3312
|
/**
|
|
3324
3313
|
* Updates particle state.
|
|
@@ -3333,44 +3322,44 @@ class ue {
|
|
|
3333
3322
|
* The emitter is responsible for calling save/restore around a batch of particles.
|
|
3334
3323
|
*/
|
|
3335
3324
|
render() {
|
|
3336
|
-
const t = this.rapid.matrixStack, e = this.datas.scale.value,
|
|
3337
|
-
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);
|
|
3338
3327
|
const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
|
|
3339
|
-
(n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight),
|
|
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();
|
|
3340
3329
|
}
|
|
3341
3330
|
initializePosition() {
|
|
3342
3331
|
switch (this.options.emitShape) {
|
|
3343
3332
|
case "circle": {
|
|
3344
3333
|
const t = Math.random() * Math.PI * 2, e = (this.options.emitRadius ?? 0) * Math.sqrt(Math.random());
|
|
3345
|
-
this.position = new
|
|
3334
|
+
this.position = new m(Math.cos(t) * e, Math.sin(t) * e);
|
|
3346
3335
|
break;
|
|
3347
3336
|
}
|
|
3348
3337
|
case "rect": {
|
|
3349
|
-
this.position = new
|
|
3338
|
+
this.position = new m(
|
|
3350
3339
|
(Math.random() - 0.5) * (this.options.emitRect?.width ?? 0),
|
|
3351
3340
|
(Math.random() - 0.5) * (this.options.emitRect?.height ?? 0)
|
|
3352
3341
|
);
|
|
3353
3342
|
break;
|
|
3354
3343
|
}
|
|
3355
3344
|
default:
|
|
3356
|
-
this.position =
|
|
3345
|
+
this.position = m.ZERO;
|
|
3357
3346
|
break;
|
|
3358
3347
|
}
|
|
3359
3348
|
!this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
|
|
3360
3349
|
}
|
|
3361
3350
|
}
|
|
3362
|
-
class
|
|
3351
|
+
class wt {
|
|
3363
3352
|
particles = [];
|
|
3364
3353
|
options;
|
|
3365
3354
|
emitting = !1;
|
|
3366
3355
|
emitTimer = 0;
|
|
3367
|
-
emitRate =
|
|
3368
|
-
emitTime =
|
|
3356
|
+
emitRate = xt;
|
|
3357
|
+
emitTime = pt;
|
|
3369
3358
|
emitTimeCounter = 0;
|
|
3370
3359
|
/** Whether spawned particles are positioned in local emitter space (default: true). */
|
|
3371
|
-
localSpace =
|
|
3360
|
+
localSpace = gt;
|
|
3372
3361
|
/** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
|
|
3373
|
-
position =
|
|
3362
|
+
position = m.ZERO;
|
|
3374
3363
|
rapid;
|
|
3375
3364
|
gameObject;
|
|
3376
3365
|
/**
|
|
@@ -3379,7 +3368,7 @@ class Mt {
|
|
|
3379
3368
|
* @param options - Emitter configuration options
|
|
3380
3369
|
*/
|
|
3381
3370
|
constructor(t, e) {
|
|
3382
|
-
this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate :
|
|
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;
|
|
3383
3372
|
}
|
|
3384
3373
|
/** Replaces the emitter's texture at runtime. */
|
|
3385
3374
|
setTexture(t) {
|
|
@@ -3390,7 +3379,7 @@ class Mt {
|
|
|
3390
3379
|
* Particle state is NOT copied.
|
|
3391
3380
|
*/
|
|
3392
3381
|
clone() {
|
|
3393
|
-
return new
|
|
3382
|
+
return new wt(this.rapid, { ...this.options });
|
|
3394
3383
|
}
|
|
3395
3384
|
/** Sets particles-per-second emission rate (continuous mode). */
|
|
3396
3385
|
setEmitRate(t) {
|
|
@@ -3417,9 +3406,9 @@ class Mt {
|
|
|
3417
3406
|
* Respects `maxParticles` if set.
|
|
3418
3407
|
*/
|
|
3419
3408
|
emit(t) {
|
|
3420
|
-
const e = this.options.maxParticles ?? 1 / 0,
|
|
3421
|
-
for (let
|
|
3422
|
-
this.particles.push(new
|
|
3409
|
+
const e = this.options.maxParticles ?? 1 / 0, r = Math.min(t, e - this.particles.length);
|
|
3410
|
+
for (let i = 0; i < r; i++)
|
|
3411
|
+
this.particles.push(new oe(this.rapid, { ...this.options, position: this.position }));
|
|
3423
3412
|
}
|
|
3424
3413
|
/**
|
|
3425
3414
|
* Updates the emitter and all live particles.
|
|
@@ -3467,44 +3456,42 @@ class Mt {
|
|
|
3467
3456
|
}
|
|
3468
3457
|
}
|
|
3469
3458
|
export {
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
Ct as TextTexture,
|
|
3459
|
+
I as ArrayType,
|
|
3460
|
+
k as BaseTexture,
|
|
3461
|
+
se as BlendMode,
|
|
3462
|
+
ne as CanvasScaleMode,
|
|
3463
|
+
p as Color,
|
|
3464
|
+
ot as CustomGlShader,
|
|
3465
|
+
B as DynamicArrayBuffer,
|
|
3466
|
+
Tt as GLShader,
|
|
3467
|
+
Ht as GraphicRegion,
|
|
3468
|
+
Yt as LineTextureMode,
|
|
3469
|
+
ie as MaskType,
|
|
3470
|
+
St as MatrixStack,
|
|
3471
|
+
Mt as MatrixStore,
|
|
3472
|
+
oe as Particle,
|
|
3473
|
+
wt as ParticleEmitter,
|
|
3474
|
+
he as ParticleShape,
|
|
3475
|
+
Ft as QUAD_VERTICES,
|
|
3476
|
+
ce as Rapid,
|
|
3477
|
+
yt as Region,
|
|
3478
|
+
At as RenderTexture,
|
|
3479
|
+
it as SpriteRegion,
|
|
3480
|
+
_t as TextTexture,
|
|
3493
3481
|
P as Texture,
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
Et as drawSpriteRaw,
|
|
3482
|
+
rt as TextureFilterMode,
|
|
3483
|
+
bt as TextureManager,
|
|
3484
|
+
Y as TextureWrapMode,
|
|
3485
|
+
m as Vec2,
|
|
3486
|
+
Q as WebglBufferArray,
|
|
3487
|
+
Vt as composeProjectionWithAffine,
|
|
3488
|
+
te as drawCircle,
|
|
3489
|
+
Et as drawGraphic,
|
|
3490
|
+
Zt as drawLine,
|
|
3491
|
+
Qt as drawMaskImage,
|
|
3492
|
+
qt as drawParticles,
|
|
3493
|
+
Jt as drawRect,
|
|
3494
|
+
Kt as drawSprite,
|
|
3495
|
+
Rt as drawSpriteRaw,
|
|
3509
3496
|
zt as multiplyMat4
|
|
3510
3497
|
};
|