rapid-render 1.0.17 → 1.0.18

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.
@@ -154,7 +154,7 @@ class m {
154
154
  static Transparent = new m(0, 0, 0, 0);
155
155
  }
156
156
  var tt = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(tt || {}), q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(q || {});
157
- class Ct {
157
+ class bt {
158
158
  render;
159
159
  cache = /* @__PURE__ */ new Map();
160
160
  constructor(t) {
@@ -166,7 +166,7 @@ class Ct {
166
166
  return new N(r);
167
167
  try {
168
168
  const i = await this._fetchImage(t);
169
- return r = V.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new N(r);
169
+ return r = G.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new N(r);
170
170
  } catch (i) {
171
171
  throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
172
172
  }
@@ -174,14 +174,14 @@ class Ct {
174
174
  create(t, e) {
175
175
  if (e?.key && this.cache.has(e.key))
176
176
  return new N(this.cache.get(e.key));
177
- const r = V.fromSource(this.render, t, e);
177
+ const r = G.fromSource(this.render, t, e);
178
178
  return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new N(r);
179
179
  }
180
180
  createRenderTexture(t) {
181
- return new _t(this.render, t);
181
+ return new Ut(this.render, t);
182
182
  }
183
183
  createTextTexture(t) {
184
- return new Pt(this.render, t);
184
+ return new _t(this.render, t);
185
185
  }
186
186
  destroy(t, e = !1) {
187
187
  let r, i;
@@ -199,7 +199,7 @@ class Ct {
199
199
  });
200
200
  }
201
201
  }
202
- class V {
202
+ class G {
203
203
  glTexture = null;
204
204
  width;
205
205
  height;
@@ -210,7 +210,7 @@ class V {
210
210
  }
211
211
  static fromSource(t, e, r = {}) {
212
212
  const i = rt(t, e, r);
213
- return new V(i, e.width, e.height);
213
+ return new G(i, e.width, e.height);
214
214
  }
215
215
  updateSource(t, e, r = {}) {
216
216
  this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && ht(t, r.textureFilter), r.wrap !== void 0 && at(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));
@@ -277,13 +277,13 @@ class N {
277
277
  }
278
278
  static fromImageSource(t, e, r = {}) {
279
279
  const i = rt(t, e, r);
280
- return new N(new V(i, e.width, e.height));
280
+ return new N(new G(i, e.width, e.height));
281
281
  }
282
282
  destroy() {
283
283
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
284
284
  }
285
285
  }
286
- class _t extends N {
286
+ class Ut extends N {
287
287
  framebuffer;
288
288
  renderbuffer;
289
289
  gl;
@@ -293,7 +293,7 @@ class _t extends N {
293
293
  constructor(t, e) {
294
294
  super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
295
295
  const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = rt(t, { width: r, height: i }, { ...e, onlySize: !0 });
296
- if (this.setBase(new V(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
296
+ if (this.setBase(new G(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
297
297
  throw new Error("Failed to create Framebuffer or Renderbuffer");
298
298
  this.resize(r, i, !0);
299
299
  }
@@ -337,7 +337,7 @@ class _t extends N {
337
337
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
338
338
  }
339
339
  }
340
- const Lt = {
340
+ const Ct = {
341
341
  fontFamily: "Arial",
342
342
  fontSize: 24,
343
343
  fontWeight: "normal",
@@ -346,7 +346,7 @@ const Lt = {
346
346
  align: "left",
347
347
  lineHeight: 1
348
348
  };
349
- class Pt extends N {
349
+ class _t extends N {
350
350
  canvas;
351
351
  ctx;
352
352
  render;
@@ -355,12 +355,12 @@ class Pt extends N {
355
355
  options;
356
356
  flipY = !0;
357
357
  constructor(t, e) {
358
- super(), this.render = t, this._style = { ...Lt, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
358
+ super(), this.render = t, this._style = { ...Ct, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
359
359
  const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
360
360
  if (!r) throw new Error("Failed to get 2d context for TextTexture");
361
361
  this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
362
362
  const i = rt(t, this.canvas, this.options);
363
- this.setBase(new V(i, 1, 1)), this.update();
363
+ this.setBase(new G(i, 1, 1)), this.update();
364
364
  }
365
365
  get text() {
366
366
  return this._text;
@@ -406,7 +406,7 @@ class Pt extends N {
406
406
  this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, E, w);
407
407
  }
408
408
  }
409
- const Nt = (n, t = !1, e = !0) => {
409
+ const Lt = (n, t = !1, e = !0) => {
410
410
  const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
411
411
  if (!r)
412
412
  throw new Error("WebGL2 is not supported in this browser.");
@@ -420,7 +420,7 @@ const Nt = (n, t = !1, e = !0) => {
420
420
  throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
421
421
  }
422
422
  return r;
423
- }, It = (n, t, e) => {
423
+ }, Pt = (n, t, e) => {
424
424
  var r = n.createProgram(), i = dt(n, t, 35633), s = dt(n, e, 35632);
425
425
  if (!r)
426
426
  throw new Error("Unable to create program shader");
@@ -458,7 +458,7 @@ function rt(n, t, e) {
458
458
  }
459
459
  return r.bindTexture(r.TEXTURE_2D, null), i;
460
460
  }
461
- function D(n, t, e = "vTextureId", r = "uv", i = "return") {
461
+ function K(n, t, e = "vTextureId", r = "uv", i = "return") {
462
462
  if (n.includes("%TEXTURE_NUM%") && (n = n.replaceAll("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
463
463
  let s = "";
464
464
  for (let a = 0; a < t; a++)
@@ -467,15 +467,15 @@ function D(n, t, e = "vTextureId", r = "uv", i = "return") {
467
467
  }
468
468
  return n;
469
469
  }
470
- const Wt = 5126, ot = 5121;
471
- function Ot(n, t, e) {
470
+ const Nt = 5126, ot = 5121;
471
+ function It(n, t, e) {
472
472
  n.vertexAttribDivisor(t, e);
473
473
  }
474
- function Et(n, t, e, r, i) {
474
+ function yt(n, t, e, r, i) {
475
475
  n.drawArraysInstanced(t, e, r, i);
476
476
  }
477
- let Ft = 0;
478
- class Rt {
477
+ let Wt = 0;
478
+ class Tt {
479
479
  program;
480
480
  attributeLoc = {};
481
481
  uniformLoc = {};
@@ -484,11 +484,11 @@ class Rt {
484
484
  uniformType = {};
485
485
  uniformIsArray = {};
486
486
  gl;
487
- shaderId = Ft++;
487
+ shaderId = Wt++;
488
488
  // for debug
489
489
  vao;
490
490
  constructor(t, e, r, i) {
491
- this.gl = t, this.program = It(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
491
+ this.gl = t, this.program = Pt(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
492
492
  }
493
493
  use() {
494
494
  this.gl.useProgram(this.program);
@@ -504,7 +504,7 @@ class Rt {
504
504
  const r = this.uniformLoc[t];
505
505
  if (r === void 0) return;
506
506
  const i = this.uniformType[t], s = this.uniformIsArray[t];
507
- Dt(this.gl, r, i, e, s);
507
+ Ot(this.gl, r, i, e, s);
508
508
  }
509
509
  setUniforms(t) {
510
510
  for (const e in t)
@@ -518,11 +518,11 @@ class Rt {
518
518
  r.vertexAttribPointer(
519
519
  e,
520
520
  t.size,
521
- t.type ?? Wt,
521
+ t.type ?? Nt,
522
522
  t.normalized ?? !1,
523
523
  t.stride,
524
524
  t.offset ?? 0
525
- ), r.enableVertexAttribArray(e), Ot(r, e, t.divisor ?? 0);
525
+ ), r.enableVertexAttribArray(e), It(r, e, t.divisor ?? 0);
526
526
  }
527
527
  setAttributes(t) {
528
528
  for (const e of t)
@@ -548,7 +548,7 @@ class Rt {
548
548
  }
549
549
  }
550
550
  }
551
- function Dt(n, t, e, r, i = !1) {
551
+ function Ot(n, t, e, r, i = !1) {
552
552
  switch (e) {
553
553
  // scalars
554
554
  case "float":
@@ -586,10 +586,10 @@ function Dt(n, t, e, r, i = !1) {
586
586
  return n.uniformMatrix3x2fv(t, !1, r);
587
587
  // fallback: guess by value shape
588
588
  default:
589
- return Bt(n, t, r);
589
+ return Ft(n, t, r);
590
590
  }
591
591
  }
592
- function Bt(n, t, e) {
592
+ function Ft(n, t, e) {
593
593
  if (typeof e == "number")
594
594
  return n.uniform1f(t, e);
595
595
  const r = e;
@@ -642,13 +642,16 @@ class ct {
642
642
  const r = this.glshader.get(t);
643
643
  r && (Object.keys(e).length > 0 && r.setUniforms(e), this.uniformDirty.has(t) && (r.setUniforms(this.uniforms), this.uniformDirty.delete(t)));
644
644
  }
645
+ replaceCustomCode(t, e) {
646
+ return t = t.replace("// CUSTOM_CODE", e + "// CUSTOM_CODE"), t;
647
+ }
645
648
  getGLShader(t, e, r, i) {
646
649
  if (this.glshader.has(e))
647
650
  return this.glshader.get(e);
648
651
  if (i == null || r == null)
649
652
  return console.warn("CustomGlShader: missing base shader for " + e), null;
650
653
  const s = this.prefix.length == 0 ? [""] : this.prefix;
651
- r = r.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "vertex(position, vRegion);").join("")), r = r.replace("// CUSTOM_CODE", this.vs), i = i.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "fragment(fragColor, vRegion);").join("")), i = i.replace("// CUSTOM_CODE", this.fs);
654
+ r = r.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "vertex(position, vRegion);").join("")), r = this.replaceCustomCode(r, this.vs), i = i.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "fragment(fragColor, vRegion);").join("")), i = this.replaceCustomCode(i, this.fs);
652
655
  const a = t.createShader(r, i);
653
656
  return a.isCustom = !0, a.padding = this.padding, this.glshader.set(e, a), this.uniformDirty.add(e), a;
654
657
  }
@@ -656,7 +659,7 @@ class ct {
656
659
  this.glshader.forEach((t) => t.destroy());
657
660
  }
658
661
  }
659
- class Mt {
662
+ class Et {
660
663
  constructor(t) {
661
664
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
662
665
  }
@@ -673,6 +676,7 @@ class Mt {
673
676
  fs = "";
674
677
  usedTextures = [];
675
678
  usedTexturePadding = [];
679
+ extraTextureUnit = 0;
676
680
  createBuffer() {
677
681
  }
678
682
  createDefaultShader() {
@@ -698,11 +702,16 @@ class Mt {
698
702
  const i = this.findTextureUnit(t, e, r);
699
703
  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;
700
704
  }
705
+ getMaxTexutreUnit(t) {
706
+ return this.rapid.maxTextureUnits - this.extraTextureUnit - (t?.usedTextureUnitNum ?? 0);
707
+ }
701
708
  createShader(t, e) {
702
- return new Rt(this.gl, t, e);
709
+ const r = this.getMaxTexutreUnit();
710
+ return e = K(e, r), t = K(t, r), new Tt(this.gl, t, e);
703
711
  }
704
712
  createCustomShader(t) {
705
- return t.getGLShader(this, this.KEY, this.vs, this.fs);
713
+ const e = this.getMaxTexutreUnit(t), r = K(this.fs, e), i = K(this.vs, e);
714
+ return t.getGLShader(this, this.KEY, i, r);
706
715
  }
707
716
  getCustomShader(t) {
708
717
  if (!t)
@@ -759,8 +768,8 @@ class Mt {
759
768
  return !1;
760
769
  }
761
770
  }
762
- var S = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(S || {});
763
- class A {
771
+ var A = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(A || {});
772
+ class S {
764
773
  usedElemNum;
765
774
  typedArray;
766
775
  arrayType;
@@ -859,7 +868,7 @@ class A {
859
868
  return this.usedElemNum;
860
869
  }
861
870
  }
862
- class ut extends A {
871
+ class ut extends S {
863
872
  buffer;
864
873
  gl;
865
874
  dirty = !0;
@@ -970,8 +979,8 @@ void main(void) {\r
970
979
  \r
971
980
  // CUSTOM_CODE_CALL\r
972
981
  }\r
973
- `, $ = 48, kt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
974
- class lt extends Mt {
982
+ `, Y = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
983
+ class lt extends Et {
975
984
  instanceBuffer;
976
985
  quadBuffer;
977
986
  instanceCount = 0;
@@ -983,30 +992,25 @@ class lt extends Mt {
983
992
  }
984
993
  createBuffer() {
985
994
  const t = this.gl;
986
- this.quadBuffer = new ut(t, S.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
987
- for (const e of kt) this.quadBuffer.pushFloat32(e);
988
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new ut(t, S.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
995
+ this.quadBuffer = new ut(t, A.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
996
+ for (const e of Dt) this.quadBuffer.pushFloat32(e);
997
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new ut(t, A.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
989
998
  }
990
999
  createDefaultShader() {
991
- const t = this.rapid, e = D(ft, t.maxTextureUnits), r = D(et, t.maxTextureUnits);
992
- return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1000
+ return this.vs = et, this.fs = ft, this.defaultShader = this.createShader(et, ft), this.defaultShader;
993
1001
  }
994
1002
  createShader(t, e) {
995
1003
  const r = super.createShader(t, e);
996
1004
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
997
- { name: "aMatrixRow0", size: 3, stride: $, offset: 0, divisor: 1 },
998
- { name: "aMatrixRow1", size: 3, stride: $, offset: 12, divisor: 1 },
999
- { name: "aUVRect", size: 4, stride: $, offset: 24, divisor: 1 },
1000
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: $, offset: 40, divisor: 1 },
1001
- { name: "aTextureId", size: 1, type: ot, stride: $, offset: 44, divisor: 1 }
1005
+ { name: "aMatrixRow0", size: 3, stride: Y, offset: 0, divisor: 1 },
1006
+ { name: "aMatrixRow1", size: 3, stride: Y, offset: 12, divisor: 1 },
1007
+ { name: "aUVRect", size: 4, stride: Y, offset: 24, divisor: 1 },
1008
+ { name: "aColor", size: 4, type: ot, normalized: !0, stride: Y, offset: 40, divisor: 1 },
1009
+ { name: "aTextureId", size: 1, type: ot, stride: Y, offset: 44, divisor: 1 }
1002
1010
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1003
1011
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1004
1012
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1005
1013
  }
1006
- createCustomShader(t) {
1007
- const e = D(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = D(et, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1008
- return t.getGLShader(this, this.KEY, r, e);
1009
- }
1010
1014
  drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, h = 4294967295, o = 0, c = 0, u = !1, l = !1, f = !1) {
1011
1015
  const d = e * 6, x = this.matrixStore.data;
1012
1016
  this.drawSpriteAffine(
@@ -1036,16 +1040,16 @@ class lt extends Mt {
1036
1040
  x / E.height
1037
1041
  ), b = this.instanceBuffer, M = b.usedElemNum;
1038
1042
  b.resize(12);
1039
- const C = b.float32, B = b.uint32, k = y ? _ : w, H = y ? w : _, I = k + 2 * d, F = H + 2 * x, X = L - d, z = W - x, R = this.localSpriteMatrix;
1040
- y ? (R[0] = 0, R[1] = v ? F : -F, R[2] = p ? -I : I, R[3] = 0, R[4] = X + (p ? I : 0), R[5] = z + (v ? 0 : F)) : (R[0] = p ? -I : I, R[1] = 0, R[2] = 0, R[3] = v ? -F : F, R[4] = X + (p ? I : 0), R[5] = z + (v ? F : 0));
1043
+ const C = b.float32, D = b.uint32, B = y ? _ : w, k = y ? w : _, I = B + 2 * d, F = k + 2 * x, V = L - d, z = W - x, R = this.localSpriteMatrix;
1044
+ y ? (R[0] = 0, R[1] = v ? F : -F, R[2] = p ? -I : I, R[3] = 0, R[4] = V + (p ? I : 0), R[5] = z + (v ? 0 : F)) : (R[0] = p ? -I : I, R[1] = 0, R[2] = 0, R[3] = v ? -F : F, R[4] = V + (p ? I : 0), R[5] = z + (v ? F : 0));
1041
1045
  const U = this.worldSpriteMatrix;
1042
- U[0] = e * R[0] + i * R[1], U[1] = r * R[0] + s * R[1], U[2] = e * R[2] + i * R[3], U[3] = r * R[2] + s * R[3], U[4] = a + e * R[4] + i * R[5], U[5] = h + r * R[4] + s * R[5], C[M + 6] = o, C[M + 7] = c, C[M + 8] = u, C[M + 9] = l, B[M + 10] = f, B[M + 11] = O, this.rapid.roundPixels && (U[4] = Math.round(U[4]), U[5] = Math.round(U[5])), C[M] = U[0], C[M + 1] = U[2], C[M + 2] = U[4], C[M + 3] = U[1], C[M + 4] = U[3], C[M + 5] = U[5], b.usedElemNum += 12, b.makeDirty(), this.instanceCount++;
1046
+ U[0] = e * R[0] + i * R[1], U[1] = r * R[0] + s * R[1], U[2] = e * R[2] + i * R[3], U[3] = r * R[2] + s * R[3], U[4] = a + e * R[4] + i * R[5], U[5] = h + r * R[4] + s * R[5], C[M + 6] = o, C[M + 7] = c, C[M + 8] = u, C[M + 9] = l, D[M + 10] = f, D[M + 11] = O, this.rapid.roundPixels && (U[4] = Math.round(U[4]), U[5] = Math.round(U[5])), C[M] = U[0], C[M + 1] = U[2], C[M + 2] = U[4], C[M + 3] = U[1], C[M + 4] = U[3], C[M + 5] = U[5], b.usedElemNum += 12, b.makeDirty(), this.instanceCount++;
1043
1047
  }
1044
1048
  render() {
1045
1049
  if (this.instanceCount === 0) return;
1046
1050
  this.prepareRender();
1047
1051
  const t = this.gl, e = this.currentShader;
1048
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Et(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1052
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1049
1053
  }
1050
1054
  resetRender() {
1051
1055
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1055,13 +1059,13 @@ class lt extends Mt {
1055
1059
  }
1056
1060
  }
1057
1061
  const T = 6;
1058
- class Ht {
1062
+ class Bt {
1059
1063
  matrixCount = 0;
1060
1064
  buffer;
1061
1065
  data;
1062
1066
  temporary = -1;
1063
1067
  constructor(t = 10) {
1064
- this.buffer = new A(S.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
1068
+ this.buffer = new S(A.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
1065
1069
  }
1066
1070
  alloc() {
1067
1071
  const t = this.allocDirty();
@@ -1165,15 +1169,15 @@ class Ht {
1165
1169
  l[u] = f * r + x * i, l[u + 1] = d * r + p * i, l[u + 2] = f * s + x * a, l[u + 3] = d * s + p * a, l[u + 4] = f * h + x * o + v, l[u + 5] = d * h + p * o + y;
1166
1170
  }
1167
1171
  }
1168
- class Gt {
1169
- matrix = new Ht();
1172
+ class kt {
1173
+ matrix = new Bt();
1170
1174
  step = 0;
1171
- stack = new A(S.Uint32);
1172
- stepWorldM = new A(S.Uint32);
1173
- stepAction = new A(S.Uint32);
1174
- stepParentM = new A(S.Uint32);
1175
- stepClose = new A(S.Uint32);
1176
- stepStack = new A(S.Uint32);
1175
+ stack = new S(A.Uint32);
1176
+ stepWorldM = new S(A.Uint32);
1177
+ stepAction = new S(A.Uint32);
1178
+ stepParentM = new S(A.Uint32);
1179
+ stepClose = new S(A.Uint32);
1180
+ stepStack = new S(A.Uint32);
1177
1181
  curLocalM = -1;
1178
1182
  curWorldM = -1;
1179
1183
  rapid;
@@ -1324,7 +1328,7 @@ class Gt {
1324
1328
  );
1325
1329
  }
1326
1330
  }
1327
- const Vt = `#version 300 es\r
1331
+ const Ht = `#version 300 es\r
1328
1332
  precision highp float;\r
1329
1333
  \r
1330
1334
  in vec2 aPosition;\r
@@ -1355,7 +1359,7 @@ void main(void) {\r
1355
1359
  // CUSTOM_CODE_CALL\r
1356
1360
  gl_Position = u_projection * position;\r
1357
1361
  }\r
1358
- `, Xt = `#version 300 es\r
1362
+ `, Gt = `#version 300 es\r
1359
1363
  precision mediump float;\r
1360
1364
  \r
1361
1365
  in vec4 vColor;\r
@@ -1363,6 +1367,7 @@ in vec2 vRegion;\r
1363
1367
  in vec4 vUVRect;\r
1364
1368
  \r
1365
1369
  uniform sampler2D uTexture;\r
1370
+ uniform sampler2D uTextures[%TEXTURE_NUM%];\r
1366
1371
  uniform int uUseTexture;\r
1367
1372
  \r
1368
1373
  out vec4 fragColor;\r
@@ -1401,7 +1406,7 @@ void main(void) {\r
1401
1406
  fragColor = sampleTexture(vRegion) * vColor;\r
1402
1407
  // CUSTOM_CODE_CALL\r
1403
1408
  }\r
1404
- `, Yt = `#version 300 es\r
1409
+ `, Vt = `#version 300 es\r
1405
1410
  precision highp float;\r
1406
1411
  \r
1407
1412
  in vec2 aPosition;\r
@@ -1424,7 +1429,7 @@ void main(void) {\r
1424
1429
  );\r
1425
1430
  gl_Position = u_projection * position;\r
1426
1431
  }\r
1427
- `, zt = `#version 300 es\r
1432
+ `, Xt = `#version 300 es\r
1428
1433
  precision mediump float;\r
1429
1434
  \r
1430
1435
  in vec2 vRegion;\r
@@ -1444,10 +1449,11 @@ void main(void) {\r
1444
1449
  discard;\r
1445
1450
  }\r
1446
1451
  }\r
1447
- `, j = 20;
1448
- class $t extends Mt {
1452
+ `, $ = 20;
1453
+ class zt extends Et {
1449
1454
  vertexBuffer;
1450
1455
  vertexCount = 0;
1456
+ extraTextureUnit = 1;
1451
1457
  matrixIndex = -1;
1452
1458
  drawMode = this.gl.TRIANGLES;
1453
1459
  texture;
@@ -1458,24 +1464,24 @@ class $t extends Mt {
1458
1464
  }
1459
1465
  createBuffer() {
1460
1466
  const t = this.gl;
1461
- this.vertexBuffer = new ut(t, S.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
1467
+ this.vertexBuffer = new ut(t, A.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Vt, Xt);
1462
1468
  }
1463
1469
  createDefaultShader() {
1464
- return this.vs = Vt, this.fs = Xt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1470
+ return this.vs = Ht, this.fs = Gt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1465
1471
  }
1466
1472
  createMaskShader(t, e) {
1467
- const r = this.gl, i = new Rt(r, t, e);
1473
+ const r = this.gl, i = new Tt(r, t, e);
1468
1474
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1469
- { name: "aPosition", size: 2, type: r.FLOAT, stride: j - 4, offset: 0, divisor: 0 },
1470
- { name: "aUV", size: 2, type: r.FLOAT, stride: j - 4, offset: 8, divisor: 0 }
1475
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: $ - 4, offset: 0, divisor: 0 },
1476
+ { name: "aUV", size: 2, type: r.FLOAT, stride: $ - 4, offset: 8, divisor: 0 }
1471
1477
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1472
1478
  }
1473
1479
  createShader(t, e) {
1474
1480
  const r = this.gl, i = super.createShader(t, e);
1475
1481
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1476
- { name: "aPosition", size: 2, type: r.FLOAT, stride: j, offset: 0, divisor: 0 },
1477
- { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: j, offset: 8, divisor: 0 },
1478
- { name: "aUV", size: 2, type: r.FLOAT, stride: j, offset: 12, divisor: 0 }
1482
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: $, offset: 0, divisor: 0 },
1483
+ { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: $, offset: 8, divisor: 0 },
1484
+ { name: "aUV", size: 2, type: r.FLOAT, stride: $, offset: 12, divisor: 0 }
1479
1485
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1480
1486
  }
1481
1487
  startGraphic(t, e = this.gl.TRIANGLES, r) {
@@ -1618,7 +1624,7 @@ class g {
1618
1624
  return new g(Math.cos(t), Math.sin(t));
1619
1625
  }
1620
1626
  }
1621
- const jt = (n, t) => {
1627
+ const Yt = (n, t) => {
1622
1628
  const [e, r, i, s, a, h] = t, o = new Float32Array([
1623
1629
  e,
1624
1630
  i,
@@ -1637,8 +1643,8 @@ const jt = (n, t) => {
1637
1643
  0,
1638
1644
  1
1639
1645
  ]);
1640
- return Kt(o, n);
1641
- }, Kt = (n, t) => {
1646
+ return $t(o, n);
1647
+ }, $t = (n, t) => {
1642
1648
  const e = new Float32Array(16);
1643
1649
  for (let r = 0; r < 4; r++)
1644
1650
  for (let i = 0; i < 4; i++) {
@@ -1649,7 +1655,7 @@ const jt = (n, t) => {
1649
1655
  }
1650
1656
  return e;
1651
1657
  };
1652
- var qt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(qt || {});
1658
+ var jt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(jt || {});
1653
1659
  const nt = 10, mt = (n, t, e, r, i, s) => {
1654
1660
  const a = [], h = [], o = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new g(t.y, -t.x);
1655
1661
  for (let l = 0; l < nt; l++) {
@@ -1657,7 +1663,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1657
1663
  a.push(n), h.push(new g(i, 0.5)), a.push(n.add(v)), h.push(new g(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e)), a.push(n.add(y)), h.push(new g(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e));
1658
1664
  }
1659
1665
  return { vertices: a, uv: h };
1660
- }, Qt = (n, t = !1) => {
1666
+ }, Kt = (n, t = !1) => {
1661
1667
  const e = [];
1662
1668
  if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
1663
1669
  const r = 4, i = 1e-3, s = n.length;
@@ -1697,18 +1703,18 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1697
1703
  } else
1698
1704
  e.push(h(n[o - 1], n[o], n[o + 1]));
1699
1705
  return { normals: e, length: a };
1700
- }, Zt = (n) => {
1706
+ }, qt = (n) => {
1701
1707
  const t = n.points;
1702
1708
  if (t.length < 2) return { vertices: [], uv: [] };
1703
- const { normals: e, length: r } = Qt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1709
+ const { normals: e, length: r } = Kt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1704
1710
  let c = 0;
1705
1711
  const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
1706
1712
  for (let f = 0; f < l; f++) {
1707
1713
  const d = t[f], x = e[f].normal, p = e[f].miters, v = (f + 1) % t.length, y = t[v], E = e[v].normal, w = e[v].miters, _ = d.add(x.multiply(p * i)), L = d.subtract(x.multiply(p * i)), W = y.add(E.multiply(w * i)), O = y.subtract(E.multiply(w * i)), b = d.distanceTo(y);
1708
1714
  let M = 0, C = 0;
1709
1715
  o === 0 ? (M = c / r, C = (c + b) / r) : (M = c / u, C = M + b / u);
1710
- const B = new g(M, 0), k = new g(M, 1), H = new g(C, 0), I = new g(C, 1);
1711
- s.push(_), a.push(B), s.push(L), a.push(k), s.push(W), a.push(H), s.push(W), a.push(H), s.push(O), a.push(I), s.push(L), a.push(k), c += b;
1716
+ const D = new g(M, 0), B = new g(M, 1), k = new g(C, 0), I = new g(C, 1);
1717
+ s.push(_), a.push(D), s.push(L), a.push(B), s.push(W), a.push(k), s.push(W), a.push(k), s.push(O), a.push(I), s.push(L), a.push(B), c += b;
1712
1718
  }
1713
1719
  if (h && !n.closed) {
1714
1720
  const f = t[0], d = e[0].normal, x = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, p = mt(f, d, i, !0, 0, x);
@@ -1736,7 +1742,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1736
1742
  i
1737
1743
  ), i;
1738
1744
  }
1739
- }, Jt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, te = 2, ee = (n, t) => {
1745
+ }, Qt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Zt = 2, Jt = (n, t) => {
1740
1746
  const e = Q(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
1741
1747
  if (!r?.base || n.inCreateMask)
1742
1748
  return;
@@ -1745,7 +1751,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1745
1751
  let s = r.uvX, a = r.uvY, h = r.uvW, o = r.uvH;
1746
1752
  const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
1747
1753
  let l = t.padding ?? i.currentShader.padding;
1748
- r.isAtlas && (l += te);
1754
+ r.isAtlas && (l += Zt);
1749
1755
  const f = s <= h ? l : -l, d = a <= o ? l : -l;
1750
1756
  i.drawSprite(
1751
1757
  r,
@@ -1761,7 +1767,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1761
1767
  u,
1762
1768
  r.isRotated
1763
1769
  );
1764
- }, re = (n, t) => {
1770
+ }, te = (n, t) => {
1765
1771
  const e = n.particleRegion;
1766
1772
  n.enterRegion(e, t.shader);
1767
1773
  const r = t.texture, i = t.count ?? t.x.length, s = t.color;
@@ -1787,7 +1793,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1787
1793
  t.reverseOrder,
1788
1794
  t.customMatrix
1789
1795
  );
1790
- }, wt = (n, t) => {
1796
+ }, Rt = (n, t) => {
1791
1797
  if (t.points.length === 0) return;
1792
1798
  const e = Q(n, t, 0, 0);
1793
1799
  n.startGraphic(
@@ -1807,17 +1813,17 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1807
1813
  );
1808
1814
  }
1809
1815
  n.endGraphic();
1810
- }, ie = (n, t) => {
1816
+ }, ee = (n, t) => {
1811
1817
  if (n.inCreateMask)
1812
1818
  return;
1813
- const { vertices: e, uv: r } = Zt(t);
1814
- wt(n, {
1819
+ const { vertices: e, uv: r } = qt(t);
1820
+ Rt(n, {
1815
1821
  ...t,
1816
1822
  points: e,
1817
1823
  uv: r,
1818
1824
  drawMode: n.gl.TRIANGLES
1819
1825
  });
1820
- }, se = (n, t) => {
1826
+ }, re = (n, t) => {
1821
1827
  const e = Q(
1822
1828
  n,
1823
1829
  t,
@@ -1829,7 +1835,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1829
1835
  t.texture,
1830
1836
  e ?? t.customMatrix
1831
1837
  ), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
1832
- }, ne = (n, t) => {
1838
+ }, ie = (n, t) => {
1833
1839
  const e = Q(n, t, t.width, t.height);
1834
1840
  n.startGraphic(
1835
1841
  n.gl.TRIANGLE_FAN,
@@ -1837,7 +1843,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1837
1843
  t.shader,
1838
1844
  e ?? t.customMatrix
1839
1845
  ), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
1840
- }, ae = (n, t) => {
1846
+ }, se = (n, t) => {
1841
1847
  const e = t.segments ?? 32, r = Q(n, t, 0, 0);
1842
1848
  n.startGraphic(
1843
1849
  n.gl.TRIANGLE_FAN,
@@ -1891,21 +1897,16 @@ void main(void) {\r
1891
1897
  // CUSTOM_CODE_CALL\r
1892
1898
  }\r
1893
1899
  `;
1894
- class he extends lt {
1900
+ class ne extends lt {
1895
1901
  KEY = "AtlasSprite";
1896
1902
  constructor(t) {
1897
1903
  super(t);
1898
1904
  }
1899
- createCustomShader(t) {
1900
- const e = D(xt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = D(et, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1901
- return t.getGLShader(this, this.KEY, r, e);
1902
- }
1903
1905
  createDefaultShader() {
1904
- const t = this.rapid, e = D(xt, t.maxTextureUnits), r = D(et, t.maxTextureUnits);
1905
- return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1906
+ return this.vs = et, this.fs = xt, this.defaultShader = this.createShader(et, xt), this.defaultShader;
1906
1907
  }
1907
1908
  }
1908
- const gt = `#version 300 es\r
1909
+ const ae = `#version 300 es\r
1909
1910
  precision highp float;\r
1910
1911
  \r
1911
1912
  // per-vertex\r
@@ -1932,23 +1933,21 @@ void main(void) {\r
1932
1933
  vColor = aColor;\r
1933
1934
  \r
1934
1935
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
1935
- // CUSTOM_CODE_CALL\r
1936
1936
  \r
1937
1937
  vec2 scaled = (aVertex - aOrigin) * aScale;\r
1938
1938
  float c = cos(aRotation);\r
1939
1939
  float s = sin(aRotation);\r
1940
1940
  \r
1941
- vec2 position = vec2(\r
1942
- scaled.x * c - scaled.y * s,\r
1943
- scaled.x * s + scaled.y * c\r
1944
- ) + aPosition;\r
1941
+ vec4 position = vec4(mat2(c, s, -s, c) * scaled + aPosition, 0.0, 1.0);\r
1942
+ // CUSTOM_CODE_CALL\r
1945
1943
  \r
1946
- gl_Position = u_projection * vec4(position, 0.0, 1.0);\r
1944
+ gl_Position = u_projection * position;\r
1947
1945
  }\r
1948
- `, pt = `#version 300 es\r
1946
+ `, he = `#version 300 es\r
1949
1947
  precision mediump float;\r
1950
1948
  \r
1951
1949
  uniform sampler2D uTexture;\r
1950
+ uniform sampler2D uTextures[%TEXTURE_NUM%];\r
1952
1951
  \r
1953
1952
  in vec2 vRegion;\r
1954
1953
  in vec4 vColor;\r
@@ -1961,20 +1960,18 @@ void main(void) {\r
1961
1960
  \r
1962
1961
  // CUSTOM_CODE_CALL\r
1963
1962
  }\r
1964
- `, G = 48, oe = G / 4;
1963
+ `, H = 48, oe = H / 4;
1965
1964
  class ce extends lt {
1966
1965
  KEY = "ParticleSprite";
1967
1966
  texture;
1968
1967
  customMatrix;
1969
1968
  particleLoopCache = /* @__PURE__ */ new Map();
1969
+ extraTextureUnit = 1;
1970
1970
  constructor(t) {
1971
1971
  super(t);
1972
1972
  }
1973
- createCustomShader(t) {
1974
- return t.getGLShader(this, this.KEY, gt, pt);
1975
- }
1976
1973
  createDefaultShader() {
1977
- const t = pt, e = gt;
1974
+ const t = he, e = ae;
1978
1975
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
1979
1976
  }
1980
1977
  enter(t) {
@@ -1983,12 +1980,12 @@ class ce extends lt {
1983
1980
  createShader(t, e) {
1984
1981
  const r = super.createShader(t, e);
1985
1982
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1986
- { name: "aPosition", size: 2, stride: G, offset: 0, divisor: 1 },
1987
- { name: "aScale", size: 2, stride: G, offset: 8, divisor: 1 },
1988
- { name: "aRotation", size: 1, stride: G, offset: 16, divisor: 1 },
1989
- { name: "aUVRect", size: 4, stride: G, offset: 20, divisor: 1 },
1990
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: G, offset: 36, divisor: 1 },
1991
- { name: "aOrigin", size: 2, stride: G, offset: 40, divisor: 1 }
1983
+ { name: "aPosition", size: 2, stride: H, offset: 0, divisor: 1 },
1984
+ { name: "aScale", size: 2, stride: H, offset: 8, divisor: 1 },
1985
+ { name: "aRotation", size: 1, stride: H, offset: 16, divisor: 1 },
1986
+ { name: "aUVRect", size: 4, stride: H, offset: 20, divisor: 1 },
1987
+ { name: "aColor", size: 4, type: ot, normalized: !0, stride: H, offset: 36, divisor: 1 },
1988
+ { name: "aOrigin", size: 2, stride: H, offset: 40, divisor: 1 }
1992
1989
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1993
1990
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1994
1991
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
@@ -1996,11 +1993,11 @@ class ce extends lt {
1996
1993
  drawParticles(t, e, r, i = 0, s = 4294967295, a, h = 1, o = 1, c = 0, u = 0, l = 1, f = 1, d = !1, x = !1, p = !1, v = 0.5, y = 0.5, E, w = !1, _) {
1997
1994
  if (!t.glTexture || a <= 0) return;
1998
1995
  this.texture && t !== this.texture && this.flush();
1999
- const L = typeof h == "number", W = typeof o == "number", O = typeof i == "number", b = typeof s == "number", M = typeof c == "number", C = !b && typeof s[0] == "number", B = t.uvW - t.uvX, k = t.uvH - t.uvY, H = B === 0 ? 0 : 1 / B, I = k === 0 ? 0 : 1 / k;
1996
+ const L = typeof h == "number", W = typeof o == "number", O = typeof i == "number", b = typeof s == "number", M = typeof c == "number", C = !b && typeof s[0] == "number", D = t.uvW - t.uvX, B = t.uvH - t.uvY, k = D === 0 ? 0 : 1 / D, I = B === 0 ? 0 : 1 / B;
2000
1997
  let F = t.rawWidth * (d ? -1 : 1);
2001
1998
  L && (F *= h);
2002
- let X = t.rawHeight * (x ? -1 : 1);
2003
- W && (X *= o), M && (F *= (l - c) * H, X *= (f - u) * I);
1999
+ let V = t.rawHeight * (x ? -1 : 1);
2000
+ W && (V *= o), M && (F *= (l - c) * k, V *= (f - u) * I);
2004
2001
  let z = p ? Math.PI / 2 : 0;
2005
2002
  O && (z += i);
2006
2003
  const R = s ?? 4294967295, U = this.getParticleLoop(
@@ -2014,10 +2011,10 @@ class ce extends lt {
2014
2011
  E
2015
2012
  );
2016
2013
  this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2017
- const it = a, Y = this.instanceBuffer;
2018
- let st = Y.usedElemNum;
2019
- Y.resize(it * oe);
2020
- const bt = Y.float32, Ut = Y.uint32;
2014
+ const it = a, X = this.instanceBuffer;
2015
+ let st = X.usedElemNum;
2016
+ X.resize(it * oe);
2017
+ const At = X.float32, St = X.uint32;
2021
2018
  st = U(
2022
2019
  e,
2023
2020
  r,
@@ -2029,11 +2026,11 @@ class ce extends lt {
2029
2026
  l,
2030
2027
  f,
2031
2028
  s,
2032
- bt,
2033
- Ut,
2029
+ At,
2030
+ St,
2034
2031
  F,
2035
- X,
2036
- H,
2032
+ V,
2033
+ k,
2037
2034
  I,
2038
2035
  z,
2039
2036
  R,
@@ -2042,7 +2039,7 @@ class ce extends lt {
2042
2039
  a,
2043
2040
  it,
2044
2041
  st
2045
- ), Y.usedElemNum = st, Y.makeDirty(), this.instanceCount += it, this.customMatrix = _, this.flush();
2042
+ ), X.usedElemNum = st, X.makeDirty(), this.instanceCount += it, this.customMatrix = _, this.flush();
2046
2043
  }
2047
2044
  getParticleLoop(t, e, r, i, s, a, h, o) {
2048
2045
  const c = [...arguments].join("_");
@@ -2098,11 +2095,11 @@ return idx;
2098
2095
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2099
2096
  const e = this.currentShader;
2100
2097
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2101
- const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
2102
- this.currentShader.setUniform("u_projection", a), Et(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2098
+ const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = Yt(this.rapid.projection, s);
2099
+ this.currentShader.setUniform("u_projection", a), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2103
2100
  }
2104
2101
  }
2105
- var St = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(St || {}), ue = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(ue || {}), le = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(le || {});
2102
+ var Mt = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(Mt || {}), ue = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(ue || {}), le = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(le || {});
2106
2103
  class pe {
2107
2104
  gl;
2108
2105
  canvas;
@@ -2116,7 +2113,7 @@ class pe {
2116
2113
  physicsHeight = 0;
2117
2114
  currentRegion = null;
2118
2115
  maxTextureUnits = 0;
2119
- matrixStack = new Gt(this);
2116
+ matrixStack = new kt(this);
2120
2117
  matrix;
2121
2118
  spriteRegion;
2122
2119
  graphicRegion;
@@ -2140,37 +2137,37 @@ class pe {
2140
2137
  }
2141
2138
  constructor(t) {
2142
2139
  this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? tt.NEAREST, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
2143
- const e = Nt(this.canvas, this.antialias, this.premultipliedAlpha);
2144
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new lt(this), this.graphicRegion = new $t(this), this.atlasSpriteRegion = new he(this), this.particleRegion = new ce(this);
2140
+ const e = Lt(this.canvas, this.antialias, this.premultipliedAlpha);
2141
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new lt(this), this.graphicRegion = new zt(this), this.atlasSpriteRegion = new ne(this), this.particleRegion = new ce(this);
2145
2142
  const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2146
- 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 Ct(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);
2143
+ 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);
2147
2144
  }
2148
2145
  setTextureFilter(t) {
2149
2146
  this.textureFilter = t;
2150
2147
  }
2151
2148
  getColorUint32(t) {
2152
- return Jt(this.premultipliedAlpha, t);
2149
+ return Qt(this.premultipliedAlpha, t);
2153
2150
  }
2154
2151
  enterRegion(t, e) {
2155
2152
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2156
2153
  }
2157
2154
  drawParticles(t) {
2158
- re(this, t);
2155
+ te(this, t);
2159
2156
  }
2160
2157
  drawSprite(t) {
2161
- ee(this, t);
2158
+ Jt(this, t);
2162
2159
  }
2163
2160
  drawLine(t) {
2164
- ie(this, t);
2161
+ ee(this, t);
2165
2162
  }
2166
2163
  drawGraphic(t) {
2167
- wt(this, t);
2164
+ Rt(this, t);
2168
2165
  }
2169
2166
  drawRect(t) {
2170
- ne(this, t);
2167
+ ie(this, t);
2171
2168
  }
2172
2169
  drawCircle(t) {
2173
- ae(this, t);
2170
+ se(this, t);
2174
2171
  }
2175
2172
  startGraphic(t = this.gl.TRIANGLES, e, r, i) {
2176
2173
  this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
@@ -2179,7 +2176,7 @@ class pe {
2179
2176
  this.startGraphic(t, e, this.graphicRegion.maskShader, r);
2180
2177
  }
2181
2178
  drawMaskImage(t) {
2182
- se(this, t);
2179
+ re(this, t);
2183
2180
  }
2184
2181
  addRectVertex(t, e, r) {
2185
2182
  const i = this.getColorUint32(r);
@@ -2445,16 +2442,16 @@ class P {
2445
2442
  }
2446
2443
  const Z = (n, t) => (Array.isArray(n) ? n : [n]).slice(0, t);
2447
2444
  var fe = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(fe || {});
2448
- const vt = 10, yt = 0, Tt = !0;
2449
- class K {
2445
+ const gt = 10, pt = 0, vt = !0;
2446
+ class j {
2450
2447
  components;
2451
2448
  constructor(t = 1) {
2452
2449
  if (!Number.isInteger(t) || t <= 0)
2453
2450
  throw new RangeError("ParticleAttributeStore size must be a positive integer");
2454
2451
  this.components = Array.from({ length: t }, () => ({
2455
- value: new A(S.Float32),
2456
- delta: new A(S.Float32),
2457
- damping: new A(S.Float32)
2452
+ value: new S(A.Float32),
2453
+ delta: new S(A.Float32),
2454
+ damping: new S(A.Float32)
2458
2455
  }));
2459
2456
  }
2460
2457
  getArrayBuffer() {
@@ -2502,32 +2499,32 @@ class K {
2502
2499
  return h;
2503
2500
  }
2504
2501
  }
2505
- class At {
2502
+ class wt {
2506
2503
  options;
2507
2504
  emitting = !1;
2508
2505
  emitTimer = 0;
2509
- emitRate = vt;
2510
- emitTime = yt;
2506
+ emitRate = gt;
2507
+ emitTime = pt;
2511
2508
  emitTimeCounter = 0;
2512
- localSpace = Tt;
2509
+ localSpace = vt;
2513
2510
  rapid;
2514
- x = new A(S.Float32);
2515
- y = new A(S.Float32);
2516
- scaleX = new A(S.Float32);
2517
- scaleY = new A(S.Float32);
2518
- rotation = new A(S.Float32);
2519
- color = new A(S.Uint32);
2520
- remainingLife = new A(S.Float32);
2511
+ x = new S(A.Float32);
2512
+ y = new S(A.Float32);
2513
+ scaleX = new S(A.Float32);
2514
+ scaleY = new S(A.Float32);
2515
+ rotation = new S(A.Float32);
2516
+ color = new S(A.Uint32);
2517
+ remainingLife = new S(A.Float32);
2521
2518
  animations = {
2522
- speed: new K(),
2523
- rotation: new K(),
2524
- scale: new K(),
2525
- color: new K(4),
2526
- velocity: new K(2)
2519
+ speed: new j(),
2520
+ rotation: new j(),
2521
+ scale: new j(),
2522
+ color: new j(4),
2523
+ velocity: new j(2)
2527
2524
  };
2528
2525
  count = 0;
2529
2526
  constructor(t, e) {
2530
- this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? vt, this.emitTime = e.emitTime ?? yt, this.localSpace = e.localSpace ?? Tt;
2527
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? gt, this.emitTime = e.emitTime ?? pt, this.localSpace = e.localSpace ?? vt;
2531
2528
  }
2532
2529
  getAllArrayBuffer() {
2533
2530
  return [
@@ -2545,7 +2542,7 @@ class At {
2545
2542
  this.options.texture = t;
2546
2543
  }
2547
2544
  clone() {
2548
- return new At(this.rapid, { ...this.options });
2545
+ return new wt(this.rapid, { ...this.options });
2549
2546
  }
2550
2547
  setEmitRate(t) {
2551
2548
  this.emitRate = t;
@@ -2613,7 +2610,7 @@ class At {
2613
2610
  r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
2614
2611
  }
2615
2612
  const e = this.updateParticle(t);
2616
- this.count -= e.length, A.removeAtIndices(e, this.getAllArrayBuffer());
2613
+ this.count -= e.length, S.removeAtIndices(e, this.getAllArrayBuffer());
2617
2614
  }
2618
2615
  updateParticle(t) {
2619
2616
  const e = [], r = this.animations;
@@ -2671,13 +2668,15 @@ uniform mat3x2 uLightMatrix[%TEXTURE_NUM%];
2671
2668
  uniform float uLightHeight[%TEXTURE_NUM%];
2672
2669
  uniform float uMetallic;
2673
2670
  uniform float uRoughness;
2671
+ uniform vec3 uAmbientColor;
2672
+ uniform vec2 uNormalScale;
2674
2673
 
2675
2674
  void light_fragment(inout vec4 color, in vec2 vRegion) {
2676
2675
  if (color.a < 0.005) return;
2677
2676
 
2678
- // 屏幕坐标映射到世界坐标
2679
2677
  vec2 worldPos = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) * (uLogicalResolution / uResolution);
2680
- vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0) * vec3(1.0, -1.0, 1.0);
2678
+ vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0);
2679
+ normal = normalize(normal * vec3(uNormalScale, 1.0));
2681
2680
 
2682
2681
  vec3 totalDiffuse = vec3(0.0);
2683
2682
  vec3 totalSpecular = vec3(0.0);
@@ -2692,11 +2691,8 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
2692
2691
  mat2 lightBasis = mat2(uLightMatrix[i][0], uLightMatrix[i][1]);
2693
2692
  vec2 lightUV = inverse(lightBasis) * (worldPos - lightPos) + 0.5;
2694
2693
 
2695
- // 判断当前像素是否在该光源范围内
2696
2694
  if (lightUV.x >= 0.0 && lightUV.x <= 1.0 && lightUV.y >= 0.0 && lightUV.y <= 1.0) {
2697
2695
 
2698
- // ⭐️ 核心修复:sampler2DArray 采样必须传 vec3
2699
- // 第三个分量是该光源对应的图层 ID (转为 float)
2700
2696
  int layer = uLightTextureId[i];
2701
2697
  vec4 lightTex;
2702
2698
  %GET_COLOR%
@@ -2711,20 +2707,23 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
2711
2707
  }
2712
2708
  }
2713
2709
 
2714
- // 环境光 + 漫反射 + 高光
2715
- color.rgb = color.rgb * (vec3(0.1, 0.1, 0.15) + totalDiffuse) + totalSpecular;
2710
+ color.rgb = color.rgb * (uAmbientColor + totalDiffuse) + totalSpecular;
2716
2711
  }
2717
2712
  `, xe = "void light_vertex(inout vec4 p, vec2 u) {}", J = 8;
2718
2713
  class ge extends ct {
2719
2714
  constructor(t, e = "", r = "", i = 0, s) {
2720
2715
  super(
2721
2716
  t,
2722
- e + xe,
2723
- D(r + me, t.maxTextureUnits - 1, "layer", "lightUV", "lightTex = "),
2724
- i + 1,
2717
+ e,
2718
+ r,
2719
+ i + 2,
2725
2720
  s
2726
2721
  ), this.prefix.push("light_");
2727
2722
  }
2723
+ getGLShader(t, e, r, i) {
2724
+ const s = K(me, t.getMaxTexutreUnit(this), "layer", "lightUV", "lightTex = ");
2725
+ return i = this.replaceCustomCode(i, s), r = this.replaceCustomCode(r, xe), super.getGLShader(t, e, r, i);
2726
+ }
2728
2727
  }
2729
2728
  class ve {
2730
2729
  shader;
@@ -2756,7 +2755,7 @@ class ve {
2756
2755
  i.endGraphic();
2757
2756
  }, () => {
2758
2757
  i.drawSprite({ texture: t });
2759
- }, St.NOT_EQUAL);
2758
+ }, Mt.NOT_EQUAL);
2760
2759
  }), this.rt;
2761
2760
  }
2762
2761
  setupLight(t) {
@@ -2776,34 +2775,44 @@ class ve {
2776
2775
  })),
2777
2776
  uLightHeight: Float32Array.from(r.map((h, o) => s[o] ?? s[0] ?? 80)),
2778
2777
  uMetallic: t.metallic ?? 0.8,
2779
- uRoughness: t.roughness ?? 0.15
2778
+ uRoughness: t.roughness ?? 0.15,
2779
+ uAmbientColor: t.ambientColor ? [t.ambientColor.r / 255, t.ambientColor.g / 255, t.ambientColor.b / 255] : [0.1, 0.1, 0.15],
2780
+ uNormalScale: [t.normalScaleX ?? 1, t.normalScaleY ?? 1]
2780
2781
  }), e;
2781
2782
  }
2782
2783
  }
2783
2784
  export {
2784
- V as BaseTexture,
2785
+ G as BaseTexture,
2785
2786
  ue as BlendMode,
2786
2787
  le as CanvasScaleMode,
2787
2788
  m as Color,
2788
2789
  ct as CustomGlShader,
2789
- Rt as GLShader,
2790
+ Tt as GLShader,
2790
2791
  ve as Light,
2791
2792
  ge as LightShader,
2792
- qt as LineTextureMode,
2793
+ jt as LineTextureMode,
2793
2794
  J as MAX_LIGHTS,
2794
- St as MaskType,
2795
- At as ParticleEmitter,
2795
+ Mt as MaskType,
2796
+ wt as ParticleEmitter,
2796
2797
  fe as ParticleShape,
2797
2798
  pe as Rapid,
2798
- _t as RenderTexture,
2799
- Pt as TextTexture,
2799
+ Ut as RenderTexture,
2800
+ _t as TextTexture,
2800
2801
  N as Texture,
2801
2802
  tt as TextureFilterMode,
2802
- Ct as TextureManager,
2803
+ bt as TextureManager,
2803
2804
  q as TextureWrapMode,
2804
2805
  g as Vec2,
2805
- jt as composeProjectionWithAffine,
2806
- Zt as getLineGeometry,
2807
- Qt as getLineNormal,
2808
- Kt as multiplyMat4
2806
+ Yt as composeProjectionWithAffine,
2807
+ se as drawCircle,
2808
+ Rt as drawGraphic,
2809
+ ee as drawLine,
2810
+ re as drawMaskImage,
2811
+ te as drawParticles,
2812
+ ie as drawRect,
2813
+ Jt as drawSprite,
2814
+ Qt as getColorUint32,
2815
+ qt as getLineGeometry,
2816
+ Kt as getLineNormal,
2817
+ $t as multiplyMat4
2809
2818
  };