rapid-render 1.0.21 → 1.0.23
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 +7 -28
- package/dist/color.d.ts +1 -1
- package/dist/draw.d.ts +2 -2
- package/dist/extensions/light.d.ts +1 -0
- package/dist/extensions/particle.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/matrix-engine.d.ts +25 -31
- package/dist/rapid-render.js +846 -673
- package/dist/rapid-render.umd.cjs +26 -20
- package/dist/region/spriteRegion.d.ts +1 -1
- package/dist/render.d.ts +17 -19
- package/dist/texture.d.ts +11 -2
- package/dist/viewport.d.ts +52 -0
- package/dist/webgl/glshader.d.ts +2 -0
- package/dist/webgl/utils.d.ts +1 -2
- package/package.json +1 -1
- package/dist/texture-filter-mode.d.ts +0 -5
package/dist/rapid-render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class g {
|
|
2
2
|
_r;
|
|
3
3
|
_g;
|
|
4
4
|
_b;
|
|
@@ -11,8 +11,14 @@ class m {
|
|
|
11
11
|
constructor(t, e, r, i = 255) {
|
|
12
12
|
this._r = t, this._g = e, this._b = r, this._a = i, this.updateUint();
|
|
13
13
|
}
|
|
14
|
-
setClearColor(t) {
|
|
15
|
-
|
|
14
|
+
setClearColor(t, e = !0) {
|
|
15
|
+
const r = e ? this.premultipliedUint32 : this.uint32;
|
|
16
|
+
t.clearColor(
|
|
17
|
+
(r & 255) / 255,
|
|
18
|
+
(r >>> 8 & 255) / 255,
|
|
19
|
+
(r >>> 16 & 255) / 255,
|
|
20
|
+
(r >>> 24) / 255
|
|
21
|
+
);
|
|
16
22
|
}
|
|
17
23
|
get r() {
|
|
18
24
|
return this._r;
|
|
@@ -40,7 +46,7 @@ class m {
|
|
|
40
46
|
}
|
|
41
47
|
updateUint() {
|
|
42
48
|
this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
|
|
43
|
-
const t =
|
|
49
|
+
const t = g.clampByte(this._a), e = g.clampByte(this._r * t / 255), r = g.clampByte(this._g * t / 255), i = g.clampByte(this._b * t / 255);
|
|
44
50
|
this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
|
|
45
51
|
}
|
|
46
52
|
reset() {
|
|
@@ -52,14 +58,14 @@ class m {
|
|
|
52
58
|
setHSL(t, e, r) {
|
|
53
59
|
t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100, r = Math.max(0, Math.min(100, r)) / 100;
|
|
54
60
|
const i = (1 - Math.abs(2 * r - 1)) * e, s = i * (1 - Math.abs(t / 60 % 2 - 1)), a = r - i / 2;
|
|
55
|
-
let
|
|
56
|
-
return t < 60 ? [
|
|
61
|
+
let o = 0, h = 0, c = 0;
|
|
62
|
+
return t < 60 ? [o, h, c] = [i, s, 0] : t < 120 ? [o, h, c] = [s, i, 0] : t < 180 ? [o, h, c] = [0, i, s] : t < 240 ? [o, h, c] = [0, s, i] : t < 300 ? [o, h, c] = [s, 0, i] : [o, h, c] = [i, 0, s], this.setRGBA((o + a) * 255, (h + a) * 255, (c + a) * 255, 255), this;
|
|
57
63
|
}
|
|
58
64
|
copy(t) {
|
|
59
65
|
this.setRGBA(t.r, t.g, t.b, t.a);
|
|
60
66
|
}
|
|
61
67
|
clone() {
|
|
62
|
-
return new
|
|
68
|
+
return new g(this._r, this._g, this._b, this._a);
|
|
63
69
|
}
|
|
64
70
|
toHexString(t = !0) {
|
|
65
71
|
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"), s = this.a.toString(16).padStart(2, "0");
|
|
@@ -69,13 +75,13 @@ class m {
|
|
|
69
75
|
return t.r === this.r && t.g === this.g && t.b === this.b && t.a === this.a;
|
|
70
76
|
}
|
|
71
77
|
static FromHSL(t, e, r) {
|
|
72
|
-
return new
|
|
78
|
+
return new g(0, 0, 0).setHSL(t, e, r);
|
|
73
79
|
}
|
|
74
80
|
static FromRGB(t, e, r) {
|
|
75
|
-
return new
|
|
81
|
+
return new g(t, e, r);
|
|
76
82
|
}
|
|
77
83
|
static fromNorm(t, e, r, i = 1) {
|
|
78
|
-
return new
|
|
84
|
+
return new g(
|
|
79
85
|
Math.round(t * 255),
|
|
80
86
|
Math.round(e * 255),
|
|
81
87
|
Math.round(r * 255),
|
|
@@ -83,17 +89,17 @@ class m {
|
|
|
83
89
|
);
|
|
84
90
|
}
|
|
85
91
|
static packColor(t, e, r, i, s) {
|
|
86
|
-
const a =
|
|
87
|
-
return (a << 24 | u << 16 | c << 8 |
|
|
92
|
+
const a = g.clampByte(i), o = s ? a / 255 : 1, h = g.clampByte(t * o), c = g.clampByte(e * o), u = g.clampByte(r * o);
|
|
93
|
+
return (a << 24 | u << 16 | c << 8 | h) >>> 0;
|
|
88
94
|
}
|
|
89
95
|
static fromHex(t) {
|
|
90
96
|
t.startsWith("#") && (t = t.slice(1));
|
|
91
97
|
const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
|
|
92
98
|
let s = 255;
|
|
93
|
-
return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new
|
|
99
|
+
return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new g(e, r, i, s);
|
|
94
100
|
}
|
|
95
101
|
add(t) {
|
|
96
|
-
return new
|
|
102
|
+
return new g(
|
|
97
103
|
Math.min(this.r + t.r, 255),
|
|
98
104
|
Math.min(this.g + t.g, 255),
|
|
99
105
|
Math.min(this.b + t.b, 255),
|
|
@@ -101,7 +107,7 @@ class m {
|
|
|
101
107
|
);
|
|
102
108
|
}
|
|
103
109
|
subtract(t) {
|
|
104
|
-
return new
|
|
110
|
+
return new g(
|
|
105
111
|
this.r - t.r,
|
|
106
112
|
this.g - t.g,
|
|
107
113
|
this.b - t.b,
|
|
@@ -109,12 +115,12 @@ class m {
|
|
|
109
115
|
);
|
|
110
116
|
}
|
|
111
117
|
divide(t) {
|
|
112
|
-
return t instanceof
|
|
118
|
+
return t instanceof g ? new g(
|
|
113
119
|
this.r / t.r,
|
|
114
120
|
this.g / t.g,
|
|
115
121
|
this.b / t.b,
|
|
116
122
|
this.a / t.a
|
|
117
|
-
) : new
|
|
123
|
+
) : new g(
|
|
118
124
|
this.r / t,
|
|
119
125
|
this.g / t,
|
|
120
126
|
this.b / t,
|
|
@@ -122,12 +128,12 @@ class m {
|
|
|
122
128
|
);
|
|
123
129
|
}
|
|
124
130
|
multiply(t) {
|
|
125
|
-
return t instanceof
|
|
131
|
+
return t instanceof g ? new g(
|
|
126
132
|
this.r * t.r,
|
|
127
133
|
this.g * t.g,
|
|
128
134
|
this.b * t.b,
|
|
129
135
|
this.a * t.a
|
|
130
|
-
) : new
|
|
136
|
+
) : new g(
|
|
131
137
|
this.r * t,
|
|
132
138
|
this.g * t,
|
|
133
139
|
this.b * t,
|
|
@@ -137,55 +143,62 @@ class m {
|
|
|
137
143
|
clamp() {
|
|
138
144
|
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)), this.updateUint();
|
|
139
145
|
}
|
|
140
|
-
static Red = new
|
|
141
|
-
static Green = new
|
|
142
|
-
static Blue = new
|
|
143
|
-
static Yellow = new
|
|
144
|
-
static Purple = new
|
|
145
|
-
static Orange = new
|
|
146
|
-
static Pink = new
|
|
147
|
-
static Gray = new
|
|
148
|
-
static Brown = new
|
|
149
|
-
static Cyan = new
|
|
150
|
-
static Magenta = new
|
|
151
|
-
static Lime = new
|
|
152
|
-
static White = new
|
|
153
|
-
static Black = new
|
|
154
|
-
static Transparent = new
|
|
146
|
+
static Red = new g(255, 0, 0, 255);
|
|
147
|
+
static Green = new g(0, 255, 0, 255);
|
|
148
|
+
static Blue = new g(0, 0, 255, 255);
|
|
149
|
+
static Yellow = new g(255, 255, 0, 255);
|
|
150
|
+
static Purple = new g(128, 0, 128, 255);
|
|
151
|
+
static Orange = new g(255, 165, 0, 255);
|
|
152
|
+
static Pink = new g(255, 192, 203, 255);
|
|
153
|
+
static Gray = new g(128, 128, 128, 255);
|
|
154
|
+
static Brown = new g(139, 69, 19, 255);
|
|
155
|
+
static Cyan = new g(0, 255, 255, 255);
|
|
156
|
+
static Magenta = new g(255, 0, 255, 255);
|
|
157
|
+
static Lime = new g(192, 255, 0, 255);
|
|
158
|
+
static White = new g(255, 255, 255, 255);
|
|
159
|
+
static Black = new g(0, 0, 0, 255);
|
|
160
|
+
static Transparent = new g(0, 0, 0, 0);
|
|
155
161
|
}
|
|
156
|
-
var
|
|
157
|
-
class
|
|
162
|
+
var it = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(it || {}), J = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(J || {});
|
|
163
|
+
class Ct {
|
|
158
164
|
render;
|
|
159
165
|
cache = /* @__PURE__ */ new Map();
|
|
166
|
+
texture = /* @__PURE__ */ new Set();
|
|
160
167
|
constructor(t) {
|
|
161
168
|
this.render = t;
|
|
162
169
|
}
|
|
170
|
+
addTexture(t) {
|
|
171
|
+
return this.texture.add(t), t;
|
|
172
|
+
}
|
|
173
|
+
removeTexture(t) {
|
|
174
|
+
return this.texture.delete(t), t;
|
|
175
|
+
}
|
|
163
176
|
async load(t, e) {
|
|
164
177
|
let r = this.cache.get(t);
|
|
165
178
|
if (r)
|
|
166
|
-
return new
|
|
179
|
+
return this.addTexture(new W(r));
|
|
167
180
|
try {
|
|
168
181
|
const i = await this._fetchImage(t);
|
|
169
|
-
return r =
|
|
182
|
+
return r = z.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), this.addTexture(new W(r));
|
|
170
183
|
} catch (i) {
|
|
171
184
|
throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
|
|
172
185
|
}
|
|
173
186
|
}
|
|
174
187
|
create(t, e) {
|
|
175
188
|
if (e?.key && this.cache.has(e.key))
|
|
176
|
-
return new
|
|
177
|
-
const r =
|
|
178
|
-
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new
|
|
189
|
+
return this.addTexture(new W(this.cache.get(e.key)));
|
|
190
|
+
const r = z.fromSource(this.render, t, e);
|
|
191
|
+
return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), this.addTexture(new W(r));
|
|
179
192
|
}
|
|
180
193
|
createRenderTexture(t) {
|
|
181
|
-
return new
|
|
194
|
+
return this.addTexture(new _t(this.render, t));
|
|
182
195
|
}
|
|
183
196
|
createTextTexture(t) {
|
|
184
|
-
return new
|
|
197
|
+
return this.addTexture(new Lt(this.render, t));
|
|
185
198
|
}
|
|
186
199
|
destroy(t, e = !1) {
|
|
187
200
|
let r, i;
|
|
188
|
-
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof
|
|
201
|
+
typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof W ? (r = t.base, i = r?.uid, this.removeTexture(t), t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
|
|
189
202
|
}
|
|
190
203
|
destroyAll() {
|
|
191
204
|
for (const t of this.cache.values())
|
|
@@ -199,7 +212,7 @@ class bt {
|
|
|
199
212
|
});
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
|
-
class
|
|
215
|
+
class z {
|
|
203
216
|
glTexture = null;
|
|
204
217
|
width;
|
|
205
218
|
height;
|
|
@@ -209,23 +222,23 @@ class X {
|
|
|
209
222
|
this.glTexture = t, this.width = e, this.height = r;
|
|
210
223
|
}
|
|
211
224
|
static fromSource(t, e, r = {}) {
|
|
212
|
-
const i =
|
|
213
|
-
return new
|
|
225
|
+
const i = nt(t, e, r);
|
|
226
|
+
return new z(i, e.width, e.height);
|
|
214
227
|
}
|
|
215
228
|
updateSource(t, e, r = {}) {
|
|
216
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && ht(t, r.textureFilter), r.wrap !== void 0 &&
|
|
229
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && ht(t, r.textureFilter), r.wrap !== void 0 && ot(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));
|
|
217
230
|
}
|
|
218
231
|
setFilterMode(t, e) {
|
|
219
232
|
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), ht(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
220
233
|
}
|
|
221
234
|
setWrapMode(t, e) {
|
|
222
|
-
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture),
|
|
235
|
+
this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), ot(t, e), t.bindTexture(t.TEXTURE_2D, null));
|
|
223
236
|
}
|
|
224
237
|
destroy(t) {
|
|
225
238
|
this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
|
|
226
239
|
}
|
|
227
240
|
}
|
|
228
|
-
class
|
|
241
|
+
class W {
|
|
229
242
|
base;
|
|
230
243
|
uvX = 0;
|
|
231
244
|
uvY = 0;
|
|
@@ -252,6 +265,8 @@ class F {
|
|
|
252
265
|
constructor(t) {
|
|
253
266
|
t && this.setBase(t);
|
|
254
267
|
}
|
|
268
|
+
updateResolution() {
|
|
269
|
+
}
|
|
255
270
|
setBase(t) {
|
|
256
271
|
return this.base === t ? this : (this.base && this.base.refCount--, this.base = t, this.base.refCount++, this.setRegion(0, 0, t.width, t.height), this.glTexture = t.glTexture, this);
|
|
257
272
|
}
|
|
@@ -259,41 +274,42 @@ class F {
|
|
|
259
274
|
return this.base ? (this._px = t, this._py = e, this.isAtlas = t !== 0 || e !== 0 || r !== this.base.width || i !== this.base.height, this.uvX = t / this.base.width, this.uvY = e / this.base.height, this.uvW = this.uvX + r / this.base.width, this.uvH = this.uvY + i / this.base.height, this.rawWidth = r * this.scale, this.rawHeight = i * this.scale, this) : this;
|
|
260
275
|
}
|
|
261
276
|
getSubTexture(t, e, r, i) {
|
|
262
|
-
if (!this.base) return new
|
|
263
|
-
const s = this.clone(), a = this._px,
|
|
264
|
-
return s.setRegion(a + t,
|
|
277
|
+
if (!this.base) return new W();
|
|
278
|
+
const s = this.clone(), a = this._px, o = this._py;
|
|
279
|
+
return s.setRegion(a + t, o + e, r, i), s;
|
|
265
280
|
}
|
|
266
281
|
clone(t) {
|
|
267
|
-
const e = t ?? new
|
|
282
|
+
const e = t ?? new W(this.base);
|
|
268
283
|
return t && this.base && t.setBase(this.base), e.scale = this.scale, e.uvX = this.uvX, e.uvY = this.uvY, e.uvW = this.uvW, e.uvH = this.uvH, e.rawWidth = this.rawWidth, e.rawHeight = this.rawHeight, e.offsetX = this.offsetX, e.offsetY = this.offsetY, e.flipY = this.flipY, e.isRotated = this.isRotated, e.isAtlas = this.isAtlas, e._px = this._px, e._py = this._py, e;
|
|
269
284
|
}
|
|
270
285
|
splitGrid(t, e, r, i, s = 0) {
|
|
271
286
|
if (!this.base) return [];
|
|
272
|
-
const a = [],
|
|
273
|
-
for (let
|
|
274
|
-
for (let
|
|
275
|
-
a.push(this.getSubTexture(
|
|
287
|
+
const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((o + c) / u), f = i ?? Math.floor((h + c) / l);
|
|
288
|
+
for (let m = 0; m < f; m++)
|
|
289
|
+
for (let x = 0; x < d; x++)
|
|
290
|
+
a.push(this.getSubTexture(x * u, m * l, t, e));
|
|
276
291
|
return a;
|
|
277
292
|
}
|
|
278
293
|
static fromImageSource(t, e, r = {}) {
|
|
279
|
-
const i =
|
|
280
|
-
return new
|
|
294
|
+
const i = nt(t, e, r);
|
|
295
|
+
return new W(new z(i, e.width, e.height));
|
|
281
296
|
}
|
|
282
297
|
destroy() {
|
|
283
298
|
this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
|
|
284
299
|
}
|
|
285
300
|
}
|
|
286
|
-
class
|
|
301
|
+
class _t extends W {
|
|
287
302
|
framebuffer;
|
|
288
303
|
renderbuffer;
|
|
289
304
|
gl;
|
|
305
|
+
premultipliedAlpha;
|
|
290
306
|
clearColor;
|
|
291
307
|
_allocW = 0;
|
|
292
308
|
_allocH = 0;
|
|
293
309
|
constructor(t, e) {
|
|
294
|
-
super(), this.gl = t.gl, this.clearColor = e.clearColor ??
|
|
295
|
-
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a =
|
|
296
|
-
if (this.setBase(new
|
|
310
|
+
super(), this.gl = t.gl, this.premultipliedAlpha = t.premultipliedAlpha, this.clearColor = e.clearColor ?? g.Black;
|
|
311
|
+
const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = nt(t, { width: r, height: i }, { ...e, onlySize: !0 });
|
|
312
|
+
if (this.setBase(new z(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
|
|
297
313
|
throw new Error("Failed to create Framebuffer or Renderbuffer");
|
|
298
314
|
this.resize(r, i, !0);
|
|
299
315
|
}
|
|
@@ -312,7 +328,7 @@ class Ut extends F {
|
|
|
312
328
|
clear(t) {
|
|
313
329
|
if (!this.framebuffer) return;
|
|
314
330
|
const e = this.gl, r = t ?? this.clearColor;
|
|
315
|
-
r && (r.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
|
|
331
|
+
r && (r.setClearColor(e, this.premultipliedAlpha), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
|
|
316
332
|
}
|
|
317
333
|
deactivate() {
|
|
318
334
|
const t = this.gl;
|
|
@@ -320,24 +336,24 @@ class Ut extends F {
|
|
|
320
336
|
}
|
|
321
337
|
GetPixels(t = 0, e = 0, r = this.rawWidth, i = this.rawHeight) {
|
|
322
338
|
if (!this.framebuffer) return new Uint8Array(0);
|
|
323
|
-
const s = Math.floor(t), a = Math.floor(e),
|
|
324
|
-
if (
|
|
339
|
+
const s = Math.floor(t), a = Math.floor(e), o = Math.floor(r), h = Math.floor(i);
|
|
340
|
+
if (o <= 0 || h <= 0) return new Uint8Array(0);
|
|
325
341
|
if (s < 0 || a < 0 || s >= this.rawWidth || a >= this.rawHeight)
|
|
326
342
|
return new Uint8Array(0);
|
|
327
|
-
const c = Math.min(
|
|
343
|
+
const c = Math.min(o, this.rawWidth - s), u = Math.min(h, this.rawHeight - a), l = this.gl, d = l.getParameter(l.FRAMEBUFFER_BINDING);
|
|
328
344
|
l.bindFramebuffer(l.FRAMEBUFFER, this.framebuffer);
|
|
329
|
-
const
|
|
330
|
-
return l.readPixels(s, a, c, u, l.RGBA, l.UNSIGNED_BYTE,
|
|
345
|
+
const f = new Uint8Array(c * u * 4);
|
|
346
|
+
return l.readPixels(s, a, c, u, l.RGBA, l.UNSIGNED_BYTE, f), l.bindFramebuffer(l.FRAMEBUFFER, d), f;
|
|
331
347
|
}
|
|
332
348
|
GetColorAt(t, e) {
|
|
333
349
|
const r = this.GetPixels(t, e, 1, 1);
|
|
334
|
-
return r.length < 4 ? new
|
|
350
|
+
return r.length < 4 ? new g(0, 0, 0, 0) : new g(r[0], r[1], r[2], r[3]);
|
|
335
351
|
}
|
|
336
352
|
destroy() {
|
|
337
353
|
super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
|
|
338
354
|
}
|
|
339
355
|
}
|
|
340
|
-
const
|
|
356
|
+
const Pt = {
|
|
341
357
|
fontFamily: "Arial",
|
|
342
358
|
fontSize: 24,
|
|
343
359
|
fontWeight: "normal",
|
|
@@ -346,21 +362,26 @@ const Ct = {
|
|
|
346
362
|
align: "left",
|
|
347
363
|
lineHeight: 1
|
|
348
364
|
};
|
|
349
|
-
class
|
|
365
|
+
class Lt extends W {
|
|
350
366
|
canvas;
|
|
351
367
|
ctx;
|
|
352
368
|
render;
|
|
353
369
|
_text;
|
|
354
370
|
_style;
|
|
355
371
|
options;
|
|
356
|
-
|
|
372
|
+
resolution = 1;
|
|
357
373
|
constructor(t, e) {
|
|
358
|
-
super(), this.render = t, this._style = { ...
|
|
374
|
+
super(), this.render = t, this._style = { ...Pt, ...e }, this._text = e?.text ?? "", this.options = {
|
|
375
|
+
premultipliedAlpha: t.premultipliedAlpha,
|
|
376
|
+
...e,
|
|
377
|
+
textureFilter: 1
|
|
378
|
+
/* NEAREST */
|
|
379
|
+
}, this.canvas = document.createElement("canvas");
|
|
359
380
|
const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
|
|
360
381
|
if (!r) throw new Error("Failed to get 2d context for TextTexture");
|
|
361
382
|
this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
|
|
362
|
-
const i =
|
|
363
|
-
this.setBase(new
|
|
383
|
+
const i = nt(t, this.canvas, this.options);
|
|
384
|
+
this.setBase(new z(i, 1, 1)), this.updateResolution(), this.update();
|
|
364
385
|
}
|
|
365
386
|
get text() {
|
|
366
387
|
return this._text;
|
|
@@ -384,42 +405,44 @@ class _t extends F {
|
|
|
384
405
|
return e;
|
|
385
406
|
}
|
|
386
407
|
}
|
|
408
|
+
updateResolution() {
|
|
409
|
+
let t = 1;
|
|
410
|
+
t *= this.render.viewport.resolution, t != this.resolution && (this.resolution = t, this.update());
|
|
411
|
+
}
|
|
387
412
|
update() {
|
|
388
|
-
const t = this.ctx, e = this.style, r =
|
|
389
|
-
`),
|
|
390
|
-
t.font =
|
|
391
|
-
let
|
|
392
|
-
for (const
|
|
393
|
-
const
|
|
394
|
-
|
|
413
|
+
const t = this.ctx, e = this.style, r = e.fontSize, i = e.fontWeight, s = e.fontFamily, a = e.lineHeight, h = Math.max(r, 32), c = r / h, u = `${i} ${r}px ${s}`, l = `${i} ${h}px ${s}`, d = this.resolution, f = e.baseline ?? "top", m = e.align ?? "left", x = e.strokeThickness ?? 0, y = x > 0, v = this._text.split(`
|
|
414
|
+
`), T = "国g", w = v[0] || T;
|
|
415
|
+
t.font = l, t.textBaseline = "alphabetic", t.textAlign = "left";
|
|
416
|
+
let U = 0, P = 0, O = 0;
|
|
417
|
+
for (const B of v) {
|
|
418
|
+
const X = t.measureText(B || T);
|
|
419
|
+
U = Math.max(U, B ? X.width * c : 0), B == v.at(0) && (P = X.actualBoundingBoxAscent * c), B == v.at(-1) && (O = X.actualBoundingBoxDescent * c);
|
|
395
420
|
}
|
|
396
421
|
t.textBaseline = "alphabetic";
|
|
397
|
-
const
|
|
398
|
-
t.textBaseline =
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
),
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0,
|
|
413
|
-
const W = _ - S;
|
|
414
|
-
this.offsetY = -I - v + W;
|
|
422
|
+
const L = t.measureText(w).fontBoundingBoxDescent * c;
|
|
423
|
+
t.textBaseline = f;
|
|
424
|
+
const S = t.measureText(w).fontBoundingBoxDescent * c, E = r * a, b = P + O + (v.length - 1) * E, I = x / 2 + 2 / d, k = U + I * 2, G = b + I * 2, N = Math.max(1, Math.ceil(k * d)), F = Math.max(1, Math.ceil(G * d)), V = N / d;
|
|
425
|
+
(this.canvas.width !== N || this.canvas.height !== F) && (this.canvas.width = N, this.canvas.height = F), t.setTransform(d, 0, 0, -d, 0, F), t.clearRect(
|
|
426
|
+
0,
|
|
427
|
+
0,
|
|
428
|
+
N / d,
|
|
429
|
+
F / d
|
|
430
|
+
), t.font = u, t.textBaseline = "alphabetic", t.textAlign = m;
|
|
431
|
+
const H = this.updateOffset(V, I);
|
|
432
|
+
y && (t.lineWidth = x, t.strokeStyle = e.stroke ?? "#000000", t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
|
|
433
|
+
let A = I + P;
|
|
434
|
+
for (const B of v)
|
|
435
|
+
y && t.strokeText(B, H, A), e.fill && t.fillText(B, H, A), A += E;
|
|
436
|
+
const $ = S - L;
|
|
437
|
+
this.scale = 1 / this.resolution, this.offsetX = -H, this.offsetY = -I - P + $, this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, N, F);
|
|
415
438
|
}
|
|
416
439
|
}
|
|
417
|
-
const
|
|
440
|
+
const Nt = (n, t = !1, e = !0) => {
|
|
418
441
|
const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
|
|
419
442
|
if (!r)
|
|
420
443
|
throw new Error("WebGL2 is not supported in this browser.");
|
|
421
444
|
return r;
|
|
422
|
-
},
|
|
445
|
+
}, ft = (n, t, e) => {
|
|
423
446
|
const r = n.createShader(e);
|
|
424
447
|
if (!r)
|
|
425
448
|
throw new Error("Unable to create webgl shader");
|
|
@@ -428,36 +451,36 @@ const Lt = (n, t = !1, e = !0) => {
|
|
|
428
451
|
throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
|
|
429
452
|
}
|
|
430
453
|
return r;
|
|
431
|
-
},
|
|
432
|
-
var r = n.createProgram(), i =
|
|
454
|
+
}, It = (n, t, e) => {
|
|
455
|
+
var r = n.createProgram(), i = ft(n, t, 35633), s = ft(n, e, 35632);
|
|
433
456
|
if (!r)
|
|
434
457
|
throw new Error("Unable to create program shader");
|
|
435
458
|
if (n.attachShader(r, i), n.attachShader(r, s), n.linkProgram(r), !n.getProgramParameter(r, n.LINK_STATUS)) {
|
|
436
|
-
const
|
|
437
|
-
throw new Error("Unable to link shader program: " +
|
|
459
|
+
const o = n.getProgramInfoLog(r);
|
|
460
|
+
throw new Error("Unable to link shader program: " + o);
|
|
438
461
|
}
|
|
439
462
|
return r;
|
|
440
463
|
};
|
|
441
|
-
function
|
|
464
|
+
function ot(n, t) {
|
|
442
465
|
const e = {
|
|
443
|
-
[
|
|
444
|
-
[
|
|
445
|
-
[
|
|
466
|
+
[J.CLAMP]: n.CLAMP_TO_EDGE,
|
|
467
|
+
[J.REPEAT]: n.REPEAT,
|
|
468
|
+
[J.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
|
|
446
469
|
}[t] || n.CLAMP_TO_EDGE;
|
|
447
470
|
n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, e);
|
|
448
471
|
}
|
|
449
472
|
function ht(n, t) {
|
|
450
473
|
const e = {
|
|
451
|
-
[
|
|
452
|
-
[
|
|
474
|
+
[it.LINEAR]: n.LINEAR,
|
|
475
|
+
[it.NEAREST]: n.NEAREST
|
|
453
476
|
}[t] ?? n.NEAREST;
|
|
454
477
|
n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e);
|
|
455
478
|
}
|
|
456
|
-
function
|
|
479
|
+
function nt(n, t, e) {
|
|
457
480
|
const r = n.gl, i = r.createTexture();
|
|
458
481
|
if (!i)
|
|
459
482
|
throw new Error("Unable to create WebGL texture");
|
|
460
|
-
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1),
|
|
483
|
+
if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), ot(r, e.wrap ?? J.CLAMP), ht(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
|
|
461
484
|
const s = t;
|
|
462
485
|
r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, s.width, s.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
|
|
463
486
|
} else {
|
|
@@ -466,7 +489,7 @@ function rt(n, t, e) {
|
|
|
466
489
|
}
|
|
467
490
|
return r.bindTexture(r.TEXTURE_2D, null), i;
|
|
468
491
|
}
|
|
469
|
-
function
|
|
492
|
+
function Z(n, t, e = "vTextureId", r = "uv", i = "return") {
|
|
470
493
|
if (n.includes("%TEXTURE_NUM%") && (n = n.replaceAll("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
|
|
471
494
|
let s = "";
|
|
472
495
|
for (let a = 0; a < t; a++)
|
|
@@ -475,15 +498,15 @@ function K(n, t, e = "vTextureId", r = "uv", i = "return") {
|
|
|
475
498
|
}
|
|
476
499
|
return n;
|
|
477
500
|
}
|
|
478
|
-
const
|
|
479
|
-
function
|
|
501
|
+
const Ft = 5126, ct = 5121;
|
|
502
|
+
function Ot(n, t, e) {
|
|
480
503
|
n.vertexAttribDivisor(t, e);
|
|
481
504
|
}
|
|
482
|
-
function
|
|
505
|
+
function wt(n, t, e, r, i) {
|
|
483
506
|
n.drawArraysInstanced(t, e, r, i);
|
|
484
507
|
}
|
|
485
|
-
let
|
|
486
|
-
class
|
|
508
|
+
let Bt = 0;
|
|
509
|
+
class Et {
|
|
487
510
|
program;
|
|
488
511
|
attributeLoc = {};
|
|
489
512
|
uniformLoc = {};
|
|
@@ -492,11 +515,11 @@ class Tt {
|
|
|
492
515
|
uniformType = {};
|
|
493
516
|
uniformIsArray = {};
|
|
494
517
|
gl;
|
|
495
|
-
shaderId =
|
|
518
|
+
shaderId = Bt++;
|
|
496
519
|
// for debug
|
|
497
520
|
vao;
|
|
498
521
|
constructor(t, e, r, i) {
|
|
499
|
-
this.gl = t, this.program =
|
|
522
|
+
this.gl = t, this.program = It(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
|
|
500
523
|
}
|
|
501
524
|
use() {
|
|
502
525
|
this.gl.useProgram(this.program);
|
|
@@ -512,7 +535,7 @@ class Tt {
|
|
|
512
535
|
const r = this.uniformLoc[t];
|
|
513
536
|
if (r === void 0) return;
|
|
514
537
|
const i = this.uniformType[t], s = this.uniformIsArray[t];
|
|
515
|
-
|
|
538
|
+
Dt(this.gl, r, i, e, s);
|
|
516
539
|
}
|
|
517
540
|
setUniforms(t) {
|
|
518
541
|
for (const e in t)
|
|
@@ -526,11 +549,11 @@ class Tt {
|
|
|
526
549
|
r.vertexAttribPointer(
|
|
527
550
|
e,
|
|
528
551
|
t.size,
|
|
529
|
-
t.type ??
|
|
552
|
+
t.type ?? Ft,
|
|
530
553
|
t.normalized ?? !1,
|
|
531
554
|
t.stride,
|
|
532
555
|
t.offset ?? 0
|
|
533
|
-
), r.enableVertexAttribArray(e),
|
|
556
|
+
), r.enableVertexAttribArray(e), Ot(r, e, t.divisor ?? 0);
|
|
534
557
|
}
|
|
535
558
|
setAttributes(t) {
|
|
536
559
|
for (const e of t)
|
|
@@ -544,19 +567,19 @@ class Tt {
|
|
|
544
567
|
const e = this.gl, r = t.match(/(?:in|attribute)\s+\w+\s+\w+/g);
|
|
545
568
|
if (r)
|
|
546
569
|
for (const s of r) {
|
|
547
|
-
const
|
|
548
|
-
|
|
570
|
+
const o = s.split(/\s+/)[2], h = e.getAttribLocation(this.program, o);
|
|
571
|
+
h !== -1 && (this.attributeLoc[o] = h);
|
|
549
572
|
}
|
|
550
573
|
const i = t.matchAll(
|
|
551
574
|
/uniform\s+(?:(?:lowp|mediump|highp)\s+)?(\w+)\s+(\w+)(\s*\[\s*\d+\s*\])?/g
|
|
552
575
|
);
|
|
553
576
|
for (const s of i) {
|
|
554
|
-
const a = s[1],
|
|
555
|
-
|
|
577
|
+
const a = s[1], o = s[2], h = e.getUniformLocation(this.program, o);
|
|
578
|
+
h !== null && (this.uniformLoc[o] = h, this.uniformType[o] = a, this.uniformIsArray[o] = s[3] !== void 0);
|
|
556
579
|
}
|
|
557
580
|
}
|
|
558
581
|
}
|
|
559
|
-
function
|
|
582
|
+
function Dt(n, t, e, r, i = !1) {
|
|
560
583
|
switch (e) {
|
|
561
584
|
// scalars
|
|
562
585
|
case "float":
|
|
@@ -594,10 +617,10 @@ function Wt(n, t, e, r, i = !1) {
|
|
|
594
617
|
return n.uniformMatrix3x2fv(t, !1, r);
|
|
595
618
|
// fallback: guess by value shape
|
|
596
619
|
default:
|
|
597
|
-
return
|
|
620
|
+
return Wt(n, t, r);
|
|
598
621
|
}
|
|
599
622
|
}
|
|
600
|
-
function
|
|
623
|
+
function Wt(n, t, e) {
|
|
601
624
|
if (typeof e == "number")
|
|
602
625
|
return n.uniform1f(t, e);
|
|
603
626
|
const r = e;
|
|
@@ -616,7 +639,7 @@ function Dt(n, t, e) {
|
|
|
616
639
|
return n.uniform1fv(t, r);
|
|
617
640
|
}
|
|
618
641
|
}
|
|
619
|
-
class
|
|
642
|
+
class ut {
|
|
620
643
|
vs;
|
|
621
644
|
fs;
|
|
622
645
|
glshader = /* @__PURE__ */ new Map();
|
|
@@ -629,7 +652,11 @@ class ct {
|
|
|
629
652
|
rapid;
|
|
630
653
|
prefix = [];
|
|
631
654
|
constructor(t, e = "", r = "", i = 0, s) {
|
|
632
|
-
this.vs = e, this.fs = r, this.rapid = t, this.uniforms = s ?? {}, this.usedTextureUnitNum = i;
|
|
655
|
+
this.vs = e, this.fs = r, this.rapid = t, this.uniforms = s ?? {}, this.usedTextureUnitNum = i, this.beforePreCompile(), this.preCompile();
|
|
656
|
+
}
|
|
657
|
+
beforePreCompile() {
|
|
658
|
+
}
|
|
659
|
+
preCompile() {
|
|
633
660
|
}
|
|
634
661
|
setUniforms(t) {
|
|
635
662
|
this.rapid.flush();
|
|
@@ -659,7 +686,7 @@ class ct {
|
|
|
659
686
|
if (i == null || r == null)
|
|
660
687
|
return console.warn("CustomGlShader: missing base shader for " + e), null;
|
|
661
688
|
const s = this.prefix.length == 0 ? [""] : this.prefix;
|
|
662
|
-
r = r.replace("// CUSTOM_CODE_CALL", s.map((
|
|
689
|
+
r = r.replace("// CUSTOM_CODE_CALL", s.map((o) => o + "vertex(position, vRegion);").join("")), r = this.replaceCustomCode(r, this.vs), i = i.replace("// CUSTOM_CODE_CALL", s.map((o) => o + "fragment(fragColor, vRegion);").join("")), i = this.replaceCustomCode(i, this.fs);
|
|
663
690
|
const a = t.createShader(r, i);
|
|
664
691
|
return a.isCustom = !0, a.padding = this.padding, this.glshader.set(e, a), this.uniformDirty.add(e), a;
|
|
665
692
|
}
|
|
@@ -667,7 +694,7 @@ class ct {
|
|
|
667
694
|
this.glshader.forEach((t) => t.destroy());
|
|
668
695
|
}
|
|
669
696
|
}
|
|
670
|
-
class
|
|
697
|
+
class Rt {
|
|
671
698
|
constructor(t) {
|
|
672
699
|
this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
|
|
673
700
|
}
|
|
@@ -715,16 +742,16 @@ class Et {
|
|
|
715
742
|
}
|
|
716
743
|
createShader(t, e) {
|
|
717
744
|
const r = this.getMaxTexutreUnit();
|
|
718
|
-
return e =
|
|
745
|
+
return e = Z(e, r), t = Z(t, r), new Et(this.gl, t, e);
|
|
719
746
|
}
|
|
720
747
|
createCustomShader(t) {
|
|
721
|
-
const e = this.getMaxTexutreUnit(t), r =
|
|
748
|
+
const e = this.getMaxTexutreUnit(t), r = Z(this.fs, e), i = Z(this.vs, e);
|
|
722
749
|
return t.getGLShader(this, this.KEY, i, r);
|
|
723
750
|
}
|
|
724
751
|
getCustomShader(t) {
|
|
725
752
|
if (!t)
|
|
726
753
|
return this.defaultShader;
|
|
727
|
-
if (t instanceof
|
|
754
|
+
if (t instanceof ut) {
|
|
728
755
|
const e = this.createCustomShader(t);
|
|
729
756
|
return e ?? this.defaultShader;
|
|
730
757
|
}
|
|
@@ -734,7 +761,7 @@ class Et {
|
|
|
734
761
|
return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
|
|
735
762
|
}
|
|
736
763
|
enter(t) {
|
|
737
|
-
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof
|
|
764
|
+
this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ut ? (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);
|
|
738
765
|
}
|
|
739
766
|
exit() {
|
|
740
767
|
this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
|
|
@@ -752,7 +779,7 @@ class Et {
|
|
|
752
779
|
for (const [s, a] of Object.entries(r.uniformTextures))
|
|
753
780
|
i[s] = this.useTexture(a);
|
|
754
781
|
for (const [s, a] of Object.entries(r.uniformArrayTexture))
|
|
755
|
-
i[s] = a.map((
|
|
782
|
+
i[s] = a.map((o) => this.useTexture(o));
|
|
756
783
|
this.customShader.applyUniform(this.KEY, i);
|
|
757
784
|
}
|
|
758
785
|
const e = this.gl;
|
|
@@ -776,8 +803,8 @@ class Et {
|
|
|
776
803
|
return !1;
|
|
777
804
|
}
|
|
778
805
|
}
|
|
779
|
-
var
|
|
780
|
-
class
|
|
806
|
+
var C = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(C || {});
|
|
807
|
+
class _ {
|
|
781
808
|
usedElemNum;
|
|
782
809
|
typedArray;
|
|
783
810
|
arrayType;
|
|
@@ -819,24 +846,24 @@ class b {
|
|
|
819
846
|
this.usedElemNum = 0;
|
|
820
847
|
}
|
|
821
848
|
static removeAtIndices(t, e) {
|
|
822
|
-
const r = Math.max(...e.map((
|
|
823
|
-
(
|
|
824
|
-
).sort((
|
|
849
|
+
const r = Math.max(...e.map((o) => o.usedElemNum)), i = [...new Set(t)].filter(
|
|
850
|
+
(o) => o >= 0 && o < r
|
|
851
|
+
).sort((o, h) => o - h);
|
|
825
852
|
if (i.length === 0)
|
|
826
853
|
return 0;
|
|
827
854
|
let s = 0, a = 0;
|
|
828
|
-
for (let
|
|
829
|
-
if (a < i.length &&
|
|
855
|
+
for (let o = 0; o < r; o++) {
|
|
856
|
+
if (a < i.length && o === i[a]) {
|
|
830
857
|
a++;
|
|
831
858
|
continue;
|
|
832
859
|
}
|
|
833
|
-
if (s !==
|
|
834
|
-
for (const
|
|
835
|
-
|
|
860
|
+
if (s !== o)
|
|
861
|
+
for (const h of e)
|
|
862
|
+
h.typedArray[s] = h.typedArray[o];
|
|
836
863
|
s++;
|
|
837
864
|
}
|
|
838
|
-
for (const
|
|
839
|
-
|
|
865
|
+
for (const o of e)
|
|
866
|
+
o.usedElemNum = s;
|
|
840
867
|
return r - s;
|
|
841
868
|
}
|
|
842
869
|
resize(t = 0) {
|
|
@@ -876,7 +903,7 @@ class b {
|
|
|
876
903
|
return this.usedElemNum;
|
|
877
904
|
}
|
|
878
905
|
}
|
|
879
|
-
class
|
|
906
|
+
class lt extends _ {
|
|
880
907
|
buffer;
|
|
881
908
|
gl;
|
|
882
909
|
dirty = !0;
|
|
@@ -902,7 +929,7 @@ class ut extends b {
|
|
|
902
929
|
}
|
|
903
930
|
}
|
|
904
931
|
}
|
|
905
|
-
const
|
|
932
|
+
const st = `#version 300 es\r
|
|
906
933
|
precision highp float;\r
|
|
907
934
|
\r
|
|
908
935
|
// per-vertex\r
|
|
@@ -950,7 +977,7 @@ void main(void) {\r
|
|
|
950
977
|
\r
|
|
951
978
|
gl_Position = u_projection * position;\r
|
|
952
979
|
}\r
|
|
953
|
-
`,
|
|
980
|
+
`, mt = `#version 300 es\r
|
|
954
981
|
precision mediump float;\r
|
|
955
982
|
\r
|
|
956
983
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -987,8 +1014,8 @@ void main(void) {\r
|
|
|
987
1014
|
\r
|
|
988
1015
|
// CUSTOM_CODE_CALL\r
|
|
989
1016
|
}\r
|
|
990
|
-
`,
|
|
991
|
-
class
|
|
1017
|
+
`, j = 48, kt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
|
|
1018
|
+
class dt extends Rt {
|
|
992
1019
|
instanceBuffer;
|
|
993
1020
|
quadBuffer;
|
|
994
1021
|
instanceCount = 0;
|
|
@@ -1000,64 +1027,64 @@ class lt extends Et {
|
|
|
1000
1027
|
}
|
|
1001
1028
|
createBuffer() {
|
|
1002
1029
|
const t = this.gl;
|
|
1003
|
-
this.quadBuffer = new
|
|
1004
|
-
for (const e of
|
|
1005
|
-
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new
|
|
1030
|
+
this.quadBuffer = new lt(t, C.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
|
|
1031
|
+
for (const e of kt) this.quadBuffer.pushFloat32(e);
|
|
1032
|
+
this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new lt(t, C.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
|
|
1006
1033
|
}
|
|
1007
1034
|
createDefaultShader() {
|
|
1008
|
-
return this.vs =
|
|
1035
|
+
return this.vs = st, this.fs = mt, this.defaultShader = this.createShader(st, mt), this.defaultShader;
|
|
1009
1036
|
}
|
|
1010
1037
|
createShader(t, e) {
|
|
1011
1038
|
const r = super.createShader(t, e);
|
|
1012
1039
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
1013
|
-
{ name: "aMatrixRow0", size: 3, stride:
|
|
1014
|
-
{ name: "aMatrixRow1", size: 3, stride:
|
|
1015
|
-
{ name: "aUVRect", size: 4, stride:
|
|
1016
|
-
{ name: "aColor", size: 4, type:
|
|
1017
|
-
{ name: "aTextureId", size: 1, type:
|
|
1040
|
+
{ name: "aMatrixRow0", size: 3, stride: j, offset: 0, divisor: 1 },
|
|
1041
|
+
{ name: "aMatrixRow1", size: 3, stride: j, offset: 12, divisor: 1 },
|
|
1042
|
+
{ name: "aUVRect", size: 4, stride: j, offset: 24, divisor: 1 },
|
|
1043
|
+
{ name: "aColor", size: 4, type: ct, normalized: !0, stride: j, offset: 40, divisor: 1 },
|
|
1044
|
+
{ name: "aTextureId", size: 1, type: ct, stride: j, offset: 44, divisor: 1 }
|
|
1018
1045
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
1019
1046
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1020
1047
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
1021
1048
|
}
|
|
1022
|
-
drawSprite(t, e, r = 0, i = 0, s = 1, a = 1,
|
|
1023
|
-
const
|
|
1049
|
+
drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, l = !1, d = !1) {
|
|
1050
|
+
const f = e * 6, m = this.matrixStore.data;
|
|
1024
1051
|
this.drawSpriteAffine(
|
|
1025
1052
|
t,
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1053
|
+
m[f],
|
|
1054
|
+
m[f + 1],
|
|
1055
|
+
m[f + 2],
|
|
1056
|
+
m[f + 3],
|
|
1057
|
+
m[f + 4],
|
|
1058
|
+
m[f + 5],
|
|
1032
1059
|
r,
|
|
1033
1060
|
i,
|
|
1034
1061
|
s,
|
|
1035
1062
|
a,
|
|
1036
|
-
h,
|
|
1037
1063
|
o,
|
|
1064
|
+
h,
|
|
1038
1065
|
c,
|
|
1039
1066
|
u,
|
|
1040
1067
|
l,
|
|
1041
|
-
|
|
1068
|
+
d
|
|
1042
1069
|
);
|
|
1043
1070
|
}
|
|
1044
|
-
drawSpriteAffine(t, e, r, i, s, a,
|
|
1045
|
-
const
|
|
1071
|
+
drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, x = !1, y = !1, v = !1) {
|
|
1072
|
+
const T = t.base, w = t.rawWidth, U = t.rawHeight, P = t.offsetX, O = t.offsetY, L = this.useTexture(
|
|
1046
1073
|
t.glTexture,
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
),
|
|
1050
|
-
|
|
1051
|
-
const
|
|
1052
|
-
v ? (
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1074
|
+
f / T.width,
|
|
1075
|
+
m / T.height
|
|
1076
|
+
), S = this.instanceBuffer, E = S.usedElemNum;
|
|
1077
|
+
S.resize(12);
|
|
1078
|
+
const b = S.float32, I = S.uint32, k = v ? U : w, G = v ? w : U, N = k + 2 * f, F = G + 2 * m, V = P - f, H = O - m, R = this.localSpriteMatrix;
|
|
1079
|
+
v ? (R[0] = 0, R[1] = y ? F : -F, R[2] = x ? -N : N, R[3] = 0, R[4] = V + (x ? N : 0), R[5] = H + (y ? 0 : F)) : (R[0] = x ? -N : N, R[1] = 0, R[2] = 0, R[3] = y ? -F : F, R[4] = V + (x ? N : 0), R[5] = H + (y ? F : 0));
|
|
1080
|
+
const A = this.worldSpriteMatrix;
|
|
1081
|
+
A[0] = e * R[0] + i * R[1], A[1] = r * R[0] + s * R[1], A[2] = e * R[2] + i * R[3], A[3] = r * R[2] + s * R[3], A[4] = a + e * R[4] + i * R[5], A[5] = o + r * R[4] + s * R[5], b[E + 6] = h, b[E + 7] = c, b[E + 8] = u, b[E + 9] = l, I[E + 10] = d, I[E + 11] = L, this.rapid.roundPixels && (A[4] = Math.round(A[4]), A[5] = Math.round(A[5])), b[E] = A[0], b[E + 1] = A[2], b[E + 2] = A[4], b[E + 3] = A[1], b[E + 4] = A[3], b[E + 5] = A[5], S.usedElemNum += 12, S.makeDirty(), this.instanceCount++;
|
|
1055
1082
|
}
|
|
1056
1083
|
render() {
|
|
1057
1084
|
if (this.instanceCount === 0) return;
|
|
1058
1085
|
this.prepareRender();
|
|
1059
1086
|
const t = this.gl, e = this.currentShader;
|
|
1060
|
-
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(),
|
|
1087
|
+
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), wt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
|
|
1061
1088
|
}
|
|
1062
1089
|
resetRender() {
|
|
1063
1090
|
super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
|
|
@@ -1066,66 +1093,78 @@ class lt extends Et {
|
|
|
1066
1093
|
return this.instanceCount > 0;
|
|
1067
1094
|
}
|
|
1068
1095
|
}
|
|
1069
|
-
const
|
|
1070
|
-
class
|
|
1096
|
+
const M = 6;
|
|
1097
|
+
class Gt {
|
|
1071
1098
|
matrixCount = 0;
|
|
1072
1099
|
buffer;
|
|
1073
1100
|
data;
|
|
1101
|
+
freeFlag;
|
|
1102
|
+
freeMatrixStack;
|
|
1074
1103
|
temporary = -1;
|
|
1104
|
+
identityMatrix = -1;
|
|
1075
1105
|
constructor(t = 10) {
|
|
1076
|
-
this.buffer = new
|
|
1106
|
+
this.buffer = new _(C.Float32), this.buffer.resize(t * M), this.data = this.buffer.getArray(), this.freeFlag = new _(C.Uint32), this.freeMatrixStack = new _(C.Uint32), this.reset();
|
|
1077
1107
|
}
|
|
1078
1108
|
alloc() {
|
|
1079
1109
|
const t = this.allocDirty();
|
|
1080
1110
|
return this.identity(t), t;
|
|
1081
1111
|
}
|
|
1082
1112
|
allocDirty() {
|
|
1083
|
-
|
|
1113
|
+
if (this.freeMatrixStack.length > 0) {
|
|
1114
|
+
const e = this.freeMatrixStack.pop();
|
|
1115
|
+
return this.freeFlag.typedArray[e] = 1, e;
|
|
1116
|
+
}
|
|
1117
|
+
this.buffer.resize(M) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += M, this.freeFlag.resize(1);
|
|
1118
|
+
const t = this.matrixCount++;
|
|
1119
|
+
return this.freeFlag.typedArray[this.freeFlag.usedElemNum++] = 1, t;
|
|
1120
|
+
}
|
|
1121
|
+
free(t) {
|
|
1122
|
+
!Number.isInteger(t) || t < 0 || t >= this.matrixCount || this.freeFlag.typedArray[t] !== 0 && (this.freeFlag.typedArray[t] = 0, this.freeMatrixStack.push(t));
|
|
1084
1123
|
}
|
|
1085
1124
|
reset() {
|
|
1086
|
-
this.matrixCount = 0, this.buffer.usedElemNum = 0, this.temporary = this.alloc();
|
|
1125
|
+
this.matrixCount = 0, this.buffer.usedElemNum = 0, this.freeFlag.clear(), this.freeMatrixStack.clear(), this.temporary = this.alloc(), this.identityMatrix = this.alloc();
|
|
1087
1126
|
}
|
|
1088
1127
|
identity(t) {
|
|
1089
|
-
const e = t *
|
|
1128
|
+
const e = t * M, r = this.data;
|
|
1090
1129
|
r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
|
|
1091
1130
|
}
|
|
1092
1131
|
translate(t, e, r) {
|
|
1093
|
-
const i = t *
|
|
1132
|
+
const i = t * M, s = this.data;
|
|
1094
1133
|
s[i + 4] = s[i] * e + s[i + 2] * r + s[i + 4], s[i + 5] = s[i + 1] * e + s[i + 3] * r + s[i + 5];
|
|
1095
1134
|
}
|
|
1096
1135
|
scale(t, e, r) {
|
|
1097
|
-
const i = t *
|
|
1136
|
+
const i = t * M, s = this.data;
|
|
1098
1137
|
s[i] *= e, s[i + 1] *= e, s[i + 2] *= r, s[i + 3] *= r;
|
|
1099
1138
|
}
|
|
1100
1139
|
rotate(t, e) {
|
|
1101
|
-
const r = t *
|
|
1102
|
-
i[r] =
|
|
1140
|
+
const r = t * M, i = this.data, s = Math.cos(e), a = Math.sin(e), o = i[r], h = i[r + 1], c = i[r + 2], u = i[r + 3];
|
|
1141
|
+
i[r] = o * s + c * a, i[r + 1] = h * s + u * a, i[r + 2] = o * -a + c * s, i[r + 3] = h * -a + u * s;
|
|
1103
1142
|
}
|
|
1104
1143
|
rotateWithOffset(t, e, r, i) {
|
|
1105
1144
|
this.translate(t, r, i), this.rotate(t, e), this.translate(t, -r, -i);
|
|
1106
1145
|
}
|
|
1107
1146
|
copy(t, e) {
|
|
1108
|
-
const r = t *
|
|
1147
|
+
const r = t * M, i = e * M, s = this.data;
|
|
1109
1148
|
s[r] = s[i], s[r + 1] = s[i + 1], s[r + 2] = s[i + 2], s[r + 3] = s[i + 3], s[r + 4] = s[i + 4], s[r + 5] = s[i + 5];
|
|
1110
1149
|
}
|
|
1111
1150
|
multiply(t, e) {
|
|
1112
1151
|
this.multiplyOut(t, t, e);
|
|
1113
1152
|
}
|
|
1114
1153
|
multiplyOut(t, e, r) {
|
|
1115
|
-
const i = t *
|
|
1116
|
-
|
|
1154
|
+
const i = t * M, s = e * M, a = r * M, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], m = o[a], x = o[a + 1], y = o[a + 2], v = o[a + 3], T = o[a + 4], w = o[a + 5];
|
|
1155
|
+
o[i] = h * m + u * x, o[i + 1] = c * m + l * x, o[i + 2] = h * y + u * v, o[i + 3] = c * y + l * v, o[i + 4] = h * T + u * w + d, o[i + 5] = c * T + l * w + f;
|
|
1117
1156
|
}
|
|
1118
1157
|
invert(t) {
|
|
1119
|
-
const e = t *
|
|
1120
|
-
let u = i *
|
|
1158
|
+
const e = t * M, r = this.data, i = r[e], s = r[e + 1], a = r[e + 2], o = r[e + 3], h = r[e + 4], c = r[e + 5];
|
|
1159
|
+
let u = i * o - s * a;
|
|
1121
1160
|
if (!u) {
|
|
1122
1161
|
this.identity(t);
|
|
1123
1162
|
return;
|
|
1124
1163
|
}
|
|
1125
|
-
u = 1 / u, r[e] =
|
|
1164
|
+
u = 1 / u, r[e] = o * u, r[e + 1] = -s * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * c - o * h) * u, r[e + 5] = (s * h - i * c) * u;
|
|
1126
1165
|
}
|
|
1127
1166
|
transformPoint(t, e, r) {
|
|
1128
|
-
const i = t *
|
|
1167
|
+
const i = t * M, s = this.data;
|
|
1129
1168
|
return {
|
|
1130
1169
|
x: e * s[i] + r * s[i + 2] + s[i + 4],
|
|
1131
1170
|
y: e * s[i + 1] + r * s[i + 3] + s[i + 5]
|
|
@@ -1135,57 +1174,80 @@ class Bt {
|
|
|
1135
1174
|
const i = this.allocDirty();
|
|
1136
1175
|
this.copy(i, t), this.invert(i);
|
|
1137
1176
|
const s = this.transformPoint(i, e, r);
|
|
1138
|
-
return this.
|
|
1177
|
+
return this.free(i), s;
|
|
1139
1178
|
}
|
|
1140
1179
|
localToWorld(t, e, r) {
|
|
1141
1180
|
return this.transformPoint(t, e, r);
|
|
1142
1181
|
}
|
|
1143
1182
|
getPosition(t) {
|
|
1144
|
-
const e = t *
|
|
1183
|
+
const e = t * M, r = this.data;
|
|
1145
1184
|
return { x: r[e + 4], y: r[e + 5] };
|
|
1146
1185
|
}
|
|
1147
1186
|
getScale(t) {
|
|
1148
|
-
const e = t *
|
|
1187
|
+
const e = t * M, r = this.data, i = Math.sqrt(r[e] * r[e] + r[e + 1] * r[e + 1]), s = Math.sqrt(r[e + 2] * r[e + 2] + r[e + 3] * r[e + 3]);
|
|
1149
1188
|
return { x: i, y: s };
|
|
1150
1189
|
}
|
|
1151
1190
|
getRotation(t) {
|
|
1152
|
-
const e = t *
|
|
1191
|
+
const e = t * M, r = this.data;
|
|
1153
1192
|
return Math.atan2(r[e + 1], r[e]);
|
|
1154
1193
|
}
|
|
1155
1194
|
toCSSMatrix(t, e = 1, r = 1) {
|
|
1156
|
-
const i = t *
|
|
1195
|
+
const i = t * M, s = this.data;
|
|
1157
1196
|
return `matrix(${s[i] * e}, ${s[i + 1] * r}, ${s[i + 2] * e}, ${s[i + 3] * r}, ${s[i + 4] * e}, ${s[i + 5] * r})`;
|
|
1158
1197
|
}
|
|
1159
1198
|
getMatrix(t) {
|
|
1160
|
-
const e = t *
|
|
1161
|
-
return this.data.slice(e, e +
|
|
1199
|
+
const e = t * M;
|
|
1200
|
+
return this.data.slice(e, e + M);
|
|
1162
1201
|
}
|
|
1163
1202
|
getMatrixRef(t) {
|
|
1164
|
-
const e = t *
|
|
1165
|
-
return this.data.subarray(e, e +
|
|
1203
|
+
const e = t * M;
|
|
1204
|
+
return this.data.subarray(e, e + M);
|
|
1166
1205
|
}
|
|
1167
1206
|
setMatrix(t, e) {
|
|
1168
|
-
const r = t *
|
|
1207
|
+
const r = t * M, i = this.data;
|
|
1169
1208
|
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];
|
|
1170
1209
|
}
|
|
1171
|
-
multiplyAffineInPlace(t, e, r, i, s, a,
|
|
1172
|
-
const
|
|
1173
|
-
c[
|
|
1210
|
+
multiplyAffineInPlace(t, e, r, i, s, a, o) {
|
|
1211
|
+
const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = c[h + 4], x = c[h + 5];
|
|
1212
|
+
c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + m, c[h + 5] = l * a + f * o + x;
|
|
1174
1213
|
}
|
|
1175
|
-
multiplyAffine(t, e, r, i, s, a,
|
|
1176
|
-
const c = t * 6, u = e * 6, l = this.data,
|
|
1177
|
-
l[u] =
|
|
1214
|
+
multiplyAffine(t, e, r, i, s, a, o, h) {
|
|
1215
|
+
const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], x = l[c + 3], y = l[c + 4], v = l[c + 5];
|
|
1216
|
+
l[u] = d * r + m * i, l[u + 1] = f * r + x * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + x * a, l[u + 4] = d * o + m * h + y, l[u + 5] = f * o + x * h + v;
|
|
1217
|
+
}
|
|
1218
|
+
clampBounds(t, e, r, i, s, a, o) {
|
|
1219
|
+
if (i === void 0 && s === void 0 && a === void 0 && o === void 0)
|
|
1220
|
+
return;
|
|
1221
|
+
const h = t * M, c = this.data, u = Math.sqrt(c[h] * c[h] + c[h + 1] * c[h + 1]) || 1, l = Math.sqrt(c[h + 2] * c[h + 2] + c[h + 3] * c[h + 3]) || 1, d = e * 0.5 * u, f = r * 0.5 * l;
|
|
1222
|
+
let m = c[h + 4], x = c[h + 5];
|
|
1223
|
+
i !== void 0 && s !== void 0 ? m = s - i < d * 2 ? (i + s) * 0.5 : Math.max(i + d, Math.min(m, s - d)) : i !== void 0 ? m = Math.max(m, i + d) : s !== void 0 && (m = Math.min(m, s - d)), a !== void 0 && o !== void 0 ? x = o - a < f * 2 ? (a + o) * 0.5 : Math.max(a + f, Math.min(x, o - f)) : a !== void 0 ? x = Math.max(x, a + f) : o !== void 0 && (x = Math.min(x, o - f)), c[h + 4] = m, c[h + 5] = x;
|
|
1224
|
+
}
|
|
1225
|
+
applyTransform(t, e = 0, r = 0) {
|
|
1226
|
+
let i = t.x ?? 0, s = t.y ?? 0;
|
|
1227
|
+
t.position && (i += t.position.x, s += t.position.y);
|
|
1228
|
+
let a = 1, o = 1;
|
|
1229
|
+
const h = t.scale;
|
|
1230
|
+
h !== void 0 && (typeof h == "number" ? (a = h, o = h) : (a = h.x, o = h.y));
|
|
1231
|
+
const c = t.rotation ?? 0;
|
|
1232
|
+
let u = t.offsetX ?? 0, l = t.offsetY ?? 0;
|
|
1233
|
+
t.offset && (u += t.offset.x, l += t.offset.y);
|
|
1234
|
+
const d = t.origin;
|
|
1235
|
+
d !== void 0 && (typeof d == "number" ? (u -= d * e, l -= d * r) : (u -= d.x * e, l -= d.y * r));
|
|
1236
|
+
const f = c ? Math.cos(c) : 1, m = c ? Math.sin(c) : 0, x = f * a, y = m * a, v = -m * o, T = f * o, w = i + x * u + v * l, U = s + y * u + T * l;
|
|
1237
|
+
return [
|
|
1238
|
+
x,
|
|
1239
|
+
y,
|
|
1240
|
+
v,
|
|
1241
|
+
T,
|
|
1242
|
+
w,
|
|
1243
|
+
U
|
|
1244
|
+
];
|
|
1178
1245
|
}
|
|
1179
1246
|
}
|
|
1180
|
-
class
|
|
1181
|
-
matrix = new
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
stepWorldM = new b(A.Uint32);
|
|
1185
|
-
stepAction = new b(A.Uint32);
|
|
1186
|
-
stepParentM = new b(A.Uint32);
|
|
1187
|
-
stepClose = new b(A.Uint32);
|
|
1188
|
-
stepStack = new b(A.Uint32);
|
|
1247
|
+
class Ht {
|
|
1248
|
+
matrix = new Gt();
|
|
1249
|
+
stack = new _(C.Uint32);
|
|
1250
|
+
currStack = new _(C.Uint32);
|
|
1189
1251
|
curLocalM = -1;
|
|
1190
1252
|
curWorldM = -1;
|
|
1191
1253
|
rapid;
|
|
@@ -1193,57 +1255,24 @@ class kt {
|
|
|
1193
1255
|
this.reset(), this.rapid = t;
|
|
1194
1256
|
}
|
|
1195
1257
|
save() {
|
|
1196
|
-
this.stack.push(this.curWorldM);
|
|
1258
|
+
this.stack.push(this.curLocalM), this.stack.push(this.curWorldM);
|
|
1197
1259
|
const t = this.curWorldM;
|
|
1198
|
-
return this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.allocDirty(), this.
|
|
1260
|
+
return this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.allocDirty(), this.matrix.copy(this.curWorldM, t), this.currStack.push(this.curLocalM), this.currStack.push(this.curWorldM), { parent: t, world: this.curWorldM, local: this.curLocalM };
|
|
1199
1261
|
}
|
|
1200
1262
|
restore() {
|
|
1201
|
-
this.stack.length
|
|
1263
|
+
this.stack.length != 0 && (this.curWorldM = this.stack.pop(), this.curLocalM = this.stack.pop());
|
|
1202
1264
|
}
|
|
1203
1265
|
restoreAll() {
|
|
1204
|
-
for (; this.stack.length > 0
|
|
1266
|
+
for (; this.stack.length > 0; )
|
|
1205
1267
|
this.restore();
|
|
1206
1268
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
let i = 0
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
if (a === 1) {
|
|
1215
|
-
if (i++, i > r) {
|
|
1216
|
-
const h = this.stepClose.get(s);
|
|
1217
|
-
if (h > s) {
|
|
1218
|
-
s = h + 1, i--;
|
|
1219
|
-
continue;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
} else
|
|
1223
|
-
i--;
|
|
1224
|
-
if (e(s, a, i) === !1 || a === 0 && i === 0) return;
|
|
1225
|
-
s++;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
getParent(t) {
|
|
1229
|
-
const e = this.getStep(t);
|
|
1230
|
-
return this.stepParentM.get(e);
|
|
1231
|
-
}
|
|
1232
|
-
getChildren(t) {
|
|
1233
|
-
const e = this.getStep(t), r = this.stepClose.get(e), i = [];
|
|
1234
|
-
let s = e + 1;
|
|
1235
|
-
for (; s < r; )
|
|
1236
|
-
this.stepAction.get(s) === 1 ? (i.push(s), s = this.stepClose.get(s) + 1) : s++;
|
|
1237
|
-
return i;
|
|
1238
|
-
}
|
|
1239
|
-
updateMatrixSubtree(t) {
|
|
1240
|
-
const e = this.getStep(t);
|
|
1241
|
-
this.walkSubtree(e, (r, i) => {
|
|
1242
|
-
if (i === 1) {
|
|
1243
|
-
const s = this.stepWorldM.get(r), a = s - 1, h = this.stepParentM.get(r);
|
|
1244
|
-
this.matrix.multiplyOut(s, h, a);
|
|
1245
|
-
}
|
|
1246
|
-
});
|
|
1269
|
+
retainMatrix(t) {
|
|
1270
|
+
const e = new Set(
|
|
1271
|
+
typeof t == "number" ? [t] : [t.local, t.world]
|
|
1272
|
+
), r = [];
|
|
1273
|
+
for (let i = 0; i < this.currStack.length; i++)
|
|
1274
|
+
e.has(this.currStack.get(i)) && r.push(i);
|
|
1275
|
+
_.removeAtIndices(r, [this.currStack]);
|
|
1247
1276
|
}
|
|
1248
1277
|
translate(t, e) {
|
|
1249
1278
|
this.matrix.translate(this.curLocalM, t, e), this.matrix.translate(this.curWorldM, t, e);
|
|
@@ -1261,7 +1290,9 @@ class kt {
|
|
|
1261
1290
|
this.matrix.identity(this.curLocalM), this.matrix.identity(this.curWorldM);
|
|
1262
1291
|
}
|
|
1263
1292
|
reset() {
|
|
1264
|
-
|
|
1293
|
+
for (let t = 0; t < this.currStack.length; t++)
|
|
1294
|
+
this.matrix.free(this.currStack.typedArray[t]);
|
|
1295
|
+
this.currStack.clear(), this.stack.clear(), this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.alloc(), this.currStack.push(this.curLocalM), this.currStack.push(this.curWorldM);
|
|
1265
1296
|
}
|
|
1266
1297
|
localToWorld(t, e) {
|
|
1267
1298
|
return this.matrix.localToWorld(this.curWorldM, t, e);
|
|
@@ -1282,61 +1313,54 @@ class kt {
|
|
|
1282
1313
|
return this.matrix.toCSSMatrix(this.curWorldM);
|
|
1283
1314
|
}
|
|
1284
1315
|
getTransform() {
|
|
1285
|
-
const t = this.curWorldM *
|
|
1286
|
-
return this.matrix.data.slice(t, t +
|
|
1316
|
+
const t = this.curWorldM * M;
|
|
1317
|
+
return this.matrix.data.slice(t, t + M);
|
|
1287
1318
|
}
|
|
1288
1319
|
setTransform(t) {
|
|
1289
|
-
const e = this.curWorldM *
|
|
1320
|
+
const e = this.curWorldM * M, r = this.matrix.data;
|
|
1290
1321
|
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];
|
|
1291
1322
|
}
|
|
1292
1323
|
transformPoint(t, e) {
|
|
1293
1324
|
return this.matrix.transformPoint(this.curLocalM, t, e);
|
|
1294
1325
|
}
|
|
1295
|
-
applyTransform(t, e = 0, r = 0, i =
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
this.curLocalM,
|
|
1322
|
-
y,
|
|
1323
|
-
v,
|
|
1324
|
-
E,
|
|
1325
|
-
S,
|
|
1326
|
-
_,
|
|
1327
|
-
P
|
|
1326
|
+
applyTransform(t, e = 0, r = 0, i, s = this.curWorldM, a = this.curLocalM) {
|
|
1327
|
+
const [
|
|
1328
|
+
o,
|
|
1329
|
+
h,
|
|
1330
|
+
c,
|
|
1331
|
+
u,
|
|
1332
|
+
l,
|
|
1333
|
+
d
|
|
1334
|
+
] = this.matrix.applyTransform(t, e, r);
|
|
1335
|
+
i != null ? this.matrix.multiplyAffine(
|
|
1336
|
+
s,
|
|
1337
|
+
i,
|
|
1338
|
+
o,
|
|
1339
|
+
h,
|
|
1340
|
+
c,
|
|
1341
|
+
u,
|
|
1342
|
+
l,
|
|
1343
|
+
d
|
|
1344
|
+
) : (this.matrix.multiplyAffineInPlace(
|
|
1345
|
+
a,
|
|
1346
|
+
o,
|
|
1347
|
+
h,
|
|
1348
|
+
c,
|
|
1349
|
+
u,
|
|
1350
|
+
l,
|
|
1351
|
+
d
|
|
1328
1352
|
), this.matrix.multiplyAffineInPlace(
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
);
|
|
1353
|
+
s,
|
|
1354
|
+
o,
|
|
1355
|
+
h,
|
|
1356
|
+
c,
|
|
1357
|
+
u,
|
|
1358
|
+
l,
|
|
1359
|
+
d
|
|
1360
|
+
));
|
|
1337
1361
|
}
|
|
1338
1362
|
}
|
|
1339
|
-
const
|
|
1363
|
+
const Vt = `#version 300 es\r
|
|
1340
1364
|
precision highp float;\r
|
|
1341
1365
|
\r
|
|
1342
1366
|
in vec2 aPosition;\r
|
|
@@ -1367,7 +1391,7 @@ void main(void) {\r
|
|
|
1367
1391
|
// CUSTOM_CODE_CALL\r
|
|
1368
1392
|
gl_Position = u_projection * position;\r
|
|
1369
1393
|
}\r
|
|
1370
|
-
`,
|
|
1394
|
+
`, Xt = `#version 300 es\r
|
|
1371
1395
|
precision mediump float;\r
|
|
1372
1396
|
\r
|
|
1373
1397
|
in vec4 vColor;\r
|
|
@@ -1414,7 +1438,7 @@ void main(void) {\r
|
|
|
1414
1438
|
fragColor = sampleTexture(vRegion) * vColor;\r
|
|
1415
1439
|
// CUSTOM_CODE_CALL\r
|
|
1416
1440
|
}\r
|
|
1417
|
-
`,
|
|
1441
|
+
`, Yt = `#version 300 es\r
|
|
1418
1442
|
precision highp float;\r
|
|
1419
1443
|
\r
|
|
1420
1444
|
in vec2 aPosition;\r
|
|
@@ -1437,7 +1461,7 @@ void main(void) {\r
|
|
|
1437
1461
|
);\r
|
|
1438
1462
|
gl_Position = u_projection * position;\r
|
|
1439
1463
|
}\r
|
|
1440
|
-
`,
|
|
1464
|
+
`, zt = `#version 300 es\r
|
|
1441
1465
|
precision mediump float;\r
|
|
1442
1466
|
\r
|
|
1443
1467
|
in vec2 vRegion;\r
|
|
@@ -1457,8 +1481,8 @@ void main(void) {\r
|
|
|
1457
1481
|
discard;\r
|
|
1458
1482
|
}\r
|
|
1459
1483
|
}\r
|
|
1460
|
-
`,
|
|
1461
|
-
class
|
|
1484
|
+
`, K = 20;
|
|
1485
|
+
class $t extends Rt {
|
|
1462
1486
|
vertexBuffer;
|
|
1463
1487
|
vertexCount = 0;
|
|
1464
1488
|
extraTextureUnit = 1;
|
|
@@ -1472,24 +1496,24 @@ class Yt extends Et {
|
|
|
1472
1496
|
}
|
|
1473
1497
|
createBuffer() {
|
|
1474
1498
|
const t = this.gl;
|
|
1475
|
-
this.vertexBuffer = new
|
|
1499
|
+
this.vertexBuffer = new lt(t, C.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
|
|
1476
1500
|
}
|
|
1477
1501
|
createDefaultShader() {
|
|
1478
|
-
return this.vs =
|
|
1502
|
+
return this.vs = Vt, this.fs = Xt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
|
|
1479
1503
|
}
|
|
1480
1504
|
createMaskShader(t, e) {
|
|
1481
|
-
const r = this.gl, i = new
|
|
1505
|
+
const r = this.gl, i = new Et(r, t, e);
|
|
1482
1506
|
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
1483
|
-
{ name: "aPosition", size: 2, type: r.FLOAT, stride:
|
|
1484
|
-
{ name: "aUV", size: 2, type: r.FLOAT, stride:
|
|
1507
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: K - 4, offset: 0, divisor: 0 },
|
|
1508
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: K - 4, offset: 8, divisor: 0 }
|
|
1485
1509
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
1486
1510
|
}
|
|
1487
1511
|
createShader(t, e) {
|
|
1488
1512
|
const r = this.gl, i = super.createShader(t, e);
|
|
1489
1513
|
return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
|
|
1490
|
-
{ name: "aPosition", size: 2, type: r.FLOAT, stride:
|
|
1491
|
-
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride:
|
|
1492
|
-
{ name: "aUV", size: 2, type: r.FLOAT, stride:
|
|
1514
|
+
{ name: "aPosition", size: 2, type: r.FLOAT, stride: K, offset: 0, divisor: 0 },
|
|
1515
|
+
{ name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: K, offset: 8, divisor: 0 },
|
|
1516
|
+
{ name: "aUV", size: 2, type: r.FLOAT, stride: K, offset: 12, divisor: 0 }
|
|
1493
1517
|
]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
|
|
1494
1518
|
}
|
|
1495
1519
|
startGraphic(t, e = this.gl.TRIANGLES, r) {
|
|
@@ -1516,32 +1540,32 @@ class Yt extends Et {
|
|
|
1516
1540
|
return !1;
|
|
1517
1541
|
}
|
|
1518
1542
|
}
|
|
1519
|
-
class
|
|
1543
|
+
class p {
|
|
1520
1544
|
x;
|
|
1521
1545
|
y;
|
|
1522
|
-
static ZERO = new
|
|
1523
|
-
static ONE = new
|
|
1524
|
-
static UP = new
|
|
1525
|
-
static DOWN = new
|
|
1526
|
-
static LEFT = new
|
|
1527
|
-
static RIGHT = new
|
|
1546
|
+
static ZERO = new p(0, 0);
|
|
1547
|
+
static ONE = new p(1, 1);
|
|
1548
|
+
static UP = new p(0, 1);
|
|
1549
|
+
static DOWN = new p(0, -1);
|
|
1550
|
+
static LEFT = new p(-1, 0);
|
|
1551
|
+
static RIGHT = new p(1, 0);
|
|
1528
1552
|
constructor(t, e) {
|
|
1529
|
-
this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e :
|
|
1553
|
+
this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : this.x;
|
|
1530
1554
|
}
|
|
1531
1555
|
set(t, e) {
|
|
1532
1556
|
return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
|
|
1533
1557
|
}
|
|
1534
1558
|
add(t) {
|
|
1535
|
-
return new
|
|
1559
|
+
return new p(this.x + t.x, this.y + t.y);
|
|
1536
1560
|
}
|
|
1537
1561
|
subtract(t) {
|
|
1538
|
-
return new
|
|
1562
|
+
return new p(this.x - t.x, this.y - t.y);
|
|
1539
1563
|
}
|
|
1540
1564
|
multiply(t) {
|
|
1541
|
-
return t instanceof
|
|
1565
|
+
return t instanceof p ? new p(this.x * t.x, this.y * t.y) : new p(this.x * t, this.y * t);
|
|
1542
1566
|
}
|
|
1543
1567
|
divide(t) {
|
|
1544
|
-
return t instanceof
|
|
1568
|
+
return t instanceof p ? new p(this.x / t.x, this.y / t.y) : new p(this.x / t, this.y / t);
|
|
1545
1569
|
}
|
|
1546
1570
|
dot(t) {
|
|
1547
1571
|
return this.x * t.x + this.y * t.y;
|
|
@@ -1554,7 +1578,7 @@ class g {
|
|
|
1554
1578
|
return Math.sqrt(e * e + r * r);
|
|
1555
1579
|
}
|
|
1556
1580
|
clone() {
|
|
1557
|
-
return new
|
|
1581
|
+
return new p(this.x, this.y);
|
|
1558
1582
|
}
|
|
1559
1583
|
to(t) {
|
|
1560
1584
|
this.x = t.x, this.y = t.y;
|
|
@@ -1570,7 +1594,7 @@ class g {
|
|
|
1570
1594
|
return this.x = -this.x, this.y = -this.y, this;
|
|
1571
1595
|
}
|
|
1572
1596
|
inverted() {
|
|
1573
|
-
return new
|
|
1597
|
+
return new p(this.x * -1, this.y * -1);
|
|
1574
1598
|
}
|
|
1575
1599
|
length() {
|
|
1576
1600
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
@@ -1584,13 +1608,13 @@ class g {
|
|
|
1584
1608
|
}
|
|
1585
1609
|
normalized() {
|
|
1586
1610
|
const t = this.length();
|
|
1587
|
-
return new
|
|
1611
|
+
return new p(this.x / t || 0, this.y / t || 0);
|
|
1588
1612
|
}
|
|
1589
1613
|
fix(t = 1e-13) {
|
|
1590
1614
|
this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
|
|
1591
1615
|
}
|
|
1592
1616
|
fixed(t = 1e-13) {
|
|
1593
|
-
return new
|
|
1617
|
+
return new p(
|
|
1594
1618
|
Math.abs(this.x) < t ? 0 : this.x,
|
|
1595
1619
|
Math.abs(this.y) < t ? 0 : this.y
|
|
1596
1620
|
);
|
|
@@ -1599,13 +1623,13 @@ class g {
|
|
|
1599
1623
|
return Math.atan2(this.y, this.x);
|
|
1600
1624
|
}
|
|
1601
1625
|
abs() {
|
|
1602
|
-
return new
|
|
1626
|
+
return new p(Math.abs(this.x), Math.abs(this.y));
|
|
1603
1627
|
}
|
|
1604
1628
|
floor() {
|
|
1605
|
-
return new
|
|
1629
|
+
return new p(Math.floor(this.x), Math.floor(this.y));
|
|
1606
1630
|
}
|
|
1607
1631
|
ceil() {
|
|
1608
|
-
return new
|
|
1632
|
+
return new p(Math.ceil(this.x), Math.ceil(this.y));
|
|
1609
1633
|
}
|
|
1610
1634
|
stringify() {
|
|
1611
1635
|
return `Vec2(${this.x}, ${this.y})`;
|
|
@@ -1626,14 +1650,14 @@ class g {
|
|
|
1626
1650
|
return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
|
|
1627
1651
|
}
|
|
1628
1652
|
static FromArray(t) {
|
|
1629
|
-
return t.map((e) => new
|
|
1653
|
+
return t.map((e) => new p(e[0], e[1]));
|
|
1630
1654
|
}
|
|
1631
1655
|
static fromAngle(t) {
|
|
1632
|
-
return new
|
|
1656
|
+
return new p(Math.cos(t), Math.sin(t));
|
|
1633
1657
|
}
|
|
1634
1658
|
}
|
|
1635
|
-
const
|
|
1636
|
-
const [e, r, i, s, a,
|
|
1659
|
+
const jt = (n, t) => {
|
|
1660
|
+
const [e, r, i, s, a, o] = t, h = new Float32Array([
|
|
1637
1661
|
e,
|
|
1638
1662
|
i,
|
|
1639
1663
|
0,
|
|
@@ -1647,12 +1671,12 @@ const zt = (n, t) => {
|
|
|
1647
1671
|
1,
|
|
1648
1672
|
0,
|
|
1649
1673
|
a,
|
|
1650
|
-
|
|
1674
|
+
o,
|
|
1651
1675
|
0,
|
|
1652
1676
|
1
|
|
1653
1677
|
]);
|
|
1654
|
-
return
|
|
1655
|
-
},
|
|
1678
|
+
return Kt(h, n);
|
|
1679
|
+
}, Kt = (n, t) => {
|
|
1656
1680
|
const e = new Float32Array(16);
|
|
1657
1681
|
for (let r = 0; r < 4; r++)
|
|
1658
1682
|
for (let i = 0; i < 4; i++) {
|
|
@@ -1663,77 +1687,84 @@ const zt = (n, t) => {
|
|
|
1663
1687
|
}
|
|
1664
1688
|
return e;
|
|
1665
1689
|
};
|
|
1666
|
-
var
|
|
1667
|
-
const
|
|
1668
|
-
const a = [],
|
|
1669
|
-
for (let l = 0; l <
|
|
1670
|
-
const
|
|
1671
|
-
a.push(n),
|
|
1672
|
-
}
|
|
1673
|
-
return { vertices: a, uv:
|
|
1674
|
-
},
|
|
1690
|
+
var qt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(qt || {});
|
|
1691
|
+
const at = 10, xt = (n, t, e, r, i, s) => {
|
|
1692
|
+
const a = [], o = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new p(t.y, -t.x);
|
|
1693
|
+
for (let l = 0; l < at; l++) {
|
|
1694
|
+
const d = l / at, f = (l + 1) / at, m = h + d * c, x = h + f * c, y = new p(Math.cos(m) * e, Math.sin(m) * e), v = new p(Math.cos(x) * e, Math.sin(x) * e);
|
|
1695
|
+
a.push(n), o.push(new p(i, 0.5)), a.push(n.add(y)), o.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e)), a.push(n.add(v)), o.push(new p(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e));
|
|
1696
|
+
}
|
|
1697
|
+
return { vertices: a, uv: o };
|
|
1698
|
+
}, Zt = (n, t = !1) => {
|
|
1675
1699
|
const e = [];
|
|
1676
1700
|
if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
|
|
1677
1701
|
const r = 4, i = 1e-3, s = n.length;
|
|
1678
1702
|
let a = 0;
|
|
1679
1703
|
if (t)
|
|
1680
|
-
for (let
|
|
1681
|
-
const c = n[
|
|
1704
|
+
for (let h = 0; h < s; h++) {
|
|
1705
|
+
const c = n[h], u = n[(h + 1) % s];
|
|
1682
1706
|
a += c.distanceTo(u);
|
|
1683
1707
|
}
|
|
1684
1708
|
else
|
|
1685
|
-
for (let
|
|
1686
|
-
a += n[
|
|
1687
|
-
const
|
|
1688
|
-
const l = c.subtract(
|
|
1689
|
-
if (
|
|
1709
|
+
for (let h = 0; h < s - 1; h++)
|
|
1710
|
+
a += n[h].distanceTo(n[h + 1]);
|
|
1711
|
+
const o = (h, c, u) => {
|
|
1712
|
+
const l = c.subtract(h).normalize(), d = c.subtract(u).normalize(), f = d.dot(l);
|
|
1713
|
+
if (f < -1 + i)
|
|
1690
1714
|
return { normal: l.perpendicular(), miters: 1 };
|
|
1691
1715
|
{
|
|
1692
|
-
let
|
|
1693
|
-
l.cross(
|
|
1694
|
-
let
|
|
1695
|
-
return { normal:
|
|
1716
|
+
let m = d.add(l).normalize();
|
|
1717
|
+
l.cross(d) < 0 && (m = m.multiply(-1));
|
|
1718
|
+
let x = 1 / Math.sqrt((1 - f) / 2);
|
|
1719
|
+
return { normal: m, miters: Math.min(x, r) };
|
|
1696
1720
|
}
|
|
1697
1721
|
};
|
|
1698
1722
|
if (t)
|
|
1699
|
-
for (let
|
|
1700
|
-
const c =
|
|
1701
|
-
e.push(
|
|
1723
|
+
for (let h = 0; h < s; h++) {
|
|
1724
|
+
const c = h === 0 ? n[s - 1] : n[h - 1], u = n[h], l = h === s - 1 ? n[0] : n[h + 1];
|
|
1725
|
+
e.push(o(c, u, l));
|
|
1702
1726
|
}
|
|
1703
1727
|
else
|
|
1704
|
-
for (let
|
|
1705
|
-
if (
|
|
1728
|
+
for (let h = 0; h < s; h++)
|
|
1729
|
+
if (h === 0) {
|
|
1706
1730
|
const c = n[1].subtract(n[0]).normalize();
|
|
1707
1731
|
e.push({ normal: c.perpendicular(), miters: 1 });
|
|
1708
|
-
} else if (
|
|
1709
|
-
const c = n[
|
|
1732
|
+
} else if (h === s - 1) {
|
|
1733
|
+
const c = n[h].subtract(n[h - 1]).normalize();
|
|
1710
1734
|
e.push({ normal: c.perpendicular(), miters: 1 });
|
|
1711
1735
|
} else
|
|
1712
|
-
e.push(
|
|
1736
|
+
e.push(o(n[h - 1], n[h], n[h + 1]));
|
|
1713
1737
|
return { normals: e, length: a };
|
|
1714
|
-
},
|
|
1738
|
+
}, Qt = (n) => {
|
|
1715
1739
|
const t = n.points;
|
|
1716
1740
|
if (t.length < 2) return { vertices: [], uv: [] };
|
|
1717
|
-
const { normals: e, length: r } =
|
|
1741
|
+
const { normals: e, length: r } = Zt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
|
|
1718
1742
|
let c = 0;
|
|
1719
1743
|
const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
|
|
1720
|
-
for (let
|
|
1721
|
-
const
|
|
1722
|
-
let
|
|
1723
|
-
|
|
1724
|
-
const
|
|
1725
|
-
s.push(
|
|
1726
|
-
}
|
|
1727
|
-
if (
|
|
1728
|
-
const
|
|
1729
|
-
s.push(...
|
|
1730
|
-
const y = t[t.length - 1], v = e[t.length - 1].normal,
|
|
1731
|
-
s.push(...
|
|
1744
|
+
for (let d = 0; d < l; d++) {
|
|
1745
|
+
const f = t[d], m = e[d].normal, x = e[d].miters, y = (d + 1) % t.length, v = t[y], T = e[y].normal, w = e[y].miters, U = f.add(m.multiply(x * i)), P = f.subtract(m.multiply(x * i)), O = v.add(T.multiply(w * i)), L = v.subtract(T.multiply(w * i)), S = f.distanceTo(v);
|
|
1746
|
+
let E = 0, b = 0;
|
|
1747
|
+
h === 0 ? (E = c / r, b = (c + S) / r) : (E = c / u, b = E + S / u);
|
|
1748
|
+
const I = new p(E, 0), k = new p(E, 1), G = new p(b, 0), N = new p(b, 1);
|
|
1749
|
+
s.push(U), a.push(I), s.push(P), a.push(k), s.push(O), a.push(G), s.push(O), a.push(G), s.push(L), a.push(N), s.push(P), a.push(k), c += S;
|
|
1750
|
+
}
|
|
1751
|
+
if (o && !n.closed) {
|
|
1752
|
+
const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, x = xt(d, f, i, !0, 0, m);
|
|
1753
|
+
s.push(...x.vertices), a.push(...x.uv);
|
|
1754
|
+
const y = t[t.length - 1], v = e[t.length - 1].normal, T = h === 0 ? 1 : c / u, w = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, U = xt(y, v, i, !1, T, w);
|
|
1755
|
+
s.push(...U.vertices), a.push(...U.uv);
|
|
1732
1756
|
}
|
|
1733
1757
|
return { vertices: s, uv: a };
|
|
1734
|
-
},
|
|
1758
|
+
}, tt = (n, t, e, r) => {
|
|
1759
|
+
const i = n.matrix.temporary;
|
|
1735
1760
|
if (t.customMatrix !== void 0)
|
|
1736
|
-
return
|
|
1761
|
+
return n.matrixStack.applyTransform(
|
|
1762
|
+
t,
|
|
1763
|
+
e,
|
|
1764
|
+
r,
|
|
1765
|
+
i,
|
|
1766
|
+
t.customMatrix
|
|
1767
|
+
), i;
|
|
1737
1768
|
if (t.modifyStack) {
|
|
1738
1769
|
n.matrixStack.applyTransform(
|
|
1739
1770
|
t,
|
|
@@ -1741,41 +1772,40 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
|
|
|
1741
1772
|
r
|
|
1742
1773
|
);
|
|
1743
1774
|
return;
|
|
1744
|
-
} else
|
|
1745
|
-
const i = n.matrix.temporary;
|
|
1775
|
+
} else
|
|
1746
1776
|
return n.matrixStack.applyTransform(
|
|
1747
1777
|
t,
|
|
1748
1778
|
e,
|
|
1749
1779
|
r,
|
|
1750
|
-
i
|
|
1780
|
+
i,
|
|
1781
|
+
n.matrixStack.curWorldM
|
|
1751
1782
|
), i;
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
const e = Q(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
|
|
1783
|
+
}, Jt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, te = 2, ee = (n, t) => {
|
|
1784
|
+
const e = tt(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
|
|
1755
1785
|
if (!r?.base || n.inCreateMask)
|
|
1756
1786
|
return;
|
|
1757
1787
|
const i = r.isAtlas ? n.atlasSpriteRegion : n.spriteRegion;
|
|
1758
1788
|
n.enterRegion(i, t.shader);
|
|
1759
|
-
let s = r.uvX, a = r.uvY,
|
|
1789
|
+
let s = r.uvX, a = r.uvY, o = r.uvW, h = r.uvH;
|
|
1760
1790
|
const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
|
|
1761
1791
|
let l = t.padding ?? i.currentShader.padding;
|
|
1762
|
-
r.isAtlas && (l +=
|
|
1763
|
-
const
|
|
1792
|
+
r.isAtlas && (l += te);
|
|
1793
|
+
const d = s <= o ? l : -l, f = a <= h ? l : -l;
|
|
1764
1794
|
i.drawSprite(
|
|
1765
1795
|
r,
|
|
1766
1796
|
e ?? t.customMatrix ?? n.matrixStack.curWorldM,
|
|
1767
1797
|
s,
|
|
1768
1798
|
a,
|
|
1769
|
-
h,
|
|
1770
1799
|
o,
|
|
1800
|
+
h,
|
|
1771
1801
|
n.getColorUint32(t.color),
|
|
1772
|
-
f,
|
|
1773
1802
|
d,
|
|
1803
|
+
f,
|
|
1774
1804
|
c,
|
|
1775
1805
|
u,
|
|
1776
1806
|
r.isRotated
|
|
1777
1807
|
);
|
|
1778
|
-
},
|
|
1808
|
+
}, re = (n, t) => {
|
|
1779
1809
|
const e = n.particleRegion;
|
|
1780
1810
|
n.enterRegion(e, t.shader);
|
|
1781
1811
|
const r = t.texture, i = t.count ?? t.x.length, s = t.color;
|
|
@@ -1803,7 +1833,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
|
|
|
1803
1833
|
);
|
|
1804
1834
|
}, Mt = (n, t) => {
|
|
1805
1835
|
if (t.points.length === 0) return;
|
|
1806
|
-
const e =
|
|
1836
|
+
const e = tt(n, t, 0, 0);
|
|
1807
1837
|
n.startGraphic(
|
|
1808
1838
|
t.drawMode ?? n.gl.TRIANGLES,
|
|
1809
1839
|
t.texture,
|
|
@@ -1821,18 +1851,18 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
|
|
|
1821
1851
|
);
|
|
1822
1852
|
}
|
|
1823
1853
|
n.endGraphic();
|
|
1824
|
-
},
|
|
1854
|
+
}, ie = (n, t) => {
|
|
1825
1855
|
if (n.inCreateMask)
|
|
1826
1856
|
return;
|
|
1827
|
-
const { vertices: e, uv: r } =
|
|
1857
|
+
const { vertices: e, uv: r } = Qt(t);
|
|
1828
1858
|
Mt(n, {
|
|
1829
1859
|
...t,
|
|
1830
1860
|
points: e,
|
|
1831
1861
|
uv: r,
|
|
1832
1862
|
drawMode: n.gl.TRIANGLES
|
|
1833
1863
|
});
|
|
1834
|
-
},
|
|
1835
|
-
const e =
|
|
1864
|
+
}, se = (n, t) => {
|
|
1865
|
+
const e = tt(
|
|
1836
1866
|
n,
|
|
1837
1867
|
t,
|
|
1838
1868
|
t.texture.rawWidth,
|
|
@@ -1843,16 +1873,16 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
|
|
|
1843
1873
|
t.texture,
|
|
1844
1874
|
e ?? t.customMatrix
|
|
1845
1875
|
), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
|
|
1846
|
-
},
|
|
1847
|
-
const e =
|
|
1876
|
+
}, ne = (n, t) => {
|
|
1877
|
+
const e = tt(n, t, t.width, t.height);
|
|
1848
1878
|
n.startGraphic(
|
|
1849
1879
|
n.gl.TRIANGLE_FAN,
|
|
1850
1880
|
t.texture,
|
|
1851
1881
|
t.shader,
|
|
1852
1882
|
e ?? t.customMatrix
|
|
1853
1883
|
), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
|
|
1854
|
-
},
|
|
1855
|
-
const e = t.segments ?? 32, r =
|
|
1884
|
+
}, ae = (n, t) => {
|
|
1885
|
+
const e = t.segments ?? 32, r = tt(n, t, 0, 0);
|
|
1856
1886
|
n.startGraphic(
|
|
1857
1887
|
n.gl.TRIANGLE_FAN,
|
|
1858
1888
|
void 0,
|
|
@@ -1861,7 +1891,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
|
|
|
1861
1891
|
);
|
|
1862
1892
|
const i = n.getColorUint32(t.color);
|
|
1863
1893
|
n.addGraphicVertex(0, 0, 0.5, 0.5, i), n.addCircleVertex(t.radius, t.color, e), n.addGraphicVertex(t.radius, 0, 1, 0.5, i), n.endGraphic();
|
|
1864
|
-
},
|
|
1894
|
+
}, pt = `#version 300 es\r
|
|
1865
1895
|
precision mediump float;\r
|
|
1866
1896
|
\r
|
|
1867
1897
|
uniform sampler2D uTextures[%TEXTURE_NUM%];\r
|
|
@@ -1905,16 +1935,16 @@ void main(void) {\r
|
|
|
1905
1935
|
// CUSTOM_CODE_CALL\r
|
|
1906
1936
|
}\r
|
|
1907
1937
|
`;
|
|
1908
|
-
class
|
|
1938
|
+
class oe extends dt {
|
|
1909
1939
|
KEY = "AtlasSprite";
|
|
1910
1940
|
constructor(t) {
|
|
1911
1941
|
super(t);
|
|
1912
1942
|
}
|
|
1913
1943
|
createDefaultShader() {
|
|
1914
|
-
return this.vs =
|
|
1944
|
+
return this.vs = st, this.fs = pt, this.defaultShader = this.createShader(st, pt), this.defaultShader;
|
|
1915
1945
|
}
|
|
1916
1946
|
}
|
|
1917
|
-
const
|
|
1947
|
+
const he = `#version 300 es\r
|
|
1918
1948
|
precision highp float;\r
|
|
1919
1949
|
\r
|
|
1920
1950
|
// per-vertex\r
|
|
@@ -1931,7 +1961,8 @@ in vec4 aUVRect;\r
|
|
|
1931
1961
|
\r
|
|
1932
1962
|
// per-instance:tint color\r
|
|
1933
1963
|
in vec4 aColor;\r
|
|
1934
|
-
|
|
1964
|
+
// Projection and scene transform are combined once per particle batch on the CPU.
|
|
1965
|
+
uniform mat4 u_matrix;
|
|
1935
1966
|
\r
|
|
1936
1967
|
out vec2 vRegion;\r
|
|
1937
1968
|
out vec4 vColor;\r
|
|
@@ -1949,9 +1980,9 @@ void main(void) {\r
|
|
|
1949
1980
|
vec4 position = vec4(mat2(c, s, -s, c) * scaled + aPosition, 0.0, 1.0);\r
|
|
1950
1981
|
// CUSTOM_CODE_CALL\r
|
|
1951
1982
|
\r
|
|
1952
|
-
gl_Position =
|
|
1983
|
+
gl_Position = u_matrix * position;
|
|
1953
1984
|
}\r
|
|
1954
|
-
`,
|
|
1985
|
+
`, ce = `#version 300 es\r
|
|
1955
1986
|
precision mediump float;\r
|
|
1956
1987
|
\r
|
|
1957
1988
|
uniform sampler2D uTexture;\r
|
|
@@ -1968,8 +1999,8 @@ void main(void) {\r
|
|
|
1968
1999
|
\r
|
|
1969
2000
|
// CUSTOM_CODE_CALL\r
|
|
1970
2001
|
}\r
|
|
1971
|
-
`,
|
|
1972
|
-
class
|
|
2002
|
+
`, Y = 48, ue = Y / 4;
|
|
2003
|
+
class le extends dt {
|
|
1973
2004
|
KEY = "ParticleSprite";
|
|
1974
2005
|
texture;
|
|
1975
2006
|
customMatrix;
|
|
@@ -1979,77 +2010,77 @@ class ce extends lt {
|
|
|
1979
2010
|
super(t);
|
|
1980
2011
|
}
|
|
1981
2012
|
createDefaultShader() {
|
|
1982
|
-
const t =
|
|
2013
|
+
const t = ce, e = he;
|
|
1983
2014
|
return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
|
|
1984
2015
|
}
|
|
1985
2016
|
enter(t) {
|
|
1986
|
-
super.enter(t), this.currentShader.setUniform("
|
|
2017
|
+
super.enter(t), this.currentShader.setUniform("u_matrix", this.rapid.projection);
|
|
1987
2018
|
}
|
|
1988
2019
|
createShader(t, e) {
|
|
1989
2020
|
const r = super.createShader(t, e);
|
|
1990
2021
|
return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
|
|
1991
|
-
{ name: "aPosition", size: 2, stride:
|
|
1992
|
-
{ name: "aScale", size: 2, stride:
|
|
1993
|
-
{ name: "aRotation", size: 1, stride:
|
|
1994
|
-
{ name: "aUVRect", size: 4, stride:
|
|
1995
|
-
{ name: "aColor", size: 4, type:
|
|
1996
|
-
{ name: "aOrigin", size: 2, stride:
|
|
2022
|
+
{ name: "aPosition", size: 2, stride: Y, offset: 0, divisor: 1 },
|
|
2023
|
+
{ name: "aScale", size: 2, stride: Y, offset: 8, divisor: 1 },
|
|
2024
|
+
{ name: "aRotation", size: 1, stride: Y, offset: 16, divisor: 1 },
|
|
2025
|
+
{ name: "aUVRect", size: 4, stride: Y, offset: 20, divisor: 1 },
|
|
2026
|
+
{ name: "aColor", size: 4, type: ct, normalized: !0, stride: Y, offset: 36, divisor: 1 },
|
|
2027
|
+
{ name: "aOrigin", size: 2, stride: Y, offset: 40, divisor: 1 }
|
|
1997
2028
|
]), this.quadBuffer.bindBuffer(), r.setAttributes([
|
|
1998
2029
|
{ name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
|
|
1999
2030
|
]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
|
|
2000
2031
|
}
|
|
2001
|
-
drawParticles(t, e, r, i = 0, s = 4294967295, a,
|
|
2032
|
+
drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, x = !1, y = 0.5, v = 0.5, T, w = !1, U) {
|
|
2002
2033
|
if (!t.glTexture || a <= 0) return;
|
|
2003
2034
|
this.texture && t !== this.texture && this.flush();
|
|
2004
|
-
const P = typeof
|
|
2005
|
-
let
|
|
2006
|
-
P && (
|
|
2007
|
-
let
|
|
2008
|
-
|
|
2009
|
-
let H =
|
|
2010
|
-
|
|
2011
|
-
const
|
|
2035
|
+
const P = typeof o == "number", O = typeof h == "number", L = typeof i == "number", S = typeof s == "number", E = typeof c == "number", b = !S && typeof s[0] == "number", I = t.uvW - t.uvX, k = t.uvH - t.uvY, G = I === 0 ? 0 : 1 / I, N = k === 0 ? 0 : 1 / k;
|
|
2036
|
+
let F = t.rawWidth * (f ? -1 : 1);
|
|
2037
|
+
P && (F *= o);
|
|
2038
|
+
let V = t.rawHeight * (m ? -1 : 1);
|
|
2039
|
+
O && (V *= h), E && (F *= (l - c) * G, V *= (d - u) * N);
|
|
2040
|
+
let H = x ? Math.PI / 2 : 0;
|
|
2041
|
+
L && (H += i);
|
|
2042
|
+
const R = s ?? 4294967295, A = this.getParticleLoop(
|
|
2012
2043
|
P,
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
C,
|
|
2017
|
-
w,
|
|
2044
|
+
O,
|
|
2045
|
+
L,
|
|
2046
|
+
E,
|
|
2018
2047
|
S,
|
|
2019
|
-
|
|
2048
|
+
b,
|
|
2049
|
+
w,
|
|
2050
|
+
T
|
|
2020
2051
|
);
|
|
2021
2052
|
this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
|
|
2022
|
-
const
|
|
2023
|
-
let
|
|
2024
|
-
|
|
2025
|
-
const
|
|
2026
|
-
|
|
2053
|
+
const $ = a, B = this.instanceBuffer;
|
|
2054
|
+
let X = B.usedElemNum;
|
|
2055
|
+
B.resize($ * ue);
|
|
2056
|
+
const bt = B.float32, Ut = B.uint32;
|
|
2057
|
+
X = A(
|
|
2027
2058
|
e,
|
|
2028
2059
|
r,
|
|
2029
|
-
h,
|
|
2030
2060
|
o,
|
|
2061
|
+
h,
|
|
2031
2062
|
i,
|
|
2032
2063
|
c,
|
|
2033
2064
|
u,
|
|
2034
2065
|
l,
|
|
2035
|
-
|
|
2066
|
+
d,
|
|
2036
2067
|
s,
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2068
|
+
bt,
|
|
2069
|
+
Ut,
|
|
2070
|
+
F,
|
|
2071
|
+
V,
|
|
2041
2072
|
G,
|
|
2042
|
-
|
|
2073
|
+
N,
|
|
2043
2074
|
H,
|
|
2044
|
-
|
|
2045
|
-
y,
|
|
2046
|
-
v,
|
|
2075
|
+
R,
|
|
2076
|
+
1 - y,
|
|
2077
|
+
1 - v,
|
|
2047
2078
|
a,
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
),
|
|
2079
|
+
$,
|
|
2080
|
+
X
|
|
2081
|
+
), B.usedElemNum = X, B.makeDirty(), this.instanceCount += $, this.customMatrix = U, this.flush();
|
|
2051
2082
|
}
|
|
2052
|
-
getParticleLoop(t, e, r, i, s, a,
|
|
2083
|
+
getParticleLoop(t, e, r, i, s, a, o, h) {
|
|
2053
2084
|
const c = [...arguments].join("_");
|
|
2054
2085
|
if (this.particleLoopCache.has(c))
|
|
2055
2086
|
return this.particleLoopCache.get(c);
|
|
@@ -2062,7 +2093,7 @@ const endIdx = index + batchCount * 12;
|
|
|
2062
2093
|
let idx = index;
|
|
2063
2094
|
if (endIdx > f32.length) return index;
|
|
2064
2095
|
|
|
2065
|
-
${
|
|
2096
|
+
${o ? "for (let src = count - 1; idx < endIdx; src--, idx += 12) {" : "for (let src = 0; idx < endIdx; src++, idx += 12) {"}
|
|
2066
2097
|
f32[idx] = x[src];
|
|
2067
2098
|
f32[idx + 1] = y[src];
|
|
2068
2099
|
|
|
@@ -2085,7 +2116,7 @@ f32[idx + 7] = cu1;
|
|
|
2085
2116
|
f32[idx + 8] = cv1;
|
|
2086
2117
|
`}
|
|
2087
2118
|
|
|
2088
|
-
u32[idx + 9] = ${s ? "staticColor" : a ? "color[src]" : `color[src].${
|
|
2119
|
+
u32[idx + 9] = ${s ? "staticColor" : a ? "color[src]" : `color[src].${h ? "premultipliedUint32" : "uint32"}`};
|
|
2089
2120
|
|
|
2090
2121
|
f32[idx + 10] = originX;
|
|
2091
2122
|
f32[idx + 11] = originY;
|
|
@@ -2103,30 +2134,171 @@ return idx;
|
|
|
2103
2134
|
this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
|
|
2104
2135
|
const e = this.currentShader;
|
|
2105
2136
|
this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
|
|
2106
|
-
const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a =
|
|
2107
|
-
this.currentShader.setUniform("
|
|
2137
|
+
const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
|
|
2138
|
+
this.currentShader.setUniform("u_matrix", a), wt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
var de = /* @__PURE__ */ ((n) => (n[n.KEEP_W = 0] = "KEEP_W", n[n.KEEP_H = 1] = "KEEP_H", n[n.KEEP = 2] = "KEEP", n[n.IGNORE = 3] = "IGNORE", n[n.EXPAND = 4] = "EXPAND", n[n.NONE = 5] = "NONE", n))(de || {});
|
|
2142
|
+
const fe = {
|
|
2143
|
+
4: new p(1, 1),
|
|
2144
|
+
0: new p(0, 1),
|
|
2145
|
+
1: new p(1, 0),
|
|
2146
|
+
2: new p(0, 0)
|
|
2147
|
+
}, gt = {
|
|
2148
|
+
4: new p(0.5, 0.5),
|
|
2149
|
+
0: new p(0.5, 0),
|
|
2150
|
+
1: new p(0, 0.5),
|
|
2151
|
+
2: new p(0.5, 0.5)
|
|
2152
|
+
};
|
|
2153
|
+
class me {
|
|
2154
|
+
constructor(t, e) {
|
|
2155
|
+
this.rapid = t, this.updateWindowOption(e);
|
|
2156
|
+
}
|
|
2157
|
+
viewLeft = 0;
|
|
2158
|
+
viewRight = 0;
|
|
2159
|
+
viewTop = 0;
|
|
2160
|
+
viewBottom = 0;
|
|
2161
|
+
window = {};
|
|
2162
|
+
scissorViewport = null;
|
|
2163
|
+
resolution = 0;
|
|
2164
|
+
updateWindowOption(t) {
|
|
2165
|
+
Object.assign(this.window, t);
|
|
2166
|
+
}
|
|
2167
|
+
resize(t, e, r, i) {
|
|
2168
|
+
const s = this.rapid, a = this.window, o = a.scale ?? 1;
|
|
2169
|
+
t /= o, e /= o, s.flush();
|
|
2170
|
+
const h = r ?? s.canvas.clientWidth ?? s.canvas.width, c = i ?? s.canvas.clientHeight ?? s.canvas.height;
|
|
2171
|
+
r !== void 0 && (s.canvas.style.width = h + "px"), i !== void 0 && (s.canvas.style.height = c + "px"), s.physicsWidth = h * s.dpr, s.physicsHeight = c * s.dpr, s.logicWidth = t, s.logicHeight = e;
|
|
2172
|
+
let u = 0, l = t, d = e, f = 0;
|
|
2173
|
+
const m = a.scaleMode ?? Q.CanvasItem, x = a.expand ?? 2;
|
|
2174
|
+
let y = p.ZERO, v = p.ZERO;
|
|
2175
|
+
switch (x in gt && (y = a.expandPosition ?? gt[x], v = fe[x]), this.scissorViewport = null, x) {
|
|
2176
|
+
case 3: {
|
|
2177
|
+
u = 0, l = t, d = e, f = 0;
|
|
2178
|
+
break;
|
|
2179
|
+
}
|
|
2180
|
+
case 5: {
|
|
2181
|
+
u = 0, l = s.physicsWidth, d = s.physicsHeight, f = 0;
|
|
2182
|
+
break;
|
|
2183
|
+
}
|
|
2184
|
+
default:
|
|
2185
|
+
case 4:
|
|
2186
|
+
case 0:
|
|
2187
|
+
case 1:
|
|
2188
|
+
case 2: {
|
|
2189
|
+
const T = y, w = v, U = Math.min(
|
|
2190
|
+
s.physicsWidth / t,
|
|
2191
|
+
s.physicsHeight / e
|
|
2192
|
+
), P = s.physicsWidth / U, O = s.physicsHeight / U, L = P - t, S = O - e;
|
|
2193
|
+
if (u = -L * T.x, l = t + L * (1 - T.x), f = -S * T.y, d = e + S * (1 - T.y), !w.x && L > 0 || !w.y && S > 0) {
|
|
2194
|
+
const E = w.x && L > 0 ? u : 0, b = w.x && L > 0 ? l : t, I = w.y && S > 0 ? f : 0, k = w.y && S > 0 ? d : e;
|
|
2195
|
+
this.scissorViewport = {
|
|
2196
|
+
x: E,
|
|
2197
|
+
y: I,
|
|
2198
|
+
width: b - E,
|
|
2199
|
+
height: k - I
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
break;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
switch (m) {
|
|
2206
|
+
case Q.Viewport:
|
|
2207
|
+
s.canvas.width = t, s.canvas.height = e, s.canvas.style.imageRendering = "pixelated", s.gl.viewport(0, 0, t, e);
|
|
2208
|
+
break;
|
|
2209
|
+
default:
|
|
2210
|
+
case Q.CanvasItem:
|
|
2211
|
+
s.canvas.width = s.physicsWidth, s.canvas.height = s.physicsHeight, s.canvas.style.imageRendering = "auto", s.gl.viewport(
|
|
2212
|
+
0,
|
|
2213
|
+
0,
|
|
2214
|
+
s.physicsWidth,
|
|
2215
|
+
s.physicsHeight
|
|
2216
|
+
);
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
this.viewLeft = u, this.viewRight = l, this.viewTop = f, this.viewBottom = d, this.updateProjection(), this.restoreViewportScissor(), this.updateResolution(m);
|
|
2220
|
+
}
|
|
2221
|
+
updateResolution(t) {
|
|
2222
|
+
let e = 1;
|
|
2223
|
+
const r = this.rapid.texture;
|
|
2224
|
+
if (t !== Q.Viewport) {
|
|
2225
|
+
const i = this.viewRight - this.viewLeft, s = this.viewBottom - this.viewTop;
|
|
2226
|
+
e = Math.max(
|
|
2227
|
+
this.rapid.physicsWidth / i,
|
|
2228
|
+
this.rapid.physicsHeight / s
|
|
2229
|
+
);
|
|
2230
|
+
}
|
|
2231
|
+
e != this.resolution && (this.resolution = e, r.texture.forEach((i) => i.updateResolution()));
|
|
2232
|
+
}
|
|
2233
|
+
updateProjection() {
|
|
2234
|
+
this.rapid.updateProjection(
|
|
2235
|
+
this.viewLeft,
|
|
2236
|
+
this.viewRight,
|
|
2237
|
+
this.viewBottom,
|
|
2238
|
+
this.viewTop
|
|
2239
|
+
);
|
|
2240
|
+
}
|
|
2241
|
+
updateOrthMatrix(t, e, r, i, s) {
|
|
2242
|
+
t[0] = 2 / (r - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (s - 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] = -(s + i) / (s - i), t[14] = 0, t[15] = 1;
|
|
2243
|
+
}
|
|
2244
|
+
applyCamera(t) {
|
|
2245
|
+
const e = this.rapid, r = e.matrix, i = e.matrixStack, s = this.scissorViewport && e.gl.getParameter(e.gl.FRAMEBUFFER_BINDING) === null ? this.scissorViewport : null, a = s?.width ?? this.viewRight - this.viewLeft, o = s?.height ?? this.viewBottom - this.viewTop, h = s ? s.x + a / 2 : (this.viewLeft + this.viewRight) / 2, c = s ? s.y + o / 2 : (this.viewTop + this.viewBottom) / 2, u = i.curWorldM, l = r.temporary, d = r.applyTransform(t, 0, 0);
|
|
2246
|
+
r.setMatrix(l, d), r.clampBounds(
|
|
2247
|
+
l,
|
|
2248
|
+
a,
|
|
2249
|
+
o,
|
|
2250
|
+
t.limitLeft,
|
|
2251
|
+
t.limitRight,
|
|
2252
|
+
t.limitTop,
|
|
2253
|
+
t.limitBottom
|
|
2254
|
+
), i.translate(h, c), r.invert(l), r.multiplyOut(u, u, l);
|
|
2255
|
+
}
|
|
2256
|
+
startScissor(t, e, r, i) {
|
|
2257
|
+
const s = this.rapid;
|
|
2258
|
+
s.flush();
|
|
2259
|
+
const a = s.gl, o = this.scissorViewport;
|
|
2260
|
+
if (o && a.getParameter(a.FRAMEBUFFER_BINDING) === null) {
|
|
2261
|
+
const P = Math.max(Math.min(t, t + r), o.x), O = Math.min(Math.max(t, t + r), o.x + o.width), L = Math.max(Math.min(e, e + i), o.y), S = Math.min(
|
|
2262
|
+
Math.max(e, e + i),
|
|
2263
|
+
o.y + o.height
|
|
2264
|
+
);
|
|
2265
|
+
t = P, e = L, r = Math.max(0, O - P), i = Math.max(0, S - L);
|
|
2266
|
+
}
|
|
2267
|
+
const [h, c, u, l] = a.getParameter(
|
|
2268
|
+
a.VIEWPORT
|
|
2269
|
+
), d = s.projection, f = h + (d[0] * t + d[12] + 1) * u / 2, m = h + (d[0] * (t + r) + d[12] + 1) * u / 2, x = c + (d[5] * e + d[13] + 1) * l / 2, y = c + (d[5] * (e + i) + d[13] + 1) * l / 2, v = Math.round(Math.min(f, m)), T = Math.round(Math.max(f, m)), w = Math.round(Math.min(x, y)), U = Math.round(Math.max(x, y));
|
|
2270
|
+
a.enable(a.SCISSOR_TEST), a.scissor(v, w, T - v, U - w);
|
|
2271
|
+
}
|
|
2272
|
+
restoreViewportScissor() {
|
|
2273
|
+
this.rapid.flush();
|
|
2274
|
+
const t = this.rapid.gl, e = this.scissorViewport;
|
|
2275
|
+
e && t.getParameter(t.FRAMEBUFFER_BINDING) === null ? this.startScissor(e.x, e.y, e.width, e.height) : t.disable(t.SCISSOR_TEST);
|
|
2276
|
+
}
|
|
2277
|
+
endScissor() {
|
|
2278
|
+
this.restoreViewportScissor();
|
|
2108
2279
|
}
|
|
2109
2280
|
}
|
|
2110
|
-
var
|
|
2111
|
-
class
|
|
2281
|
+
var St = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(St || {}), xe = /* @__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))(xe || {}), Q = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(Q || {});
|
|
2282
|
+
class we {
|
|
2112
2283
|
gl;
|
|
2113
2284
|
canvas;
|
|
2114
2285
|
projection = new Float32Array(16);
|
|
2115
2286
|
projectionDirty = !0;
|
|
2116
2287
|
dpr;
|
|
2117
|
-
backgroundColor =
|
|
2288
|
+
backgroundColor = g.Black;
|
|
2118
2289
|
logicWidth = 0;
|
|
2119
2290
|
logicHeight = 0;
|
|
2120
2291
|
physicsWidth = 0;
|
|
2121
2292
|
physicsHeight = 0;
|
|
2122
2293
|
currentRegion = null;
|
|
2123
2294
|
maxTextureUnits = 0;
|
|
2124
|
-
matrixStack = new
|
|
2295
|
+
matrixStack = new Ht(this);
|
|
2125
2296
|
matrix;
|
|
2126
2297
|
spriteRegion;
|
|
2127
2298
|
graphicRegion;
|
|
2128
2299
|
atlasSpriteRegion;
|
|
2129
2300
|
particleRegion;
|
|
2301
|
+
regions;
|
|
2130
2302
|
drawcallCount = 0;
|
|
2131
2303
|
inCreateMask = !1;
|
|
2132
2304
|
texture;
|
|
@@ -2134,9 +2306,9 @@ class pe {
|
|
|
2134
2306
|
antialias;
|
|
2135
2307
|
roundPixels;
|
|
2136
2308
|
textureFilter;
|
|
2137
|
-
|
|
2309
|
+
viewport;
|
|
2138
2310
|
_filterRT = [null, null];
|
|
2139
|
-
_filterInput = new
|
|
2311
|
+
_filterInput = new W();
|
|
2140
2312
|
get height() {
|
|
2141
2313
|
return this.logicHeight;
|
|
2142
2314
|
}
|
|
@@ -2144,38 +2316,41 @@ class pe {
|
|
|
2144
2316
|
return this.logicWidth;
|
|
2145
2317
|
}
|
|
2146
2318
|
constructor(t) {
|
|
2147
|
-
this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ??
|
|
2148
|
-
const e =
|
|
2149
|
-
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new
|
|
2150
|
-
|
|
2151
|
-
|
|
2319
|
+
this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? it.NEAREST, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1;
|
|
2320
|
+
const e = Nt(this.canvas, this.antialias, this.premultipliedAlpha);
|
|
2321
|
+
this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new dt(this), this.graphicRegion = new $t(this), this.atlasSpriteRegion = new oe(this), this.particleRegion = new le(this), this.viewport = new me(this, t.window), this.texture = new Ct(this), this.regions = [
|
|
2322
|
+
this.spriteRegion,
|
|
2323
|
+
this.atlasSpriteRegion
|
|
2324
|
+
];
|
|
2325
|
+
const r = this.canvas.clientWidth ?? this.canvas.width, i = this.canvas.clientHeight ?? this.canvas.height;
|
|
2326
|
+
this.physicsWidth = t.physicsWidth ?? Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight ?? Math.round(i * this.dpr), this.logicWidth = t.width ?? this.physicsWidth / this.dpr, this.logicHeight = t.height ?? this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), 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);
|
|
2152
2327
|
}
|
|
2153
2328
|
setTextureFilter(t) {
|
|
2154
2329
|
this.textureFilter = t;
|
|
2155
2330
|
}
|
|
2156
2331
|
getColorUint32(t) {
|
|
2157
|
-
return
|
|
2332
|
+
return Jt(this.premultipliedAlpha, t);
|
|
2158
2333
|
}
|
|
2159
2334
|
enterRegion(t, e) {
|
|
2160
2335
|
this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
|
|
2161
2336
|
}
|
|
2162
2337
|
drawParticles(t) {
|
|
2163
|
-
|
|
2338
|
+
re(this, t);
|
|
2164
2339
|
}
|
|
2165
2340
|
drawSprite(t) {
|
|
2166
|
-
|
|
2341
|
+
ee(this, t);
|
|
2167
2342
|
}
|
|
2168
2343
|
drawLine(t) {
|
|
2169
|
-
|
|
2344
|
+
ie(this, t);
|
|
2170
2345
|
}
|
|
2171
2346
|
drawGraphic(t) {
|
|
2172
2347
|
Mt(this, t);
|
|
2173
2348
|
}
|
|
2174
2349
|
drawRect(t) {
|
|
2175
|
-
|
|
2350
|
+
ne(this, t);
|
|
2176
2351
|
}
|
|
2177
2352
|
drawCircle(t) {
|
|
2178
|
-
|
|
2353
|
+
ae(this, t);
|
|
2179
2354
|
}
|
|
2180
2355
|
startGraphic(t = this.gl.TRIANGLES, e, r, i) {
|
|
2181
2356
|
this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
|
|
@@ -2184,7 +2359,7 @@ class pe {
|
|
|
2184
2359
|
this.startGraphic(t, e, this.graphicRegion.maskShader, r);
|
|
2185
2360
|
}
|
|
2186
2361
|
drawMaskImage(t) {
|
|
2187
|
-
|
|
2362
|
+
se(this, t);
|
|
2188
2363
|
}
|
|
2189
2364
|
addRectVertex(t, e, r) {
|
|
2190
2365
|
const i = this.getColorUint32(r);
|
|
@@ -2193,8 +2368,8 @@ class pe {
|
|
|
2193
2368
|
addCircleVertex(t, e, r = 32) {
|
|
2194
2369
|
const i = Math.PI * 2 / r, s = this.getColorUint32(e);
|
|
2195
2370
|
for (let a = 0; a < r; a++) {
|
|
2196
|
-
const
|
|
2197
|
-
this.addGraphicVertex(
|
|
2371
|
+
const o = i * a, h = Math.cos(o) * t, c = Math.sin(o) * t, u = 0.5 + Math.cos(o) * 0.5, l = 0.5 + Math.sin(o) * 0.5;
|
|
2372
|
+
this.addGraphicVertex(h, c, u, l, s);
|
|
2198
2373
|
}
|
|
2199
2374
|
}
|
|
2200
2375
|
addGraphicVertex(t, e, r = 0, i = 0, s = 4294967295) {
|
|
@@ -2204,29 +2379,14 @@ class pe {
|
|
|
2204
2379
|
this.graphicRegion.endGraphic();
|
|
2205
2380
|
}
|
|
2206
2381
|
resize(t, e, r, i) {
|
|
2207
|
-
this.
|
|
2208
|
-
const s = r ?? this.canvas.clientWidth ?? this.canvas.width, a = i ?? this.canvas.clientHeight ?? this.canvas.height;
|
|
2209
|
-
switch (r !== void 0 && (this.canvas.style.width = s + "px"), i !== void 0 && (this.canvas.style.height = a + "px"), this.physicsWidth = s * this.dpr, this.physicsHeight = a * this.dpr, this.logicWidth = t, this.logicHeight = e, this.scaleMode) {
|
|
2210
|
-
case 1:
|
|
2211
|
-
this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
|
|
2212
|
-
break;
|
|
2213
|
-
case 0:
|
|
2214
|
-
this.canvas.width = this.physicsWidth, this.canvas.height = this.physicsHeight, this.canvas.style.imageRendering = "auto", this.gl.viewport(0, 0, this.physicsWidth, this.physicsHeight);
|
|
2215
|
-
break;
|
|
2216
|
-
default:
|
|
2217
|
-
throw new Error("scaleMode can only be CanvasScaleMode.Viewport or CanvasScaleMode.CanvasItem");
|
|
2218
|
-
}
|
|
2219
|
-
this.updateProjection(0, this.logicWidth, this.logicHeight, 0);
|
|
2382
|
+
this.viewport.resize(t, e, r, i);
|
|
2220
2383
|
}
|
|
2221
2384
|
updateProjection(t, e, r, i) {
|
|
2222
|
-
this.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
|
|
2385
|
+
this.viewport.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
|
|
2223
2386
|
}
|
|
2224
2387
|
clear() {
|
|
2225
2388
|
const t = this.gl;
|
|
2226
|
-
this.backgroundColor.setClearColor(t), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT), this.drawcallCount = 0, this.matrixStack.reset();
|
|
2227
|
-
}
|
|
2228
|
-
updateOrthMatrix(t, e, r, i, s) {
|
|
2229
|
-
t[0] = 2 / (r - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (s - 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] = -(s + i) / (s - i), t[14] = 0, t[15] = 1;
|
|
2389
|
+
this.flush(), t.disable(t.SCISSOR_TEST), this.viewport.scissorViewport && t.getParameter(t.FRAMEBUFFER_BINDING) === null ? (t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT), this.backgroundColor.setClearColor(t, this.premultipliedAlpha), this.viewport.restoreViewportScissor(), t.clear(t.COLOR_BUFFER_BIT)) : (this.backgroundColor.setClearColor(t, this.premultipliedAlpha), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT)), this.drawcallCount = 0, this.matrixStack.reset();
|
|
2230
2390
|
}
|
|
2231
2391
|
flush() {
|
|
2232
2392
|
this.currentRegion && (this.currentRegion.exit(), this.currentRegion = null);
|
|
@@ -2237,33 +2397,33 @@ class pe {
|
|
|
2237
2397
|
const r = Math.max(...e.map((c) => c.padding)), i = r, s = t.rawWidth + r * 2, a = t.rawHeight + r * 2;
|
|
2238
2398
|
for (let c = 0; c < 2; c++)
|
|
2239
2399
|
this._filterRT[c] ? this._filterRT[c].resize(s, a) : this._filterRT[c] = this.texture.createRenderTexture({ width: s, height: a });
|
|
2240
|
-
let
|
|
2400
|
+
let o = t.clone(this._filterInput), h = 0;
|
|
2241
2401
|
this.matrixStack.save(), this.matrixStack.identity();
|
|
2242
2402
|
for (let c = 0; c < e.length; c++) {
|
|
2243
|
-
const u = this._filterRT[
|
|
2403
|
+
const u = this._filterRT[h % 2];
|
|
2244
2404
|
u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
|
|
2245
|
-
texture:
|
|
2405
|
+
texture: o,
|
|
2246
2406
|
shader: e[c],
|
|
2247
2407
|
offsetX: c == 0 ? i : 0,
|
|
2248
2408
|
// padding back
|
|
2249
2409
|
offsetY: c == 0 ? i : 0,
|
|
2250
2410
|
padding: r
|
|
2251
|
-
}), this.leaveRenderTexture(),
|
|
2411
|
+
}), this.leaveRenderTexture(), o = u, h++;
|
|
2252
2412
|
}
|
|
2253
|
-
return this.matrixStack.restore(),
|
|
2413
|
+
return this.matrixStack.restore(), o.offsetX = -i, o.offsetY = -i, o;
|
|
2254
2414
|
}
|
|
2255
2415
|
enterRenderTexture(t) {
|
|
2256
|
-
this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, 0, t.rawHeight);
|
|
2416
|
+
this.flush(), t.activate(), this.viewport.restoreViewportScissor(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, 0, t.rawHeight);
|
|
2257
2417
|
}
|
|
2258
|
-
clearRenderTexture(t = new
|
|
2418
|
+
clearRenderTexture(t = new g(0, 0, 0, 0)) {
|
|
2259
2419
|
this.flush();
|
|
2260
2420
|
const e = this.gl;
|
|
2261
|
-
t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
|
|
2421
|
+
t.setClearColor(e, this.premultipliedAlpha), e.clear(e.COLOR_BUFFER_BIT);
|
|
2262
2422
|
}
|
|
2263
2423
|
leaveRenderTexture() {
|
|
2264
|
-
this.flush(), this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null), this.gl.viewport(0, 0, this.
|
|
2424
|
+
this.flush(), this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null), this.gl.viewport(0, 0, this.canvas.width, this.canvas.height), this.viewport.updateProjection(), this.viewport.restoreViewportScissor();
|
|
2265
2425
|
}
|
|
2266
|
-
drawToRenderTexture(t, e, r = new
|
|
2426
|
+
drawToRenderTexture(t, e, r = new g(0, 0, 0, 0)) {
|
|
2267
2427
|
this.enterRenderTexture(t);
|
|
2268
2428
|
try {
|
|
2269
2429
|
r !== null && this.clearRenderTexture(r), e();
|
|
@@ -2359,26 +2519,22 @@ class pe {
|
|
|
2359
2519
|
}
|
|
2360
2520
|
}
|
|
2361
2521
|
startScissor(t, e, r, i) {
|
|
2362
|
-
this.
|
|
2363
|
-
const s = this.gl, a = this.physicsWidth / this.logicWidth, h = this.physicsHeight / this.logicHeight, o = Math.round(t * a), c = Math.round(this.physicsHeight - (e + i) * h), u = Math.round(r * a), l = Math.round(i * h);
|
|
2364
|
-
s.enable(s.SCISSOR_TEST), s.scissor(o, c, u, l);
|
|
2522
|
+
this.viewport.startScissor(t, e, r, i);
|
|
2365
2523
|
}
|
|
2366
2524
|
endScissor() {
|
|
2367
|
-
this.
|
|
2525
|
+
this.viewport.endScissor();
|
|
2368
2526
|
}
|
|
2369
2527
|
applyCamera(t) {
|
|
2370
|
-
this.
|
|
2371
|
-
const e = this.matrixStack.curWorldM;
|
|
2372
|
-
this.matrix.invert(e);
|
|
2528
|
+
this.viewport.applyCamera(t);
|
|
2373
2529
|
}
|
|
2374
2530
|
logicToPhysics(t) {
|
|
2375
|
-
return t.multiply(new
|
|
2531
|
+
return t.multiply(new p(
|
|
2376
2532
|
this.physicsWidth / this.logicWidth,
|
|
2377
2533
|
this.physicsHeight / this.logicHeight
|
|
2378
2534
|
));
|
|
2379
2535
|
}
|
|
2380
2536
|
physicsToLogic(t) {
|
|
2381
|
-
return t.multiply(new
|
|
2537
|
+
return t.multiply(new p(
|
|
2382
2538
|
this.logicWidth / this.physicsWidth,
|
|
2383
2539
|
this.logicHeight / this.physicsHeight
|
|
2384
2540
|
));
|
|
@@ -2398,10 +2554,10 @@ class pe {
|
|
|
2398
2554
|
return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
|
|
2399
2555
|
}
|
|
2400
2556
|
}
|
|
2401
|
-
function
|
|
2402
|
-
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof
|
|
2557
|
+
function pe(n) {
|
|
2558
|
+
return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof g);
|
|
2403
2559
|
}
|
|
2404
|
-
class
|
|
2560
|
+
class D {
|
|
2405
2561
|
static float(t, e) {
|
|
2406
2562
|
return Math.random() * (e - t) + t;
|
|
2407
2563
|
}
|
|
@@ -2412,18 +2568,18 @@ class N {
|
|
|
2412
2568
|
return Math.random() * Math.PI * 2;
|
|
2413
2569
|
}
|
|
2414
2570
|
static vector(t, e, r, i) {
|
|
2415
|
-
return new
|
|
2571
|
+
return new p(D.float(t, e), D.float(r, i));
|
|
2416
2572
|
}
|
|
2417
2573
|
static randomColor(t, e) {
|
|
2418
|
-
return new
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2574
|
+
return new g(
|
|
2575
|
+
D.float(t.r, e.r),
|
|
2576
|
+
D.float(t.g, e.g),
|
|
2577
|
+
D.float(t.b, e.b),
|
|
2578
|
+
D.float(t.a, e.a)
|
|
2423
2579
|
);
|
|
2424
2580
|
}
|
|
2425
2581
|
static pick(t) {
|
|
2426
|
-
return t[
|
|
2582
|
+
return t[D.int(0, t.length - 1)];
|
|
2427
2583
|
}
|
|
2428
2584
|
static pickWeight(t) {
|
|
2429
2585
|
if (!t || t.length === 0) return null;
|
|
@@ -2439,27 +2595,27 @@ class N {
|
|
|
2439
2595
|
if (Array.isArray(t)) {
|
|
2440
2596
|
const [r, i] = t;
|
|
2441
2597
|
if (typeof r == "number")
|
|
2442
|
-
return
|
|
2598
|
+
return D.float(r, i);
|
|
2599
|
+
if (r instanceof p)
|
|
2600
|
+
return D.vector(r.x, i.x, r.y, i.y);
|
|
2443
2601
|
if (r instanceof g)
|
|
2444
|
-
return
|
|
2445
|
-
if (r instanceof m)
|
|
2446
|
-
return N.randomColor(r, i);
|
|
2602
|
+
return D.randomColor(r, i);
|
|
2447
2603
|
}
|
|
2448
2604
|
return typeof t == "number" ? t : t.clone();
|
|
2449
2605
|
}
|
|
2450
2606
|
}
|
|
2451
|
-
const
|
|
2452
|
-
var
|
|
2453
|
-
const
|
|
2454
|
-
class
|
|
2607
|
+
const et = (n, t) => (Array.isArray(n) ? n : [n]).slice(0, t);
|
|
2608
|
+
var ge = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(ge || {});
|
|
2609
|
+
const vt = 10, yt = 0, Tt = !0;
|
|
2610
|
+
class q {
|
|
2455
2611
|
components;
|
|
2456
2612
|
constructor(t = 1) {
|
|
2457
2613
|
if (!Number.isInteger(t) || t <= 0)
|
|
2458
2614
|
throw new RangeError("ParticleAttributeStore size must be a positive integer");
|
|
2459
2615
|
this.components = Array.from({ length: t }, () => ({
|
|
2460
|
-
value: new
|
|
2461
|
-
delta: new
|
|
2462
|
-
damping: new
|
|
2616
|
+
value: new _(C.Float32),
|
|
2617
|
+
delta: new _(C.Float32),
|
|
2618
|
+
damping: new _(C.Float32)
|
|
2463
2619
|
}));
|
|
2464
2620
|
}
|
|
2465
2621
|
getArrayBuffer() {
|
|
@@ -2476,7 +2632,7 @@ class j {
|
|
|
2476
2632
|
getComponent(t, e) {
|
|
2477
2633
|
if (typeof t == "number")
|
|
2478
2634
|
return t;
|
|
2479
|
-
if (t instanceof
|
|
2635
|
+
if (t instanceof p)
|
|
2480
2636
|
return e === 0 ? t.x : t.y;
|
|
2481
2637
|
switch (e) {
|
|
2482
2638
|
case 0:
|
|
@@ -2492,47 +2648,47 @@ class j {
|
|
|
2492
2648
|
}
|
|
2493
2649
|
}
|
|
2494
2650
|
resolveComponent(t, e, r) {
|
|
2495
|
-
return t === void 0 ? r : Array.isArray(t) ?
|
|
2651
|
+
return t === void 0 ? r : Array.isArray(t) ? D.float(
|
|
2496
2652
|
this.getComponent(t[0], e),
|
|
2497
2653
|
this.getComponent(t[1], e)
|
|
2498
2654
|
) : this.getComponent(t, e);
|
|
2499
2655
|
}
|
|
2500
2656
|
create(t, e, r = 1) {
|
|
2501
|
-
const i =
|
|
2502
|
-
let
|
|
2503
|
-
for (let
|
|
2504
|
-
const { value: c, delta: u, damping: l } = this.components[
|
|
2505
|
-
c.push(
|
|
2657
|
+
const i = pe(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
|
|
2658
|
+
let o = 0;
|
|
2659
|
+
for (let h = 0; h < this.components.length; h++) {
|
|
2660
|
+
const { value: c, delta: u, damping: l } = this.components[h], d = this.getComponent(e, h), f = s === void 0 ? this.resolveComponent(i?.start, h, d) : this.getComponent(s, h), m = i?.end === void 0 ? f : this.resolveComponent(i.end, h, d);
|
|
2661
|
+
c.push(f), u.push(i?.delta === void 0 ? (m - f) / a : this.getComponent(i.delta, h)), l.push(i?.damping ?? 1), h === 0 && (o = f);
|
|
2506
2662
|
}
|
|
2507
|
-
return
|
|
2663
|
+
return o;
|
|
2508
2664
|
}
|
|
2509
2665
|
}
|
|
2510
|
-
class
|
|
2666
|
+
class At {
|
|
2511
2667
|
options;
|
|
2512
2668
|
emitting = !1;
|
|
2513
2669
|
emitTimer = 0;
|
|
2514
|
-
emitRate =
|
|
2515
|
-
emitTime =
|
|
2670
|
+
emitRate = vt;
|
|
2671
|
+
emitTime = yt;
|
|
2516
2672
|
emitTimeCounter = 0;
|
|
2517
|
-
localSpace =
|
|
2673
|
+
localSpace = Tt;
|
|
2518
2674
|
rapid;
|
|
2519
|
-
x = new
|
|
2520
|
-
y = new
|
|
2521
|
-
scaleX = new
|
|
2522
|
-
scaleY = new
|
|
2523
|
-
rotation = new
|
|
2524
|
-
color = new
|
|
2525
|
-
remainingLife = new
|
|
2675
|
+
x = new _(C.Float32);
|
|
2676
|
+
y = new _(C.Float32);
|
|
2677
|
+
scaleX = new _(C.Float32);
|
|
2678
|
+
scaleY = new _(C.Float32);
|
|
2679
|
+
rotation = new _(C.Float32);
|
|
2680
|
+
color = new _(C.Uint32);
|
|
2681
|
+
remainingLife = new _(C.Float32);
|
|
2526
2682
|
animations = {
|
|
2527
|
-
speed: new
|
|
2528
|
-
rotation: new
|
|
2529
|
-
scale: new
|
|
2530
|
-
color: new
|
|
2531
|
-
velocity: new
|
|
2683
|
+
speed: new q(),
|
|
2684
|
+
rotation: new q(),
|
|
2685
|
+
scale: new q(),
|
|
2686
|
+
color: new q(4),
|
|
2687
|
+
velocity: new q(2)
|
|
2532
2688
|
};
|
|
2533
2689
|
count = 0;
|
|
2534
2690
|
constructor(t, e) {
|
|
2535
|
-
this.rapid = t, this.options = e, this.emitRate = e.emitRate ??
|
|
2691
|
+
this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? vt, this.emitTime = e.emitTime ?? yt, this.localSpace = e.localSpace ?? Tt;
|
|
2536
2692
|
}
|
|
2537
2693
|
getAllArrayBuffer() {
|
|
2538
2694
|
return [
|
|
@@ -2550,7 +2706,7 @@ class wt {
|
|
|
2550
2706
|
this.options.texture = t;
|
|
2551
2707
|
}
|
|
2552
2708
|
clone() {
|
|
2553
|
-
return new
|
|
2709
|
+
return new At(this.rapid, { ...this.options });
|
|
2554
2710
|
}
|
|
2555
2711
|
setEmitRate(t) {
|
|
2556
2712
|
this.emitRate = t;
|
|
@@ -2575,7 +2731,7 @@ class wt {
|
|
|
2575
2731
|
this.createParticle();
|
|
2576
2732
|
}
|
|
2577
2733
|
createParticle() {
|
|
2578
|
-
const t =
|
|
2734
|
+
const t = D.scalarOrRange(this.options.life, 1);
|
|
2579
2735
|
this.remainingLife.push(t);
|
|
2580
2736
|
let e = 0, r = 0;
|
|
2581
2737
|
switch (this.options.emitShape) {
|
|
@@ -2596,8 +2752,8 @@ class wt {
|
|
|
2596
2752
|
const { x: c, y: u } = i.localToWorld(e, r);
|
|
2597
2753
|
this.x.push(c), this.y.push(u);
|
|
2598
2754
|
}
|
|
2599
|
-
const s = this.options.animation, a = this.animations,
|
|
2600
|
-
a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity,
|
|
2755
|
+
const s = this.options.animation, a = this.animations, o = a.scale.create(s.scale, 1, t), h = a.rotation.create(s.rotation, 0, t);
|
|
2756
|
+
a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, p.ZERO, t), a.color.create(s.color, g.White, t), this.rotation.push(h), this.scaleX.push(o), this.scaleY.push(o), this.color.pushUint32(g.packColor(
|
|
2601
2757
|
a.color.get(this.count, 0),
|
|
2602
2758
|
a.color.get(this.count, 1),
|
|
2603
2759
|
a.color.get(this.count, 2),
|
|
@@ -2618,7 +2774,7 @@ class wt {
|
|
|
2618
2774
|
r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
|
|
2619
2775
|
}
|
|
2620
2776
|
const e = this.updateParticle(t);
|
|
2621
|
-
this.count -= e.length,
|
|
2777
|
+
this.count -= e.length, _.removeAtIndices(e, this.getAllArrayBuffer());
|
|
2622
2778
|
}
|
|
2623
2779
|
updateParticle(t) {
|
|
2624
2780
|
const e = [], r = this.animations;
|
|
@@ -2628,34 +2784,38 @@ class wt {
|
|
|
2628
2784
|
e.push(i);
|
|
2629
2785
|
continue;
|
|
2630
2786
|
}
|
|
2631
|
-
const s = r.rotation.get(i), a = r.scale.get(i),
|
|
2632
|
-
this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] =
|
|
2787
|
+
const s = r.rotation.get(i), a = r.scale.get(i), o = r.speed.get(i);
|
|
2788
|
+
this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = g.packColor(
|
|
2633
2789
|
r.color.get(i, 0),
|
|
2634
2790
|
r.color.get(i, 1),
|
|
2635
2791
|
r.color.get(i, 2),
|
|
2636
2792
|
r.color.get(i, 3),
|
|
2637
2793
|
this.rapid.premultipliedAlpha
|
|
2638
|
-
), this.x.typedArray[i] += (
|
|
2794
|
+
), this.x.typedArray[i] += (o * Math.cos(s) + r.velocity.get(i, 0)) * t, this.y.typedArray[i] += (o * Math.sin(s) + r.velocity.get(i, 1)) * t;
|
|
2639
2795
|
}
|
|
2640
2796
|
return e;
|
|
2641
2797
|
}
|
|
2642
|
-
render() {
|
|
2643
|
-
const
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2798
|
+
render(t) {
|
|
2799
|
+
const e = this.options, r = t ?? (this.localSpace ? void 0 : this.rapid.matrix.alloc());
|
|
2800
|
+
try {
|
|
2801
|
+
this.rapid.drawParticles({
|
|
2802
|
+
texture: e.texture,
|
|
2803
|
+
shader: e.shader,
|
|
2804
|
+
x: this.x.typedArray,
|
|
2805
|
+
y: this.y.typedArray,
|
|
2806
|
+
scaleX: this.scaleX.typedArray,
|
|
2807
|
+
scaleY: this.scaleY.typedArray,
|
|
2808
|
+
rotation: this.rotation.typedArray,
|
|
2809
|
+
color: this.color.typedArray,
|
|
2810
|
+
count: this.count,
|
|
2811
|
+
reverseOrder: !0,
|
|
2812
|
+
originX: e.origin?.x ?? 0.5,
|
|
2813
|
+
originY: e.origin?.y ?? 0.5,
|
|
2814
|
+
customMatrix: r
|
|
2815
|
+
});
|
|
2816
|
+
} finally {
|
|
2817
|
+
t === void 0 && r !== void 0 && !this.localSpace && this.rapid.matrix.free(r);
|
|
2818
|
+
}
|
|
2659
2819
|
}
|
|
2660
2820
|
isActive() {
|
|
2661
2821
|
return this.emitting || this.count > 0;
|
|
@@ -2664,12 +2824,10 @@ class wt {
|
|
|
2664
2824
|
this.emit(this.emitRate);
|
|
2665
2825
|
}
|
|
2666
2826
|
}
|
|
2667
|
-
const
|
|
2827
|
+
const ve = `
|
|
2668
2828
|
uniform mediump int uLightTextureId[%TEXTURE_NUM%];
|
|
2669
2829
|
|
|
2670
2830
|
uniform sampler2D uNormalMap;
|
|
2671
|
-
uniform vec2 uResolution;
|
|
2672
|
-
uniform vec2 uLogicalResolution;
|
|
2673
2831
|
uniform mediump int uLightCount;
|
|
2674
2832
|
uniform vec4 uLightColor[%TEXTURE_NUM%];
|
|
2675
2833
|
uniform mat3x2 uLightMatrix[%TEXTURE_NUM%];
|
|
@@ -2679,10 +2837,12 @@ uniform float uRoughness;
|
|
|
2679
2837
|
uniform vec3 uAmbientColor;
|
|
2680
2838
|
uniform vec2 uNormalScale;
|
|
2681
2839
|
|
|
2840
|
+
in vec2 light_worldPos;
|
|
2841
|
+
|
|
2682
2842
|
void light_fragment(inout vec4 color, in vec2 vRegion) {
|
|
2683
2843
|
if (color.a < 0.005) return;
|
|
2684
2844
|
|
|
2685
|
-
vec2 worldPos =
|
|
2845
|
+
vec2 worldPos = light_worldPos;
|
|
2686
2846
|
vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0);
|
|
2687
2847
|
normal = normalize(normal * vec3(uNormalScale, 1.0));
|
|
2688
2848
|
|
|
@@ -2717,8 +2877,13 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
|
|
|
2717
2877
|
|
|
2718
2878
|
color.rgb = color.rgb * (uAmbientColor + totalDiffuse) + totalSpecular;
|
|
2719
2879
|
}
|
|
2720
|
-
`,
|
|
2721
|
-
|
|
2880
|
+
`, ye = `out vec2 light_worldPos;
|
|
2881
|
+
|
|
2882
|
+
void light_vertex(inout vec4 p, vec2 u) {
|
|
2883
|
+
light_worldPos = p.xy;
|
|
2884
|
+
}
|
|
2885
|
+
`, rt = 8;
|
|
2886
|
+
class Te extends ut {
|
|
2722
2887
|
constructor(t, e = "", r = "", i = 0, s) {
|
|
2723
2888
|
super(
|
|
2724
2889
|
t,
|
|
@@ -2726,25 +2891,28 @@ class ge extends ct {
|
|
|
2726
2891
|
r,
|
|
2727
2892
|
i + 2,
|
|
2728
2893
|
s
|
|
2729
|
-
)
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
beforePreCompile() {
|
|
2897
|
+
this.prefix.push("light_");
|
|
2730
2898
|
}
|
|
2731
2899
|
getGLShader(t, e, r, i) {
|
|
2732
|
-
const s =
|
|
2733
|
-
return i = this.replaceCustomCode(i, s), r = this.replaceCustomCode(r,
|
|
2900
|
+
const s = Z(ve, t.getMaxTexutreUnit(this), "layer", "lightUV", "lightTex = ");
|
|
2901
|
+
return i = this.replaceCustomCode(i, s), r = this.replaceCustomCode(r, ye), super.getGLShader(t, e, r, i);
|
|
2734
2902
|
}
|
|
2735
2903
|
}
|
|
2736
|
-
class
|
|
2904
|
+
class Ee {
|
|
2737
2905
|
shader;
|
|
2738
2906
|
rapid;
|
|
2739
2907
|
rt;
|
|
2740
2908
|
constructor(t) {
|
|
2741
|
-
this.rapid = t, this.shader = new
|
|
2909
|
+
this.rapid = t, this.shader = new Te(t), this.rt = t.texture.createRenderTexture({ width: 0, height: 0 });
|
|
2742
2910
|
}
|
|
2743
2911
|
lightShadow(t, e, r) {
|
|
2744
2912
|
if (r.length === 0) return;
|
|
2745
|
-
const i = this.rapid, s = typeof e == "number" ? e : e.world, a = new
|
|
2913
|
+
const i = this.rapid, s = typeof e == "number" ? e : e.world, a = new p(t.rawWidth * 0.5, t.rawHeight * 0.5), o = r.map((c) => {
|
|
2746
2914
|
const u = i.matrixStack.localToWorld(c.x, c.y), l = i.matrix.worldToLocal(s, u.x, u.y);
|
|
2747
|
-
return new
|
|
2915
|
+
return new p(
|
|
2748
2916
|
// 要把LightTexture的基向量转化为RenderTexture的坐标
|
|
2749
2917
|
// 纹理是从左上角开始的,所以要 + 0.5
|
|
2750
2918
|
(l.x + 0.5) * t.rawWidth,
|
|
@@ -2752,36 +2920,39 @@ class ve {
|
|
|
2752
2920
|
);
|
|
2753
2921
|
});
|
|
2754
2922
|
this.rt.resize(t.rawWidth, t.rawHeight);
|
|
2755
|
-
const
|
|
2923
|
+
const h = Math.hypot(t.rawWidth, t.rawHeight) * 0.5 * 1.05;
|
|
2756
2924
|
return i.drawToRenderTexture(this.rt, () => {
|
|
2757
|
-
i.
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2925
|
+
i.matrixStack.save(), i.matrixStack.identity();
|
|
2926
|
+
try {
|
|
2927
|
+
i.withMask(() => {
|
|
2928
|
+
i.startMaskGraphic(i.gl.TRIANGLES);
|
|
2929
|
+
for (let c = 0; c < o.length; c++) {
|
|
2930
|
+
const u = o[c], l = o[(c + 1) % o.length], d = u.subtract(a).normalized(), f = l.subtract(a).normalized(), m = Math.max(-0.999, Math.min(1, d.dot(f))), x = Math.sqrt((1 + m) * 0.5), y = h / x, v = a.add(d.multiply(y)), T = a.add(f.multiply(y));
|
|
2931
|
+
i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(l.x, l.y), i.addGraphicVertex(T.x, T.y), i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(T.x, T.y), i.addGraphicVertex(v.x, v.y);
|
|
2932
|
+
}
|
|
2933
|
+
i.endGraphic();
|
|
2934
|
+
}, () => {
|
|
2935
|
+
i.drawSprite({ texture: t });
|
|
2936
|
+
}, St.NOT_EQUAL);
|
|
2937
|
+
} finally {
|
|
2938
|
+
i.matrixStack.restore();
|
|
2939
|
+
}
|
|
2767
2940
|
}), this.rt;
|
|
2768
2941
|
}
|
|
2769
2942
|
setupLight(t) {
|
|
2770
|
-
const e = t.customShader ?? this.shader, r =
|
|
2943
|
+
const e = t.customShader ?? this.shader, r = et(t.lightMatrix, rt), i = et(t.color, rt), s = et(t.lightHeight, rt), a = et(t.lightTexture, rt);
|
|
2771
2944
|
return e.setUniforms({
|
|
2772
|
-
uResolution: [this.rapid.physicsWidth, this.rapid.physicsHeight],
|
|
2773
|
-
uLogicalResolution: [this.rapid.logicWidth, this.rapid.logicHeight],
|
|
2774
2945
|
uNormalMap: t.normalMap.glTexture,
|
|
2775
|
-
uLightTextureId: a.map((
|
|
2946
|
+
uLightTextureId: a.map((o) => o.glTexture),
|
|
2776
2947
|
uLightCount: r.length,
|
|
2777
2948
|
uLightMatrix: Float32Array.from(r.flatMap(
|
|
2778
|
-
(
|
|
2949
|
+
(o) => Array.from(this.rapid.matrix.getMatrix(typeof o == "number" ? o : o.world))
|
|
2779
2950
|
)),
|
|
2780
|
-
uLightColor: Float32Array.from(r.flatMap((
|
|
2781
|
-
const c = i[
|
|
2951
|
+
uLightColor: Float32Array.from(r.flatMap((o, h) => {
|
|
2952
|
+
const c = i[h] ?? i[0];
|
|
2782
2953
|
return c ? [c.r / 255, c.g / 255, c.b / 255, c.a / 255] : [1, 1, 1, 1];
|
|
2783
2954
|
})),
|
|
2784
|
-
uLightHeight: Float32Array.from(r.map((
|
|
2955
|
+
uLightHeight: Float32Array.from(r.map((o, h) => s[h] ?? s[0] ?? 80)),
|
|
2785
2956
|
uMetallic: t.metallic ?? 0.8,
|
|
2786
2957
|
uRoughness: t.roughness ?? 0.15,
|
|
2787
2958
|
uAmbientColor: t.ambientColor ? [t.ambientColor.r / 255, t.ambientColor.g / 255, t.ambientColor.b / 255] : [0.1, 0.1, 0.15],
|
|
@@ -2790,37 +2961,39 @@ class ve {
|
|
|
2790
2961
|
}
|
|
2791
2962
|
}
|
|
2792
2963
|
export {
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
_t as
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2964
|
+
z as BaseTexture,
|
|
2965
|
+
xe as BlendMode,
|
|
2966
|
+
Q as CanvasScaleMode,
|
|
2967
|
+
g as Color,
|
|
2968
|
+
ut as CustomGlShader,
|
|
2969
|
+
de as ExpandMode,
|
|
2970
|
+
Et as GLShader,
|
|
2971
|
+
Ee as Light,
|
|
2972
|
+
Te as LightShader,
|
|
2973
|
+
qt as LineTextureMode,
|
|
2974
|
+
rt as MAX_LIGHTS,
|
|
2975
|
+
St as MaskType,
|
|
2976
|
+
At as ParticleEmitter,
|
|
2977
|
+
ge as ParticleShape,
|
|
2978
|
+
we as Rapid,
|
|
2979
|
+
_t as RenderTexture,
|
|
2980
|
+
Lt as TextTexture,
|
|
2981
|
+
W as Texture,
|
|
2982
|
+
it as TextureFilterMode,
|
|
2983
|
+
Ct as TextureManager,
|
|
2984
|
+
J as TextureWrapMode,
|
|
2985
|
+
p as Vec2,
|
|
2986
|
+
me as ViewPort,
|
|
2987
|
+
jt as composeProjectionWithAffine,
|
|
2988
|
+
ae as drawCircle,
|
|
2816
2989
|
Mt as drawGraphic,
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2990
|
+
ie as drawLine,
|
|
2991
|
+
se as drawMaskImage,
|
|
2992
|
+
re as drawParticles,
|
|
2993
|
+
ne as drawRect,
|
|
2994
|
+
ee as drawSprite,
|
|
2995
|
+
Jt as getColorUint32,
|
|
2996
|
+
Qt as getLineGeometry,
|
|
2997
|
+
Zt as getLineNormal,
|
|
2998
|
+
Kt as multiplyMat4
|
|
2826
2999
|
};
|