openvideo 0.1.10 → 0.2.0
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/dist/animation/gsap-animation.d.ts +1 -1
- package/dist/animation/presets.d.ts +31 -0
- package/dist/animation/types.d.ts +18 -0
- package/dist/browserAll-DjjOJsg2.js +7 -0
- package/dist/clips/base-clip.d.ts +2 -2
- package/dist/clips/caption-clip.d.ts +45 -42
- package/dist/clips/iclip.d.ts +10 -0
- package/dist/clips/text-clip.d.ts +17 -17
- package/dist/compositor.d.ts +3 -0
- package/dist/effect/effect.d.ts +4 -1
- package/dist/effect/glsl/custom-glsl.d.ts +15 -0
- package/dist/effect/glsl/gl-effect.d.ts +29 -7
- package/dist/index-DCWl03Hg.js +82357 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.es.js +35 -27
- package/dist/index.umd.js +2522 -495
- package/dist/json-serialization.d.ts +12 -1
- package/dist/sprite/base-sprite.d.ts +7 -2
- package/dist/sprite/pixi-sprite-renderer.d.ts +1 -0
- package/dist/studio.d.ts +21 -14
- package/dist/transition/glsl/gl-transition.d.ts +25 -5
- package/dist/utils/color.d.ts +8 -0
- package/dist/utils/stream-utils.d.ts +0 -5
- package/dist/webworkerAll-DY6Fccy4.js +17 -0
- package/package.json +3 -2
- package/dist/SharedSystems-BToBuu4Q.js +0 -2691
- package/dist/WebGLRenderer-CFWSnnJo.js +0 -2639
- package/dist/WebGPURenderer-7lmK3Jak.js +0 -1655
- package/dist/animation/easings.spec.d.ts +0 -1
- package/dist/animation/keyframe-animation.spec.d.ts +0 -1
- package/dist/browserAll-D7xrJ7bE.js +0 -1876
- package/dist/colorToUniform-C2jGzNe1.js +0 -97
- package/dist/index-B3edIoqh.js +0 -49178
- package/dist/webworkerAll-DvrCPjE-.js +0 -2643
|
@@ -1,2643 +0,0 @@
|
|
|
1
|
-
import { E as p, U as dt, T as ce, F as ht, G as Fe, v as Re, af as ft, M as P, l as M, d as Ue, I as w, t as R, a8 as te, R as re, w as N, H as Be, a5 as O, a6 as Me, c as D, B as C, D as W, ag as de, V as q, ah as B, m as I, ai as pt, a0 as Ge, aj as he, S as E, y as V, ak as mt, al as ne, L as Q, am as k, s as se, $ as J, n as De, q as Ae, aa as ke, ad as ze, o as gt, p as xt, ab as _t, ac as bt, ae as vt, an as yt, ao as Tt, ap as Z, aq as wt, ar as Ct, as as fe, e as y, at as Pt } from "./index-B3edIoqh.js";
|
|
2
|
-
import { c as L, a as St, b as Ft, B as Oe } from "./colorToUniform-C2jGzNe1.js";
|
|
3
|
-
class Ie {
|
|
4
|
-
/**
|
|
5
|
-
* Initialize the plugin with scope of application instance
|
|
6
|
-
* @private
|
|
7
|
-
* @param {object} [options] - See application options
|
|
8
|
-
*/
|
|
9
|
-
static init(e) {
|
|
10
|
-
Object.defineProperty(
|
|
11
|
-
this,
|
|
12
|
-
"resizeTo",
|
|
13
|
-
{
|
|
14
|
-
configurable: !0,
|
|
15
|
-
set(t) {
|
|
16
|
-
globalThis.removeEventListener("resize", this.queueResize), this._resizeTo = t, t && (globalThis.addEventListener("resize", this.queueResize), this.resize());
|
|
17
|
-
},
|
|
18
|
-
get() {
|
|
19
|
-
return this._resizeTo;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
), this.queueResize = () => {
|
|
23
|
-
this._resizeTo && (this._cancelResize(), this._resizeId = requestAnimationFrame(() => this.resize()));
|
|
24
|
-
}, this._cancelResize = () => {
|
|
25
|
-
this._resizeId && (cancelAnimationFrame(this._resizeId), this._resizeId = null);
|
|
26
|
-
}, this.resize = () => {
|
|
27
|
-
if (!this._resizeTo)
|
|
28
|
-
return;
|
|
29
|
-
this._cancelResize();
|
|
30
|
-
let t, r;
|
|
31
|
-
if (this._resizeTo === globalThis.window)
|
|
32
|
-
t = globalThis.innerWidth, r = globalThis.innerHeight;
|
|
33
|
-
else {
|
|
34
|
-
const { clientWidth: n, clientHeight: s } = this._resizeTo;
|
|
35
|
-
t = n, r = s;
|
|
36
|
-
}
|
|
37
|
-
this.renderer.resize(t, r), this.render();
|
|
38
|
-
}, this._resizeId = null, this._resizeTo = null, this.resizeTo = e.resizeTo || null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Clean up the ticker, scoped to application
|
|
42
|
-
* @private
|
|
43
|
-
*/
|
|
44
|
-
static destroy() {
|
|
45
|
-
globalThis.removeEventListener("resize", this.queueResize), this._cancelResize(), this._cancelResize = null, this.queueResize = null, this.resizeTo = null, this.resize = null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
Ie.extension = p.Application;
|
|
49
|
-
class Ee {
|
|
50
|
-
/**
|
|
51
|
-
* Initialize the plugin with scope of application instance
|
|
52
|
-
* @private
|
|
53
|
-
* @param {object} [options] - See application options
|
|
54
|
-
*/
|
|
55
|
-
static init(e) {
|
|
56
|
-
e = Object.assign({
|
|
57
|
-
autoStart: !0,
|
|
58
|
-
sharedTicker: !1
|
|
59
|
-
}, e), Object.defineProperty(
|
|
60
|
-
this,
|
|
61
|
-
"ticker",
|
|
62
|
-
{
|
|
63
|
-
configurable: !0,
|
|
64
|
-
set(t) {
|
|
65
|
-
this._ticker && this._ticker.remove(this.render, this), this._ticker = t, t && t.add(this.render, this, dt.LOW);
|
|
66
|
-
},
|
|
67
|
-
get() {
|
|
68
|
-
return this._ticker;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
), this.stop = () => {
|
|
72
|
-
this._ticker.stop();
|
|
73
|
-
}, this.start = () => {
|
|
74
|
-
this._ticker.start();
|
|
75
|
-
}, this._ticker = null, this.ticker = e.sharedTicker ? ce.shared : new ce(), e.autoStart && this.start();
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Clean up the ticker, scoped to application.
|
|
79
|
-
* @private
|
|
80
|
-
*/
|
|
81
|
-
static destroy() {
|
|
82
|
-
if (this._ticker) {
|
|
83
|
-
const e = this._ticker;
|
|
84
|
-
this.ticker = null, e.destroy();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
Ee.extension = p.Application;
|
|
89
|
-
var Rt = `in vec2 vTextureCoord;
|
|
90
|
-
out vec4 finalColor;
|
|
91
|
-
uniform sampler2D uTexture;
|
|
92
|
-
void main() {
|
|
93
|
-
finalColor = texture(uTexture, vTextureCoord);
|
|
94
|
-
}
|
|
95
|
-
`, pe = `struct GlobalFilterUniforms {
|
|
96
|
-
uInputSize: vec4<f32>,
|
|
97
|
-
uInputPixel: vec4<f32>,
|
|
98
|
-
uInputClamp: vec4<f32>,
|
|
99
|
-
uOutputFrame: vec4<f32>,
|
|
100
|
-
uGlobalFrame: vec4<f32>,
|
|
101
|
-
uOutputTexture: vec4<f32>,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
@group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;
|
|
105
|
-
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
106
|
-
@group(0) @binding(2) var uSampler: sampler;
|
|
107
|
-
|
|
108
|
-
struct VSOutput {
|
|
109
|
-
@builtin(position) position: vec4<f32>,
|
|
110
|
-
@location(0) uv: vec2<f32>
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
fn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>
|
|
114
|
-
{
|
|
115
|
-
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
116
|
-
|
|
117
|
-
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
118
|
-
position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
119
|
-
|
|
120
|
-
return vec4(position, 0.0, 1.0);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
fn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>
|
|
124
|
-
{
|
|
125
|
-
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@vertex
|
|
129
|
-
fn mainVertex(
|
|
130
|
-
@location(0) aPosition: vec2<f32>,
|
|
131
|
-
) -> VSOutput {
|
|
132
|
-
return VSOutput(
|
|
133
|
-
filterVertexPosition(aPosition),
|
|
134
|
-
filterTextureCoord(aPosition)
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
@fragment
|
|
139
|
-
fn mainFragment(
|
|
140
|
-
@location(0) uv: vec2<f32>,
|
|
141
|
-
) -> @location(0) vec4<f32> {
|
|
142
|
-
return textureSample(uTexture, uSampler, uv);
|
|
143
|
-
}
|
|
144
|
-
`;
|
|
145
|
-
class Ut extends ht {
|
|
146
|
-
constructor() {
|
|
147
|
-
const e = Fe.from({
|
|
148
|
-
vertex: { source: pe, entryPoint: "mainVertex" },
|
|
149
|
-
fragment: { source: pe, entryPoint: "mainFragment" },
|
|
150
|
-
name: "passthrough-filter"
|
|
151
|
-
}), t = Re.from({
|
|
152
|
-
vertex: ft,
|
|
153
|
-
fragment: Rt,
|
|
154
|
-
name: "passthrough-filter"
|
|
155
|
-
});
|
|
156
|
-
super({
|
|
157
|
-
gpuProgram: e,
|
|
158
|
-
glProgram: t
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
class Ve {
|
|
163
|
-
constructor(e) {
|
|
164
|
-
this._renderer = e;
|
|
165
|
-
}
|
|
166
|
-
push(e, t, r) {
|
|
167
|
-
this._renderer.renderPipes.batch.break(r), r.add({
|
|
168
|
-
renderPipeId: "filter",
|
|
169
|
-
canBundle: !1,
|
|
170
|
-
action: "pushFilter",
|
|
171
|
-
container: t,
|
|
172
|
-
filterEffect: e
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
pop(e, t, r) {
|
|
176
|
-
this._renderer.renderPipes.batch.break(r), r.add({
|
|
177
|
-
renderPipeId: "filter",
|
|
178
|
-
action: "popFilter",
|
|
179
|
-
canBundle: !1
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
execute(e) {
|
|
183
|
-
e.action === "pushFilter" ? this._renderer.filter.push(e) : e.action === "popFilter" && this._renderer.filter.pop();
|
|
184
|
-
}
|
|
185
|
-
destroy() {
|
|
186
|
-
this._renderer = null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
Ve.extension = {
|
|
190
|
-
type: [
|
|
191
|
-
p.WebGLPipes,
|
|
192
|
-
p.WebGPUPipes,
|
|
193
|
-
p.CanvasPipes
|
|
194
|
-
],
|
|
195
|
-
name: "filter"
|
|
196
|
-
};
|
|
197
|
-
const me = new P();
|
|
198
|
-
function Bt(o, e) {
|
|
199
|
-
e.clear();
|
|
200
|
-
const t = e.matrix;
|
|
201
|
-
for (let r = 0; r < o.length; r++) {
|
|
202
|
-
const n = o[r];
|
|
203
|
-
if (n.globalDisplayStatus < 7)
|
|
204
|
-
continue;
|
|
205
|
-
const s = n.renderGroup ?? n.parentRenderGroup;
|
|
206
|
-
s?.isCachedAsTexture ? e.matrix = me.copyFrom(s.textureOffsetInverseTransform).append(n.worldTransform) : s?._parentCacheAsTextureRenderGroup ? e.matrix = me.copyFrom(s._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(n.groupTransform) : e.matrix = n.worldTransform, e.addBounds(n.bounds);
|
|
207
|
-
}
|
|
208
|
-
return e.matrix = t, e;
|
|
209
|
-
}
|
|
210
|
-
const Mt = new te({
|
|
211
|
-
attributes: {
|
|
212
|
-
aPosition: {
|
|
213
|
-
buffer: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
214
|
-
format: "float32x2",
|
|
215
|
-
stride: 8,
|
|
216
|
-
offset: 0
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
indexBuffer: new Uint32Array([0, 1, 2, 0, 2, 3])
|
|
220
|
-
});
|
|
221
|
-
class Gt {
|
|
222
|
-
constructor() {
|
|
223
|
-
this.skip = !1, this.inputTexture = null, this.backTexture = null, this.filters = null, this.bounds = new Be(), this.container = null, this.blendRequired = !1, this.outputRenderSurface = null, this.globalFrame = { x: 0, y: 0, width: 0, height: 0 }, this.firstEnabledIndex = -1, this.lastEnabledIndex = -1;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
class We {
|
|
227
|
-
constructor(e) {
|
|
228
|
-
this._filterStackIndex = 0, this._filterStack = [], this._filterGlobalUniforms = new M({
|
|
229
|
-
uInputSize: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
230
|
-
uInputPixel: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
231
|
-
uInputClamp: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
232
|
-
uOutputFrame: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
233
|
-
uGlobalFrame: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
234
|
-
uOutputTexture: { value: new Float32Array(4), type: "vec4<f32>" }
|
|
235
|
-
}), this._globalFilterBindGroup = new Ue({}), this.renderer = e;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* The back texture of the currently active filter. Requires the filter to have `blendRequired` set to true.
|
|
239
|
-
* @readonly
|
|
240
|
-
*/
|
|
241
|
-
get activeBackTexture() {
|
|
242
|
-
return this._activeFilterData?.backTexture;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Pushes a filter instruction onto the filter stack.
|
|
246
|
-
* @param instruction - The instruction containing the filter effect and container.
|
|
247
|
-
* @internal
|
|
248
|
-
*/
|
|
249
|
-
push(e) {
|
|
250
|
-
const t = this.renderer, r = e.filterEffect.filters, n = this._pushFilterData();
|
|
251
|
-
n.skip = !1, n.filters = r, n.container = e.container, n.outputRenderSurface = t.renderTarget.renderSurface;
|
|
252
|
-
const s = t.renderTarget.renderTarget.colorTexture.source, i = s.resolution, a = s.antialias;
|
|
253
|
-
if (r.every((f) => !f.enabled)) {
|
|
254
|
-
n.skip = !0;
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
const l = n.bounds;
|
|
258
|
-
if (this._calculateFilterArea(e, l), this._calculateFilterBounds(n, t.renderTarget.rootViewPort, a, i, 1), n.skip)
|
|
259
|
-
return;
|
|
260
|
-
const u = this._getPreviousFilterData(), h = this._findFilterResolution(i);
|
|
261
|
-
let c = 0, d = 0;
|
|
262
|
-
u && (c = u.bounds.minX, d = u.bounds.minY), this._calculateGlobalFrame(
|
|
263
|
-
n,
|
|
264
|
-
c,
|
|
265
|
-
d,
|
|
266
|
-
h,
|
|
267
|
-
s.width,
|
|
268
|
-
s.height
|
|
269
|
-
), this._setupFilterTextures(n, l, t, u);
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Applies filters to a texture.
|
|
273
|
-
*
|
|
274
|
-
* This method takes a texture and a list of filters, applies the filters to the texture,
|
|
275
|
-
* and returns the resulting texture.
|
|
276
|
-
* @param {object} params - The parameters for applying filters.
|
|
277
|
-
* @param {Texture} params.texture - The texture to apply filters to.
|
|
278
|
-
* @param {Filter[]} params.filters - The filters to apply.
|
|
279
|
-
* @returns {Texture} The resulting texture after all filters have been applied.
|
|
280
|
-
* @example
|
|
281
|
-
*
|
|
282
|
-
* ```ts
|
|
283
|
-
* // Create a texture and a list of filters
|
|
284
|
-
* const texture = new Texture(...);
|
|
285
|
-
* const filters = [new BlurFilter(), new ColorMatrixFilter()];
|
|
286
|
-
*
|
|
287
|
-
* // Apply the filters to the texture
|
|
288
|
-
* const resultTexture = filterSystem.applyToTexture({ texture, filters });
|
|
289
|
-
*
|
|
290
|
-
* // Use the resulting texture
|
|
291
|
-
* sprite.texture = resultTexture;
|
|
292
|
-
* ```
|
|
293
|
-
*
|
|
294
|
-
* Key Points:
|
|
295
|
-
* 1. padding is not currently supported here - so clipping may occur with filters that use padding.
|
|
296
|
-
* 2. If all filters are disabled or skipped, the original texture is returned.
|
|
297
|
-
*/
|
|
298
|
-
generateFilteredTexture({ texture: e, filters: t }) {
|
|
299
|
-
const r = this._pushFilterData();
|
|
300
|
-
this._activeFilterData = r, r.skip = !1, r.filters = t;
|
|
301
|
-
const n = e.source, s = n.resolution, i = n.antialias;
|
|
302
|
-
if (t.every((f) => !f.enabled))
|
|
303
|
-
return r.skip = !0, e;
|
|
304
|
-
const a = r.bounds;
|
|
305
|
-
if (a.addRect(e.frame), this._calculateFilterBounds(r, a.rectangle, i, s, 0), r.skip)
|
|
306
|
-
return e;
|
|
307
|
-
const l = s;
|
|
308
|
-
this._calculateGlobalFrame(
|
|
309
|
-
r,
|
|
310
|
-
0,
|
|
311
|
-
0,
|
|
312
|
-
l,
|
|
313
|
-
n.width,
|
|
314
|
-
n.height
|
|
315
|
-
), r.outputRenderSurface = w.getOptimalTexture(
|
|
316
|
-
a.width,
|
|
317
|
-
a.height,
|
|
318
|
-
r.resolution,
|
|
319
|
-
r.antialias
|
|
320
|
-
), r.backTexture = R.EMPTY, r.inputTexture = e, this.renderer.renderTarget.finishRenderPass(), this._applyFiltersToTexture(r, !0);
|
|
321
|
-
const d = r.outputRenderSurface;
|
|
322
|
-
return d.source.alphaMode = "premultiplied-alpha", d;
|
|
323
|
-
}
|
|
324
|
-
/** @internal */
|
|
325
|
-
pop() {
|
|
326
|
-
const e = this.renderer, t = this._popFilterData();
|
|
327
|
-
t.skip || (e.globalUniforms.pop(), e.renderTarget.finishRenderPass(), this._activeFilterData = t, this._applyFiltersToTexture(t, !1), t.blendRequired && w.returnTexture(t.backTexture), w.returnTexture(t.inputTexture));
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Copies the last render surface to a texture.
|
|
331
|
-
* @param lastRenderSurface - The last render surface to copy from.
|
|
332
|
-
* @param bounds - The bounds of the area to copy.
|
|
333
|
-
* @param previousBounds - The previous bounds to use for offsetting the copy.
|
|
334
|
-
*/
|
|
335
|
-
getBackTexture(e, t, r) {
|
|
336
|
-
const n = e.colorTexture.source._resolution, s = w.getOptimalTexture(
|
|
337
|
-
t.width,
|
|
338
|
-
t.height,
|
|
339
|
-
n,
|
|
340
|
-
!1
|
|
341
|
-
);
|
|
342
|
-
let i = t.minX, a = t.minY;
|
|
343
|
-
r && (i -= r.minX, a -= r.minY), i = Math.floor(i * n), a = Math.floor(a * n);
|
|
344
|
-
const l = Math.ceil(t.width * n), u = Math.ceil(t.height * n);
|
|
345
|
-
return this.renderer.renderTarget.copyToTexture(
|
|
346
|
-
e,
|
|
347
|
-
s,
|
|
348
|
-
{ x: i, y: a },
|
|
349
|
-
{ width: l, height: u },
|
|
350
|
-
{ x: 0, y: 0 }
|
|
351
|
-
), s;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Applies a filter to a texture.
|
|
355
|
-
* @param filter - The filter to apply.
|
|
356
|
-
* @param input - The input texture.
|
|
357
|
-
* @param output - The output render surface.
|
|
358
|
-
* @param clear - Whether to clear the output surface before applying the filter.
|
|
359
|
-
*/
|
|
360
|
-
applyFilter(e, t, r, n) {
|
|
361
|
-
const s = this.renderer, i = this._activeFilterData, l = i.outputRenderSurface === r, u = s.renderTarget.rootRenderTarget.colorTexture.source._resolution, h = this._findFilterResolution(u);
|
|
362
|
-
let c = 0, d = 0;
|
|
363
|
-
if (l) {
|
|
364
|
-
const m = this._findPreviousFilterOffset();
|
|
365
|
-
c = m.x, d = m.y;
|
|
366
|
-
}
|
|
367
|
-
this._updateFilterUniforms(t, r, i, c, d, h, l, n);
|
|
368
|
-
const f = e.enabled ? e : this._getPassthroughFilter();
|
|
369
|
-
this._setupBindGroupsAndRender(f, t, s);
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
|
|
373
|
-
*
|
|
374
|
-
* Use `outputMatrix * vTextureCoord` in the shader.
|
|
375
|
-
* @param outputMatrix - The matrix to output to.
|
|
376
|
-
* @param {Sprite} sprite - The sprite to map to.
|
|
377
|
-
* @returns The mapped matrix.
|
|
378
|
-
*/
|
|
379
|
-
calculateSpriteMatrix(e, t) {
|
|
380
|
-
const r = this._activeFilterData, n = e.set(
|
|
381
|
-
r.inputTexture._source.width,
|
|
382
|
-
0,
|
|
383
|
-
0,
|
|
384
|
-
r.inputTexture._source.height,
|
|
385
|
-
r.bounds.minX,
|
|
386
|
-
r.bounds.minY
|
|
387
|
-
), s = t.worldTransform.copyTo(P.shared), i = t.renderGroup || t.parentRenderGroup;
|
|
388
|
-
return i && i.cacheToLocalTransform && s.prepend(i.cacheToLocalTransform), s.invert(), n.prepend(s), n.scale(
|
|
389
|
-
1 / t.texture.orig.width,
|
|
390
|
-
1 / t.texture.orig.height
|
|
391
|
-
), n.translate(t.anchor.x, t.anchor.y), n;
|
|
392
|
-
}
|
|
393
|
-
destroy() {
|
|
394
|
-
this._passthroughFilter?.destroy(!0), this._passthroughFilter = null;
|
|
395
|
-
}
|
|
396
|
-
_getPassthroughFilter() {
|
|
397
|
-
return this._passthroughFilter ?? (this._passthroughFilter = new Ut()), this._passthroughFilter;
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Sets up the bind groups and renders the filter.
|
|
401
|
-
* @param filter - The filter to apply
|
|
402
|
-
* @param input - The input texture
|
|
403
|
-
* @param renderer - The renderer instance
|
|
404
|
-
*/
|
|
405
|
-
_setupBindGroupsAndRender(e, t, r) {
|
|
406
|
-
if (r.renderPipes.uniformBatch) {
|
|
407
|
-
const n = r.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);
|
|
408
|
-
this._globalFilterBindGroup.setResource(n, 0);
|
|
409
|
-
} else
|
|
410
|
-
this._globalFilterBindGroup.setResource(this._filterGlobalUniforms, 0);
|
|
411
|
-
this._globalFilterBindGroup.setResource(t.source, 1), this._globalFilterBindGroup.setResource(t.source.style, 2), e.groups[0] = this._globalFilterBindGroup, r.encoder.draw({
|
|
412
|
-
geometry: Mt,
|
|
413
|
-
shader: e,
|
|
414
|
-
state: e._state,
|
|
415
|
-
topology: "triangle-list"
|
|
416
|
-
}), r.type === re.WEBGL && r.renderTarget.finishRenderPass();
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Sets up the filter textures including input texture and back texture if needed.
|
|
420
|
-
* @param filterData - The filter data to update
|
|
421
|
-
* @param bounds - The bounds for the texture
|
|
422
|
-
* @param renderer - The renderer instance
|
|
423
|
-
* @param previousFilterData - The previous filter data for back texture calculation
|
|
424
|
-
*/
|
|
425
|
-
_setupFilterTextures(e, t, r, n) {
|
|
426
|
-
if (e.backTexture = R.EMPTY, e.inputTexture = w.getOptimalTexture(
|
|
427
|
-
t.width,
|
|
428
|
-
t.height,
|
|
429
|
-
e.resolution,
|
|
430
|
-
e.antialias
|
|
431
|
-
), e.blendRequired) {
|
|
432
|
-
r.renderTarget.finishRenderPass();
|
|
433
|
-
const s = r.renderTarget.getRenderTarget(e.outputRenderSurface);
|
|
434
|
-
e.backTexture = this.getBackTexture(s, t, n?.bounds);
|
|
435
|
-
}
|
|
436
|
-
r.renderTarget.bind(e.inputTexture, !0), r.globalUniforms.push({
|
|
437
|
-
offset: t
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Calculates and sets the global frame for the filter.
|
|
442
|
-
* @param filterData - The filter data to update
|
|
443
|
-
* @param offsetX - The X offset
|
|
444
|
-
* @param offsetY - The Y offset
|
|
445
|
-
* @param globalResolution - The global resolution
|
|
446
|
-
* @param sourceWidth - The source texture width
|
|
447
|
-
* @param sourceHeight - The source texture height
|
|
448
|
-
*/
|
|
449
|
-
_calculateGlobalFrame(e, t, r, n, s, i) {
|
|
450
|
-
const a = e.globalFrame;
|
|
451
|
-
a.x = t * n, a.y = r * n, a.width = s * n, a.height = i * n;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Updates the filter uniforms with the current filter state.
|
|
455
|
-
* @param input - The input texture
|
|
456
|
-
* @param output - The output render surface
|
|
457
|
-
* @param filterData - The current filter data
|
|
458
|
-
* @param offsetX - The X offset for positioning
|
|
459
|
-
* @param offsetY - The Y offset for positioning
|
|
460
|
-
* @param resolution - The current resolution
|
|
461
|
-
* @param isFinalTarget - Whether this is the final render target
|
|
462
|
-
* @param clear - Whether to clear the output surface
|
|
463
|
-
*/
|
|
464
|
-
_updateFilterUniforms(e, t, r, n, s, i, a, l) {
|
|
465
|
-
const u = this._filterGlobalUniforms.uniforms, h = u.uOutputFrame, c = u.uInputSize, d = u.uInputPixel, f = u.uInputClamp, m = u.uGlobalFrame, x = u.uOutputTexture;
|
|
466
|
-
a ? (h[0] = r.bounds.minX - n, h[1] = r.bounds.minY - s) : (h[0] = 0, h[1] = 0), h[2] = e.frame.width, h[3] = e.frame.height, c[0] = e.source.width, c[1] = e.source.height, c[2] = 1 / c[0], c[3] = 1 / c[1], d[0] = e.source.pixelWidth, d[1] = e.source.pixelHeight, d[2] = 1 / d[0], d[3] = 1 / d[1], f[0] = 0.5 * d[2], f[1] = 0.5 * d[3], f[2] = e.frame.width * c[2] - 0.5 * d[2], f[3] = e.frame.height * c[3] - 0.5 * d[3];
|
|
467
|
-
const g = this.renderer.renderTarget.rootRenderTarget.colorTexture;
|
|
468
|
-
m[0] = n * i, m[1] = s * i, m[2] = g.source.width * i, m[3] = g.source.height * i, t instanceof R && (t.source.resource = null);
|
|
469
|
-
const _ = this.renderer.renderTarget.getRenderTarget(t);
|
|
470
|
-
this.renderer.renderTarget.bind(t, !!l), t instanceof R ? (x[0] = t.frame.width, x[1] = t.frame.height) : (x[0] = _.width, x[1] = _.height), x[2] = _.isRoot ? -1 : 1, this._filterGlobalUniforms.update();
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Finds the correct resolution by looking back through the filter stack.
|
|
474
|
-
* @param rootResolution - The fallback root resolution to use
|
|
475
|
-
* @returns The resolution from the previous filter or root resolution
|
|
476
|
-
*/
|
|
477
|
-
_findFilterResolution(e) {
|
|
478
|
-
let t = this._filterStackIndex - 1;
|
|
479
|
-
for (; t > 0 && this._filterStack[t].skip; )
|
|
480
|
-
--t;
|
|
481
|
-
return t > 0 && this._filterStack[t].inputTexture ? this._filterStack[t].inputTexture.source._resolution : e;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Finds the offset from the previous non-skipped filter in the stack.
|
|
485
|
-
* @returns The offset coordinates from the previous filter
|
|
486
|
-
*/
|
|
487
|
-
_findPreviousFilterOffset() {
|
|
488
|
-
let e = 0, t = 0, r = this._filterStackIndex;
|
|
489
|
-
for (; r > 0; ) {
|
|
490
|
-
r--;
|
|
491
|
-
const n = this._filterStack[r];
|
|
492
|
-
if (!n.skip) {
|
|
493
|
-
e = n.bounds.minX, t = n.bounds.minY;
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
return { x: e, y: t };
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Calculates the filter area bounds based on the instruction type.
|
|
501
|
-
* @param instruction - The filter instruction
|
|
502
|
-
* @param bounds - The bounds object to populate
|
|
503
|
-
*/
|
|
504
|
-
_calculateFilterArea(e, t) {
|
|
505
|
-
if (e.renderables ? Bt(e.renderables, t) : e.filterEffect.filterArea ? (t.clear(), t.addRect(e.filterEffect.filterArea), t.applyMatrix(e.container.worldTransform)) : e.container.getFastGlobalBounds(!0, t), e.container) {
|
|
506
|
-
const n = (e.container.renderGroup || e.container.parentRenderGroup).cacheToLocalTransform;
|
|
507
|
-
n && t.applyMatrix(n);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
_applyFiltersToTexture(e, t) {
|
|
511
|
-
const r = e.inputTexture, n = e.bounds, s = e.filters, i = e.firstEnabledIndex, a = e.lastEnabledIndex;
|
|
512
|
-
if (this._globalFilterBindGroup.setResource(r.source.style, 2), this._globalFilterBindGroup.setResource(e.backTexture.source, 3), i === a)
|
|
513
|
-
s[i].apply(this, r, e.outputRenderSurface, t);
|
|
514
|
-
else {
|
|
515
|
-
let l = e.inputTexture;
|
|
516
|
-
const u = w.getOptimalTexture(
|
|
517
|
-
n.width,
|
|
518
|
-
n.height,
|
|
519
|
-
l.source._resolution,
|
|
520
|
-
!1
|
|
521
|
-
);
|
|
522
|
-
let h = u;
|
|
523
|
-
for (let c = i; c < a; c++) {
|
|
524
|
-
const d = s[c];
|
|
525
|
-
if (!d.enabled)
|
|
526
|
-
continue;
|
|
527
|
-
d.apply(this, l, h, !0);
|
|
528
|
-
const f = l;
|
|
529
|
-
l = h, h = f;
|
|
530
|
-
}
|
|
531
|
-
s[a].apply(this, l, e.outputRenderSurface, t), w.returnTexture(u);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
_calculateFilterBounds(e, t, r, n, s) {
|
|
535
|
-
const i = this.renderer, a = e.bounds, l = e.filters;
|
|
536
|
-
let u = 1 / 0, h = 0, c = !0, d = !1, f = !1, m = !0, x = -1, g = -1;
|
|
537
|
-
for (let _ = 0; _ < l.length; _++) {
|
|
538
|
-
const b = l[_];
|
|
539
|
-
if (!b.enabled)
|
|
540
|
-
continue;
|
|
541
|
-
if (x === -1 && (x = _), g = _, u = Math.min(u, b.resolution === "inherit" ? n : b.resolution), h += b.padding, b.antialias === "off" ? c = !1 : b.antialias === "inherit" && c && (c = r), b.clipToViewport || (m = !1), !!!(b.compatibleRenderers & i.type)) {
|
|
542
|
-
f = !1;
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
if (b.blendRequired && !(i.backBuffer?.useBackBuffer ?? !0)) {
|
|
546
|
-
N("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."), f = !1;
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
f = !0, d || (d = b.blendRequired);
|
|
550
|
-
}
|
|
551
|
-
if (!f) {
|
|
552
|
-
e.skip = !0;
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
if (m && a.fitBounds(0, t.width / n, 0, t.height / n), a.scale(u).ceil().scale(1 / u).pad((h | 0) * s), !a.isPositive) {
|
|
556
|
-
e.skip = !0;
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
e.antialias = c, e.resolution = u, e.blendRequired = d, e.firstEnabledIndex = x, e.lastEnabledIndex = g;
|
|
560
|
-
}
|
|
561
|
-
_popFilterData() {
|
|
562
|
-
return this._filterStackIndex--, this._filterStack[this._filterStackIndex];
|
|
563
|
-
}
|
|
564
|
-
_getPreviousFilterData() {
|
|
565
|
-
let e, t = this._filterStackIndex - 1;
|
|
566
|
-
for (; t > 0 && (t--, e = this._filterStack[t], !!e.skip); )
|
|
567
|
-
;
|
|
568
|
-
return e;
|
|
569
|
-
}
|
|
570
|
-
_pushFilterData() {
|
|
571
|
-
let e = this._filterStack[this._filterStackIndex];
|
|
572
|
-
return e || (e = this._filterStack[this._filterStackIndex] = new Gt()), this._filterStackIndex++, e;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
We.extension = {
|
|
576
|
-
type: [
|
|
577
|
-
p.WebGLSystem,
|
|
578
|
-
p.WebGPUSystem
|
|
579
|
-
],
|
|
580
|
-
name: "filter"
|
|
581
|
-
};
|
|
582
|
-
const Le = class Ye extends te {
|
|
583
|
-
constructor(...e) {
|
|
584
|
-
let t = e[0] ?? {};
|
|
585
|
-
t instanceof Float32Array && (O(Me, "use new MeshGeometry({ positions, uvs, indices }) instead"), t = {
|
|
586
|
-
positions: t,
|
|
587
|
-
uvs: e[1],
|
|
588
|
-
indices: e[2]
|
|
589
|
-
}), t = { ...Ye.defaultOptions, ...t };
|
|
590
|
-
const r = t.positions || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
|
|
591
|
-
let n = t.uvs;
|
|
592
|
-
n || (t.positions ? n = new Float32Array(r.length) : n = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]));
|
|
593
|
-
const s = t.indices || new Uint32Array([0, 1, 2, 0, 2, 3]), i = t.shrinkBuffersToFit, a = new D({
|
|
594
|
-
data: r,
|
|
595
|
-
label: "attribute-mesh-positions",
|
|
596
|
-
shrinkToFit: i,
|
|
597
|
-
usage: C.VERTEX | C.COPY_DST
|
|
598
|
-
}), l = new D({
|
|
599
|
-
data: n,
|
|
600
|
-
label: "attribute-mesh-uvs",
|
|
601
|
-
shrinkToFit: i,
|
|
602
|
-
usage: C.VERTEX | C.COPY_DST
|
|
603
|
-
}), u = new D({
|
|
604
|
-
data: s,
|
|
605
|
-
label: "index-mesh-buffer",
|
|
606
|
-
shrinkToFit: i,
|
|
607
|
-
usage: C.INDEX | C.COPY_DST
|
|
608
|
-
});
|
|
609
|
-
super({
|
|
610
|
-
attributes: {
|
|
611
|
-
aPosition: {
|
|
612
|
-
buffer: a,
|
|
613
|
-
format: "float32x2",
|
|
614
|
-
stride: 8,
|
|
615
|
-
offset: 0
|
|
616
|
-
},
|
|
617
|
-
aUV: {
|
|
618
|
-
buffer: l,
|
|
619
|
-
format: "float32x2",
|
|
620
|
-
stride: 8,
|
|
621
|
-
offset: 0
|
|
622
|
-
}
|
|
623
|
-
},
|
|
624
|
-
indexBuffer: u,
|
|
625
|
-
topology: t.topology
|
|
626
|
-
}), this.batchMode = "auto";
|
|
627
|
-
}
|
|
628
|
-
/** The positions of the mesh. */
|
|
629
|
-
get positions() {
|
|
630
|
-
return this.attributes.aPosition.buffer.data;
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Set the positions of the mesh.
|
|
634
|
-
* When setting the positions, its important that the uvs array is at least as long as the positions array.
|
|
635
|
-
* otherwise the geometry will not be valid.
|
|
636
|
-
* @param {Float32Array} value - The positions of the mesh.
|
|
637
|
-
*/
|
|
638
|
-
set positions(e) {
|
|
639
|
-
this.attributes.aPosition.buffer.data = e;
|
|
640
|
-
}
|
|
641
|
-
/** The UVs of the mesh. */
|
|
642
|
-
get uvs() {
|
|
643
|
-
return this.attributes.aUV.buffer.data;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Set the UVs of the mesh.
|
|
647
|
-
* Its important that the uvs array you set is at least as long as the positions array.
|
|
648
|
-
* otherwise the geometry will not be valid.
|
|
649
|
-
* @param {Float32Array} value - The UVs of the mesh.
|
|
650
|
-
*/
|
|
651
|
-
set uvs(e) {
|
|
652
|
-
this.attributes.aUV.buffer.data = e;
|
|
653
|
-
}
|
|
654
|
-
/** The indices of the mesh. */
|
|
655
|
-
get indices() {
|
|
656
|
-
return this.indexBuffer.data;
|
|
657
|
-
}
|
|
658
|
-
set indices(e) {
|
|
659
|
-
this.indexBuffer.data = e;
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
Le.defaultOptions = {
|
|
663
|
-
topology: "triangle-list",
|
|
664
|
-
shrinkBuffersToFit: !1
|
|
665
|
-
};
|
|
666
|
-
let ie = Le, U = null, S = null;
|
|
667
|
-
function Dt(o, e) {
|
|
668
|
-
U || (U = W.get().createCanvas(256, 128), S = U.getContext("2d", { willReadFrequently: !0 }), S.globalCompositeOperation = "copy", S.globalAlpha = 1), (U.width < o || U.height < e) && (U.width = de(o), U.height = de(e));
|
|
669
|
-
}
|
|
670
|
-
function ge(o, e, t) {
|
|
671
|
-
for (let r = 0, n = 4 * t * e; r < e; ++r, n += 4)
|
|
672
|
-
if (o[n + 3] !== 0)
|
|
673
|
-
return !1;
|
|
674
|
-
return !0;
|
|
675
|
-
}
|
|
676
|
-
function xe(o, e, t, r, n) {
|
|
677
|
-
const s = 4 * e;
|
|
678
|
-
for (let i = r, a = r * s + 4 * t; i <= n; ++i, a += s)
|
|
679
|
-
if (o[a + 3] !== 0)
|
|
680
|
-
return !1;
|
|
681
|
-
return !0;
|
|
682
|
-
}
|
|
683
|
-
function At(...o) {
|
|
684
|
-
let e = o[0];
|
|
685
|
-
e.canvas || (e = { canvas: o[0], resolution: o[1] });
|
|
686
|
-
const { canvas: t } = e, r = Math.min(e.resolution ?? 1, 1), n = e.width ?? t.width, s = e.height ?? t.height;
|
|
687
|
-
let i = e.output;
|
|
688
|
-
if (Dt(n, s), !S)
|
|
689
|
-
throw new TypeError("Failed to get canvas 2D context");
|
|
690
|
-
S.drawImage(
|
|
691
|
-
t,
|
|
692
|
-
0,
|
|
693
|
-
0,
|
|
694
|
-
n,
|
|
695
|
-
s,
|
|
696
|
-
0,
|
|
697
|
-
0,
|
|
698
|
-
n * r,
|
|
699
|
-
s * r
|
|
700
|
-
);
|
|
701
|
-
const l = S.getImageData(0, 0, n, s).data;
|
|
702
|
-
let u = 0, h = 0, c = n - 1, d = s - 1;
|
|
703
|
-
for (; h < s && ge(l, n, h); )
|
|
704
|
-
++h;
|
|
705
|
-
if (h === s)
|
|
706
|
-
return q.EMPTY;
|
|
707
|
-
for (; ge(l, n, d); )
|
|
708
|
-
--d;
|
|
709
|
-
for (; xe(l, n, u, h, d); )
|
|
710
|
-
++u;
|
|
711
|
-
for (; xe(l, n, c, h, d); )
|
|
712
|
-
--c;
|
|
713
|
-
return ++c, ++d, S.globalCompositeOperation = "source-over", S.strokeRect(u, h, c - u, d - h), S.globalCompositeOperation = "copy", i ?? (i = new q()), i.set(u / r, h / r, (c - u) / r, (d - h) / r), i;
|
|
714
|
-
}
|
|
715
|
-
const _e = new q();
|
|
716
|
-
class kt {
|
|
717
|
-
/**
|
|
718
|
-
* Creates a canvas with the specified text rendered to it.
|
|
719
|
-
*
|
|
720
|
-
* Generates a canvas of appropriate size, renders the text with the provided style,
|
|
721
|
-
* and returns both the canvas/context and a Rectangle representing the text bounds.
|
|
722
|
-
*
|
|
723
|
-
* When trim is enabled in the style, the frame will represent the bounds of the
|
|
724
|
-
* non-transparent pixels, which can be smaller than the full canvas.
|
|
725
|
-
* @param options - The options for generating the text canvas
|
|
726
|
-
* @param options.text - The text to render
|
|
727
|
-
* @param options.style - The style to apply to the text
|
|
728
|
-
* @param options.resolution - The resolution of the canvas (defaults to 1)
|
|
729
|
-
* @param options.padding
|
|
730
|
-
* @returns An object containing the canvas/context and the frame (bounds) of the text
|
|
731
|
-
*/
|
|
732
|
-
getCanvasAndContext(e) {
|
|
733
|
-
const { text: t, style: r, resolution: n = 1 } = e, s = r._getFinalPadding(), i = B.measureText(t || " ", r), a = Math.ceil(Math.ceil(Math.max(1, i.width) + s * 2) * n), l = Math.ceil(Math.ceil(Math.max(1, i.height) + s * 2) * n), u = I.getOptimalCanvasAndContext(a, l);
|
|
734
|
-
this._renderTextToCanvas(t, r, s, n, u);
|
|
735
|
-
const h = r.trim ? At({ canvas: u.canvas, width: a, height: l, resolution: 1, output: _e }) : _e.set(0, 0, a, l);
|
|
736
|
-
return {
|
|
737
|
-
canvasAndContext: u,
|
|
738
|
-
frame: h
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Returns a canvas and context to the pool.
|
|
743
|
-
*
|
|
744
|
-
* This should be called when you're done with the canvas to allow reuse
|
|
745
|
-
* and prevent memory leaks.
|
|
746
|
-
* @param canvasAndContext - The canvas and context to return to the pool
|
|
747
|
-
*/
|
|
748
|
-
returnCanvasAndContext(e) {
|
|
749
|
-
I.returnCanvasAndContext(e);
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Renders text to its canvas, and updates its texture.
|
|
753
|
-
* @param text - The text to render
|
|
754
|
-
* @param style - The style of the text
|
|
755
|
-
* @param padding - The padding of the text
|
|
756
|
-
* @param resolution - The resolution of the text
|
|
757
|
-
* @param canvasAndContext - The canvas and context to render the text to
|
|
758
|
-
*/
|
|
759
|
-
_renderTextToCanvas(e, t, r, n, s) {
|
|
760
|
-
const { canvas: i, context: a } = s, l = pt(t), u = B.measureText(e || " ", t), h = u.lines, c = u.lineHeight, d = u.lineWidths, f = u.maxLineWidth, m = u.fontProperties, x = i.height;
|
|
761
|
-
if (a.resetTransform(), a.scale(n, n), a.textBaseline = t.textBaseline, t._stroke?.width) {
|
|
762
|
-
const T = t._stroke;
|
|
763
|
-
a.lineWidth = T.width, a.miterLimit = T.miterLimit, a.lineJoin = T.join, a.lineCap = T.cap;
|
|
764
|
-
}
|
|
765
|
-
a.font = l;
|
|
766
|
-
let g, _;
|
|
767
|
-
const b = t.dropShadow ? 2 : 1;
|
|
768
|
-
for (let T = 0; T < b; ++T) {
|
|
769
|
-
const A = t.dropShadow && T === 0, F = A ? Math.ceil(Math.max(1, x) + r * 2) : 0, G = F * n;
|
|
770
|
-
if (A) {
|
|
771
|
-
a.fillStyle = "black", a.strokeStyle = "black";
|
|
772
|
-
const v = t.dropShadow, ut = v.color, lt = v.alpha;
|
|
773
|
-
a.shadowColor = Ge.shared.setValue(ut).setAlpha(lt).toRgbaString();
|
|
774
|
-
const ct = v.blur * n, le = v.distance * n;
|
|
775
|
-
a.shadowBlur = ct, a.shadowOffsetX = Math.cos(v.angle) * le, a.shadowOffsetY = Math.sin(v.angle) * le + G;
|
|
776
|
-
} else {
|
|
777
|
-
if (a.fillStyle = t._fill ? he(t._fill, a, u, r * 2) : null, t._stroke?.width) {
|
|
778
|
-
const v = t._stroke.width * 0.5 + r * 2;
|
|
779
|
-
a.strokeStyle = he(t._stroke, a, u, v);
|
|
780
|
-
}
|
|
781
|
-
a.shadowColor = "black";
|
|
782
|
-
}
|
|
783
|
-
let oe = (c - m.fontSize) / 2;
|
|
784
|
-
c - m.fontSize < 0 && (oe = 0);
|
|
785
|
-
const ue = t._stroke?.width ?? 0;
|
|
786
|
-
for (let v = 0; v < h.length; v++)
|
|
787
|
-
g = ue / 2, _ = ue / 2 + v * c + m.ascent + oe, t.align === "right" ? g += f - d[v] : t.align === "center" && (g += (f - d[v]) / 2), t._stroke?.width && this._drawLetterSpacing(
|
|
788
|
-
h[v],
|
|
789
|
-
t,
|
|
790
|
-
s,
|
|
791
|
-
g + r,
|
|
792
|
-
_ + r - F,
|
|
793
|
-
!0
|
|
794
|
-
), t._fill !== void 0 && this._drawLetterSpacing(
|
|
795
|
-
h[v],
|
|
796
|
-
t,
|
|
797
|
-
s,
|
|
798
|
-
g + r,
|
|
799
|
-
_ + r - F
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Render the text with letter-spacing.
|
|
805
|
-
*
|
|
806
|
-
* This method handles rendering text with the correct letter spacing, using either:
|
|
807
|
-
* 1. Native letter spacing if supported by the browser
|
|
808
|
-
* 2. Manual letter spacing calculation if not natively supported
|
|
809
|
-
*
|
|
810
|
-
* For manual letter spacing, it calculates the position of each character
|
|
811
|
-
* based on its width and the desired spacing.
|
|
812
|
-
* @param text - The text to draw
|
|
813
|
-
* @param style - The text style to apply
|
|
814
|
-
* @param canvasAndContext - The canvas and context to draw to
|
|
815
|
-
* @param x - Horizontal position to draw the text
|
|
816
|
-
* @param y - Vertical position to draw the text
|
|
817
|
-
* @param isStroke - Whether to render the stroke (true) or fill (false)
|
|
818
|
-
* @private
|
|
819
|
-
*/
|
|
820
|
-
_drawLetterSpacing(e, t, r, n, s, i = !1) {
|
|
821
|
-
const { context: a } = r, l = t.letterSpacing;
|
|
822
|
-
let u = !1;
|
|
823
|
-
if (B.experimentalLetterSpacingSupported && (B.experimentalLetterSpacing ? (a.letterSpacing = `${l}px`, a.textLetterSpacing = `${l}px`, u = !0) : (a.letterSpacing = "0px", a.textLetterSpacing = "0px")), l === 0 || u) {
|
|
824
|
-
i ? a.strokeText(e, n, s) : a.fillText(e, n, s);
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
let h = n;
|
|
828
|
-
const c = B.graphemeSegmenter(e);
|
|
829
|
-
let d = a.measureText(e).width, f = 0;
|
|
830
|
-
for (let m = 0; m < c.length; ++m) {
|
|
831
|
-
const x = c[m];
|
|
832
|
-
i ? a.strokeText(x, h, s) : a.fillText(x, h, s);
|
|
833
|
-
let g = "";
|
|
834
|
-
for (let _ = m + 1; _ < c.length; ++_)
|
|
835
|
-
g += c[_];
|
|
836
|
-
f = a.measureText(g).width, h += d - f + l, d = f;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
const Y = new kt(), be = "http://www.w3.org/2000/svg", ve = "http://www.w3.org/1999/xhtml";
|
|
841
|
-
class Xe {
|
|
842
|
-
constructor() {
|
|
843
|
-
this.svgRoot = document.createElementNS(be, "svg"), this.foreignObject = document.createElementNS(be, "foreignObject"), this.domElement = document.createElementNS(ve, "div"), this.styleElement = document.createElementNS(ve, "style");
|
|
844
|
-
const { foreignObject: e, svgRoot: t, styleElement: r, domElement: n } = this;
|
|
845
|
-
e.setAttribute("width", "10000"), e.setAttribute("height", "10000"), e.style.overflow = "hidden", t.appendChild(e), e.appendChild(r), e.appendChild(n), this.image = W.get().createImage();
|
|
846
|
-
}
|
|
847
|
-
destroy() {
|
|
848
|
-
this.svgRoot.remove(), this.foreignObject.remove(), this.styleElement.remove(), this.domElement.remove(), this.image.src = "", this.image.remove(), this.svgRoot = null, this.foreignObject = null, this.styleElement = null, this.domElement = null, this.image = null, this.canvasAndContext = null;
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
let ye;
|
|
852
|
-
function zt(o, e, t, r) {
|
|
853
|
-
r || (r = ye || (ye = new Xe()));
|
|
854
|
-
const { domElement: n, styleElement: s, svgRoot: i } = r;
|
|
855
|
-
n.innerHTML = `<style>${e.cssStyle};</style><div style='padding:0'>${o}</div>`, n.setAttribute("style", "transform-origin: top left; display: inline-block"), t && (s.textContent = t), document.body.appendChild(i);
|
|
856
|
-
const a = n.getBoundingClientRect();
|
|
857
|
-
i.remove();
|
|
858
|
-
const l = e.padding * 2;
|
|
859
|
-
return {
|
|
860
|
-
width: a.width - l,
|
|
861
|
-
height: a.height - l
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
class Ot {
|
|
865
|
-
constructor() {
|
|
866
|
-
this.batches = [], this.batched = !1;
|
|
867
|
-
}
|
|
868
|
-
destroy() {
|
|
869
|
-
this.batches.forEach((e) => {
|
|
870
|
-
V.return(e);
|
|
871
|
-
}), this.batches.length = 0;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
class He {
|
|
875
|
-
constructor(e, t) {
|
|
876
|
-
this.state = E.for2d(), this.renderer = e, this._adaptor = t, this.renderer.runners.contextChange.add(this);
|
|
877
|
-
}
|
|
878
|
-
contextChange() {
|
|
879
|
-
this._adaptor.contextChange(this.renderer);
|
|
880
|
-
}
|
|
881
|
-
validateRenderable(e) {
|
|
882
|
-
const t = e.context, r = !!e._gpuData, n = this.renderer.graphicsContext.updateGpuContext(t);
|
|
883
|
-
return !!(n.isBatchable || r !== n.isBatchable);
|
|
884
|
-
}
|
|
885
|
-
addRenderable(e, t) {
|
|
886
|
-
const r = this.renderer.graphicsContext.updateGpuContext(e.context);
|
|
887
|
-
e.didViewUpdate && this._rebuild(e), r.isBatchable ? this._addToBatcher(e, t) : (this.renderer.renderPipes.batch.break(t), t.add(e));
|
|
888
|
-
}
|
|
889
|
-
updateRenderable(e) {
|
|
890
|
-
const r = this._getGpuDataForRenderable(e).batches;
|
|
891
|
-
for (let n = 0; n < r.length; n++) {
|
|
892
|
-
const s = r[n];
|
|
893
|
-
s._batcher.updateElement(s);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
execute(e) {
|
|
897
|
-
if (!e.isRenderable)
|
|
898
|
-
return;
|
|
899
|
-
const t = this.renderer, r = e.context;
|
|
900
|
-
if (!t.graphicsContext.getGpuContext(r).batches.length)
|
|
901
|
-
return;
|
|
902
|
-
const s = r.customShader || this._adaptor.shader;
|
|
903
|
-
this.state.blendMode = e.groupBlendMode;
|
|
904
|
-
const i = s.resources.localUniforms.uniforms;
|
|
905
|
-
i.uTransformMatrix = e.groupTransform, i.uRound = t._roundPixels | e._roundPixels, L(
|
|
906
|
-
e.groupColorAlpha,
|
|
907
|
-
i.uColor,
|
|
908
|
-
0
|
|
909
|
-
), this._adaptor.execute(this, e);
|
|
910
|
-
}
|
|
911
|
-
_rebuild(e) {
|
|
912
|
-
const t = this._getGpuDataForRenderable(e), r = this.renderer.graphicsContext.updateGpuContext(e.context);
|
|
913
|
-
t.destroy(), r.isBatchable && this._updateBatchesForRenderable(e, t);
|
|
914
|
-
}
|
|
915
|
-
_addToBatcher(e, t) {
|
|
916
|
-
const r = this.renderer.renderPipes.batch, n = this._getGpuDataForRenderable(e).batches;
|
|
917
|
-
for (let s = 0; s < n.length; s++) {
|
|
918
|
-
const i = n[s];
|
|
919
|
-
r.addToBatch(i, t);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
_getGpuDataForRenderable(e) {
|
|
923
|
-
return e._gpuData[this.renderer.uid] || this._initGpuDataForRenderable(e);
|
|
924
|
-
}
|
|
925
|
-
_initGpuDataForRenderable(e) {
|
|
926
|
-
const t = new Ot();
|
|
927
|
-
return e._gpuData[this.renderer.uid] = t, t;
|
|
928
|
-
}
|
|
929
|
-
_updateBatchesForRenderable(e, t) {
|
|
930
|
-
const r = e.context, n = this.renderer.graphicsContext.getGpuContext(r), s = this.renderer._roundPixels | e._roundPixels;
|
|
931
|
-
t.batches = n.batches.map((i) => {
|
|
932
|
-
const a = V.get(mt);
|
|
933
|
-
return i.copyTo(a), a.renderable = e, a.roundPixels = s, a;
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
destroy() {
|
|
937
|
-
this.renderer = null, this._adaptor.destroy(), this._adaptor = null, this.state = null;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
He.extension = {
|
|
941
|
-
type: [
|
|
942
|
-
p.WebGLPipes,
|
|
943
|
-
p.WebGPUPipes,
|
|
944
|
-
p.CanvasPipes
|
|
945
|
-
],
|
|
946
|
-
name: "graphics"
|
|
947
|
-
};
|
|
948
|
-
const Ke = class $e extends ie {
|
|
949
|
-
constructor(...e) {
|
|
950
|
-
super({});
|
|
951
|
-
let t = e[0] ?? {};
|
|
952
|
-
typeof t == "number" && (O(Me, "PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead"), t = {
|
|
953
|
-
width: t,
|
|
954
|
-
height: e[1],
|
|
955
|
-
verticesX: e[2],
|
|
956
|
-
verticesY: e[3]
|
|
957
|
-
}), this.build(t);
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Refreshes plane coordinates
|
|
961
|
-
* @param options - Options to be applied to plane geometry
|
|
962
|
-
*/
|
|
963
|
-
build(e) {
|
|
964
|
-
e = { ...$e.defaultOptions, ...e }, this.verticesX = this.verticesX ?? e.verticesX, this.verticesY = this.verticesY ?? e.verticesY, this.width = this.width ?? e.width, this.height = this.height ?? e.height;
|
|
965
|
-
const t = this.verticesX * this.verticesY, r = [], n = [], s = [], i = this.verticesX - 1, a = this.verticesY - 1, l = this.width / i, u = this.height / a;
|
|
966
|
-
for (let c = 0; c < t; c++) {
|
|
967
|
-
const d = c % this.verticesX, f = c / this.verticesX | 0;
|
|
968
|
-
r.push(d * l, f * u), n.push(d / i, f / a);
|
|
969
|
-
}
|
|
970
|
-
const h = i * a;
|
|
971
|
-
for (let c = 0; c < h; c++) {
|
|
972
|
-
const d = c % i, f = c / i | 0, m = f * this.verticesX + d, x = f * this.verticesX + d + 1, g = (f + 1) * this.verticesX + d, _ = (f + 1) * this.verticesX + d + 1;
|
|
973
|
-
s.push(
|
|
974
|
-
m,
|
|
975
|
-
x,
|
|
976
|
-
g,
|
|
977
|
-
x,
|
|
978
|
-
_,
|
|
979
|
-
g
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
this.buffers[0].data = new Float32Array(r), this.buffers[1].data = new Float32Array(n), this.indexBuffer.data = new Uint32Array(s), this.buffers[0].update(), this.buffers[1].update(), this.indexBuffer.update();
|
|
983
|
-
}
|
|
984
|
-
};
|
|
985
|
-
Ke.defaultOptions = {
|
|
986
|
-
width: 100,
|
|
987
|
-
height: 100,
|
|
988
|
-
verticesX: 10,
|
|
989
|
-
verticesY: 10
|
|
990
|
-
};
|
|
991
|
-
let It = Ke;
|
|
992
|
-
class ae {
|
|
993
|
-
constructor() {
|
|
994
|
-
this.batcherName = "default", this.packAsQuad = !1, this.indexOffset = 0, this.attributeOffset = 0, this.roundPixels = 0, this._batcher = null, this._batch = null, this._textureMatrixUpdateId = -1, this._uvUpdateId = -1;
|
|
995
|
-
}
|
|
996
|
-
get blendMode() {
|
|
997
|
-
return this.renderable.groupBlendMode;
|
|
998
|
-
}
|
|
999
|
-
get topology() {
|
|
1000
|
-
return this._topology || this.geometry.topology;
|
|
1001
|
-
}
|
|
1002
|
-
set topology(e) {
|
|
1003
|
-
this._topology = e;
|
|
1004
|
-
}
|
|
1005
|
-
reset() {
|
|
1006
|
-
this.renderable = null, this.texture = null, this._batcher = null, this._batch = null, this.geometry = null, this._uvUpdateId = -1, this._textureMatrixUpdateId = -1;
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* Sets the texture for the batchable mesh.
|
|
1010
|
-
* As it does so, it resets the texture matrix update ID.
|
|
1011
|
-
* this is to ensure that the texture matrix is recalculated when the uvs are referenced
|
|
1012
|
-
* @param value - The texture to set.
|
|
1013
|
-
*/
|
|
1014
|
-
setTexture(e) {
|
|
1015
|
-
this.texture !== e && (this.texture = e, this._textureMatrixUpdateId = -1);
|
|
1016
|
-
}
|
|
1017
|
-
get uvs() {
|
|
1018
|
-
const t = this.geometry.getBuffer("aUV"), r = t.data;
|
|
1019
|
-
let n = r;
|
|
1020
|
-
const s = this.texture.textureMatrix;
|
|
1021
|
-
return s.isSimple || (n = this._transformedUvs, (this._textureMatrixUpdateId !== s._updateID || this._uvUpdateId !== t._updateID) && ((!n || n.length < r.length) && (n = this._transformedUvs = new Float32Array(r.length)), this._textureMatrixUpdateId = s._updateID, this._uvUpdateId = t._updateID, s.multiplyUvs(r, n))), n;
|
|
1022
|
-
}
|
|
1023
|
-
get positions() {
|
|
1024
|
-
return this.geometry.positions;
|
|
1025
|
-
}
|
|
1026
|
-
get indices() {
|
|
1027
|
-
return this.geometry.indices;
|
|
1028
|
-
}
|
|
1029
|
-
get color() {
|
|
1030
|
-
return this.renderable.groupColorAlpha;
|
|
1031
|
-
}
|
|
1032
|
-
get groupTransform() {
|
|
1033
|
-
return this.renderable.groupTransform;
|
|
1034
|
-
}
|
|
1035
|
-
get attributeSize() {
|
|
1036
|
-
return this.geometry.positions.length / 2;
|
|
1037
|
-
}
|
|
1038
|
-
get indexSize() {
|
|
1039
|
-
return this.geometry.indices.length;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
class Te {
|
|
1043
|
-
destroy() {
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
class je {
|
|
1047
|
-
constructor(e, t) {
|
|
1048
|
-
this.localUniforms = new M({
|
|
1049
|
-
uTransformMatrix: { value: new P(), type: "mat3x3<f32>" },
|
|
1050
|
-
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
1051
|
-
uRound: { value: 0, type: "f32" }
|
|
1052
|
-
}), this.localUniformsBindGroup = new Ue({
|
|
1053
|
-
0: this.localUniforms
|
|
1054
|
-
}), this.renderer = e, this._adaptor = t, this._adaptor.init();
|
|
1055
|
-
}
|
|
1056
|
-
validateRenderable(e) {
|
|
1057
|
-
const t = this._getMeshData(e), r = t.batched, n = e.batched;
|
|
1058
|
-
if (t.batched = n, r !== n)
|
|
1059
|
-
return !0;
|
|
1060
|
-
if (n) {
|
|
1061
|
-
const s = e._geometry;
|
|
1062
|
-
if (s.indices.length !== t.indexSize || s.positions.length !== t.vertexSize)
|
|
1063
|
-
return t.indexSize = s.indices.length, t.vertexSize = s.positions.length, !0;
|
|
1064
|
-
const i = this._getBatchableMesh(e);
|
|
1065
|
-
return i.texture.uid !== e._texture.uid && (i._textureMatrixUpdateId = -1), !i._batcher.checkAndUpdateTexture(
|
|
1066
|
-
i,
|
|
1067
|
-
e._texture
|
|
1068
|
-
);
|
|
1069
|
-
}
|
|
1070
|
-
return !1;
|
|
1071
|
-
}
|
|
1072
|
-
addRenderable(e, t) {
|
|
1073
|
-
const r = this.renderer.renderPipes.batch, n = this._getMeshData(e);
|
|
1074
|
-
if (e.didViewUpdate && (n.indexSize = e._geometry.indices?.length, n.vertexSize = e._geometry.positions?.length), n.batched) {
|
|
1075
|
-
const s = this._getBatchableMesh(e);
|
|
1076
|
-
s.setTexture(e._texture), s.geometry = e._geometry, r.addToBatch(s, t);
|
|
1077
|
-
} else
|
|
1078
|
-
r.break(t), t.add(e);
|
|
1079
|
-
}
|
|
1080
|
-
updateRenderable(e) {
|
|
1081
|
-
if (e.batched) {
|
|
1082
|
-
const t = this._getBatchableMesh(e);
|
|
1083
|
-
t.setTexture(e._texture), t.geometry = e._geometry, t._batcher.updateElement(t);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
execute(e) {
|
|
1087
|
-
if (!e.isRenderable)
|
|
1088
|
-
return;
|
|
1089
|
-
e.state.blendMode = ne(e.groupBlendMode, e.texture._source);
|
|
1090
|
-
const t = this.localUniforms;
|
|
1091
|
-
t.uniforms.uTransformMatrix = e.groupTransform, t.uniforms.uRound = this.renderer._roundPixels | e._roundPixels, t.update(), L(
|
|
1092
|
-
e.groupColorAlpha,
|
|
1093
|
-
t.uniforms.uColor,
|
|
1094
|
-
0
|
|
1095
|
-
), this._adaptor.execute(this, e);
|
|
1096
|
-
}
|
|
1097
|
-
_getMeshData(e) {
|
|
1098
|
-
var t, r;
|
|
1099
|
-
return (t = e._gpuData)[r = this.renderer.uid] || (t[r] = new Te()), e._gpuData[this.renderer.uid].meshData || this._initMeshData(e);
|
|
1100
|
-
}
|
|
1101
|
-
_initMeshData(e) {
|
|
1102
|
-
return e._gpuData[this.renderer.uid].meshData = {
|
|
1103
|
-
batched: e.batched,
|
|
1104
|
-
indexSize: 0,
|
|
1105
|
-
vertexSize: 0
|
|
1106
|
-
}, e._gpuData[this.renderer.uid].meshData;
|
|
1107
|
-
}
|
|
1108
|
-
_getBatchableMesh(e) {
|
|
1109
|
-
var t, r;
|
|
1110
|
-
return (t = e._gpuData)[r = this.renderer.uid] || (t[r] = new Te()), e._gpuData[this.renderer.uid].batchableMesh || this._initBatchableMesh(e);
|
|
1111
|
-
}
|
|
1112
|
-
_initBatchableMesh(e) {
|
|
1113
|
-
const t = new ae();
|
|
1114
|
-
return t.renderable = e, t.setTexture(e._texture), t.transform = e.groupTransform, t.roundPixels = this.renderer._roundPixels | e._roundPixels, e._gpuData[this.renderer.uid].batchableMesh = t, t;
|
|
1115
|
-
}
|
|
1116
|
-
destroy() {
|
|
1117
|
-
this.localUniforms = null, this.localUniformsBindGroup = null, this._adaptor.destroy(), this._adaptor = null, this.renderer = null;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
je.extension = {
|
|
1121
|
-
type: [
|
|
1122
|
-
p.WebGLPipes,
|
|
1123
|
-
p.WebGPUPipes,
|
|
1124
|
-
p.CanvasPipes
|
|
1125
|
-
],
|
|
1126
|
-
name: "mesh"
|
|
1127
|
-
};
|
|
1128
|
-
class Et {
|
|
1129
|
-
execute(e, t) {
|
|
1130
|
-
const r = e.state, n = e.renderer, s = t.shader || e.defaultShader;
|
|
1131
|
-
s.resources.uTexture = t.texture._source, s.resources.uniforms = e.localUniforms;
|
|
1132
|
-
const i = n.gl, a = e.getBuffers(t);
|
|
1133
|
-
n.shader.bind(s), n.state.set(r), n.geometry.bind(a.geometry, s.glProgram);
|
|
1134
|
-
const u = a.geometry.indexBuffer.data.BYTES_PER_ELEMENT === 2 ? i.UNSIGNED_SHORT : i.UNSIGNED_INT;
|
|
1135
|
-
i.drawElements(i.TRIANGLES, t.particleChildren.length * 6, u, 0);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
class Vt {
|
|
1139
|
-
execute(e, t) {
|
|
1140
|
-
const r = e.renderer, n = t.shader || e.defaultShader;
|
|
1141
|
-
n.groups[0] = r.renderPipes.uniformBatch.getUniformBindGroup(e.localUniforms, !0), n.groups[1] = r.texture.getTextureBindGroup(t.texture);
|
|
1142
|
-
const s = e.state, i = e.getBuffers(t);
|
|
1143
|
-
r.encoder.draw({
|
|
1144
|
-
geometry: i.geometry,
|
|
1145
|
-
shader: t.shader || e.defaultShader,
|
|
1146
|
-
state: s,
|
|
1147
|
-
size: t.particleChildren.length * 6
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
function we(o, e = null) {
|
|
1152
|
-
const t = o * 6;
|
|
1153
|
-
if (t > 65535 ? e || (e = new Uint32Array(t)) : e || (e = new Uint16Array(t)), e.length !== t)
|
|
1154
|
-
throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${t}`);
|
|
1155
|
-
for (let r = 0, n = 0; r < t; r += 6, n += 4)
|
|
1156
|
-
e[r + 0] = n + 0, e[r + 1] = n + 1, e[r + 2] = n + 2, e[r + 3] = n + 0, e[r + 4] = n + 2, e[r + 5] = n + 3;
|
|
1157
|
-
return e;
|
|
1158
|
-
}
|
|
1159
|
-
function Wt(o) {
|
|
1160
|
-
return {
|
|
1161
|
-
dynamicUpdate: Ce(o, !0),
|
|
1162
|
-
staticUpdate: Ce(o, !1)
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
function Ce(o, e) {
|
|
1166
|
-
const t = [];
|
|
1167
|
-
t.push(`
|
|
1168
|
-
|
|
1169
|
-
var index = 0;
|
|
1170
|
-
|
|
1171
|
-
for (let i = 0; i < ps.length; ++i)
|
|
1172
|
-
{
|
|
1173
|
-
const p = ps[i];
|
|
1174
|
-
|
|
1175
|
-
`);
|
|
1176
|
-
let r = 0;
|
|
1177
|
-
for (const s in o) {
|
|
1178
|
-
const i = o[s];
|
|
1179
|
-
if (e !== i.dynamic)
|
|
1180
|
-
continue;
|
|
1181
|
-
t.push(`offset = index + ${r}`), t.push(i.code);
|
|
1182
|
-
const a = Q(i.format);
|
|
1183
|
-
r += a.stride / 4;
|
|
1184
|
-
}
|
|
1185
|
-
t.push(`
|
|
1186
|
-
index += stride * 4;
|
|
1187
|
-
}
|
|
1188
|
-
`), t.unshift(`
|
|
1189
|
-
var stride = ${r};
|
|
1190
|
-
`);
|
|
1191
|
-
const n = t.join(`
|
|
1192
|
-
`);
|
|
1193
|
-
return new Function("ps", "f32v", "u32v", n);
|
|
1194
|
-
}
|
|
1195
|
-
class Lt {
|
|
1196
|
-
constructor(e) {
|
|
1197
|
-
this._size = 0, this._generateParticleUpdateCache = {};
|
|
1198
|
-
const t = this._size = e.size ?? 1e3, r = e.properties;
|
|
1199
|
-
let n = 0, s = 0;
|
|
1200
|
-
for (const h in r) {
|
|
1201
|
-
const c = r[h], d = Q(c.format);
|
|
1202
|
-
c.dynamic ? s += d.stride : n += d.stride;
|
|
1203
|
-
}
|
|
1204
|
-
this._dynamicStride = s / 4, this._staticStride = n / 4, this.staticAttributeBuffer = new k(t * 4 * n), this.dynamicAttributeBuffer = new k(t * 4 * s), this.indexBuffer = we(t);
|
|
1205
|
-
const i = new te();
|
|
1206
|
-
let a = 0, l = 0;
|
|
1207
|
-
this._staticBuffer = new D({
|
|
1208
|
-
data: new Float32Array(1),
|
|
1209
|
-
label: "static-particle-buffer",
|
|
1210
|
-
shrinkToFit: !1,
|
|
1211
|
-
usage: C.VERTEX | C.COPY_DST
|
|
1212
|
-
}), this._dynamicBuffer = new D({
|
|
1213
|
-
data: new Float32Array(1),
|
|
1214
|
-
label: "dynamic-particle-buffer",
|
|
1215
|
-
shrinkToFit: !1,
|
|
1216
|
-
usage: C.VERTEX | C.COPY_DST
|
|
1217
|
-
});
|
|
1218
|
-
for (const h in r) {
|
|
1219
|
-
const c = r[h], d = Q(c.format);
|
|
1220
|
-
c.dynamic ? (i.addAttribute(c.attributeName, {
|
|
1221
|
-
buffer: this._dynamicBuffer,
|
|
1222
|
-
stride: this._dynamicStride * 4,
|
|
1223
|
-
offset: a * 4,
|
|
1224
|
-
format: c.format
|
|
1225
|
-
}), a += d.size) : (i.addAttribute(c.attributeName, {
|
|
1226
|
-
buffer: this._staticBuffer,
|
|
1227
|
-
stride: this._staticStride * 4,
|
|
1228
|
-
offset: l * 4,
|
|
1229
|
-
format: c.format
|
|
1230
|
-
}), l += d.size);
|
|
1231
|
-
}
|
|
1232
|
-
i.addIndex(this.indexBuffer);
|
|
1233
|
-
const u = this.getParticleUpdate(r);
|
|
1234
|
-
this._dynamicUpload = u.dynamicUpdate, this._staticUpload = u.staticUpdate, this.geometry = i;
|
|
1235
|
-
}
|
|
1236
|
-
getParticleUpdate(e) {
|
|
1237
|
-
const t = Yt(e);
|
|
1238
|
-
return this._generateParticleUpdateCache[t] ? this._generateParticleUpdateCache[t] : (this._generateParticleUpdateCache[t] = this.generateParticleUpdate(e), this._generateParticleUpdateCache[t]);
|
|
1239
|
-
}
|
|
1240
|
-
generateParticleUpdate(e) {
|
|
1241
|
-
return Wt(e);
|
|
1242
|
-
}
|
|
1243
|
-
update(e, t) {
|
|
1244
|
-
e.length > this._size && (t = !0, this._size = Math.max(e.length, this._size * 1.5 | 0), this.staticAttributeBuffer = new k(this._size * this._staticStride * 4 * 4), this.dynamicAttributeBuffer = new k(this._size * this._dynamicStride * 4 * 4), this.indexBuffer = we(this._size), this.geometry.indexBuffer.setDataWithSize(
|
|
1245
|
-
this.indexBuffer,
|
|
1246
|
-
this.indexBuffer.byteLength,
|
|
1247
|
-
!0
|
|
1248
|
-
));
|
|
1249
|
-
const r = this.dynamicAttributeBuffer;
|
|
1250
|
-
if (this._dynamicUpload(e, r.float32View, r.uint32View), this._dynamicBuffer.setDataWithSize(
|
|
1251
|
-
this.dynamicAttributeBuffer.float32View,
|
|
1252
|
-
e.length * this._dynamicStride * 4,
|
|
1253
|
-
!0
|
|
1254
|
-
), t) {
|
|
1255
|
-
const n = this.staticAttributeBuffer;
|
|
1256
|
-
this._staticUpload(e, n.float32View, n.uint32View), this._staticBuffer.setDataWithSize(
|
|
1257
|
-
n.float32View,
|
|
1258
|
-
e.length * this._staticStride * 4,
|
|
1259
|
-
!0
|
|
1260
|
-
);
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
destroy() {
|
|
1264
|
-
this._staticBuffer.destroy(), this._dynamicBuffer.destroy(), this.geometry.destroy();
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
function Yt(o) {
|
|
1268
|
-
const e = [];
|
|
1269
|
-
for (const t in o) {
|
|
1270
|
-
const r = o[t];
|
|
1271
|
-
e.push(t, r.code, r.dynamic ? "d" : "s");
|
|
1272
|
-
}
|
|
1273
|
-
return e.join("_");
|
|
1274
|
-
}
|
|
1275
|
-
var Xt = `varying vec2 vUV;
|
|
1276
|
-
varying vec4 vColor;
|
|
1277
|
-
|
|
1278
|
-
uniform sampler2D uTexture;
|
|
1279
|
-
|
|
1280
|
-
void main(void){
|
|
1281
|
-
vec4 color = texture2D(uTexture, vUV) * vColor;
|
|
1282
|
-
gl_FragColor = color;
|
|
1283
|
-
}`, Ht = `attribute vec2 aVertex;
|
|
1284
|
-
attribute vec2 aUV;
|
|
1285
|
-
attribute vec4 aColor;
|
|
1286
|
-
|
|
1287
|
-
attribute vec2 aPosition;
|
|
1288
|
-
attribute float aRotation;
|
|
1289
|
-
|
|
1290
|
-
uniform mat3 uTranslationMatrix;
|
|
1291
|
-
uniform float uRound;
|
|
1292
|
-
uniform vec2 uResolution;
|
|
1293
|
-
uniform vec4 uColor;
|
|
1294
|
-
|
|
1295
|
-
varying vec2 vUV;
|
|
1296
|
-
varying vec4 vColor;
|
|
1297
|
-
|
|
1298
|
-
vec2 roundPixels(vec2 position, vec2 targetSize)
|
|
1299
|
-
{
|
|
1300
|
-
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
void main(void){
|
|
1304
|
-
float cosRotation = cos(aRotation);
|
|
1305
|
-
float sinRotation = sin(aRotation);
|
|
1306
|
-
float x = aVertex.x * cosRotation - aVertex.y * sinRotation;
|
|
1307
|
-
float y = aVertex.x * sinRotation + aVertex.y * cosRotation;
|
|
1308
|
-
|
|
1309
|
-
vec2 v = vec2(x, y);
|
|
1310
|
-
v = v + aPosition;
|
|
1311
|
-
|
|
1312
|
-
gl_Position = vec4((uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
|
|
1313
|
-
|
|
1314
|
-
if(uRound == 1.0)
|
|
1315
|
-
{
|
|
1316
|
-
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
vUV = aUV;
|
|
1320
|
-
vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uColor;
|
|
1321
|
-
}
|
|
1322
|
-
`, Pe = `
|
|
1323
|
-
struct ParticleUniforms {
|
|
1324
|
-
uTranslationMatrix:mat3x3<f32>,
|
|
1325
|
-
uColor:vec4<f32>,
|
|
1326
|
-
uRound:f32,
|
|
1327
|
-
uResolution:vec2<f32>,
|
|
1328
|
-
};
|
|
1329
|
-
|
|
1330
|
-
fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
|
|
1331
|
-
{
|
|
1332
|
-
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
@group(0) @binding(0) var<uniform> uniforms: ParticleUniforms;
|
|
1336
|
-
|
|
1337
|
-
@group(1) @binding(0) var uTexture: texture_2d<f32>;
|
|
1338
|
-
@group(1) @binding(1) var uSampler : sampler;
|
|
1339
|
-
|
|
1340
|
-
struct VSOutput {
|
|
1341
|
-
@builtin(position) position: vec4<f32>,
|
|
1342
|
-
@location(0) uv : vec2<f32>,
|
|
1343
|
-
@location(1) color : vec4<f32>,
|
|
1344
|
-
};
|
|
1345
|
-
@vertex
|
|
1346
|
-
fn mainVertex(
|
|
1347
|
-
@location(0) aVertex: vec2<f32>,
|
|
1348
|
-
@location(1) aPosition: vec2<f32>,
|
|
1349
|
-
@location(2) aUV: vec2<f32>,
|
|
1350
|
-
@location(3) aColor: vec4<f32>,
|
|
1351
|
-
@location(4) aRotation: f32,
|
|
1352
|
-
) -> VSOutput {
|
|
1353
|
-
|
|
1354
|
-
let v = vec2(
|
|
1355
|
-
aVertex.x * cos(aRotation) - aVertex.y * sin(aRotation),
|
|
1356
|
-
aVertex.x * sin(aRotation) + aVertex.y * cos(aRotation)
|
|
1357
|
-
) + aPosition;
|
|
1358
|
-
|
|
1359
|
-
var position = vec4((uniforms.uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
|
|
1360
|
-
|
|
1361
|
-
if(uniforms.uRound == 1.0) {
|
|
1362
|
-
position = vec4(roundPixels(position.xy, uniforms.uResolution), position.zw);
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
let vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uniforms.uColor;
|
|
1366
|
-
|
|
1367
|
-
return VSOutput(
|
|
1368
|
-
position,
|
|
1369
|
-
aUV,
|
|
1370
|
-
vColor,
|
|
1371
|
-
);
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
@fragment
|
|
1375
|
-
fn mainFragment(
|
|
1376
|
-
@location(0) uv: vec2<f32>,
|
|
1377
|
-
@location(1) color: vec4<f32>,
|
|
1378
|
-
@builtin(position) position: vec4<f32>,
|
|
1379
|
-
) -> @location(0) vec4<f32> {
|
|
1380
|
-
|
|
1381
|
-
var sample = textureSample(uTexture, uSampler, uv) * color;
|
|
1382
|
-
|
|
1383
|
-
return sample;
|
|
1384
|
-
}`;
|
|
1385
|
-
class Kt extends se {
|
|
1386
|
-
constructor() {
|
|
1387
|
-
const e = Re.from({
|
|
1388
|
-
vertex: Ht,
|
|
1389
|
-
fragment: Xt
|
|
1390
|
-
}), t = Fe.from({
|
|
1391
|
-
fragment: {
|
|
1392
|
-
source: Pe,
|
|
1393
|
-
entryPoint: "mainFragment"
|
|
1394
|
-
},
|
|
1395
|
-
vertex: {
|
|
1396
|
-
source: Pe,
|
|
1397
|
-
entryPoint: "mainVertex"
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
super({
|
|
1401
|
-
glProgram: e,
|
|
1402
|
-
gpuProgram: t,
|
|
1403
|
-
resources: {
|
|
1404
|
-
// this will be replaced with the texture from the particle container
|
|
1405
|
-
uTexture: R.WHITE.source,
|
|
1406
|
-
// this will be replaced with the texture style from the particle container
|
|
1407
|
-
uSampler: new J({}),
|
|
1408
|
-
// this will be replaced with the local uniforms from the particle container
|
|
1409
|
-
uniforms: {
|
|
1410
|
-
uTranslationMatrix: { value: new P(), type: "mat3x3<f32>" },
|
|
1411
|
-
uColor: { value: new Ge(16777215), type: "vec4<f32>" },
|
|
1412
|
-
uRound: { value: 1, type: "f32" },
|
|
1413
|
-
uResolution: { value: [0, 0], type: "vec2<f32>" }
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
});
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
class Ne {
|
|
1420
|
-
/**
|
|
1421
|
-
* @param renderer - The renderer this sprite batch works for.
|
|
1422
|
-
* @param adaptor
|
|
1423
|
-
*/
|
|
1424
|
-
constructor(e, t) {
|
|
1425
|
-
this.state = E.for2d(), this.localUniforms = new M({
|
|
1426
|
-
uTranslationMatrix: { value: new P(), type: "mat3x3<f32>" },
|
|
1427
|
-
uColor: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
1428
|
-
uRound: { value: 1, type: "f32" },
|
|
1429
|
-
uResolution: { value: [0, 0], type: "vec2<f32>" }
|
|
1430
|
-
}), this.renderer = e, this.adaptor = t, this.defaultShader = new Kt(), this.state = E.for2d();
|
|
1431
|
-
}
|
|
1432
|
-
validateRenderable(e) {
|
|
1433
|
-
return !1;
|
|
1434
|
-
}
|
|
1435
|
-
addRenderable(e, t) {
|
|
1436
|
-
this.renderer.renderPipes.batch.break(t), t.add(e);
|
|
1437
|
-
}
|
|
1438
|
-
getBuffers(e) {
|
|
1439
|
-
return e._gpuData[this.renderer.uid] || this._initBuffer(e);
|
|
1440
|
-
}
|
|
1441
|
-
_initBuffer(e) {
|
|
1442
|
-
return e._gpuData[this.renderer.uid] = new Lt({
|
|
1443
|
-
size: e.particleChildren.length,
|
|
1444
|
-
properties: e._properties
|
|
1445
|
-
}), e._gpuData[this.renderer.uid];
|
|
1446
|
-
}
|
|
1447
|
-
updateRenderable(e) {
|
|
1448
|
-
}
|
|
1449
|
-
execute(e) {
|
|
1450
|
-
const t = e.particleChildren;
|
|
1451
|
-
if (t.length === 0)
|
|
1452
|
-
return;
|
|
1453
|
-
const r = this.renderer, n = this.getBuffers(e);
|
|
1454
|
-
e.texture || (e.texture = t[0].texture);
|
|
1455
|
-
const s = this.state;
|
|
1456
|
-
n.update(t, e._childrenDirty), e._childrenDirty = !1, s.blendMode = ne(e.blendMode, e.texture._source);
|
|
1457
|
-
const i = this.localUniforms.uniforms, a = i.uTranslationMatrix;
|
|
1458
|
-
e.worldTransform.copyTo(a), a.prepend(r.globalUniforms.globalUniformData.projectionMatrix), i.uResolution = r.globalUniforms.globalUniformData.resolution, i.uRound = r._roundPixels | e._roundPixels, L(
|
|
1459
|
-
e.groupColorAlpha,
|
|
1460
|
-
i.uColor,
|
|
1461
|
-
0
|
|
1462
|
-
), this.adaptor.execute(this, e);
|
|
1463
|
-
}
|
|
1464
|
-
/** Destroys the ParticleRenderer. */
|
|
1465
|
-
destroy() {
|
|
1466
|
-
this.renderer = null, this.defaultShader && (this.defaultShader.destroy(), this.defaultShader = null);
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
class qe extends Ne {
|
|
1470
|
-
constructor(e) {
|
|
1471
|
-
super(e, new Et());
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
qe.extension = {
|
|
1475
|
-
type: [
|
|
1476
|
-
p.WebGLPipes
|
|
1477
|
-
],
|
|
1478
|
-
name: "particle"
|
|
1479
|
-
};
|
|
1480
|
-
class Qe extends Ne {
|
|
1481
|
-
constructor(e) {
|
|
1482
|
-
super(e, new Vt());
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
Qe.extension = {
|
|
1486
|
-
type: [
|
|
1487
|
-
p.WebGPUPipes
|
|
1488
|
-
],
|
|
1489
|
-
name: "particle"
|
|
1490
|
-
};
|
|
1491
|
-
const Je = class Ze extends It {
|
|
1492
|
-
constructor(e = {}) {
|
|
1493
|
-
e = { ...Ze.defaultOptions, ...e }, super({
|
|
1494
|
-
width: e.width,
|
|
1495
|
-
height: e.height,
|
|
1496
|
-
verticesX: 4,
|
|
1497
|
-
verticesY: 4
|
|
1498
|
-
}), this.update(e);
|
|
1499
|
-
}
|
|
1500
|
-
/**
|
|
1501
|
-
* Updates the NineSliceGeometry with the options.
|
|
1502
|
-
* @param options - The options of the NineSliceGeometry.
|
|
1503
|
-
*/
|
|
1504
|
-
update(e) {
|
|
1505
|
-
this.width = e.width ?? this.width, this.height = e.height ?? this.height, this._originalWidth = e.originalWidth ?? this._originalWidth, this._originalHeight = e.originalHeight ?? this._originalHeight, this._leftWidth = e.leftWidth ?? this._leftWidth, this._rightWidth = e.rightWidth ?? this._rightWidth, this._topHeight = e.topHeight ?? this._topHeight, this._bottomHeight = e.bottomHeight ?? this._bottomHeight, this._anchorX = e.anchor?.x, this._anchorY = e.anchor?.y, this.updateUvs(), this.updatePositions();
|
|
1506
|
-
}
|
|
1507
|
-
/** Updates the positions of the vertices. */
|
|
1508
|
-
updatePositions() {
|
|
1509
|
-
const e = this.positions, {
|
|
1510
|
-
width: t,
|
|
1511
|
-
height: r,
|
|
1512
|
-
_leftWidth: n,
|
|
1513
|
-
_rightWidth: s,
|
|
1514
|
-
_topHeight: i,
|
|
1515
|
-
_bottomHeight: a,
|
|
1516
|
-
_anchorX: l,
|
|
1517
|
-
_anchorY: u
|
|
1518
|
-
} = this, h = n + s, c = t > h ? 1 : t / h, d = i + a, f = r > d ? 1 : r / d, m = Math.min(c, f), x = l * t, g = u * r;
|
|
1519
|
-
e[0] = e[8] = e[16] = e[24] = -x, e[2] = e[10] = e[18] = e[26] = n * m - x, e[4] = e[12] = e[20] = e[28] = t - s * m - x, e[6] = e[14] = e[22] = e[30] = t - x, e[1] = e[3] = e[5] = e[7] = -g, e[9] = e[11] = e[13] = e[15] = i * m - g, e[17] = e[19] = e[21] = e[23] = r - a * m - g, e[25] = e[27] = e[29] = e[31] = r - g, this.getBuffer("aPosition").update();
|
|
1520
|
-
}
|
|
1521
|
-
/** Updates the UVs of the vertices. */
|
|
1522
|
-
updateUvs() {
|
|
1523
|
-
const e = this.uvs;
|
|
1524
|
-
e[0] = e[8] = e[16] = e[24] = 0, e[1] = e[3] = e[5] = e[7] = 0, e[6] = e[14] = e[22] = e[30] = 1, e[25] = e[27] = e[29] = e[31] = 1;
|
|
1525
|
-
const t = 1 / this._originalWidth, r = 1 / this._originalHeight;
|
|
1526
|
-
e[2] = e[10] = e[18] = e[26] = t * this._leftWidth, e[9] = e[11] = e[13] = e[15] = r * this._topHeight, e[4] = e[12] = e[20] = e[28] = 1 - t * this._rightWidth, e[17] = e[19] = e[21] = e[23] = 1 - r * this._bottomHeight, this.getBuffer("aUV").update();
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
Je.defaultOptions = {
|
|
1530
|
-
/** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
|
|
1531
|
-
width: 100,
|
|
1532
|
-
/** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
|
|
1533
|
-
height: 100,
|
|
1534
|
-
/** The width of the left column. */
|
|
1535
|
-
leftWidth: 10,
|
|
1536
|
-
/** The height of the top row. */
|
|
1537
|
-
topHeight: 10,
|
|
1538
|
-
/** The width of the right column. */
|
|
1539
|
-
rightWidth: 10,
|
|
1540
|
-
/** The height of the bottom row. */
|
|
1541
|
-
bottomHeight: 10,
|
|
1542
|
-
/** The original width of the texture */
|
|
1543
|
-
originalWidth: 100,
|
|
1544
|
-
/** The original height of the texture */
|
|
1545
|
-
originalHeight: 100
|
|
1546
|
-
};
|
|
1547
|
-
let $t = Je;
|
|
1548
|
-
class jt extends ae {
|
|
1549
|
-
constructor() {
|
|
1550
|
-
super(), this.geometry = new $t();
|
|
1551
|
-
}
|
|
1552
|
-
destroy() {
|
|
1553
|
-
this.geometry.destroy();
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
class et {
|
|
1557
|
-
constructor(e) {
|
|
1558
|
-
this._renderer = e;
|
|
1559
|
-
}
|
|
1560
|
-
addRenderable(e, t) {
|
|
1561
|
-
const r = this._getGpuSprite(e);
|
|
1562
|
-
e.didViewUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r, t);
|
|
1563
|
-
}
|
|
1564
|
-
updateRenderable(e) {
|
|
1565
|
-
const t = this._getGpuSprite(e);
|
|
1566
|
-
e.didViewUpdate && this._updateBatchableSprite(e, t), t._batcher.updateElement(t);
|
|
1567
|
-
}
|
|
1568
|
-
validateRenderable(e) {
|
|
1569
|
-
const t = this._getGpuSprite(e);
|
|
1570
|
-
return !t._batcher.checkAndUpdateTexture(
|
|
1571
|
-
t,
|
|
1572
|
-
e._texture
|
|
1573
|
-
);
|
|
1574
|
-
}
|
|
1575
|
-
_updateBatchableSprite(e, t) {
|
|
1576
|
-
t.geometry.update(e), t.setTexture(e._texture);
|
|
1577
|
-
}
|
|
1578
|
-
_getGpuSprite(e) {
|
|
1579
|
-
return e._gpuData[this._renderer.uid] || this._initGPUSprite(e);
|
|
1580
|
-
}
|
|
1581
|
-
_initGPUSprite(e) {
|
|
1582
|
-
const t = e._gpuData[this._renderer.uid] = new jt(), r = t;
|
|
1583
|
-
return r.renderable = e, r.transform = e.groupTransform, r.texture = e._texture, r.roundPixels = this._renderer._roundPixels | e._roundPixels, e.didViewUpdate || this._updateBatchableSprite(e, r), t;
|
|
1584
|
-
}
|
|
1585
|
-
destroy() {
|
|
1586
|
-
this._renderer = null;
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
et.extension = {
|
|
1590
|
-
type: [
|
|
1591
|
-
p.WebGLPipes,
|
|
1592
|
-
p.WebGPUPipes,
|
|
1593
|
-
p.CanvasPipes
|
|
1594
|
-
],
|
|
1595
|
-
name: "nineSliceSprite"
|
|
1596
|
-
};
|
|
1597
|
-
const Nt = {
|
|
1598
|
-
name: "tiling-bit",
|
|
1599
|
-
vertex: {
|
|
1600
|
-
header: (
|
|
1601
|
-
/* wgsl */
|
|
1602
|
-
`
|
|
1603
|
-
struct TilingUniforms {
|
|
1604
|
-
uMapCoord:mat3x3<f32>,
|
|
1605
|
-
uClampFrame:vec4<f32>,
|
|
1606
|
-
uClampOffset:vec2<f32>,
|
|
1607
|
-
uTextureTransform:mat3x3<f32>,
|
|
1608
|
-
uSizeAnchor:vec4<f32>
|
|
1609
|
-
};
|
|
1610
|
-
|
|
1611
|
-
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
|
1612
|
-
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
|
1613
|
-
@group(2) @binding(2) var uSampler: sampler;
|
|
1614
|
-
`
|
|
1615
|
-
),
|
|
1616
|
-
main: (
|
|
1617
|
-
/* wgsl */
|
|
1618
|
-
`
|
|
1619
|
-
uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
|
|
1620
|
-
|
|
1621
|
-
position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
|
|
1622
|
-
`
|
|
1623
|
-
)
|
|
1624
|
-
},
|
|
1625
|
-
fragment: {
|
|
1626
|
-
header: (
|
|
1627
|
-
/* wgsl */
|
|
1628
|
-
`
|
|
1629
|
-
struct TilingUniforms {
|
|
1630
|
-
uMapCoord:mat3x3<f32>,
|
|
1631
|
-
uClampFrame:vec4<f32>,
|
|
1632
|
-
uClampOffset:vec2<f32>,
|
|
1633
|
-
uTextureTransform:mat3x3<f32>,
|
|
1634
|
-
uSizeAnchor:vec4<f32>
|
|
1635
|
-
};
|
|
1636
|
-
|
|
1637
|
-
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
|
1638
|
-
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
|
1639
|
-
@group(2) @binding(2) var uSampler: sampler;
|
|
1640
|
-
`
|
|
1641
|
-
),
|
|
1642
|
-
main: (
|
|
1643
|
-
/* wgsl */
|
|
1644
|
-
`
|
|
1645
|
-
|
|
1646
|
-
var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
|
|
1647
|
-
coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
|
|
1648
|
-
var unclamped = coord;
|
|
1649
|
-
coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
|
|
1650
|
-
|
|
1651
|
-
var bias = 0.;
|
|
1652
|
-
|
|
1653
|
-
if(unclamped.x == coord.x && unclamped.y == coord.y)
|
|
1654
|
-
{
|
|
1655
|
-
bias = -32.;
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
|
-
outColor = textureSampleBias(uTexture, uSampler, coord, bias);
|
|
1659
|
-
`
|
|
1660
|
-
)
|
|
1661
|
-
}
|
|
1662
|
-
}, qt = {
|
|
1663
|
-
name: "tiling-bit",
|
|
1664
|
-
vertex: {
|
|
1665
|
-
header: (
|
|
1666
|
-
/* glsl */
|
|
1667
|
-
`
|
|
1668
|
-
uniform mat3 uTextureTransform;
|
|
1669
|
-
uniform vec4 uSizeAnchor;
|
|
1670
|
-
|
|
1671
|
-
`
|
|
1672
|
-
),
|
|
1673
|
-
main: (
|
|
1674
|
-
/* glsl */
|
|
1675
|
-
`
|
|
1676
|
-
uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
|
|
1677
|
-
|
|
1678
|
-
position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
|
|
1679
|
-
`
|
|
1680
|
-
)
|
|
1681
|
-
},
|
|
1682
|
-
fragment: {
|
|
1683
|
-
header: (
|
|
1684
|
-
/* glsl */
|
|
1685
|
-
`
|
|
1686
|
-
uniform sampler2D uTexture;
|
|
1687
|
-
uniform mat3 uMapCoord;
|
|
1688
|
-
uniform vec4 uClampFrame;
|
|
1689
|
-
uniform vec2 uClampOffset;
|
|
1690
|
-
`
|
|
1691
|
-
),
|
|
1692
|
-
main: (
|
|
1693
|
-
/* glsl */
|
|
1694
|
-
`
|
|
1695
|
-
|
|
1696
|
-
vec2 coord = vUV + ceil(uClampOffset - vUV);
|
|
1697
|
-
coord = (uMapCoord * vec3(coord, 1.0)).xy;
|
|
1698
|
-
vec2 unclamped = coord;
|
|
1699
|
-
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
|
|
1700
|
-
|
|
1701
|
-
outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
|
|
1702
|
-
|
|
1703
|
-
`
|
|
1704
|
-
)
|
|
1705
|
-
}
|
|
1706
|
-
};
|
|
1707
|
-
let X, H;
|
|
1708
|
-
class Qt extends se {
|
|
1709
|
-
constructor() {
|
|
1710
|
-
X ?? (X = De({
|
|
1711
|
-
name: "tiling-sprite-shader",
|
|
1712
|
-
bits: [
|
|
1713
|
-
St,
|
|
1714
|
-
Nt,
|
|
1715
|
-
Ae
|
|
1716
|
-
]
|
|
1717
|
-
})), H ?? (H = ke({
|
|
1718
|
-
name: "tiling-sprite-shader",
|
|
1719
|
-
bits: [
|
|
1720
|
-
Ft,
|
|
1721
|
-
qt,
|
|
1722
|
-
ze
|
|
1723
|
-
]
|
|
1724
|
-
}));
|
|
1725
|
-
const e = new M({
|
|
1726
|
-
uMapCoord: { value: new P(), type: "mat3x3<f32>" },
|
|
1727
|
-
uClampFrame: { value: new Float32Array([0, 0, 1, 1]), type: "vec4<f32>" },
|
|
1728
|
-
uClampOffset: { value: new Float32Array([0, 0]), type: "vec2<f32>" },
|
|
1729
|
-
uTextureTransform: { value: new P(), type: "mat3x3<f32>" },
|
|
1730
|
-
uSizeAnchor: { value: new Float32Array([100, 100, 0.5, 0.5]), type: "vec4<f32>" }
|
|
1731
|
-
});
|
|
1732
|
-
super({
|
|
1733
|
-
glProgram: H,
|
|
1734
|
-
gpuProgram: X,
|
|
1735
|
-
resources: {
|
|
1736
|
-
localUniforms: new M({
|
|
1737
|
-
uTransformMatrix: { value: new P(), type: "mat3x3<f32>" },
|
|
1738
|
-
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
1739
|
-
uRound: { value: 0, type: "f32" }
|
|
1740
|
-
}),
|
|
1741
|
-
tilingUniforms: e,
|
|
1742
|
-
uTexture: R.EMPTY.source,
|
|
1743
|
-
uSampler: R.EMPTY.source.style
|
|
1744
|
-
}
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
updateUniforms(e, t, r, n, s, i) {
|
|
1748
|
-
const a = this.resources.tilingUniforms, l = i.width, u = i.height, h = i.textureMatrix, c = a.uniforms.uTextureTransform;
|
|
1749
|
-
c.set(
|
|
1750
|
-
r.a * l / e,
|
|
1751
|
-
r.b * l / t,
|
|
1752
|
-
r.c * u / e,
|
|
1753
|
-
r.d * u / t,
|
|
1754
|
-
r.tx / e,
|
|
1755
|
-
r.ty / t
|
|
1756
|
-
), c.invert(), a.uniforms.uMapCoord = h.mapCoord, a.uniforms.uClampFrame = h.uClampFrame, a.uniforms.uClampOffset = h.uClampOffset, a.uniforms.uTextureTransform = c, a.uniforms.uSizeAnchor[0] = e, a.uniforms.uSizeAnchor[1] = t, a.uniforms.uSizeAnchor[2] = n, a.uniforms.uSizeAnchor[3] = s, i && (this.resources.uTexture = i.source, this.resources.uSampler = i.source.style);
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
class Jt extends ie {
|
|
1760
|
-
constructor() {
|
|
1761
|
-
super({
|
|
1762
|
-
positions: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
1763
|
-
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
1764
|
-
indices: new Uint32Array([0, 1, 2, 0, 2, 3])
|
|
1765
|
-
});
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
function Zt(o, e) {
|
|
1769
|
-
const t = o.anchor.x, r = o.anchor.y;
|
|
1770
|
-
e[0] = -t * o.width, e[1] = -r * o.height, e[2] = (1 - t) * o.width, e[3] = -r * o.height, e[4] = (1 - t) * o.width, e[5] = (1 - r) * o.height, e[6] = -t * o.width, e[7] = (1 - r) * o.height;
|
|
1771
|
-
}
|
|
1772
|
-
function er(o, e, t, r) {
|
|
1773
|
-
let n = 0;
|
|
1774
|
-
const s = o.length / e, i = r.a, a = r.b, l = r.c, u = r.d, h = r.tx, c = r.ty;
|
|
1775
|
-
for (t *= e; n < s; ) {
|
|
1776
|
-
const d = o[t], f = o[t + 1];
|
|
1777
|
-
o[t] = i * d + l * f + h, o[t + 1] = a * d + u * f + c, t += e, n++;
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
function tr(o, e) {
|
|
1781
|
-
const t = o.texture, r = t.frame.width, n = t.frame.height;
|
|
1782
|
-
let s = 0, i = 0;
|
|
1783
|
-
o.applyAnchorToTexture && (s = o.anchor.x, i = o.anchor.y), e[0] = e[6] = -s, e[2] = e[4] = 1 - s, e[1] = e[3] = -i, e[5] = e[7] = 1 - i;
|
|
1784
|
-
const a = P.shared;
|
|
1785
|
-
a.copyFrom(o._tileTransform.matrix), a.tx /= o.width, a.ty /= o.height, a.invert(), a.scale(o.width / r, o.height / n), er(e, 2, 0, a);
|
|
1786
|
-
}
|
|
1787
|
-
const z = new Jt();
|
|
1788
|
-
class rr {
|
|
1789
|
-
constructor() {
|
|
1790
|
-
this.canBatch = !0, this.geometry = new ie({
|
|
1791
|
-
indices: z.indices.slice(),
|
|
1792
|
-
positions: z.positions.slice(),
|
|
1793
|
-
uvs: z.uvs.slice()
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
destroy() {
|
|
1797
|
-
this.geometry.destroy(), this.shader?.destroy();
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
class tt {
|
|
1801
|
-
constructor(e) {
|
|
1802
|
-
this._state = E.default2d, this._renderer = e;
|
|
1803
|
-
}
|
|
1804
|
-
validateRenderable(e) {
|
|
1805
|
-
const t = this._getTilingSpriteData(e), r = t.canBatch;
|
|
1806
|
-
this._updateCanBatch(e);
|
|
1807
|
-
const n = t.canBatch;
|
|
1808
|
-
if (n && n === r) {
|
|
1809
|
-
const { batchableMesh: s } = t;
|
|
1810
|
-
return !s._batcher.checkAndUpdateTexture(
|
|
1811
|
-
s,
|
|
1812
|
-
e.texture
|
|
1813
|
-
);
|
|
1814
|
-
}
|
|
1815
|
-
return r !== n;
|
|
1816
|
-
}
|
|
1817
|
-
addRenderable(e, t) {
|
|
1818
|
-
const r = this._renderer.renderPipes.batch;
|
|
1819
|
-
this._updateCanBatch(e);
|
|
1820
|
-
const n = this._getTilingSpriteData(e), { geometry: s, canBatch: i } = n;
|
|
1821
|
-
if (i) {
|
|
1822
|
-
n.batchableMesh || (n.batchableMesh = new ae());
|
|
1823
|
-
const a = n.batchableMesh;
|
|
1824
|
-
e.didViewUpdate && (this._updateBatchableMesh(e), a.geometry = s, a.renderable = e, a.transform = e.groupTransform, a.setTexture(e._texture)), a.roundPixels = this._renderer._roundPixels | e._roundPixels, r.addToBatch(a, t);
|
|
1825
|
-
} else
|
|
1826
|
-
r.break(t), n.shader || (n.shader = new Qt()), this.updateRenderable(e), t.add(e);
|
|
1827
|
-
}
|
|
1828
|
-
execute(e) {
|
|
1829
|
-
const { shader: t } = this._getTilingSpriteData(e);
|
|
1830
|
-
t.groups[0] = this._renderer.globalUniforms.bindGroup;
|
|
1831
|
-
const r = t.resources.localUniforms.uniforms;
|
|
1832
|
-
r.uTransformMatrix = e.groupTransform, r.uRound = this._renderer._roundPixels | e._roundPixels, L(
|
|
1833
|
-
e.groupColorAlpha,
|
|
1834
|
-
r.uColor,
|
|
1835
|
-
0
|
|
1836
|
-
), this._state.blendMode = ne(e.groupBlendMode, e.texture._source), this._renderer.encoder.draw({
|
|
1837
|
-
geometry: z,
|
|
1838
|
-
shader: t,
|
|
1839
|
-
state: this._state
|
|
1840
|
-
});
|
|
1841
|
-
}
|
|
1842
|
-
updateRenderable(e) {
|
|
1843
|
-
const t = this._getTilingSpriteData(e), { canBatch: r } = t;
|
|
1844
|
-
if (r) {
|
|
1845
|
-
const { batchableMesh: n } = t;
|
|
1846
|
-
e.didViewUpdate && this._updateBatchableMesh(e), n._batcher.updateElement(n);
|
|
1847
|
-
} else if (e.didViewUpdate) {
|
|
1848
|
-
const { shader: n } = t;
|
|
1849
|
-
n.updateUniforms(
|
|
1850
|
-
e.width,
|
|
1851
|
-
e.height,
|
|
1852
|
-
e._tileTransform.matrix,
|
|
1853
|
-
e.anchor.x,
|
|
1854
|
-
e.anchor.y,
|
|
1855
|
-
e.texture
|
|
1856
|
-
);
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
_getTilingSpriteData(e) {
|
|
1860
|
-
return e._gpuData[this._renderer.uid] || this._initTilingSpriteData(e);
|
|
1861
|
-
}
|
|
1862
|
-
_initTilingSpriteData(e) {
|
|
1863
|
-
const t = new rr();
|
|
1864
|
-
return t.renderable = e, e._gpuData[this._renderer.uid] = t, t;
|
|
1865
|
-
}
|
|
1866
|
-
_updateBatchableMesh(e) {
|
|
1867
|
-
const t = this._getTilingSpriteData(e), { geometry: r } = t, n = e.texture.source.style;
|
|
1868
|
-
n.addressMode !== "repeat" && (n.addressMode = "repeat", n.update()), tr(e, r.uvs), Zt(e, r.positions);
|
|
1869
|
-
}
|
|
1870
|
-
destroy() {
|
|
1871
|
-
this._renderer = null;
|
|
1872
|
-
}
|
|
1873
|
-
_updateCanBatch(e) {
|
|
1874
|
-
const t = this._getTilingSpriteData(e), r = e.texture;
|
|
1875
|
-
let n = !0;
|
|
1876
|
-
return this._renderer.type === re.WEBGL && (n = this._renderer.context.supports.nonPowOf2wrapping), t.canBatch = r.textureMatrix.isSimple && (n || r.source.isPowerOfTwo), t.canBatch;
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
tt.extension = {
|
|
1880
|
-
type: [
|
|
1881
|
-
p.WebGLPipes,
|
|
1882
|
-
p.WebGPUPipes,
|
|
1883
|
-
p.CanvasPipes
|
|
1884
|
-
],
|
|
1885
|
-
name: "tilingSprite"
|
|
1886
|
-
};
|
|
1887
|
-
const nr = {
|
|
1888
|
-
name: "local-uniform-msdf-bit",
|
|
1889
|
-
vertex: {
|
|
1890
|
-
header: (
|
|
1891
|
-
/* wgsl */
|
|
1892
|
-
`
|
|
1893
|
-
struct LocalUniforms {
|
|
1894
|
-
uColor:vec4<f32>,
|
|
1895
|
-
uTransformMatrix:mat3x3<f32>,
|
|
1896
|
-
uDistance: f32,
|
|
1897
|
-
uRound:f32,
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
1901
|
-
`
|
|
1902
|
-
),
|
|
1903
|
-
main: (
|
|
1904
|
-
/* wgsl */
|
|
1905
|
-
`
|
|
1906
|
-
vColor *= localUniforms.uColor;
|
|
1907
|
-
modelMatrix *= localUniforms.uTransformMatrix;
|
|
1908
|
-
`
|
|
1909
|
-
),
|
|
1910
|
-
end: (
|
|
1911
|
-
/* wgsl */
|
|
1912
|
-
`
|
|
1913
|
-
if(localUniforms.uRound == 1)
|
|
1914
|
-
{
|
|
1915
|
-
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
1916
|
-
}
|
|
1917
|
-
`
|
|
1918
|
-
)
|
|
1919
|
-
},
|
|
1920
|
-
fragment: {
|
|
1921
|
-
header: (
|
|
1922
|
-
/* wgsl */
|
|
1923
|
-
`
|
|
1924
|
-
struct LocalUniforms {
|
|
1925
|
-
uColor:vec4<f32>,
|
|
1926
|
-
uTransformMatrix:mat3x3<f32>,
|
|
1927
|
-
uDistance: f32
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
1931
|
-
`
|
|
1932
|
-
),
|
|
1933
|
-
main: (
|
|
1934
|
-
/* wgsl */
|
|
1935
|
-
`
|
|
1936
|
-
outColor = vec4<f32>(calculateMSDFAlpha(outColor, localUniforms.uColor, localUniforms.uDistance));
|
|
1937
|
-
`
|
|
1938
|
-
)
|
|
1939
|
-
}
|
|
1940
|
-
}, sr = {
|
|
1941
|
-
name: "local-uniform-msdf-bit",
|
|
1942
|
-
vertex: {
|
|
1943
|
-
header: (
|
|
1944
|
-
/* glsl */
|
|
1945
|
-
`
|
|
1946
|
-
uniform mat3 uTransformMatrix;
|
|
1947
|
-
uniform vec4 uColor;
|
|
1948
|
-
uniform float uRound;
|
|
1949
|
-
`
|
|
1950
|
-
),
|
|
1951
|
-
main: (
|
|
1952
|
-
/* glsl */
|
|
1953
|
-
`
|
|
1954
|
-
vColor *= uColor;
|
|
1955
|
-
modelMatrix *= uTransformMatrix;
|
|
1956
|
-
`
|
|
1957
|
-
),
|
|
1958
|
-
end: (
|
|
1959
|
-
/* glsl */
|
|
1960
|
-
`
|
|
1961
|
-
if(uRound == 1.)
|
|
1962
|
-
{
|
|
1963
|
-
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
1964
|
-
}
|
|
1965
|
-
`
|
|
1966
|
-
)
|
|
1967
|
-
},
|
|
1968
|
-
fragment: {
|
|
1969
|
-
header: (
|
|
1970
|
-
/* glsl */
|
|
1971
|
-
`
|
|
1972
|
-
uniform float uDistance;
|
|
1973
|
-
`
|
|
1974
|
-
),
|
|
1975
|
-
main: (
|
|
1976
|
-
/* glsl */
|
|
1977
|
-
`
|
|
1978
|
-
outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance));
|
|
1979
|
-
`
|
|
1980
|
-
)
|
|
1981
|
-
}
|
|
1982
|
-
}, ir = {
|
|
1983
|
-
name: "msdf-bit",
|
|
1984
|
-
fragment: {
|
|
1985
|
-
header: (
|
|
1986
|
-
/* wgsl */
|
|
1987
|
-
`
|
|
1988
|
-
fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 {
|
|
1989
|
-
|
|
1990
|
-
// MSDF
|
|
1991
|
-
var median = msdfColor.r + msdfColor.g + msdfColor.b -
|
|
1992
|
-
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
|
1993
|
-
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
|
1994
|
-
|
|
1995
|
-
// SDF
|
|
1996
|
-
median = min(median, msdfColor.a);
|
|
1997
|
-
|
|
1998
|
-
var screenPxDistance = distance * (median - 0.5);
|
|
1999
|
-
var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
|
2000
|
-
if (median < 0.01) {
|
|
2001
|
-
alpha = 0.0;
|
|
2002
|
-
} else if (median > 0.99) {
|
|
2003
|
-
alpha = 1.0;
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
// Gamma correction for coverage-like alpha
|
|
2007
|
-
var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114));
|
|
2008
|
-
var gamma: f32 = mix(1.0, 1.0 / 2.2, luma);
|
|
2009
|
-
var coverage: f32 = pow(shapeColor.a * alpha, gamma);
|
|
2010
|
-
|
|
2011
|
-
return coverage;
|
|
2012
|
-
|
|
2013
|
-
}
|
|
2014
|
-
`
|
|
2015
|
-
)
|
|
2016
|
-
}
|
|
2017
|
-
}, ar = {
|
|
2018
|
-
name: "msdf-bit",
|
|
2019
|
-
fragment: {
|
|
2020
|
-
header: (
|
|
2021
|
-
/* glsl */
|
|
2022
|
-
`
|
|
2023
|
-
float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) {
|
|
2024
|
-
|
|
2025
|
-
// MSDF
|
|
2026
|
-
float median = msdfColor.r + msdfColor.g + msdfColor.b -
|
|
2027
|
-
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
|
2028
|
-
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
|
2029
|
-
|
|
2030
|
-
// SDF
|
|
2031
|
-
median = min(median, msdfColor.a);
|
|
2032
|
-
|
|
2033
|
-
float screenPxDistance = distance * (median - 0.5);
|
|
2034
|
-
float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
|
2035
|
-
|
|
2036
|
-
if (median < 0.01) {
|
|
2037
|
-
alpha = 0.0;
|
|
2038
|
-
} else if (median > 0.99) {
|
|
2039
|
-
alpha = 1.0;
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
|
-
// Gamma correction for coverage-like alpha
|
|
2043
|
-
float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114));
|
|
2044
|
-
float gamma = mix(1.0, 1.0 / 2.2, luma);
|
|
2045
|
-
float coverage = pow(shapeColor.a * alpha, gamma);
|
|
2046
|
-
|
|
2047
|
-
return coverage;
|
|
2048
|
-
}
|
|
2049
|
-
`
|
|
2050
|
-
)
|
|
2051
|
-
}
|
|
2052
|
-
};
|
|
2053
|
-
let K, $;
|
|
2054
|
-
class or extends se {
|
|
2055
|
-
constructor(e) {
|
|
2056
|
-
const t = new M({
|
|
2057
|
-
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
2058
|
-
uTransformMatrix: { value: new P(), type: "mat3x3<f32>" },
|
|
2059
|
-
uDistance: { value: 4, type: "f32" },
|
|
2060
|
-
uRound: { value: 0, type: "f32" }
|
|
2061
|
-
});
|
|
2062
|
-
K ?? (K = De({
|
|
2063
|
-
name: "sdf-shader",
|
|
2064
|
-
bits: [
|
|
2065
|
-
gt,
|
|
2066
|
-
xt(e),
|
|
2067
|
-
nr,
|
|
2068
|
-
ir,
|
|
2069
|
-
Ae
|
|
2070
|
-
]
|
|
2071
|
-
})), $ ?? ($ = ke({
|
|
2072
|
-
name: "sdf-shader",
|
|
2073
|
-
bits: [
|
|
2074
|
-
_t,
|
|
2075
|
-
bt(e),
|
|
2076
|
-
sr,
|
|
2077
|
-
ar,
|
|
2078
|
-
ze
|
|
2079
|
-
]
|
|
2080
|
-
})), super({
|
|
2081
|
-
glProgram: $,
|
|
2082
|
-
gpuProgram: K,
|
|
2083
|
-
resources: {
|
|
2084
|
-
localUniforms: t,
|
|
2085
|
-
batchSamplers: vt(e)
|
|
2086
|
-
}
|
|
2087
|
-
});
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
class ur extends wt {
|
|
2091
|
-
destroy() {
|
|
2092
|
-
this.context.customShader && this.context.customShader.destroy(), super.destroy();
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
class rt {
|
|
2096
|
-
constructor(e) {
|
|
2097
|
-
this._renderer = e;
|
|
2098
|
-
}
|
|
2099
|
-
validateRenderable(e) {
|
|
2100
|
-
const t = this._getGpuBitmapText(e);
|
|
2101
|
-
return this._renderer.renderPipes.graphics.validateRenderable(t);
|
|
2102
|
-
}
|
|
2103
|
-
addRenderable(e, t) {
|
|
2104
|
-
const r = this._getGpuBitmapText(e);
|
|
2105
|
-
Se(e, r), e._didTextUpdate && (e._didTextUpdate = !1, this._updateContext(e, r)), this._renderer.renderPipes.graphics.addRenderable(r, t), r.context.customShader && this._updateDistanceField(e);
|
|
2106
|
-
}
|
|
2107
|
-
updateRenderable(e) {
|
|
2108
|
-
const t = this._getGpuBitmapText(e);
|
|
2109
|
-
Se(e, t), this._renderer.renderPipes.graphics.updateRenderable(t), t.context.customShader && this._updateDistanceField(e);
|
|
2110
|
-
}
|
|
2111
|
-
_updateContext(e, t) {
|
|
2112
|
-
const { context: r } = t, n = yt.getFont(e.text, e._style);
|
|
2113
|
-
r.clear(), n.distanceField.type !== "none" && (r.customShader || (r.customShader = new or(this._renderer.limits.maxBatchableTextures)));
|
|
2114
|
-
const s = B.graphemeSegmenter(e.text), i = e._style;
|
|
2115
|
-
let a = n.baseLineOffset;
|
|
2116
|
-
const l = Tt(s, i, n, !0), u = i.padding, h = l.scale;
|
|
2117
|
-
let c = l.width, d = l.height + l.offsetY;
|
|
2118
|
-
i._stroke && (c += i._stroke.width / h, d += i._stroke.width / h), r.translate(-e._anchor._x * c - u, -e._anchor._y * d - u).scale(h, h);
|
|
2119
|
-
const f = n.applyFillAsTint ? i._fill.color : 16777215;
|
|
2120
|
-
let m = n.fontMetrics.fontSize, x = n.lineHeight;
|
|
2121
|
-
i.lineHeight && (m = i.fontSize / h, x = i.lineHeight / h);
|
|
2122
|
-
let g = (x - m) / 2;
|
|
2123
|
-
g - n.baseLineOffset < 0 && (g = 0);
|
|
2124
|
-
for (let _ = 0; _ < l.lines.length; _++) {
|
|
2125
|
-
const b = l.lines[_];
|
|
2126
|
-
for (let T = 0; T < b.charPositions.length; T++) {
|
|
2127
|
-
const A = b.chars[T], F = n.chars[A];
|
|
2128
|
-
if (F?.texture) {
|
|
2129
|
-
const G = F.texture;
|
|
2130
|
-
r.texture(
|
|
2131
|
-
G,
|
|
2132
|
-
f || "black",
|
|
2133
|
-
Math.round(b.charPositions[T] + F.xOffset),
|
|
2134
|
-
Math.round(a + F.yOffset + g),
|
|
2135
|
-
G.orig.width,
|
|
2136
|
-
G.orig.height
|
|
2137
|
-
);
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
a += x;
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
_getGpuBitmapText(e) {
|
|
2144
|
-
return e._gpuData[this._renderer.uid] || this.initGpuText(e);
|
|
2145
|
-
}
|
|
2146
|
-
initGpuText(e) {
|
|
2147
|
-
const t = new ur();
|
|
2148
|
-
return e._gpuData[this._renderer.uid] = t, this._updateContext(e, t), t;
|
|
2149
|
-
}
|
|
2150
|
-
_updateDistanceField(e) {
|
|
2151
|
-
const t = this._getGpuBitmapText(e).context, r = e._style.fontFamily, n = Z.get(`${r}-bitmap`), { a: s, b: i, c: a, d: l } = e.groupTransform, u = Math.sqrt(s * s + i * i), h = Math.sqrt(a * a + l * l), c = (Math.abs(u) + Math.abs(h)) / 2, d = n.baseRenderedFontSize / e._style.fontSize, f = c * n.distanceField.range * (1 / d);
|
|
2152
|
-
t.customShader.resources.localUniforms.uniforms.uDistance = f;
|
|
2153
|
-
}
|
|
2154
|
-
destroy() {
|
|
2155
|
-
this._renderer = null;
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
rt.extension = {
|
|
2159
|
-
type: [
|
|
2160
|
-
p.WebGLPipes,
|
|
2161
|
-
p.WebGPUPipes,
|
|
2162
|
-
p.CanvasPipes
|
|
2163
|
-
],
|
|
2164
|
-
name: "bitmapText"
|
|
2165
|
-
};
|
|
2166
|
-
function Se(o, e) {
|
|
2167
|
-
e.groupTransform = o.groupTransform, e.groupColorAlpha = o.groupColorAlpha, e.groupColor = o.groupColor, e.groupBlendMode = o.groupBlendMode, e.globalDisplayStatus = o.globalDisplayStatus, e.groupTransform = o.groupTransform, e.localDisplayStatus = o.localDisplayStatus, e.groupAlpha = o.groupAlpha, e._roundPixels = o._roundPixels;
|
|
2168
|
-
}
|
|
2169
|
-
class lr extends Oe {
|
|
2170
|
-
/**
|
|
2171
|
-
* Creates an instance of BatchableHTMLText.
|
|
2172
|
-
* @param renderer - The renderer instance to be used.
|
|
2173
|
-
*/
|
|
2174
|
-
constructor(e) {
|
|
2175
|
-
super(), this.generatingTexture = !1, this.currentKey = "--", this._renderer = e, e.runners.resolutionChange.add(this);
|
|
2176
|
-
}
|
|
2177
|
-
/** Handles resolution changes for the HTML text. If the text has auto resolution enabled, it triggers a view update. */
|
|
2178
|
-
resolutionChange() {
|
|
2179
|
-
const e = this.renderable;
|
|
2180
|
-
e._autoResolution && e.onViewUpdate();
|
|
2181
|
-
}
|
|
2182
|
-
/** Destroys the BatchableHTMLText instance. Returns the texture promise to the renderer and cleans up references. */
|
|
2183
|
-
destroy() {
|
|
2184
|
-
const { htmlText: e } = this._renderer;
|
|
2185
|
-
e.getReferenceCount(this.currentKey) === null ? e.returnTexturePromise(this.texturePromise) : e.decreaseReferenceCount(this.currentKey), this._renderer.runners.resolutionChange.remove(this), this.texturePromise = null, this._renderer = null;
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
function ee(o, e) {
|
|
2189
|
-
const { texture: t, bounds: r } = o, n = e._style._getFinalPadding();
|
|
2190
|
-
Ct(r, e._anchor, t);
|
|
2191
|
-
const s = e._anchor._x * n * 2, i = e._anchor._y * n * 2;
|
|
2192
|
-
r.minX -= n - s, r.minY -= n - i, r.maxX -= n - s, r.maxY -= n - i;
|
|
2193
|
-
}
|
|
2194
|
-
class nt {
|
|
2195
|
-
constructor(e) {
|
|
2196
|
-
this._renderer = e;
|
|
2197
|
-
}
|
|
2198
|
-
validateRenderable(e) {
|
|
2199
|
-
const t = this._getGpuText(e), r = e.styleKey;
|
|
2200
|
-
return t.currentKey !== r;
|
|
2201
|
-
}
|
|
2202
|
-
addRenderable(e, t) {
|
|
2203
|
-
const r = this._getGpuText(e);
|
|
2204
|
-
if (e._didTextUpdate) {
|
|
2205
|
-
const n = e._autoResolution ? this._renderer.resolution : e.resolution;
|
|
2206
|
-
(r.currentKey !== e.styleKey || e.resolution !== n) && this._updateGpuText(e).catch((s) => {
|
|
2207
|
-
console.error(s);
|
|
2208
|
-
}), e._didTextUpdate = !1, ee(r, e);
|
|
2209
|
-
}
|
|
2210
|
-
this._renderer.renderPipes.batch.addToBatch(r, t);
|
|
2211
|
-
}
|
|
2212
|
-
updateRenderable(e) {
|
|
2213
|
-
const t = this._getGpuText(e);
|
|
2214
|
-
t._batcher.updateElement(t);
|
|
2215
|
-
}
|
|
2216
|
-
async _updateGpuText(e) {
|
|
2217
|
-
e._didTextUpdate = !1;
|
|
2218
|
-
const t = this._getGpuText(e);
|
|
2219
|
-
if (t.generatingTexture)
|
|
2220
|
-
return;
|
|
2221
|
-
const r = t.texturePromise;
|
|
2222
|
-
t.texturePromise = null, t.generatingTexture = !0, e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution;
|
|
2223
|
-
let n = this._renderer.htmlText.getTexturePromise(e);
|
|
2224
|
-
r && (n = n.finally(() => {
|
|
2225
|
-
this._renderer.htmlText.decreaseReferenceCount(t.currentKey), this._renderer.htmlText.returnTexturePromise(r);
|
|
2226
|
-
})), t.texturePromise = n, t.currentKey = e.styleKey, t.texture = await n;
|
|
2227
|
-
const s = e.renderGroup || e.parentRenderGroup;
|
|
2228
|
-
s && (s.structureDidChange = !0), t.generatingTexture = !1, ee(t, e);
|
|
2229
|
-
}
|
|
2230
|
-
_getGpuText(e) {
|
|
2231
|
-
return e._gpuData[this._renderer.uid] || this.initGpuText(e);
|
|
2232
|
-
}
|
|
2233
|
-
initGpuText(e) {
|
|
2234
|
-
const t = new lr(this._renderer);
|
|
2235
|
-
return t.renderable = e, t.transform = e.groupTransform, t.texture = R.EMPTY, t.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution, e._gpuData[this._renderer.uid] = t, t;
|
|
2236
|
-
}
|
|
2237
|
-
destroy() {
|
|
2238
|
-
this._renderer = null;
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
nt.extension = {
|
|
2242
|
-
type: [
|
|
2243
|
-
p.WebGLPipes,
|
|
2244
|
-
p.WebGPUPipes,
|
|
2245
|
-
p.CanvasPipes
|
|
2246
|
-
],
|
|
2247
|
-
name: "htmlText"
|
|
2248
|
-
};
|
|
2249
|
-
function cr() {
|
|
2250
|
-
const { userAgent: o } = W.get().getNavigator();
|
|
2251
|
-
return /^((?!chrome|android).)*safari/i.test(o);
|
|
2252
|
-
}
|
|
2253
|
-
const dr = new Be();
|
|
2254
|
-
function st(o, e, t, r) {
|
|
2255
|
-
const n = dr;
|
|
2256
|
-
n.minX = 0, n.minY = 0, n.maxX = o.width / r | 0, n.maxY = o.height / r | 0;
|
|
2257
|
-
const s = w.getOptimalTexture(
|
|
2258
|
-
n.width,
|
|
2259
|
-
n.height,
|
|
2260
|
-
r,
|
|
2261
|
-
!1
|
|
2262
|
-
);
|
|
2263
|
-
return s.source.uploadMethodId = "image", s.source.resource = o, s.source.alphaMode = "premultiply-alpha-on-upload", s.frame.width = e / r, s.frame.height = t / r, s.source.emit("update", s.source), s.updateUvs(), s;
|
|
2264
|
-
}
|
|
2265
|
-
function hr(o, e) {
|
|
2266
|
-
const t = e.fontFamily, r = [], n = {}, s = /font-family:([^;"\s]+)/g, i = o.match(s);
|
|
2267
|
-
function a(l) {
|
|
2268
|
-
n[l] || (r.push(l), n[l] = !0);
|
|
2269
|
-
}
|
|
2270
|
-
if (Array.isArray(t))
|
|
2271
|
-
for (let l = 0; l < t.length; l++)
|
|
2272
|
-
a(t[l]);
|
|
2273
|
-
else
|
|
2274
|
-
a(t);
|
|
2275
|
-
i && i.forEach((l) => {
|
|
2276
|
-
const u = l.split(":")[1].trim();
|
|
2277
|
-
a(u);
|
|
2278
|
-
});
|
|
2279
|
-
for (const l in e.tagStyles) {
|
|
2280
|
-
const u = e.tagStyles[l].fontFamily;
|
|
2281
|
-
a(u);
|
|
2282
|
-
}
|
|
2283
|
-
return r;
|
|
2284
|
-
}
|
|
2285
|
-
async function fr(o) {
|
|
2286
|
-
const t = await (await W.get().fetch(o)).blob(), r = new FileReader();
|
|
2287
|
-
return await new Promise((s, i) => {
|
|
2288
|
-
r.onloadend = () => s(r.result), r.onerror = i, r.readAsDataURL(t);
|
|
2289
|
-
});
|
|
2290
|
-
}
|
|
2291
|
-
async function pr(o, e) {
|
|
2292
|
-
const t = await fr(e);
|
|
2293
|
-
return `@font-face {
|
|
2294
|
-
font-family: "${o.fontFamily}";
|
|
2295
|
-
font-weight: ${o.fontWeight};
|
|
2296
|
-
font-style: ${o.fontStyle};
|
|
2297
|
-
src: url('${t}');
|
|
2298
|
-
}`;
|
|
2299
|
-
}
|
|
2300
|
-
const j = /* @__PURE__ */ new Map();
|
|
2301
|
-
async function mr(o) {
|
|
2302
|
-
const e = o.filter((t) => Z.has(`${t}-and-url`)).map((t) => {
|
|
2303
|
-
if (!j.has(t)) {
|
|
2304
|
-
const { entries: r } = Z.get(`${t}-and-url`), n = [];
|
|
2305
|
-
r.forEach((s) => {
|
|
2306
|
-
const i = s.url, l = s.faces.map((u) => ({ weight: u.weight, style: u.style }));
|
|
2307
|
-
n.push(
|
|
2308
|
-
...l.map(
|
|
2309
|
-
(u) => pr(
|
|
2310
|
-
{
|
|
2311
|
-
fontWeight: u.weight,
|
|
2312
|
-
fontStyle: u.style,
|
|
2313
|
-
fontFamily: t
|
|
2314
|
-
},
|
|
2315
|
-
i
|
|
2316
|
-
)
|
|
2317
|
-
)
|
|
2318
|
-
);
|
|
2319
|
-
}), j.set(
|
|
2320
|
-
t,
|
|
2321
|
-
Promise.all(n).then((s) => s.join(`
|
|
2322
|
-
`))
|
|
2323
|
-
);
|
|
2324
|
-
}
|
|
2325
|
-
return j.get(t);
|
|
2326
|
-
});
|
|
2327
|
-
return (await Promise.all(e)).join(`
|
|
2328
|
-
`);
|
|
2329
|
-
}
|
|
2330
|
-
function gr(o, e, t, r, n) {
|
|
2331
|
-
const { domElement: s, styleElement: i, svgRoot: a } = n;
|
|
2332
|
-
s.innerHTML = `<style>${e.cssStyle}</style><div style='padding:0;'>${o}</div>`, s.setAttribute("style", `transform: scale(${t});transform-origin: top left; display: inline-block`), i.textContent = r;
|
|
2333
|
-
const { width: l, height: u } = n.image;
|
|
2334
|
-
return a.setAttribute("width", l.toString()), a.setAttribute("height", u.toString()), new XMLSerializer().serializeToString(a);
|
|
2335
|
-
}
|
|
2336
|
-
function xr(o, e) {
|
|
2337
|
-
const t = I.getOptimalCanvasAndContext(
|
|
2338
|
-
o.width,
|
|
2339
|
-
o.height,
|
|
2340
|
-
e
|
|
2341
|
-
), { context: r } = t;
|
|
2342
|
-
return r.clearRect(0, 0, o.width, o.height), r.drawImage(o, 0, 0), t;
|
|
2343
|
-
}
|
|
2344
|
-
function _r(o, e, t) {
|
|
2345
|
-
return new Promise(async (r) => {
|
|
2346
|
-
t && await new Promise((n) => setTimeout(n, 100)), o.onload = () => {
|
|
2347
|
-
r();
|
|
2348
|
-
}, o.src = `data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`, o.crossOrigin = "anonymous";
|
|
2349
|
-
});
|
|
2350
|
-
}
|
|
2351
|
-
class it {
|
|
2352
|
-
constructor(e) {
|
|
2353
|
-
this._activeTextures = {}, this._renderer = e, this._createCanvas = e.type === re.WEBGPU;
|
|
2354
|
-
}
|
|
2355
|
-
/**
|
|
2356
|
-
* @param options
|
|
2357
|
-
* @deprecated Use getTexturePromise instead
|
|
2358
|
-
*/
|
|
2359
|
-
getTexture(e) {
|
|
2360
|
-
return this.getTexturePromise(e);
|
|
2361
|
-
}
|
|
2362
|
-
/**
|
|
2363
|
-
* Increases the reference count for a texture.
|
|
2364
|
-
* @param text - The HTMLText instance associated with the texture.
|
|
2365
|
-
*/
|
|
2366
|
-
getManagedTexture(e) {
|
|
2367
|
-
const t = e.styleKey;
|
|
2368
|
-
if (this._activeTextures[t])
|
|
2369
|
-
return this._increaseReferenceCount(t), this._activeTextures[t].promise;
|
|
2370
|
-
const r = this._buildTexturePromise(e).then((n) => (this._activeTextures[t].texture = n, n));
|
|
2371
|
-
return this._activeTextures[t] = {
|
|
2372
|
-
texture: null,
|
|
2373
|
-
promise: r,
|
|
2374
|
-
usageCount: 1
|
|
2375
|
-
}, r;
|
|
2376
|
-
}
|
|
2377
|
-
/**
|
|
2378
|
-
* Gets the current reference count for a texture associated with a text key.
|
|
2379
|
-
* @param textKey - The unique key identifying the text style configuration
|
|
2380
|
-
* @returns The number of Text instances currently using this texture
|
|
2381
|
-
*/
|
|
2382
|
-
getReferenceCount(e) {
|
|
2383
|
-
return this._activeTextures[e]?.usageCount ?? null;
|
|
2384
|
-
}
|
|
2385
|
-
_increaseReferenceCount(e) {
|
|
2386
|
-
this._activeTextures[e].usageCount++;
|
|
2387
|
-
}
|
|
2388
|
-
/**
|
|
2389
|
-
* Decreases the reference count for a texture.
|
|
2390
|
-
* If the count reaches zero, the texture is cleaned up.
|
|
2391
|
-
* @param textKey - The key associated with the HTMLText instance.
|
|
2392
|
-
*/
|
|
2393
|
-
decreaseReferenceCount(e) {
|
|
2394
|
-
const t = this._activeTextures[e];
|
|
2395
|
-
t && (t.usageCount--, t.usageCount === 0 && (t.texture ? this._cleanUp(t.texture) : t.promise.then((r) => {
|
|
2396
|
-
t.texture = r, this._cleanUp(t.texture);
|
|
2397
|
-
}).catch(() => {
|
|
2398
|
-
N("HTMLTextSystem: Failed to clean texture");
|
|
2399
|
-
}), this._activeTextures[e] = null));
|
|
2400
|
-
}
|
|
2401
|
-
/**
|
|
2402
|
-
* Returns a promise that resolves to a texture for the given HTMLText options.
|
|
2403
|
-
* @param options - The options for the HTMLText.
|
|
2404
|
-
* @returns A promise that resolves to a Texture.
|
|
2405
|
-
*/
|
|
2406
|
-
getTexturePromise(e) {
|
|
2407
|
-
return this._buildTexturePromise(e);
|
|
2408
|
-
}
|
|
2409
|
-
async _buildTexturePromise(e) {
|
|
2410
|
-
const { text: t, style: r, resolution: n, textureStyle: s } = e, i = V.get(Xe), a = hr(t, r), l = await mr(a), u = zt(t, r, l, i), h = Math.ceil(Math.ceil(Math.max(1, u.width) + r.padding * 2) * n), c = Math.ceil(Math.ceil(Math.max(1, u.height) + r.padding * 2) * n), d = i.image, f = 2;
|
|
2411
|
-
d.width = (h | 0) + f, d.height = (c | 0) + f;
|
|
2412
|
-
const m = gr(t, r, n, l, i);
|
|
2413
|
-
await _r(d, m, cr() && a.length > 0);
|
|
2414
|
-
const x = d;
|
|
2415
|
-
let g;
|
|
2416
|
-
this._createCanvas && (g = xr(d, n));
|
|
2417
|
-
const _ = st(
|
|
2418
|
-
g ? g.canvas : x,
|
|
2419
|
-
d.width - f,
|
|
2420
|
-
d.height - f,
|
|
2421
|
-
n
|
|
2422
|
-
);
|
|
2423
|
-
return s && (_.source.style = s), this._createCanvas && (this._renderer.texture.initSource(_.source), I.returnCanvasAndContext(g)), V.return(i), _;
|
|
2424
|
-
}
|
|
2425
|
-
returnTexturePromise(e) {
|
|
2426
|
-
e.then((t) => {
|
|
2427
|
-
this._cleanUp(t);
|
|
2428
|
-
}).catch(() => {
|
|
2429
|
-
N("HTMLTextSystem: Failed to clean texture");
|
|
2430
|
-
});
|
|
2431
|
-
}
|
|
2432
|
-
_cleanUp(e) {
|
|
2433
|
-
w.returnTexture(e, !0), e.source.resource = null, e.source.uploadMethodId = "unknown";
|
|
2434
|
-
}
|
|
2435
|
-
destroy() {
|
|
2436
|
-
this._renderer = null;
|
|
2437
|
-
for (const e in this._activeTextures)
|
|
2438
|
-
this._activeTextures[e] && this.returnTexturePromise(this._activeTextures[e].promise);
|
|
2439
|
-
this._activeTextures = null;
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
it.extension = {
|
|
2443
|
-
type: [
|
|
2444
|
-
p.WebGLSystem,
|
|
2445
|
-
p.WebGPUSystem,
|
|
2446
|
-
p.CanvasSystem
|
|
2447
|
-
],
|
|
2448
|
-
name: "htmlText"
|
|
2449
|
-
};
|
|
2450
|
-
class br extends Oe {
|
|
2451
|
-
constructor(e) {
|
|
2452
|
-
super(), this._renderer = e, e.runners.resolutionChange.add(this);
|
|
2453
|
-
}
|
|
2454
|
-
resolutionChange() {
|
|
2455
|
-
const e = this.renderable;
|
|
2456
|
-
e._autoResolution && e.onViewUpdate();
|
|
2457
|
-
}
|
|
2458
|
-
destroy() {
|
|
2459
|
-
const { canvasText: e } = this._renderer;
|
|
2460
|
-
e.getReferenceCount(this.currentKey) > 0 ? e.decreaseReferenceCount(this.currentKey) : this.texture && e.returnTexture(this.texture), this._renderer.runners.resolutionChange.remove(this), this._renderer = null;
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
class at {
|
|
2464
|
-
constructor(e) {
|
|
2465
|
-
this._renderer = e;
|
|
2466
|
-
}
|
|
2467
|
-
validateRenderable(e) {
|
|
2468
|
-
const t = this._getGpuText(e), r = e.styleKey;
|
|
2469
|
-
return t.currentKey !== r ? !0 : e._didTextUpdate;
|
|
2470
|
-
}
|
|
2471
|
-
addRenderable(e, t) {
|
|
2472
|
-
const r = this._getGpuText(e);
|
|
2473
|
-
if (e._didTextUpdate) {
|
|
2474
|
-
const n = e._autoResolution ? this._renderer.resolution : e.resolution;
|
|
2475
|
-
(r.currentKey !== e.styleKey || e.resolution !== n) && this._updateGpuText(e), e._didTextUpdate = !1, ee(r, e);
|
|
2476
|
-
}
|
|
2477
|
-
this._renderer.renderPipes.batch.addToBatch(r, t);
|
|
2478
|
-
}
|
|
2479
|
-
updateRenderable(e) {
|
|
2480
|
-
const t = this._getGpuText(e);
|
|
2481
|
-
t._batcher.updateElement(t);
|
|
2482
|
-
}
|
|
2483
|
-
_updateGpuText(e) {
|
|
2484
|
-
const t = this._getGpuText(e);
|
|
2485
|
-
t.texture && this._renderer.canvasText.decreaseReferenceCount(t.currentKey), e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution, t.texture = this._renderer.canvasText.getManagedTexture(e), t.currentKey = e.styleKey;
|
|
2486
|
-
}
|
|
2487
|
-
_getGpuText(e) {
|
|
2488
|
-
return e._gpuData[this._renderer.uid] || this.initGpuText(e);
|
|
2489
|
-
}
|
|
2490
|
-
initGpuText(e) {
|
|
2491
|
-
const t = new br(this._renderer);
|
|
2492
|
-
return t.currentKey = "--", t.renderable = e, t.transform = e.groupTransform, t.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._gpuData[this._renderer.uid] = t, t;
|
|
2493
|
-
}
|
|
2494
|
-
destroy() {
|
|
2495
|
-
this._renderer = null;
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
at.extension = {
|
|
2499
|
-
type: [
|
|
2500
|
-
p.WebGLPipes,
|
|
2501
|
-
p.WebGPUPipes,
|
|
2502
|
-
p.CanvasPipes
|
|
2503
|
-
],
|
|
2504
|
-
name: "text"
|
|
2505
|
-
};
|
|
2506
|
-
class ot {
|
|
2507
|
-
constructor(e) {
|
|
2508
|
-
this._activeTextures = {}, this._renderer = e;
|
|
2509
|
-
}
|
|
2510
|
-
getTexture(e, t, r, n) {
|
|
2511
|
-
typeof e == "string" && (O("8.0.0", "CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"), e = {
|
|
2512
|
-
text: e,
|
|
2513
|
-
style: r,
|
|
2514
|
-
resolution: t
|
|
2515
|
-
}), e.style instanceof fe || (e.style = new fe(e.style)), e.textureStyle instanceof J || (e.textureStyle = new J(e.textureStyle)), typeof e.text != "string" && (e.text = e.text.toString());
|
|
2516
|
-
const { text: s, style: i, textureStyle: a } = e, l = e.resolution ?? this._renderer.resolution, { frame: u, canvasAndContext: h } = Y.getCanvasAndContext({
|
|
2517
|
-
text: s,
|
|
2518
|
-
style: i,
|
|
2519
|
-
resolution: l
|
|
2520
|
-
}), c = st(h.canvas, u.width, u.height, l);
|
|
2521
|
-
if (a && (c.source.style = a), i.trim && (u.pad(i.padding), c.frame.copyFrom(u), c.frame.scale(1 / l), c.updateUvs()), i.filters) {
|
|
2522
|
-
const d = this._applyFilters(c, i.filters);
|
|
2523
|
-
return this.returnTexture(c), Y.returnCanvasAndContext(h), d;
|
|
2524
|
-
}
|
|
2525
|
-
return this._renderer.texture.initSource(c._source), Y.returnCanvasAndContext(h), c;
|
|
2526
|
-
}
|
|
2527
|
-
/**
|
|
2528
|
-
* Returns a texture that was created wit the above `getTexture` function.
|
|
2529
|
-
* Handy if you are done with a texture and want to return it to the pool.
|
|
2530
|
-
* @param texture - The texture to be returned.
|
|
2531
|
-
*/
|
|
2532
|
-
returnTexture(e) {
|
|
2533
|
-
const t = e.source;
|
|
2534
|
-
t.resource = null, t.uploadMethodId = "unknown", t.alphaMode = "no-premultiply-alpha", w.returnTexture(e, !0);
|
|
2535
|
-
}
|
|
2536
|
-
/**
|
|
2537
|
-
* Renders text to its canvas, and updates its texture.
|
|
2538
|
-
* @deprecated since 8.10.0
|
|
2539
|
-
*/
|
|
2540
|
-
renderTextToCanvas() {
|
|
2541
|
-
O(
|
|
2542
|
-
"8.10.0",
|
|
2543
|
-
"CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead"
|
|
2544
|
-
);
|
|
2545
|
-
}
|
|
2546
|
-
/**
|
|
2547
|
-
* Gets or creates a managed texture for a Text object. This method handles texture reuse and reference counting.
|
|
2548
|
-
* @param text - The Text object that needs a texture
|
|
2549
|
-
* @returns A Texture instance that represents the rendered text
|
|
2550
|
-
* @remarks
|
|
2551
|
-
* This method performs the following:
|
|
2552
|
-
* 1. Sets the appropriate resolution based on auto-resolution settings
|
|
2553
|
-
* 2. Checks if a texture already exists for the text's style
|
|
2554
|
-
* 3. Creates a new texture if needed or returns an existing one
|
|
2555
|
-
* 4. Manages reference counting for texture reuse
|
|
2556
|
-
*/
|
|
2557
|
-
getManagedTexture(e) {
|
|
2558
|
-
e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution;
|
|
2559
|
-
const t = e.styleKey;
|
|
2560
|
-
if (this._activeTextures[t])
|
|
2561
|
-
return this._increaseReferenceCount(t), this._activeTextures[t].texture;
|
|
2562
|
-
const r = this.getTexture({
|
|
2563
|
-
text: e.text,
|
|
2564
|
-
style: e.style,
|
|
2565
|
-
resolution: e._resolution,
|
|
2566
|
-
textureStyle: e.textureStyle
|
|
2567
|
-
});
|
|
2568
|
-
return this._activeTextures[t] = {
|
|
2569
|
-
texture: r,
|
|
2570
|
-
usageCount: 1
|
|
2571
|
-
}, r;
|
|
2572
|
-
}
|
|
2573
|
-
/**
|
|
2574
|
-
* Decreases the reference count for a texture associated with a text key.
|
|
2575
|
-
* When the reference count reaches zero, the texture is returned to the pool.
|
|
2576
|
-
* @param textKey - The unique key identifying the text style configuration
|
|
2577
|
-
* @remarks
|
|
2578
|
-
* This method is crucial for memory management, ensuring textures are properly
|
|
2579
|
-
* cleaned up when they are no longer needed by any Text instances.
|
|
2580
|
-
*/
|
|
2581
|
-
decreaseReferenceCount(e) {
|
|
2582
|
-
const t = this._activeTextures[e];
|
|
2583
|
-
t.usageCount--, t.usageCount === 0 && (this.returnTexture(t.texture), this._activeTextures[e] = null);
|
|
2584
|
-
}
|
|
2585
|
-
/**
|
|
2586
|
-
* Gets the current reference count for a texture associated with a text key.
|
|
2587
|
-
* @param textKey - The unique key identifying the text style configuration
|
|
2588
|
-
* @returns The number of Text instances currently using this texture
|
|
2589
|
-
*/
|
|
2590
|
-
getReferenceCount(e) {
|
|
2591
|
-
return this._activeTextures[e]?.usageCount ?? 0;
|
|
2592
|
-
}
|
|
2593
|
-
_increaseReferenceCount(e) {
|
|
2594
|
-
this._activeTextures[e].usageCount++;
|
|
2595
|
-
}
|
|
2596
|
-
/**
|
|
2597
|
-
* Applies the specified filters to the given texture.
|
|
2598
|
-
*
|
|
2599
|
-
* This method takes a texture and a list of filters, applies the filters to the texture,
|
|
2600
|
-
* and returns the resulting texture. It also ensures that the alpha mode of the resulting
|
|
2601
|
-
* texture is set to 'premultiplied-alpha'.
|
|
2602
|
-
* @param {Texture} texture - The texture to which the filters will be applied.
|
|
2603
|
-
* @param {Filter[]} filters - The filters to apply to the texture.
|
|
2604
|
-
* @returns {Texture} The resulting texture after all filters have been applied.
|
|
2605
|
-
*/
|
|
2606
|
-
_applyFilters(e, t) {
|
|
2607
|
-
const r = this._renderer.renderTarget.renderTarget, n = this._renderer.filter.generateFilteredTexture({
|
|
2608
|
-
texture: e,
|
|
2609
|
-
filters: t
|
|
2610
|
-
});
|
|
2611
|
-
return this._renderer.renderTarget.bind(r, !1), n;
|
|
2612
|
-
}
|
|
2613
|
-
destroy() {
|
|
2614
|
-
this._renderer = null;
|
|
2615
|
-
for (const e in this._activeTextures)
|
|
2616
|
-
this._activeTextures[e] && this.returnTexture(this._activeTextures[e].texture);
|
|
2617
|
-
this._activeTextures = null;
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
ot.extension = {
|
|
2621
|
-
type: [
|
|
2622
|
-
p.WebGLSystem,
|
|
2623
|
-
p.WebGPUSystem,
|
|
2624
|
-
p.CanvasSystem
|
|
2625
|
-
],
|
|
2626
|
-
name: "canvasText"
|
|
2627
|
-
};
|
|
2628
|
-
y.add(Ie);
|
|
2629
|
-
y.add(Ee);
|
|
2630
|
-
y.add(He);
|
|
2631
|
-
y.add(Pt);
|
|
2632
|
-
y.add(je);
|
|
2633
|
-
y.add(qe);
|
|
2634
|
-
y.add(Qe);
|
|
2635
|
-
y.add(ot);
|
|
2636
|
-
y.add(at);
|
|
2637
|
-
y.add(rt);
|
|
2638
|
-
y.add(it);
|
|
2639
|
-
y.add(nt);
|
|
2640
|
-
y.add(tt);
|
|
2641
|
-
y.add(et);
|
|
2642
|
-
y.add(We);
|
|
2643
|
-
y.add(Ve);
|