@eva/plugin-a11y 1.2.0-alpha.6 → 1.2.1

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.
@@ -1,8 +1,6 @@
1
- import { OBSERVER_TYPE, decorators, resourceLoader, resource, RESOURCE_TYPE_STRATEGY, LOAD_SCENE_MODE, System, Component } from '@eva/eva.js';
2
- import { Application as Application$2, Container as Container$2, glCore, Texture, BaseTexture, utils, ticker } from 'pixi.js';
1
+ import { Component, decorators, System, OBSERVER_TYPE } from '@eva/eva.js';
2
+ import { RendererSystem } from '@eva/plugin-renderer';
3
3
  import { type, step } from '@eva/inspector-decorator';
4
- import isEqual from 'lodash-es/isEqual';
5
- import EventEmitter from 'eventemitter3';
6
4
 
7
5
  /*! *****************************************************************************
8
6
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -97,918 +95,8 @@ function __values(o) {
97
95
  return { value: o && o[i++], done: !o };
98
96
  }
99
97
  };
100
- }
101
-
102
- function __read(o, n) {
103
- var m = typeof Symbol === "function" && o[Symbol.iterator];
104
- if (!m) return o;
105
- var i = m.call(o), r, ar = [], e;
106
- try {
107
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
108
- }
109
- catch (error) { e = { error: error }; }
110
- finally {
111
- try {
112
- if (r && !r.done && (m = i["return"])) m.call(i);
113
- }
114
- finally { if (e) throw e.error; }
115
- }
116
- return ar;
117
- }
118
-
119
- function __spread() {
120
- for (var ar = [], i = 0; i < arguments.length; i++)
121
- ar = ar.concat(__read(arguments[i]));
122
- return ar;
123
- }
124
-
125
- var Application = (function (_super) {
126
- __extends(Application, _super);
127
- function Application(params) {
128
- var _this = this;
129
- params.autoStart = false;
130
- _this = _super.call(this, params) || this;
131
- return _this;
132
- }
133
- return Application;
134
- }(Application$2));
135
- var Application$1 = Application;
136
-
137
- var Container = (function (_super) {
138
- __extends(Container, _super);
139
- function Container() {
140
- return _super !== null && _super.apply(this, arguments) || this;
141
- }
142
- return Container;
143
- }(Container$2));
144
- var Container$1 = Container;
145
-
146
- var RendererManager = (function () {
147
- function RendererManager(_a) {
148
- var game = _a.game, rendererSystem = _a.rendererSystem;
149
- this.renderers = [];
150
- this.game = game;
151
- this.rendererSystem = rendererSystem;
152
- }
153
- RendererManager.prototype.register = function () {
154
- var e_1, _a;
155
- var renderers = [];
156
- for (var _i = 0; _i < arguments.length; _i++) {
157
- renderers[_i] = arguments[_i];
158
- }
159
- try {
160
- for (var renderers_1 = __values(renderers), renderers_1_1 = renderers_1.next(); !renderers_1_1.done; renderers_1_1 = renderers_1.next()) {
161
- var renderer = renderers_1_1.value;
162
- renderer.game = this.game;
163
- renderer.rendererManager = this.rendererSystem.rendererManager;
164
- renderer.containerManager = this.rendererSystem.containerManager;
165
- this.renderers.push(renderer);
166
- }
167
- }
168
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
169
- finally {
170
- try {
171
- if (renderers_1_1 && !renderers_1_1.done && (_a = renderers_1.return)) _a.call(renderers_1);
172
- }
173
- finally { if (e_1) throw e_1.error; }
174
- }
175
- };
176
- RendererManager.prototype.componentChanged = function (changes) {
177
- var e_2, _a;
178
- var _loop_1 = function (changed) {
179
- var e_3, _a;
180
- try {
181
- for (var _b = (e_3 = void 0, __values(this_1.renderers)), _c = _b.next(); !_c.done; _c = _b.next()) {
182
- var renderer = _c.value;
183
- var props = renderer.observerInfo[changed.componentName];
184
- if (props) {
185
- if ([OBSERVER_TYPE.ADD, OBSERVER_TYPE.REMOVE].indexOf(changed.type) > -1) {
186
- try {
187
- renderer.componentChanged && renderer.componentChanged(changed);
188
- }
189
- catch (e) {
190
- console.error("gameObject: " + changed.gameObject.name + ", " + changed.componentName + " is error.", changed, e);
191
- }
192
- continue;
193
- }
194
- var index = props.findIndex(function (prop) {
195
- return isEqual(prop, changed.prop);
196
- });
197
- if (index > -1) {
198
- try {
199
- renderer.componentChanged && renderer.componentChanged(changed);
200
- }
201
- catch (e) {
202
- console.error("gameObject: " + (changed.gameObject && changed.gameObject.name) + ", " + changed.componentName + " is componentChanged error.", changed, e);
203
- }
204
- }
205
- }
206
- }
207
- }
208
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
209
- finally {
210
- try {
211
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
212
- }
213
- finally { if (e_3) throw e_3.error; }
214
- }
215
- };
216
- var this_1 = this;
217
- try {
218
- for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
219
- var changed = changes_1_1.value;
220
- _loop_1(changed);
221
- }
222
- }
223
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
224
- finally {
225
- try {
226
- if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
227
- }
228
- finally { if (e_2) throw e_2.error; }
229
- }
230
- };
231
- RendererManager.prototype.update = function (gameObject) {
232
- var e_4, _a, e_5, _b;
233
- try {
234
- for (var _c = __values(gameObject.components), _d = _c.next(); !_d.done; _d = _c.next()) {
235
- var component = _d.value;
236
- try {
237
- for (var _e = (e_5 = void 0, __values(this.renderers)), _f = _e.next(); !_f.done; _f = _e.next()) {
238
- var renderer = _f.value;
239
- var cache = [];
240
- var props = renderer.observerInfo[component.name];
241
- if (props && cache.indexOf(gameObject) === -1) {
242
- cache.push(gameObject);
243
- try {
244
- renderer.rendererUpdate && renderer.rendererUpdate(gameObject);
245
- }
246
- catch (e) {
247
- console.info("gameObject: " + gameObject.name + ", " + component.name + " is update error", e);
248
- }
249
- }
250
- }
251
- }
252
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
253
- finally {
254
- try {
255
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
256
- }
257
- finally { if (e_5) throw e_5.error; }
258
- }
259
- }
260
- }
261
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
262
- finally {
263
- try {
264
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
265
- }
266
- finally { if (e_4) throw e_4.error; }
267
- }
268
- };
269
- return RendererManager;
270
- }());
271
- var RendererManager$1 = RendererManager;
272
-
273
- var ContainerManager = (function () {
274
- function ContainerManager() {
275
- this.containerMap = {};
276
- }
277
- ContainerManager.prototype.addContainer = function (_a) {
278
- var name = _a.name, container = _a.container;
279
- this.containerMap[name] = container;
280
- };
281
- ContainerManager.prototype.getContainer = function (name) {
282
- return this.containerMap[name];
283
- };
284
- ContainerManager.prototype.removeContainer = function (name) {
285
- var _a;
286
- (_a = this.containerMap[name]) === null || _a === void 0 ? void 0 : _a.destroy({ children: true });
287
- delete this.containerMap[name];
288
- };
289
- ContainerManager.prototype.updateTransform = function (_a) {
290
- var name = _a.name, transform = _a.transform;
291
- var container = this.containerMap[name];
292
- if (!container)
293
- return;
294
- var anchor = transform.anchor, origin = transform.origin, position = transform.position, rotation = transform.rotation, scale = transform.scale, size = transform.size, skew = transform.skew;
295
- container.rotation = rotation;
296
- container.scale = scale;
297
- container.pivot.x = size.width * origin.x;
298
- container.pivot.y = size.height * origin.y;
299
- container.skew = skew;
300
- var x = position.x;
301
- var y = position.y;
302
- if (transform.parent) {
303
- var parent_1 = transform.parent;
304
- x = x + parent_1.size.width * anchor.x;
305
- y = y + parent_1.size.height * anchor.y;
306
- }
307
- container.position = { x: x, y: y };
308
- };
309
- return ContainerManager;
310
- }());
311
- var ContainerManager$1 = ContainerManager;
312
-
313
- var Transform = (function (_super) {
314
- __extends(Transform, _super);
315
- function Transform(_a) {
316
- var system = _a.system, containerManager = _a.containerManager;
317
- var _this = _super.call(this) || this;
318
- _this.name = 'Transform';
319
- _this.waitRemoveIds = [];
320
- _this.waitChangeScenes = [];
321
- _this.containerManager = containerManager;
322
- _this.init(system);
323
- return _this;
324
- }
325
- Transform.prototype.init = function (system) {
326
- var _this = this;
327
- this.system = system;
328
- this.on('changeScene', function (_a) {
329
- var scene = _a.scene, mode = _a.mode, application = _a.application;
330
- _this.waitChangeScenes.push({ scene: scene, mode: mode, application: application });
331
- });
332
- };
333
- Transform.prototype.update = function () {
334
- var e_1, _a, e_2, _b;
335
- try {
336
- for (var _c = __values(this.waitRemoveIds), _d = _c.next(); !_d.done; _d = _c.next()) {
337
- var id = _d.value;
338
- this.containerManager.removeContainer(id);
339
- }
340
- }
341
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
342
- finally {
343
- try {
344
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
345
- }
346
- finally { if (e_1) throw e_1.error; }
347
- }
348
- this.waitRemoveIds = [];
349
- try {
350
- for (var _e = __values(this.waitChangeScenes), _f = _e.next(); !_f.done; _f = _e.next()) {
351
- var sceneInfo = _f.value;
352
- var container = this.containerManager.getContainer(sceneInfo.scene.id);
353
- if (container) {
354
- sceneInfo.application.stage.removeChildren();
355
- sceneInfo.application.stage.addChild(container);
356
- }
357
- }
358
- }
359
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
360
- finally {
361
- try {
362
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
363
- }
364
- finally { if (e_2) throw e_2.error; }
365
- }
366
- this.waitChangeScenes = [];
367
- };
368
- Transform.prototype.componentChanged = function (changed) {
369
- if (changed.type === OBSERVER_TYPE.ADD) {
370
- this.addContainer(changed);
371
- }
372
- else if (changed.type === OBSERVER_TYPE.CHANGE) {
373
- this.change(changed);
374
- }
375
- else if (changed.type === OBSERVER_TYPE.REMOVE) {
376
- this.waitRemoveIds.push(changed.gameObject.id);
377
- }
378
- };
379
- Transform.prototype.addContainer = function (changed) {
380
- var container = new Container$1();
381
- container.name = changed.gameObject.name;
382
- this.containerManager.addContainer({
383
- name: changed.gameObject.id,
384
- container: container,
385
- });
386
- var transform = changed.component;
387
- transform.worldTransform = container.transform.worldTransform;
388
- };
389
- Transform.prototype.change = function (changed) {
390
- var transform = changed.component;
391
- if (transform.parent) {
392
- var parentContainer = this.containerManager.getContainer(transform.parent.gameObject.id);
393
- parentContainer.addChild(this.containerManager.getContainer(changed.gameObject.id));
394
- var render = changed.gameObject.transform.parent &&
395
- changed.gameObject.transform.parent.gameObject.getComponent('Render');
396
- if (render) {
397
- render.sortDirty = true;
398
- }
399
- }
400
- else {
401
- var container = this.containerManager.getContainer(changed.gameObject.id);
402
- delete transform.worldTransform;
403
- container.parent && container.parent.removeChild(container);
404
- }
405
- };
406
- Transform.prototype.destroy = function () {
407
- this.removeAllListeners();
408
- this.waitRemoveIds = null;
409
- this.waitChangeScenes = null;
410
- this.system = null;
411
- this.containerManager = null;
412
- };
413
- Transform = __decorate([
414
- decorators.componentObserver({
415
- Transform: ['_parent'],
416
- })
417
- ], Transform);
418
- return Transform;
419
- }(EventEmitter));
420
- var Transform$1 = Transform;
421
-
422
- var result = undefined;
423
- function getSuportCompressedTextureFormats(gl) {
424
- if (result)
425
- return result;
426
- if (!gl) {
427
- console.warn('WebGL not available for compressed textures. Silently failing.');
428
- return {
429
- s3tc: false,
430
- etc: false,
431
- etc1: false,
432
- pvrtc: false,
433
- atc: false,
434
- astc: false,
435
- };
436
- }
437
- result = {
438
- s3tc: !!gl.getExtension('WEBGL_compressed_texture_s3tc'),
439
- etc: !!gl.getExtension('WEBGL_compressed_texture_etc'),
440
- etc1: !!gl.getExtension('WEBGL_compressed_texture_etc1'),
441
- pvrtc: !!gl.getExtension('WEBGL_compressed_texture_pvrtc')
442
- || !!gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc'),
443
- atc: !!gl.getExtension('WEBGL_compressed_texture_atc'),
444
- astc: !!gl.getExtension('WEBGL_compressed_texture_astc')
445
- };
446
- try {
447
- console.log('Eva.js Supported Compressed Texture Format List: ' + Object.keys(result).filter(function (type) { return result[type]; }).join(', '));
448
- }
449
- catch (e) { }
450
- return result;
451
98
  }
452
99
 
453
- var XLS = resourceLoader.XhrLoadStrategy;
454
- var XhrLoadStrategy = XLS;
455
-
456
- var _a$2, _b;
457
- var INTERNAL_FORMATS;
458
- (function (INTERNAL_FORMATS) {
459
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_S3TC_DXT1_EXT"] = 33776] = "COMPRESSED_RGB_S3TC_DXT1_EXT";
460
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT1_EXT"] = 33777] = "COMPRESSED_RGBA_S3TC_DXT1_EXT";
461
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT3_EXT"] = 33778] = "COMPRESSED_RGBA_S3TC_DXT3_EXT";
462
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_S3TC_DXT5_EXT"] = 33779] = "COMPRESSED_RGBA_S3TC_DXT5_EXT";
463
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT"] = 35917] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT";
464
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT"] = 35918] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT";
465
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT"] = 35919] = "COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT";
466
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB_S3TC_DXT1_EXT"] = 35916] = "COMPRESSED_SRGB_S3TC_DXT1_EXT";
467
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_R11_EAC"] = 37488] = "COMPRESSED_R11_EAC";
468
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SIGNED_R11_EAC"] = 37489] = "COMPRESSED_SIGNED_R11_EAC";
469
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RG11_EAC"] = 37490] = "COMPRESSED_RG11_EAC";
470
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SIGNED_RG11_EAC"] = 37491] = "COMPRESSED_SIGNED_RG11_EAC";
471
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB8_ETC2"] = 37492] = "COMPRESSED_RGB8_ETC2";
472
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA8_ETC2_EAC"] = 37496] = "COMPRESSED_RGBA8_ETC2_EAC";
473
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ETC2"] = 37493] = "COMPRESSED_SRGB8_ETC2";
474
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ETC2_EAC"] = 37497] = "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC";
475
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 37494] = "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2";
476
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 37495] = "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2";
477
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_PVRTC_4BPPV1_IMG"] = 35840] = "COMPRESSED_RGB_PVRTC_4BPPV1_IMG";
478
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_PVRTC_4BPPV1_IMG"] = 35842] = "COMPRESSED_RGBA_PVRTC_4BPPV1_IMG";
479
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_PVRTC_2BPPV1_IMG"] = 35841] = "COMPRESSED_RGB_PVRTC_2BPPV1_IMG";
480
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_PVRTC_2BPPV1_IMG"] = 35843] = "COMPRESSED_RGBA_PVRTC_2BPPV1_IMG";
481
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_ETC1_WEBGL"] = 36196] = "COMPRESSED_RGB_ETC1_WEBGL";
482
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGB_ATC_WEBGL"] = 35986] = "COMPRESSED_RGB_ATC_WEBGL";
483
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL"] = 35986] = "COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL";
484
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL"] = 34798] = "COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL";
485
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x10_KHR"] = 37819] = "COMPRESSED_RGBA_ASTC_10x10_KHR";
486
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x5_KHR"] = 37816] = "COMPRESSED_RGBA_ASTC_10x5_KHR";
487
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x6_KHR"] = 37817] = "COMPRESSED_RGBA_ASTC_10x6_KHR";
488
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_10x8_KHR"] = 37818] = "COMPRESSED_RGBA_ASTC_10x8_KHR";
489
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_12x10_KHR"] = 37820] = "COMPRESSED_RGBA_ASTC_12x10_KHR";
490
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_12x12_KHR"] = 37821] = "COMPRESSED_RGBA_ASTC_12x12_KHR";
491
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_4x4_KHR"] = 37808] = "COMPRESSED_RGBA_ASTC_4x4_KHR";
492
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_5x4_KHR"] = 37809] = "COMPRESSED_RGBA_ASTC_5x4_KHR";
493
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_5x5_KHR"] = 37810] = "COMPRESSED_RGBA_ASTC_5x5_KHR";
494
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_6x5_KHR"] = 37811] = "COMPRESSED_RGBA_ASTC_6x5_KHR";
495
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_6x6_KHR"] = 37812] = "COMPRESSED_RGBA_ASTC_6x6_KHR";
496
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_8x5_KHR"] = 37813] = "COMPRESSED_RGBA_ASTC_8x5_KHR";
497
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_8x6_KHR"] = 37814] = "COMPRESSED_RGBA_ASTC_8x6_KHR";
498
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_RGBA_ASTC_8x8_KHR"] = 37815] = "COMPRESSED_RGBA_ASTC_8x8_KHR";
499
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR"] = 3781] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR";
500
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR"] = 37847] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR";
501
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR"] = 37849] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR";
502
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR"] = 37850] = "COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR";
503
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR"] = 37852] = "COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR";
504
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR"] = 37853] = "COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR";
505
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR"] = 37840] = "COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR";
506
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR"] = 37841] = "COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR";
507
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR"] = 37842] = "COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR";
508
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR"] = 37843] = "COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR";
509
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR"] = 37844] = "COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR";
510
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR"] = 37845] = "COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR";
511
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR"] = 37846] = "COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR";
512
- INTERNAL_FORMATS[INTERNAL_FORMATS["COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR"] = 37847] = "COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR";
513
- })(INTERNAL_FORMATS || (INTERNAL_FORMATS = {}));
514
- var INTERNAL_FORMAT_TO_BLOCK_SIZE = (_a$2 = {},
515
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT] = [4, 4],
516
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT] = [4, 4],
517
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT] = [4, 4],
518
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT] = [4, 4],
519
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT] = [4, 4],
520
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = [4, 4],
521
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = [4, 4],
522
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = [4, 4],
523
- _a$2[INTERNAL_FORMATS.COMPRESSED_R11_EAC] = [4, 4],
524
- _a$2[INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC] = [4, 4],
525
- _a$2[INTERNAL_FORMATS.COMPRESSED_RG11_EAC] = [4, 4],
526
- _a$2[INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC] = [4, 4],
527
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2] = [4, 4],
528
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC] = [4, 4],
529
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2] = [4, 4],
530
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = [4, 4],
531
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = [4, 4],
532
- _a$2[INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = [4, 4],
533
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = [4, 4],
534
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = [4, 4],
535
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = [8, 4],
536
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = [8, 4],
537
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL] = [4, 4],
538
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL] = [4, 4],
539
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL] = [4, 4],
540
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL] = [4, 4],
541
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_4x4_KHR] = [4, 4],
542
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x5_KHR] = [5, 5],
543
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x6_KHR] = [6, 6],
544
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x8_KHR] = [8, 8],
545
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x10_KHR] = [10, 10],
546
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x12_KHR] = [12, 12],
547
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x5_KHR] = [10, 5],
548
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x6_KHR] = [10, 6],
549
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x8_KHR] = [10, 8],
550
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x10_KHR] = [12, 10],
551
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x4_KHR] = [5, 4],
552
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x5_KHR] = [6, 5],
553
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x5_KHR] = [8, 5],
554
- _a$2[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x6_KHR] = [8, 6],
555
- _a$2);
556
- var INTERNAL_FORMATS_TO_EXTENSION_NAME = (_b = {},
557
- _b[INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc',
558
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc',
559
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT] = 'WEBGL_compressed_texture_s3tc',
560
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT] = 'WEBGL_compressed_texture_s3tc',
561
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc_srgb',
562
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = 'WEBGL_compressed_texture_s3tc_srgb',
563
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = 'WEBGL_compressed_texture_s3tc_srgb',
564
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = 'WEBGL_compressed_texture_s3tc_srgb',
565
- _b[INTERNAL_FORMATS.COMPRESSED_R11_EAC] = 'WEBGL_compressed_texture_etc',
566
- _b[INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC] = 'WEBGL_compressed_texture_etc',
567
- _b[INTERNAL_FORMATS.COMPRESSED_RG11_EAC] = 'WEBGL_compressed_texture_etc',
568
- _b[INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC] = 'WEBGL_compressed_texture_etc',
569
- _b[INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2] = 'WEBGL_compressed_texture_etc',
570
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC] = 'WEBGL_compressed_texture_etc',
571
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2] = 'WEBGL_compressed_texture_etc',
572
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = 'WEBGL_compressed_texture_etc',
573
- _b[INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = 'WEBGL_compressed_texture_etc',
574
- _b[INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = 'WEBGL_compressed_texture_etc',
575
- _b[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc',
576
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc',
577
- _b[INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc',
578
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = 'WEBGL_compressed_texture_pvrtc',
579
- _b[INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL] = 'WEBGL_compressed_texture_etc1',
580
- _b[INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL] = 'WEBGL_compressed_texture_atc',
581
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL] = 'WEBGL_compressed_texture_atc',
582
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL] = 'WEBGL_compressed_texture_atc',
583
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_4x4_KHR] = 'WEBGL_compressed_texture_astc',
584
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x5_KHR] = 'WEBGL_compressed_texture_astc',
585
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x6_KHR] = 'WEBGL_compressed_texture_astc',
586
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x8_KHR] = 'WEBGL_compressed_texture_astc',
587
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x10_KHR] = 'WEBGL_compressed_texture_astc',
588
- _b[INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x12_KHR] = 'WEBGL_compressed_texture_astc',
589
- _b);
590
-
591
- var CompressedTextureResource = (function () {
592
- function CompressedTextureResource() {
593
- this.levelBuffers = [];
594
- }
595
- CompressedTextureResource.prototype.upload = function (gl) {
596
- var levels = this.levels;
597
- var name = INTERNAL_FORMATS_TO_EXTENSION_NAME[this.internalFormat];
598
- if (!gl[name]) {
599
- gl[name] = true;
600
- if (name === 'WEBGL_compressed_texture_pvrtc') {
601
- gl.getExtension(name) || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
602
- }
603
- else {
604
- gl.getExtension(name);
605
- }
606
- }
607
- for (var i = 0; i < this.levels; ++i) {
608
- var _a = this.levelBuffers[i], levelWidth = _a.levelWidth, levelHeight = _a.levelHeight, levelBuffer = _a.levelBuffer;
609
- gl.compressedTexImage2D(gl.TEXTURE_2D, i, this.internalFormat, levelWidth, levelHeight, 0, levelBuffer);
610
- }
611
- if (levels > 1) {
612
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
613
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
614
- }
615
- else {
616
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
617
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
618
- }
619
- };
620
- return CompressedTextureResource;
621
- }());
622
-
623
- var FILE_HEADER_SIZE = 64;
624
- var KTX_FIELDS = {
625
- FILE_IDENTIFIER: 0,
626
- ENDIANNESS: 12,
627
- GL_TYPE: 16,
628
- GL_TYPE_SIZE: 20,
629
- GL_FORMAT: 24,
630
- GL_INTERNAL_FORMAT: 28,
631
- GL_BASE_INTERNAL_FORMAT: 32,
632
- PIXEL_WIDTH: 36,
633
- PIXEL_HEIGHT: 40,
634
- PIXEL_DEPTH: 44,
635
- NUMBER_OF_ARRAY_ELEMENTS: 48,
636
- NUMBER_OF_FACES: 52,
637
- NUMBER_OF_MIPMAP_LEVELS: 56,
638
- BYTES_OF_KEY_VALUE_DATA: 60
639
- };
640
- var FILE_IDENTIFIER = [0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A];
641
- var ENDIANNESS = 0x04030201;
642
- var KTXTextureResource = (function (_super) {
643
- __extends(KTXTextureResource, _super);
644
- function KTXTextureResource(source, config) {
645
- var _a;
646
- var _this = _super.call(this) || this;
647
- _this.complete = true;
648
- _this.src = config.url;
649
- var dataView = new DataView(source);
650
- if (!validateKTX(dataView)) {
651
- throw new Error('Not a valid KTX Texture');
652
- }
653
- var littleEndian = dataView.getUint32(KTX_FIELDS.ENDIANNESS, true) === ENDIANNESS;
654
- _this.internalFormat = dataView.getUint32(KTX_FIELDS.GL_INTERNAL_FORMAT, littleEndian);
655
- var pixelWidth = _this.formerWidth = dataView.getUint32(KTX_FIELDS.PIXEL_WIDTH, littleEndian);
656
- var pixelHeight = _this.formerHeight = dataView.getUint32(KTX_FIELDS.PIXEL_HEIGHT, littleEndian) || 1;
657
- var size = INTERNAL_FORMAT_TO_BLOCK_SIZE[_this.internalFormat];
658
- _this.width = pixelWidth % size[0] === 0 ? pixelWidth : (pixelWidth + size[0] - (pixelWidth % size[0]));
659
- _this.height = pixelHeight % size[1] === 0 ? pixelHeight : (pixelHeight + size[1] - (pixelHeight % size[1]));
660
- var src = resource.resourcesMap[config.metadata.name].src[config.metadata.key];
661
- var _b = (_a = src === null || src === void 0 ? void 0 : src.size) !== null && _a !== void 0 ? _a : {}, width = _b.width, height = _b.height;
662
- if (width && height) {
663
- _this.naturalWidth = width;
664
- _this.naturalHeight = height;
665
- }
666
- var pixelDepth = dataView.getUint32(KTX_FIELDS.PIXEL_DEPTH, littleEndian) || 1;
667
- var numberOfArrayElements = dataView.getUint32(KTX_FIELDS.NUMBER_OF_ARRAY_ELEMENTS, littleEndian) || 1;
668
- var numberOfFaces = dataView.getUint32(KTX_FIELDS.NUMBER_OF_FACES, littleEndian);
669
- var numberOfMipmapLevels = _this.levels = dataView.getUint32(KTX_FIELDS.NUMBER_OF_MIPMAP_LEVELS, littleEndian);
670
- var bytesOfKeyValueData = dataView.getUint32(KTX_FIELDS.BYTES_OF_KEY_VALUE_DATA, littleEndian);
671
- if (pixelHeight === 0 || pixelDepth !== 1) {
672
- throw new Error('Only 2D textures are supported!');
673
- }
674
- if (numberOfFaces !== 1) {
675
- throw new Error('CubeTextures are not supported!');
676
- }
677
- if (numberOfArrayElements !== 1) {
678
- throw new Error('It does not support array textures!');
679
- }
680
- var mipWidth = pixelWidth;
681
- var mipHeight = pixelHeight;
682
- var imageOffset = FILE_HEADER_SIZE + bytesOfKeyValueData;
683
- for (var mipmapLevel = 0; mipmapLevel < numberOfMipmapLevels; mipmapLevel++) {
684
- var imageSize = dataView.getUint32(imageOffset, littleEndian);
685
- imageOffset += 4;
686
- var size_1 = INTERNAL_FORMAT_TO_BLOCK_SIZE[_this.internalFormat];
687
- var levelWidth = mipWidth % size_1[0] === 0 ? mipWidth : mipWidth + size_1[0] - (mipWidth % size_1[0]);
688
- var levelHeight = mipHeight % size_1[1] === 0 ? mipHeight : mipHeight + size_1[1] - (mipHeight % size_1[1]);
689
- var mip = {
690
- levelID: mipmapLevel,
691
- levelWidth: levelWidth,
692
- levelHeight: levelHeight,
693
- levelBuffer: new Uint8Array(source, imageOffset, imageSize)
694
- };
695
- _this.levelBuffers.push(mip);
696
- imageOffset += imageSize;
697
- imageOffset += 3 - ((imageOffset + 3) % 4);
698
- mipWidth = (mipWidth >> 1) || 1;
699
- mipHeight = (mipHeight >> 1) || 1;
700
- }
701
- return _this;
702
- }
703
- return KTXTextureResource;
704
- }(CompressedTextureResource));
705
- function validateKTX(dataView) {
706
- for (var i = 0; i < FILE_IDENTIFIER.length; i++) {
707
- if (dataView.getUint8(i) !== FILE_IDENTIFIER[i]) {
708
- return false;
709
- }
710
- }
711
- return true;
712
- }
713
-
714
- var KTXLoadStrategy = (function (_super) {
715
- __extends(KTXLoadStrategy, _super);
716
- function KTXLoadStrategy() {
717
- return _super !== null && _super.apply(this, arguments) || this;
718
- }
719
- KTXLoadStrategy.prototype._complete = function (type, data) {
720
- _super.prototype._complete.call(this, type, new KTXTextureResource(data, this.config));
721
- };
722
- return KTXLoadStrategy;
723
- }(XhrLoadStrategy));
724
- var KTXLoadStrategy$1 = KTXLoadStrategy;
725
-
726
- var XhrResponseType = resourceLoader.XhrResponseType;
727
- function addPreProcessResourceHandler(resource, gl) {
728
- resource.addPreProcessResourceHandler(function normalizeResource(resource) {
729
- var _a, _b, _c;
730
- var textures = (_b = (_a = resource.src) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.texture;
731
- if (!textures)
732
- return;
733
- if (!Array.isArray(textures)) {
734
- textures = [textures];
735
- }
736
- var formats = (_c = getSuportCompressedTextureFormats(gl)) !== null && _c !== void 0 ? _c : {};
737
- var target = textures.find(function (texture) { return formats[texture.type]; });
738
- if (target) {
739
- Object.assign(resource.src.image, target);
740
- }
741
- });
742
- }
743
- function addKTXStragetyAndRegister() {
744
- Object.assign(RESOURCE_TYPE_STRATEGY, {
745
- astc: KTXLoadStrategy$1,
746
- etc: KTXLoadStrategy$1,
747
- pvrtc: KTXLoadStrategy$1,
748
- s3tc: KTXLoadStrategy$1,
749
- atc: KTXLoadStrategy$1,
750
- });
751
- KTXLoadStrategy$1.setExtensionXhrType('ktx', XhrResponseType.Buffer);
752
- }
753
-
754
- var GLTexture = glCore.GLTexture;
755
- var GLTextureMixin = {
756
- isCompressed: false,
757
- uploadNotCompressed: GLTexture.prototype.upload,
758
- upload: function (source) {
759
- if (!(source instanceof CompressedTextureResource)) {
760
- return this.uploadNotCompressed(source);
761
- }
762
- this.bind();
763
- var gl = this.gl;
764
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha);
765
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
766
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
767
- this.isCompressed = true;
768
- source.upload(gl);
769
- },
770
- enableMipmap: function () {
771
- if (this.isCompressed) {
772
- return;
773
- }
774
- var gl = this.gl;
775
- this.bind();
776
- this.mipmap = true;
777
- gl.generateMipmap(gl.TEXTURE_2D);
778
- }
779
- };
780
-
781
- var _a$1;
782
- var oldFrom$1 = Symbol();
783
- var TextureMixin = (_a$1 = {},
784
- _a$1[oldFrom$1] = Texture.from,
785
- _a$1.from = function (source) {
786
- if (!(source instanceof CompressedTextureResource)) {
787
- return this[oldFrom$1](source);
788
- }
789
- return new Texture(BaseTexture.from(source));
790
- },
791
- _a$1);
792
-
793
- var _a;
794
- var oldFrom = Symbol();
795
- var BaseTextureMixin = (_a = {},
796
- _a[oldFrom] = BaseTexture.from,
797
- _a.from = function (source, scaleMode, sourceScale) {
798
- if (!(source instanceof CompressedTextureResource)) {
799
- return this[oldFrom](source, scaleMode, sourceScale);
800
- }
801
- var imageUrl = source.src;
802
- var baseTexture = utils.BaseTextureCache[imageUrl];
803
- if (!baseTexture) {
804
- baseTexture = new BaseTexture(source, scaleMode);
805
- baseTexture.imageUrl = imageUrl;
806
- if (sourceScale) {
807
- baseTexture.sourceScale = sourceScale;
808
- }
809
- BaseTexture.addToCache(baseTexture, imageUrl);
810
- }
811
- return baseTexture;
812
- },
813
- _a);
814
-
815
- function registerCompressedTexture(gl) {
816
- addPreProcessResourceHandler(resource, gl);
817
- addKTXStragetyAndRegister();
818
- Object.assign(glCore.GLTexture.prototype, GLTextureMixin);
819
- Object.assign(Texture, TextureMixin);
820
- Object.assign(BaseTexture, BaseTextureMixin);
821
- }
822
-
823
- var RENDERER_TYPE;
824
- (function (RENDERER_TYPE) {
825
- RENDERER_TYPE[RENDERER_TYPE["UNKNOWN"] = 0] = "UNKNOWN";
826
- RENDERER_TYPE[RENDERER_TYPE["WEBGL"] = 1] = "WEBGL";
827
- RENDERER_TYPE[RENDERER_TYPE["CANVAS"] = 2] = "CANVAS";
828
- })(RENDERER_TYPE || (RENDERER_TYPE = {}));
829
- var disableScroll = function (renderer) {
830
- renderer.plugins.interaction.autoPreventDefault = true;
831
- renderer.view.style.touchAction = 'none';
832
- };
833
- var enableScroll = function (renderer) {
834
- renderer.plugins.interaction.autoPreventDefault = false;
835
- renderer.view.style.touchAction = 'auto';
836
- };
837
- var Renderer = (function (_super) {
838
- __extends(Renderer, _super);
839
- function Renderer() {
840
- var _this = _super !== null && _super.apply(this, arguments) || this;
841
- _this.multiApps = [];
842
- return _this;
843
- }
844
- Renderer.prototype.init = function (params) {
845
- var _this = this;
846
- this.params = params;
847
- this.application = this.createApplication(params);
848
- this.containerManager = new ContainerManager$1();
849
- this.rendererManager = new RendererManager$1({
850
- game: this.game,
851
- rendererSystem: this,
852
- });
853
- this.game.canvas = this.application.view;
854
- this.transform = new Transform$1({
855
- system: this,
856
- containerManager: this.containerManager,
857
- });
858
- this.game.on('sceneChanged', function (_a) {
859
- var scene = _a.scene, mode = _a.mode, params = _a.params;
860
- var application;
861
- switch (mode) {
862
- case LOAD_SCENE_MODE.SINGLE:
863
- application = _this.application;
864
- break;
865
- case LOAD_SCENE_MODE.MULTI_CANVAS:
866
- application = _this.createMultiApplication({ params: params });
867
- break;
868
- }
869
- scene.canvas = application.view;
870
- _this.transform.emit('changeScene', {
871
- scene: scene,
872
- mode: mode,
873
- application: application,
874
- });
875
- });
876
- var gl = this.application.renderer.gl;
877
- if (gl) {
878
- this.suportedCompressedTextureFormats = getSuportCompressedTextureFormats(gl);
879
- registerCompressedTexture(gl);
880
- }
881
- };
882
- Renderer.prototype.registerObserver = function (observerInfo) {
883
- var _a;
884
- var thisObserverInfo = this.constructor.observerInfo;
885
- for (var key in observerInfo) {
886
- if (!thisObserverInfo[key]) {
887
- thisObserverInfo[key] = [];
888
- }
889
- (_a = thisObserverInfo[key]).push.apply(_a, __spread(observerInfo[key]));
890
- }
891
- };
892
- Renderer.prototype.createMultiApplication = function (_a) {
893
- var params = _a.params;
894
- var app = this.createApplication(params);
895
- this.multiApps.push(app);
896
- return app;
897
- };
898
- Renderer.prototype.createApplication = function (params) {
899
- params.view = params.canvas;
900
- if (params.renderType === RENDERER_TYPE.CANVAS) {
901
- params.forceCanvas = true;
902
- }
903
- ticker.shared.autoStart = false;
904
- ticker.shared.stop();
905
- var app = new Application$1(__assign({ sharedTicker: true }, params));
906
- if (params.preventScroll !== undefined) {
907
- console.warn('PreventScroll property will deprecate at next major version, please use enableEnable instead. https://eva.js.org/#/tutorials/game');
908
- params.preventScroll ? enableScroll(app.renderer) : disableScroll(app.renderer);
909
- }
910
- if (params.enableScroll !== undefined) {
911
- params.enableScroll ? enableScroll(app.renderer) : disableScroll(app.renderer);
912
- }
913
- if (params.preventScroll === undefined && params.enableScroll === undefined) {
914
- enableScroll(app.renderer);
915
- }
916
- return app;
917
- };
918
- Renderer.prototype.update = function () {
919
- var e_1, _a, e_2, _b;
920
- var changes = this.componentObserver.clear();
921
- try {
922
- for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
923
- var changed = changes_1_1.value;
924
- this.transform.componentChanged(changed);
925
- }
926
- }
927
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
928
- finally {
929
- try {
930
- if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
931
- }
932
- finally { if (e_1) throw e_1.error; }
933
- }
934
- try {
935
- for (var _c = __values(this.game.gameObjects), _d = _c.next(); !_d.done; _d = _c.next()) {
936
- var gameObject = _d.value;
937
- this.containerManager.updateTransform({
938
- name: gameObject.id,
939
- transform: gameObject.transform,
940
- });
941
- this.rendererManager.update(gameObject);
942
- }
943
- }
944
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
945
- finally {
946
- try {
947
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
948
- }
949
- finally { if (e_2) throw e_2.error; }
950
- }
951
- };
952
- Renderer.prototype.lateUpdate = function (e) {
953
- this.transform.update();
954
- this.application.ticker.update(e.time);
955
- };
956
- Renderer.prototype.onDestroy = function () {
957
- var e_3, _a;
958
- this.application.destroy();
959
- try {
960
- for (var _b = __values(this.multiApps), _c = _b.next(); !_c.done; _c = _b.next()) {
961
- var app = _c.value;
962
- app && app.destroy();
963
- }
964
- }
965
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
966
- finally {
967
- try {
968
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
969
- }
970
- finally { if (e_3) throw e_3.error; }
971
- }
972
- this.transform.destroy();
973
- this.transform = null;
974
- this.params = null;
975
- this.rendererManager = null;
976
- this.containerManager = null;
977
- this.application = null;
978
- this.game = null;
979
- this.multiApps = null;
980
- };
981
- Renderer.prototype.resize = function (width, height) {
982
- this.params.width = width;
983
- this.params.height = height;
984
- this.application.renderer.resize(width, height);
985
- };
986
- Renderer.systemName = 'Renderer';
987
- Renderer = __decorate([
988
- decorators.componentObserver({
989
- Transform: ['_parent'],
990
- })
991
- ], Renderer);
992
- return Renderer;
993
- }(System));
994
- var RendererSystem = Renderer;
995
-
996
- var mixinPIXI = function () {
997
- BaseTexture.prototype.destroy = function () {
998
- if (this.imageUrl) {
999
- delete utils.TextureCache[this.imageUrl];
1000
- this.imageUrl = null;
1001
- }
1002
- this.source = null;
1003
- this.dispose();
1004
- BaseTexture.removeFromCache(this);
1005
- this.textureCacheIds = null;
1006
- this._destroyed = true;
1007
- };
1008
- };
1009
-
1010
- mixinPIXI();
1011
-
1012
100
  function uuid(len) {
1013
101
  var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
1014
102
  var uuid = [];