@galacean/engine-loader 1.1.2 → 1.1.6

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 (51) hide show
  1. package/dist/main.js +728 -598
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +728 -598
  4. package/dist/module.js +730 -601
  5. package/dist/module.js.map +1 -1
  6. package/package.json +5 -5
  7. package/types/GLTFContentRestorer.d.ts +7 -6
  8. package/types/gltf/GLTFUtils.d.ts +2 -7
  9. package/types/gltf/parser/GLTFMeshParser.d.ts +11 -6
  10. package/types/gltf/parser/GLTFParser.d.ts +1 -1
  11. package/types/gltf/parser/GLTFParserContext.d.ts +7 -6
  12. package/types/gltf/parser/index.d.ts +2 -1
  13. package/types/ktx2/KTX2Loader.d.ts +1 -1
  14. package/types/resource-deserialize/index.d.ts +8 -8
  15. package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +1 -1
  16. package/types/resource-deserialize/resources/texture2D/TextureDecoder.d.ts +1 -1
  17. package/types/resource-deserialize/utils/Decorator.d.ts +1 -1
  18. package/types/PrimitiveMeshLoader.d.ts +0 -1
  19. package/types/gltf/GLTFParser.d.ts +0 -9
  20. package/types/gltf/GLTFPipeline.d.ts +0 -23
  21. package/types/gltf/GLTFUtil.d.ts +0 -53
  22. package/types/gltf/Schema.d.ts +0 -814
  23. package/types/gltf/extensions/EXT_meshopt_compression.d.ts +0 -13
  24. package/types/gltf/extensions/ExtensionParser.d.ts +0 -8
  25. package/types/gltf/extensions/KHR_materials_anisotropy.d.ts +0 -1
  26. package/types/gltf/extensions/MeshoptDecoder.d.ts +0 -8
  27. package/types/gltf/extensions/Schema.d.ts +0 -142
  28. package/types/gltf/parser/AnimationParser.d.ts +0 -7
  29. package/types/gltf/parser/BufferParser.d.ts +0 -7
  30. package/types/gltf/parser/EntityParser.d.ts +0 -9
  31. package/types/gltf/parser/MaterialParser.d.ts +0 -8
  32. package/types/gltf/parser/MeshParser.d.ts +0 -13
  33. package/types/gltf/parser/Parser.d.ts +0 -21
  34. package/types/gltf/parser/ParserContext.d.ts +0 -46
  35. package/types/gltf/parser/SceneParser.d.ts +0 -11
  36. package/types/gltf/parser/SkinParser.d.ts +0 -6
  37. package/types/gltf/parser/TextureParser.d.ts +0 -8
  38. package/types/gltf/parser/Validator.d.ts +0 -5
  39. package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +0 -13
  40. package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +0 -33
  41. package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +0 -17
  42. package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +0 -34
  43. package/types/ktx2/TranscodeResult.d.ts +0 -10
  44. package/types/ktx2/constants.d.ts +0 -7
  45. package/types/ktx2/zstddec.d.ts +0 -62
  46. package/types/resource-deserialize/resources/parser/HierarchyParser.d.ts +0 -36
  47. package/types/resource-deserialize/resources/parser/ParserContext.d.ts +0 -29
  48. package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +0 -70
  49. package/types/resource-deserialize/resources/prefab/PrefabParser.d.ts +0 -14
  50. package/types/resource-deserialize/resources/prefab/PrefabParserContext.d.ts +0 -5
  51. package/types/resource-deserialize/resources/prefab/ReflectionParser.d.ts +0 -14
package/dist/main.js CHANGED
@@ -284,11 +284,201 @@ var FileHeader = /*#__PURE__*/ function() {
284
284
  return FileHeader;
285
285
  }();
286
286
 
287
+ var ComponentMap = {
288
+ Transform: engineCore.Transform,
289
+ Animator: engineCore.Animator,
290
+ DirectLight: engineCore.DirectLight,
291
+ Camera: engineCore.Camera,
292
+ MeshRenderer: engineCore.MeshRenderer,
293
+ ParticleRenderer: engineCore.ParticleRenderer,
294
+ PointLight: engineCore.PointLight,
295
+ SpotLight: engineCore.SpotLight,
296
+ Script: engineCore.Script,
297
+ SpriteMask: engineCore.SpriteMask,
298
+ SpriteRenderer: engineCore.SpriteRenderer,
299
+ TextRenderer: engineCore.TextRenderer
300
+ };
301
+
302
+ exports.InterpolableValueType = void 0;
303
+ (function(InterpolableValueType) {
304
+ InterpolableValueType[InterpolableValueType["Float"] = 0] = "Float";
305
+ InterpolableValueType[InterpolableValueType["FloatArray"] = 1] = "FloatArray";
306
+ InterpolableValueType[InterpolableValueType["Vector2"] = 2] = "Vector2";
307
+ InterpolableValueType[InterpolableValueType["Vector3"] = 3] = "Vector3";
308
+ InterpolableValueType[InterpolableValueType["Vector4"] = 4] = "Vector4";
309
+ InterpolableValueType[InterpolableValueType["Quaternion"] = 5] = "Quaternion";
310
+ InterpolableValueType[InterpolableValueType["Color"] = 6] = "Color";
311
+ InterpolableValueType[InterpolableValueType["Array"] = 7] = "Array";
312
+ InterpolableValueType[InterpolableValueType["Boolean"] = 8] = "Boolean";
313
+ InterpolableValueType[InterpolableValueType["Rect"] = 9] = "Rect";
314
+ InterpolableValueType[InterpolableValueType["ReferResource"] = 10] = "ReferResource";
315
+ })(exports.InterpolableValueType || (exports.InterpolableValueType = {}));
316
+ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
317
+ function AnimationClipDecoder() {}
318
+ AnimationClipDecoder.decode = function decode(engine, bufferReader) {
319
+ return new Promise(function(resolve) {
320
+ var name = bufferReader.nextStr();
321
+ var clip = new engineCore.AnimationClip(name);
322
+ var eventsLen = bufferReader.nextUint16();
323
+ for(var i = 0; i < eventsLen; ++i){
324
+ var event = new engineCore.AnimationEvent();
325
+ event.time = bufferReader.nextFloat32();
326
+ event.functionName = bufferReader.nextStr();
327
+ event.parameter = JSON.parse(bufferReader.nextStr()).val;
328
+ clip.addEvent(event);
329
+ }
330
+ var curveBindingsLen = bufferReader.nextUint16();
331
+ for(var i1 = 0; i1 < curveBindingsLen; ++i1){
332
+ var relativePath = bufferReader.nextStr();
333
+ var componentStr = bufferReader.nextStr();
334
+ var componentType = ComponentMap[componentStr];
335
+ var property = bufferReader.nextStr();
336
+ var curve = void 0;
337
+ var interpolation = bufferReader.nextUint8();
338
+ var keysLen = bufferReader.nextUint16();
339
+ var curveType = bufferReader.nextStr();
340
+ switch(curveType){
341
+ case "AnimationFloatCurve":
342
+ {
343
+ curve = new engineCore.AnimationFloatCurve();
344
+ curve.interpolation = interpolation;
345
+ for(var j = 0; j < keysLen; ++j){
346
+ var keyframe = new engineCore.Keyframe();
347
+ keyframe.time = bufferReader.nextFloat32();
348
+ keyframe.value = bufferReader.nextFloat32();
349
+ keyframe.inTangent = bufferReader.nextFloat32();
350
+ keyframe.outTangent = bufferReader.nextFloat32();
351
+ curve.addKey(keyframe);
352
+ }
353
+ break;
354
+ }
355
+ case "AnimationArrayCurve":
356
+ {
357
+ curve = new engineCore.AnimationArrayCurve();
358
+ curve.interpolation = interpolation;
359
+ for(var j1 = 0; j1 < keysLen; ++j1){
360
+ var keyframe1 = new engineCore.Keyframe();
361
+ keyframe1.time = bufferReader.nextFloat32();
362
+ var len = bufferReader.nextUint16();
363
+ keyframe1.value = Array.from(bufferReader.nextFloat32Array(len));
364
+ keyframe1.inTangent = Array.from(bufferReader.nextFloat32Array(len));
365
+ keyframe1.outTangent = Array.from(bufferReader.nextFloat32Array(len));
366
+ curve.addKey(keyframe1);
367
+ }
368
+ break;
369
+ }
370
+ case "AnimationFloatArrayCurve":
371
+ {
372
+ curve = new engineCore.AnimationFloatArrayCurve();
373
+ curve.interpolation = interpolation;
374
+ for(var j2 = 0; j2 < keysLen; ++j2){
375
+ var keyframe2 = new engineCore.Keyframe();
376
+ keyframe2.time = bufferReader.nextFloat32();
377
+ var len1 = bufferReader.nextUint16();
378
+ keyframe2.value = bufferReader.nextFloat32Array(len1);
379
+ keyframe2.inTangent = Array.from(bufferReader.nextFloat32Array(len1));
380
+ keyframe2.outTangent = Array.from(bufferReader.nextFloat32Array(len1));
381
+ curve.addKey(keyframe2);
382
+ }
383
+ break;
384
+ }
385
+ case "AnimationVector2Curve":
386
+ {
387
+ curve = new engineCore.AnimationVector2Curve();
388
+ curve.interpolation = interpolation;
389
+ for(var j3 = 0; j3 < keysLen; ++j3){
390
+ var keyframe3 = new engineCore.Keyframe();
391
+ keyframe3.time = bufferReader.nextFloat32();
392
+ keyframe3.value = new engineMath.Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
393
+ keyframe3.inTangent = new engineMath.Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
394
+ keyframe3.outTangent = new engineMath.Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
395
+ curve.addKey(keyframe3);
396
+ }
397
+ break;
398
+ }
399
+ case "AnimationVector3Curve":
400
+ {
401
+ curve = new engineCore.AnimationVector3Curve();
402
+ curve.interpolation = interpolation;
403
+ for(var j4 = 0; j4 < keysLen; ++j4){
404
+ var keyframe4 = new engineCore.Keyframe();
405
+ keyframe4.time = bufferReader.nextFloat32();
406
+ keyframe4.value = new engineMath.Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
407
+ keyframe4.inTangent = new engineMath.Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
408
+ keyframe4.outTangent = new engineMath.Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
409
+ curve.addKey(keyframe4);
410
+ }
411
+ break;
412
+ }
413
+ case "AnimationVector4Curve":
414
+ {
415
+ curve = new engineCore.AnimationVector4Curve();
416
+ curve.interpolation = interpolation;
417
+ var keyframe5 = new engineCore.Keyframe();
418
+ keyframe5.time = bufferReader.nextFloat32();
419
+ keyframe5.value = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
420
+ keyframe5.inTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
421
+ keyframe5.outTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
422
+ curve.addKey(keyframe5);
423
+ break;
424
+ }
425
+ case "AnimationColorCurve":
426
+ {
427
+ curve = new engineCore.AnimationColorCurve();
428
+ curve.interpolation = interpolation;
429
+ for(var j5 = 0; j5 < keysLen; ++j5){
430
+ var keyframe6 = new engineCore.Keyframe();
431
+ keyframe6.time = bufferReader.nextFloat32();
432
+ keyframe6.value = new engineMath.Color(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
433
+ keyframe6.inTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
434
+ keyframe6.outTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
435
+ curve.addKey(keyframe6);
436
+ }
437
+ break;
438
+ }
439
+ case "AnimationQuaternionCurve":
440
+ {
441
+ curve = new engineCore.AnimationQuaternionCurve();
442
+ curve.interpolation = interpolation;
443
+ for(var j6 = 0; j6 < keysLen; ++j6){
444
+ var keyframe7 = new engineCore.Keyframe();
445
+ keyframe7.time = bufferReader.nextFloat32();
446
+ keyframe7.value = new engineMath.Quaternion(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
447
+ keyframe7.inTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
448
+ keyframe7.outTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
449
+ curve.addKey(keyframe7);
450
+ }
451
+ break;
452
+ }
453
+ case "AnimationRefCurve":
454
+ {
455
+ curve = new engineCore.AnimationRefCurve();
456
+ curve.interpolation = interpolation;
457
+ for(var j7 = 0; j7 < keysLen; ++j7){
458
+ var keyframe8 = new engineCore.Keyframe();
459
+ keyframe8.time = bufferReader.nextFloat32();
460
+ keyframe8.value = JSON.parse(bufferReader.nextStr());
461
+ curve.addKey(keyframe8);
462
+ }
463
+ break;
464
+ }
465
+ }
466
+ clip.addCurveBinding(relativePath, componentType, property, curve);
467
+ }
468
+ resolve(clip);
469
+ });
470
+ };
471
+ return AnimationClipDecoder;
472
+ }();
473
+ exports.AnimationClipDecoder = __decorate([
474
+ decoder("AnimationClip")
475
+ ], exports.AnimationClipDecoder);
476
+
287
477
  exports.MeshDecoder = /*#__PURE__*/ function() {
288
478
  function MeshDecoder() {}
289
- MeshDecoder.decode = function decode(engine, bufferReader) {
479
+ MeshDecoder.decode = function decode(engine, bufferReader, restoredMesh) {
290
480
  return new Promise(function(resolve) {
291
- var modelMesh = new engineCore.ModelMesh(engine);
481
+ var modelMesh = restoredMesh || new engineCore.ModelMesh(engine);
292
482
  var jsonDataString = bufferReader.nextStr();
293
483
  var encodedMeshData = JSON.parse(jsonDataString);
294
484
  // @ts-ignore Vector3 is not compatible with {x: number, y: number, z: number}.
@@ -418,80 +608,22 @@ function float32ArrayToVector2(float32Array, vertexCount) {
418
608
  return array;
419
609
  }
420
610
 
421
- exports.Texture2DDecoder = /*#__PURE__*/ function() {
422
- function Texture2DDecoder() {}
423
- Texture2DDecoder.decode = function decode(engine, bufferReader) {
424
- return new Promise(function(resolve, reject) {
425
- var objectId = bufferReader.nextStr();
426
- var mipmap = !!bufferReader.nextUint8();
427
- var filterMode = bufferReader.nextUint8();
428
- var anisoLevel = bufferReader.nextUint8();
429
- var wrapModeU = bufferReader.nextUint8();
430
- var wrapModeV = bufferReader.nextUint8();
431
- var format = bufferReader.nextUint8();
432
- var width = bufferReader.nextUint16();
433
- var height = bufferReader.nextUint16();
434
- var isPixelBuffer = bufferReader.nextUint8();
435
- var mipCount = bufferReader.nextUint8();
436
- var imagesData = bufferReader.nextImagesData(mipCount);
437
- var texture2D = new engineCore.Texture2D(engine, width, height, format, mipmap);
438
- texture2D.filterMode = filterMode;
439
- texture2D.anisoLevel = anisoLevel;
440
- texture2D.wrapModeU = wrapModeU;
441
- texture2D.wrapModeV = wrapModeV;
442
- if (isPixelBuffer) {
443
- var pixelBuffer = imagesData[0];
444
- texture2D.setPixelBuffer(pixelBuffer);
445
- if (mipmap) {
446
- texture2D.generateMipmaps();
447
- for(var i = 1; i < mipCount; i++){
448
- var pixelBuffer1 = imagesData[i];
449
- texture2D.setPixelBuffer(pixelBuffer1, i);
450
- }
451
- }
452
- // @ts-ignore
453
- engine.resourceManager._objectPool[objectId] = texture2D;
454
- resolve(texture2D);
455
- } else {
456
- var blob = new window.Blob([
457
- imagesData[0]
458
- ]);
459
- var img = new Image();
460
- img.onload = function() {
461
- texture2D.setImageSource(img);
462
- var completedCount = 0;
463
- var onComplete = function() {
464
- completedCount++;
465
- if (completedCount >= mipCount) {
466
- resolve(texture2D);
467
- }
468
- };
469
- onComplete();
470
- if (mipmap) {
471
- var _loop = function(i) {
472
- var blob = new window.Blob([
473
- imagesData[i]
474
- ]);
475
- var img = new Image();
476
- img.onload = function() {
477
- texture2D.setImageSource(img, i);
478
- onComplete();
479
- };
480
- img.src = URL.createObjectURL(blob);
481
- };
482
- texture2D.generateMipmaps();
483
- for(var i = 1; i < mipCount; i++)_loop(i);
484
- }
485
- };
486
- img.src = URL.createObjectURL(blob);
611
+ var PrefabParser = /*#__PURE__*/ function() {
612
+ function PrefabParser() {}
613
+ PrefabParser.parseChildren = function parseChildren(entitiesConfig, entities, parentId) {
614
+ var children = entitiesConfig.get(parentId).children;
615
+ if (children && children.length > 0) {
616
+ var parent = entities.get(parentId);
617
+ for(var i = 0; i < children.length; i++){
618
+ var childId = children[i];
619
+ var entity = entities.get(childId);
620
+ parent.addChild(entity);
621
+ this.parseChildren(entitiesConfig, entities, childId);
487
622
  }
488
- });
623
+ }
489
624
  };
490
- return Texture2DDecoder;
625
+ return PrefabParser;
491
626
  }();
492
- exports.Texture2DDecoder = __decorate([
493
- decoder("Texture2D")
494
- ], exports.Texture2DDecoder);
495
627
 
496
628
  function _is_native_reflect_construct() {
497
629
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
@@ -673,218 +805,148 @@ var ReflectionParser = /*#__PURE__*/ function() {
673
805
  ReflectionParser.customParseComponentHandles = new Map();
674
806
  })();
675
807
 
676
- var PrefabParser = /*#__PURE__*/ function() {
677
- function PrefabParser() {}
678
- PrefabParser.parseChildren = function parseChildren(entitiesConfig, entities, parentId) {
679
- var children = entitiesConfig.get(parentId).children;
680
- if (children && children.length > 0) {
681
- var parent = entities.get(parentId);
682
- for(var i = 0; i < children.length; i++){
683
- var childId = children[i];
684
- var entity = entities.get(childId);
685
- parent.addChild(entity);
686
- this.parseChildren(entitiesConfig, entities, childId);
687
- }
688
- }
689
- };
690
- return PrefabParser;
691
- }();
692
-
693
- var ComponentMap = {
694
- Transform: engineCore.Transform,
695
- Animator: engineCore.Animator,
696
- DirectLight: engineCore.DirectLight,
697
- Camera: engineCore.Camera,
698
- MeshRenderer: engineCore.MeshRenderer,
699
- ParticleRenderer: engineCore.ParticleRenderer,
700
- PointLight: engineCore.PointLight,
701
- SpotLight: engineCore.SpotLight,
702
- Script: engineCore.Script,
703
- SpriteMask: engineCore.SpriteMask,
704
- SpriteRenderer: engineCore.SpriteRenderer,
705
- TextRenderer: engineCore.TextRenderer
706
- };
707
-
708
- exports.InterpolableValueType = void 0;
709
- (function(InterpolableValueType) {
710
- InterpolableValueType[InterpolableValueType["Float"] = 0] = "Float";
711
- InterpolableValueType[InterpolableValueType["FloatArray"] = 1] = "FloatArray";
712
- InterpolableValueType[InterpolableValueType["Vector2"] = 2] = "Vector2";
713
- InterpolableValueType[InterpolableValueType["Vector3"] = 3] = "Vector3";
714
- InterpolableValueType[InterpolableValueType["Vector4"] = 4] = "Vector4";
715
- InterpolableValueType[InterpolableValueType["Quaternion"] = 5] = "Quaternion";
716
- InterpolableValueType[InterpolableValueType["Color"] = 6] = "Color";
717
- InterpolableValueType[InterpolableValueType["Array"] = 7] = "Array";
718
- InterpolableValueType[InterpolableValueType["Boolean"] = 8] = "Boolean";
719
- InterpolableValueType[InterpolableValueType["Rect"] = 9] = "Rect";
720
- InterpolableValueType[InterpolableValueType["ReferResource"] = 10] = "ReferResource";
721
- })(exports.InterpolableValueType || (exports.InterpolableValueType = {}));
722
- exports.AnimationClipDecoder = /*#__PURE__*/ function() {
723
- function AnimationClipDecoder() {}
724
- AnimationClipDecoder.decode = function decode(engine, bufferReader) {
725
- return new Promise(function(resolve) {
726
- var name = bufferReader.nextStr();
727
- var clip = new engineCore.AnimationClip(name);
728
- var eventsLen = bufferReader.nextUint16();
729
- for(var i = 0; i < eventsLen; ++i){
730
- var event = new engineCore.AnimationEvent();
731
- event.time = bufferReader.nextFloat32();
732
- event.functionName = bufferReader.nextStr();
733
- event.parameter = JSON.parse(bufferReader.nextStr()).val;
734
- clip.addEvent(event);
735
- }
736
- var curveBindingsLen = bufferReader.nextUint16();
737
- for(var i1 = 0; i1 < curveBindingsLen; ++i1){
738
- var relativePath = bufferReader.nextStr();
739
- var componentStr = bufferReader.nextStr();
740
- var componentType = ComponentMap[componentStr];
741
- var property = bufferReader.nextStr();
742
- var curve = void 0;
743
- var interpolation = bufferReader.nextUint8();
744
- var keysLen = bufferReader.nextUint16();
745
- var curveType = bufferReader.nextStr();
746
- switch(curveType){
747
- case "AnimationFloatCurve":
748
- {
749
- curve = new engineCore.AnimationFloatCurve();
750
- curve.interpolation = interpolation;
751
- for(var j = 0; j < keysLen; ++j){
752
- var keyframe = new engineCore.Keyframe();
753
- keyframe.time = bufferReader.nextFloat32();
754
- keyframe.value = bufferReader.nextFloat32();
755
- keyframe.inTangent = bufferReader.nextFloat32();
756
- keyframe.outTangent = bufferReader.nextFloat32();
757
- curve.addKey(keyframe);
758
- }
759
- break;
760
- }
761
- case "AnimationArrayCurve":
762
- {
763
- curve = new engineCore.AnimationArrayCurve();
764
- curve.interpolation = interpolation;
765
- for(var j1 = 0; j1 < keysLen; ++j1){
766
- var keyframe1 = new engineCore.Keyframe();
767
- keyframe1.time = bufferReader.nextFloat32();
768
- var len = bufferReader.nextUint16();
769
- keyframe1.value = Array.from(bufferReader.nextFloat32Array(len));
770
- keyframe1.inTangent = Array.from(bufferReader.nextFloat32Array(len));
771
- keyframe1.outTangent = Array.from(bufferReader.nextFloat32Array(len));
772
- curve.addKey(keyframe1);
773
- }
774
- break;
775
- }
776
- case "AnimationFloatArrayCurve":
777
- {
778
- curve = new engineCore.AnimationFloatArrayCurve();
779
- curve.interpolation = interpolation;
780
- for(var j2 = 0; j2 < keysLen; ++j2){
781
- var keyframe2 = new engineCore.Keyframe();
782
- keyframe2.time = bufferReader.nextFloat32();
783
- var len1 = bufferReader.nextUint16();
784
- keyframe2.value = bufferReader.nextFloat32Array(len1);
785
- keyframe2.inTangent = Array.from(bufferReader.nextFloat32Array(len1));
786
- keyframe2.outTangent = Array.from(bufferReader.nextFloat32Array(len1));
787
- curve.addKey(keyframe2);
788
- }
789
- break;
790
- }
791
- case "AnimationVector2Curve":
792
- {
793
- curve = new engineCore.AnimationVector2Curve();
794
- curve.interpolation = interpolation;
795
- for(var j3 = 0; j3 < keysLen; ++j3){
796
- var keyframe3 = new engineCore.Keyframe();
797
- keyframe3.time = bufferReader.nextFloat32();
798
- keyframe3.value = new engineMath.Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
799
- keyframe3.inTangent = new engineMath.Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
800
- keyframe3.outTangent = new engineMath.Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
801
- curve.addKey(keyframe3);
802
- }
803
- break;
804
- }
805
- case "AnimationVector3Curve":
806
- {
807
- curve = new engineCore.AnimationVector3Curve();
808
- curve.interpolation = interpolation;
809
- for(var j4 = 0; j4 < keysLen; ++j4){
810
- var keyframe4 = new engineCore.Keyframe();
811
- keyframe4.time = bufferReader.nextFloat32();
812
- keyframe4.value = new engineMath.Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
813
- keyframe4.inTangent = new engineMath.Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
814
- keyframe4.outTangent = new engineMath.Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
815
- curve.addKey(keyframe4);
816
- }
817
- break;
818
- }
819
- case "AnimationVector4Curve":
820
- {
821
- curve = new engineCore.AnimationVector4Curve();
822
- curve.interpolation = interpolation;
823
- var keyframe5 = new engineCore.Keyframe();
824
- keyframe5.time = bufferReader.nextFloat32();
825
- keyframe5.value = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
826
- keyframe5.inTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
827
- keyframe5.outTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
828
- curve.addKey(keyframe5);
829
- break;
830
- }
831
- case "AnimationColorCurve":
832
- {
833
- curve = new engineCore.AnimationColorCurve();
834
- curve.interpolation = interpolation;
835
- for(var j5 = 0; j5 < keysLen; ++j5){
836
- var keyframe6 = new engineCore.Keyframe();
837
- keyframe6.time = bufferReader.nextFloat32();
838
- keyframe6.value = new engineMath.Color(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
839
- keyframe6.inTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
840
- keyframe6.outTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
841
- curve.addKey(keyframe6);
842
- }
843
- break;
844
- }
845
- case "AnimationQuaternionCurve":
846
- {
847
- curve = new engineCore.AnimationQuaternionCurve();
848
- curve.interpolation = interpolation;
849
- for(var j6 = 0; j6 < keysLen; ++j6){
850
- var keyframe7 = new engineCore.Keyframe();
851
- keyframe7.time = bufferReader.nextFloat32();
852
- keyframe7.value = new engineMath.Quaternion(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
853
- keyframe7.inTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
854
- keyframe7.outTangent = new engineMath.Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
855
- curve.addKey(keyframe7);
856
- }
857
- break;
858
- }
859
- case "AnimationRefCurve":
860
- {
861
- curve = new engineCore.AnimationRefCurve();
862
- curve.interpolation = interpolation;
863
- for(var j7 = 0; j7 < keysLen; ++j7){
864
- var keyframe8 = new engineCore.Keyframe();
865
- keyframe8.time = bufferReader.nextFloat32();
866
- keyframe8.value = JSON.parse(bufferReader.nextStr());
867
- curve.addKey(keyframe8);
868
- }
869
- break;
870
- }
808
+ exports.Texture2DDecoder = /*#__PURE__*/ function() {
809
+ function Texture2DDecoder() {}
810
+ Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
811
+ return new Promise(function(resolve, reject) {
812
+ var objectId = bufferReader.nextStr();
813
+ var mipmap = !!bufferReader.nextUint8();
814
+ var filterMode = bufferReader.nextUint8();
815
+ var anisoLevel = bufferReader.nextUint8();
816
+ var wrapModeU = bufferReader.nextUint8();
817
+ var wrapModeV = bufferReader.nextUint8();
818
+ var format = bufferReader.nextUint8();
819
+ var width = bufferReader.nextUint16();
820
+ var height = bufferReader.nextUint16();
821
+ var isPixelBuffer = bufferReader.nextUint8();
822
+ var mipCount = bufferReader.nextUint8();
823
+ var imagesData = bufferReader.nextImagesData(mipCount);
824
+ var texture2D = restoredTexture || new engineCore.Texture2D(engine, width, height, format, mipmap);
825
+ texture2D.filterMode = filterMode;
826
+ texture2D.anisoLevel = anisoLevel;
827
+ texture2D.wrapModeU = wrapModeU;
828
+ texture2D.wrapModeV = wrapModeV;
829
+ if (isPixelBuffer) {
830
+ var pixelBuffer = imagesData[0];
831
+ texture2D.setPixelBuffer(pixelBuffer);
832
+ if (mipmap) {
833
+ texture2D.generateMipmaps();
834
+ for(var i = 1; i < mipCount; i++){
835
+ var pixelBuffer1 = imagesData[i];
836
+ texture2D.setPixelBuffer(pixelBuffer1, i);
837
+ }
871
838
  }
872
- clip.addCurveBinding(relativePath, componentType, property, curve);
839
+ // @ts-ignore
840
+ engine.resourceManager._objectPool[objectId] = texture2D;
841
+ resolve(texture2D);
842
+ } else {
843
+ var blob = new window.Blob([
844
+ imagesData[0]
845
+ ]);
846
+ var img = new Image();
847
+ img.onload = function() {
848
+ texture2D.setImageSource(img);
849
+ var completedCount = 0;
850
+ var onComplete = function() {
851
+ completedCount++;
852
+ if (completedCount >= mipCount) {
853
+ resolve(texture2D);
854
+ }
855
+ };
856
+ onComplete();
857
+ if (mipmap) {
858
+ var _loop = function(i) {
859
+ var blob = new window.Blob([
860
+ imagesData[i]
861
+ ]);
862
+ var img = new Image();
863
+ img.onload = function() {
864
+ texture2D.setImageSource(img, i);
865
+ onComplete();
866
+ };
867
+ img.src = URL.createObjectURL(blob);
868
+ };
869
+ texture2D.generateMipmaps();
870
+ for(var i = 1; i < mipCount; i++)_loop(i);
871
+ }
872
+ };
873
+ img.src = URL.createObjectURL(blob);
873
874
  }
874
- resolve(clip);
875
875
  });
876
876
  };
877
- return AnimationClipDecoder;
877
+ return Texture2DDecoder;
878
878
  }();
879
- exports.AnimationClipDecoder = __decorate([
880
- decoder("AnimationClip")
881
- ], exports.AnimationClipDecoder);
879
+ exports.Texture2DDecoder = __decorate([
880
+ decoder("Texture2D")
881
+ ], exports.Texture2DDecoder);
882
882
 
883
- exports.SpecularMode = void 0;
884
- (function(SpecularMode) {
885
- SpecularMode["Sky"] = "Sky";
886
- SpecularMode["Custom"] = "Custom";
887
- })(exports.SpecularMode || (exports.SpecularMode = {}));
883
+ exports.EditorTextureLoader = /*#__PURE__*/ function(Loader1) {
884
+ _inherits(EditorTextureLoader, Loader1);
885
+ function EditorTextureLoader() {
886
+ return Loader1.apply(this, arguments);
887
+ }
888
+ var _proto = EditorTextureLoader.prototype;
889
+ _proto.load = function load(item, resourceManager) {
890
+ var _this = this;
891
+ return new engineCore.AssetPromise(function(resolve, reject) {
892
+ var request = _this.request;
893
+ request(item.url, _extends({}, item, {
894
+ type: "arraybuffer"
895
+ })).then(function(data) {
896
+ decode(data, resourceManager.engine).then(function(texture) {
897
+ resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
898
+ _inherits(_class, ContentRestorer);
899
+ function _class() {
900
+ return ContentRestorer.apply(this, arguments);
901
+ }
902
+ var _proto = _class.prototype;
903
+ _proto.restoreContent = function restoreContent() {
904
+ return request(item.url, _extends({}, item, {
905
+ type: "arraybuffer"
906
+ })).then(function(data) {
907
+ return decode(data, resourceManager.engine, texture);
908
+ });
909
+ };
910
+ return _class;
911
+ }(engineCore.ContentRestorer))(texture));
912
+ resolve(texture);
913
+ });
914
+ }).catch(reject);
915
+ });
916
+ };
917
+ return EditorTextureLoader;
918
+ }(engineCore.Loader);
919
+ exports.EditorTextureLoader = __decorate([
920
+ engineCore.resourceLoader("EditorTexture2D", [
921
+ "prefab"
922
+ ], true)
923
+ ], exports.EditorTextureLoader);
924
+
925
+ exports.MeshLoader = /*#__PURE__*/ function(Loader1) {
926
+ _inherits(MeshLoader, Loader1);
927
+ function MeshLoader() {
928
+ return Loader1.apply(this, arguments);
929
+ }
930
+ var _proto = MeshLoader.prototype;
931
+ _proto.load = function load(item, resourceManager) {
932
+ var _this = this;
933
+ return new engineCore.AssetPromise(function(resolve, reject) {
934
+ _this.request(item.url, {
935
+ type: "arraybuffer"
936
+ }).then(function(data) {
937
+ decode(data, resourceManager.engine).then(function(mesh) {
938
+ resolve(mesh);
939
+ });
940
+ }).catch(reject);
941
+ });
942
+ };
943
+ return MeshLoader;
944
+ }(engineCore.Loader);
945
+ exports.MeshLoader = __decorate([
946
+ engineCore.resourceLoader("Mesh", [
947
+ "prefab"
948
+ ], true)
949
+ ], exports.MeshLoader);
888
950
 
889
951
  function _array_like_to_array(arr, len) {
890
952
  if (len == null || len > arr.length) len = arr.length;
@@ -1041,57 +1103,11 @@ var SceneParserContext = /*#__PURE__*/ function() {
1041
1103
  return SceneParser;
1042
1104
  }();
1043
1105
 
1044
- exports.MeshLoader = /*#__PURE__*/ function(Loader1) {
1045
- _inherits(MeshLoader, Loader1);
1046
- function MeshLoader() {
1047
- return Loader1.apply(this, arguments);
1048
- }
1049
- var _proto = MeshLoader.prototype;
1050
- _proto.load = function load(item, resourceManager) {
1051
- var _this = this;
1052
- return new engineCore.AssetPromise(function(resolve, reject) {
1053
- _this.request(item.url, {
1054
- type: "arraybuffer"
1055
- }).then(function(data) {
1056
- decode(data, resourceManager.engine).then(function(mesh) {
1057
- resolve(mesh);
1058
- });
1059
- }).catch(reject);
1060
- });
1061
- };
1062
- return MeshLoader;
1063
- }(engineCore.Loader);
1064
- exports.MeshLoader = __decorate([
1065
- engineCore.resourceLoader("Mesh", [
1066
- "prefab"
1067
- ], true)
1068
- ], exports.MeshLoader);
1069
-
1070
- exports.EditorTextureLoader = /*#__PURE__*/ function(Loader1) {
1071
- _inherits(EditorTextureLoader, Loader1);
1072
- function EditorTextureLoader() {
1073
- return Loader1.apply(this, arguments);
1074
- }
1075
- var _proto = EditorTextureLoader.prototype;
1076
- _proto.load = function load(item, resourceManager) {
1077
- var _this = this;
1078
- return new engineCore.AssetPromise(function(resolve, reject) {
1079
- _this.request(item.url, {
1080
- type: "arraybuffer"
1081
- }).then(function(data) {
1082
- decode(data, resourceManager.engine).then(function(texture) {
1083
- resolve(texture);
1084
- });
1085
- }).catch(reject);
1086
- });
1087
- };
1088
- return EditorTextureLoader;
1089
- }(engineCore.Loader);
1090
- exports.EditorTextureLoader = __decorate([
1091
- engineCore.resourceLoader("EditorTexture2D", [
1092
- "prefab"
1093
- ], true)
1094
- ], exports.EditorTextureLoader);
1106
+ exports.SpecularMode = void 0;
1107
+ (function(SpecularMode) {
1108
+ SpecularMode["Sky"] = "Sky";
1109
+ SpecularMode["Custom"] = "Custom";
1110
+ })(exports.SpecularMode || (exports.SpecularMode = {}));
1095
1111
 
1096
1112
  /**
1097
1113
  * Decode engine binary resource.
@@ -1099,9 +1115,13 @@ exports.EditorTextureLoader = __decorate([
1099
1115
  * @param engine - engine
1100
1116
  * @returns
1101
1117
  */ function decode(arrayBuffer, engine) {
1118
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
1119
+ args[_key - 2] = arguments[_key];
1120
+ }
1121
+ var _decoderMap_header_type;
1102
1122
  var header = FileHeader.decode(arrayBuffer);
1103
1123
  var bufferReader = new BufferReader(new Uint8Array(arrayBuffer), header.headerLength, header.dataLength);
1104
- return decoderMap[header.type].decode(engine, bufferReader).then(function(object) {
1124
+ return (_decoderMap_header_type = decoderMap[header.type]).decode.apply(_decoderMap_header_type, [].concat(engine, bufferReader, args)).then(function(object) {
1105
1125
  object.name = header.name;
1106
1126
  return object;
1107
1127
  });
@@ -1269,39 +1289,42 @@ BufferLoader = __decorate([
1269
1289
  ], BufferLoader);
1270
1290
 
1271
1291
  var EnvLoader = /*#__PURE__*/ function(Loader1) {
1272
- _inherits(EnvLoader, Loader1);
1273
- function EnvLoader() {
1292
+ _inherits(EnvLoader1, Loader1);
1293
+ function EnvLoader1() {
1274
1294
  return Loader1.apply(this, arguments);
1275
1295
  }
1276
- var _proto = EnvLoader.prototype;
1296
+ var _proto = EnvLoader1.prototype;
1277
1297
  _proto.load = function load(item, resourceManager) {
1278
1298
  var _this = this;
1279
1299
  return new engineCore.AssetPromise(function(resolve, reject) {
1280
- _this.request(item.url, {
1300
+ var engine = resourceManager.engine;
1301
+ var request = _this.request;
1302
+ request(item.url, _extends({}, item, {
1281
1303
  type: "arraybuffer"
1282
- }).then(function(arraybuffer) {
1283
- var _this;
1284
- var shArray = new Float32Array(arraybuffer, 0, 27);
1285
- var shByteLength = 27 * 4;
1286
- var size = (_this = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _this[0];
1287
- var engine = resourceManager.engine;
1288
- var texture = new engineCore.TextureCube(engine, size);
1289
- texture.filterMode = engineCore.TextureFilterMode.Trilinear;
1290
- var mipmapCount = texture.mipmapCount;
1291
- var offset = shByteLength + 2;
1292
- for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
1293
- var mipSize = size >> mipLevel;
1294
- for(var face = 0; face < 6; face++){
1295
- var dataSize = mipSize * mipSize * 4;
1296
- var data = new Uint8Array(arraybuffer, offset, dataSize);
1297
- offset += dataSize;
1298
- texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + face, data, mipLevel);
1304
+ })).then(function(arraybuffer) {
1305
+ var texture = EnvLoader._setTextureByBuffer(engine, arraybuffer);
1306
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
1307
+ _inherits(_class, ContentRestorer);
1308
+ function _class() {
1309
+ return ContentRestorer.apply(this, arguments);
1299
1310
  }
1300
- }
1311
+ var _proto = _class.prototype;
1312
+ _proto.restoreContent = function restoreContent() {
1313
+ return new engineCore.AssetPromise(function(resolve, reject) {
1314
+ request(item.url, _extends({}, item, {
1315
+ type: "arraybuffer"
1316
+ })).then(function(buffer) {
1317
+ EnvLoader._setTextureByBuffer(engine, buffer, texture);
1318
+ resolve(texture);
1319
+ }).catch(reject);
1320
+ });
1321
+ };
1322
+ return _class;
1323
+ }(engineCore.ContentRestorer))(texture));
1301
1324
  var ambientLight = new engineCore.AmbientLight(engine);
1302
1325
  var sh = new engineMath.SphericalHarmonics3();
1303
1326
  ambientLight.diffuseMode = engineCore.DiffuseMode.SphericalHarmonics;
1304
- sh.copyFromArray(shArray);
1327
+ sh.copyFromArray(new Float32Array(arraybuffer, 0, 27));
1305
1328
  ambientLight.diffuseSphericalHarmonics = sh;
1306
1329
  ambientLight.specularTexture = texture;
1307
1330
  ambientLight.specularTextureDecodeRGBM = true;
@@ -1311,7 +1334,28 @@ var EnvLoader = /*#__PURE__*/ function(Loader1) {
1311
1334
  });
1312
1335
  });
1313
1336
  };
1314
- return EnvLoader;
1337
+ /**
1338
+ * @internal
1339
+ */ EnvLoader1._setTextureByBuffer = function _setTextureByBuffer(engine, buffer, texture) {
1340
+ var _this;
1341
+ var shByteLength = 27 * 4;
1342
+ var size = (_this = new Uint16Array(buffer, shByteLength, 1)) == null ? void 0 : _this[0];
1343
+ texture || (texture = new engineCore.TextureCube(engine, size));
1344
+ texture.filterMode = engineCore.TextureFilterMode.Trilinear;
1345
+ var mipmapCount = texture.mipmapCount;
1346
+ var offset = shByteLength + 2;
1347
+ for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
1348
+ var mipSize = size >> mipLevel;
1349
+ for(var face = 0; face < 6; face++){
1350
+ var dataSize = mipSize * mipSize * 4;
1351
+ var data = new Uint8Array(buffer, offset, dataSize);
1352
+ offset += dataSize;
1353
+ texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + face, data, mipLevel);
1354
+ }
1355
+ }
1356
+ return texture;
1357
+ };
1358
+ return EnvLoader1;
1315
1359
  }(engineCore.Loader);
1316
1360
  EnvLoader = __decorate([
1317
1361
  engineCore.resourceLoader(engineCore.AssetType.Env, [
@@ -1599,7 +1643,7 @@ var TextureWrapMode;
1599
1643
  var glTFItems = this.glTF[glTFSchemaMap[type]];
1600
1644
  if (glTFItems && (index === undefined || glTFItems[index])) {
1601
1645
  if (index === undefined) {
1602
- resource = type === 7 ? glTFItems.map(function(_, index) {
1646
+ resource = type === 8 ? glTFItems.map(function(_, index) {
1603
1647
  return _this.get(type, index);
1604
1648
  }) : Promise.all(glTFItems.map(function(_, index) {
1605
1649
  return _this.get(type, index);
@@ -1621,11 +1665,11 @@ var TextureWrapMode;
1621
1665
  _this.glTF = json;
1622
1666
  return Promise.all([
1623
1667
  _this.get(1),
1624
- _this.get(4),
1625
1668
  _this.get(5),
1626
1669
  _this.get(6),
1627
- _this.get(8),
1670
+ _this.get(7),
1628
1671
  _this.get(9),
1672
+ _this.get(10),
1629
1673
  _this.get(2)
1630
1674
  ]).then(function() {
1631
1675
  var glTFResource = _this.glTFResource;
@@ -1663,7 +1707,7 @@ var TextureWrapMode;
1663
1707
  var _this = this;
1664
1708
  var glTFResourceKey = glTFResourceMap[type];
1665
1709
  if (!glTFResourceKey) return;
1666
- if (type === 7) {
1710
+ if (type === 8) {
1667
1711
  var _this_glTFResource, _glTFResourceKey;
1668
1712
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
1669
1713
  } else {
@@ -1671,7 +1715,7 @@ var TextureWrapMode;
1671
1715
  resource.then(function(item) {
1672
1716
  var _this_glTFResource, _glTFResourceKey;
1673
1717
  ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
1674
- if (type === 6) {
1718
+ if (type === 7) {
1675
1719
  for(var i = 0, length = item.length; i < length; i++){
1676
1720
  var mesh = item[i];
1677
1721
  // @ts-ignore
@@ -1711,17 +1755,18 @@ exports.GLTFParserType = void 0;
1711
1755
  GLTFParserType[GLTFParserType["Validator"] = 1] = "Validator";
1712
1756
  GLTFParserType[GLTFParserType["Scene"] = 2] = "Scene";
1713
1757
  GLTFParserType[GLTFParserType["Buffer"] = 3] = "Buffer";
1714
- GLTFParserType[GLTFParserType["Texture"] = 4] = "Texture";
1715
- GLTFParserType[GLTFParserType["Material"] = 5] = "Material";
1716
- GLTFParserType[GLTFParserType["Mesh"] = 6] = "Mesh";
1717
- GLTFParserType[GLTFParserType["Entity"] = 7] = "Entity";
1718
- GLTFParserType[GLTFParserType["Skin"] = 8] = "Skin";
1719
- GLTFParserType[GLTFParserType["Animation"] = 9] = "Animation";
1758
+ GLTFParserType[GLTFParserType["BufferView"] = 4] = "BufferView";
1759
+ GLTFParserType[GLTFParserType["Texture"] = 5] = "Texture";
1760
+ GLTFParserType[GLTFParserType["Material"] = 6] = "Material";
1761
+ GLTFParserType[GLTFParserType["Mesh"] = 7] = "Mesh";
1762
+ GLTFParserType[GLTFParserType["Entity"] = 8] = "Entity";
1763
+ GLTFParserType[GLTFParserType["Skin"] = 9] = "Skin";
1764
+ GLTFParserType[GLTFParserType["Animation"] = 10] = "Animation";
1720
1765
  })(exports.GLTFParserType || (exports.GLTFParserType = {}));
1721
1766
  var _obj;
1722
- var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[4] = "textures", _obj[5] = "materials", _obj[6] = "meshes", _obj[7] = "nodes", _obj[8] = "skins", _obj[9] = "animations", _obj);
1767
+ var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[5] = "textures", _obj[6] = "materials", _obj[7] = "meshes", _obj[8] = "nodes", _obj[9] = "skins", _obj[10] = "animations", _obj[4] = "bufferViews", _obj);
1723
1768
  var _obj1;
1724
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "sceneRoots", _obj1[4] = "textures", _obj1[5] = "materials", _obj1[6] = "meshes", _obj1[7] = "entities", _obj1[8] = "skins", _obj1[9] = "animations", _obj1);
1769
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1);
1725
1770
  function registerGLTFParser(pipeline) {
1726
1771
  return function(Parser) {
1727
1772
  var parser = new Parser();
@@ -1826,113 +1871,68 @@ function registerGLTFParser(pipeline) {
1826
1871
  };
1827
1872
  GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
1828
1873
  var componentType = accessor.componentType;
1829
- var _accessor_bufferView;
1830
- var bufferViewIndex = (_accessor_bufferView = accessor.bufferView) != null ? _accessor_bufferView : 0;
1831
- var bufferView = bufferViews[bufferViewIndex];
1832
- return context.get(exports.GLTFParserType.Buffer).then(function(buffers) {
1833
- var bufferIndex = bufferView.buffer;
1834
- var buffer = buffers[bufferIndex];
1835
- var _bufferView_byteOffset;
1836
- var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
1837
- var _accessor_byteOffset;
1838
- var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
1839
- var TypedArray = GLTFUtils.getComponentType(componentType);
1840
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1841
- var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
1842
- var elementStride = dataElementSize * dataElementBytes;
1843
- var accessorCount = accessor.count;
1844
- var bufferStride = bufferView.byteStride;
1845
- var bufferInfo;
1846
- // According to the glTF official documentation only byteStride not undefined is allowed
1847
- if (bufferStride !== undefined && bufferStride !== elementStride) {
1848
- var bufferSlice = Math.floor(byteOffset / bufferStride);
1849
- var bufferCacheKey = bufferViewIndex + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
1850
- var accessorBufferCache = context.accessorBufferCache;
1851
- bufferInfo = accessorBufferCache[bufferCacheKey];
1852
- if (!bufferInfo) {
1853
- var offset = bufferByteOffset + bufferSlice * bufferStride;
1854
- var count = accessorCount * (bufferStride / dataElementBytes);
1855
- var data = new TypedArray(buffer, offset, count);
1856
- accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
1857
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
1874
+ var TypedArray = GLTFUtils.getComponentType(componentType);
1875
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1876
+ var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
1877
+ var elementStride = dataElementSize * dataElementBytes;
1878
+ var accessorCount = accessor.count;
1879
+ var promise;
1880
+ if (accessor.bufferView !== undefined) {
1881
+ var bufferViewIndex = accessor.bufferView;
1882
+ var bufferView = bufferViews[bufferViewIndex];
1883
+ promise = context.get(exports.GLTFParserType.BufferView, accessor.bufferView).then(function(bufferViewData) {
1884
+ var bufferIndex = bufferView.buffer;
1885
+ var _bufferViewData_byteOffset;
1886
+ var bufferByteOffset = (_bufferViewData_byteOffset = bufferViewData.byteOffset) != null ? _bufferViewData_byteOffset : 0;
1887
+ var _accessor_byteOffset;
1888
+ var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
1889
+ var bufferStride = bufferView.byteStride;
1890
+ var bufferInfo;
1891
+ // According to the glTF official documentation only byteStride not undefined is allowed
1892
+ if (bufferStride !== undefined && bufferStride !== elementStride) {
1893
+ var bufferSlice = Math.floor(byteOffset / bufferStride);
1894
+ var bufferCacheKey = bufferViewIndex + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
1895
+ var accessorBufferCache = context.accessorBufferCache;
1896
+ bufferInfo = accessorBufferCache[bufferCacheKey];
1897
+ if (!bufferInfo) {
1898
+ var offset = bufferByteOffset + bufferSlice * bufferStride;
1899
+ var count = accessorCount * (bufferStride / dataElementBytes);
1900
+ var data = new TypedArray(bufferViewData.buffer, offset, count);
1901
+ accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
1902
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
1903
+ }
1904
+ } else {
1905
+ var offset1 = bufferByteOffset + byteOffset;
1906
+ var count1 = accessorCount * dataElementSize;
1907
+ var data1 = new TypedArray(bufferViewData.buffer, offset1, count1);
1908
+ bufferInfo = new BufferInfo(data1, false, elementStride);
1909
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
1858
1910
  }
1859
- } else {
1860
- var offset1 = bufferByteOffset + byteOffset;
1861
- var count1 = accessorCount * dataElementSize;
1862
- var data1 = new TypedArray(buffer, offset1, count1);
1863
- bufferInfo = new BufferInfo(data1, false, elementStride);
1864
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
1865
- }
1866
- if (accessor.sparse) {
1867
- GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
1868
- }
1869
- return bufferInfo;
1870
- });
1911
+ return bufferInfo;
1912
+ });
1913
+ } else {
1914
+ var count = accessorCount * dataElementSize;
1915
+ var data = new TypedArray(count);
1916
+ var bufferInfo = new BufferInfo(data, false, elementStride);
1917
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(undefined, TypedArray, undefined, count));
1918
+ promise = Promise.resolve(bufferInfo);
1919
+ }
1920
+ return accessor.sparse ? promise.then(function(bufferInfo) {
1921
+ return GLTFUtils.processingSparseData(context, accessor, bufferInfo).then(function() {
1922
+ return bufferInfo;
1923
+ });
1924
+ }) : promise;
1871
1925
  };
1872
- GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
1873
- var bytesPerElement = data.BYTES_PER_ELEMENT;
1874
- var offset = accessorByteOffset % byteStride / bytesPerElement;
1875
- var stride = byteStride / bytesPerElement;
1876
- var vector3s = new Array(count);
1926
+ GLTFUtils.bufferToVector3Array = function bufferToVector3Array(buffer, byteOffset, count, normalized, componentType) {
1927
+ var baseOffset = byteOffset / buffer.BYTES_PER_ELEMENT;
1928
+ var stride = buffer.length / count;
1929
+ var vertices = new Array(count);
1930
+ var factor = normalized ? GLTFUtils.getNormalizedComponentScale(componentType) : 1;
1877
1931
  for(var i = 0; i < count; i++){
1878
- var index = offset + i * stride;
1879
- vector3s[i] = new engineMath.Vector3(data[index], data[index + 1], data[index + 2]);
1880
- }
1881
- return vector3s;
1882
- };
1883
- /**
1884
- * @deprecated
1885
- * Get accessor data.
1886
- */ GLTFUtils.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
1887
- var bufferViews = glTF.bufferViews;
1888
- var _accessor_bufferView;
1889
- var bufferView = bufferViews[(_accessor_bufferView = accessor.bufferView) != null ? _accessor_bufferView : 0];
1890
- var arrayBuffer = buffers[bufferView.buffer];
1891
- var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
1892
- var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
1893
- var byteOffset = accessorByteOffset + bufferViewByteOffset;
1894
- var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1895
- var length = accessorTypeSize * accessor.count;
1896
- var _bufferView_byteStride;
1897
- var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
1898
- var arrayType = GLTFUtils.getComponentType(accessor.componentType);
1899
- var uint8Array;
1900
- if (byteStride) {
1901
- var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
1902
- uint8Array = new Uint8Array(accessor.count * accessorByteSize);
1903
- var originalBufferView = new Uint8Array(arrayBuffer, bufferViewByteOffset, bufferView.byteLength);
1904
- for(var i = 0; i < accessor.count; i++){
1905
- for(var j = 0; j < accessorByteSize; j++){
1906
- uint8Array[i * accessorByteSize + j] = originalBufferView[i * byteStride + accessorByteOffset + j];
1907
- }
1908
- }
1909
- } else {
1910
- uint8Array = new Uint8Array(arrayBuffer.slice(byteOffset, byteOffset + length * arrayType.BYTES_PER_ELEMENT));
1911
- }
1912
- var typedArray = new arrayType(uint8Array.buffer);
1913
- if (accessor.sparse) {
1914
- var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
1915
- var indicesBufferView = bufferViews[indices.bufferView];
1916
- var valuesBufferView = bufferViews[values.bufferView];
1917
- var indicesArrayBuffer = buffers[indicesBufferView.buffer];
1918
- var valuesArrayBuffer = buffers[valuesBufferView.buffer];
1919
- var _indices_byteOffset, _indicesBufferView_byteOffset;
1920
- var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
1921
- var indicesByteLength = indicesBufferView.byteLength;
1922
- var _values_byteOffset, _valuesBufferView_byteOffset;
1923
- var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
1924
- var valuesByteLength = valuesBufferView.byteLength;
1925
- var indicesType = GLTFUtils.getComponentType(indices.componentType);
1926
- var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
1927
- var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
1928
- for(var i1 = 0; i1 < count; i1++){
1929
- var replaceIndex = indicesArray[i1];
1930
- for(var j1 = 0; j1 < accessorTypeSize; j1++){
1931
- typedArray[replaceIndex * accessorTypeSize + j1] = valuesArray[i1 * accessorTypeSize + j1];
1932
- }
1933
- }
1932
+ var index = baseOffset + i * stride;
1933
+ vertices[i] = new engineMath.Vector3(buffer[index] * factor, buffer[index + 1] * factor, buffer[index + 2] * factor);
1934
1934
  }
1935
- return typedArray;
1935
+ return vertices;
1936
1936
  };
1937
1937
  GLTFUtils.getBufferViewData = function getBufferViewData(bufferView, buffers) {
1938
1938
  var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
@@ -1941,40 +1941,43 @@ function registerGLTFParser(pipeline) {
1941
1941
  };
1942
1942
  /**
1943
1943
  * Get accessor data.
1944
- */ GLTFUtils.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
1944
+ */ GLTFUtils.processingSparseData = function processingSparseData(context, accessor, bufferInfo) {
1945
1945
  var restoreInfo = bufferInfo.restoreInfo;
1946
+ var bufferViews = context.glTF.bufferViews;
1946
1947
  var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1947
1948
  var TypedArray = GLTFUtils.getComponentType(accessor.componentType);
1948
1949
  var data = bufferInfo.data.slice();
1949
1950
  var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
1950
1951
  var indicesBufferView = bufferViews[indices.bufferView];
1951
1952
  var valuesBufferView = bufferViews[values.bufferView];
1952
- var indicesBufferIndex = indicesBufferView.buffer;
1953
- var valuesBufferIndex = valuesBufferView.buffer;
1954
- var indicesArrayBuffer = buffers[indicesBufferIndex];
1955
- var valuesArrayBuffer = buffers[valuesBufferIndex];
1956
- var _indices_byteOffset, _indicesBufferView_byteOffset;
1957
- var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
1958
- var indicesByteLength = indicesBufferView.byteLength;
1959
- var _values_byteOffset, _valuesBufferView_byteOffset;
1960
- var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
1961
- var valuesByteLength = valuesBufferView.byteLength;
1962
- restoreInfo.typeSize = accessorTypeSize;
1963
- restoreInfo.sparseCount = count;
1964
- var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
1965
- var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
1966
- var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
1967
- restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
1968
- var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
1969
- var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
1970
- restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
1971
- for(var i = 0; i < count; i++){
1972
- var replaceIndex = indicesArray[i];
1973
- for(var j = 0; j < accessorTypeSize; j++){
1974
- data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
1953
+ return Promise.all([
1954
+ context.get(exports.GLTFParserType.BufferView, indices.bufferView),
1955
+ context.get(exports.GLTFParserType.BufferView, values.bufferView)
1956
+ ]).then(function(param) {
1957
+ var indicesUint8Array = param[0], valuesUin8Array = param[1];
1958
+ var _indices_byteOffset, _indicesUint8Array_byteOffset;
1959
+ var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesUint8Array_byteOffset = indicesUint8Array.byteOffset) != null ? _indicesUint8Array_byteOffset : 0);
1960
+ var indicesByteLength = indicesUint8Array.byteLength;
1961
+ var _values_byteOffset, _valuesUin8Array_byteOffset;
1962
+ var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesUin8Array_byteOffset = valuesUin8Array.byteOffset) != null ? _valuesUin8Array_byteOffset : 0);
1963
+ var valuesByteLength = valuesUin8Array.byteLength;
1964
+ restoreInfo.typeSize = accessorTypeSize;
1965
+ restoreInfo.sparseCount = count;
1966
+ var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
1967
+ var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
1968
+ var indicesArray = new IndexTypeArray(indicesUint8Array.buffer, indicesByteOffset, indexLength);
1969
+ restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferView.buffer, IndexTypeArray, indicesByteOffset, indexLength);
1970
+ var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
1971
+ var valuesArray = new TypedArray(valuesUin8Array.buffer, valuesByteOffset, valueLength);
1972
+ restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferView.buffer, TypedArray, valuesByteOffset, valueLength);
1973
+ for(var i = 0; i < count; i++){
1974
+ var replaceIndex = indicesArray[i];
1975
+ for(var j = 0; j < accessorTypeSize; j++){
1976
+ data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
1977
+ }
1975
1978
  }
1976
- }
1977
- bufferInfo.data = data;
1979
+ bufferInfo.data = data;
1980
+ });
1978
1981
  };
1979
1982
  GLTFUtils.getIndexFormat = function getIndexFormat(type) {
1980
1983
  switch(type){
@@ -2072,28 +2075,29 @@ function registerGLTFParser(pipeline) {
2072
2075
  BIN: 0x004e4942
2073
2076
  };
2074
2077
  var dataView = new DataView(originBuffer);
2075
- // read header
2078
+ // Read header
2076
2079
  var header = {
2077
2080
  magic: dataView.getUint32(0, true),
2078
2081
  version: dataView.getUint32(UINT32_LENGTH, true),
2079
2082
  length: dataView.getUint32(2 * UINT32_LENGTH, true)
2080
2083
  };
2084
+ // Return the original buffer if it is not a glb
2081
2085
  if (header.magic !== GLB_HEADER_MAGIC) {
2082
2086
  return {
2083
2087
  originBuffer: originBuffer
2084
2088
  };
2085
2089
  }
2086
- // read main data
2090
+ // Read main data
2087
2091
  var chunkLength = dataView.getUint32(GLB_HEADER_LENGTH, true);
2088
2092
  var chunkType = dataView.getUint32(GLB_HEADER_LENGTH + UINT32_LENGTH, true);
2089
- // read glTF json
2093
+ // Read glTF json
2090
2094
  if (chunkType !== GLB_CHUNK_TYPES.JSON) {
2091
2095
  console.error("Invalid glb chunk type. Expected 0x4E4F534A, found 0x" + chunkType.toString(16));
2092
2096
  return null;
2093
2097
  }
2094
2098
  var glTFData = new Uint8Array(originBuffer, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2095
2099
  var glTF = JSON.parse(engineCore.Utils.decodeText(glTFData));
2096
- // read all buffers
2100
+ // Read all buffers
2097
2101
  var buffers = [];
2098
2102
  var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
2099
2103
  var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
@@ -2984,13 +2988,39 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2984
2988
  /**
2985
2989
  * @internal
2986
2990
  */ _proto.load = function load(item, resourceManager) {
2987
- return this.request(item.url, {
2988
- type: "arraybuffer"
2989
- }).then(function(buffer) {
2990
- return exports.KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
2991
- var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2992
- return exports.KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
2993
- });
2991
+ var _this = this;
2992
+ return new engineCore.AssetPromise(function(resolve, reject) {
2993
+ var request = _this.request;
2994
+ request(item.url, _extends({}, item, {
2995
+ type: "arraybuffer"
2996
+ })).then(function(buffer) {
2997
+ return exports.KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
2998
+ var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2999
+ return exports.KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
3000
+ }).then(function(texture) {
3001
+ resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
3002
+ _inherits(_class, ContentRestorer);
3003
+ function _class() {
3004
+ return ContentRestorer.apply(this, arguments);
3005
+ }
3006
+ var _proto = _class.prototype;
3007
+ _proto.restoreContent = function restoreContent() {
3008
+ return new engineCore.AssetPromise(function(resolve, reject) {
3009
+ request(item.url, _extends({}, item, {
3010
+ type: "arraybuffer"
3011
+ })).then(function(buffer) {
3012
+ return exports.KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
3013
+ var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
3014
+ return exports.KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params, texture);
3015
+ });
3016
+ }).then(resolve).catch(reject);
3017
+ });
3018
+ };
3019
+ return _class;
3020
+ }(engineCore.ContentRestorer))(texture));
3021
+ resolve(texture);
3022
+ });
3023
+ }).catch(reject);
2994
3024
  });
2995
3025
  };
2996
3026
  /**
@@ -3029,7 +3059,7 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3029
3059
  };
3030
3060
  });
3031
3061
  };
3032
- /** @internal */ KTX2Loader1._createTextureByBuffer = function _createTextureByBuffer(engine, transcodeResult, targetFormat, params) {
3062
+ /** @internal */ KTX2Loader1._createTextureByBuffer = function _createTextureByBuffer(engine, transcodeResult, targetFormat, params, restoredTexture) {
3033
3063
  var width = transcodeResult.width, height = transcodeResult.height, faces = transcodeResult.faces;
3034
3064
  var faceCount = faces.length;
3035
3065
  var mipmaps = faces[0];
@@ -3037,13 +3067,13 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3037
3067
  var engineFormat = this._getEngineTextureFormat(targetFormat, transcodeResult);
3038
3068
  var texture;
3039
3069
  if (faceCount !== 6) {
3040
- texture = new engineCore.Texture2D(engine, width, height, engineFormat, mipmap);
3070
+ texture = restoredTexture || new engineCore.Texture2D(engine, width, height, engineFormat, mipmap);
3041
3071
  for(var mipLevel = 0; mipLevel < mipmaps.length; mipLevel++){
3042
3072
  var data = mipmaps[mipLevel].data;
3043
3073
  texture.setPixelBuffer(data, mipLevel);
3044
3074
  }
3045
3075
  } else {
3046
- texture = new engineCore.TextureCube(engine, height, engineFormat, mipmap);
3076
+ texture = restoredTexture || new engineCore.TextureCube(engine, height, engineFormat, mipmap);
3047
3077
  for(var i = 0; i < faces.length; i++){
3048
3078
  var faceData = faces[i];
3049
3079
  for(var mipLevel1 = 0; mipLevel1 < mipmaps.length; mipLevel1++){
@@ -3240,16 +3270,16 @@ exports.KTX2Transcoder = void 0;
3240
3270
  var frame = restoreInfo.blendShape.frames[0];
3241
3271
  var position = restoreInfo.position;
3242
3272
  var positionData = _this._getBufferData(buffers, position.buffer);
3243
- frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
3273
+ frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.byteOffset, position.count, position.normalized, position.componentType);
3244
3274
  if (restoreInfo.normal) {
3245
3275
  var normal = restoreInfo.normal;
3246
3276
  var normalData = _this._getBufferData(buffers, normal.buffer);
3247
- frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
3277
+ frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.byteOffset, normal.count, normal.normalized, normal.componentType);
3248
3278
  }
3249
3279
  if (restoreInfo.tangent) {
3250
3280
  var tangent = restoreInfo.tangent;
3251
3281
  var tangentData = _this._getBufferData(buffers, tangent.buffer);
3252
- frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
3282
+ frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.byteOffset, tangent.count, tangent.normalized, tangent.componentType);
3253
3283
  }
3254
3284
  }
3255
3285
  mesh.uploadData(true);
@@ -3261,8 +3291,13 @@ exports.KTX2Transcoder = void 0;
3261
3291
  };
3262
3292
  _proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
3263
3293
  var main = restoreInfo.main;
3264
- var buffer = buffers[main.bufferIndex];
3265
- var data = new main.TypedArray(buffer, main.byteOffset, main.length);
3294
+ var data;
3295
+ if (main) {
3296
+ var buffer = buffers[main.bufferIndex];
3297
+ data = new main.TypedArray(buffer, main.byteOffset, main.length);
3298
+ } else {
3299
+ data = new main.TypedArray(main.length);
3300
+ }
3266
3301
  var sparseCount = restoreInfo.sparseCount;
3267
3302
  if (sparseCount) {
3268
3303
  var sparseIndex = restoreInfo.sparseIndices;
@@ -3335,11 +3370,12 @@ exports.KTX2Transcoder = void 0;
3335
3370
  };
3336
3371
  /**
3337
3372
  * @internal
3338
- */ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
3373
+ */ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, byteOffset, count, normalized, componentType) {
3339
3374
  this.buffer = buffer;
3340
- this.stride = stride;
3341
3375
  this.byteOffset = byteOffset;
3342
3376
  this.count = count;
3377
+ this.normalized = normalized;
3378
+ this.componentType = componentType;
3343
3379
  };
3344
3380
 
3345
3381
  /**
@@ -3516,8 +3552,13 @@ exports.GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3516
3552
  type: "arraybuffer"
3517
3553
  };
3518
3554
  return engineCore.request(url, requestConfig).then(function(buffer) {
3519
- restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3520
- return GLTFUtils.parseGLB(context, buffer);
3555
+ var _parseResult;
3556
+ var parseResult = GLTFUtils.parseGLB(context, buffer);
3557
+ // If the buffer is a GLB file, we need to restore the buffer data
3558
+ if ((_parseResult = parseResult) == null ? void 0 : _parseResult.glTF) {
3559
+ restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3560
+ }
3561
+ return parseResult;
3521
3562
  }).then(function(result) {
3522
3563
  var _result;
3523
3564
  if ((_result = result) == null ? void 0 : _result.glTF) {
@@ -3935,7 +3976,7 @@ exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1)
3935
3976
  resolve(mesh);
3936
3977
  } else {
3937
3978
  mesh.then(function(mesh) {
3938
- return resolve(mesh);
3979
+ resolve(mesh);
3939
3980
  });
3940
3981
  }
3941
3982
  } else {
@@ -3943,35 +3984,20 @@ exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1)
3943
3984
  var meshRestoreInfo = new ModelMeshRestoreInfo();
3944
3985
  meshRestoreInfo.mesh = mesh1;
3945
3986
  context.contentRestorer.meshes.push(meshRestoreInfo);
3946
- exports.GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, meshInfo, gltfPrimitive, glTF, function(attributeSemantic) {
3947
- return null;
3948
- }, function(attributeName, shapeIndex) {
3949
- var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
3950
- var attributeAccessorIdx = shapeAccessorIdx[attributeName];
3951
- if (attributeAccessorIdx) {
3952
- var accessor = glTF.accessors[attributeAccessorIdx];
3953
- return GLTFUtils.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
3954
- } else {
3955
- return null;
3956
- }
3957
- }, function() {
3958
- var indexAccessor = glTF.accessors[gltfPrimitive.indices];
3959
- return context.get(exports.GLTFParserType.Buffer).then(function(buffers) {
3960
- return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
3961
- });
3962
- }, context.params.keepMeshData).then(resolve);
3987
+ exports.GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, meshInfo, gltfPrimitive, glTF, context.params.keepMeshData).then(resolve);
3963
3988
  }
3964
3989
  });
3965
3990
  };
3966
3991
  var meshInfo = context.glTF.meshes[index];
3967
- var glTF = context.glTF, engine = context.glTFResource.engine;
3992
+ var glTF = context.glTF, glTFResource = context.glTFResource;
3993
+ var engine = glTFResource.engine;
3968
3994
  var primitivePromises = new Array();
3969
3995
  for(var i = 0, length = meshInfo.primitives.length; i < length; i++)_loop(i);
3970
3996
  return Promise.all(primitivePromises);
3971
3997
  };
3972
3998
  /**
3973
3999
  * @internal
3974
- */ GLTFMeshParser1._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
4000
+ */ GLTFMeshParser1._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, keepMeshData) {
3975
4001
  var _loop = function(attribute) {
3976
4002
  var accessor = accessors[attributes[attribute]];
3977
4003
  var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
@@ -4042,6 +4068,7 @@ exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1)
4042
4068
  });
4043
4069
  promises.push(promise);
4044
4070
  };
4071
+ var _this = this;
4045
4072
  var accessors = gltf.accessors;
4046
4073
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
4047
4074
  var engine = mesh.engine;
@@ -4066,61 +4093,68 @@ exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1)
4066
4093
  }
4067
4094
  // BlendShapes
4068
4095
  if (targets) {
4069
- promises.push(exports.GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
4096
+ promises.push(exports.GLTFMeshParser._createBlendShape(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, targets, _this._getBlendShapeData));
4070
4097
  }
4071
4098
  return Promise.all(promises).then(function() {
4072
4099
  mesh.uploadData(!keepMeshData);
4073
- return Promise.resolve(mesh);
4100
+ return mesh;
4074
4101
  });
4075
4102
  });
4076
4103
  };
4104
+ GLTFMeshParser1._getBlendShapeData = function _getBlendShapeData(context, glTF, accessor) {
4105
+ return GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
4106
+ var buffer = bufferInfo.data;
4107
+ var _accessor_byteOffset;
4108
+ var byteOffset = bufferInfo.interleaved ? ((_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0) % bufferInfo.stride : 0;
4109
+ var count = accessor.count, normalized = accessor.normalized, componentType = accessor.componentType;
4110
+ var vertices = GLTFUtils.bufferToVector3Array(buffer, byteOffset, count, normalized, componentType);
4111
+ var restoreInfo = new BlendShapeDataRestoreInfo(bufferInfo.restoreInfo, byteOffset, count, normalized, componentType);
4112
+ return {
4113
+ vertices: vertices,
4114
+ restoreInfo: restoreInfo
4115
+ };
4116
+ });
4117
+ };
4077
4118
  /**
4078
4119
  * @internal
4079
- */ GLTFMeshParser1._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
4080
- var _loop = function(i, n) {
4120
+ */ GLTFMeshParser1._createBlendShape = function _createBlendShape(context, mesh, meshRestoreInfo, glTFMesh, gltfPrimitive, glTFTargets, getBlendShapeData) {
4121
+ var _loop = function(i) {
4122
+ var blendShapeData = {};
4123
+ blendShapeCollection[i] = blendShapeData;
4081
4124
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
4125
+ var targets = gltfPrimitive.targets[i];
4126
+ var normalTarget = targets["NORMAL"];
4127
+ var tangentTarget = targets["TANGENT"];
4128
+ var hasNormal = normalTarget !== undefined;
4129
+ var hasTangent = tangentTarget !== undefined;
4082
4130
  var promise = Promise.all([
4083
- getBlendShapeData("POSITION", i),
4084
- getBlendShapeData("NORMAL", i),
4085
- getBlendShapeData("TANGENT", i)
4086
- ]).then(function(infos) {
4087
- var posBufferInfo = infos[0];
4088
- var norBufferInfo = infos[1];
4089
- var tanBufferInfo = infos[2];
4090
- var target = glTFTargets[i];
4091
- var posAccessor;
4092
- var norAccessor;
4093
- var tanAccessor;
4094
- var positions = null;
4095
- if (posBufferInfo) {
4096
- posAccessor = accessors[target["POSITION"]];
4097
- var _posAccessor_byteOffset;
4098
- positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
4099
- }
4100
- var normals = null;
4101
- if (norBufferInfo) {
4102
- norAccessor = accessors[target["NORMAL"]];
4103
- var _norAccessor_byteOffset;
4104
- normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
4105
- }
4106
- var tangents = null;
4107
- if (tanBufferInfo) {
4108
- tanAccessor = accessors[target["NORMAL"]];
4109
- var _tanAccessor_byteOffset;
4110
- tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
4111
- }
4131
+ getBlendShapeData(context, glTF, accessors[targets["POSITION"]]),
4132
+ hasNormal ? getBlendShapeData(context, glTF, accessors[normalTarget]) : null,
4133
+ hasTangent ? getBlendShapeData(context, glTF, accessors[tangentTarget]) : null
4134
+ ]).then(function(vertices) {
4135
+ var _tangentData;
4136
+ var positionData = vertices[0], normalData = vertices[1], tangentData = vertices[2];
4112
4137
  var blendShape = new engineCore.BlendShape(name);
4113
- blendShape.addFrame(1.0, positions, normals, tangents);
4114
- mesh.addBlendShape(blendShape);
4115
- var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
4116
- meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
4138
+ blendShape.addFrame(1.0, positionData.vertices, hasNormal ? normalData.vertices : null, hasTangent ? tangentData.vertices : null);
4139
+ blendShapeData.blendShape = blendShape;
4140
+ blendShapeData.restoreInfo = new BlendShapeRestoreInfo(blendShape, positionData.restoreInfo, hasNormal ? normalData.restoreInfo : null, hasTangent ? (_tangentData = tangentData) == null ? void 0 : _tangentData.restoreInfo : null);
4117
4141
  });
4118
4142
  promises.push(promise);
4119
4143
  };
4144
+ var glTF = context.glTF;
4145
+ var accessors = glTF.accessors;
4120
4146
  var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
4121
4147
  var promises = new Array();
4122
- for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
4123
- return Promise.all(promises);
4148
+ var blendShapeCount = glTFTargets.length;
4149
+ var blendShapeCollection = new Array(blendShapeCount);
4150
+ for(var i = 0; i < blendShapeCount; i++)_loop(i);
4151
+ return Promise.all(promises).then(function() {
4152
+ for(var _iterator = _create_for_of_iterator_helper_loose(blendShapeCollection), _step; !(_step = _iterator()).done;){
4153
+ var blendShape = _step.value;
4154
+ mesh.addBlendShape(blendShape.blendShape);
4155
+ meshRestoreInfo.blendShapes.push(blendShape.restoreInfo);
4156
+ }
4157
+ });
4124
4158
  };
4125
4159
  return GLTFMeshParser1;
4126
4160
  }(GLTFParser), function() {
@@ -4501,6 +4535,25 @@ exports.GLTFValidator = __decorate([
4501
4535
  registerGLTFParser(exports.GLTFParserType.Validator)
4502
4536
  ], exports.GLTFValidator);
4503
4537
 
4538
+ exports.GLTFBufferViewParser = /*#__PURE__*/ function(GLTFParser1) {
4539
+ _inherits(GLTFBufferViewParser, GLTFParser1);
4540
+ function GLTFBufferViewParser() {
4541
+ return GLTFParser1.apply(this, arguments);
4542
+ }
4543
+ var _proto = GLTFBufferViewParser.prototype;
4544
+ _proto.parse = function parse(context, index) {
4545
+ var bufferView = context.glTF.bufferViews[index];
4546
+ var extensions = bufferView.extensions, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength, bufferIndex = bufferView.buffer;
4547
+ return extensions ? GLTFParser.executeExtensionsCreateAndParse(extensions, context, bufferView) : context.get(exports.GLTFParserType.Buffer, bufferIndex).then(function(buffer) {
4548
+ return new Uint8Array(buffer, byteOffset, byteLength);
4549
+ });
4550
+ };
4551
+ return GLTFBufferViewParser;
4552
+ }(GLTFParser);
4553
+ exports.GLTFBufferViewParser = __decorate([
4554
+ registerGLTFParser(exports.GLTFParserType.BufferView)
4555
+ ], exports.GLTFBufferViewParser);
4556
+
4504
4557
  var GLTFLoader = /*#__PURE__*/ function(Loader1) {
4505
4558
  _inherits(GLTFLoader, Loader1);
4506
4559
  function GLTFLoader() {
@@ -4537,23 +4590,48 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
4537
4590
  var _this = this;
4538
4591
  return new engineCore.AssetPromise(function(resolve, reject) {
4539
4592
  var engine = resourceManager.engine;
4540
- _this.request(item.url, {
4593
+ var request = _this.request;
4594
+ _this.request(item.url, _extends({}, item, {
4541
4595
  type: "arraybuffer"
4542
- }).then(function(buffer) {
4543
- var uint8Array = new Uint8Array(buffer);
4544
- var _HDRLoader__parseHeader = HDRLoader._parseHeader(uint8Array), width = _HDRLoader__parseHeader.width, height = _HDRLoader__parseHeader.height, dataPosition = _HDRLoader__parseHeader.dataPosition;
4545
- var pixels = HDRLoader._readPixels(uint8Array.subarray(dataPosition), width, height);
4546
- var cubeSize = height >> 1;
4547
- var cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize);
4548
- var texture = new engineCore.TextureCube(engine, cubeSize);
4549
- for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4550
- texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + faceIndex, cubeMapData[faceIndex], 0);
4551
- }
4552
- texture.generateMipmaps();
4596
+ })).then(function(buffer) {
4597
+ var texture = HDRLoader._setTextureByBuffer(engine, buffer);
4598
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
4599
+ _inherits(_class, ContentRestorer);
4600
+ function _class() {
4601
+ return ContentRestorer.apply(this, arguments);
4602
+ }
4603
+ var _proto = _class.prototype;
4604
+ _proto.restoreContent = function restoreContent() {
4605
+ return new engineCore.AssetPromise(function(resolve, reject) {
4606
+ request(item.url, _extends({}, item, {
4607
+ type: "arraybuffer"
4608
+ })).then(function(buffer) {
4609
+ HDRLoader._setTextureByBuffer(engine, buffer, texture);
4610
+ resolve(texture);
4611
+ }).catch(reject);
4612
+ });
4613
+ };
4614
+ return _class;
4615
+ }(engineCore.ContentRestorer))(texture));
4553
4616
  resolve(texture);
4554
4617
  }).catch(reject);
4555
4618
  });
4556
4619
  };
4620
+ /**
4621
+ * @internal
4622
+ */ HDRLoader1._setTextureByBuffer = function _setTextureByBuffer(engine, buffer, texture) {
4623
+ var bufferArray = new Uint8Array(buffer);
4624
+ var _HDRLoader__parseHeader = HDRLoader._parseHeader(bufferArray), width = _HDRLoader__parseHeader.width, height = _HDRLoader__parseHeader.height, dataPosition = _HDRLoader__parseHeader.dataPosition;
4625
+ var cubeSize = height >> 1;
4626
+ texture || (texture = new engineCore.TextureCube(engine, cubeSize));
4627
+ var pixels = HDRLoader._readPixels(bufferArray.subarray(dataPosition), width, height);
4628
+ var cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize);
4629
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4630
+ texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + faceIndex, cubeMapData[faceIndex], 0);
4631
+ }
4632
+ texture.generateMipmaps();
4633
+ return texture;
4634
+ };
4557
4635
  HDRLoader1._convertToCubemap = function _convertToCubemap(pixels, inputWidth, inputHeight, size) {
4558
4636
  if (!pixels) {
4559
4637
  throw "ConvertPanoramaToCubemap: input cannot be null";
@@ -5091,7 +5169,8 @@ var KTXLoader = /*#__PURE__*/ function(Loader1) {
5091
5169
  _proto.load = function load(item, resourceManager) {
5092
5170
  var _this = this;
5093
5171
  return new engineCore.AssetPromise(function(resolve, reject) {
5094
- _this.request(item.url, _extends({}, item, {
5172
+ var request = _this.request;
5173
+ request(item.url, _extends({}, item, {
5095
5174
  type: "arraybuffer"
5096
5175
  })).then(function(bin) {
5097
5176
  var parsedData = parseSingleKTX(bin);
@@ -5102,6 +5181,32 @@ var KTXLoader = /*#__PURE__*/ function(Loader1) {
5102
5181
  var _mipmaps_miplevel = mipmaps[miplevel], width1 = _mipmaps_miplevel.width, height1 = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
5103
5182
  texture.setPixelBuffer(data, miplevel, 0, 0, width1, height1);
5104
5183
  }
5184
+ resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
5185
+ _inherits(_class, ContentRestorer);
5186
+ function _class() {
5187
+ return ContentRestorer.apply(this, arguments);
5188
+ }
5189
+ var _proto = _class.prototype;
5190
+ _proto.restoreContent = function restoreContent() {
5191
+ var _this = this;
5192
+ return new engineCore.AssetPromise(function(resolve, reject) {
5193
+ request(item.url, _extends({}, item, {
5194
+ type: "arraybuffer"
5195
+ })).then(function(bin) {
5196
+ var mipmaps = parseSingleKTX(bin).mipmaps;
5197
+ var texture = _this.resource;
5198
+ for(var miplevel = 0; miplevel < mipmaps.length; miplevel++){
5199
+ var _mipmaps_miplevel = mipmaps[miplevel], width = _mipmaps_miplevel.width, height = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
5200
+ texture.setPixelBuffer(data, miplevel, 0, 0, width, height);
5201
+ }
5202
+ resolve(texture);
5203
+ }).catch(function(e) {
5204
+ reject(e);
5205
+ });
5206
+ });
5207
+ };
5208
+ return _class;
5209
+ }(engineCore.ContentRestorer))(texture));
5105
5210
  resolve(texture);
5106
5211
  }).catch(function(e) {
5107
5212
  reject(e);
@@ -5208,11 +5313,32 @@ var MeshLoader = /*#__PURE__*/ function(Loader1) {
5208
5313
  _proto.load = function load(item, resourceManager) {
5209
5314
  var _this = this;
5210
5315
  return new engineCore.AssetPromise(function(resolve, reject) {
5211
- _this.request(item.url, _extends({}, item, {
5316
+ var request = _this.request;
5317
+ var engine = resourceManager.engine;
5318
+ request(item.url, _extends({}, item, {
5212
5319
  type: "arraybuffer"
5213
5320
  })).then(function(data) {
5214
- return decode(data, resourceManager.engine);
5321
+ return decode(data, engine);
5215
5322
  }).then(function(mesh) {
5323
+ resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
5324
+ _inherits(_class, ContentRestorer);
5325
+ function _class() {
5326
+ return ContentRestorer.apply(this, arguments);
5327
+ }
5328
+ var _proto = _class.prototype;
5329
+ _proto.restoreContent = function restoreContent() {
5330
+ return new engineCore.AssetPromise(function(resolve, reject) {
5331
+ request(item.url, _extends({}, item, {
5332
+ type: "arraybuffer"
5333
+ })).then(function(data) {
5334
+ return decode(data, engine, mesh);
5335
+ }).then(function(mesh) {
5336
+ resolve(mesh);
5337
+ }).catch(reject);
5338
+ });
5339
+ };
5340
+ return _class;
5341
+ }(engineCore.ContentRestorer))(mesh));
5216
5342
  resolve(mesh);
5217
5343
  }).catch(reject);
5218
5344
  });
@@ -5748,14 +5874,17 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
5748
5874
  var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
5749
5875
  return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
5750
5876
  var mesh = new engineCore.ModelMesh(engine, glTFMesh.name);
5751
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
5877
+ var meshRestoreInfo = new ModelMeshRestoreInfo();
5878
+ meshRestoreInfo.mesh = mesh;
5879
+ context.contentRestorer.meshes.push(meshRestoreInfo);
5880
+ return _this._parseMeshFromGLTFPrimitiveDraco(context, mesh, meshRestoreInfo, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
5752
5881
  for(var j = 0; j < decodedGeometry.attributes.length; j++){
5753
5882
  if (decodedGeometry.attributes[j].name === attributeSemantic) {
5754
5883
  return decodedGeometry.attributes[j].array;
5755
5884
  }
5756
5885
  }
5757
5886
  return null;
5758
- }, function(attributeSemantic, shapeIndex) {
5887
+ }, function() {
5759
5888
  throw "BlendShape animation is not supported when using draco.";
5760
5889
  }, function() {
5761
5890
  return decodedGeometry.index.array;
@@ -5768,7 +5897,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
5768
5897
  KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
5769
5898
  }
5770
5899
  };
5771
- _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
5900
+ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
5772
5901
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
5773
5902
  var vertexCount;
5774
5903
  var accessors = gltf.accessors;
@@ -5864,7 +5993,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
5864
5993
  mesh.addSubMesh(0, vertexCount, mode);
5865
5994
  }
5866
5995
  // BlendShapes
5867
- targets && exports.GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
5996
+ targets && exports.GLTFMeshParser._createBlendShape(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, targets, getBlendShapeData);
5868
5997
  mesh.uploadData(!keepMeshData);
5869
5998
  return Promise.resolve(mesh);
5870
5999
  };
@@ -6204,6 +6333,7 @@ GALACEAN_animation_event = __decorate([
6204
6333
  registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
6205
6334
  ], GALACEAN_animation_event);
6206
6335
 
6336
+ exports.BufferInfo = BufferInfo;
6207
6337
  exports.ComponentMap = ComponentMap;
6208
6338
  exports.GLTFExtensionParser = GLTFExtensionParser;
6209
6339
  exports.GLTFParser = GLTFParser;