@babylonjs/loaders 5.0.0-alpha.8 → 5.0.0-beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. package/OBJ/index.d.ts +2 -0
  2. package/OBJ/index.js +4 -2
  3. package/OBJ/index.js.map +1 -1
  4. package/OBJ/mtlFileLoader.d.ts +4 -2
  5. package/OBJ/mtlFileLoader.js +7 -6
  6. package/OBJ/mtlFileLoader.js.map +1 -1
  7. package/OBJ/objFileLoader.d.ts +12 -84
  8. package/OBJ/objFileLoader.js +50 -667
  9. package/OBJ/objFileLoader.js.map +1 -1
  10. package/OBJ/objLoadingOptions.d.ts +43 -0
  11. package/OBJ/objLoadingOptions.js +2 -0
  12. package/OBJ/objLoadingOptions.js.map +1 -0
  13. package/OBJ/solidParser.d.ts +153 -0
  14. package/OBJ/solidParser.js +700 -0
  15. package/OBJ/solidParser.js.map +1 -0
  16. package/STL/index.js +1 -1
  17. package/STL/stlFileLoader.d.ts +6 -0
  18. package/STL/stlFileLoader.js +38 -11
  19. package/STL/stlFileLoader.js.map +1 -1
  20. package/glTF/1.0/glTFBinaryExtension.js +4 -4
  21. package/glTF/1.0/glTFLoader.d.ts +4 -4
  22. package/glTF/1.0/glTFLoader.js +60 -55
  23. package/glTF/1.0/glTFLoader.js.map +1 -1
  24. package/glTF/1.0/glTFLoaderInterfaces.d.ts +3 -1
  25. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  26. package/glTF/1.0/glTFLoaderUtils.js +6 -6
  27. package/glTF/1.0/glTFMaterialsCommonExtension.js +12 -12
  28. package/glTF/1.0/index.js +5 -5
  29. package/glTF/2.0/Extensions/EXT_lights_image_based.js +8 -5
  30. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  31. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +3 -3
  32. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  33. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +1 -5
  34. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +5 -21
  35. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  36. package/glTF/2.0/Extensions/EXT_texture_webp.js +2 -2
  37. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  38. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +1 -1
  39. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +8 -4
  40. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  41. package/glTF/2.0/Extensions/KHR_lights_punctual.js +9 -8
  42. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  43. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +2 -2
  44. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +30 -0
  45. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +46 -0
  46. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
  47. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +1 -2
  48. package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -4
  49. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  50. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +3 -4
  51. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  52. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -1
  53. package/glTF/2.0/Extensions/KHR_materials_sheen.js +3 -4
  54. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -2
  56. package/glTF/2.0/Extensions/KHR_materials_specular.js +12 -6
  57. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_materials_translucency.js +6 -6
  59. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  60. package/glTF/2.0/Extensions/KHR_materials_transmission.js +93 -84
  61. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  62. package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
  63. package/glTF/2.0/Extensions/KHR_materials_variants.js +70 -5
  64. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  65. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +31 -0
  66. package/glTF/2.0/Extensions/KHR_materials_volume.js +79 -0
  67. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
  68. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +1 -1
  69. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +1 -2
  70. package/glTF/2.0/Extensions/KHR_texture_basisu.js +3 -4
  71. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  72. package/glTF/2.0/Extensions/KHR_texture_transform.js +2 -2
  73. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +2 -2
  74. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +6 -3
  75. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  76. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +6 -7
  77. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  78. package/glTF/2.0/Extensions/MSFT_lod.d.ts +2 -1
  79. package/glTF/2.0/Extensions/MSFT_lod.js +48 -8
  80. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  81. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +2 -2
  82. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +2 -2
  83. package/glTF/2.0/Extensions/index.d.ts +2 -0
  84. package/glTF/2.0/Extensions/index.js +26 -24
  85. package/glTF/2.0/Extensions/index.js.map +1 -1
  86. package/glTF/2.0/glTFLoader.d.ts +6 -11
  87. package/glTF/2.0/glTFLoader.js +129 -95
  88. package/glTF/2.0/glTFLoader.js.map +1 -1
  89. package/glTF/2.0/glTFLoaderInterfaces.d.ts +4 -2
  90. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  91. package/glTF/2.0/index.d.ts +1 -1
  92. package/glTF/2.0/index.js +4 -4
  93. package/glTF/2.0/index.js.map +1 -1
  94. package/glTF/glTFFileLoader.d.ts +15 -9
  95. package/glTF/glTFFileLoader.js +62 -76
  96. package/glTF/glTFFileLoader.js.map +1 -1
  97. package/glTF/glTFValidation.js +1 -1
  98. package/glTF/glTFValidation.js.map +1 -1
  99. package/glTF/index.d.ts +2 -2
  100. package/glTF/index.js +4 -4
  101. package/glTF/index.js.map +1 -1
  102. package/index.d.ts +3 -3
  103. package/index.js +3 -3
  104. package/index.js.map +1 -1
  105. package/legacy/legacy-glTF.js +4 -4
  106. package/legacy/legacy-glTF1.d.ts +1 -1
  107. package/legacy/legacy-glTF1.js +1 -1
  108. package/legacy/legacy-glTF1.js.map +1 -1
  109. package/legacy/legacy-glTF1FileLoader.js +2 -2
  110. package/legacy/legacy-glTF2.d.ts +1 -1
  111. package/legacy/legacy-glTF2.js +3 -3
  112. package/legacy/legacy-glTF2.js.map +1 -1
  113. package/legacy/legacy-glTF2FileLoader.js +2 -2
  114. package/legacy/legacy-glTFFileLoader.js +3 -3
  115. package/legacy/legacy-objFileLoader.d.ts +1 -1
  116. package/legacy/legacy-objFileLoader.js +2 -2
  117. package/legacy/legacy-objFileLoader.js.map +1 -1
  118. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  119. package/legacy/legacy-stlFileLoader.js +2 -2
  120. package/legacy/legacy-stlFileLoader.js.map +1 -1
  121. package/legacy/legacy.js +6 -6
  122. package/package.json +16 -4
@@ -1,5 +1,5 @@
1
- import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
2
- import { GLTFLoader } from "../glTFLoader";
1
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
2
+ import { GLTFLoader } from "../glTFLoader.js";
3
3
  var NAME = "MSFT_minecraftMesh";
4
4
  /** @hidden */
5
5
  var MSFT_minecraftMesh = /** @class */ (function () {
@@ -1,5 +1,5 @@
1
- import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
2
- import { GLTFLoader } from "../glTFLoader";
1
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
2
+ import { GLTFLoader } from "../glTFLoader.js";
3
3
  var NAME = "MSFT_sRGBFactors";
4
4
  /** @hidden */
5
5
  var MSFT_sRGBFactors = /** @class */ (function () {
@@ -7,12 +7,14 @@ export * from "./KHR_lights_punctual";
7
7
  export * from "./KHR_materials_pbrSpecularGlossiness";
8
8
  export * from "./KHR_materials_unlit";
9
9
  export * from "./KHR_materials_clearcoat";
10
+ export * from "./KHR_materials_emissive_strength";
10
11
  export * from "./KHR_materials_sheen";
11
12
  export * from "./KHR_materials_specular";
12
13
  export * from "./KHR_materials_ior";
13
14
  export * from "./KHR_materials_variants";
14
15
  export * from "./KHR_materials_transmission";
15
16
  export * from "./KHR_materials_translucency";
17
+ export * from "./KHR_materials_volume";
16
18
  export * from "./KHR_mesh_quantization";
17
19
  export * from "./KHR_texture_basisu";
18
20
  export * from "./KHR_texture_transform";
@@ -1,25 +1,27 @@
1
- export * from "./EXT_lights_image_based";
2
- export * from "./EXT_mesh_gpu_instancing";
3
- export * from "./EXT_meshopt_compression";
4
- export * from "./EXT_texture_webp";
5
- export * from "./KHR_draco_mesh_compression";
6
- export * from "./KHR_lights_punctual";
7
- export * from "./KHR_materials_pbrSpecularGlossiness";
8
- export * from "./KHR_materials_unlit";
9
- export * from "./KHR_materials_clearcoat";
10
- export * from "./KHR_materials_sheen";
11
- export * from "./KHR_materials_specular";
12
- export * from "./KHR_materials_ior";
13
- export * from "./KHR_materials_variants";
14
- export * from "./KHR_materials_transmission";
15
- export * from "./KHR_materials_translucency";
16
- export * from "./KHR_mesh_quantization";
17
- export * from "./KHR_texture_basisu";
18
- export * from "./KHR_texture_transform";
19
- export * from "./KHR_xmp_json_ld";
20
- export * from "./MSFT_audio_emitter";
21
- export * from "./MSFT_lod";
22
- export * from "./MSFT_minecraftMesh";
23
- export * from "./MSFT_sRGBFactors";
24
- export * from "./ExtrasAsMetadata";
1
+ export * from "./EXT_lights_image_based.js";
2
+ export * from "./EXT_mesh_gpu_instancing.js";
3
+ export * from "./EXT_meshopt_compression.js";
4
+ export * from "./EXT_texture_webp.js";
5
+ export * from "./KHR_draco_mesh_compression.js";
6
+ export * from "./KHR_lights_punctual.js";
7
+ export * from "./KHR_materials_pbrSpecularGlossiness.js";
8
+ export * from "./KHR_materials_unlit.js";
9
+ export * from "./KHR_materials_clearcoat.js";
10
+ export * from "./KHR_materials_emissive_strength.js";
11
+ export * from "./KHR_materials_sheen.js";
12
+ export * from "./KHR_materials_specular.js";
13
+ export * from "./KHR_materials_ior.js";
14
+ export * from "./KHR_materials_variants.js";
15
+ export * from "./KHR_materials_transmission.js";
16
+ export * from "./KHR_materials_translucency.js";
17
+ export * from "./KHR_materials_volume.js";
18
+ export * from "./KHR_mesh_quantization.js";
19
+ export * from "./KHR_texture_basisu.js";
20
+ export * from "./KHR_texture_transform.js";
21
+ export * from "./KHR_xmp_json_ld.js";
22
+ export * from "./MSFT_audio_emitter.js";
23
+ export * from "./MSFT_lod.js";
24
+ export * from "./MSFT_minecraftMesh.js";
25
+ export * from "./MSFT_sRGBFactors.js";
26
+ export * from "./ExtrasAsMetadata.js";
25
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./EXT_lights_image_based\";\r\nexport * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./EXT_meshopt_compression\";\r\nexport * from \"./EXT_texture_webp\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_pbrSpecularGlossiness\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_variants\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_translucency\";\r\nexport * from \"./KHR_mesh_quantization\";\r\nexport * from \"./KHR_texture_basisu\";\r\nexport * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_xmp_json_ld\";\r\nexport * from \"./MSFT_audio_emitter\";\r\nexport * from \"./MSFT_lod\";\r\nexport * from \"./MSFT_minecraftMesh\";\r\nexport * from \"./MSFT_sRGBFactors\";\r\nexport * from \"./ExtrasAsMetadata\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./EXT_lights_image_based\";\r\nexport * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./EXT_meshopt_compression\";\r\nexport * from \"./EXT_texture_webp\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_pbrSpecularGlossiness\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_variants\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_translucency\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_mesh_quantization\";\r\nexport * from \"./KHR_texture_basisu\";\r\nexport * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_xmp_json_ld\";\r\nexport * from \"./MSFT_audio_emitter\";\r\nexport * from \"./MSFT_lod\";\r\nexport * from \"./MSFT_minecraftMesh\";\r\nexport * from \"./MSFT_sRGBFactors\";\r\nexport * from \"./ExtrasAsMetadata\";\r\n"]}
@@ -11,10 +11,11 @@ import { Scene } from "@babylonjs/core/scene";
11
11
  import { IProperty } from "babylonjs-gltf2interface";
12
12
  import { IGLTF, ISampler, INode, IScene, IMesh, IAccessor, ICamera, IAnimation, IAnimationChannel, IBuffer, IBufferView, IMaterial, ITextureInfo, ITexture, IImage, IMeshPrimitive, IArrayItem as IArrItem } from "./glTFLoaderInterfaces";
13
13
  import { IGLTFLoaderExtension } from "./glTFLoaderExtension";
14
- import { IGLTFLoader, GLTFFileLoader, GLTFLoaderState, IGLTFLoaderData } from "../glTFFileLoader";
14
+ import { IGLTFLoader, GLTFFileLoader, IGLTFLoaderData } from "../glTFFileLoader";
15
15
  import { IAnimatable } from '@babylonjs/core/Animations/animatable.interface';
16
16
  import { IDataBuffer } from '@babylonjs/core/Misc/dataReader';
17
17
  import { Light } from '@babylonjs/core/Lights/light';
18
+ import { AssetContainer } from "@babylonjs/core/assetContainer";
18
19
  /**
19
20
  * Helper class for working with arrays when loading the glTF asset
20
21
  */
@@ -40,14 +41,13 @@ export declare class GLTFLoader implements IGLTFLoader {
40
41
  /** @hidden */
41
42
  _completePromises: Promise<any>[];
42
43
  /** @hidden */
43
- _forAssetContainer: boolean;
44
+ _assetContainer: Nullable<AssetContainer>;
44
45
  /** Storage */
45
46
  _babylonLights: Light[];
46
47
  /** @hidden */
47
48
  _disableInstancedMesh: number;
48
49
  private _disposed;
49
50
  private _parent;
50
- private _state;
51
51
  private _extensions;
52
52
  private _rootUrl;
53
53
  private _fileName;
@@ -74,10 +74,6 @@ export declare class GLTFLoader implements IGLTFLoader {
74
74
  * @returns A boolean indicating whether the extension has been unregistered
75
75
  */
76
76
  static UnregisterExtension(name: string): boolean;
77
- /**
78
- * The loader state.
79
- */
80
- get state(): Nullable<GLTFLoaderState>;
81
77
  /**
82
78
  * The object that represents the glTF JSON.
83
79
  */
@@ -97,13 +93,13 @@ export declare class GLTFLoader implements IGLTFLoader {
97
93
  /**
98
94
  * The root Babylon mesh when loading the asset.
99
95
  */
100
- get rootBabylonMesh(): Mesh;
96
+ get rootBabylonMesh(): Nullable<Mesh>;
101
97
  /** @hidden */
102
98
  constructor(parent: GLTFFileLoader);
103
99
  /** @hidden */
104
100
  dispose(): void;
105
101
  /** @hidden */
106
- importMeshAsync(meshesNames: any, scene: Scene, forAssetContainer: boolean, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
102
+ importMeshAsync(meshesNames: any, scene: Scene, container: Nullable<AssetContainer>, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<ISceneLoaderAsyncResult>;
107
103
  /** @hidden */
108
104
  loadAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onProgress?: (event: ISceneLoaderProgressEvent) => void, fileName?: string): Promise<void>;
109
105
  private _loadAsync;
@@ -111,7 +107,6 @@ export declare class GLTFLoader implements IGLTFLoader {
111
107
  private _setupData;
112
108
  private _loadExtensions;
113
109
  private _checkExtensions;
114
- private _setState;
115
110
  private _createRootNode;
116
111
  /**
117
112
  * Loads a glTF scene.
@@ -255,7 +250,7 @@ export declare class GLTFLoader implements IGLTFLoader {
255
250
  /** @hidden */
256
251
  _loadTextureAsync(context: string, texture: ITexture, assign?: (babylonTexture: BaseTexture) => void): Promise<BaseTexture>;
257
252
  /** @hidden */
258
- _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign?: (babylonTexture: BaseTexture) => void, textureLoaderOptions?: any): Promise<BaseTexture>;
253
+ _createTextureAsync(context: string, sampler: ISampler, image: IImage, assign?: (babylonTexture: BaseTexture) => void, textureLoaderOptions?: any, useSRGBBuffer?: boolean): Promise<BaseTexture>;
259
254
  private _loadSampler;
260
255
  /**
261
256
  * Loads a glTF image.
@@ -1,29 +1,29 @@
1
- import { Deferred } from "@babylonjs/core/Misc/deferred";
2
- import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector";
3
- import { Color3 } from '@babylonjs/core/Maths/math.color';
4
- import { Tools } from "@babylonjs/core/Misc/tools";
5
- import { Camera } from "@babylonjs/core/Cameras/camera";
6
- import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
7
- import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup";
8
- import { Animation } from "@babylonjs/core/Animations/animation";
9
- import { Bone } from "@babylonjs/core/Bones/bone";
10
- import { Skeleton } from "@babylonjs/core/Bones/skeleton";
11
- import { Material } from "@babylonjs/core/Materials/material";
12
- import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
13
- import { Texture } from "@babylonjs/core/Materials/Textures/texture";
14
- import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
15
- import { Buffer, VertexBuffer } from "@babylonjs/core/Meshes/buffer";
16
- import { Geometry } from "@babylonjs/core/Meshes/geometry";
17
- import { Mesh } from "@babylonjs/core/Meshes/mesh";
18
- import { MorphTarget } from "@babylonjs/core/Morph/morphTarget";
19
- import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager";
20
- import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader";
21
- import { AnimationKeyInterpolation } from '@babylonjs/core/Animations/animationKey';
22
- import { LoadFileError } from '@babylonjs/core/Misc/fileTools';
23
- import { Logger } from '@babylonjs/core/Misc/logger';
24
- import { TmpVectors } from '@babylonjs/core/Maths/math.vector';
25
- import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';
26
- import { StringTools } from '@babylonjs/core/Misc/stringTools';
1
+ import { Deferred } from "@babylonjs/core/Misc/deferred.js";
2
+ import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector.js";
3
+ import { Color3 } from '@babylonjs/core/Maths/math.color.js';
4
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
5
+ import { Camera } from "@babylonjs/core/Cameras/camera.js";
6
+ import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera.js";
7
+ import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
8
+ import { Animation } from "@babylonjs/core/Animations/animation.js";
9
+ import { Bone } from "@babylonjs/core/Bones/bone.js";
10
+ import { Skeleton } from "@babylonjs/core/Bones/skeleton.js";
11
+ import { Material } from "@babylonjs/core/Materials/material.js";
12
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
13
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
14
+ import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
15
+ import { Buffer, VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
16
+ import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
17
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
18
+ import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
19
+ import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager.js";
20
+ import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader.js";
21
+ import { AnimationKeyInterpolation } from '@babylonjs/core/Animations/animationKey.js';
22
+ import { DecodeBase64UrlToBinary, IsBase64DataUrl, LoadFileError } from '@babylonjs/core/Misc/fileTools.js';
23
+ import { Logger } from '@babylonjs/core/Misc/logger.js';
24
+ import { TmpVectors } from '@babylonjs/core/Maths/math.vector.js';
25
+ import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo.js';
26
+ import { StringTools } from '@babylonjs/core/Misc/stringTools.js';
27
27
  /**
28
28
  * Helper class for working with arrays when loading the glTF asset
29
29
  */
@@ -66,14 +66,14 @@ var GLTFLoader = /** @class */ (function () {
66
66
  /** @hidden */
67
67
  this._completePromises = new Array();
68
68
  /** @hidden */
69
- this._forAssetContainer = false;
69
+ this._assetContainer = null;
70
70
  /** Storage */
71
71
  this._babylonLights = [];
72
72
  /** @hidden */
73
73
  this._disableInstancedMesh = 0;
74
74
  this._disposed = false;
75
- this._state = null;
76
75
  this._extensions = new Array();
76
+ this._rootBabylonMesh = null;
77
77
  this._defaultBabylonMaterialData = {};
78
78
  this._parent = parent;
79
79
  }
@@ -102,16 +102,6 @@ var GLTFLoader = /** @class */ (function () {
102
102
  delete GLTFLoader._RegisteredExtensions[name];
103
103
  return true;
104
104
  };
105
- Object.defineProperty(GLTFLoader.prototype, "state", {
106
- /**
107
- * The loader state.
108
- */
109
- get: function () {
110
- return this._state;
111
- },
112
- enumerable: false,
113
- configurable: true
114
- });
115
105
  Object.defineProperty(GLTFLoader.prototype, "gltf", {
116
106
  /**
117
107
  * The object that represents the glTF JSON.
@@ -180,12 +170,12 @@ var GLTFLoader = /** @class */ (function () {
180
170
  this._parent.dispose();
181
171
  };
182
172
  /** @hidden */
183
- GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
173
+ GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, container, data, rootUrl, onProgress, fileName) {
184
174
  var _this = this;
185
175
  if (fileName === void 0) { fileName = ""; }
186
176
  return Promise.resolve().then(function () {
187
177
  _this._babylonScene = scene;
188
- _this._forAssetContainer = forAssetContainer;
178
+ _this._assetContainer = container;
189
179
  _this._loadData(data);
190
180
  var nodes = null;
191
181
  if (meshesNames) {
@@ -242,7 +232,7 @@ var GLTFLoader = /** @class */ (function () {
242
232
  var loadingToCompleteCounterName = GLTFLoaderState[GLTFLoaderState.LOADING] + " => " + GLTFLoaderState[GLTFLoaderState.COMPLETE];
243
233
  _this._parent._startPerformanceCounter(loadingToReadyCounterName);
244
234
  _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
245
- _this._setState(GLTFLoaderState.LOADING);
235
+ _this._parent._setState(GLTFLoaderState.LOADING);
246
236
  _this._extensionsOnLoading();
247
237
  var promises = new Array();
248
238
  // Block the marking of materials dirty until the scene is loaded.
@@ -276,7 +266,7 @@ var GLTFLoader = /** @class */ (function () {
276
266
  _this._rootBabylonMesh.setEnabled(true);
277
267
  }
278
268
  _this._extensionsOnReady();
279
- _this._setState(GLTFLoaderState.READY);
269
+ _this._parent._setState(GLTFLoaderState.READY);
280
270
  _this._startAnimations();
281
271
  return resultFunc();
282
272
  });
@@ -286,7 +276,7 @@ var GLTFLoader = /** @class */ (function () {
286
276
  if (!_this._disposed) {
287
277
  Promise.all(_this._completePromises).then(function () {
288
278
  _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
289
- _this._setState(GLTFLoaderState.COMPLETE);
279
+ _this._parent._setState(GLTFLoaderState.COMPLETE);
290
280
  _this._parent.onCompleteObservable.notifyObservers(undefined);
291
281
  _this._parent.onCompleteObservable.clear();
292
282
  _this.dispose();
@@ -385,13 +375,10 @@ var GLTFLoader = /** @class */ (function () {
385
375
  }
386
376
  }
387
377
  };
388
- GLTFLoader.prototype._setState = function (state) {
389
- this._state = state;
390
- this.log(GLTFLoaderState[this._state]);
391
- };
392
378
  GLTFLoader.prototype._createRootNode = function () {
393
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
379
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
394
380
  this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
381
+ this._rootBabylonMesh._parentContainer = this._assetContainer;
395
382
  this._babylonScene._blockEntityCollection = false;
396
383
  this._rootBabylonMesh.setEnabled(false);
397
384
  var rootNode = {
@@ -484,8 +471,10 @@ var GLTFLoader = /** @class */ (function () {
484
471
  };
485
472
  GLTFLoader.prototype._getMeshes = function () {
486
473
  var meshes = new Array();
487
- // Root mesh is always first.
488
- meshes.push(this._rootBabylonMesh);
474
+ // Root mesh is always first, if available.
475
+ if (this._rootBabylonMesh) {
476
+ meshes.push(this._rootBabylonMesh);
477
+ }
489
478
  var nodes = this._gltf.nodes;
490
479
  if (nodes) {
491
480
  for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
@@ -604,8 +593,9 @@ var GLTFLoader = /** @class */ (function () {
604
593
  };
605
594
  if (node.mesh == undefined) {
606
595
  var nodeName = node.name || "node" + node.index;
607
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
596
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
608
597
  node._babylonTransformNode = new TransformNode(nodeName, this._babylonScene);
598
+ node._babylonTransformNode._parentContainer = this._assetContainer;
609
599
  this._babylonScene._blockEntityCollection = false;
610
600
  loadNode(node._babylonTransformNode);
611
601
  }
@@ -646,8 +636,9 @@ var GLTFLoader = /** @class */ (function () {
646
636
  }));
647
637
  }
648
638
  else {
649
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
639
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
650
640
  node._babylonTransformNode = new TransformNode(name, this._babylonScene);
641
+ node._babylonTransformNode._parentContainer = this._assetContainer;
651
642
  this._babylonScene._blockEntityCollection = false;
652
643
  node._primitiveBabylonMeshes = [];
653
644
  for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
@@ -689,22 +680,25 @@ var GLTFLoader = /** @class */ (function () {
689
680
  var babylonAbstractMesh;
690
681
  var promise;
691
682
  if (shouldInstance && primitive._instanceData) {
692
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
683
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
693
684
  babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
685
+ babylonAbstractMesh._parentContainer = this._assetContainer;
694
686
  this._babylonScene._blockEntityCollection = false;
695
687
  promise = primitive._instanceData.promise;
696
688
  }
697
689
  else {
698
690
  var promises = new Array();
699
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
691
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
700
692
  var babylonMesh_1 = new Mesh(name, this._babylonScene);
693
+ babylonMesh_1._parentContainer = this._assetContainer;
701
694
  this._babylonScene._blockEntityCollection = false;
702
695
  babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
703
696
  this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
704
697
  promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
705
698
  return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
706
- _this._babylonScene._blockEntityCollection = _this._forAssetContainer;
699
+ _this._babylonScene._blockEntityCollection = !!_this._assetContainer;
707
700
  babylonGeometry.applyToMesh(babylonMesh_1);
701
+ babylonGeometry._parentContainer = _this._assetContainer;
708
702
  _this._babylonScene._blockEntityCollection = false;
709
703
  });
710
704
  }));
@@ -775,6 +769,27 @@ var GLTFLoader = /** @class */ (function () {
775
769
  if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
776
770
  var mmin = accessor.min, mmax = accessor.max;
777
771
  if (mmin !== undefined && mmax !== undefined) {
772
+ if (accessor.normalized && accessor.componentType !== 5126 /* FLOAT */) {
773
+ var divider = 1;
774
+ switch (accessor.componentType) {
775
+ case 5120 /* BYTE */:
776
+ divider = 127.0;
777
+ break;
778
+ case 5121 /* UNSIGNED_BYTE */:
779
+ divider = 255.0;
780
+ break;
781
+ case 5122 /* SHORT */:
782
+ divider = 32767.0;
783
+ break;
784
+ case 5123 /* UNSIGNED_SHORT */:
785
+ divider = 65535.0;
786
+ break;
787
+ }
788
+ for (var i = 0; i < 3; ++i) {
789
+ mmin[i] = Math.max(mmin[i] / divider, -1.0);
790
+ mmax[i] = Math.max(mmax[i] / divider, -1.0);
791
+ }
792
+ }
778
793
  var min = TmpVectors.Vector3[0], max = TmpVectors.Vector3[1];
779
794
  min.copyFromFloats.apply(min, mmin);
780
795
  max.copyFromFloats.apply(max, mmax);
@@ -796,6 +811,10 @@ var GLTFLoader = /** @class */ (function () {
796
811
  loadAttribute("TANGENT", VertexBuffer.TangentKind);
797
812
  loadAttribute("TEXCOORD_0", VertexBuffer.UVKind);
798
813
  loadAttribute("TEXCOORD_1", VertexBuffer.UV2Kind);
814
+ loadAttribute("TEXCOORD_2", VertexBuffer.UV3Kind);
815
+ loadAttribute("TEXCOORD_3", VertexBuffer.UV4Kind);
816
+ loadAttribute("TEXCOORD_4", VertexBuffer.UV5Kind);
817
+ loadAttribute("TEXCOORD_5", VertexBuffer.UV6Kind);
799
818
  loadAttribute("JOINTS_0", VertexBuffer.MatricesIndicesKind);
800
819
  loadAttribute("WEIGHTS_0", VertexBuffer.MatricesWeightsKind);
801
820
  loadAttribute("JOINTS_1", VertexBuffer.MatricesIndicesExtraKind);
@@ -821,6 +840,7 @@ var GLTFLoader = /** @class */ (function () {
821
840
  }
822
841
  var targetNames = mesh.extras ? mesh.extras.targetNames : null;
823
842
  babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
843
+ babylonMesh.morphTargetManager.areUpdatesFrozen = true;
824
844
  for (var index = 0; index < primitive.targets.length; index++) {
825
845
  var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
826
846
  var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
@@ -838,7 +858,9 @@ var GLTFLoader = /** @class */ (function () {
838
858
  var babylonMorphTarget = morphTargetManager.getTarget(index);
839
859
  promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
840
860
  }
841
- return Promise.all(promises).then(function () { });
861
+ return Promise.all(promises).then(function () {
862
+ morphTargetManager.areUpdatesFrozen = false;
863
+ });
842
864
  };
843
865
  GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
844
866
  var _this = this;
@@ -930,8 +952,9 @@ var GLTFLoader = /** @class */ (function () {
930
952
  return skin._data.promise;
931
953
  }
932
954
  var skeletonId = "skeleton" + skin.index;
933
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
955
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
934
956
  var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
957
+ babylonSkeleton._parentContainer = this._assetContainer;
935
958
  this._babylonScene._blockEntityCollection = false;
936
959
  // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
937
960
  babylonSkeleton.overrideMesh = this._rootBabylonMesh;
@@ -990,7 +1013,6 @@ var GLTFLoader = /** @class */ (function () {
990
1013
  if (babylonParentBone) {
991
1014
  baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
992
1015
  }
993
- babylonBone.setBindPose(baseMatrix);
994
1016
  babylonBone.updateMatrix(baseMatrix, false, false);
995
1017
  babylonBone._updateDifferenceMatrix(undefined, false);
996
1018
  }
@@ -1015,8 +1037,9 @@ var GLTFLoader = /** @class */ (function () {
1015
1037
  }
1016
1038
  var promises = new Array();
1017
1039
  this.logOpen(context + " " + (camera.name || ""));
1018
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
1040
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
1019
1041
  var babylonCamera = new FreeCamera(camera.name || "camera" + camera.index, Vector3.Zero(), this._babylonScene, false);
1042
+ babylonCamera._parentContainer = this._assetContainer;
1020
1043
  this._babylonScene._blockEntityCollection = false;
1021
1044
  babylonCamera.ignoreParentScaling = true;
1022
1045
  babylonCamera.rotation = new Vector3(0, Math.PI, 0);
@@ -1084,8 +1107,9 @@ var GLTFLoader = /** @class */ (function () {
1084
1107
  if (promise) {
1085
1108
  return promise;
1086
1109
  }
1087
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
1110
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
1088
1111
  var babylonAnimationGroup = new AnimationGroup(animation.name || "animation" + animation.index, this._babylonScene);
1112
+ babylonAnimationGroup._parentContainer = this._assetContainer;
1089
1113
  this._babylonScene._blockEntityCollection = false;
1090
1114
  animation._babylonAnimationGroup = babylonAnimationGroup;
1091
1115
  var promises = new Array();
@@ -1441,36 +1465,33 @@ var GLTFLoader = /** @class */ (function () {
1441
1465
  };
1442
1466
  GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
1443
1467
  var _this = this;
1444
- if (accessor._babylonVertexBuffer) {
1445
- return accessor._babylonVertexBuffer;
1468
+ var _a;
1469
+ if ((_a = accessor._babylonVertexBuffer) === null || _a === void 0 ? void 0 : _a[kind]) {
1470
+ return accessor._babylonVertexBuffer[kind];
1446
1471
  }
1447
- if (accessor.sparse) {
1448
- accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
1449
- return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
1450
- });
1472
+ if (!accessor._babylonVertexBuffer) {
1473
+ accessor._babylonVertexBuffer = {};
1451
1474
  }
1452
- // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
1453
- else if (accessor.byteOffset && accessor.byteOffset % VertexBuffer.GetTypeByteLength(accessor.componentType) !== 0) {
1454
- Logger.Warn("Accessor byte offset is not a multiple of component type byte length");
1455
- accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
1475
+ if (accessor.sparse) {
1476
+ accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
1456
1477
  return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
1457
1478
  });
1458
1479
  }
1459
1480
  // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
1460
1481
  // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
1461
1482
  else if (kind === VertexBuffer.MatricesIndicesKind || kind === VertexBuffer.MatricesIndicesExtraKind) {
1462
- accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
1483
+ accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
1463
1484
  return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
1464
1485
  });
1465
1486
  }
1466
1487
  else {
1467
1488
  var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
1468
- accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
1489
+ accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
1469
1490
  var size = GLTFLoader._GetNumComponents(context, accessor.type);
1470
1491
  return new VertexBuffer(_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true, 1, true);
1471
1492
  });
1472
1493
  }
1473
- return accessor._babylonVertexBuffer;
1494
+ return accessor._babylonVertexBuffer[kind];
1474
1495
  };
1475
1496
  GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
1476
1497
  if (!(babylonMaterial instanceof PBRMaterial)) {
@@ -1543,8 +1564,9 @@ var GLTFLoader = /** @class */ (function () {
1543
1564
  });
1544
1565
  };
1545
1566
  GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
1546
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
1567
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
1547
1568
  var babylonMaterial = new PBRMaterial(name, this._babylonScene);
1569
+ babylonMaterial._parentContainer = this._assetContainer;
1548
1570
  this._babylonScene._blockEntityCollection = false;
1549
1571
  // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
1550
1572
  babylonMaterial.fillMode = babylonDrawMode;
@@ -1694,7 +1716,7 @@ var GLTFLoader = /** @class */ (function () {
1694
1716
  return extensionPromise;
1695
1717
  }
1696
1718
  this.logOpen("" + context);
1697
- if (textureInfo.texCoord >= 2) {
1719
+ if (textureInfo.texCoord >= 6) {
1698
1720
  throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
1699
1721
  }
1700
1722
  var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
@@ -1718,27 +1740,38 @@ var GLTFLoader = /** @class */ (function () {
1718
1740
  this.logOpen(context + " " + (texture.name || ""));
1719
1741
  var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
1720
1742
  var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
1721
- var promise = this._createTextureAsync(context, sampler, image, assign);
1743
+ var promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
1722
1744
  this.logClose();
1723
1745
  return promise;
1724
1746
  };
1725
1747
  /** @hidden */
1726
- GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions) {
1748
+ GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions, useSRGBBuffer) {
1727
1749
  var _this = this;
1728
1750
  if (assign === void 0) { assign = function () { }; }
1729
1751
  var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
1730
1752
  var promises = new Array();
1731
1753
  var deferred = new Deferred();
1732
- this._babylonScene._blockEntityCollection = this._forAssetContainer;
1733
- var babylonTexture = new Texture(null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
1734
- if (!_this._disposed) {
1735
- deferred.resolve();
1736
- }
1737
- }, function (message, exception) {
1738
- if (!_this._disposed) {
1739
- deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
1740
- }
1741
- }, undefined, undefined, undefined, image.mimeType, textureLoaderOptions);
1754
+ this._babylonScene._blockEntityCollection = !!this._assetContainer;
1755
+ var textureCreationOptions = {
1756
+ noMipmap: samplerData.noMipMaps,
1757
+ invertY: false,
1758
+ samplingMode: samplerData.samplingMode,
1759
+ onLoad: function () {
1760
+ if (!_this._disposed) {
1761
+ deferred.resolve();
1762
+ }
1763
+ },
1764
+ onError: function (message, exception) {
1765
+ if (!_this._disposed) {
1766
+ deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
1767
+ }
1768
+ },
1769
+ mimeType: image.mimeType,
1770
+ loaderOptions: textureLoaderOptions,
1771
+ useSRGBBuffer: !!useSRGBBuffer && this._parent.useSRGBBuffers,
1772
+ };
1773
+ var babylonTexture = new Texture(null, this._babylonScene, textureCreationOptions);
1774
+ babylonTexture._parentContainer = this._assetContainer;
1742
1775
  this._babylonScene._blockEntityCollection = false;
1743
1776
  promises.push(deferred.promise);
1744
1777
  promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
@@ -1800,15 +1833,15 @@ var GLTFLoader = /** @class */ (function () {
1800
1833
  if (!GLTFLoader._ValidateUri(uri)) {
1801
1834
  throw new Error(context + ": '" + uri + "' is invalid");
1802
1835
  }
1803
- if (Tools.IsBase64(uri)) {
1804
- var data = new Uint8Array(Tools.DecodeBase64(uri));
1836
+ if (IsBase64DataUrl(uri)) {
1837
+ var data = new Uint8Array(DecodeBase64UrlToBinary(uri));
1805
1838
  this.log(context + ": Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
1806
1839
  return Promise.resolve(data);
1807
1840
  }
1808
1841
  this.log(context + ": Loading " + uri);
1809
1842
  return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
1810
1843
  return new Promise(function (resolve, reject) {
1811
- _this._parent._loadFile(url, _this._babylonScene, function (data) {
1844
+ _this._parent._loadFile(_this._babylonScene, url, function (data) {
1812
1845
  if (!_this._disposed) {
1813
1846
  _this.log(context + ": Loaded " + uri + " (" + data.byteLength + " bytes)");
1814
1847
  resolve(new Uint8Array(data));
@@ -1891,12 +1924,13 @@ var GLTFLoader = /** @class */ (function () {
1891
1924
  var buffer = bufferView.buffer;
1892
1925
  byteOffset = bufferView.byteOffset + (byteOffset || 0);
1893
1926
  var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
1894
- try {
1895
- return new constructor(buffer, byteOffset, length);
1896
- }
1897
- catch (e) {
1898
- throw new Error(context + ": " + e);
1927
+ var componentTypeLength = VertexBuffer.GetTypeByteLength(componentType);
1928
+ if (byteOffset % componentTypeLength !== 0) {
1929
+ // HACK: Copy the buffer if byte offset is not a multiple of component type byte length.
1930
+ Logger.Warn(context + ": Copying buffer as byte offset (" + byteOffset + ") is not a multiple of component type byte length (" + componentTypeLength + ")");
1931
+ return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
1899
1932
  }
1933
+ return new constructor(buffer, byteOffset, length);
1900
1934
  };
1901
1935
  GLTFLoader._GetNumComponents = function (context, type) {
1902
1936
  switch (type) {