@galacean/engine-loader 1.0.0-alpha.6 → 1.0.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.
Files changed (36) hide show
  1. package/dist/main.js +1278 -1637
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +1299 -1658
  4. package/dist/module.js +1280 -1624
  5. package/dist/module.js.map +1 -1
  6. package/package.json +5 -5
  7. package/types/AnimationClipLoader.d.ts +0 -1
  8. package/types/GLTFLoader.d.ts +4 -7
  9. package/types/gltf/GLTFResource.d.ts +11 -7
  10. package/types/gltf/GLTFUtil.d.ts +8 -8
  11. package/types/gltf/extensions/KHR_materials_variants.d.ts +1 -6
  12. package/types/gltf/extensions/index.d.ts +2 -5
  13. package/types/index.d.ts +2 -2
  14. package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
  15. package/types/GLTFContentRestorer.d.ts +0 -85
  16. package/types/Texture2DContentRestorer.d.ts +0 -14
  17. package/types/TextureCubeContentRestorer.d.ts +0 -14
  18. package/types/gltf/GLTFPipeline.d.ts +0 -23
  19. package/types/gltf/GLTFSchema.d.ts +0 -816
  20. package/types/gltf/extensions/GLTFExtensionParser.d.ts +0 -52
  21. package/types/gltf/extensions/GLTFExtensionSchema.d.ts +0 -149
  22. package/types/gltf/extensions/OASIS_animation_event.d.ts +0 -1
  23. package/types/gltf/extensions/OASIS_materials_remap.d.ts +0 -1
  24. package/types/gltf/index.d.ts +0 -6
  25. package/types/gltf/parser/GLTFAnimationParser.d.ts +0 -12
  26. package/types/gltf/parser/GLTFBufferParser.d.ts +0 -7
  27. package/types/gltf/parser/GLTFEntityParser.d.ts +0 -9
  28. package/types/gltf/parser/GLTFMaterialParser.d.ts +0 -15
  29. package/types/gltf/parser/GLTFMeshParser.d.ts +0 -19
  30. package/types/gltf/parser/GLTFParser.d.ts +0 -63
  31. package/types/gltf/parser/GLTFParserContext.d.ts +0 -48
  32. package/types/gltf/parser/GLTFSceneParser.d.ts +0 -11
  33. package/types/gltf/parser/GLTFSkinParser.d.ts +0 -6
  34. package/types/gltf/parser/GLTFTextureParser.d.ts +0 -8
  35. package/types/gltf/parser/GLTFValidator.d.ts +0 -6
  36. package/types/gltf/parser/index.d.ts +0 -11
package/dist/main.js CHANGED
@@ -4,57 +4,40 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var engineCore = require('@galacean/engine-core');
6
6
  var engineMath = require('@galacean/engine-math');
7
- var engineRhiWebgl = require('@galacean/engine-rhi-webgl');
8
7
  var engineDraco = require('@galacean/engine-draco');
8
+ var engineRhiWebgl = require('@galacean/engine-rhi-webgl');
9
9
 
10
- function extends_() {
11
- extends_ = Object.assign || function (target) {
12
- for (var i = 1; i < arguments.length; i++) {
13
- var source = arguments[i];
14
-
15
- for (var key in source) {
16
- if (Object.prototype.hasOwnProperty.call(source, key)) {
17
- target[key] = source[key];
10
+ function _extends() {
11
+ _extends = Object.assign || function assign(target) {
12
+ for (var i = 1; i < arguments.length; i++) {
13
+ var source = arguments[i];
14
+ for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
18
15
  }
19
- }
20
- }
21
-
22
- return target;
23
- };
24
16
 
25
- return extends_.apply(this, arguments);
26
- }
17
+ return target;
18
+ };
27
19
 
28
- function _extends() {
29
- return extends_.apply(this, arguments);
20
+ return _extends.apply(this, arguments);
30
21
  }
31
22
 
32
- function setPrototypeOf(o, p) {
33
- setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(o, p) {
34
- o.__proto__ = p;
35
- return o;
36
- };
23
+ function _set_prototype_of(o, p) {
24
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
25
+ o.__proto__ = p;
37
26
 
38
- return setPrototypeOf(o, p);
39
- }
27
+ return o;
28
+ };
40
29
 
41
- function _setPrototypeOf(o, p) {
42
- return setPrototypeOf(o, p);
30
+ return _set_prototype_of(o, p);
43
31
  }
44
32
 
45
33
  function _inherits(subClass, superClass) {
46
- if (typeof superClass !== "function" && superClass !== null) {
47
- throw new TypeError("Super expression must either be null or a function");
48
- }
49
-
50
- subClass.prototype = Object.create(superClass && superClass.prototype, {
51
- constructor: {
52
- value: subClass,
53
- writable: true,
54
- configurable: true
34
+ if (typeof superClass !== "function" && superClass !== null) {
35
+ throw new TypeError("Super expression must either be null or a function");
55
36
  }
56
- });
57
- if (superClass) _setPrototypeOf(subClass, superClass);
37
+
38
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
39
+
40
+ if (superClass) _set_prototype_of(subClass, superClass);
58
41
  }
59
42
 
60
43
  /******************************************************************************
@@ -107,10 +90,10 @@ function __generator(thisArg, body) {
107
90
  }
108
91
  }
109
92
 
110
- var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
111
- _inherits(AnimatorControllerLoader, Loader1);
93
+ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
94
+ _inherits(AnimatorControllerLoader, Loader);
112
95
  function AnimatorControllerLoader() {
113
- return Loader1.apply(this, arguments);
96
+ return Loader.apply(this, arguments);
114
97
  }
115
98
  var _proto = AnimatorControllerLoader.prototype;
116
99
  _proto.load = function load(item, resourceManager) {
@@ -131,16 +114,13 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
131
114
  var states = stateMachineData.states;
132
115
  var stateMachine = layer.stateMachine = new engineCore.AnimatorStateMachine();
133
116
  states.forEach(function(stateData, stateIndex) {
134
- var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip, scripts = stateData.scripts;
117
+ var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
135
118
  var state = stateMachine.addState(name);
136
119
  isDefaultState && (stateMachine.defaultState = state);
137
120
  state.speed = speed;
138
121
  state.wrapMode = wrapMode;
139
122
  state.clipStartTime = clipStartNormalizedTime;
140
123
  state.clipEndTime = clipEndNormalizedTime;
141
- scripts == null ? void 0 : scripts.forEach(function(script) {
142
- state.addStateMachineScript(engineCore.Loader.getClass(script));
143
- });
144
124
  if (clipData) {
145
125
  promises.push(new Promise(function(resolve) {
146
126
  //@ts-ignore
@@ -273,39 +253,34 @@ EnvLoader = __decorate([
273
253
  ], EnvLoader);
274
254
 
275
255
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
276
- try {
277
- var info = gen[key](arg);
278
- var value = info.value;
279
- } catch (error) {
280
- reject(error);
281
- return;
282
- }
283
-
284
- if (info.done) {
285
- resolve(value);
286
- } else {
287
- Promise.resolve(value).then(_next, _throw);
288
- }
256
+ try {
257
+ var info = gen[key](arg);
258
+ var value = info.value;
259
+ } catch (error) {
260
+ reject(error);
261
+ return;
262
+ }
263
+ if (info.done) resolve(value);
264
+ else Promise.resolve(value).then(_next, _throw);
289
265
  }
266
+ function _async_to_generator(fn) {
267
+ return function() {
268
+ var self = this, args = arguments;
290
269
 
291
- function _asyncToGenerator(fn) {
292
- return function () {
293
- var self = this,
294
- args = arguments;
295
- return new Promise(function (resolve, reject) {
296
- var gen = fn.apply(self, args);
270
+ return new Promise(function(resolve, reject) {
271
+ var gen = fn.apply(self, args);
297
272
 
298
- function _next(value) {
299
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
300
- }
273
+ function _next(value) {
274
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
275
+ }
301
276
 
302
- function _throw(err) {
303
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
304
- }
277
+ function _throw(err) {
278
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
279
+ }
305
280
 
306
- _next(undefined);
307
- });
308
- };
281
+ _next(undefined);
282
+ });
283
+ };
309
284
  }
310
285
 
311
286
  var FontLoader = /*#__PURE__*/ function(Loader) {
@@ -338,7 +313,7 @@ var FontLoader = /*#__PURE__*/ function(Loader) {
338
313
  });
339
314
  };
340
315
  _proto._registerFont = function _registerFont(fontName, fontUrl) {
341
- return _asyncToGenerator(function() {
316
+ return _async_to_generator(function() {
342
317
  var fontFace;
343
318
  return __generator(this, function(_state) {
344
319
  switch(_state.label){
@@ -366,192 +341,52 @@ FontLoader = __decorate([
366
341
  ], false)
367
342
  ], FontLoader);
368
343
 
369
- function _arrayLikeToArray(arr, len) {
370
- if (len == null || len > arr.length) len = arr.length;
371
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
372
- return arr2;
373
- }
374
-
375
- function _unsupportedIterableToArray(o, minLen) {
376
- if (!o) return;
377
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
378
- var n = Object.prototype.toString.call(o).slice(8, -1);
379
- if (n === "Object" && o.constructor) n = o.constructor.name;
380
- if (n === "Map" || n === "Set") return Array.from(n);
381
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
382
- return _arrayLikeToArray(o, minLen);
383
- }
384
-
385
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
386
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
387
- if (it) return (it = it.call(o)).next.bind(it);
388
- // Fallback for engines without symbol support
389
- if (
390
- Array.isArray(o) ||
391
- (it = _unsupportedIterableToArray(o)) ||
392
- (allowArrayLike && o && typeof o.length === "number")
393
- ) {
394
- if (it) o = it;
395
- var i = 0;
396
- return function () {
397
- if (i >= o.length) return { done: true };
398
- return { done: false, value: o[i++] };
399
- }
400
- }
401
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
402
- }
403
-
404
344
  /**
405
345
  * @internal
406
- */ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
407
- _inherits(GLTFContentRestorer, ContentRestorer);
408
- function GLTFContentRestorer() {
409
- var _this;
410
- _this = ContentRestorer.apply(this, arguments) || this;
411
- _this.bufferRequests = [];
412
- _this.glbBufferSlices = [];
413
- _this.bufferTextures = [];
414
- _this.meshes = [];
415
- return _this;
346
+ */ var ParserContext = /*#__PURE__*/ function() {
347
+ function ParserContext(url) {
348
+ this.hasSkinned = false;
349
+ /** chain asset promise */ this.chainPromises = [];
350
+ this.accessorBufferCache = {};
351
+ this.texturesPromiseInfo = new PromiseInfo();
352
+ this.materialsPromiseInfo = new PromiseInfo();
353
+ this.meshesPromiseInfo = new PromiseInfo();
354
+ this.animationClipsPromiseInfo = new PromiseInfo();
355
+ this.defaultSceneRootPromiseInfo = new PromiseInfo();
356
+ this.masterPromiseInfo = new PromiseInfo();
357
+ this.promiseMap = {};
358
+ var promiseMap = this.promiseMap;
359
+ promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
360
+ promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
361
+ promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
362
+ promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
363
+ promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
364
+ promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
416
365
  }
417
- var _proto = GLTFContentRestorer.prototype;
418
- /**
419
- * @override
420
- */ _proto.restoreContent = function restoreContent() {
421
- var _this = this;
422
- return new engineCore.AssetPromise(function(resolve, reject) {
423
- Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
424
- return engineCore.request(bufferRequestInfo.url, bufferRequestInfo.config);
425
- })).then(function(buffers) {
426
- // Buffer parse
427
- if (_this.isGLB) {
428
- var glbBufferSlice = _this.glbBufferSlices;
429
- var bigBuffer = buffers[0];
430
- var bufferCount = glbBufferSlice.length;
431
- buffers.length = bufferCount;
432
- for(var i = 0; i < bufferCount; i++){
433
- var slice = glbBufferSlice[i];
434
- buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
435
- }
436
- }
437
- // Restore texture
438
- engineCore.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
439
- var bufferView = textureRestoreInfo.bufferView;
440
- var buffer = buffers[bufferView.buffer];
441
- var _bufferView_byteOffset;
442
- var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
443
- return GLTFUtil.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
444
- textureRestoreInfo.texture.setImageSource(image);
445
- textureRestoreInfo.texture.generateMipmaps();
446
- });
447
- })).then(function() {
448
- // Restore mesh
449
- for(var _iterator = _createForOfIteratorHelperLoose(_this.meshes), _step; !(_step = _iterator()).done;){
450
- var meshInfo = _step.value;
451
- var mesh = meshInfo.mesh;
452
- for(var _iterator1 = _createForOfIteratorHelperLoose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
453
- var bufferRestoreInfo = _step1.value;
454
- var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
455
- bufferRestoreInfo.buffer.setData(vertexData);
456
- }
457
- if (meshInfo.indexBuffer) {
458
- var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
459
- mesh.setIndices(indexData);
460
- }
461
- for(var _iterator2 = _createForOfIteratorHelperLoose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
462
- var restoreInfo = _step2.value;
463
- var frame = restoreInfo.blendShape.frames[0];
464
- var positionData = _this._getBufferData(buffers, restoreInfo.position);
465
- frame.deltaPositions = GLTFUtil.floatBufferToVector3Array(positionData);
466
- if (restoreInfo.normal) {
467
- var normalData = _this._getBufferData(buffers, restoreInfo.normal);
468
- frame.deltaNormals = GLTFUtil.floatBufferToVector3Array(normalData);
469
- }
470
- if (restoreInfo.tangent) {
471
- var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
472
- frame.deltaTangents = GLTFUtil.floatBufferToVector3Array(tangentData);
473
- }
474
- }
475
- mesh.uploadData(true);
476
- }
477
- resolve(_this.resource);
478
- }).catch(reject);
479
- }).catch(reject);
366
+ var _proto = ParserContext.prototype;
367
+ _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
368
+ var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
369
+ promiseInfo.resolve = resolve;
370
+ promiseInfo.reject = reject;
371
+ promiseInfo.setProgress = setProgress;
372
+ promiseInfo.onCancel = onCancel;
480
373
  });
374
+ promiseInfo.promise = promise;
375
+ return promise;
481
376
  };
482
- _proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
483
- var main = restoreInfo.main;
484
- var buffer = buffers[main.bufferIndex];
485
- var data = new main.TypedArray(buffer, main.byteOffset, main.length);
486
- var sparseCount = restoreInfo.sparseCount;
487
- if (sparseCount) {
488
- var sparseIndex = restoreInfo.sparseIndices;
489
- var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
490
- var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
491
- var sparseValue = restoreInfo.sparseValues;
492
- var sparseValueBuffer = buffers[sparseValue.bufferIndex];
493
- var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
494
- var typeSize = restoreInfo.typeSize;
495
- for(var i = 0; i < sparseCount; i++){
496
- var replaceIndex = sparseIndexData[i];
497
- for(var j = 0; j < typeSize; j++){
498
- data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
499
- }
500
- }
501
- }
502
- return data;
503
- };
504
- return GLTFContentRestorer;
505
- }(engineCore.ContentRestorer);
506
- /**
507
- * @internal
508
- */ var BufferRequestInfo = function BufferRequestInfo(url, config) {
509
- this.url = url;
510
- this.config = config;
511
- };
512
- /**
513
- * @internal
514
- */ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
515
- this.texture = texture;
516
- this.bufferView = bufferView;
517
- this.mimeType = mimeType;
518
- };
519
- /**
520
- * @internal
521
- */ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
522
- this.vertexBuffers = [];
523
- this.blendShapes = [];
524
- };
377
+ return ParserContext;
378
+ }();
525
379
  /**
526
380
  * @internal
527
- */ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
528
- this.buffer = buffer;
381
+ */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
529
382
  this.data = data;
383
+ this.interleaved = interleaved;
384
+ this.stride = stride;
385
+ this.vertexBindingInfos = {};
530
386
  };
531
387
  /**
532
388
  * @internal
533
- */ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
534
- this.main = main;
535
- this.typeSize = typeSize;
536
- this.sparseCount = sparseCount;
537
- this.sparseIndices = sparseIndices;
538
- this.sparseValues = sparseValues;
539
- };
540
- /**
541
- * @internal
542
- */ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
543
- this.bufferIndex = bufferIndex;
544
- this.TypedArray = TypedArray;
545
- this.byteOffset = byteOffset;
546
- this.length = length;
547
- };
548
- /**
549
- * @internal
550
- */ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
551
- this.blendShape = blendShape;
552
- this.position = position;
553
- this.normal = normal;
554
- this.tangent = tangent;
389
+ */ var PromiseInfo = function PromiseInfo() {
555
390
  };
556
391
 
557
392
  /**
@@ -701,54 +536,6 @@ var TextureWrapMode;
701
536
  */ "REPEAT"] = 10497] = "REPEAT";
702
537
  })(TextureWrapMode || (TextureWrapMode = {}));
703
538
 
704
- /**
705
- * @internal
706
- */ var GLTFParserContext = /*#__PURE__*/ function() {
707
- function GLTFParserContext(url) {
708
- this.hasSkinned = false;
709
- this.chainPromises = [];
710
- this.accessorBufferCache = {};
711
- this.texturesPromiseInfo = new PromiseInfo();
712
- this.materialsPromiseInfo = new PromiseInfo();
713
- this.meshesPromiseInfo = new PromiseInfo();
714
- this.animationClipsPromiseInfo = new PromiseInfo();
715
- this.defaultSceneRootPromiseInfo = new PromiseInfo();
716
- this.masterPromiseInfo = new PromiseInfo();
717
- this.promiseMap = {};
718
- var promiseMap = this.promiseMap;
719
- promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
720
- promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
721
- promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
722
- promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
723
- promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
724
- promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
725
- }
726
- var _proto = GLTFParserContext.prototype;
727
- _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
728
- var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
729
- promiseInfo.resolve = resolve;
730
- promiseInfo.reject = reject;
731
- promiseInfo.setProgress = setProgress;
732
- promiseInfo.onCancel = onCancel;
733
- });
734
- promiseInfo.promise = promise;
735
- return promise;
736
- };
737
- return GLTFParserContext;
738
- }();
739
- /**
740
- * @internal
741
- */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
742
- this.data = data;
743
- this.interleaved = interleaved;
744
- this.stride = stride;
745
- this.vertexBindingInfos = {};
746
- };
747
- /**
748
- * @internal
749
- */ var PromiseInfo = function PromiseInfo() {
750
- };
751
-
752
539
  /**
753
540
  * @internal
754
541
  */ var GLTFUtil = /*#__PURE__*/ function() {
@@ -857,18 +644,18 @@ var TextureWrapMode;
857
644
  throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
858
645
  }
859
646
  };
860
- GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
647
+ GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
861
648
  var buffers = context.buffers;
649
+ var bufferViews = gltf.bufferViews;
862
650
  var componentType = accessor.componentType;
863
651
  var bufferView = bufferViews[accessor.bufferView];
864
- var bufferIndex = bufferView.buffer;
865
- var buffer = buffers[bufferIndex];
652
+ var buffer = buffers[bufferView.buffer];
866
653
  var bufferByteOffset = bufferView.byteOffset || 0;
867
654
  var byteOffset = accessor.byteOffset || 0;
868
655
  var TypedArray = GLTFUtil.getComponentType(componentType);
869
- var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
656
+ var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
870
657
  var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
871
- var elementStride = dataElementSize * dataElementBytes;
658
+ var elementStride = dataElmentSize * dataElementBytes;
872
659
  var accessorCount = accessor.count;
873
660
  var bufferStride = bufferView.byteStride;
874
661
  var bufferInfo;
@@ -883,25 +670,24 @@ var TextureWrapMode;
883
670
  var count = accessorCount * (bufferStride / dataElementBytes);
884
671
  var data = new TypedArray(buffer, offset, count);
885
672
  accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
886
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
887
673
  }
888
674
  } else {
889
675
  var offset1 = bufferByteOffset + byteOffset;
890
- var count1 = accessorCount * dataElementSize;
676
+ var count1 = accessorCount * dataElmentSize;
891
677
  var data1 = new TypedArray(buffer, offset1, count1);
892
678
  bufferInfo = new BufferInfo(data1, false, elementStride);
893
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
894
679
  }
895
680
  if (accessor.sparse) {
896
- GLTFUtil.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
681
+ var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
682
+ bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
897
683
  }
898
684
  return bufferInfo;
899
685
  };
900
686
  /**
901
687
  * @deprecated
902
688
  * Get accessor data.
903
- */ GLTFUtil.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
904
- var bufferViews = glTF.bufferViews;
689
+ */ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
690
+ var bufferViews = gltf.bufferViews;
905
691
  var bufferView = bufferViews[accessor.bufferView];
906
692
  var arrayBuffer = buffers[bufferView.buffer];
907
693
  var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
@@ -951,46 +737,38 @@ var TextureWrapMode;
951
737
  return typedArray;
952
738
  };
953
739
  GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
954
- var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
955
- var arrayBuffer = buffers[bufferView.buffer];
956
- return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
740
+ var buffer = bufferView.buffer, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength;
741
+ var arrayBuffer = buffers[buffer];
742
+ return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
957
743
  };
958
744
  /**
959
745
  * Get accessor data.
960
- */ GLTFUtil.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
961
- var restoreInfo = bufferInfo.restoreInfo;
746
+ */ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
747
+ var bufferViews = gltf.bufferViews;
962
748
  var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
963
749
  var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
964
- var data = bufferInfo.data.slice();
750
+ var data = originData.slice();
965
751
  var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
966
752
  var indicesBufferView = bufferViews[indices.bufferView];
967
753
  var valuesBufferView = bufferViews[values.bufferView];
968
- var indicesBufferIndex = indicesBufferView.buffer;
969
- var valuesBufferIndex = valuesBufferView.buffer;
970
- var indicesArrayBuffer = buffers[indicesBufferIndex];
971
- var valuesArrayBuffer = buffers[valuesBufferIndex];
754
+ var indicesArrayBuffer = buffers[indicesBufferView.buffer];
755
+ var valuesArrayBuffer = buffers[valuesBufferView.buffer];
972
756
  var _indices_byteOffset, _indicesBufferView_byteOffset;
973
757
  var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
974
758
  var indicesByteLength = indicesBufferView.byteLength;
975
759
  var _values_byteOffset, _valuesBufferView_byteOffset;
976
760
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
977
761
  var valuesByteLength = valuesBufferView.byteLength;
978
- restoreInfo.typeSize = accessorTypeSize;
979
- restoreInfo.sparseCount = count;
980
762
  var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
981
- var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
982
- var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
983
- restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
984
- var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
985
- var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
986
- restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
763
+ var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
764
+ var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
987
765
  for(var i = 0; i < count; i++){
988
766
  var replaceIndex = indicesArray[i];
989
767
  for(var j = 0; j < accessorTypeSize; j++){
990
768
  data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
991
769
  }
992
770
  }
993
- bufferInfo.data = data;
771
+ return data;
994
772
  };
995
773
  GLTFUtil.getIndexFormat = function getIndexFormat(type) {
996
774
  switch(type){
@@ -1088,7 +866,7 @@ var TextureWrapMode;
1088
866
  };
1089
867
  /**
1090
868
  * Parse the glb format.
1091
- */ GLTFUtil.parseGLB = function parseGLB(context, glb) {
869
+ */ GLTFUtil.parseGLB = function parseGLB(glb) {
1092
870
  var UINT32_LENGTH = 4;
1093
871
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
1094
872
  var GLB_HEADER_LENGTH = 12;
@@ -1116,11 +894,10 @@ var TextureWrapMode;
1116
894
  return null;
1117
895
  }
1118
896
  var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
1119
- var glTF = JSON.parse(GLTFUtil.decodeText(glTFData));
897
+ var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
1120
898
  // read all buffers
1121
899
  var buffers = [];
1122
900
  var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
1123
- var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
1124
901
  while(byteOffset < header.length){
1125
902
  chunkLength = dataView.getUint32(byteOffset, true);
1126
903
  chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
@@ -1131,11 +908,10 @@ var TextureWrapMode;
1131
908
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
1132
909
  var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
1133
910
  buffers.push(buffer);
1134
- restoreGLBBufferSlice.push(new engineMath.Vector2(currentOffset, chunkLength));
1135
911
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
1136
912
  }
1137
913
  return {
1138
- glTF: glTF,
914
+ gltf: gltf,
1139
915
  buffers: buffers
1140
916
  };
1141
917
  };
@@ -1150,339 +926,630 @@ var TextureWrapMode;
1150
926
  return GLTFUtil;
1151
927
  }();
1152
928
 
1153
- function _arrayWithoutHoles(arr) {
1154
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
929
+ function _array_like_to_array(arr, len) {
930
+ if (len == null || len > arr.length) len = arr.length;
931
+
932
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
933
+
934
+ return arr2;
1155
935
  }
1156
936
 
1157
- function _iterableToArray(iter) {
1158
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
937
+ function _array_without_holes(arr) {
938
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1159
939
  }
1160
940
 
1161
- function _nonIterableSpread() {
1162
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
941
+ function _iterable_to_array(iter) {
942
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
943
+ return Array.from(iter);
944
+ }
1163
945
  }
1164
946
 
1165
- function _toConsumableArray(arr) {
1166
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
947
+ function _non_iterable_spread() {
948
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1167
949
  }
1168
950
 
1169
- /**
1170
- * Base class of glTF extension parser.
1171
- */ var GLTFExtensionParser = /*#__PURE__*/ function() {
1172
- function GLTFExtensionParser() {}
1173
- var _proto = GLTFExtensionParser.prototype;
1174
- /**
1175
- * Initialize the parser.
1176
- * @remarks Some plugins require initialization.
1177
- * @returns The void or promise
1178
- */ _proto.initialize = function initialize() {};
1179
- /**
1180
- * Create and parse the resource.
1181
- * @remarks This method overrides the default resource creation.
1182
- * @param context - The parser context
1183
- * @param extensionSchema - The extension schema
1184
- * @param extensionOwnerSchema - The extension owner schema
1185
- * @returns The resource or promise
1186
- */ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
1187
- for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1188
- extra[_key - 3] = arguments[_key];
1189
- }
1190
- throw "Not implemented.";
1191
- };
1192
- /**
1193
- * Additive parse to the resource.
1194
- * @param context - The parser context
1195
- * @param parseResource - The parsed resource
1196
- * @param extensionSchema - The extension schema
1197
- * @param extensionOwnerSchema - The extension owner schema
1198
- * @returns The void or promise
1199
- */ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
951
+ function _unsupported_iterable_to_array(o, minLen) {
952
+ if (!o) return;
953
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
954
+
955
+ var n = Object.prototype.toString.call(o).slice(8, -1);
956
+
957
+ if (n === "Object" && o.constructor) n = o.constructor.name;
958
+ if (n === "Map" || n === "Set") return Array.from(n);
959
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
960
+ }
961
+
962
+ function _to_consumable_array(arr) {
963
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
964
+ }
965
+
966
+ var Parser = /*#__PURE__*/ function() {
967
+ function Parser() {}
968
+ Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
1200
969
  for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1201
970
  extra[_key - 4] = arguments[_key];
1202
971
  }
1203
- throw "Not implemented.";
1204
- };
1205
- return GLTFExtensionParser;
1206
- }();
1207
- exports.GLTFExtensionMode = void 0;
1208
- (function(GLTFExtensionMode) {
1209
- GLTFExtensionMode[GLTFExtensionMode[/**
1210
- * Cerate instance and parse mode.
1211
- * @remarks
1212
- * If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
1213
- * If this method is registered, the default pipeline processing will be ignored.
1214
- */ "CreateAndParse"] = 0] = "CreateAndParse";
1215
- GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
1216
- })(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
1217
-
1218
- /**
1219
- * Base class of glTF parser.
1220
- */ var GLTFParser = /*#__PURE__*/ function() {
1221
- function GLTFParser() {}
1222
- /**
1223
- * Execute all parses of extension to initialize plugin.
1224
- * @remarks Some plugins require initialization.
1225
- * @returns The void or promise
1226
- */ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
1227
- var parsers = GLTFParser._extensionParsers[extensionName];
1228
- var length = parsers == null ? void 0 : parsers.length;
1229
- if (length) {
1230
- return parsers[length - 1].initialize();
972
+ var parsers = Parser._extensionParsers[extensionName];
973
+ if (parsers == null ? void 0 : parsers.length) {
974
+ for(var i = 0; i < parsers.length; i++){
975
+ var _parsers_i;
976
+ (_parsers_i = parsers[i]).parseEngineResource.apply(_parsers_i, [
977
+ extensionSchema,
978
+ parseResource,
979
+ context
980
+ ].concat(_to_consumable_array(extra)));
981
+ }
1231
982
  }
1232
983
  };
1233
- /**
1234
- * Execute all parses of extension to create resource.
1235
- * @param extensions - Related extensions field
1236
- * @param context - The parser context
1237
- * @param ownerSchema - The extension owner schema
1238
- * @param extra - Extra params
1239
- * @returns
1240
- */ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
1241
- if (extensions === void 0) extensions = {};
984
+ Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
1242
985
  for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1243
986
  extra[_key - 3] = arguments[_key];
1244
987
  }
1245
- var resource = null;
1246
- var extensionArray = Object.keys(extensions);
1247
- for(var i = extensionArray.length - 1; i >= 0; --i){
1248
- var _GLTFParser;
1249
- var extensionName = extensionArray[i];
1250
- var extensionSchema = extensions[extensionName];
1251
- resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
1252
- extensionName,
1253
- context,
988
+ var parsers = Parser._extensionParsers[extensionName];
989
+ if (parsers == null ? void 0 : parsers.length) {
990
+ var _parsers_;
991
+ return (_parsers_ = parsers[0]).createEngineResource.apply(_parsers_, [
1254
992
  extensionSchema,
1255
- ownerSchema
1256
- ].concat(_toConsumableArray(extra)));
1257
- if (resource) {
1258
- return resource;
1259
- }
1260
- }
1261
- };
1262
- /**
1263
- * Execute all parses of extension to parse resource.
1264
- * @param extensions - Related extensions field
1265
- * @param context - The parser context
1266
- * @param parseResource - The parsed resource
1267
- * @param ownerSchema - The extension owner schema
1268
- * @param extra - Extra params
1269
- */ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
1270
- for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1271
- extra[_key - 4] = arguments[_key];
1272
- }
1273
- for(var extensionName in extensions){
1274
- var _GLTFParser;
1275
- var extensionSchema = extensions[extensionName];
1276
- (_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
1277
- extensionName,
1278
- context,
1279
- parseResource,
1280
- extensionSchema,
1281
- ownerSchema
1282
- ].concat(_toConsumableArray(extra)));
993
+ context
994
+ ].concat(_to_consumable_array(extra)));
1283
995
  }
1284
996
  };
1285
- /**
1286
- * Whether the plugin is registered.
1287
- * @param extensionName - Extension name
1288
- * @returns Boolean
1289
- */ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
1290
- var _GLTFParser__extensionParsers_extensionName;
1291
- return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
997
+ Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
998
+ var parsers = Parser._extensionParsers[extensionName];
999
+ return !!(parsers == null ? void 0 : parsers.length);
1292
1000
  };
1293
- /**
1294
- * Get the last plugin by glTF extension mode.
1295
- * @param extensionName - Extension name
1296
- * @param mode - GLTF extension mode
1297
- * @returns GLTF extension parser
1298
- */ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
1299
- var parsers = GLTFParser._extensionParsers[extensionName];
1300
- var length = parsers == null ? void 0 : parsers.length;
1301
- if (length) {
1302
- // only use the last parser.
1303
- for(var i = length - 1; i >= 0; --i){
1304
- var currentParser = parsers[i];
1305
- if (currentParser._mode === mode) {
1306
- return currentParser;
1307
- }
1001
+ Parser.initialize = function initialize(extensionName) {
1002
+ var parsers = Parser._extensionParsers[extensionName];
1003
+ if (parsers == null ? void 0 : parsers.length) {
1004
+ for(var i = 0; i < parsers.length; i++){
1005
+ parsers[i].initialize();
1308
1006
  }
1309
1007
  }
1310
1008
  };
1311
1009
  /**
1312
1010
  * @internal
1313
- */ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1314
- if (!GLTFParser._extensionParsers[extensionName]) {
1315
- GLTFParser._extensionParsers[extensionName] = [];
1316
- }
1317
- GLTFParser._extensionParsers[extensionName].push(extensionParser);
1318
- };
1319
- GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
1320
- for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1321
- extra[_key - 4] = arguments[_key];
1322
- }
1323
- var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
1324
- if (parser) {
1325
- var _parser;
1326
- return (_parser = parser).createAndParse.apply(_parser, [
1327
- context,
1328
- extensionSchema,
1329
- ownerSchema
1330
- ].concat(_toConsumableArray(extra)));
1331
- }
1332
- };
1333
- GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
1334
- for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
1335
- extra[_key - 5] = arguments[_key];
1336
- }
1337
- var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
1338
- if (parser) {
1339
- var _parser;
1340
- (_parser = parser).additiveParse.apply(_parser, [
1341
- context,
1342
- parseResource,
1343
- extensionSchema,
1344
- ownerSchema
1345
- ].concat(_toConsumableArray(extra)));
1011
+ */ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1012
+ if (!Parser._extensionParsers[extensionName]) {
1013
+ Parser._extensionParsers[extensionName] = [];
1346
1014
  }
1015
+ Parser._extensionParsers[extensionName].push(extensionParser);
1347
1016
  };
1348
- return GLTFParser;
1017
+ return Parser;
1349
1018
  }();
1350
- GLTFParser._extensionParsers = {};
1019
+ (function() {
1020
+ Parser._extensionParsers = {};
1021
+ })();
1351
1022
  /**
1352
1023
  * Declare ExtensionParser's decorator.
1353
1024
  * @param extensionName - Extension name
1354
- */ function registerGLTFExtension(extensionName, mode) {
1025
+ */ function registerExtension(extensionName) {
1355
1026
  return function(parser) {
1356
1027
  var extensionParser = new parser();
1357
- extensionParser._mode = mode;
1358
- GLTFParser._addExtensionParser(extensionName, extensionParser);
1028
+ Parser._addExtensionParser(extensionName, extensionParser);
1359
1029
  };
1360
1030
  }
1361
1031
 
1362
- var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1363
- _inherits(GLTFAnimationParser, GLTFParser1);
1364
- function GLTFAnimationParser() {
1365
- return GLTFParser1.apply(this, arguments);
1366
- }
1367
- var _proto = GLTFAnimationParser.prototype;
1368
- _proto.parse = function parse(context) {
1369
- var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
1370
- glTFResource.entities;
1371
- var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
1372
- if (!animations) {
1373
- return;
1032
+ var ExtensionParser = /*#__PURE__*/ function() {
1033
+ function ExtensionParser() {}
1034
+ var _proto = ExtensionParser.prototype;
1035
+ _proto.initialize = function initialize() {};
1036
+ _proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
1037
+ for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1038
+ extra[_key - 3] = arguments[_key];
1374
1039
  }
1375
- var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1376
- var animationClipCount = animations.length;
1377
- var animationClipPromises = [];
1378
- new Array(animationClipCount);
1379
- for(var i = 0; i < animationClipCount; i++){
1380
- var animationInfo = animations[i];
1381
- var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
1382
- var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
1383
- if (!animationClip) {
1384
- animationClip = new engineCore.AnimationClip(name);
1385
- GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
1386
- }
1387
- animationClipPromises.push(animationClip);
1040
+ };
1041
+ _proto.createEngineResource = function createEngineResource(schema, context) {
1042
+ for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
1043
+ extra[_key - 2] = arguments[_key];
1388
1044
  }
1389
- return engineCore.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1390
- glTFResource.animations = animationClips;
1391
- for(var i = 0; i < glTF.animations.length; i++){
1392
- var animationInfo = glTF.animations[i];
1393
- GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
1394
- }
1395
- animationClipsPromiseInfo.resolve(animationClips);
1396
- return animationClipsPromiseInfo.promise;
1397
- });
1045
+ return null;
1398
1046
  };
1399
- /**
1400
- * @internal
1401
- */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
1402
- var glTF = context.glTF, glTFResource = context.glTFResource;
1403
- var entities = glTFResource.entities;
1404
- var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
1405
- var channels = animationInfo.channels, samplers = animationInfo.samplers;
1406
- var sampleDataCollection = new Array();
1407
- // parse samplers
1408
- for(var j = 0, m = samplers.length; j < m; j++){
1409
- var gltfSampler = samplers[j];
1410
- var inputAccessor = accessors[gltfSampler.input];
1411
- var outputAccessor = accessors[gltfSampler.output];
1412
- var input = GLTFUtil.getAccessorBuffer(context, bufferViews, inputAccessor).data;
1413
- var output = GLTFUtil.getAccessorBuffer(context, bufferViews, outputAccessor).data;
1414
- if (outputAccessor.normalized) {
1415
- var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
1416
- var scaled = new Float32Array(output.length);
1417
- for(var k = 0, v = output.length; k < v; k++){
1418
- scaled[k] = output[k] * scale;
1419
- }
1420
- output = scaled;
1421
- }
1422
- var outputStride = output.length / input.length;
1423
- var _gltfSampler_interpolation;
1424
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1425
- var samplerInterpolation = void 0;
1426
- switch(interpolation){
1427
- case AnimationSamplerInterpolation.CubicSpine:
1428
- samplerInterpolation = engineCore.InterpolationType.CubicSpine;
1429
- break;
1430
- case AnimationSamplerInterpolation.Step:
1431
- samplerInterpolation = engineCore.InterpolationType.Step;
1432
- break;
1433
- case AnimationSamplerInterpolation.Linear:
1434
- samplerInterpolation = engineCore.InterpolationType.Linear;
1435
- break;
1436
- }
1437
- input[input.length - 1];
1438
- sampleDataCollection.push({
1439
- type: outputAccessor.type,
1440
- interpolation: samplerInterpolation,
1441
- input: input,
1442
- output: output,
1443
- outputSize: outputStride
1444
- });
1047
+ return ExtensionParser;
1048
+ }();
1049
+
1050
+ var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
1051
+ _inherits(KHR_draco_mesh_compression1, ExtensionParser);
1052
+ function KHR_draco_mesh_compression1() {
1053
+ return ExtensionParser.apply(this, arguments);
1054
+ }
1055
+ var _proto = KHR_draco_mesh_compression1.prototype;
1056
+ _proto.initialize = function initialize() {
1057
+ if (!KHR_draco_mesh_compression._decoder) {
1058
+ KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
1445
1059
  }
1446
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1447
- var gltfChannel = channels[j1];
1448
- var target = gltfChannel.target;
1449
- var channelTargetEntity = entities[target.node];
1450
- var relativePath = "";
1451
- var entity = channelTargetEntity;
1452
- while(entity.parent){
1453
- relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1454
- entity = entity.parent;
1455
- }
1456
- var ComponentType = void 0;
1457
- var propertyName = void 0;
1458
- switch(target.path){
1459
- case AnimationChannelTargetPath.TRANSLATION:
1460
- ComponentType = engineCore.Transform;
1461
- propertyName = "position";
1462
- break;
1463
- case AnimationChannelTargetPath.ROTATION:
1464
- ComponentType = engineCore.Transform;
1465
- propertyName = "rotationQuaternion";
1466
- break;
1467
- case AnimationChannelTargetPath.SCALE:
1468
- ComponentType = engineCore.Transform;
1469
- propertyName = "scale";
1470
- break;
1471
- case AnimationChannelTargetPath.WEIGHTS:
1472
- ComponentType = engineCore.SkinnedMeshRenderer;
1473
- propertyName = "blendShapeWeights";
1474
- break;
1060
+ };
1061
+ _proto.createEngineResource = function createEngineResource(schema, context, gltfPrimitive) {
1062
+ var gltf = context.gltf, buffers = context.buffers;
1063
+ var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
1064
+ var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
1065
+ var attributeMap = {};
1066
+ var attributeTypeMap = {};
1067
+ for(var attributeName in gltfAttributeMap){
1068
+ attributeMap[attributeName] = gltfAttributeMap[attributeName];
1069
+ }
1070
+ for(var attributeName1 in gltfPrimitive.attributes){
1071
+ if (gltfAttributeMap[attributeName1] !== undefined) {
1072
+ var accessorDef = accessors[gltfPrimitive.attributes[attributeName1]];
1073
+ attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
1475
1074
  }
1476
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1477
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1478
1075
  }
1076
+ var indexAccessor = accessors[gltfPrimitive.indices];
1077
+ var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
1078
+ var taskConfig = {
1079
+ attributeIDs: attributeMap,
1080
+ attributeTypes: attributeTypeMap,
1081
+ useUniqueIDs: true,
1082
+ indexType: indexType
1083
+ };
1084
+ var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
1085
+ return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
1086
+ return parsedGeometry;
1087
+ });
1479
1088
  };
1480
- GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
1481
- var sampleData = sampleDataCollection[gltfChannel.sampler];
1482
- var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
1483
- switch(animationChannelTargetPath){
1484
- case AnimationChannelTargetPath.TRANSLATION:
1485
- case AnimationChannelTargetPath.SCALE:
1089
+ return KHR_draco_mesh_compression1;
1090
+ }(ExtensionParser);
1091
+ KHR_draco_mesh_compression = __decorate([
1092
+ registerExtension("KHR_draco_mesh_compression")
1093
+ ], KHR_draco_mesh_compression);
1094
+
1095
+ function _instanceof(left, right) {
1096
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1097
+ return !!right[Symbol.hasInstance](left);
1098
+ } else return left instanceof right;
1099
+ }
1100
+
1101
+ var KHR_lights_punctual = /*#__PURE__*/ function(ExtensionParser) {
1102
+ _inherits(KHR_lights_punctual, ExtensionParser);
1103
+ function KHR_lights_punctual() {
1104
+ return ExtensionParser.apply(this, arguments);
1105
+ }
1106
+ var _proto = KHR_lights_punctual.prototype;
1107
+ _proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
1108
+ var color = schema.color, _schema_intensity = schema.intensity, intensity = _schema_intensity === void 0 ? 1 : _schema_intensity, type = schema.type, range = schema.range, spot = schema.spot;
1109
+ var glTFResource = context.glTFResource;
1110
+ var light;
1111
+ if (type === "directional") {
1112
+ light = entity.addComponent(engineCore.DirectLight);
1113
+ } else if (type === "point") {
1114
+ light = entity.addComponent(engineCore.PointLight);
1115
+ } else if (type === "spot") {
1116
+ light = entity.addComponent(engineCore.SpotLight);
1117
+ }
1118
+ if (color) {
1119
+ light.color.set(color[0], color[1], color[2], 1);
1120
+ }
1121
+ light.intensity = intensity;
1122
+ if (range && !_instanceof(light, engineCore.DirectLight)) {
1123
+ light.distance = range;
1124
+ }
1125
+ if (spot && _instanceof(light, engineCore.SpotLight)) {
1126
+ var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
1127
+ light.angle = innerConeAngle;
1128
+ light.penumbra = outerConeAngle - innerConeAngle;
1129
+ }
1130
+ if (!glTFResource.lights) glTFResource.lights = [];
1131
+ glTFResource.lights.push(light);
1132
+ };
1133
+ return KHR_lights_punctual;
1134
+ }(ExtensionParser);
1135
+ KHR_lights_punctual = __decorate([
1136
+ registerExtension("KHR_lights_punctual")
1137
+ ], KHR_lights_punctual);
1138
+
1139
+ var MaterialParser = /*#__PURE__*/ function(Parser1) {
1140
+ _inherits(MaterialParser, Parser1);
1141
+ function MaterialParser() {
1142
+ return Parser1.apply(this, arguments);
1143
+ }
1144
+ var _proto = MaterialParser.prototype;
1145
+ _proto.parse = function parse(context) {
1146
+ var gltf = context.gltf, glTFResource = context.glTFResource;
1147
+ var engine = glTFResource.engine, textures = glTFResource.textures;
1148
+ if (!gltf.materials) return;
1149
+ var materialsPromiseInfo = context.materialsPromiseInfo;
1150
+ var materials = [];
1151
+ for(var i = 0; i < gltf.materials.length; i++){
1152
+ var _gltf_materials_i = gltf.materials[i], _gltf_materials_i_extensions = _gltf_materials_i.extensions, extensions = _gltf_materials_i_extensions === void 0 ? {} : _gltf_materials_i_extensions, pbrMetallicRoughness = _gltf_materials_i.pbrMetallicRoughness, normalTexture = _gltf_materials_i.normalTexture, occlusionTexture = _gltf_materials_i.occlusionTexture, emissiveTexture = _gltf_materials_i.emissiveTexture, emissiveFactor = _gltf_materials_i.emissiveFactor, alphaMode = _gltf_materials_i.alphaMode, alphaCutoff = _gltf_materials_i.alphaCutoff, doubleSided = _gltf_materials_i.doubleSided, _gltf_materials_i_name = _gltf_materials_i.name, name = _gltf_materials_i_name === void 0 ? "" : _gltf_materials_i_name;
1153
+ var KHR_materials_unlit = extensions.KHR_materials_unlit, KHR_materials_pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness, KHR_materials_clearcoat = extensions.KHR_materials_clearcoat, OASIS_materials_remap = extensions.OASIS_materials_remap;
1154
+ var material = null;
1155
+ if (KHR_materials_unlit) {
1156
+ material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
1157
+ } else if (KHR_materials_pbrSpecularGlossiness) {
1158
+ material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
1159
+ } else {
1160
+ material = new engineCore.PBRMaterial(engine);
1161
+ }
1162
+ material.name = name;
1163
+ if (KHR_materials_clearcoat) {
1164
+ Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
1165
+ }
1166
+ if (pbrMetallicRoughness) {
1167
+ var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1168
+ if (baseColorFactor) {
1169
+ material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
1170
+ }
1171
+ if (baseColorTexture) {
1172
+ material.baseTexture = textures[baseColorTexture.index];
1173
+ MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
1174
+ }
1175
+ if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
1176
+ var m = material;
1177
+ m.metallic = metallicFactor != null ? metallicFactor : 1;
1178
+ m.roughness = roughnessFactor != null ? roughnessFactor : 1;
1179
+ if (metallicRoughnessTexture) {
1180
+ m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1181
+ MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
1182
+ }
1183
+ }
1184
+ }
1185
+ if (!KHR_materials_unlit) {
1186
+ var m1 = material;
1187
+ if (emissiveTexture) {
1188
+ m1.emissiveTexture = textures[emissiveTexture.index];
1189
+ MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
1190
+ }
1191
+ if (emissiveFactor) {
1192
+ m1.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
1193
+ }
1194
+ if (normalTexture) {
1195
+ var index = normalTexture.index, scale = normalTexture.scale;
1196
+ m1.normalTexture = textures[index];
1197
+ MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
1198
+ if (scale !== undefined) {
1199
+ m1.normalTextureIntensity = scale;
1200
+ }
1201
+ }
1202
+ if (occlusionTexture) {
1203
+ var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1204
+ m1.occlusionTexture = textures[index1];
1205
+ MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
1206
+ if (strength !== undefined) {
1207
+ m1.occlusionTextureIntensity = strength;
1208
+ }
1209
+ if (texCoord === engineCore.TextureCoordinate.UV1) {
1210
+ m1.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
1211
+ } else if (texCoord > engineCore.TextureCoordinate.UV1) {
1212
+ engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1213
+ }
1214
+ }
1215
+ }
1216
+ if (OASIS_materials_remap) {
1217
+ var _gltf_extensions;
1218
+ gltf.extensions = (_gltf_extensions = gltf.extensions) != null ? _gltf_extensions : {};
1219
+ var _gltf_extensions_OASIS_materials_remap;
1220
+ gltf.extensions["OASIS_materials_remap"] = (_gltf_extensions_OASIS_materials_remap = gltf.extensions["OASIS_materials_remap"]) != null ? _gltf_extensions_OASIS_materials_remap : {};
1221
+ gltf.extensions["OASIS_materials_remap"][i] = Parser.createEngineResource("OASIS_materials_remap", OASIS_materials_remap, context);
1222
+ }
1223
+ if (doubleSided) {
1224
+ material.renderFace = engineCore.RenderFace.Double;
1225
+ } else {
1226
+ material.renderFace = engineCore.RenderFace.Front;
1227
+ }
1228
+ switch(alphaMode){
1229
+ case MaterialAlphaMode.OPAQUE:
1230
+ material.isTransparent = false;
1231
+ break;
1232
+ case MaterialAlphaMode.BLEND:
1233
+ material.isTransparent = true;
1234
+ break;
1235
+ case MaterialAlphaMode.MASK:
1236
+ material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1237
+ break;
1238
+ }
1239
+ materials[i] = material;
1240
+ }
1241
+ glTFResource.materials = materials;
1242
+ materialsPromiseInfo.resolve(materials);
1243
+ return materialsPromiseInfo.promise;
1244
+ };
1245
+ /** @internal */ MaterialParser._parseTextureTransform = function _parseTextureTransform(material, extensions, context) {
1246
+ if (extensions === void 0) extensions = {};
1247
+ var schema = extensions.KHR_texture_transform;
1248
+ if (schema) {
1249
+ Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
1250
+ }
1251
+ };
1252
+ return MaterialParser;
1253
+ }(Parser);
1254
+
1255
+ var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
1256
+ _inherits(KHR_materials_clearcoat, ExtensionParser);
1257
+ function KHR_materials_clearcoat() {
1258
+ return ExtensionParser.apply(this, arguments);
1259
+ }
1260
+ var _proto = KHR_materials_clearcoat.prototype;
1261
+ _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1262
+ var textures = context.glTFResource.textures;
1263
+ var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
1264
+ material.clearCoat = clearcoatFactor;
1265
+ material.clearCoatRoughness = clearcoatRoughnessFactor;
1266
+ if (clearcoatTexture) {
1267
+ material.clearCoatTexture = textures[clearcoatTexture.index];
1268
+ MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
1269
+ }
1270
+ if (clearcoatRoughnessTexture) {
1271
+ material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
1272
+ MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
1273
+ }
1274
+ if (clearcoatNormalTexture) {
1275
+ material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
1276
+ MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
1277
+ }
1278
+ };
1279
+ return KHR_materials_clearcoat;
1280
+ }(ExtensionParser);
1281
+ KHR_materials_clearcoat = __decorate([
1282
+ registerExtension("KHR_materials_clearcoat")
1283
+ ], KHR_materials_clearcoat);
1284
+
1285
+ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
1286
+ _inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
1287
+ function KHR_materials_pbrSpecularGlossiness() {
1288
+ return ExtensionParser.apply(this, arguments);
1289
+ }
1290
+ var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
1291
+ _proto.createEngineResource = function createEngineResource(schema, context) {
1292
+ var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
1293
+ var material = new engineCore.PBRSpecularMaterial(engine);
1294
+ var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
1295
+ if (diffuseFactor) {
1296
+ material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
1297
+ }
1298
+ if (diffuseTexture) {
1299
+ material.baseTexture = textures[diffuseTexture.index];
1300
+ MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
1301
+ }
1302
+ if (specularFactor) {
1303
+ material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
1304
+ }
1305
+ if (glossinessFactor !== undefined) {
1306
+ material.glossiness = glossinessFactor;
1307
+ }
1308
+ if (specularGlossinessTexture) {
1309
+ material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
1310
+ MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
1311
+ }
1312
+ return material;
1313
+ };
1314
+ return KHR_materials_pbrSpecularGlossiness;
1315
+ }(ExtensionParser);
1316
+ KHR_materials_pbrSpecularGlossiness = __decorate([
1317
+ registerExtension("KHR_materials_pbrSpecularGlossiness")
1318
+ ], KHR_materials_pbrSpecularGlossiness);
1319
+
1320
+ var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
1321
+ _inherits(KHR_materials_unlit, ExtensionParser);
1322
+ function KHR_materials_unlit() {
1323
+ return ExtensionParser.apply(this, arguments);
1324
+ }
1325
+ var _proto = KHR_materials_unlit.prototype;
1326
+ _proto.createEngineResource = function createEngineResource(schema, context) {
1327
+ var engine = context.glTFResource.engine;
1328
+ var material = new engineCore.UnlitMaterial(engine);
1329
+ return material;
1330
+ };
1331
+ return KHR_materials_unlit;
1332
+ }(ExtensionParser);
1333
+ KHR_materials_unlit = __decorate([
1334
+ registerExtension("KHR_materials_unlit")
1335
+ ], KHR_materials_unlit);
1336
+
1337
+ var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
1338
+ _inherits(KHR_materials_variants, ExtensionParser);
1339
+ function KHR_materials_variants() {
1340
+ return ExtensionParser.apply(this, arguments);
1341
+ }
1342
+ var _proto = KHR_materials_variants.prototype;
1343
+ _proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
1344
+ var _context_gltf = context.gltf, _context_gltf_extensions = _context_gltf.extensions, _context_gltf_extensions_KHR_materials_variants = _context_gltf_extensions.KHR_materials_variants, variantNames = _context_gltf_extensions_KHR_materials_variants.variants, glTFResource = context.glTFResource;
1345
+ var mappings = schema.mappings;
1346
+ for(var i = 0; i < mappings.length; i++){
1347
+ var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
1348
+ if (!glTFResource.variants) glTFResource.variants = [];
1349
+ glTFResource.variants.push({
1350
+ renderer: renderer,
1351
+ material: glTFResource.materials[material],
1352
+ variants: variants.map(function(index) {
1353
+ return variantNames[index].name;
1354
+ })
1355
+ });
1356
+ }
1357
+ };
1358
+ return KHR_materials_variants;
1359
+ }(ExtensionParser);
1360
+ KHR_materials_variants = __decorate([
1361
+ registerExtension("KHR_materials_variants")
1362
+ ], KHR_materials_variants);
1363
+
1364
+ var KHR_mesh_quantization = /*#__PURE__*/ function(ExtensionParser) {
1365
+ _inherits(KHR_mesh_quantization, ExtensionParser);
1366
+ function KHR_mesh_quantization() {
1367
+ return ExtensionParser.apply(this, arguments);
1368
+ }
1369
+ return KHR_mesh_quantization;
1370
+ }(ExtensionParser);
1371
+ KHR_mesh_quantization = __decorate([
1372
+ registerExtension("KHR_mesh_quantization")
1373
+ ], KHR_mesh_quantization);
1374
+
1375
+ var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
1376
+ _inherits(KHR_texture_transform, ExtensionParser);
1377
+ function KHR_texture_transform() {
1378
+ return ExtensionParser.apply(this, arguments);
1379
+ }
1380
+ var _proto = KHR_texture_transform.prototype;
1381
+ _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1382
+ var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
1383
+ if (offset) {
1384
+ material.tilingOffset.z = offset[0];
1385
+ material.tilingOffset.w = offset[1];
1386
+ }
1387
+ if (scale) {
1388
+ material.tilingOffset.x = scale[0];
1389
+ material.tilingOffset.y = scale[1];
1390
+ }
1391
+ if (rotation) {
1392
+ engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
1393
+ }
1394
+ if (texCoord) {
1395
+ engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
1396
+ }
1397
+ };
1398
+ return KHR_texture_transform;
1399
+ }(ExtensionParser);
1400
+ KHR_texture_transform = __decorate([
1401
+ registerExtension("KHR_texture_transform")
1402
+ ], KHR_texture_transform);
1403
+
1404
+ var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
1405
+ _inherits(GalaceanMaterialsRemap, ExtensionParser);
1406
+ function GalaceanMaterialsRemap() {
1407
+ return ExtensionParser.apply(this, arguments);
1408
+ }
1409
+ var _proto = GalaceanMaterialsRemap.prototype;
1410
+ _proto.createEngineResource = function createEngineResource(schema, context) {
1411
+ var engine = context.glTFResource.engine;
1412
+ // @ts-ignore
1413
+ return engine.resourceManager.getResourceByRef(schema);
1414
+ };
1415
+ return GalaceanMaterialsRemap;
1416
+ }(ExtensionParser);
1417
+ GalaceanMaterialsRemap = __decorate([
1418
+ registerExtension("OASIS_materials_remap")
1419
+ ], GalaceanMaterialsRemap);
1420
+
1421
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1422
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1423
+
1424
+ if (it) return (it = it.call(o)).next.bind(it);
1425
+ // Fallback for engines without symbol support
1426
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
1427
+ if (it) o = it;
1428
+
1429
+ var i = 0;
1430
+
1431
+ return function() {
1432
+ if (i >= o.length) return { done: true };
1433
+
1434
+ return { done: false, value: o[i++] };
1435
+ };
1436
+ }
1437
+
1438
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1439
+ }
1440
+
1441
+ var AnimationParser = /*#__PURE__*/ function(Parser) {
1442
+ _inherits(AnimationParser, Parser);
1443
+ function AnimationParser() {
1444
+ return Parser.apply(this, arguments);
1445
+ }
1446
+ var _proto = AnimationParser.prototype;
1447
+ _proto.parse = function parse(context) {
1448
+ var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
1449
+ var entities = glTFResource.entities;
1450
+ var animations = gltf.animations, accessors = gltf.accessors;
1451
+ if (!animations) {
1452
+ return;
1453
+ }
1454
+ var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1455
+ var animationClipCount = animations.length;
1456
+ var animationClips = new Array(animationClipCount);
1457
+ var animationsIndices = new Array(animationClipCount);
1458
+ for(var i = 0; i < animationClipCount; i++){
1459
+ var gltfAnimation = animations[i];
1460
+ var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
1461
+ var animationClip = new engineCore.AnimationClip(name);
1462
+ var sampleDataCollection = new Array();
1463
+ // parse samplers
1464
+ for(var j = 0, m = samplers.length; j < m; j++){
1465
+ var gltfSampler = samplers[j];
1466
+ var inputAccessor = accessors[gltfSampler.input];
1467
+ var outputAccessor = accessors[gltfSampler.output];
1468
+ var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
1469
+ var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
1470
+ if (outputAccessor.normalized) {
1471
+ var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
1472
+ var scaled = new Float32Array(output.length);
1473
+ for(var k = 0, v = output.length; k < v; k++){
1474
+ scaled[k] = output[k] * scale;
1475
+ }
1476
+ output = scaled;
1477
+ }
1478
+ var outputStride = output.length / input.length;
1479
+ var _gltfSampler_interpolation;
1480
+ var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1481
+ var samplerInterpolation = void 0;
1482
+ switch(interpolation){
1483
+ case AnimationSamplerInterpolation.CubicSpine:
1484
+ samplerInterpolation = engineCore.InterpolationType.CubicSpine;
1485
+ break;
1486
+ case AnimationSamplerInterpolation.Step:
1487
+ samplerInterpolation = engineCore.InterpolationType.Step;
1488
+ break;
1489
+ case AnimationSamplerInterpolation.Linear:
1490
+ samplerInterpolation = engineCore.InterpolationType.Linear;
1491
+ break;
1492
+ }
1493
+ input[input.length - 1];
1494
+ sampleDataCollection.push({
1495
+ type: outputAccessor.type,
1496
+ interpolation: samplerInterpolation,
1497
+ input: input,
1498
+ output: output,
1499
+ outputSize: outputStride
1500
+ });
1501
+ }
1502
+ for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1503
+ var gltfChannel = channels[j1];
1504
+ var target = gltfChannel.target;
1505
+ var channelTargetEntity = entities[target.node];
1506
+ var relativePath = "";
1507
+ var entity = channelTargetEntity;
1508
+ while(entity.parent){
1509
+ relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1510
+ entity = entity.parent;
1511
+ }
1512
+ var ComponentType = void 0;
1513
+ var propertyName = void 0;
1514
+ switch(target.path){
1515
+ case AnimationChannelTargetPath.TRANSLATION:
1516
+ ComponentType = engineCore.Transform;
1517
+ propertyName = "position";
1518
+ break;
1519
+ case AnimationChannelTargetPath.ROTATION:
1520
+ ComponentType = engineCore.Transform;
1521
+ propertyName = "rotationQuaternion";
1522
+ break;
1523
+ case AnimationChannelTargetPath.SCALE:
1524
+ ComponentType = engineCore.Transform;
1525
+ propertyName = "scale";
1526
+ break;
1527
+ case AnimationChannelTargetPath.WEIGHTS:
1528
+ ComponentType = engineCore.SkinnedMeshRenderer;
1529
+ propertyName = "blendShapeWeights";
1530
+ break;
1531
+ }
1532
+ var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1533
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1534
+ }
1535
+ animationClips[i] = animationClip;
1536
+ animationsIndices[i] = {
1537
+ name: name,
1538
+ index: i
1539
+ };
1540
+ }
1541
+ glTFResource.animations = animationClips;
1542
+ // @ts-ignore for editor
1543
+ glTFResource._animationsIndices = animationsIndices;
1544
+ animationClipsPromiseInfo.resolve(animationClips);
1545
+ return animationClipsPromiseInfo.promise;
1546
+ };
1547
+ _proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
1548
+ var sampleData = sampleDataCollection[gltfChannel.sampler];
1549
+ var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
1550
+ switch(animationchannelTargetPath){
1551
+ case AnimationChannelTargetPath.TRANSLATION:
1552
+ case AnimationChannelTargetPath.SCALE:
1486
1553
  {
1487
1554
  var curve = new engineCore.AnimationVector3Curve();
1488
1555
  var interpolation = curve.interpolation = sampleData.interpolation;
@@ -1545,42 +1612,35 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1545
1612
  }
1546
1613
  }
1547
1614
  };
1548
- return GLTFAnimationParser;
1549
- }(GLTFParser);
1615
+ return AnimationParser;
1616
+ }(Parser);
1550
1617
 
1551
- var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1552
- _inherits(GLTFBufferParser, GLTFParser);
1553
- function GLTFBufferParser() {
1554
- return GLTFParser.apply(this, arguments);
1618
+ var BufferParser = /*#__PURE__*/ function(Parser) {
1619
+ _inherits(BufferParser, Parser);
1620
+ function BufferParser() {
1621
+ return Parser.apply(this, arguments);
1555
1622
  }
1556
- var _proto = GLTFBufferParser.prototype;
1623
+ var _proto = BufferParser.prototype;
1557
1624
  _proto.parse = function parse(context) {
1558
- var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
1625
+ var glTFResource = context.glTFResource;
1559
1626
  var url = glTFResource.url;
1560
- var restoreBufferRequests = contentRestorer.bufferRequests;
1561
- var requestConfig = {
1562
- type: "arraybuffer"
1563
- };
1564
- var isGLB = this._isGLB(url);
1565
- contentRestorer.isGLB = isGLB;
1566
- if (isGLB) {
1567
- return engineCore.request(url, requestConfig).then(function(glb) {
1568
- restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
1569
- return GLTFUtil.parseGLB(context, glb);
1570
- }).then(function(param) {
1571
- var glTF = param.glTF, buffers = param.buffers;
1572
- context.glTF = glTF;
1627
+ if (this._isGLB(url)) {
1628
+ return engineCore.request(url, {
1629
+ type: "arraybuffer"
1630
+ }).then(GLTFUtil.parseGLB).then(function(param) {
1631
+ var gltf = param.gltf, buffers = param.buffers;
1632
+ context.gltf = gltf;
1573
1633
  context.buffers = buffers;
1574
1634
  });
1575
1635
  } else {
1576
1636
  return engineCore.request(url, {
1577
1637
  type: "json"
1578
- }).then(function(glTF) {
1579
- context.glTF = glTF;
1580
- return Promise.all(glTF.buffers.map(function(buffer) {
1581
- var absoluteUrl = GLTFUtil.parseRelativeUrl(url, buffer.uri);
1582
- restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
1583
- return engineCore.request(absoluteUrl, requestConfig);
1638
+ }).then(function(gltf) {
1639
+ context.gltf = gltf;
1640
+ return Promise.all(gltf.buffers.map(function(buffer) {
1641
+ return engineCore.request(GLTFUtil.parseRelativeUrl(url, buffer.uri), {
1642
+ type: "arraybuffer"
1643
+ });
1584
1644
  })).then(function(buffers) {
1585
1645
  context.buffers = buffers;
1586
1646
  });
@@ -1591,24 +1651,24 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1591
1651
  var index = url.lastIndexOf(".");
1592
1652
  return url.substring(index + 1, index + 4) === "glb";
1593
1653
  };
1594
- return GLTFBufferParser;
1595
- }(GLTFParser);
1654
+ return BufferParser;
1655
+ }(Parser);
1596
1656
 
1597
- var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1598
- _inherits(GLTFEntityParser, GLTFParser);
1599
- function GLTFEntityParser() {
1600
- return GLTFParser.apply(this, arguments);
1657
+ var EntityParser = /*#__PURE__*/ function(Parser) {
1658
+ _inherits(EntityParser, Parser);
1659
+ function EntityParser() {
1660
+ return Parser.apply(this, arguments);
1601
1661
  }
1602
- var _proto = GLTFEntityParser.prototype;
1662
+ var _proto = EntityParser.prototype;
1603
1663
  _proto.parse = function parse(context) {
1604
- var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
1664
+ var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
1605
1665
  var engine = glTFResource.engine;
1606
1666
  if (!nodes) return;
1607
1667
  var entities = [];
1608
1668
  for(var i = 0; i < nodes.length; i++){
1609
1669
  var gltfNode = nodes[i];
1610
1670
  var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
1611
- var entity = new engineCore.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
1671
+ var entity = new engineCore.Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
1612
1672
  var transform = entity.transform;
1613
1673
  if (matrix) {
1614
1674
  var localMatrix = transform.localMatrix;
@@ -1632,7 +1692,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1632
1692
  this._createSceneRoots(context, glTFResource);
1633
1693
  };
1634
1694
  _proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
1635
- var nodes = context.glTF.nodes;
1695
+ var nodes = context.gltf.nodes;
1636
1696
  var entities = glTFResource.entities;
1637
1697
  for(var i = 0; i < nodes.length; i++){
1638
1698
  var children = nodes[i].children;
@@ -1646,7 +1706,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1646
1706
  }
1647
1707
  };
1648
1708
  _proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
1649
- var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
1709
+ var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
1650
1710
  var engine = glTFResource.engine, entities = glTFResource.entities;
1651
1711
  if (!scenes) return;
1652
1712
  var sceneRoots = [];
@@ -1666,193 +1726,79 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1666
1726
  glTFResource.sceneRoots = sceneRoots;
1667
1727
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
1668
1728
  };
1669
- return GLTFEntityParser;
1670
- }(GLTFParser);
1671
- /** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
1729
+ return EntityParser;
1730
+ }(Parser);
1731
+ (function() {
1732
+ /** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
1733
+ })();
1672
1734
 
1673
- var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
1674
- _inherits(GLTFMaterialParser, GLTFParser1);
1675
- function GLTFMaterialParser() {
1676
- return GLTFParser1.apply(this, arguments);
1735
+ var MeshParser = /*#__PURE__*/ function(Parser1) {
1736
+ _inherits(MeshParser, Parser1);
1737
+ function MeshParser() {
1738
+ return Parser1.apply(this, arguments);
1677
1739
  }
1678
- var _proto = GLTFMaterialParser.prototype;
1740
+ var _proto = MeshParser.prototype;
1679
1741
  _proto.parse = function parse(context) {
1680
- var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
1681
- if (!glTF.materials) return;
1742
+ var _loop = function(i) {
1743
+ var _loop = function(j) {
1744
+ var gltfPrimitive = gltfMesh.primitives[j];
1745
+ var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
1746
+ var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
1747
+ primitivePromises[j] = new Promise(function(resolve) {
1748
+ var mesh = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
1749
+ if (KHR_draco_mesh_compression) {
1750
+ Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
1751
+ return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1752
+ for(var j = 0; j < decodedGeometry.attributes.length; j++){
1753
+ if (decodedGeometry.attributes[j].name === attributeSemantic) {
1754
+ return decodedGeometry.attributes[j].array;
1755
+ }
1756
+ }
1757
+ return null;
1758
+ }, function(attributeSemantic, shapeIndex) {
1759
+ throw "BlendShape animation is not supported when using draco.";
1760
+ }, function() {
1761
+ return decodedGeometry.index.array;
1762
+ }, context.keepMeshData);
1763
+ }).then(resolve);
1764
+ } else {
1765
+ _this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1766
+ return null;
1767
+ }, function(attributeName, shapeIndex) {
1768
+ var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1769
+ var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1770
+ if (attributeAccessorIdx) {
1771
+ var accessor = gltf.accessors[attributeAccessorIdx];
1772
+ return GLTFUtil.getAccessorData(gltf, accessor, buffers);
1773
+ } else {
1774
+ return null;
1775
+ }
1776
+ }, function() {
1777
+ var indexAccessor = gltf.accessors[gltfPrimitive.indices];
1778
+ return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
1779
+ }, context.keepMeshData).then(resolve);
1780
+ }
1781
+ });
1782
+ };
1783
+ var gltfMesh = gltf.meshes[i];
1784
+ var primitivePromises = [];
1785
+ for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1786
+ meshPromises[i] = Promise.all(primitivePromises);
1787
+ };
1788
+ var _this = this;
1789
+ var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
1682
1790
  var engine = glTFResource.engine;
1683
- var materialPromises = [];
1684
- for(var i = 0; i < glTF.materials.length; i++){
1685
- var materialInfo = glTF.materials[i];
1686
- var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
1687
- if (!material) {
1688
- material = new engineCore.PBRMaterial(engine);
1689
- material.name = materialInfo.name;
1690
- GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
1691
- }
1692
- materialPromises.push(material);
1693
- }
1694
- return engineCore.AssetPromise.all(materialPromises).then(function(materials) {
1695
- glTFResource.materials = materials;
1696
- for(var i = 0; i < glTF.materials.length; i++){
1697
- var materialInfo = glTF.materials[i];
1698
- GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
1699
- }
1700
- materialsPromiseInfo.resolve(materials);
1701
- return materialsPromiseInfo.promise;
1702
- });
1703
- };
1704
- /**
1705
- * @internal
1706
- */ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
1707
- var _texture_extensions;
1708
- if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
1709
- engineCore.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
1710
- }
1711
- };
1712
- /**
1713
- * @internal
1714
- */ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
1715
- var textures = context.glTFResource.textures;
1716
- var pbrMetallicRoughness = materialInfo.pbrMetallicRoughness, normalTexture = materialInfo.normalTexture, occlusionTexture = materialInfo.occlusionTexture, emissiveTexture = materialInfo.emissiveTexture, emissiveFactor = materialInfo.emissiveFactor, alphaMode = materialInfo.alphaMode, alphaCutoff = materialInfo.alphaCutoff, doubleSided = materialInfo.doubleSided;
1717
- if (pbrMetallicRoughness) {
1718
- var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1719
- if (baseColorFactor) {
1720
- material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
1721
- }
1722
- if (baseColorTexture) {
1723
- material.baseTexture = textures[baseColorTexture.index];
1724
- GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
1725
- }
1726
- if (material.constructor === engineCore.PBRMaterial) {
1727
- material.metallic = metallicFactor != null ? metallicFactor : 1;
1728
- material.roughness = roughnessFactor != null ? roughnessFactor : 1;
1729
- if (metallicRoughnessTexture) {
1730
- material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1731
- GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
1732
- }
1733
- }
1734
- }
1735
- if (material.constructor === engineCore.PBRMaterial || material.constructor === engineCore.PBRSpecularMaterial) {
1736
- if (emissiveTexture) {
1737
- material.emissiveTexture = textures[emissiveTexture.index];
1738
- GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
1739
- }
1740
- if (emissiveFactor) {
1741
- material.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
1742
- }
1743
- if (normalTexture) {
1744
- var index = normalTexture.index, scale = normalTexture.scale;
1745
- material.normalTexture = textures[index];
1746
- GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
1747
- if (scale !== undefined) {
1748
- material.normalTextureIntensity = scale;
1749
- }
1750
- }
1751
- if (occlusionTexture) {
1752
- var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1753
- material.occlusionTexture = textures[index1];
1754
- GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
1755
- if (strength !== undefined) {
1756
- material.occlusionTextureIntensity = strength;
1757
- }
1758
- if (texCoord === engineCore.TextureCoordinate.UV1) {
1759
- material.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
1760
- } else if (texCoord > engineCore.TextureCoordinate.UV1) {
1761
- engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1762
- }
1763
- }
1764
- }
1765
- if (doubleSided) {
1766
- material.renderFace = engineCore.RenderFace.Double;
1767
- } else {
1768
- material.renderFace = engineCore.RenderFace.Front;
1769
- }
1770
- switch(alphaMode){
1771
- case MaterialAlphaMode.OPAQUE:
1772
- material.isTransparent = false;
1773
- break;
1774
- case MaterialAlphaMode.BLEND:
1775
- material.isTransparent = true;
1776
- break;
1777
- case MaterialAlphaMode.MASK:
1778
- material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1779
- break;
1780
- }
1781
- };
1782
- return GLTFMaterialParser;
1783
- }(GLTFParser);
1784
-
1785
- function _instanceof(left, right) {
1786
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1787
- return !!right[Symbol.hasInstance](left);
1788
- } else {
1789
- return left instanceof right;
1790
- }
1791
- }
1792
-
1793
- var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1794
- _inherits(GLTFMeshParser, GLTFParser1);
1795
- function GLTFMeshParser() {
1796
- return GLTFParser1.apply(this, arguments);
1797
- }
1798
- var _proto = GLTFMeshParser.prototype;
1799
- _proto.parse = function parse(context) {
1800
- var _loop = function(i) {
1801
- var _loop = function(j) {
1802
- var gltfPrimitive = gltfMesh.primitives[j];
1803
- primitivePromises[j] = new Promise(function(resolve) {
1804
- var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
1805
- if (mesh) {
1806
- if (_instanceof(mesh, engineCore.ModelMesh)) {
1807
- resolve(mesh);
1808
- } else {
1809
- mesh.then(function(mesh) {
1810
- return resolve(mesh);
1811
- });
1812
- }
1813
- } else {
1814
- var mesh1 = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
1815
- var meshRestoreInfo = new ModelMeshRestoreInfo();
1816
- meshRestoreInfo.mesh = mesh1;
1817
- context.contentRestorer.meshes.push(meshRestoreInfo);
1818
- GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
1819
- return null;
1820
- }, function(attributeName, shapeIndex) {
1821
- var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1822
- var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1823
- if (attributeAccessorIdx) {
1824
- var accessor = glTF.accessors[attributeAccessorIdx];
1825
- return GLTFUtil.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
1826
- } else {
1827
- return null;
1828
- }
1829
- }, function() {
1830
- var indexAccessor = glTF.accessors[gltfPrimitive.indices];
1831
- return GLTFUtil.getAccessorData(glTF, indexAccessor, buffers);
1832
- }, context.keepMeshData).then(resolve);
1833
- }
1834
- });
1835
- };
1836
- var gltfMesh = glTF.meshes[i];
1837
- var primitivePromises = [];
1838
- for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1839
- meshPromises[i] = Promise.all(primitivePromises);
1840
- };
1841
- var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
1842
- var engine = glTFResource.engine;
1843
- if (!glTF.meshes) return;
1791
+ if (!gltf.meshes) return;
1844
1792
  var meshesPromiseInfo = context.meshesPromiseInfo;
1845
1793
  var meshPromises = [];
1846
- for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
1794
+ for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
1847
1795
  engineCore.AssetPromise.all(meshPromises).then(function(meshes) {
1848
1796
  glTFResource.meshes = meshes;
1849
1797
  meshesPromiseInfo.resolve(meshes);
1850
1798
  }).catch(meshesPromiseInfo.reject);
1851
1799
  return meshesPromiseInfo.promise;
1852
1800
  };
1853
- /**
1854
- * @internal
1855
- */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1801
+ _proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1856
1802
  var accessors = gltf.accessors;
1857
1803
  context.buffers;
1858
1804
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
@@ -1860,16 +1806,18 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1860
1806
  var vertexElements = new Array();
1861
1807
  var vertexCount;
1862
1808
  var bufferBindIndex = 0;
1809
+ var positions;
1810
+ keepMeshData && (positions = new Array(vertexCount));
1863
1811
  for(var attribute in attributes){
1864
1812
  var accessor = accessors[attributes[attribute]];
1865
- var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf.bufferViews, accessor);
1866
- var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1813
+ var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
1814
+ var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1867
1815
  var attributeCount = accessor.count;
1868
1816
  var vertices = accessorBuffer.data;
1869
1817
  var vertexElement = void 0;
1870
1818
  var meshId = mesh.instanceId;
1871
1819
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1872
- var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
1820
+ var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
1873
1821
  if (accessorBuffer.interleaved) {
1874
1822
  var byteOffset = accessor.byteOffset || 0;
1875
1823
  var stride = accessorBuffer.stride;
@@ -1881,7 +1829,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1881
1829
  vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
1882
1830
  vertexBuffer.setData(vertices);
1883
1831
  accessorBuffer.vertexBuffer = vertexBuffer;
1884
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1885
1832
  }
1886
1833
  mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1887
1834
  vertexBindingInfos[meshId] = bufferBindIndex++;
@@ -1892,7 +1839,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1892
1839
  vertexElement = new engineCore.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
1893
1840
  var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
1894
1841
  vertexBuffer1.setData(vertices);
1895
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1896
1842
  mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1897
1843
  vertexBindingInfos[meshId] = bufferBindIndex++;
1898
1844
  }
@@ -1903,22 +1849,30 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1903
1849
  if (accessor.min && accessor.max) {
1904
1850
  min.copyFromArray(accessor.min);
1905
1851
  max.copyFromArray(accessor.max);
1852
+ if (keepMeshData) {
1853
+ var stride1 = vertices.length / attributeCount;
1854
+ for(var j = 0; j < attributeCount; j++){
1855
+ var offset = j * stride1;
1856
+ positions[j] = new engineMath.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1857
+ }
1858
+ }
1906
1859
  } else {
1907
- var position = GLTFMeshParser._tempVector3;
1860
+ var position = MeshParser._tempVector3;
1908
1861
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1909
1862
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1910
- var stride1 = vertices.length / attributeCount;
1911
- for(var j = 0; j < attributeCount; j++){
1912
- var offset = j * stride1;
1913
- position.copyFromArray(vertices, offset);
1863
+ var stride2 = vertices.length / attributeCount;
1864
+ for(var j1 = 0; j1 < attributeCount; j1++){
1865
+ var offset1 = j1 * stride2;
1866
+ position.copyFromArray(vertices, offset1);
1914
1867
  engineMath.Vector3.min(min, position, min);
1915
1868
  engineMath.Vector3.max(max, position, max);
1869
+ keepMeshData && (positions[j1] = position.clone());
1916
1870
  }
1917
1871
  }
1918
1872
  if (accessor.normalized) {
1919
- var scaleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1920
- min.scale(scaleFactor);
1921
- max.scale(scaleFactor);
1873
+ var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1874
+ min.scale(sacleFactor);
1875
+ max.scale(sacleFactor);
1922
1876
  }
1923
1877
  }
1924
1878
  }
@@ -1926,68 +1880,179 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1926
1880
  // Indices
1927
1881
  if (indices !== undefined) {
1928
1882
  var indexAccessor = gltf.accessors[indices];
1929
- var accessorBuffer1 = GLTFUtil.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
1930
- mesh.setIndices(accessorBuffer1.data);
1883
+ var indexData = getIndexBufferData();
1884
+ mesh.setIndices(indexData);
1931
1885
  mesh.addSubMesh(0, indexAccessor.count, mode);
1932
- meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
1933
1886
  } else {
1934
1887
  mesh.addSubMesh(0, vertexCount, mode);
1935
1888
  }
1936
1889
  // BlendShapes
1937
- targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
1890
+ targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
1938
1891
  mesh.uploadData(!keepMeshData);
1892
+ //@ts-ignore
1893
+ mesh._positions = positions;
1939
1894
  return Promise.resolve(mesh);
1940
1895
  };
1941
- /**
1942
- * @internal
1943
- */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
1896
+ _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
1944
1897
  var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
1945
1898
  for(var i = 0, n = glTFTargets.length; i < n; i++){
1946
1899
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1947
- var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
1948
- var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
1949
- var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
1950
- var deltaPositions = deltaPosBufferInfo.data ? GLTFUtil.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
1951
- var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtil.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
1952
- var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtil.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
1900
+ var deltaPosBuffer = getBlendShapeData("POSITION", i);
1901
+ var deltaNorBuffer = getBlendShapeData("NORMAL", i);
1902
+ var deltaTanBuffer = getBlendShapeData("TANGENT", i);
1903
+ var deltaPositions = deltaPosBuffer ? GLTFUtil.floatBufferToVector3Array(deltaPosBuffer) : null;
1904
+ var deltaNormals = deltaNorBuffer ? GLTFUtil.floatBufferToVector3Array(deltaNorBuffer) : null;
1905
+ var deltaTangents = deltaTanBuffer ? GLTFUtil.floatBufferToVector3Array(deltaTanBuffer) : null;
1953
1906
  var blendShape = new engineCore.BlendShape(name);
1954
1907
  blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
1955
1908
  mesh.addBlendShape(blendShape);
1956
- meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
1957
1909
  }
1958
1910
  };
1959
- return GLTFMeshParser;
1960
- }(GLTFParser);
1961
- GLTFMeshParser._tempVector3 = new engineMath.Vector3();
1911
+ /**
1912
+ * @deprecated
1913
+ */ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1914
+ var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1915
+ var vertexCount;
1916
+ var accessors = gltf.accessors;
1917
+ var accessor = accessors[attributes["POSITION"]];
1918
+ var positionBuffer = getVertexBufferData("POSITION");
1919
+ var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
1920
+ mesh.setPositions(positions);
1921
+ var bounds = mesh.bounds;
1922
+ vertexCount = accessor.count;
1923
+ if (accessor.min && accessor.max) {
1924
+ bounds.min.copyFromArray(accessor.min);
1925
+ bounds.max.copyFromArray(accessor.max);
1926
+ } else {
1927
+ var position = MeshParser._tempVector3;
1928
+ var min = bounds.min, max = bounds.max;
1929
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1930
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1931
+ var stride = positionBuffer.length / vertexCount;
1932
+ for(var j = 0; j < vertexCount; j++){
1933
+ var offset = j * stride;
1934
+ position.copyFromArray(positionBuffer, offset);
1935
+ engineMath.Vector3.min(min, position, min);
1936
+ engineMath.Vector3.max(max, position, max);
1937
+ }
1938
+ }
1939
+ for(var attributeSemantic in attributes){
1940
+ if (attributeSemantic === "POSITION") {
1941
+ continue;
1942
+ }
1943
+ var bufferData = getVertexBufferData(attributeSemantic);
1944
+ switch(attributeSemantic){
1945
+ case "NORMAL":
1946
+ var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
1947
+ mesh.setNormals(normals);
1948
+ break;
1949
+ case "TEXCOORD_0":
1950
+ var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
1951
+ mesh.setUVs(texturecoords, 0);
1952
+ break;
1953
+ case "TEXCOORD_1":
1954
+ var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
1955
+ mesh.setUVs(texturecoords1, 1);
1956
+ break;
1957
+ case "TEXCOORD_2":
1958
+ var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
1959
+ mesh.setUVs(texturecoords2, 2);
1960
+ break;
1961
+ case "TEXCOORD_3":
1962
+ var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
1963
+ mesh.setUVs(texturecoords3, 3);
1964
+ break;
1965
+ case "TEXCOORD_4":
1966
+ var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
1967
+ mesh.setUVs(texturecoords4, 4);
1968
+ break;
1969
+ case "TEXCOORD_5":
1970
+ var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
1971
+ mesh.setUVs(texturecoords5, 5);
1972
+ break;
1973
+ case "TEXCOORD_6":
1974
+ var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
1975
+ mesh.setUVs(texturecoords6, 6);
1976
+ break;
1977
+ case "TEXCOORD_7":
1978
+ var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
1979
+ mesh.setUVs(texturecoords7, 7);
1980
+ break;
1981
+ case "COLOR_0":
1982
+ var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
1983
+ mesh.setColors(colors);
1984
+ break;
1985
+ case "TANGENT":
1986
+ var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
1987
+ mesh.setTangents(tangents);
1988
+ break;
1989
+ case "JOINTS_0":
1990
+ var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
1991
+ mesh.setBoneIndices(joints);
1992
+ break;
1993
+ case "WEIGHTS_0":
1994
+ var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
1995
+ mesh.setBoneWeights(weights);
1996
+ break;
1997
+ }
1998
+ }
1999
+ // Indices
2000
+ if (indices !== undefined) {
2001
+ var indexAccessor = gltf.accessors[indices];
2002
+ var indexData = getIndexBufferData();
2003
+ mesh.setIndices(indexData);
2004
+ mesh.addSubMesh(0, indexAccessor.count, mode);
2005
+ } else {
2006
+ mesh.addSubMesh(0, vertexCount, mode);
2007
+ }
2008
+ // BlendShapes
2009
+ targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
2010
+ mesh.uploadData(!keepMeshData);
2011
+ return Promise.resolve(mesh);
2012
+ };
2013
+ return MeshParser;
2014
+ }(Parser);
2015
+ (function() {
2016
+ MeshParser._tempVector3 = new engineMath.Vector3();
2017
+ })();
1962
2018
 
1963
- var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
1964
- _inherits(GLTFSceneParser, GLTFParser1);
1965
- function GLTFSceneParser() {
1966
- return GLTFParser1.apply(this, arguments);
2019
+ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2020
+ _inherits(SceneParser, Parser1);
2021
+ function SceneParser() {
2022
+ return Parser1.apply(this, arguments);
1967
2023
  }
1968
- var _proto = GLTFSceneParser.prototype;
2024
+ var _proto = SceneParser.prototype;
1969
2025
  _proto.parse = function parse(context) {
1970
- var glTFResource = context.glTFResource, glTF = context.glTF;
2026
+ var glTFResource = context.glTFResource, gltf = context.gltf;
1971
2027
  var entities = glTFResource.entities;
1972
- var nodes = glTF.nodes, cameras = glTF.cameras;
2028
+ var nodes = gltf.nodes, gltfCameras = gltf.cameras;
1973
2029
  if (!nodes) return;
1974
2030
  var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
2031
+ var promises = [];
1975
2032
  for(var i = 0; i < nodes.length; i++){
1976
- var glTFNode = nodes[i];
1977
- var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
2033
+ var gltfNode = nodes[i];
2034
+ var cameraID = gltfNode.camera, meshID = gltfNode.mesh, _gltfNode_extensions = gltfNode.extensions, extensions = _gltfNode_extensions === void 0 ? {} : _gltfNode_extensions;
2035
+ var KHR_lights_punctual = extensions.KHR_lights_punctual;
1978
2036
  var entity = entities[i];
1979
2037
  if (cameraID !== undefined) {
1980
- this._createCamera(glTFResource, cameras[cameraID], entity);
2038
+ this._createCamera(glTFResource, gltfCameras[cameraID], entity);
1981
2039
  }
1982
2040
  if (meshID !== undefined) {
1983
- this._createRenderer(context, glTFNode, entity);
2041
+ promises.push(this._createRenderer(context, gltfNode, entity));
2042
+ }
2043
+ if (KHR_lights_punctual) {
2044
+ var lightIndex = KHR_lights_punctual.light;
2045
+ var lights = gltf.extensions.KHR_lights_punctual.lights;
2046
+ Parser.parseEngineResource("KHR_lights_punctual", lights[lightIndex], entity, context);
1984
2047
  }
1985
- GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
1986
2048
  }
1987
2049
  if (glTFResource.defaultSceneRoot) {
1988
2050
  this._createAnimator(context);
1989
2051
  }
1990
- defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2052
+ gltf.extensions && delete gltf.extensions["OASIS_materials_remap"];
2053
+ engineCore.AssetPromise.all(promises).then(function() {
2054
+ return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2055
+ }).catch(defaultSceneRootPromiseInfo.reject);
1991
2056
  return defaultSceneRootPromiseInfo.promise;
1992
2057
  };
1993
2058
  _proto._createCamera = function _createCamera(context, cameraSchema, entity) {
@@ -2023,16 +2088,8 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2023
2088
  // @todo: use engine camera by default
2024
2089
  camera.enabled = false;
2025
2090
  };
2026
- _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
2027
- var glTFResource = context.glTFResource, glTF = context.glTF;
2028
- var glTFMeshes = glTF.meshes;
2029
- var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2030
- var meshID = glTFNode.mesh, skinID = glTFNode.skin;
2031
- var glTFMesh = glTFMeshes[meshID];
2032
- var glTFMeshPrimitives = glTFMesh.primitives;
2033
- var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
2034
- for(var i = 0; i < glTFMeshPrimitives.length; i++){
2035
- var gltfPrimitive = glTFMeshPrimitives[i];
2091
+ _proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
2092
+ var _loop = function(i) {
2036
2093
  var mesh = meshes[meshID][i];
2037
2094
  var renderer = void 0;
2038
2095
  if (skinID !== undefined || blendShapeWeights) {
@@ -2050,11 +2107,32 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2050
2107
  renderer = entity.addComponent(engineCore.MeshRenderer);
2051
2108
  renderer.mesh = mesh;
2052
2109
  }
2053
- var materialIndex = gltfPrimitive.material;
2054
- var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
2055
- renderer.setMaterial(material);
2056
- GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
2057
- }
2110
+ var materialIndex = gltfMeshPrimitives[i].material;
2111
+ var remapMaterials = gltf.extensions && gltf.extensions["OASIS_materials_remap"];
2112
+ if (remapMaterials && remapMaterials[materialIndex]) {
2113
+ promises.push(remapMaterials[materialIndex].then(function(mtl) {
2114
+ renderer.setMaterial(mtl);
2115
+ }));
2116
+ } else {
2117
+ var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
2118
+ renderer.setMaterial(material);
2119
+ }
2120
+ var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
2121
+ var KHR_materials_variants = extensions.KHR_materials_variants;
2122
+ if (KHR_materials_variants) {
2123
+ Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
2124
+ }
2125
+ };
2126
+ var glTFResource = context.glTFResource, gltf = context.gltf;
2127
+ var gltfMeshes = gltf.meshes;
2128
+ var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2129
+ var meshID = gltfNode.mesh, skinID = gltfNode.skin;
2130
+ var glTFMesh = gltfMeshes[meshID];
2131
+ var gltfMeshPrimitives = glTFMesh.primitives;
2132
+ var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
2133
+ var promises = [];
2134
+ for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
2135
+ return Promise.all(promises);
2058
2136
  };
2059
2137
  _proto._createAnimator = function _createAnimator(context) {
2060
2138
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -2081,25 +2159,25 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2081
2159
  }
2082
2160
  }
2083
2161
  };
2084
- GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2085
- if (!GLTFSceneParser._defaultMaterial) {
2086
- GLTFSceneParser._defaultMaterial = new engineCore.BlinnPhongMaterial(engine);
2162
+ SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2163
+ if (!SceneParser._defaultMaterial) {
2164
+ SceneParser._defaultMaterial = new engineCore.BlinnPhongMaterial(engine);
2087
2165
  }
2088
- return GLTFSceneParser._defaultMaterial;
2166
+ return SceneParser._defaultMaterial;
2089
2167
  };
2090
- return GLTFSceneParser;
2091
- }(GLTFParser);
2168
+ return SceneParser;
2169
+ }(Parser);
2092
2170
 
2093
- var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2094
- _inherits(GLTFSkinParser, GLTFParser);
2095
- function GLTFSkinParser() {
2096
- return GLTFParser.apply(this, arguments);
2171
+ var SkinParser = /*#__PURE__*/ function(Parser) {
2172
+ _inherits(SkinParser, Parser);
2173
+ function SkinParser() {
2174
+ return Parser.apply(this, arguments);
2097
2175
  }
2098
- var _proto = GLTFSkinParser.prototype;
2176
+ var _proto = SkinParser.prototype;
2099
2177
  _proto.parse = function parse(context) {
2100
- var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
2178
+ var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
2101
2179
  var entities = glTFResource.entities;
2102
- var gltfSkins = glTF.skins;
2180
+ var gltfSkins = gltf.skins;
2103
2181
  if (!gltfSkins) return;
2104
2182
  var count = gltfSkins.length;
2105
2183
  var skins = new Array(count);
@@ -2109,8 +2187,8 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2109
2187
  var skin = new engineCore.Skin(name);
2110
2188
  skin.inverseBindMatrices.length = jointCount;
2111
2189
  // parse IBM
2112
- var accessor = glTF.accessors[inverseBindMatrices];
2113
- var buffer = GLTFUtil.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
2190
+ var accessor = gltf.accessors[inverseBindMatrices];
2191
+ var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
2114
2192
  for(var i1 = 0; i1 < jointCount; i1++){
2115
2193
  var inverseBindMatrix = new engineMath.Matrix();
2116
2194
  inverseBindMatrix.copyFromArray(buffer, i1 * 16);
@@ -2145,7 +2223,7 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2145
2223
  };
2146
2224
  _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
2147
2225
  var paths = {};
2148
- for(var _iterator = _createForOfIteratorHelperLoose(joints), _step; !(_step = _iterator()).done;){
2226
+ for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
2149
2227
  var index = _step.value;
2150
2228
  var path = new Array();
2151
2229
  var entity = entities[index];
@@ -2171,24 +2249,24 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2171
2249
  rootNode = entity1;
2172
2250
  }
2173
2251
  };
2174
- return GLTFSkinParser;
2175
- }(GLTFParser);
2252
+ return SkinParser;
2253
+ }(Parser);
2176
2254
 
2177
- var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2178
- _inherits(GLTFTextureParser, GLTFParser);
2179
- function GLTFTextureParser() {
2180
- return GLTFParser.apply(this, arguments);
2255
+ var TextureParser = /*#__PURE__*/ function(Parser) {
2256
+ _inherits(TextureParser, Parser);
2257
+ function TextureParser() {
2258
+ return Parser.apply(this, arguments);
2181
2259
  }
2182
- var _proto = GLTFTextureParser.prototype;
2260
+ var _proto = TextureParser.prototype;
2183
2261
  _proto.parse = function parse(context) {
2184
2262
  var _this = this;
2185
- var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
2263
+ var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
2186
2264
  var engine = glTFResource.engine, url = glTFResource.url;
2187
- if (glTF.textures) {
2265
+ if (gltf.textures) {
2188
2266
  var texturesPromiseInfo = context.texturesPromiseInfo;
2189
- engineCore.AssetPromise.all(glTF.textures.map(function(param, index) {
2267
+ engineCore.AssetPromise.all(gltf.textures.map(function(param, index) {
2190
2268
  var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
2191
- var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
2269
+ var _gltf_images_source = gltf.images[source], uri = _gltf_images_source.uri, bufferViewIndex = _gltf_images_source.bufferView, mimeType = _gltf_images_source.mimeType, imageName = _gltf_images_source.name;
2192
2270
  if (uri) {
2193
2271
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
2194
2272
  var index1 = uri.lastIndexOf(".");
@@ -2202,24 +2280,21 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2202
2280
  texture.name = textureName || imageName || "texture_" + index1;
2203
2281
  }
2204
2282
  if (sampler !== undefined) {
2205
- _this._parseSampler(texture, glTF.samplers[sampler]);
2283
+ _this._parseSampler(texture, gltf.samplers[sampler]);
2206
2284
  }
2207
2285
  return texture;
2208
2286
  });
2209
2287
  } else {
2210
- var bufferView = glTF.bufferViews[bufferViewIndex];
2211
- var buffer = buffers[bufferView.buffer];
2212
- var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2213
- return GLTFUtil.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2288
+ var bufferView = gltf.bufferViews[bufferViewIndex];
2289
+ var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
2290
+ return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
2214
2291
  var texture = new engineCore.Texture2D(engine, image.width, image.height);
2215
2292
  texture.setImageSource(image);
2216
2293
  texture.generateMipmaps();
2217
2294
  texture.name = textureName || imageName || "texture_" + index;
2218
2295
  if (sampler !== undefined) {
2219
- _this._parseSampler(texture, glTF.samplers[sampler]);
2296
+ _this._parseSampler(texture, gltf.samplers[sampler]);
2220
2297
  }
2221
- var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2222
- context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2223
2298
  return texture;
2224
2299
  });
2225
2300
  }
@@ -2242,36 +2317,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2242
2317
  }
2243
2318
  }
2244
2319
  if (wrapS) {
2245
- texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2320
+ texture.wrapModeU = TextureParser._wrapMap[wrapS];
2246
2321
  }
2247
2322
  if (wrapT) {
2248
- texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2323
+ texture.wrapModeV = TextureParser._wrapMap[wrapT];
2249
2324
  }
2250
2325
  };
2251
- return GLTFTextureParser;
2252
- }(GLTFParser);
2253
- var _obj;
2254
- GLTFTextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = engineCore.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = engineCore.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = engineCore.TextureWrapMode.Repeat, _obj);
2326
+ return TextureParser;
2327
+ }(Parser);
2328
+ (function() {
2329
+ var _obj;
2330
+ TextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = engineCore.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = engineCore.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = engineCore.TextureWrapMode.Repeat, _obj);
2331
+ })();
2255
2332
 
2256
- var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2257
- _inherits(GLTFValidator, GLTFParser1);
2258
- function GLTFValidator() {
2259
- return GLTFParser1.apply(this, arguments);
2333
+ var Validator = /*#__PURE__*/ function(Parser1) {
2334
+ _inherits(Validator, Parser1);
2335
+ function Validator() {
2336
+ return Parser1.apply(this, arguments);
2260
2337
  }
2261
- var _proto = GLTFValidator.prototype;
2338
+ var _proto = Validator.prototype;
2262
2339
  _proto.parse = function parse(context) {
2263
- var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
2264
- var glTFVersion = Number(version);
2265
- if (!(glTFVersion >= 2 && glTFVersion < 3)) {
2266
- throw "Only support glTF 2.x.";
2340
+ var _context_gltf = context.gltf, version = _context_gltf.asset.version, extensionsUsed = _context_gltf.extensionsUsed, extensionsRequired = _context_gltf.extensionsRequired;
2341
+ var gltfVersion = Number(version);
2342
+ if (!(gltfVersion >= 2 && gltfVersion < 3)) {
2343
+ throw "Only support gltf 2.x.";
2267
2344
  }
2268
- var promises = [];
2269
2345
  if (extensionsUsed) {
2270
2346
  engineCore.Logger.info("extensionsUsed: ", extensionsUsed);
2271
2347
  for(var i = 0; i < extensionsUsed.length; i++){
2272
- var extensionUsed = extensionsUsed[i];
2273
- if (!GLTFParser.hasExtensionParser(extensionUsed)) {
2274
- engineCore.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
2348
+ if (!Parser.hasExtensionParser(extensionsUsed[i])) {
2349
+ engineCore.Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
2275
2350
  }
2276
2351
  }
2277
2352
  }
@@ -2279,66 +2354,68 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2279
2354
  engineCore.Logger.info("extensionsRequired: " + extensionsRequired);
2280
2355
  for(var i1 = 0; i1 < extensionsRequired.length; i1++){
2281
2356
  var extensionRequired = extensionsRequired[i1];
2282
- if (!GLTFParser.hasExtensionParser(extensionRequired)) {
2357
+ if (!Parser.hasExtensionParser(extensionRequired)) {
2283
2358
  engineCore.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
2284
2359
  } else {
2285
- promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
2360
+ Parser.initialize(extensionRequired);
2286
2361
  }
2287
2362
  }
2288
2363
  }
2289
- return engineCore.AssetPromise.all(promises).then(null);
2290
2364
  };
2291
- return GLTFValidator;
2292
- }(GLTFParser);
2365
+ return Validator;
2366
+ }(Parser);
2293
2367
 
2294
- /**
2295
- * GLTF pipeline.
2296
- */ var GLTFPipeline = /*#__PURE__*/ function() {
2297
- function GLTFPipeline() {
2298
- for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
2299
- parsers[_key] = arguments[_key];
2300
- }
2368
+ var GLTFParser = /*#__PURE__*/ function() {
2369
+ function GLTFParser(pipes) {
2301
2370
  var _this = this;
2302
- this._parsers = [];
2303
- parsers.forEach(function(pipe, index) {
2304
- _this._parsers[index] = new pipe();
2371
+ this._pipes = [];
2372
+ pipes.forEach(function(pipe, index) {
2373
+ _this._pipes[index] = new pipe();
2305
2374
  });
2306
2375
  }
2307
- var _proto = GLTFPipeline.prototype;
2308
- /**
2309
- * @internal
2310
- */ _proto._parse = function _parse(context) {
2376
+ var _proto = GLTFParser.prototype;
2377
+ _proto.parse = function parse(context) {
2311
2378
  var _this = this;
2312
2379
  var glTFResource = context.glTFResource;
2313
- var lastParser;
2380
+ var lastPipe;
2314
2381
  return new engineCore.AssetPromise(function(resolve, reject) {
2315
- _this._parsers.forEach(function(parser) {
2316
- if (lastParser) {
2317
- lastParser = lastParser.then(function() {
2382
+ _this._pipes.forEach(function(parser) {
2383
+ if (lastPipe) {
2384
+ lastPipe = lastPipe.then(function() {
2318
2385
  return parser.parse(context);
2319
2386
  });
2320
- if (lastParser.cancel) {
2321
- context.chainPromises.push(lastParser);
2387
+ if (lastPipe.cancel) {
2388
+ context.chainPromises.push(lastPipe);
2322
2389
  }
2323
2390
  } else {
2324
- lastParser = parser.parse(context);
2391
+ lastPipe = parser.parse(context);
2325
2392
  }
2326
2393
  });
2327
- if (lastParser) {
2328
- lastParser.then(function() {
2394
+ if (lastPipe) {
2395
+ lastPipe.then(function() {
2329
2396
  resolve(glTFResource);
2330
2397
  }).catch(reject);
2331
2398
  }
2332
2399
  });
2333
2400
  };
2334
- return GLTFPipeline;
2401
+ return GLTFParser;
2335
2402
  }();
2336
- /**
2337
- * Default pipeline.
2338
- */ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
2403
+ (function() {
2404
+ GLTFParser.defaultPipeline = new GLTFParser([
2405
+ BufferParser,
2406
+ Validator,
2407
+ TextureParser,
2408
+ MaterialParser,
2409
+ MeshParser,
2410
+ EntityParser,
2411
+ SkinParser,
2412
+ AnimationParser,
2413
+ SceneParser$1
2414
+ ]);
2415
+ })();
2339
2416
 
2340
2417
  /**
2341
- * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
2418
+ * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
2342
2419
  */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
2343
2420
  _inherits(GLTFResource, EngineObject);
2344
2421
  function GLTFResource(engine, url) {
@@ -2350,8 +2427,11 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2350
2427
  var _proto = GLTFResource.prototype;
2351
2428
  /**
2352
2429
  * @override
2353
- */ _proto._onDestroy = function _onDestroy() {
2354
- EngineObject.prototype._onDestroy.call(this);
2430
+ */ _proto.destroy = function destroy() {
2431
+ if (this._destroyed) {
2432
+ return;
2433
+ }
2434
+ EngineObject.prototype.destroy.call(this);
2355
2435
  this.defaultSceneRoot.destroy();
2356
2436
  this.textures = null;
2357
2437
  this.materials = null;
@@ -2362,7 +2442,7 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2362
2442
  this.cameras = null;
2363
2443
  this.lights = null;
2364
2444
  this.sceneRoots = null;
2365
- this.extensionsData = null;
2445
+ this.variants = null;
2366
2446
  };
2367
2447
  return GLTFResource;
2368
2448
  }(engineCore.EngineObject);
@@ -2373,30 +2453,23 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2373
2453
  return Loader.apply(this, arguments);
2374
2454
  }
2375
2455
  var _proto = GLTFLoader.prototype;
2376
- /**
2377
- * @override
2378
- */ _proto.load = function load(item, resourceManager) {
2456
+ _proto.load = function load(item, resourceManager) {
2457
+ var _item_params;
2379
2458
  var url = item.url;
2380
- var params = item.params;
2381
- var context = new GLTFParserContext(url);
2459
+ var context = new ParserContext(url);
2382
2460
  var glTFResource = new GLTFResource(resourceManager.engine, url);
2383
- var restorer = new GLTFContentRestorer(glTFResource);
2384
2461
  var masterPromiseInfo = context.masterPromiseInfo;
2385
- context.contentRestorer = restorer;
2386
2462
  context.glTFResource = glTFResource;
2387
- var _params_keepMeshData;
2388
- context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
2463
+ var _item_params_keepMeshData;
2464
+ context.keepMeshData = (_item_params_keepMeshData = (_item_params = item.params) == null ? void 0 : _item_params.keepMeshData) != null ? _item_params_keepMeshData : false;
2389
2465
  masterPromiseInfo.onCancel(function() {
2390
2466
  var chainPromises = context.chainPromises;
2391
- for(var _iterator = _createForOfIteratorHelperLoose(chainPromises), _step; !(_step = _iterator()).done;){
2467
+ for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
2392
2468
  var promise = _step.value;
2393
2469
  promise.cancel();
2394
2470
  }
2395
2471
  });
2396
- ((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
2397
- resourceManager.addContentRestorer(restorer);
2398
- masterPromiseInfo.resolve(glTFResource);
2399
- }).catch(function(e) {
2472
+ GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
2400
2473
  console.error(e);
2401
2474
  masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
2402
2475
  });
@@ -2405,7 +2478,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2405
2478
  return GLTFLoader;
2406
2479
  }(engineCore.Loader);
2407
2480
  GLTFLoader = __decorate([
2408
- engineCore.resourceLoader(engineCore.AssetType.GLTF, [
2481
+ engineCore.resourceLoader(engineCore.AssetType.Prefab, [
2409
2482
  "gltf",
2410
2483
  "glb"
2411
2484
  ])
@@ -2652,37 +2725,75 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
2652
2725
  color.a *= M;
2653
2726
  };
2654
2727
  return HDRLoader1;
2655
- }(engineCore.Loader), _HDRLoader._rightBottomBack = new engineMath.Vector3(1.0, -1.0, -1.0), _HDRLoader._rightBottomFront = new engineMath.Vector3(1.0, -1.0, 1.0), _HDRLoader._rightUpBack = new engineMath.Vector3(1.0, 1.0, -1.0), _HDRLoader._rightUpFront = new engineMath.Vector3(1.0, 1.0, 1.0), _HDRLoader._leftBottomBack = new engineMath.Vector3(-1.0, -1.0, -1.0), _HDRLoader._leftBottomFront = new engineMath.Vector3(-1.0, -1.0, 1.0), _HDRLoader._leftUpBack = new engineMath.Vector3(-1.0, 1.0, -1.0), _HDRLoader._leftUpFront = new engineMath.Vector3(-1.0, 1.0, 1.0), _HDRLoader._faceRight = [
2656
- _HDRLoader._rightBottomBack,
2657
- _HDRLoader._rightBottomFront,
2658
- _HDRLoader._rightUpBack,
2659
- _HDRLoader._rightUpFront
2660
- ], _HDRLoader._faceLeft = [
2661
- _HDRLoader._leftBottomFront,
2662
- _HDRLoader._leftBottomBack,
2663
- _HDRLoader._leftUpFront,
2664
- _HDRLoader._leftUpBack
2665
- ], _HDRLoader._faceUp = [
2666
- _HDRLoader._leftBottomFront,
2667
- _HDRLoader._rightBottomFront,
2668
- _HDRLoader._leftBottomBack,
2669
- _HDRLoader._rightBottomBack
2670
- ], _HDRLoader._faceBottom = [
2671
- _HDRLoader._leftUpBack,
2672
- _HDRLoader._rightUpBack,
2673
- _HDRLoader._leftUpFront,
2674
- _HDRLoader._rightUpFront
2675
- ], _HDRLoader._faceFront = [
2676
- _HDRLoader._leftBottomBack,
2677
- _HDRLoader._rightBottomBack,
2678
- _HDRLoader._leftUpBack,
2679
- _HDRLoader._rightUpBack
2680
- ], _HDRLoader._faceBack = [
2681
- _HDRLoader._rightBottomFront,
2682
- _HDRLoader._leftBottomFront,
2683
- _HDRLoader._rightUpFront,
2684
- _HDRLoader._leftUpFront
2685
- ], _HDRLoader._tempVector3 = new engineMath.Vector3(), _HDRLoader._temp2Vector3 = new engineMath.Vector3(), _HDRLoader._temp3Vector3 = new engineMath.Vector3(), _HDRLoader._temp4Vector3 = new engineMath.Vector3(), _HDRLoader._temp5Vector3 = new engineMath.Vector3(), _HDRLoader);
2728
+ }(engineCore.Loader), function() {
2729
+ _HDRLoader._rightBottomBack = new engineMath.Vector3(1.0, -1.0, -1.0);
2730
+ }(), function() {
2731
+ _HDRLoader._rightBottomFront = new engineMath.Vector3(1.0, -1.0, 1.0);
2732
+ }(), function() {
2733
+ _HDRLoader._rightUpBack = new engineMath.Vector3(1.0, 1.0, -1.0);
2734
+ }(), function() {
2735
+ _HDRLoader._rightUpFront = new engineMath.Vector3(1.0, 1.0, 1.0);
2736
+ }(), function() {
2737
+ _HDRLoader._leftBottomBack = new engineMath.Vector3(-1.0, -1.0, -1.0);
2738
+ }(), function() {
2739
+ _HDRLoader._leftBottomFront = new engineMath.Vector3(-1.0, -1.0, 1.0);
2740
+ }(), function() {
2741
+ _HDRLoader._leftUpBack = new engineMath.Vector3(-1.0, 1.0, -1.0);
2742
+ }(), function() {
2743
+ _HDRLoader._leftUpFront = new engineMath.Vector3(-1.0, 1.0, 1.0);
2744
+ }(), function() {
2745
+ _HDRLoader._faceRight = [
2746
+ _HDRLoader._rightBottomBack,
2747
+ _HDRLoader._rightBottomFront,
2748
+ _HDRLoader._rightUpBack,
2749
+ _HDRLoader._rightUpFront
2750
+ ];
2751
+ }(), function() {
2752
+ _HDRLoader._faceLeft = [
2753
+ _HDRLoader._leftBottomFront,
2754
+ _HDRLoader._leftBottomBack,
2755
+ _HDRLoader._leftUpFront,
2756
+ _HDRLoader._leftUpBack
2757
+ ];
2758
+ }(), function() {
2759
+ _HDRLoader._faceUp = [
2760
+ _HDRLoader._leftBottomFront,
2761
+ _HDRLoader._rightBottomFront,
2762
+ _HDRLoader._leftBottomBack,
2763
+ _HDRLoader._rightBottomBack
2764
+ ];
2765
+ }(), function() {
2766
+ _HDRLoader._faceBottom = [
2767
+ _HDRLoader._leftUpBack,
2768
+ _HDRLoader._rightUpBack,
2769
+ _HDRLoader._leftUpFront,
2770
+ _HDRLoader._rightUpFront
2771
+ ];
2772
+ }(), function() {
2773
+ _HDRLoader._faceFront = [
2774
+ _HDRLoader._leftBottomBack,
2775
+ _HDRLoader._rightBottomBack,
2776
+ _HDRLoader._leftUpBack,
2777
+ _HDRLoader._rightUpBack
2778
+ ];
2779
+ }(), function() {
2780
+ _HDRLoader._faceBack = [
2781
+ _HDRLoader._rightBottomFront,
2782
+ _HDRLoader._leftBottomFront,
2783
+ _HDRLoader._rightUpFront,
2784
+ _HDRLoader._leftUpFront
2785
+ ];
2786
+ }(), function() {
2787
+ _HDRLoader._tempVector3 = new engineMath.Vector3();
2788
+ }(), function() {
2789
+ _HDRLoader._temp2Vector3 = new engineMath.Vector3();
2790
+ }(), function() {
2791
+ _HDRLoader._temp3Vector3 = new engineMath.Vector3();
2792
+ }(), function() {
2793
+ _HDRLoader._temp4Vector3 = new engineMath.Vector3();
2794
+ }(), function() {
2795
+ _HDRLoader._temp5Vector3 = new engineMath.Vector3();
2796
+ }(), _HDRLoader);
2686
2797
  HDRLoader = __decorate([
2687
2798
  engineCore.resourceLoader(engineCore.AssetType.HDR, [
2688
2799
  "hdr"
@@ -3052,19 +3163,21 @@ MaterialLoader = __decorate([
3052
3163
  ], MaterialLoader);
3053
3164
 
3054
3165
  function _defineProperties(target, props) {
3055
- for (var i = 0; i < props.length; i++) {
3056
- var descriptor = props[i];
3057
- descriptor.enumerable = descriptor.enumerable || false;
3058
- descriptor.configurable = true;
3059
- if ("value" in descriptor) descriptor.writable = true;
3060
- Object.defineProperty(target, descriptor.key, descriptor);
3061
- }
3166
+ for (var i = 0; i < props.length; i++) {
3167
+ var descriptor = props[i];
3168
+ descriptor.enumerable = descriptor.enumerable || false;
3169
+ descriptor.configurable = true;
3170
+
3171
+ if ("value" in descriptor) descriptor.writable = true;
3172
+
3173
+ Object.defineProperty(target, descriptor.key, descriptor);
3174
+ }
3062
3175
  }
3176
+ function _create_class(Constructor, protoProps, staticProps) {
3177
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
3178
+ if (staticProps) _defineProperties(Constructor, staticProps);
3063
3179
 
3064
- function _createClass(Constructor, protoProps, staticProps) {
3065
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
3066
- if (staticProps) _defineProperties(Constructor, staticProps);
3067
- return Constructor;
3180
+ return Constructor;
3068
3181
  }
3069
3182
 
3070
3183
  var BufferReader = /*#__PURE__*/ function() {
@@ -3173,7 +3286,7 @@ var BufferReader = /*#__PURE__*/ function() {
3173
3286
  if (byteLength < maxByteLength) this._offset++;
3174
3287
  return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
3175
3288
  };
3176
- _createClass(BufferReader, [
3289
+ _create_class(BufferReader, [
3177
3290
  {
3178
3291
  key: "offset",
3179
3292
  get: function get() {
@@ -3183,12 +3296,14 @@ var BufferReader = /*#__PURE__*/ function() {
3183
3296
  ]);
3184
3297
  return BufferReader;
3185
3298
  }();
3186
- BufferReader.imageMapping = {
3187
- 0: "image/png",
3188
- 1: "image/jpg",
3189
- 2: "image/webp",
3190
- 3: "ktx"
3191
- };
3299
+ (function() {
3300
+ BufferReader.imageMapping = {
3301
+ 0: "image/png",
3302
+ 1: "image/jpg",
3303
+ 2: "image/webp",
3304
+ 3: "ktx"
3305
+ };
3306
+ })();
3192
3307
 
3193
3308
  var decoderMap = {};
3194
3309
  /**
@@ -3227,7 +3342,7 @@ var FileHeader = /*#__PURE__*/ function() {
3227
3342
  header.headerLength = nameUint8Array.byteLength + typeUint8Array.byteLength + 9;
3228
3343
  return header;
3229
3344
  };
3230
- _createClass(FileHeader, [
3345
+ _create_class(FileHeader, [
3231
3346
  {
3232
3347
  key: "dataLength",
3233
3348
  get: function get() {
@@ -3446,38 +3561,36 @@ exports.Texture2DDecoder = __decorate([
3446
3561
  decoder("Texture2D")
3447
3562
  ], exports.Texture2DDecoder);
3448
3563
 
3449
- function isNativeReflectConstruct() {
3450
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
3451
- if (Reflect.construct.sham) return false;
3452
- if (typeof Proxy === "function") return true;
3453
-
3454
- try {
3455
- Date.prototype.toString.call(Reflect.construct(Date, [], function () { }));
3456
- return true;
3457
- } catch (e) {
3458
- return false;
3459
- }
3460
- }
3564
+ function _is_native_reflect_construct() {
3565
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
3566
+ if (Reflect.construct.sham) return false;
3567
+ if (typeof Proxy === "function") return true;
3461
3568
 
3462
- function construct(Parent, args, Class) {
3463
- if (isNativeReflectConstruct()) {
3464
- construct = Reflect.construct;
3465
- } else {
3466
- construct = function construct(Parent, args, Class) {
3467
- var a = [null];
3468
- a.push.apply(a, args);
3469
- var Constructor = Function.bind.apply(Parent, a);
3470
- var instance = new Constructor();
3471
- if (Class) _setPrototypeOf(instance, Class.prototype);
3472
- return instance;
3473
- };
3474
- }
3569
+ try {
3570
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
3475
3571
 
3476
- return construct.apply(null, arguments);
3572
+ return true;
3573
+ } catch (e) {
3574
+ return false;
3575
+ }
3477
3576
  }
3478
3577
 
3479
3578
  function _construct(Parent, args, Class) {
3480
- return construct.apply(null, arguments);
3579
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
3580
+ else {
3581
+ _construct = function construct(Parent, args, Class) {
3582
+ var a = [null];
3583
+ a.push.apply(a, args);
3584
+ var Constructor = Function.bind.apply(Parent, a);
3585
+ var instance = new Constructor();
3586
+
3587
+ if (Class) _set_prototype_of(instance, Class.prototype);
3588
+
3589
+ return instance;
3590
+ };
3591
+ }
3592
+
3593
+ return _construct.apply(null, arguments);
3481
3594
  }
3482
3595
 
3483
3596
  var ReflectionParser = /*#__PURE__*/ function() {
@@ -3592,7 +3705,9 @@ var ReflectionParser = /*#__PURE__*/ function() {
3592
3705
  };
3593
3706
  return ReflectionParser;
3594
3707
  }();
3595
- ReflectionParser.customParseComponentHandles = new Map();
3708
+ (function() {
3709
+ ReflectionParser.customParseComponentHandles = new Map();
3710
+ })();
3596
3711
 
3597
3712
  var PrefabParser = /*#__PURE__*/ function() {
3598
3713
  function PrefabParser() {}
@@ -3846,7 +3961,7 @@ var SceneParserContext = /*#__PURE__*/ function() {
3846
3961
  };
3847
3962
  _proto._organizeEntities = function _organizeEntities() {
3848
3963
  var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
3849
- for(var _iterator = _createForOfIteratorHelperLoose(rootIds), _step; !(_step = _iterator()).done;){
3964
+ for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
3850
3965
  var rootId = _step.value;
3851
3966
  PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
3852
3967
  }
@@ -4010,7 +4125,7 @@ var SourceFontLoader = /*#__PURE__*/ function(Loader) {
4010
4125
  });
4011
4126
  };
4012
4127
  _proto._registerFont = function _registerFont(fontName, fontUrl) {
4013
- return _asyncToGenerator(function() {
4128
+ return _async_to_generator(function() {
4014
4129
  var fontFace;
4015
4130
  return __generator(this, function(_state) {
4016
4131
  switch(_state.label){
@@ -4047,6 +4162,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
4047
4162
  _this = Loader.apply(this, arguments) || this;
4048
4163
  _this._tempRect = new engineMath.Rect();
4049
4164
  _this._tempVec2 = new engineMath.Vector2();
4165
+ _this._tempVec4 = new engineMath.Vector4();
4050
4166
  return _this;
4051
4167
  }
4052
4168
  var _proto = SpriteAtlasLoader.prototype;
@@ -4064,57 +4180,65 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
4064
4180
  }));
4065
4181
  chainPromises.push(configPromise);
4066
4182
  configPromise.then(function(atlasData) {
4067
- var atlasItems = atlasData.atlasItems, format = atlasData.format;
4068
- var atlasItemsLen = atlasItems.length;
4069
- var imagePromises = engineCore.AssetPromise.all(atlasItems.map(function(param) {
4070
- var img = param.img;
4071
- return _this.request(GLTFUtil.parseRelativeUrl(item.url, img), _extends({}, item, {
4072
- type: "image"
4073
- }));
4074
- }));
4075
- chainPromises.push(imagePromises);
4076
- return imagePromises.then(function(imgs) {
4077
- var engine = resourceManager.engine;
4078
- // Generate a SpriteAtlas object.
4079
- var tempRect = _this._tempRect, tempVec2 = _this._tempVec2;
4080
- var spriteAtlas = new engineCore.SpriteAtlas(engine);
4081
- for(var i = 0; i < atlasItemsLen; i++){
4082
- // Generate Texture2D according to configuration.
4083
- var originalImg = imgs[i];
4084
- var width = originalImg.width, height = originalImg.height;
4085
- var texture = new engineCore.Texture2D(engine, width, height, format);
4086
- texture.setImageSource(originalImg);
4087
- texture.generateMipmaps();
4088
- // Generate all the sprites on this texture.
4089
- var atlasItem = atlasItems[i];
4090
- var sprites = atlasItem.sprites;
4091
- var sourceWidthReciprocal = 1.0 / width;
4092
- var sourceHeightReciprocal = 1.0 / height;
4093
- for(var j = sprites.length - 1; j >= 0; j--){
4094
- var atlasSprite = sprites[j];
4095
- var region = atlasSprite.region, atlasRegionOffset = atlasSprite.atlasRegionOffset, atlasRegion = atlasSprite.atlasRegion, id = atlasSprite.id, pivot = atlasSprite.pivot;
4096
- var sprite = new engineCore.Sprite(engine, texture, region ? tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? tempVec2.set(pivot.x, pivot.y) : undefined, undefined, atlasSprite.name);
4097
- sprite.atlasRegion.set(atlasRegion.x * sourceWidthReciprocal, atlasRegion.y * sourceHeightReciprocal, atlasRegion.w * sourceWidthReciprocal, atlasRegion.h * sourceHeightReciprocal);
4098
- atlasSprite.atlasRotated && (sprite.atlasRotated = true);
4099
- if (atlasRegionOffset) {
4100
- var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
4101
- sprite.atlasRegionOffset.set(offsetLeft * sourceWidthReciprocal, offsetTop * sourceHeightReciprocal, offsetRight * sourceWidthReciprocal, offsetBottom * sourceHeightReciprocal);
4183
+ var _loop = function(i) {
4184
+ var atlasItem = atlasItems[i];
4185
+ if (atlasItem.img) {
4186
+ chainPromises.push(resourceManager.load({
4187
+ url: atlasItem.img,
4188
+ type: engineCore.AssetType.Texture2D,
4189
+ params: {
4190
+ format: format,
4191
+ mipmap: mipmap
4102
4192
  }
4103
- if (id !== undefined) {
4193
+ }).then(function(texture) {
4194
+ anisoLevel && (texture.anisoLevel = anisoLevel);
4195
+ filterMode !== undefined && (texture.filterMode = filterMode);
4196
+ wrapModeU !== undefined && (texture.wrapModeU = wrapModeU);
4197
+ wrapModeV !== undefined && (texture.wrapModeV = wrapModeV);
4198
+ for(var i = 0; i < atlasItem.sprites.length; i++){
4104
4199
  // @ts-ignore
4105
- sprite._assetID = id;
4200
+ spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i], texture));
4106
4201
  }
4202
+ }).catch(reject));
4203
+ } else {
4204
+ for(var i1 = 0; i1 < atlasItem.sprites.length; i1++){
4107
4205
  // @ts-ignore
4108
- spriteAtlas._addSprite(sprite);
4206
+ spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i1]));
4109
4207
  }
4110
4208
  }
4209
+ };
4210
+ var atlasItems = atlasData.atlasItems, mipmap = atlasData.mipmap, anisoLevel = atlasData.anisoLevel, filterMode = atlasData.filterMode, wrapModeU = atlasData.wrapModeU, wrapModeV = atlasData.wrapModeV, format = atlasData.format;
4211
+ var atlasItemsLen = atlasItems ? atlasItems.length : 0;
4212
+ var engine = resourceManager.engine;
4213
+ var spriteAtlas = new engineCore.SpriteAtlas(engine);
4214
+ if (atlasItemsLen < 0) {
4111
4215
  resolve(spriteAtlas);
4112
- });
4113
- }).catch(function(e) {
4114
- reject(e);
4115
- });
4216
+ return;
4217
+ }
4218
+ chainPromises.length = 0;
4219
+ for(var i = 0; i < atlasItems.length; i++)_loop(i);
4220
+ engineCore.AssetPromise.all(chainPromises).then(function() {
4221
+ resolve(spriteAtlas);
4222
+ }).catch(reject);
4223
+ }).catch(reject);
4116
4224
  });
4117
4225
  };
4226
+ _proto._makeSprite = function _makeSprite(engine, config, texture) {
4227
+ // Generate a SpriteAtlas object.
4228
+ var region = config.region, atlasRegionOffset = config.atlasRegionOffset, atlasRegion = config.atlasRegion, pivot = config.pivot, border = config.border;
4229
+ var sprite = new engineCore.Sprite(engine, texture, region ? this._tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? this._tempVec2.set(pivot.x, pivot.y) : undefined, border ? this._tempVec4.set(border.x, border.y, border.z, border.w) : undefined, config.name);
4230
+ if (texture) {
4231
+ var invW = 1 / texture.width;
4232
+ var invH = 1 / texture.height;
4233
+ sprite.atlasRegion.set(atlasRegion.x * invW, atlasRegion.y * invH, atlasRegion.w * invW, atlasRegion.h * invH);
4234
+ if (atlasRegionOffset) {
4235
+ var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
4236
+ sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
4237
+ }
4238
+ config.atlasRotated && (sprite.atlasRotated = true);
4239
+ }
4240
+ return sprite;
4241
+ };
4118
4242
  return SpriteAtlasLoader;
4119
4243
  }(engineCore.Loader);
4120
4244
  SpriteAtlasLoader = __decorate([
@@ -4135,13 +4259,19 @@ var SpriteLoader = /*#__PURE__*/ function(Loader) {
4135
4259
  _this.request(item.url, _extends({}, item, {
4136
4260
  type: "json"
4137
4261
  })).then(function(data) {
4138
- // @ts-ignore
4139
- resourceManager.getResourceByRef(data.texture).then(function(texture) {
4140
- var sprite = new engineCore.Sprite(resourceManager.engine, texture);
4141
- sprite.region = data.region;
4142
- sprite.pivot = data.pivot;
4143
- resolve(sprite);
4144
- });
4262
+ if (data.belongToAtlas) {
4263
+ resourceManager// @ts-ignore
4264
+ .getResourceByRef(data.belongToAtlas).then(function(atlas) {
4265
+ resolve(atlas.getSprite(data.fullPath));
4266
+ }).catch(reject);
4267
+ } else if (data.texture) {
4268
+ resourceManager// @ts-ignore
4269
+ .getResourceByRef(data.texture).then(function(texture) {
4270
+ resolve(new engineCore.Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border));
4271
+ }).catch(reject);
4272
+ } else {
4273
+ resolve(new engineCore.Sprite(resourceManager.engine, null, data.region, data.pivot, data.border));
4274
+ }
4145
4275
  }).catch(reject);
4146
4276
  });
4147
4277
  };
@@ -4153,57 +4283,28 @@ SpriteLoader = __decorate([
4153
4283
  ], false)
4154
4284
  ], SpriteLoader);
4155
4285
 
4156
- /**
4157
- * @internal
4158
- */ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4159
- _inherits(Texture2DContentRestorer, ContentRestorer);
4160
- function Texture2DContentRestorer(resource, url, requestConfig) {
4161
- var _this;
4162
- _this = ContentRestorer.call(this, resource) || this;
4163
- _this.url = url;
4164
- _this.requestConfig = requestConfig;
4165
- return _this;
4166
- }
4167
- var _proto = Texture2DContentRestorer.prototype;
4168
- /**
4169
- * @override
4170
- */ _proto.restoreContent = function restoreContent() {
4171
- var _this = this;
4172
- return engineCore.request(this.url, this.requestConfig).then(function(image) {
4173
- var resource = _this.resource;
4174
- resource.setImageSource(image);
4175
- resource.generateMipmaps();
4176
- return resource;
4177
- });
4178
- };
4179
- return Texture2DContentRestorer;
4180
- }(engineCore.ContentRestorer);
4181
-
4182
4286
  var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4183
4287
  _inherits(Texture2DLoader, Loader);
4184
4288
  function Texture2DLoader() {
4185
4289
  return Loader.apply(this, arguments);
4186
4290
  }
4187
4291
  var _proto = Texture2DLoader.prototype;
4188
- /**
4189
- * @override
4190
- */ _proto.load = function load(item, resourceManager) {
4292
+ _proto.load = function load(item, resourceManager) {
4191
4293
  var _this = this;
4192
4294
  return new engineCore.AssetPromise(function(resolve, reject) {
4193
- var url = item.url;
4194
- var requestConfig = _extends({}, item, {
4295
+ _this.request(item.url, _extends({}, item, {
4195
4296
  type: "image"
4196
- });
4197
- _this.request(url, requestConfig).then(function(image) {
4198
- var params = item.params;
4199
- var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
4297
+ })).then(function(image) {
4298
+ var _item_params;
4299
+ var params = (_item_params = item.params) != null ? _item_params : {};
4300
+ var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
4301
+ /** @ts-ignore */ if (!texture._platformTexture) return;
4200
4302
  texture.setImageSource(image);
4201
4303
  texture.generateMipmaps();
4202
- if (url.indexOf("data:") !== 0) {
4203
- var index = url.lastIndexOf("/");
4204
- texture.name = url.substring(index + 1);
4304
+ if (item.url.indexOf("data:") !== 0) {
4305
+ var splitPath = item.url.split("/");
4306
+ texture.name = splitPath[splitPath.length - 1];
4205
4307
  }
4206
- resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
4207
4308
  resolve(texture);
4208
4309
  }).catch(function(e) {
4209
4310
  reject(e);
@@ -4221,70 +4322,32 @@ Texture2DLoader = __decorate([
4221
4322
  ])
4222
4323
  ], Texture2DLoader);
4223
4324
 
4224
- /**
4225
- * @internal
4226
- */ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4227
- _inherits(TextureCubeContentRestorer, ContentRestorer);
4228
- function TextureCubeContentRestorer(resource, urls, requestConfig) {
4229
- var _this;
4230
- _this = ContentRestorer.call(this, resource) || this;
4231
- _this.urls = urls;
4232
- _this.requestConfig = requestConfig;
4233
- return _this;
4234
- }
4235
- var _proto = TextureCubeContentRestorer.prototype;
4236
- /**
4237
- * @override
4238
- */ _proto.restoreContent = function restoreContent() {
4239
- var _this = this;
4240
- return new engineCore.AssetPromise(function(resolve, reject) {
4241
- Promise.all(_this.urls.map(function(url) {
4242
- return engineCore.request(url, _this.requestConfig);
4243
- })).then(function(images) {
4244
- var resource = _this.resource;
4245
- for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4246
- resource.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4247
- }
4248
- resource.generateMipmaps();
4249
- resolve(resource);
4250
- }).catch(function(e) {
4251
- reject(e);
4252
- });
4253
- });
4254
- };
4255
- return TextureCubeContentRestorer;
4256
- }(engineCore.ContentRestorer);
4257
-
4258
4325
  var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4259
4326
  _inherits(TextureCubeLoader, Loader);
4260
4327
  function TextureCubeLoader() {
4261
4328
  return Loader.apply(this, arguments);
4262
4329
  }
4263
4330
  var _proto = TextureCubeLoader.prototype;
4264
- /**
4265
- * @override
4266
- */ _proto.load = function load(item, resourceManager) {
4331
+ _proto.load = function load(item, resourceManager) {
4267
4332
  var _this = this;
4268
4333
  return new engineCore.AssetPromise(function(resolve, reject) {
4269
- var urls = item.urls;
4270
- var requestConfig = _extends({}, item, {
4271
- type: "image"
4272
- });
4273
- Promise.all(urls.map(function(url) {
4274
- return _this.request(url, requestConfig);
4334
+ Promise.all(item.urls.map(function(url) {
4335
+ return _this.request(url, _extends({}, item, {
4336
+ type: "image"
4337
+ }));
4275
4338
  })).then(function(images) {
4276
4339
  var _images_ = images[0], width = _images_.width, height = _images_.height;
4277
4340
  if (width !== height) {
4278
4341
  console.error("The cube texture must have the same width and height");
4279
4342
  return;
4280
4343
  }
4281
- var texture = new engineCore.TextureCube(resourceManager.engine, width);
4344
+ var tex = new engineCore.TextureCube(resourceManager.engine, width);
4345
+ /** @ts-ignore */ if (!tex._platformTexture) return;
4282
4346
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4283
- texture.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4347
+ tex.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4284
4348
  }
4285
- texture.generateMipmaps();
4286
- resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
4287
- resolve(texture);
4349
+ tex.generateMipmaps();
4350
+ resolve(tex);
4288
4351
  }).catch(function(e) {
4289
4352
  reject(e);
4290
4353
  });
@@ -4298,30 +4361,6 @@ TextureCubeLoader = __decorate([
4298
4361
  ])
4299
4362
  ], TextureCubeLoader);
4300
4363
 
4301
- var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
4302
- _inherits(AnimationClipLoader, Loader);
4303
- function AnimationClipLoader() {
4304
- return Loader.apply(this, arguments);
4305
- }
4306
- var _proto = AnimationClipLoader.prototype;
4307
- _proto.load = function load(item, resourceManager) {
4308
- var _this = this;
4309
- return new engineCore.AssetPromise(function(resolve, reject) {
4310
- _this.request(item.url, _extends({}, item, {
4311
- type: "arraybuffer"
4312
- })).then(function(data) {
4313
- return decode(data, resourceManager.engine);
4314
- }).catch(reject);
4315
- });
4316
- };
4317
- return AnimationClipLoader;
4318
- }(engineCore.Loader);
4319
- AnimationClipLoader = __decorate([
4320
- engineCore.resourceLoader(engineCore.AssetType.AnimationClip, [
4321
- "ani"
4322
- ])
4323
- ], AnimationClipLoader);
4324
-
4325
4364
  var SceneLoader = /*#__PURE__*/ function(Loader) {
4326
4365
  _inherits(SceneLoader, Loader);
4327
4366
  function SceneLoader() {
@@ -4407,7 +4446,7 @@ SceneLoader = __decorate([
4407
4446
  "prefab"
4408
4447
  ], true)
4409
4448
  ], SceneLoader);
4410
- ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asyncToGenerator(function(instance, item, engine) {
4449
+ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item, engine) {
4411
4450
  var props;
4412
4451
  return __generator(this, function(_state) {
4413
4452
  props = item.props;
@@ -4422,409 +4461,11 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
4422
4461
  });
4423
4462
  }));
4424
4463
 
4425
- var _KHR_draco_mesh_compression;
4426
- var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
4427
- _inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
4428
- function KHR_draco_mesh_compression1() {
4429
- return GLTFExtensionParser.apply(this, arguments);
4430
- }
4431
- var _proto = KHR_draco_mesh_compression1.prototype;
4432
- /**
4433
- * @override
4434
- */ _proto.initialize = function initialize() {
4435
- if (!KHR_draco_mesh_compression._decoder) {
4436
- KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
4437
- }
4438
- };
4439
- /**
4440
- * @override
4441
- */ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
4442
- var _this = this;
4443
- var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
4444
- var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
4445
- var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
4446
- var attributeMap = {};
4447
- var attributeTypeMap = {};
4448
- for(var attributeName in gltfAttributeMap){
4449
- attributeMap[attributeName] = gltfAttributeMap[attributeName];
4450
- }
4451
- for(var attributeName1 in glTFPrimitive.attributes){
4452
- if (gltfAttributeMap[attributeName1] !== undefined) {
4453
- var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
4454
- attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
4455
- }
4456
- }
4457
- var indexAccessor = accessors[glTFPrimitive.indices];
4458
- var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
4459
- var taskConfig = {
4460
- attributeIDs: attributeMap,
4461
- attributeTypes: attributeTypeMap,
4462
- useUniqueIDs: true,
4463
- indexType: indexType
4464
- };
4465
- var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4466
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4467
- var mesh = new engineCore.ModelMesh(engine, glTFMesh.name);
4468
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4469
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
4470
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
4471
- return decodedGeometry.attributes[j].array;
4472
- }
4473
- }
4474
- return null;
4475
- }, function(attributeSemantic, shapeIndex) {
4476
- throw "BlendShape animation is not supported when using draco.";
4477
- }, function() {
4478
- return decodedGeometry.index.array;
4479
- }, context.keepMeshData);
4480
- });
4481
- };
4482
- _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
4483
- var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
4484
- var vertexCount;
4485
- var accessors = gltf.accessors;
4486
- var accessor = accessors[attributes["POSITION"]];
4487
- var positionBuffer = getVertexBufferData("POSITION");
4488
- var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
4489
- mesh.setPositions(positions);
4490
- var bounds = mesh.bounds;
4491
- vertexCount = accessor.count;
4492
- if (accessor.min && accessor.max) {
4493
- bounds.min.copyFromArray(accessor.min);
4494
- bounds.max.copyFromArray(accessor.max);
4495
- } else {
4496
- var position = KHR_draco_mesh_compression._tempVector3;
4497
- var min = bounds.min, max = bounds.max;
4498
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
4499
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
4500
- var stride = positionBuffer.length / vertexCount;
4501
- for(var j = 0; j < vertexCount; j++){
4502
- var offset = j * stride;
4503
- position.copyFromArray(positionBuffer, offset);
4504
- engineMath.Vector3.min(min, position, min);
4505
- engineMath.Vector3.max(max, position, max);
4506
- }
4507
- }
4508
- for(var attributeSemantic in attributes){
4509
- if (attributeSemantic === "POSITION") {
4510
- continue;
4511
- }
4512
- var bufferData = getVertexBufferData(attributeSemantic);
4513
- switch(attributeSemantic){
4514
- case "NORMAL":
4515
- var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
4516
- mesh.setNormals(normals);
4517
- break;
4518
- case "TEXCOORD_0":
4519
- var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
4520
- mesh.setUVs(texturecoords, 0);
4521
- break;
4522
- case "TEXCOORD_1":
4523
- var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
4524
- mesh.setUVs(texturecoords1, 1);
4525
- break;
4526
- case "TEXCOORD_2":
4527
- var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
4528
- mesh.setUVs(texturecoords2, 2);
4529
- break;
4530
- case "TEXCOORD_3":
4531
- var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
4532
- mesh.setUVs(texturecoords3, 3);
4533
- break;
4534
- case "TEXCOORD_4":
4535
- var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
4536
- mesh.setUVs(texturecoords4, 4);
4537
- break;
4538
- case "TEXCOORD_5":
4539
- var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
4540
- mesh.setUVs(texturecoords5, 5);
4541
- break;
4542
- case "TEXCOORD_6":
4543
- var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
4544
- mesh.setUVs(texturecoords6, 6);
4545
- break;
4546
- case "TEXCOORD_7":
4547
- var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
4548
- mesh.setUVs(texturecoords7, 7);
4549
- break;
4550
- case "COLOR_0":
4551
- var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
4552
- mesh.setColors(colors);
4553
- break;
4554
- case "TANGENT":
4555
- var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
4556
- mesh.setTangents(tangents);
4557
- break;
4558
- case "JOINTS_0":
4559
- var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
4560
- mesh.setBoneIndices(joints);
4561
- break;
4562
- case "WEIGHTS_0":
4563
- var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
4564
- mesh.setBoneWeights(weights);
4565
- break;
4566
- }
4567
- }
4568
- // Indices
4569
- if (indices !== undefined) {
4570
- var indexAccessor = gltf.accessors[indices];
4571
- var indexData = getIndexBufferData();
4572
- mesh.setIndices(indexData);
4573
- mesh.addSubMesh(0, indexAccessor.count, mode);
4574
- } else {
4575
- mesh.addSubMesh(0, vertexCount, mode);
4576
- }
4577
- // BlendShapes
4578
- targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
4579
- mesh.uploadData(!keepMeshData);
4580
- return Promise.resolve(mesh);
4581
- };
4582
- return KHR_draco_mesh_compression1;
4583
- }(GLTFExtensionParser), _KHR_draco_mesh_compression._tempVector3 = new engineMath.Vector3(), _KHR_draco_mesh_compression);
4584
- KHR_draco_mesh_compression = __decorate([
4585
- registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
4586
- ], KHR_draco_mesh_compression);
4587
-
4588
- var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
4589
- _inherits(KHR_lights_punctual, GLTFExtensionParser);
4590
- function KHR_lights_punctual() {
4591
- return GLTFExtensionParser.apply(this, arguments);
4592
- }
4593
- var _proto = KHR_lights_punctual.prototype;
4594
- /**
4595
- * @override
4596
- */ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
4597
- var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
4598
- var lightSchema = lightsSchema[extensionSchema.light];
4599
- var color = lightSchema.color, _lightSchema_intensity = lightSchema.intensity, intensity = _lightSchema_intensity === void 0 ? 1 : _lightSchema_intensity, type = lightSchema.type, range = lightSchema.range, spot = lightSchema.spot;
4600
- var glTFResource = context.glTFResource;
4601
- var light;
4602
- if (type === "directional") {
4603
- light = entity.addComponent(engineCore.DirectLight);
4604
- } else if (type === "point") {
4605
- light = entity.addComponent(engineCore.PointLight);
4606
- } else if (type === "spot") {
4607
- light = entity.addComponent(engineCore.SpotLight);
4608
- }
4609
- if (color) {
4610
- light.color.set(color[0], color[1], color[2], 1);
4611
- }
4612
- light.intensity = intensity;
4613
- if (range && !_instanceof(light, engineCore.DirectLight)) {
4614
- light.distance = range;
4615
- }
4616
- if (spot && _instanceof(light, engineCore.SpotLight)) {
4617
- var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
4618
- light.angle = innerConeAngle;
4619
- light.penumbra = outerConeAngle - innerConeAngle;
4620
- }
4621
- if (!glTFResource.lights) glTFResource.lights = [];
4622
- glTFResource.lights.push(light);
4623
- };
4624
- return KHR_lights_punctual;
4625
- }(GLTFExtensionParser);
4626
- KHR_lights_punctual = __decorate([
4627
- registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
4628
- ], KHR_lights_punctual);
4629
-
4630
- var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
4631
- _inherits(KHR_materials_clearcoat, GLTFExtensionParser);
4632
- function KHR_materials_clearcoat() {
4633
- return GLTFExtensionParser.apply(this, arguments);
4634
- }
4635
- var _proto = KHR_materials_clearcoat.prototype;
4636
- /**
4637
- * @override
4638
- */ _proto.additiveParse = function additiveParse(context, material, schema) {
4639
- var textures = context.glTFResource.textures;
4640
- var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
4641
- material.clearCoat = clearcoatFactor;
4642
- material.clearCoatRoughness = clearcoatRoughnessFactor;
4643
- if (clearcoatTexture) {
4644
- material.clearCoatTexture = textures[clearcoatTexture.index];
4645
- GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
4646
- }
4647
- if (clearcoatRoughnessTexture) {
4648
- material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
4649
- GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
4650
- }
4651
- if (clearcoatNormalTexture) {
4652
- material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
4653
- GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
4654
- }
4655
- };
4656
- return KHR_materials_clearcoat;
4657
- }(GLTFExtensionParser);
4658
- KHR_materials_clearcoat = __decorate([
4659
- registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
4660
- ], KHR_materials_clearcoat);
4661
-
4662
- var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
4663
- _inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
4664
- function KHR_materials_pbrSpecularGlossiness() {
4665
- return GLTFExtensionParser.apply(this, arguments);
4666
- }
4667
- var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
4668
- /**
4669
- * @override
4670
- */ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
4671
- var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
4672
- var material = new engineCore.PBRSpecularMaterial(engine);
4673
- var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
4674
- if (diffuseFactor) {
4675
- material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
4676
- }
4677
- if (diffuseTexture) {
4678
- material.baseTexture = textures[diffuseTexture.index];
4679
- GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
4680
- }
4681
- if (specularFactor) {
4682
- material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
4683
- }
4684
- if (glossinessFactor !== undefined) {
4685
- material.glossiness = glossinessFactor;
4686
- }
4687
- if (specularGlossinessTexture) {
4688
- material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
4689
- GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
4690
- }
4691
- material.name = ownerSchema.name;
4692
- GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4693
- return material;
4694
- };
4695
- return KHR_materials_pbrSpecularGlossiness;
4696
- }(GLTFExtensionParser);
4697
- KHR_materials_pbrSpecularGlossiness = __decorate([
4698
- registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
4699
- ], KHR_materials_pbrSpecularGlossiness);
4700
-
4701
- var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
4702
- _inherits(KHR_materials_unlit, GLTFExtensionParser);
4703
- function KHR_materials_unlit() {
4704
- return GLTFExtensionParser.apply(this, arguments);
4705
- }
4706
- var _proto = KHR_materials_unlit.prototype;
4707
- /**
4708
- * @override
4709
- */ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
4710
- var engine = context.glTFResource.engine;
4711
- var material = new engineCore.UnlitMaterial(engine);
4712
- material.name = ownerSchema.name;
4713
- GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4714
- return material;
4715
- };
4716
- return KHR_materials_unlit;
4717
- }(GLTFExtensionParser);
4718
- KHR_materials_unlit = __decorate([
4719
- registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
4720
- ], KHR_materials_unlit);
4721
-
4722
- var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
4723
- _inherits(KHR_mesh_quantization, GLTFExtensionParser);
4724
- function KHR_mesh_quantization() {
4725
- return GLTFExtensionParser.apply(this, arguments);
4726
- }
4727
- return KHR_mesh_quantization;
4728
- }(GLTFExtensionParser);
4729
- KHR_mesh_quantization = __decorate([
4730
- registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
4731
- ], KHR_mesh_quantization);
4732
-
4733
- var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
4734
- _inherits(KHR_texture_transform, GLTFExtensionParser);
4735
- function KHR_texture_transform() {
4736
- return GLTFExtensionParser.apply(this, arguments);
4737
- }
4738
- var _proto = KHR_texture_transform.prototype;
4739
- /**
4740
- * @override
4741
- */ _proto.additiveParse = function additiveParse(context, material, schema) {
4742
- var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
4743
- if (offset) {
4744
- material.tilingOffset.z = offset[0];
4745
- material.tilingOffset.w = offset[1];
4746
- }
4747
- if (scale) {
4748
- material.tilingOffset.x = scale[0];
4749
- material.tilingOffset.y = scale[1];
4750
- }
4751
- if (rotation) {
4752
- engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
4753
- }
4754
- if (texCoord) {
4755
- engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
4756
- }
4757
- };
4758
- return KHR_texture_transform;
4759
- }(GLTFExtensionParser);
4760
- KHR_texture_transform = __decorate([
4761
- registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
4762
- ], KHR_texture_transform);
4763
-
4764
- var GalaceanMaterialsRemap = /*#__PURE__*/ function(GLTFExtensionParser) {
4765
- _inherits(GalaceanMaterialsRemap, GLTFExtensionParser);
4766
- function GalaceanMaterialsRemap() {
4767
- return GLTFExtensionParser.apply(this, arguments);
4768
- }
4769
- var _proto = GalaceanMaterialsRemap.prototype;
4770
- /**
4771
- * @override
4772
- */ _proto.createAndParse = function createAndParse(context, schema) {
4773
- var engine = context.glTFResource.engine;
4774
- // @ts-ignore
4775
- return engine.resourceManager.getResourceByRef(schema);
4776
- };
4777
- return GalaceanMaterialsRemap;
4778
- }(GLTFExtensionParser);
4779
- GalaceanMaterialsRemap = __decorate([
4780
- registerGLTFExtension("OASIS_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
4781
- ], GalaceanMaterialsRemap);
4782
-
4783
- var OASIS_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
4784
- _inherits(OASIS_animation_event, GLTFExtensionParser);
4785
- function OASIS_animation_event() {
4786
- return GLTFExtensionParser.apply(this, arguments);
4787
- }
4788
- var _proto = OASIS_animation_event.prototype;
4789
- /**
4790
- * @override
4791
- */ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
4792
- context.glTFResource.engine;
4793
- var events = schema.events;
4794
- events.map(function(eventData) {
4795
- var event = new engineCore.AnimationEvent();
4796
- event.functionName = eventData.functionName;
4797
- event.time = eventData.time;
4798
- event.parameter = eventData.parameter;
4799
- animationClip.addEvent(event);
4800
- });
4801
- };
4802
- return OASIS_animation_event;
4803
- }(GLTFExtensionParser);
4804
- OASIS_animation_event = __decorate([
4805
- registerGLTFExtension("OASIS_animation_event", exports.GLTFExtensionMode.AdditiveParse)
4806
- ], OASIS_animation_event);
4807
-
4808
4464
  exports.ComponentMap = ComponentMap;
4809
- exports.GLTFAnimationParser = GLTFAnimationParser;
4810
- exports.GLTFBufferParser = GLTFBufferParser;
4811
- exports.GLTFEntityParser = GLTFEntityParser;
4812
- exports.GLTFExtensionParser = GLTFExtensionParser;
4813
- exports.GLTFMaterialParser = GLTFMaterialParser;
4814
- exports.GLTFMeshParser = GLTFMeshParser;
4815
- exports.GLTFParser = GLTFParser;
4816
- exports.GLTFParserContext = GLTFParserContext;
4817
- exports.GLTFPipeline = GLTFPipeline;
4818
4465
  exports.GLTFResource = GLTFResource;
4819
- exports.GLTFSceneParser = GLTFSceneParser;
4820
- exports.GLTFSkinParser = GLTFSkinParser;
4821
- exports.GLTFTextureParser = GLTFTextureParser;
4822
- exports.GLTFUtil = GLTFUtil;
4823
- exports.GLTFValidator = GLTFValidator;
4824
4466
  exports.PrefabParser = PrefabParser;
4825
4467
  exports.ReflectionParser = ReflectionParser;
4826
4468
  exports.SceneParser = SceneParser;
4827
4469
  exports.decode = decode;
4828
4470
  exports.parseSingleKTX = parseSingleKTX;
4829
- exports.registerGLTFExtension = registerGLTFExtension;
4830
4471
  //# sourceMappingURL=main.js.map