@babylonjs/loaders 5.0.0-beta.6 → 5.0.0-beta.8-snapshot

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 (172) hide show
  1. package/package.json +20 -198
  2. package/OBJ/index.d.ts +0 -4
  3. package/OBJ/index.js +0 -5
  4. package/OBJ/index.js.map +0 -1
  5. package/OBJ/mtlFileLoader.d.ts +0 -40
  6. package/OBJ/mtlFileLoader.js +0 -222
  7. package/OBJ/mtlFileLoader.js.map +0 -1
  8. package/OBJ/objFileLoader.d.ts +0 -133
  9. package/OBJ/objFileLoader.js +0 -301
  10. package/OBJ/objFileLoader.js.map +0 -1
  11. package/OBJ/objLoadingOptions.d.ts +0 -43
  12. package/OBJ/objLoadingOptions.js +0 -2
  13. package/OBJ/objLoadingOptions.js.map +0 -1
  14. package/OBJ/solidParser.d.ts +0 -153
  15. package/OBJ/solidParser.js +0 -700
  16. package/OBJ/solidParser.js.map +0 -1
  17. package/STL/index.d.ts +0 -1
  18. package/STL/index.js +0 -2
  19. package/STL/index.js.map +0 -1
  20. package/STL/stlFileLoader.d.ts +0 -71
  21. package/STL/stlFileLoader.js +0 -240
  22. package/STL/stlFileLoader.js.map +0 -1
  23. package/glTF/1.0/glTFBinaryExtension.d.ts +0 -13
  24. package/glTF/1.0/glTFBinaryExtension.js +0 -62
  25. package/glTF/1.0/glTFBinaryExtension.js.map +0 -1
  26. package/glTF/1.0/glTFLoader.d.ts +0 -106
  27. package/glTF/1.0/glTFLoader.js +0 -1697
  28. package/glTF/1.0/glTFLoader.js.map +0 -1
  29. package/glTF/1.0/glTFLoaderInterfaces.d.ts +0 -412
  30. package/glTF/1.0/glTFLoaderInterfaces.js +0 -96
  31. package/glTF/1.0/glTFLoaderInterfaces.js.map +0 -1
  32. package/glTF/1.0/glTFLoaderUtils.d.ts +0 -62
  33. package/glTF/1.0/glTFLoaderUtils.js +0 -233
  34. package/glTF/1.0/glTFLoaderUtils.js.map +0 -1
  35. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +0 -10
  36. package/glTF/1.0/glTFMaterialsCommonExtension.js +0 -128
  37. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +0 -1
  38. package/glTF/1.0/index.d.ts +0 -5
  39. package/glTF/1.0/index.js +0 -6
  40. package/glTF/1.0/index.js.map +0 -1
  41. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +0 -36
  42. package/glTF/2.0/Extensions/EXT_lights_image_based.js +0 -111
  43. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +0 -1
  44. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +0 -27
  45. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +0 -80
  46. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +0 -1
  47. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +0 -27
  48. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +0 -43
  49. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +0 -1
  50. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +0 -21
  51. package/glTF/2.0/Extensions/EXT_texture_webp.js +0 -33
  52. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +0 -1
  53. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +0 -32
  54. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +0 -56
  55. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +0 -1
  56. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +0 -31
  57. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +0 -102
  58. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +0 -1
  59. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +0 -28
  60. package/glTF/2.0/Extensions/KHR_lights_punctual.js +0 -82
  61. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +0 -1
  62. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +0 -31
  63. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +0 -87
  64. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +0 -1
  65. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +0 -30
  66. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +0 -46
  67. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +0 -1
  68. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +0 -34
  69. package/glTF/2.0/Extensions/KHR_materials_ior.js +0 -55
  70. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +0 -1
  71. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +0 -30
  72. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +0 -73
  73. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +0 -1
  74. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -31
  75. package/glTF/2.0/Extensions/KHR_materials_sheen.js +0 -77
  76. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +0 -1
  77. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +0 -30
  78. package/glTF/2.0/Extensions/KHR_materials_specular.js +0 -67
  79. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +0 -1
  80. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +0 -31
  81. package/glTF/2.0/Extensions/KHR_materials_translucency.js +0 -77
  82. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +0 -1
  83. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +0 -30
  84. package/glTF/2.0/Extensions/KHR_materials_transmission.js +0 -278
  85. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +0 -1
  86. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +0 -30
  87. package/glTF/2.0/Extensions/KHR_materials_unlit.js +0 -66
  88. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +0 -1
  89. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +0 -76
  90. package/glTF/2.0/Extensions/KHR_materials_variants.js +0 -244
  91. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +0 -1
  92. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +0 -31
  93. package/glTF/2.0/Extensions/KHR_materials_volume.js +0 -79
  94. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +0 -1
  95. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +0 -19
  96. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +0 -22
  97. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +0 -1
  98. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +0 -21
  99. package/glTF/2.0/Extensions/KHR_texture_basisu.js +0 -33
  100. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +0 -1
  101. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +0 -25
  102. package/glTF/2.0/Extensions/KHR_texture_transform.js +0 -54
  103. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +0 -1
  104. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +0 -29
  105. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +0 -47
  106. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +0 -1
  107. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +0 -38
  108. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +0 -217
  109. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +0 -1
  110. package/glTF/2.0/Extensions/MSFT_lod.d.ts +0 -75
  111. package/glTF/2.0/Extensions/MSFT_lod.js +0 -334
  112. package/glTF/2.0/Extensions/MSFT_lod.js.map +0 -1
  113. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +0 -14
  114. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +0 -37
  115. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +0 -1
  116. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +0 -14
  117. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +0 -37
  118. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +0 -1
  119. package/glTF/2.0/Extensions/index.d.ts +0 -26
  120. package/glTF/2.0/Extensions/index.js +0 -27
  121. package/glTF/2.0/Extensions/index.js.map +0 -1
  122. package/glTF/2.0/glTFLoader.d.ts +0 -355
  123. package/glTF/2.0/glTFLoader.js +0 -2184
  124. package/glTF/2.0/glTFLoader.js.map +0 -1
  125. package/glTF/2.0/glTFLoaderExtension.d.ts +0 -152
  126. package/glTF/2.0/glTFLoaderExtension.js +0 -2
  127. package/glTF/2.0/glTFLoaderExtension.js.map +0 -1
  128. package/glTF/2.0/glTFLoaderInterfaces.d.ts +0 -212
  129. package/glTF/2.0/glTFLoaderInterfaces.js +0 -2
  130. package/glTF/2.0/glTFLoaderInterfaces.js.map +0 -1
  131. package/glTF/2.0/index.d.ts +0 -4
  132. package/glTF/2.0/index.js +0 -5
  133. package/glTF/2.0/index.js.map +0 -1
  134. package/glTF/glTFFileLoader.d.ts +0 -364
  135. package/glTF/glTFFileLoader.js +0 -865
  136. package/glTF/glTFFileLoader.js.map +0 -1
  137. package/glTF/glTFValidation.d.ts +0 -29
  138. package/glTF/glTFValidation.js +0 -122
  139. package/glTF/glTFValidation.js.map +0 -1
  140. package/glTF/index.d.ts +0 -5
  141. package/glTF/index.js +0 -6
  142. package/glTF/index.js.map +0 -1
  143. package/index.d.ts +0 -3
  144. package/index.js.map +0 -1
  145. package/legacy/legacy-glTF.d.ts +0 -2
  146. package/legacy/legacy-glTF.js +0 -19
  147. package/legacy/legacy-glTF.js.map +0 -1
  148. package/legacy/legacy-glTF1.d.ts +0 -2
  149. package/legacy/legacy-glTF1.js +0 -15
  150. package/legacy/legacy-glTF1.js.map +0 -1
  151. package/legacy/legacy-glTF1FileLoader.d.ts +0 -2
  152. package/legacy/legacy-glTF1FileLoader.js +0 -3
  153. package/legacy/legacy-glTF1FileLoader.js.map +0 -1
  154. package/legacy/legacy-glTF2.d.ts +0 -2
  155. package/legacy/legacy-glTF2.js +0 -33
  156. package/legacy/legacy-glTF2.js.map +0 -1
  157. package/legacy/legacy-glTF2FileLoader.d.ts +0 -2
  158. package/legacy/legacy-glTF2FileLoader.js +0 -3
  159. package/legacy/legacy-glTF2FileLoader.js.map +0 -1
  160. package/legacy/legacy-glTFFileLoader.d.ts +0 -3
  161. package/legacy/legacy-glTFFileLoader.js +0 -4
  162. package/legacy/legacy-glTFFileLoader.js.map +0 -1
  163. package/legacy/legacy-objFileLoader.d.ts +0 -1
  164. package/legacy/legacy-objFileLoader.js +0 -13
  165. package/legacy/legacy-objFileLoader.js.map +0 -1
  166. package/legacy/legacy-stlFileLoader.d.ts +0 -1
  167. package/legacy/legacy-stlFileLoader.js +0 -13
  168. package/legacy/legacy-stlFileLoader.js.map +0 -1
  169. package/legacy/legacy.d.ts +0 -6
  170. package/legacy/legacy.js +0 -7
  171. package/legacy/legacy.js.map +0 -1
  172. package/readme.md +0 -24
@@ -1,2184 +0,0 @@
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
- /**
28
- * Helper class for working with arrays when loading the glTF asset
29
- */
30
- var ArrayItem = /** @class */ (function () {
31
- function ArrayItem() {
32
- }
33
- /**
34
- * Gets an item from the given array.
35
- * @param context The context when loading the asset
36
- * @param array The array to get the item from
37
- * @param index The index to the array
38
- * @returns The array item
39
- */
40
- ArrayItem.Get = function (context, array, index) {
41
- if (!array || index == undefined || !array[index]) {
42
- throw new Error("".concat(context, ": Failed to find index (").concat(index, ")"));
43
- }
44
- return array[index];
45
- };
46
- /**
47
- * Assign an `index` field to each item of the given array.
48
- * @param array The array of items
49
- */
50
- ArrayItem.Assign = function (array) {
51
- if (array) {
52
- for (var index = 0; index < array.length; index++) {
53
- array[index].index = index;
54
- }
55
- }
56
- };
57
- return ArrayItem;
58
- }());
59
- export { ArrayItem };
60
- /**
61
- * The glTF 2.0 loader
62
- */
63
- var GLTFLoader = /** @class */ (function () {
64
- /** @hidden */
65
- function GLTFLoader(parent) {
66
- /** @hidden */
67
- this._completePromises = new Array();
68
- /** @hidden */
69
- this._assetContainer = null;
70
- /** Storage */
71
- this._babylonLights = [];
72
- /** @hidden */
73
- this._disableInstancedMesh = 0;
74
- this._disposed = false;
75
- this._extensions = new Array();
76
- this._rootBabylonMesh = null;
77
- this._defaultBabylonMaterialData = {};
78
- this._parent = parent;
79
- }
80
- /**
81
- * Registers a loader extension.
82
- * @param name The name of the loader extension.
83
- * @param factory The factory function that creates the loader extension.
84
- */
85
- GLTFLoader.RegisterExtension = function (name, factory) {
86
- if (GLTFLoader.UnregisterExtension(name)) {
87
- Logger.Warn("Extension with the name '".concat(name, "' already exists"));
88
- }
89
- GLTFLoader._RegisteredExtensions[name] = {
90
- factory: factory
91
- };
92
- };
93
- /**
94
- * Unregisters a loader extension.
95
- * @param name The name of the loader extension.
96
- * @returns A boolean indicating whether the extension has been unregistered
97
- */
98
- GLTFLoader.UnregisterExtension = function (name) {
99
- if (!GLTFLoader._RegisteredExtensions[name]) {
100
- return false;
101
- }
102
- delete GLTFLoader._RegisteredExtensions[name];
103
- return true;
104
- };
105
- Object.defineProperty(GLTFLoader.prototype, "gltf", {
106
- /**
107
- * The object that represents the glTF JSON.
108
- */
109
- get: function () {
110
- return this._gltf;
111
- },
112
- enumerable: false,
113
- configurable: true
114
- });
115
- Object.defineProperty(GLTFLoader.prototype, "bin", {
116
- /**
117
- * The BIN chunk of a binary glTF.
118
- */
119
- get: function () {
120
- return this._bin;
121
- },
122
- enumerable: false,
123
- configurable: true
124
- });
125
- Object.defineProperty(GLTFLoader.prototype, "parent", {
126
- /**
127
- * The parent file loader.
128
- */
129
- get: function () {
130
- return this._parent;
131
- },
132
- enumerable: false,
133
- configurable: true
134
- });
135
- Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
136
- /**
137
- * The Babylon scene when loading the asset.
138
- */
139
- get: function () {
140
- return this._babylonScene;
141
- },
142
- enumerable: false,
143
- configurable: true
144
- });
145
- Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
146
- /**
147
- * The root Babylon mesh when loading the asset.
148
- */
149
- get: function () {
150
- return this._rootBabylonMesh;
151
- },
152
- enumerable: false,
153
- configurable: true
154
- });
155
- /** @hidden */
156
- GLTFLoader.prototype.dispose = function () {
157
- if (this._disposed) {
158
- return;
159
- }
160
- this._disposed = true;
161
- this._completePromises.length = 0;
162
- for (var name_1 in this._extensions) {
163
- var extension = this._extensions[name_1];
164
- extension.dispose && extension.dispose();
165
- delete this._extensions[name_1];
166
- }
167
- this._gltf = null;
168
- this._babylonScene = null;
169
- this._rootBabylonMesh = null;
170
- this._parent.dispose();
171
- };
172
- /** @hidden */
173
- GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, container, data, rootUrl, onProgress, fileName) {
174
- var _this = this;
175
- if (fileName === void 0) { fileName = ""; }
176
- return Promise.resolve().then(function () {
177
- _this._babylonScene = scene;
178
- _this._assetContainer = container;
179
- _this._loadData(data);
180
- var nodes = null;
181
- if (meshesNames) {
182
- var nodeMap_1 = {};
183
- if (_this._gltf.nodes) {
184
- for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
185
- var node = _a[_i];
186
- if (node.name) {
187
- nodeMap_1[node.name] = node.index;
188
- }
189
- }
190
- }
191
- var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
192
- nodes = names.map(function (name) {
193
- var node = nodeMap_1[name];
194
- if (node === undefined) {
195
- throw new Error("Failed to find node '".concat(name, "'"));
196
- }
197
- return node;
198
- });
199
- }
200
- return _this._loadAsync(rootUrl, fileName, nodes, function () {
201
- return {
202
- meshes: _this._getMeshes(),
203
- particleSystems: [],
204
- skeletons: _this._getSkeletons(),
205
- animationGroups: _this._getAnimationGroups(),
206
- lights: _this._babylonLights,
207
- transformNodes: _this._getTransformNodes(),
208
- geometries: _this._getGeometries()
209
- };
210
- });
211
- });
212
- };
213
- /** @hidden */
214
- GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
215
- var _this = this;
216
- if (fileName === void 0) { fileName = ""; }
217
- return Promise.resolve().then(function () {
218
- _this._babylonScene = scene;
219
- _this._loadData(data);
220
- return _this._loadAsync(rootUrl, fileName, null, function () { return undefined; });
221
- });
222
- };
223
- GLTFLoader.prototype._loadAsync = function (rootUrl, fileName, nodes, resultFunc) {
224
- var _this = this;
225
- return Promise.resolve().then(function () {
226
- _this._rootUrl = rootUrl;
227
- _this._uniqueRootUrl = (!StringTools.StartsWith(rootUrl, "file:") && fileName) ? rootUrl : "".concat(rootUrl).concat(Date.now(), "/");
228
- _this._fileName = fileName;
229
- _this._loadExtensions();
230
- _this._checkExtensions();
231
- var loadingToReadyCounterName = "".concat(GLTFLoaderState[GLTFLoaderState.LOADING], " => ").concat(GLTFLoaderState[GLTFLoaderState.READY]);
232
- var loadingToCompleteCounterName = "".concat(GLTFLoaderState[GLTFLoaderState.LOADING], " => ").concat(GLTFLoaderState[GLTFLoaderState.COMPLETE]);
233
- _this._parent._startPerformanceCounter(loadingToReadyCounterName);
234
- _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
235
- _this._parent._setState(GLTFLoaderState.LOADING);
236
- _this._extensionsOnLoading();
237
- var promises = new Array();
238
- // Block the marking of materials dirty until the scene is loaded.
239
- var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
240
- _this._babylonScene.blockMaterialDirtyMechanism = true;
241
- if (nodes) {
242
- promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
243
- }
244
- else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
245
- var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
246
- promises.push(_this.loadSceneAsync("/scenes/".concat(scene.index), scene));
247
- }
248
- if (_this.parent.loadAllMaterials && _this._gltf.materials) {
249
- for (var m = 0; m < _this._gltf.materials.length; ++m) {
250
- var material = _this._gltf.materials[m];
251
- var context_1 = "/materials/" + m;
252
- var babylonDrawMode = Material.TriangleFillMode;
253
- promises.push(_this._loadMaterialAsync(context_1, material, null, babylonDrawMode, function (material) { }));
254
- }
255
- }
256
- // Restore the blocking of material dirty.
257
- _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
258
- if (_this._parent.compileMaterials) {
259
- promises.push(_this._compileMaterialsAsync());
260
- }
261
- if (_this._parent.compileShadowGenerators) {
262
- promises.push(_this._compileShadowGeneratorsAsync());
263
- }
264
- var resultPromise = Promise.all(promises).then(function () {
265
- if (_this._rootBabylonMesh) {
266
- _this._rootBabylonMesh.setEnabled(true);
267
- }
268
- _this._extensionsOnReady();
269
- _this._parent._setState(GLTFLoaderState.READY);
270
- _this._startAnimations();
271
- return resultFunc();
272
- });
273
- return resultPromise.then(function (result) {
274
- _this._parent._endPerformanceCounter(loadingToReadyCounterName);
275
- Tools.SetImmediate(function () {
276
- if (!_this._disposed) {
277
- Promise.all(_this._completePromises).then(function () {
278
- _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
279
- _this._parent._setState(GLTFLoaderState.COMPLETE);
280
- _this._parent.onCompleteObservable.notifyObservers(undefined);
281
- _this._parent.onCompleteObservable.clear();
282
- _this.dispose();
283
- }, function (error) {
284
- _this._parent.onErrorObservable.notifyObservers(error);
285
- _this._parent.onErrorObservable.clear();
286
- _this.dispose();
287
- });
288
- }
289
- });
290
- return result;
291
- });
292
- }).catch(function (error) {
293
- if (!_this._disposed) {
294
- _this._parent.onErrorObservable.notifyObservers(error);
295
- _this._parent.onErrorObservable.clear();
296
- _this.dispose();
297
- }
298
- throw error;
299
- });
300
- };
301
- GLTFLoader.prototype._loadData = function (data) {
302
- this._gltf = data.json;
303
- this._setupData();
304
- if (data.bin) {
305
- var buffers = this._gltf.buffers;
306
- if (buffers && buffers[0] && !buffers[0].uri) {
307
- var binaryBuffer = buffers[0];
308
- if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
309
- Logger.Warn("Binary buffer length (".concat(binaryBuffer.byteLength, ") from JSON does not match chunk length (").concat(data.bin.byteLength, ")"));
310
- }
311
- this._bin = data.bin;
312
- }
313
- else {
314
- Logger.Warn("Unexpected BIN chunk");
315
- }
316
- }
317
- };
318
- GLTFLoader.prototype._setupData = function () {
319
- ArrayItem.Assign(this._gltf.accessors);
320
- ArrayItem.Assign(this._gltf.animations);
321
- ArrayItem.Assign(this._gltf.buffers);
322
- ArrayItem.Assign(this._gltf.bufferViews);
323
- ArrayItem.Assign(this._gltf.cameras);
324
- ArrayItem.Assign(this._gltf.images);
325
- ArrayItem.Assign(this._gltf.materials);
326
- ArrayItem.Assign(this._gltf.meshes);
327
- ArrayItem.Assign(this._gltf.nodes);
328
- ArrayItem.Assign(this._gltf.samplers);
329
- ArrayItem.Assign(this._gltf.scenes);
330
- ArrayItem.Assign(this._gltf.skins);
331
- ArrayItem.Assign(this._gltf.textures);
332
- if (this._gltf.nodes) {
333
- var nodeParents = {};
334
- for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
335
- var node = _a[_i];
336
- if (node.children) {
337
- for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
338
- var index = _c[_b];
339
- nodeParents[index] = node.index;
340
- }
341
- }
342
- }
343
- var rootNode = this._createRootNode();
344
- for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
345
- var node = _e[_d];
346
- var parentIndex = nodeParents[node.index];
347
- node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
348
- }
349
- }
350
- };
351
- GLTFLoader.prototype._loadExtensions = function () {
352
- for (var name_2 in GLTFLoader._RegisteredExtensions) {
353
- var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
354
- if (extension.name !== name_2) {
355
- Logger.Warn("The name of the glTF loader extension instance does not match the registered name: ".concat(extension.name, " !== ").concat(name_2));
356
- }
357
- this._extensions.push(extension);
358
- this._parent.onExtensionLoadedObservable.notifyObservers(extension);
359
- }
360
- this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
361
- this._parent.onExtensionLoadedObservable.clear();
362
- };
363
- GLTFLoader.prototype._checkExtensions = function () {
364
- if (this._gltf.extensionsRequired) {
365
- var _loop_1 = function (name_3) {
366
- var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
367
- if (!available) {
368
- throw new Error("Require extension ".concat(name_3, " is not available"));
369
- }
370
- };
371
- var this_1 = this;
372
- for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
373
- var name_3 = _a[_i];
374
- _loop_1(name_3);
375
- }
376
- }
377
- };
378
- GLTFLoader.prototype._createRootNode = function () {
379
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
380
- this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
381
- this._rootBabylonMesh._parentContainer = this._assetContainer;
382
- this._babylonScene._blockEntityCollection = false;
383
- this._rootBabylonMesh.setEnabled(false);
384
- var rootNode = {
385
- _babylonTransformNode: this._rootBabylonMesh,
386
- index: -1
387
- };
388
- switch (this._parent.coordinateSystemMode) {
389
- case GLTFLoaderCoordinateSystemMode.AUTO: {
390
- if (!this._babylonScene.useRightHandedSystem) {
391
- rootNode.rotation = [0, 1, 0, 0];
392
- rootNode.scale = [1, 1, -1];
393
- GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
394
- }
395
- break;
396
- }
397
- case GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED: {
398
- this._babylonScene.useRightHandedSystem = true;
399
- break;
400
- }
401
- default: {
402
- throw new Error("Invalid coordinate system mode (".concat(this._parent.coordinateSystemMode, ")"));
403
- }
404
- }
405
- this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
406
- return rootNode;
407
- };
408
- /**
409
- * Loads a glTF scene.
410
- * @param context The context when loading the asset
411
- * @param scene The glTF scene property
412
- * @returns A promise that resolves when the load is complete
413
- */
414
- GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
415
- var _this = this;
416
- var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
417
- if (extensionPromise) {
418
- return extensionPromise;
419
- }
420
- var promises = new Array();
421
- this.logOpen("".concat(context, " ").concat(scene.name || ""));
422
- if (scene.nodes) {
423
- for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
424
- var index = _a[_i];
425
- var node = ArrayItem.Get("".concat(context, "/nodes/").concat(index), this._gltf.nodes, index);
426
- promises.push(this.loadNodeAsync("/nodes/".concat(node.index), node, function (babylonMesh) {
427
- babylonMesh.parent = _this._rootBabylonMesh;
428
- }));
429
- }
430
- }
431
- // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
432
- // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
433
- if (this._gltf.nodes) {
434
- for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
435
- var node = _c[_b];
436
- if (node._babylonTransformNode && node._babylonBones) {
437
- for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
438
- var babylonBone = _e[_d];
439
- babylonBone.linkTransformNode(node._babylonTransformNode);
440
- }
441
- }
442
- }
443
- }
444
- promises.push(this._loadAnimationsAsync());
445
- this.logClose();
446
- return Promise.all(promises).then(function () { });
447
- };
448
- GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
449
- if (node._primitiveBabylonMeshes) {
450
- for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
451
- var babylonMesh = _a[_i];
452
- callback(babylonMesh);
453
- }
454
- }
455
- };
456
- GLTFLoader.prototype._getGeometries = function () {
457
- var geometries = new Array();
458
- var nodes = this._gltf.nodes;
459
- if (nodes) {
460
- for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
461
- var node = nodes_1[_i];
462
- this._forEachPrimitive(node, function (babylonMesh) {
463
- var geometry = babylonMesh.geometry;
464
- if (geometry && geometries.indexOf(geometry) === -1) {
465
- geometries.push(geometry);
466
- }
467
- });
468
- }
469
- }
470
- return geometries;
471
- };
472
- GLTFLoader.prototype._getMeshes = function () {
473
- var meshes = new Array();
474
- // Root mesh is always first, if available.
475
- if (this._rootBabylonMesh) {
476
- meshes.push(this._rootBabylonMesh);
477
- }
478
- var nodes = this._gltf.nodes;
479
- if (nodes) {
480
- for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
481
- var node = nodes_2[_i];
482
- this._forEachPrimitive(node, function (babylonMesh) {
483
- meshes.push(babylonMesh);
484
- });
485
- }
486
- }
487
- return meshes;
488
- };
489
- GLTFLoader.prototype._getTransformNodes = function () {
490
- var transformNodes = new Array();
491
- var nodes = this._gltf.nodes;
492
- if (nodes) {
493
- for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
494
- var node = nodes_3[_i];
495
- if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
496
- transformNodes.push(node._babylonTransformNode);
497
- }
498
- }
499
- }
500
- return transformNodes;
501
- };
502
- GLTFLoader.prototype._getSkeletons = function () {
503
- var skeletons = new Array();
504
- var skins = this._gltf.skins;
505
- if (skins) {
506
- for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
507
- var skin = skins_1[_i];
508
- if (skin._data) {
509
- skeletons.push(skin._data.babylonSkeleton);
510
- }
511
- }
512
- }
513
- return skeletons;
514
- };
515
- GLTFLoader.prototype._getAnimationGroups = function () {
516
- var animationGroups = new Array();
517
- var animations = this._gltf.animations;
518
- if (animations) {
519
- for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
520
- var animation = animations_1[_i];
521
- if (animation._babylonAnimationGroup) {
522
- animationGroups.push(animation._babylonAnimationGroup);
523
- }
524
- }
525
- }
526
- return animationGroups;
527
- };
528
- GLTFLoader.prototype._startAnimations = function () {
529
- switch (this._parent.animationStartMode) {
530
- case GLTFLoaderAnimationStartMode.NONE: {
531
- // do nothing
532
- break;
533
- }
534
- case GLTFLoaderAnimationStartMode.FIRST: {
535
- var babylonAnimationGroups = this._getAnimationGroups();
536
- if (babylonAnimationGroups.length !== 0) {
537
- babylonAnimationGroups[0].start(true);
538
- }
539
- break;
540
- }
541
- case GLTFLoaderAnimationStartMode.ALL: {
542
- var babylonAnimationGroups = this._getAnimationGroups();
543
- for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
544
- var babylonAnimationGroup = babylonAnimationGroups_1[_i];
545
- babylonAnimationGroup.start(true);
546
- }
547
- break;
548
- }
549
- default: {
550
- Logger.Error("Invalid animation start mode (".concat(this._parent.animationStartMode, ")"));
551
- return;
552
- }
553
- }
554
- };
555
- /**
556
- * Loads a glTF node.
557
- * @param context The context when loading the asset
558
- * @param node The glTF node property
559
- * @param assign A function called synchronously after parsing the glTF properties
560
- * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
561
- */
562
- GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
563
- var _this = this;
564
- if (assign === void 0) { assign = function () { }; }
565
- var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
566
- if (extensionPromise) {
567
- return extensionPromise;
568
- }
569
- if (node._babylonTransformNode) {
570
- throw new Error("".concat(context, ": Invalid recursive node hierarchy"));
571
- }
572
- var promises = new Array();
573
- this.logOpen("".concat(context, " ").concat(node.name || ""));
574
- var loadNode = function (babylonTransformNode) {
575
- GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
576
- GLTFLoader._LoadTransform(node, babylonTransformNode);
577
- if (node.camera != undefined) {
578
- var camera = ArrayItem.Get("".concat(context, "/camera"), _this._gltf.cameras, node.camera);
579
- promises.push(_this.loadCameraAsync("/cameras/".concat(camera.index), camera, function (babylonCamera) {
580
- babylonCamera.parent = babylonTransformNode;
581
- }));
582
- }
583
- if (node.children) {
584
- for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
585
- var index = _a[_i];
586
- var childNode = ArrayItem.Get("".concat(context, "/children/").concat(index), _this._gltf.nodes, index);
587
- promises.push(_this.loadNodeAsync("/nodes/".concat(childNode.index), childNode, function (childBabylonMesh) {
588
- childBabylonMesh.parent = babylonTransformNode;
589
- }));
590
- }
591
- }
592
- assign(babylonTransformNode);
593
- };
594
- if (node.mesh == undefined) {
595
- var nodeName = node.name || "node".concat(node.index);
596
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
597
- node._babylonTransformNode = new TransformNode(nodeName, this._babylonScene);
598
- node._babylonTransformNode._parentContainer = this._assetContainer;
599
- this._babylonScene._blockEntityCollection = false;
600
- loadNode(node._babylonTransformNode);
601
- }
602
- else {
603
- var mesh = ArrayItem.Get("".concat(context, "/mesh"), this._gltf.meshes, node.mesh);
604
- promises.push(this._loadMeshAsync("/meshes/".concat(mesh.index), node, mesh, loadNode));
605
- }
606
- this.logClose();
607
- return Promise.all(promises).then(function () {
608
- _this._forEachPrimitive(node, function (babylonMesh) {
609
- if (babylonMesh.geometry && babylonMesh.geometry.useBoundingInfoFromGeometry) {
610
- // simply apply the world matrices to the bounding info - the extends are already ok
611
- babylonMesh._updateBoundingInfo();
612
- }
613
- else {
614
- babylonMesh.refreshBoundingInfo(true);
615
- }
616
- });
617
- return node._babylonTransformNode;
618
- });
619
- };
620
- GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
621
- var primitives = mesh.primitives;
622
- if (!primitives || !primitives.length) {
623
- throw new Error("".concat(context, ": Primitives are missing"));
624
- }
625
- if (primitives[0].index == undefined) {
626
- ArrayItem.Assign(primitives);
627
- }
628
- var promises = new Array();
629
- this.logOpen("".concat(context, " ").concat(mesh.name || ""));
630
- var name = node.name || "node".concat(node.index);
631
- if (primitives.length === 1) {
632
- var primitive = mesh.primitives[0];
633
- promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), name, node, mesh, primitive, function (babylonMesh) {
634
- node._babylonTransformNode = babylonMesh;
635
- node._primitiveBabylonMeshes = [babylonMesh];
636
- }));
637
- }
638
- else {
639
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
640
- node._babylonTransformNode = new TransformNode(name, this._babylonScene);
641
- node._babylonTransformNode._parentContainer = this._assetContainer;
642
- this._babylonScene._blockEntityCollection = false;
643
- node._primitiveBabylonMeshes = [];
644
- for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
645
- var primitive = primitives_1[_i];
646
- promises.push(this._loadMeshPrimitiveAsync("".concat(context, "/primitives/").concat(primitive.index), "".concat(name, "_primitive").concat(primitive.index), node, mesh, primitive, function (babylonMesh) {
647
- babylonMesh.parent = node._babylonTransformNode;
648
- node._primitiveBabylonMeshes.push(babylonMesh);
649
- }));
650
- }
651
- }
652
- if (node.skin != undefined) {
653
- var skin = ArrayItem.Get("".concat(context, "/skin"), this._gltf.skins, node.skin);
654
- promises.push(this._loadSkinAsync("/skins/".concat(skin.index), node, skin));
655
- }
656
- assign(node._babylonTransformNode);
657
- this.logClose();
658
- return Promise.all(promises).then(function () {
659
- return node._babylonTransformNode;
660
- });
661
- };
662
- /**
663
- * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
664
- * @param context The context when loading the asset
665
- * @param name The mesh name when loading the asset
666
- * @param node The glTF node when loading the asset
667
- * @param mesh The glTF mesh when loading the asset
668
- * @param primitive The glTF mesh primitive property
669
- * @param assign A function called synchronously after parsing the glTF properties
670
- * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
671
- */
672
- GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
673
- var _this = this;
674
- var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
675
- if (extensionPromise) {
676
- return extensionPromise;
677
- }
678
- this.logOpen("".concat(context));
679
- var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
680
- var babylonAbstractMesh;
681
- var promise;
682
- if (shouldInstance && primitive._instanceData) {
683
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
684
- babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
685
- babylonAbstractMesh._parentContainer = this._assetContainer;
686
- this._babylonScene._blockEntityCollection = false;
687
- promise = primitive._instanceData.promise;
688
- }
689
- else {
690
- var promises = new Array();
691
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
692
- var babylonMesh_1 = new Mesh(name, this._babylonScene);
693
- babylonMesh_1._parentContainer = this._assetContainer;
694
- this._babylonScene._blockEntityCollection = false;
695
- babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
696
- this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
697
- promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
698
- return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
699
- _this._babylonScene._blockEntityCollection = !!_this._assetContainer;
700
- babylonGeometry.applyToMesh(babylonMesh_1);
701
- babylonGeometry._parentContainer = _this._assetContainer;
702
- _this._babylonScene._blockEntityCollection = false;
703
- });
704
- }));
705
- var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
706
- if (primitive.material == undefined) {
707
- var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
708
- if (!babylonMaterial) {
709
- babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
710
- this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
711
- this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
712
- }
713
- babylonMesh_1.material = babylonMaterial;
714
- }
715
- else {
716
- var material = ArrayItem.Get("".concat(context, "/material"), this._gltf.materials, primitive.material);
717
- promises.push(this._loadMaterialAsync("/materials/".concat(material.index), material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
718
- babylonMesh_1.material = babylonMaterial;
719
- }));
720
- }
721
- promise = Promise.all(promises);
722
- if (shouldInstance) {
723
- primitive._instanceData = {
724
- babylonSourceMesh: babylonMesh_1,
725
- promise: promise
726
- };
727
- }
728
- babylonAbstractMesh = babylonMesh_1;
729
- }
730
- GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
731
- this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
732
- assign(babylonAbstractMesh);
733
- this.logClose();
734
- return promise.then(function () {
735
- return babylonAbstractMesh;
736
- });
737
- };
738
- GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
739
- var _this = this;
740
- var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
741
- if (extensionPromise) {
742
- return extensionPromise;
743
- }
744
- var attributes = primitive.attributes;
745
- if (!attributes) {
746
- throw new Error("".concat(context, ": Attributes are missing"));
747
- }
748
- var promises = new Array();
749
- var babylonGeometry = new Geometry(babylonMesh.name, this._babylonScene);
750
- if (primitive.indices == undefined) {
751
- babylonMesh.isUnIndexed = true;
752
- }
753
- else {
754
- var accessor = ArrayItem.Get("".concat(context, "/indices"), this._gltf.accessors, primitive.indices);
755
- promises.push(this._loadIndicesAccessorAsync("/accessors/".concat(accessor.index), accessor).then(function (data) {
756
- babylonGeometry.setIndices(data);
757
- }));
758
- }
759
- var loadAttribute = function (attribute, kind, callback) {
760
- if (attributes[attribute] == undefined) {
761
- return;
762
- }
763
- babylonMesh._delayInfo = babylonMesh._delayInfo || [];
764
- if (babylonMesh._delayInfo.indexOf(kind) === -1) {
765
- babylonMesh._delayInfo.push(kind);
766
- }
767
- var accessor = ArrayItem.Get("".concat(context, "/attributes/").concat(attribute), _this._gltf.accessors, attributes[attribute]);
768
- promises.push(_this._loadVertexAccessorAsync("/accessors/".concat(accessor.index), accessor, kind).then(function (babylonVertexBuffer) {
769
- if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
770
- var mmin = accessor.min, mmax = accessor.max;
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
- }
793
- var min = TmpVectors.Vector3[0], max = TmpVectors.Vector3[1];
794
- min.copyFromFloats.apply(min, mmin);
795
- max.copyFromFloats.apply(max, mmax);
796
- babylonGeometry._boundingInfo = new BoundingInfo(min, max);
797
- babylonGeometry.useBoundingInfoFromGeometry = true;
798
- }
799
- }
800
- babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
801
- }));
802
- if (kind == VertexBuffer.MatricesIndicesExtraKind) {
803
- babylonMesh.numBoneInfluencers = 8;
804
- }
805
- if (callback) {
806
- callback(accessor);
807
- }
808
- };
809
- loadAttribute("POSITION", VertexBuffer.PositionKind);
810
- loadAttribute("NORMAL", VertexBuffer.NormalKind);
811
- loadAttribute("TANGENT", VertexBuffer.TangentKind);
812
- loadAttribute("TEXCOORD_0", VertexBuffer.UVKind);
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);
818
- loadAttribute("JOINTS_0", VertexBuffer.MatricesIndicesKind);
819
- loadAttribute("WEIGHTS_0", VertexBuffer.MatricesWeightsKind);
820
- loadAttribute("JOINTS_1", VertexBuffer.MatricesIndicesExtraKind);
821
- loadAttribute("WEIGHTS_1", VertexBuffer.MatricesWeightsExtraKind);
822
- loadAttribute("COLOR_0", VertexBuffer.ColorKind, function (accessor) {
823
- if (accessor.type === "VEC4" /* VEC4 */) {
824
- babylonMesh.hasVertexAlpha = true;
825
- }
826
- });
827
- return Promise.all(promises).then(function () {
828
- return babylonGeometry;
829
- });
830
- };
831
- GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
832
- if (!primitive.targets) {
833
- return;
834
- }
835
- if (node._numMorphTargets == undefined) {
836
- node._numMorphTargets = primitive.targets.length;
837
- }
838
- else if (primitive.targets.length !== node._numMorphTargets) {
839
- throw new Error("".concat(context, ": Primitives do not have the same number of targets"));
840
- }
841
- var targetNames = mesh.extras ? mesh.extras.targetNames : null;
842
- babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
843
- babylonMesh.morphTargetManager.areUpdatesFrozen = true;
844
- for (var index = 0; index < primitive.targets.length; index++) {
845
- var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
846
- var name_4 = targetNames ? targetNames[index] : "morphTarget".concat(index);
847
- babylonMesh.morphTargetManager.addTarget(new MorphTarget(name_4, weight, babylonMesh.getScene()));
848
- // TODO: tell the target whether it has positions, normals, tangents
849
- }
850
- };
851
- GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
852
- if (!primitive.targets) {
853
- return Promise.resolve();
854
- }
855
- var promises = new Array();
856
- var morphTargetManager = babylonMesh.morphTargetManager;
857
- for (var index = 0; index < morphTargetManager.numTargets; index++) {
858
- var babylonMorphTarget = morphTargetManager.getTarget(index);
859
- promises.push(this._loadMorphTargetVertexDataAsync("".concat(context, "/targets/").concat(index), babylonGeometry, primitive.targets[index], babylonMorphTarget));
860
- }
861
- return Promise.all(promises).then(function () {
862
- morphTargetManager.areUpdatesFrozen = false;
863
- });
864
- };
865
- GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
866
- var _this = this;
867
- var promises = new Array();
868
- var loadAttribute = function (attribute, kind, setData) {
869
- if (attributes[attribute] == undefined) {
870
- return;
871
- }
872
- var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
873
- if (!babylonVertexBuffer) {
874
- return;
875
- }
876
- var accessor = ArrayItem.Get("".concat(context, "/").concat(attribute), _this._gltf.accessors, attributes[attribute]);
877
- promises.push(_this._loadFloatAccessorAsync("/accessors/".concat(accessor.index), accessor).then(function (data) {
878
- setData(babylonVertexBuffer, data);
879
- }));
880
- };
881
- loadAttribute("POSITION", VertexBuffer.PositionKind, function (babylonVertexBuffer, data) {
882
- var positions = new Float32Array(data.length);
883
- babylonVertexBuffer.forEach(data.length, function (value, index) {
884
- positions[index] = data[index] + value;
885
- });
886
- babylonMorphTarget.setPositions(positions);
887
- });
888
- loadAttribute("NORMAL", VertexBuffer.NormalKind, function (babylonVertexBuffer, data) {
889
- var normals = new Float32Array(data.length);
890
- babylonVertexBuffer.forEach(normals.length, function (value, index) {
891
- normals[index] = data[index] + value;
892
- });
893
- babylonMorphTarget.setNormals(normals);
894
- });
895
- loadAttribute("TANGENT", VertexBuffer.TangentKind, function (babylonVertexBuffer, data) {
896
- var tangents = new Float32Array(data.length / 3 * 4);
897
- var dataIndex = 0;
898
- babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
899
- // Tangent data for morph targets is stored as xyz delta.
900
- // The vertexData.tangent is stored as xyzw.
901
- // So we need to skip every fourth vertexData.tangent.
902
- if (((index + 1) % 4) !== 0) {
903
- tangents[dataIndex] = data[dataIndex] + value;
904
- dataIndex++;
905
- }
906
- });
907
- babylonMorphTarget.setTangents(tangents);
908
- });
909
- return Promise.all(promises).then(function () { });
910
- };
911
- GLTFLoader._LoadTransform = function (node, babylonNode) {
912
- // Ignore the TRS of skinned nodes.
913
- // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
914
- if (node.skin != undefined) {
915
- return;
916
- }
917
- var position = Vector3.Zero();
918
- var rotation = Quaternion.Identity();
919
- var scaling = Vector3.One();
920
- if (node.matrix) {
921
- var matrix = Matrix.FromArray(node.matrix);
922
- matrix.decompose(scaling, rotation, position);
923
- }
924
- else {
925
- if (node.translation) {
926
- position = Vector3.FromArray(node.translation);
927
- }
928
- if (node.rotation) {
929
- rotation = Quaternion.FromArray(node.rotation);
930
- }
931
- if (node.scale) {
932
- scaling = Vector3.FromArray(node.scale);
933
- }
934
- }
935
- babylonNode.position = position;
936
- babylonNode.rotationQuaternion = rotation;
937
- babylonNode.scaling = scaling;
938
- };
939
- GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
940
- var _this = this;
941
- var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
942
- if (extensionPromise) {
943
- return extensionPromise;
944
- }
945
- var assignSkeleton = function (skeleton) {
946
- _this._forEachPrimitive(node, function (babylonMesh) {
947
- babylonMesh.skeleton = skeleton;
948
- });
949
- };
950
- if (skin._data) {
951
- assignSkeleton(skin._data.babylonSkeleton);
952
- return skin._data.promise;
953
- }
954
- var skeletonId = "skeleton".concat(skin.index);
955
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
956
- var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
957
- babylonSkeleton._parentContainer = this._assetContainer;
958
- this._babylonScene._blockEntityCollection = false;
959
- // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
960
- babylonSkeleton.overrideMesh = this._rootBabylonMesh;
961
- this._loadBones(context, skin, babylonSkeleton);
962
- assignSkeleton(babylonSkeleton);
963
- var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
964
- _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
965
- });
966
- skin._data = {
967
- babylonSkeleton: babylonSkeleton,
968
- promise: promise
969
- };
970
- return promise;
971
- };
972
- GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
973
- var babylonBones = {};
974
- for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
975
- var index = _a[_i];
976
- var node = ArrayItem.Get("".concat(context, "/joints/").concat(index), this._gltf.nodes, index);
977
- this._loadBone(node, skin, babylonSkeleton, babylonBones);
978
- }
979
- };
980
- GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
981
- var babylonBone = babylonBones[node.index];
982
- if (babylonBone) {
983
- return babylonBone;
984
- }
985
- var babylonParentBone = null;
986
- if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
987
- babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
988
- }
989
- var boneIndex = skin.joints.indexOf(node.index);
990
- babylonBone = new Bone(node.name || "joint".concat(node.index), babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
991
- babylonBones[node.index] = babylonBone;
992
- node._babylonBones = node._babylonBones || [];
993
- node._babylonBones.push(babylonBone);
994
- return babylonBone;
995
- };
996
- GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
997
- if (skin.inverseBindMatrices == undefined) {
998
- return Promise.resolve(null);
999
- }
1000
- var accessor = ArrayItem.Get("".concat(context, "/inverseBindMatrices"), this._gltf.accessors, skin.inverseBindMatrices);
1001
- return this._loadFloatAccessorAsync("/accessors/".concat(accessor.index), accessor);
1002
- };
1003
- GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
1004
- for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
1005
- var babylonBone = _a[_i];
1006
- var baseMatrix = Matrix.Identity();
1007
- var boneIndex = babylonBone._index;
1008
- if (inverseBindMatricesData && boneIndex !== -1) {
1009
- Matrix.FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
1010
- baseMatrix.invertToRef(baseMatrix);
1011
- }
1012
- var babylonParentBone = babylonBone.getParent();
1013
- if (babylonParentBone) {
1014
- baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
1015
- }
1016
- babylonBone.updateMatrix(baseMatrix, false, false);
1017
- babylonBone._updateDifferenceMatrix(undefined, false);
1018
- }
1019
- };
1020
- GLTFLoader.prototype._getNodeMatrix = function (node) {
1021
- return node.matrix ?
1022
- Matrix.FromArray(node.matrix) :
1023
- Matrix.Compose(node.scale ? Vector3.FromArray(node.scale) : Vector3.One(), node.rotation ? Quaternion.FromArray(node.rotation) : Quaternion.Identity(), node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
1024
- };
1025
- /**
1026
- * Loads a glTF camera.
1027
- * @param context The context when loading the asset
1028
- * @param camera The glTF camera property
1029
- * @param assign A function called synchronously after parsing the glTF properties
1030
- * @returns A promise that resolves with the loaded Babylon camera when the load is complete
1031
- */
1032
- GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
1033
- if (assign === void 0) { assign = function () { }; }
1034
- var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
1035
- if (extensionPromise) {
1036
- return extensionPromise;
1037
- }
1038
- var promises = new Array();
1039
- this.logOpen("".concat(context, " ").concat(camera.name || ""));
1040
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1041
- var babylonCamera = new FreeCamera(camera.name || "camera".concat(camera.index), Vector3.Zero(), this._babylonScene, false);
1042
- babylonCamera._parentContainer = this._assetContainer;
1043
- this._babylonScene._blockEntityCollection = false;
1044
- babylonCamera.ignoreParentScaling = true;
1045
- babylonCamera.rotation = new Vector3(0, Math.PI, 0);
1046
- switch (camera.type) {
1047
- case "perspective" /* PERSPECTIVE */: {
1048
- var perspective = camera.perspective;
1049
- if (!perspective) {
1050
- throw new Error("".concat(context, ": Camera perspective properties are missing"));
1051
- }
1052
- babylonCamera.fov = perspective.yfov;
1053
- babylonCamera.minZ = perspective.znear;
1054
- babylonCamera.maxZ = perspective.zfar || 0;
1055
- break;
1056
- }
1057
- case "orthographic" /* ORTHOGRAPHIC */: {
1058
- if (!camera.orthographic) {
1059
- throw new Error("".concat(context, ": Camera orthographic properties are missing"));
1060
- }
1061
- babylonCamera.mode = Camera.ORTHOGRAPHIC_CAMERA;
1062
- babylonCamera.orthoLeft = -camera.orthographic.xmag;
1063
- babylonCamera.orthoRight = camera.orthographic.xmag;
1064
- babylonCamera.orthoBottom = -camera.orthographic.ymag;
1065
- babylonCamera.orthoTop = camera.orthographic.ymag;
1066
- babylonCamera.minZ = camera.orthographic.znear;
1067
- babylonCamera.maxZ = camera.orthographic.zfar;
1068
- break;
1069
- }
1070
- default: {
1071
- throw new Error("".concat(context, ": Invalid camera type (").concat(camera.type, ")"));
1072
- }
1073
- }
1074
- GLTFLoader.AddPointerMetadata(babylonCamera, context);
1075
- this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
1076
- assign(babylonCamera);
1077
- this.logClose();
1078
- return Promise.all(promises).then(function () {
1079
- return babylonCamera;
1080
- });
1081
- };
1082
- GLTFLoader.prototype._loadAnimationsAsync = function () {
1083
- var animations = this._gltf.animations;
1084
- if (!animations) {
1085
- return Promise.resolve();
1086
- }
1087
- var promises = new Array();
1088
- for (var index = 0; index < animations.length; index++) {
1089
- var animation = animations[index];
1090
- promises.push(this.loadAnimationAsync("/animations/".concat(animation.index), animation).then(function (animationGroup) {
1091
- // Delete the animation group if it ended up not having any animations in it.
1092
- if (animationGroup.targetedAnimations.length === 0) {
1093
- animationGroup.dispose();
1094
- }
1095
- }));
1096
- }
1097
- return Promise.all(promises).then(function () { });
1098
- };
1099
- /**
1100
- * Loads a glTF animation.
1101
- * @param context The context when loading the asset
1102
- * @param animation The glTF animation property
1103
- * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
1104
- */
1105
- GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
1106
- var promise = this._extensionsLoadAnimationAsync(context, animation);
1107
- if (promise) {
1108
- return promise;
1109
- }
1110
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1111
- var babylonAnimationGroup = new AnimationGroup(animation.name || "animation".concat(animation.index), this._babylonScene);
1112
- babylonAnimationGroup._parentContainer = this._assetContainer;
1113
- this._babylonScene._blockEntityCollection = false;
1114
- animation._babylonAnimationGroup = babylonAnimationGroup;
1115
- var promises = new Array();
1116
- ArrayItem.Assign(animation.channels);
1117
- ArrayItem.Assign(animation.samplers);
1118
- for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
1119
- var channel = _a[_i];
1120
- promises.push(this._loadAnimationChannelAsync("".concat(context, "/channels/").concat(channel.index), context, animation, channel, babylonAnimationGroup));
1121
- }
1122
- return Promise.all(promises).then(function () {
1123
- babylonAnimationGroup.normalize(0);
1124
- return babylonAnimationGroup;
1125
- });
1126
- };
1127
- /**
1128
- * @hidden Loads a glTF animation channel.
1129
- * @param context The context when loading the asset
1130
- * @param animationContext The context of the animation when loading the asset
1131
- * @param animation The glTF animation property
1132
- * @param channel The glTF animation channel property
1133
- * @param babylonAnimationGroup The babylon animation group property
1134
- * @param animationTargetOverride The babylon animation channel target override property. My be null.
1135
- * @returns A void promise when the channel load is complete
1136
- */
1137
- GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
1138
- var _this = this;
1139
- if (animationTargetOverride === void 0) { animationTargetOverride = null; }
1140
- if (channel.target.node == undefined) {
1141
- return Promise.resolve();
1142
- }
1143
- var targetNode = ArrayItem.Get("".concat(context, "/target/node"), this._gltf.nodes, channel.target.node);
1144
- // Ignore animations that have no animation targets.
1145
- if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
1146
- (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
1147
- return Promise.resolve();
1148
- }
1149
- var sampler = ArrayItem.Get("".concat(context, "/sampler"), animation.samplers, channel.sampler);
1150
- return this._loadAnimationSamplerAsync("".concat(animationContext, "/samplers/").concat(channel.sampler), sampler).then(function (data) {
1151
- var targetPath;
1152
- var animationType;
1153
- switch (channel.target.path) {
1154
- case "translation" /* TRANSLATION */: {
1155
- targetPath = "position";
1156
- animationType = Animation.ANIMATIONTYPE_VECTOR3;
1157
- break;
1158
- }
1159
- case "rotation" /* ROTATION */: {
1160
- targetPath = "rotationQuaternion";
1161
- animationType = Animation.ANIMATIONTYPE_QUATERNION;
1162
- break;
1163
- }
1164
- case "scale" /* SCALE */: {
1165
- targetPath = "scaling";
1166
- animationType = Animation.ANIMATIONTYPE_VECTOR3;
1167
- break;
1168
- }
1169
- case "weights" /* WEIGHTS */: {
1170
- targetPath = "influence";
1171
- animationType = Animation.ANIMATIONTYPE_FLOAT;
1172
- break;
1173
- }
1174
- default: {
1175
- throw new Error("".concat(context, "/target/path: Invalid value (").concat(channel.target.path, ")"));
1176
- }
1177
- }
1178
- var outputBufferOffset = 0;
1179
- var getNextOutputValue;
1180
- switch (targetPath) {
1181
- case "position": {
1182
- getNextOutputValue = function () {
1183
- var value = Vector3.FromArray(data.output, outputBufferOffset);
1184
- outputBufferOffset += 3;
1185
- return value;
1186
- };
1187
- break;
1188
- }
1189
- case "rotationQuaternion": {
1190
- getNextOutputValue = function () {
1191
- var value = Quaternion.FromArray(data.output, outputBufferOffset);
1192
- outputBufferOffset += 4;
1193
- return value;
1194
- };
1195
- break;
1196
- }
1197
- case "scaling": {
1198
- getNextOutputValue = function () {
1199
- var value = Vector3.FromArray(data.output, outputBufferOffset);
1200
- outputBufferOffset += 3;
1201
- return value;
1202
- };
1203
- break;
1204
- }
1205
- case "influence": {
1206
- getNextOutputValue = function () {
1207
- var value = new Array(targetNode._numMorphTargets);
1208
- for (var i = 0; i < targetNode._numMorphTargets; i++) {
1209
- value[i] = data.output[outputBufferOffset++];
1210
- }
1211
- return value;
1212
- };
1213
- break;
1214
- }
1215
- }
1216
- var getNextKey;
1217
- switch (data.interpolation) {
1218
- case "STEP" /* STEP */: {
1219
- getNextKey = function (frameIndex) { return ({
1220
- frame: data.input[frameIndex],
1221
- value: getNextOutputValue(),
1222
- interpolation: AnimationKeyInterpolation.STEP
1223
- }); };
1224
- break;
1225
- }
1226
- case "LINEAR" /* LINEAR */: {
1227
- getNextKey = function (frameIndex) { return ({
1228
- frame: data.input[frameIndex],
1229
- value: getNextOutputValue()
1230
- }); };
1231
- break;
1232
- }
1233
- case "CUBICSPLINE" /* CUBICSPLINE */: {
1234
- getNextKey = function (frameIndex) { return ({
1235
- frame: data.input[frameIndex],
1236
- inTangent: getNextOutputValue(),
1237
- value: getNextOutputValue(),
1238
- outTangent: getNextOutputValue()
1239
- }); };
1240
- break;
1241
- }
1242
- }
1243
- var keys = new Array(data.input.length);
1244
- for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
1245
- keys[frameIndex] = getNextKey(frameIndex);
1246
- }
1247
- if (targetPath === "influence") {
1248
- var _loop_2 = function (targetIndex) {
1249
- var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
1250
- var babylonAnimation = new Animation(animationName, targetPath, 1, animationType);
1251
- babylonAnimation.setKeys(keys.map(function (key) { return ({
1252
- frame: key.frame,
1253
- inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
1254
- value: key.value[targetIndex],
1255
- outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
1256
- }); }));
1257
- _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
1258
- var babylonMesh = babylonAbstractMesh;
1259
- var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
1260
- var babylonAnimationClone = babylonAnimation.clone();
1261
- morphTarget.animations.push(babylonAnimationClone);
1262
- babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
1263
- });
1264
- };
1265
- for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
1266
- _loop_2(targetIndex);
1267
- }
1268
- }
1269
- else {
1270
- var animationName = "".concat(babylonAnimationGroup.name, "_channel").concat(babylonAnimationGroup.targetedAnimations.length);
1271
- var babylonAnimation = new Animation(animationName, targetPath, 1, animationType);
1272
- babylonAnimation.setKeys(keys);
1273
- if (animationTargetOverride != null && animationTargetOverride.animations != null) {
1274
- animationTargetOverride.animations.push(babylonAnimation);
1275
- babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
1276
- }
1277
- else {
1278
- targetNode._babylonTransformNode.animations.push(babylonAnimation);
1279
- babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
1280
- }
1281
- }
1282
- });
1283
- };
1284
- GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
1285
- if (sampler._data) {
1286
- return sampler._data;
1287
- }
1288
- var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
1289
- switch (interpolation) {
1290
- case "STEP" /* STEP */:
1291
- case "LINEAR" /* LINEAR */:
1292
- case "CUBICSPLINE" /* CUBICSPLINE */: {
1293
- break;
1294
- }
1295
- default: {
1296
- throw new Error("".concat(context, "/interpolation: Invalid value (").concat(sampler.interpolation, ")"));
1297
- }
1298
- }
1299
- var inputAccessor = ArrayItem.Get("".concat(context, "/input"), this._gltf.accessors, sampler.input);
1300
- var outputAccessor = ArrayItem.Get("".concat(context, "/output"), this._gltf.accessors, sampler.output);
1301
- sampler._data = Promise.all([
1302
- this._loadFloatAccessorAsync("/accessors/".concat(inputAccessor.index), inputAccessor),
1303
- this._loadFloatAccessorAsync("/accessors/".concat(outputAccessor.index), outputAccessor)
1304
- ]).then(function (_a) {
1305
- var inputData = _a[0], outputData = _a[1];
1306
- return {
1307
- input: inputData,
1308
- interpolation: interpolation,
1309
- output: outputData,
1310
- };
1311
- });
1312
- return sampler._data;
1313
- };
1314
- /**
1315
- * Loads a glTF buffer.
1316
- * @param context The context when loading the asset
1317
- * @param buffer The glTF buffer property
1318
- * @param byteOffset The byte offset to use
1319
- * @param byteLength The byte length to use
1320
- * @returns A promise that resolves with the loaded data when the load is complete
1321
- */
1322
- GLTFLoader.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
1323
- var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
1324
- if (extensionPromise) {
1325
- return extensionPromise;
1326
- }
1327
- if (!buffer._data) {
1328
- if (buffer.uri) {
1329
- buffer._data = this.loadUriAsync("".concat(context, "/uri"), buffer, buffer.uri);
1330
- }
1331
- else {
1332
- if (!this._bin) {
1333
- throw new Error("".concat(context, ": Uri is missing or the binary glTF is missing its binary chunk"));
1334
- }
1335
- buffer._data = this._bin.readAsync(0, buffer.byteLength);
1336
- }
1337
- }
1338
- return buffer._data.then(function (data) {
1339
- try {
1340
- return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
1341
- }
1342
- catch (e) {
1343
- throw new Error("".concat(context, ": ").concat(e.message));
1344
- }
1345
- });
1346
- };
1347
- /**
1348
- * Loads a glTF buffer view.
1349
- * @param context The context when loading the asset
1350
- * @param bufferView The glTF buffer view property
1351
- * @returns A promise that resolves with the loaded data when the load is complete
1352
- */
1353
- GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
1354
- var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
1355
- if (extensionPromise) {
1356
- return extensionPromise;
1357
- }
1358
- if (bufferView._data) {
1359
- return bufferView._data;
1360
- }
1361
- var buffer = ArrayItem.Get("".concat(context, "/buffer"), this._gltf.buffers, bufferView.buffer);
1362
- bufferView._data = this.loadBufferAsync("/buffers/".concat(buffer.index), buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
1363
- return bufferView._data;
1364
- };
1365
- GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
1366
- var _this = this;
1367
- if (accessor._data) {
1368
- return accessor._data;
1369
- }
1370
- var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
1371
- var byteStride = numComponents * VertexBuffer.GetTypeByteLength(accessor.componentType);
1372
- var length = numComponents * accessor.count;
1373
- if (accessor.bufferView == undefined) {
1374
- accessor._data = Promise.resolve(new constructor(length));
1375
- }
1376
- else {
1377
- var bufferView_1 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
1378
- accessor._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView_1.index), bufferView_1).then(function (data) {
1379
- if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized && (!bufferView_1.byteStride || bufferView_1.byteStride === byteStride)) {
1380
- return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
1381
- }
1382
- else {
1383
- var typedArray_1 = new constructor(length);
1384
- VertexBuffer.ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, typedArray_1.length, accessor.normalized || false, function (value, index) {
1385
- typedArray_1[index] = value;
1386
- });
1387
- return typedArray_1;
1388
- }
1389
- });
1390
- }
1391
- if (accessor.sparse) {
1392
- var sparse_1 = accessor.sparse;
1393
- accessor._data = accessor._data.then(function (data) {
1394
- var typedArray = data;
1395
- var indicesBufferView = ArrayItem.Get("".concat(context, "/sparse/indices/bufferView"), _this._gltf.bufferViews, sparse_1.indices.bufferView);
1396
- var valuesBufferView = ArrayItem.Get("".concat(context, "/sparse/values/bufferView"), _this._gltf.bufferViews, sparse_1.values.bufferView);
1397
- return Promise.all([
1398
- _this.loadBufferViewAsync("/bufferViews/".concat(indicesBufferView.index), indicesBufferView),
1399
- _this.loadBufferViewAsync("/bufferViews/".concat(valuesBufferView.index), valuesBufferView)
1400
- ]).then(function (_a) {
1401
- var indicesData = _a[0], valuesData = _a[1];
1402
- var indices = GLTFLoader._GetTypedArray("".concat(context, "/sparse/indices"), sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
1403
- var sparseLength = numComponents * sparse_1.count;
1404
- var values;
1405
- if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
1406
- values = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
1407
- }
1408
- else {
1409
- var sparseData = GLTFLoader._GetTypedArray("".concat(context, "/sparse/values"), accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
1410
- values = new constructor(sparseLength);
1411
- VertexBuffer.ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
1412
- values[index] = value;
1413
- });
1414
- }
1415
- var valuesIndex = 0;
1416
- for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
1417
- var dataIndex = indices[indicesIndex] * numComponents;
1418
- for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
1419
- typedArray[dataIndex++] = values[valuesIndex++];
1420
- }
1421
- }
1422
- return typedArray;
1423
- });
1424
- });
1425
- }
1426
- return accessor._data;
1427
- };
1428
- /** @hidden */
1429
- GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
1430
- return this._loadAccessorAsync(context, accessor, Float32Array);
1431
- };
1432
- GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
1433
- if (accessor.type !== "SCALAR" /* SCALAR */) {
1434
- throw new Error("".concat(context, "/type: Invalid value ").concat(accessor.type));
1435
- }
1436
- if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
1437
- accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
1438
- accessor.componentType !== 5125 /* UNSIGNED_INT */) {
1439
- throw new Error("".concat(context, "/componentType: Invalid value ").concat(accessor.componentType));
1440
- }
1441
- if (accessor._data) {
1442
- return accessor._data;
1443
- }
1444
- if (accessor.sparse) {
1445
- var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), accessor.componentType);
1446
- accessor._data = this._loadAccessorAsync(context, accessor, constructor);
1447
- }
1448
- else {
1449
- var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
1450
- accessor._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
1451
- return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
1452
- });
1453
- }
1454
- return accessor._data;
1455
- };
1456
- GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
1457
- var _this = this;
1458
- if (bufferView._babylonBuffer) {
1459
- return bufferView._babylonBuffer;
1460
- }
1461
- bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView).then(function (data) {
1462
- return new Buffer(_this._babylonScene.getEngine(), data, false);
1463
- });
1464
- return bufferView._babylonBuffer;
1465
- };
1466
- GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
1467
- var _this = this;
1468
- var _a;
1469
- if ((_a = accessor._babylonVertexBuffer) === null || _a === void 0 ? void 0 : _a[kind]) {
1470
- return accessor._babylonVertexBuffer[kind];
1471
- }
1472
- if (!accessor._babylonVertexBuffer) {
1473
- accessor._babylonVertexBuffer = {};
1474
- }
1475
- if (accessor.sparse) {
1476
- accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
1477
- return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
1478
- });
1479
- }
1480
- // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
1481
- // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
1482
- else if (kind === VertexBuffer.MatricesIndicesKind || kind === VertexBuffer.MatricesIndicesExtraKind) {
1483
- accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
1484
- return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
1485
- });
1486
- }
1487
- else {
1488
- var bufferView_2 = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, accessor.bufferView);
1489
- accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
1490
- var size = GLTFLoader._GetNumComponents(context, accessor.type);
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);
1492
- });
1493
- }
1494
- return accessor._babylonVertexBuffer[kind];
1495
- };
1496
- GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
1497
- if (!(babylonMaterial instanceof PBRMaterial)) {
1498
- throw new Error("".concat(context, ": Material type not supported"));
1499
- }
1500
- var promises = new Array();
1501
- if (properties) {
1502
- if (properties.baseColorFactor) {
1503
- babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);
1504
- babylonMaterial.alpha = properties.baseColorFactor[3];
1505
- }
1506
- else {
1507
- babylonMaterial.albedoColor = Color3.White();
1508
- }
1509
- babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
1510
- babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
1511
- if (properties.baseColorTexture) {
1512
- promises.push(this.loadTextureInfoAsync("".concat(context, "/baseColorTexture"), properties.baseColorTexture, function (texture) {
1513
- texture.name = "".concat(babylonMaterial.name, " (Base Color)");
1514
- babylonMaterial.albedoTexture = texture;
1515
- }));
1516
- }
1517
- if (properties.metallicRoughnessTexture) {
1518
- properties.metallicRoughnessTexture.nonColorData = true;
1519
- promises.push(this.loadTextureInfoAsync("".concat(context, "/metallicRoughnessTexture"), properties.metallicRoughnessTexture, function (texture) {
1520
- texture.name = "".concat(babylonMaterial.name, " (Metallic Roughness)");
1521
- babylonMaterial.metallicTexture = texture;
1522
- }));
1523
- babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
1524
- babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
1525
- babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
1526
- }
1527
- }
1528
- return Promise.all(promises).then(function () { });
1529
- };
1530
- /** @hidden */
1531
- GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
1532
- if (assign === void 0) { assign = function () { }; }
1533
- var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
1534
- if (extensionPromise) {
1535
- return extensionPromise;
1536
- }
1537
- material._data = material._data || {};
1538
- var babylonData = material._data[babylonDrawMode];
1539
- if (!babylonData) {
1540
- this.logOpen("".concat(context, " ").concat(material.name || ""));
1541
- var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
1542
- babylonData = {
1543
- babylonMaterial: babylonMaterial,
1544
- babylonMeshes: [],
1545
- promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
1546
- };
1547
- material._data[babylonDrawMode] = babylonData;
1548
- GLTFLoader.AddPointerMetadata(babylonMaterial, context);
1549
- this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
1550
- this.logClose();
1551
- }
1552
- if (babylonMesh) {
1553
- babylonData.babylonMeshes.push(babylonMesh);
1554
- babylonMesh.onDisposeObservable.addOnce(function () {
1555
- var index = babylonData.babylonMeshes.indexOf(babylonMesh);
1556
- if (index !== -1) {
1557
- babylonData.babylonMeshes.splice(index, 1);
1558
- }
1559
- });
1560
- }
1561
- assign(babylonData.babylonMaterial);
1562
- return babylonData.promise.then(function () {
1563
- return babylonData.babylonMaterial;
1564
- });
1565
- };
1566
- GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
1567
- this._babylonScene._blockEntityCollection = !!this._assetContainer;
1568
- var babylonMaterial = new PBRMaterial(name, this._babylonScene);
1569
- babylonMaterial._parentContainer = this._assetContainer;
1570
- this._babylonScene._blockEntityCollection = false;
1571
- // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
1572
- babylonMaterial.fillMode = babylonDrawMode;
1573
- babylonMaterial.enableSpecularAntiAliasing = true;
1574
- babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
1575
- babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
1576
- babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_OPAQUE;
1577
- babylonMaterial.metallic = 1;
1578
- babylonMaterial.roughness = 1;
1579
- return babylonMaterial;
1580
- };
1581
- /**
1582
- * Creates a Babylon material from a glTF material.
1583
- * @param context The context when loading the asset
1584
- * @param material The glTF material property
1585
- * @param babylonDrawMode The draw mode for the Babylon material
1586
- * @returns The Babylon material
1587
- */
1588
- GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
1589
- var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
1590
- if (extensionPromise) {
1591
- return extensionPromise;
1592
- }
1593
- var name = material.name || "material".concat(material.index);
1594
- var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
1595
- return babylonMaterial;
1596
- };
1597
- /**
1598
- * Loads properties from a glTF material into a Babylon material.
1599
- * @param context The context when loading the asset
1600
- * @param material The glTF material property
1601
- * @param babylonMaterial The Babylon material
1602
- * @returns A promise that resolves when the load is complete
1603
- */
1604
- GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
1605
- var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
1606
- if (extensionPromise) {
1607
- return extensionPromise;
1608
- }
1609
- var promises = new Array();
1610
- promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
1611
- if (material.pbrMetallicRoughness) {
1612
- promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync("".concat(context, "/pbrMetallicRoughness"), material.pbrMetallicRoughness, babylonMaterial));
1613
- }
1614
- this.loadMaterialAlphaProperties(context, material, babylonMaterial);
1615
- return Promise.all(promises).then(function () { });
1616
- };
1617
- /**
1618
- * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
1619
- * @param context The context when loading the asset
1620
- * @param material The glTF material property
1621
- * @param babylonMaterial The Babylon material
1622
- * @returns A promise that resolves when the load is complete
1623
- */
1624
- GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
1625
- if (!(babylonMaterial instanceof PBRMaterial)) {
1626
- throw new Error("".concat(context, ": Material type not supported"));
1627
- }
1628
- var promises = new Array();
1629
- babylonMaterial.emissiveColor = material.emissiveFactor ? Color3.FromArray(material.emissiveFactor) : new Color3(0, 0, 0);
1630
- if (material.doubleSided) {
1631
- babylonMaterial.backFaceCulling = false;
1632
- babylonMaterial.twoSidedLighting = true;
1633
- }
1634
- if (material.normalTexture) {
1635
- material.normalTexture.nonColorData = true;
1636
- promises.push(this.loadTextureInfoAsync("".concat(context, "/normalTexture"), material.normalTexture, function (texture) {
1637
- texture.name = "".concat(babylonMaterial.name, " (Normal)");
1638
- babylonMaterial.bumpTexture = texture;
1639
- }));
1640
- babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
1641
- babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
1642
- if (material.normalTexture.scale != undefined) {
1643
- babylonMaterial.bumpTexture.level = material.normalTexture.scale;
1644
- }
1645
- babylonMaterial.forceIrradianceInFragment = true;
1646
- }
1647
- if (material.occlusionTexture) {
1648
- material.occlusionTexture.nonColorData = true;
1649
- promises.push(this.loadTextureInfoAsync("".concat(context, "/occlusionTexture"), material.occlusionTexture, function (texture) {
1650
- texture.name = "".concat(babylonMaterial.name, " (Occlusion)");
1651
- babylonMaterial.ambientTexture = texture;
1652
- }));
1653
- babylonMaterial.useAmbientInGrayScale = true;
1654
- if (material.occlusionTexture.strength != undefined) {
1655
- babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
1656
- }
1657
- }
1658
- if (material.emissiveTexture) {
1659
- promises.push(this.loadTextureInfoAsync("".concat(context, "/emissiveTexture"), material.emissiveTexture, function (texture) {
1660
- texture.name = "".concat(babylonMaterial.name, " (Emissive)");
1661
- babylonMaterial.emissiveTexture = texture;
1662
- }));
1663
- }
1664
- return Promise.all(promises).then(function () { });
1665
- };
1666
- /**
1667
- * Loads the alpha properties from a glTF material into a Babylon material.
1668
- * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
1669
- * @param context The context when loading the asset
1670
- * @param material The glTF material property
1671
- * @param babylonMaterial The Babylon material
1672
- */
1673
- GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
1674
- if (!(babylonMaterial instanceof PBRMaterial)) {
1675
- throw new Error("".concat(context, ": Material type not supported"));
1676
- }
1677
- var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
1678
- switch (alphaMode) {
1679
- case "OPAQUE" /* OPAQUE */: {
1680
- babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_OPAQUE;
1681
- break;
1682
- }
1683
- case "MASK" /* MASK */: {
1684
- babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHATEST;
1685
- babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
1686
- if (babylonMaterial.albedoTexture) {
1687
- babylonMaterial.albedoTexture.hasAlpha = true;
1688
- }
1689
- break;
1690
- }
1691
- case "BLEND" /* BLEND */: {
1692
- babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
1693
- if (babylonMaterial.albedoTexture) {
1694
- babylonMaterial.albedoTexture.hasAlpha = true;
1695
- babylonMaterial.useAlphaFromAlbedoTexture = true;
1696
- }
1697
- break;
1698
- }
1699
- default: {
1700
- throw new Error("".concat(context, "/alphaMode: Invalid value (").concat(material.alphaMode, ")"));
1701
- }
1702
- }
1703
- };
1704
- /**
1705
- * Loads a glTF texture info.
1706
- * @param context The context when loading the asset
1707
- * @param textureInfo The glTF texture info property
1708
- * @param assign A function called synchronously after parsing the glTF properties
1709
- * @returns A promise that resolves with the loaded Babylon texture when the load is complete
1710
- */
1711
- GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
1712
- var _this = this;
1713
- if (assign === void 0) { assign = function () { }; }
1714
- var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
1715
- if (extensionPromise) {
1716
- return extensionPromise;
1717
- }
1718
- this.logOpen("".concat(context));
1719
- if (textureInfo.texCoord >= 6) {
1720
- throw new Error("".concat(context, "/texCoord: Invalid value (").concat(textureInfo.texCoord, ")"));
1721
- }
1722
- var texture = ArrayItem.Get("".concat(context, "/index"), this._gltf.textures, textureInfo.index);
1723
- texture._textureInfo = textureInfo;
1724
- var promise = this._loadTextureAsync("/textures/".concat(textureInfo.index), texture, function (babylonTexture) {
1725
- babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
1726
- GLTFLoader.AddPointerMetadata(babylonTexture, context);
1727
- _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
1728
- assign(babylonTexture);
1729
- });
1730
- this.logClose();
1731
- return promise;
1732
- };
1733
- /** @hidden */
1734
- GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
1735
- if (assign === void 0) { assign = function () { }; }
1736
- var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
1737
- if (extensionPromise) {
1738
- return extensionPromise;
1739
- }
1740
- this.logOpen("".concat(context, " ").concat(texture.name || ""));
1741
- var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get("".concat(context, "/sampler"), this._gltf.samplers, texture.sampler));
1742
- var image = ArrayItem.Get("".concat(context, "/source"), this._gltf.images, texture.source);
1743
- var promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
1744
- this.logClose();
1745
- return promise;
1746
- };
1747
- /** @hidden */
1748
- GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions, useSRGBBuffer) {
1749
- var _this = this;
1750
- if (assign === void 0) { assign = function () { }; }
1751
- var samplerData = this._loadSampler("/samplers/".concat(sampler.index), sampler);
1752
- var promises = new Array();
1753
- var deferred = new Deferred();
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("".concat(context, ": ").concat((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;
1775
- this._babylonScene._blockEntityCollection = false;
1776
- promises.push(deferred.promise);
1777
- promises.push(this.loadImageAsync("/images/".concat(image.index), image).then(function (data) {
1778
- var name = image.uri || "".concat(_this._fileName, "#image").concat(image.index);
1779
- var dataUrl = "data:".concat(_this._uniqueRootUrl).concat(name);
1780
- babylonTexture.updateURL(dataUrl, data);
1781
- }));
1782
- babylonTexture.wrapU = samplerData.wrapU;
1783
- babylonTexture.wrapV = samplerData.wrapV;
1784
- assign(babylonTexture);
1785
- return Promise.all(promises).then(function () {
1786
- return babylonTexture;
1787
- });
1788
- };
1789
- GLTFLoader.prototype._loadSampler = function (context, sampler) {
1790
- if (!sampler._data) {
1791
- sampler._data = {
1792
- noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
1793
- samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
1794
- wrapU: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapS"), sampler.wrapS),
1795
- wrapV: GLTFLoader._GetTextureWrapMode("".concat(context, "/wrapT"), sampler.wrapT)
1796
- };
1797
- }
1798
- return sampler._data;
1799
- };
1800
- /**
1801
- * Loads a glTF image.
1802
- * @param context The context when loading the asset
1803
- * @param image The glTF image property
1804
- * @returns A promise that resolves with the loaded data when the load is complete
1805
- */
1806
- GLTFLoader.prototype.loadImageAsync = function (context, image) {
1807
- if (!image._data) {
1808
- this.logOpen("".concat(context, " ").concat(image.name || ""));
1809
- if (image.uri) {
1810
- image._data = this.loadUriAsync("".concat(context, "/uri"), image, image.uri);
1811
- }
1812
- else {
1813
- var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._gltf.bufferViews, image.bufferView);
1814
- image._data = this.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView);
1815
- }
1816
- this.logClose();
1817
- }
1818
- return image._data;
1819
- };
1820
- /**
1821
- * Loads a glTF uri.
1822
- * @param context The context when loading the asset
1823
- * @param property The glTF property associated with the uri
1824
- * @param uri The base64 or relative uri
1825
- * @returns A promise that resolves with the loaded data when the load is complete
1826
- */
1827
- GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
1828
- var _this = this;
1829
- var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
1830
- if (extensionPromise) {
1831
- return extensionPromise;
1832
- }
1833
- if (!GLTFLoader._ValidateUri(uri)) {
1834
- throw new Error("".concat(context, ": '").concat(uri, "' is invalid"));
1835
- }
1836
- if (IsBase64DataUrl(uri)) {
1837
- var data = new Uint8Array(DecodeBase64UrlToBinary(uri));
1838
- this.log("".concat(context, ": Decoded ").concat(uri.substr(0, 64), "... (").concat(data.length, " bytes)"));
1839
- return Promise.resolve(data);
1840
- }
1841
- this.log("".concat(context, ": Loading ").concat(uri));
1842
- return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
1843
- return new Promise(function (resolve, reject) {
1844
- _this._parent._loadFile(_this._babylonScene, url, function (data) {
1845
- if (!_this._disposed) {
1846
- _this.log("".concat(context, ": Loaded ").concat(uri, " (").concat(data.byteLength, " bytes)"));
1847
- resolve(new Uint8Array(data));
1848
- }
1849
- }, true, function (request) {
1850
- reject(new LoadFileError("".concat(context, ": Failed to load '").concat(uri, "'").concat(request ? ": " + request.status + " " + request.statusText : ""), request));
1851
- });
1852
- });
1853
- });
1854
- };
1855
- /**
1856
- * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
1857
- * @param babylonObject the Babylon object with metadata
1858
- * @param pointer the JSON pointer
1859
- */
1860
- GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
1861
- var metadata = (babylonObject.metadata = babylonObject.metadata || {});
1862
- var gltf = (metadata.gltf = metadata.gltf || {});
1863
- var pointers = (gltf.pointers = gltf.pointers || []);
1864
- pointers.push(pointer);
1865
- };
1866
- GLTFLoader._GetTextureWrapMode = function (context, mode) {
1867
- // Set defaults if undefined
1868
- mode = mode == undefined ? 10497 /* REPEAT */ : mode;
1869
- switch (mode) {
1870
- case 33071 /* CLAMP_TO_EDGE */: return Texture.CLAMP_ADDRESSMODE;
1871
- case 33648 /* MIRRORED_REPEAT */: return Texture.MIRROR_ADDRESSMODE;
1872
- case 10497 /* REPEAT */: return Texture.WRAP_ADDRESSMODE;
1873
- default:
1874
- Logger.Warn("".concat(context, ": Invalid value (").concat(mode, ")"));
1875
- return Texture.WRAP_ADDRESSMODE;
1876
- }
1877
- };
1878
- GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
1879
- // Set defaults if undefined
1880
- var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
1881
- var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
1882
- if (magFilter === 9729 /* LINEAR */) {
1883
- switch (minFilter) {
1884
- case 9728 /* NEAREST */: return Texture.LINEAR_NEAREST;
1885
- case 9729 /* LINEAR */: return Texture.LINEAR_LINEAR;
1886
- case 9984 /* NEAREST_MIPMAP_NEAREST */: return Texture.LINEAR_NEAREST_MIPNEAREST;
1887
- case 9985 /* LINEAR_MIPMAP_NEAREST */: return Texture.LINEAR_LINEAR_MIPNEAREST;
1888
- case 9986 /* NEAREST_MIPMAP_LINEAR */: return Texture.LINEAR_NEAREST_MIPLINEAR;
1889
- case 9987 /* LINEAR_MIPMAP_LINEAR */: return Texture.LINEAR_LINEAR_MIPLINEAR;
1890
- default:
1891
- Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
1892
- return Texture.LINEAR_LINEAR_MIPLINEAR;
1893
- }
1894
- }
1895
- else {
1896
- if (magFilter !== 9728 /* NEAREST */) {
1897
- Logger.Warn("".concat(context, "/magFilter: Invalid value (").concat(magFilter, ")"));
1898
- }
1899
- switch (minFilter) {
1900
- case 9728 /* NEAREST */: return Texture.NEAREST_NEAREST;
1901
- case 9729 /* LINEAR */: return Texture.NEAREST_LINEAR;
1902
- case 9984 /* NEAREST_MIPMAP_NEAREST */: return Texture.NEAREST_NEAREST_MIPNEAREST;
1903
- case 9985 /* LINEAR_MIPMAP_NEAREST */: return Texture.NEAREST_LINEAR_MIPNEAREST;
1904
- case 9986 /* NEAREST_MIPMAP_LINEAR */: return Texture.NEAREST_NEAREST_MIPLINEAR;
1905
- case 9987 /* LINEAR_MIPMAP_LINEAR */: return Texture.NEAREST_LINEAR_MIPLINEAR;
1906
- default:
1907
- Logger.Warn("".concat(context, "/minFilter: Invalid value (").concat(minFilter, ")"));
1908
- return Texture.NEAREST_NEAREST_MIPNEAREST;
1909
- }
1910
- }
1911
- };
1912
- GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
1913
- switch (componentType) {
1914
- case 5120 /* BYTE */: return Int8Array;
1915
- case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
1916
- case 5122 /* SHORT */: return Int16Array;
1917
- case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
1918
- case 5125 /* UNSIGNED_INT */: return Uint32Array;
1919
- case 5126 /* FLOAT */: return Float32Array;
1920
- default: throw new Error("".concat(context, ": Invalid component type ").concat(componentType));
1921
- }
1922
- };
1923
- GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
1924
- var buffer = bufferView.buffer;
1925
- byteOffset = bufferView.byteOffset + (byteOffset || 0);
1926
- var constructor = GLTFLoader._GetTypedArrayConstructor("".concat(context, "/componentType"), componentType);
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("".concat(context, ": Copying buffer as byte offset (").concat(byteOffset, ") is not a multiple of component type byte length (").concat(componentTypeLength, ")"));
1931
- return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
1932
- }
1933
- return new constructor(buffer, byteOffset, length);
1934
- };
1935
- GLTFLoader._GetNumComponents = function (context, type) {
1936
- switch (type) {
1937
- case "SCALAR": return 1;
1938
- case "VEC2": return 2;
1939
- case "VEC3": return 3;
1940
- case "VEC4": return 4;
1941
- case "MAT2": return 4;
1942
- case "MAT3": return 9;
1943
- case "MAT4": return 16;
1944
- }
1945
- throw new Error("".concat(context, ": Invalid type (").concat(type, ")"));
1946
- };
1947
- GLTFLoader._ValidateUri = function (uri) {
1948
- return (Tools.IsBase64(uri) || uri.indexOf("..") === -1);
1949
- };
1950
- /** @hidden */
1951
- GLTFLoader._GetDrawMode = function (context, mode) {
1952
- if (mode == undefined) {
1953
- mode = 4 /* TRIANGLES */;
1954
- }
1955
- switch (mode) {
1956
- case 0 /* POINTS */: return Material.PointListDrawMode;
1957
- case 1 /* LINES */: return Material.LineListDrawMode;
1958
- case 2 /* LINE_LOOP */: return Material.LineLoopDrawMode;
1959
- case 3 /* LINE_STRIP */: return Material.LineStripDrawMode;
1960
- case 4 /* TRIANGLES */: return Material.TriangleFillMode;
1961
- case 5 /* TRIANGLE_STRIP */: return Material.TriangleStripDrawMode;
1962
- case 6 /* TRIANGLE_FAN */: return Material.TriangleFanDrawMode;
1963
- }
1964
- throw new Error("".concat(context, ": Invalid mesh primitive mode (").concat(mode, ")"));
1965
- };
1966
- GLTFLoader.prototype._compileMaterialsAsync = function () {
1967
- var _this = this;
1968
- this._parent._startPerformanceCounter("Compile materials");
1969
- var promises = new Array();
1970
- if (this._gltf.materials) {
1971
- for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
1972
- var material = _a[_i];
1973
- if (material._data) {
1974
- for (var babylonDrawMode in material._data) {
1975
- var babylonData = material._data[babylonDrawMode];
1976
- for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
1977
- var babylonMesh = _c[_b];
1978
- // Ensure nonUniformScaling is set if necessary.
1979
- babylonMesh.computeWorldMatrix(true);
1980
- var babylonMaterial = babylonData.babylonMaterial;
1981
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
1982
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
1983
- if (this._parent.useClipPlane) {
1984
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
1985
- promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
1986
- }
1987
- }
1988
- }
1989
- }
1990
- }
1991
- }
1992
- return Promise.all(promises).then(function () {
1993
- _this._parent._endPerformanceCounter("Compile materials");
1994
- });
1995
- };
1996
- GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
1997
- var _this = this;
1998
- this._parent._startPerformanceCounter("Compile shadow generators");
1999
- var promises = new Array();
2000
- var lights = this._babylonScene.lights;
2001
- for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
2002
- var light = lights_1[_i];
2003
- var generator = light.getShadowGenerator();
2004
- if (generator) {
2005
- promises.push(generator.forceCompilationAsync());
2006
- }
2007
- }
2008
- return Promise.all(promises).then(function () {
2009
- _this._parent._endPerformanceCounter("Compile shadow generators");
2010
- });
2011
- };
2012
- GLTFLoader.prototype._forEachExtensions = function (action) {
2013
- for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
2014
- var extension = _a[_i];
2015
- if (extension.enabled) {
2016
- action(extension);
2017
- }
2018
- }
2019
- };
2020
- GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
2021
- for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
2022
- var extension = _a[_i];
2023
- if (extension.enabled) {
2024
- var id = "".concat(extension.name, ".").concat(functionName);
2025
- var loaderProperty = property;
2026
- loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
2027
- var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
2028
- if (!activeLoaderExtensionFunctions[id]) {
2029
- activeLoaderExtensionFunctions[id] = true;
2030
- try {
2031
- var result = actionAsync(extension);
2032
- if (result) {
2033
- return result;
2034
- }
2035
- }
2036
- finally {
2037
- delete activeLoaderExtensionFunctions[id];
2038
- }
2039
- }
2040
- }
2041
- }
2042
- return null;
2043
- };
2044
- GLTFLoader.prototype._extensionsOnLoading = function () {
2045
- this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
2046
- };
2047
- GLTFLoader.prototype._extensionsOnReady = function () {
2048
- this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
2049
- };
2050
- GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
2051
- return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
2052
- };
2053
- GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
2054
- return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
2055
- };
2056
- GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
2057
- return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
2058
- };
2059
- GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
2060
- return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
2061
- };
2062
- GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
2063
- return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
2064
- };
2065
- GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
2066
- return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
2067
- };
2068
- GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
2069
- return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
2070
- };
2071
- GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
2072
- return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
2073
- };
2074
- GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
2075
- return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
2076
- };
2077
- GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
2078
- return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
2079
- };
2080
- GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
2081
- return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
2082
- };
2083
- GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
2084
- return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
2085
- };
2086
- GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
2087
- return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
2088
- };
2089
- GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
2090
- return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
2091
- };
2092
- GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
2093
- return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
2094
- };
2095
- /**
2096
- * Helper method called by a loader extension to load an glTF extension.
2097
- * @param context The context when loading the asset
2098
- * @param property The glTF property to load the extension from
2099
- * @param extensionName The name of the extension to load
2100
- * @param actionAsync The action to run
2101
- * @returns The promise returned by actionAsync or null if the extension does not exist
2102
- */
2103
- GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
2104
- if (!property.extensions) {
2105
- return null;
2106
- }
2107
- var extensions = property.extensions;
2108
- var extension = extensions[extensionName];
2109
- if (!extension) {
2110
- return null;
2111
- }
2112
- return actionAsync("".concat(context, "/extensions/").concat(extensionName), extension);
2113
- };
2114
- /**
2115
- * Helper method called by a loader extension to load a glTF extra.
2116
- * @param context The context when loading the asset
2117
- * @param property The glTF property to load the extra from
2118
- * @param extensionName The name of the extension to load
2119
- * @param actionAsync The action to run
2120
- * @returns The promise returned by actionAsync or null if the extra does not exist
2121
- */
2122
- GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
2123
- if (!property.extras) {
2124
- return null;
2125
- }
2126
- var extras = property.extras;
2127
- var extra = extras[extensionName];
2128
- if (!extra) {
2129
- return null;
2130
- }
2131
- return actionAsync("".concat(context, "/extras/").concat(extensionName), extra);
2132
- };
2133
- /**
2134
- * Checks for presence of an extension.
2135
- * @param name The name of the extension to check
2136
- * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
2137
- */
2138
- GLTFLoader.prototype.isExtensionUsed = function (name) {
2139
- return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
2140
- };
2141
- /**
2142
- * Increments the indentation level and logs a message.
2143
- * @param message The message to log
2144
- */
2145
- GLTFLoader.prototype.logOpen = function (message) {
2146
- this._parent._logOpen(message);
2147
- };
2148
- /**
2149
- * Decrements the indentation level.
2150
- */
2151
- GLTFLoader.prototype.logClose = function () {
2152
- this._parent._logClose();
2153
- };
2154
- /**
2155
- * Logs a message
2156
- * @param message The message to log
2157
- */
2158
- GLTFLoader.prototype.log = function (message) {
2159
- this._parent._log(message);
2160
- };
2161
- /**
2162
- * Starts a performance counter.
2163
- * @param counterName The name of the performance counter
2164
- */
2165
- GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
2166
- this._parent._startPerformanceCounter(counterName);
2167
- };
2168
- /**
2169
- * Ends a performance counter.
2170
- * @param counterName The name of the performance counter
2171
- */
2172
- GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
2173
- this._parent._endPerformanceCounter(counterName);
2174
- };
2175
- GLTFLoader._RegisteredExtensions = {};
2176
- /**
2177
- * The default glTF sampler.
2178
- */
2179
- GLTFLoader.DefaultSampler = { index: -1 };
2180
- return GLTFLoader;
2181
- }());
2182
- export { GLTFLoader };
2183
- GLTFFileLoader._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
2184
- //# sourceMappingURL=glTFLoader.js.map