@babylonjs/loaders 5.0.0-rc.6 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. package/OBJ/index.d.ts +4 -4
  2. package/OBJ/index.js +4 -4
  3. package/OBJ/mtlFileLoader.d.ts +41 -41
  4. package/OBJ/mtlFileLoader.js +232 -232
  5. package/OBJ/mtlFileLoader.js.map +1 -1
  6. package/OBJ/objFileLoader.d.ts +126 -126
  7. package/OBJ/objFileLoader.js +296 -296
  8. package/OBJ/objFileLoader.js.map +1 -1
  9. package/OBJ/objLoadingOptions.d.ts +43 -43
  10. package/OBJ/objLoadingOptions.js +1 -1
  11. package/OBJ/objLoadingOptions.js.map +1 -1
  12. package/OBJ/solidParser.d.ts +154 -154
  13. package/OBJ/solidParser.js +693 -693
  14. package/OBJ/solidParser.js.map +1 -1
  15. package/STL/index.d.ts +1 -1
  16. package/STL/index.js +1 -1
  17. package/STL/stlFileLoader.d.ts +64 -64
  18. package/STL/stlFileLoader.js +233 -233
  19. package/STL/stlFileLoader.js.map +1 -1
  20. package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
  21. package/glTF/1.0/glTFBinaryExtension.js +60 -60
  22. package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
  23. package/glTF/1.0/glTFLoader.d.ts +136 -136
  24. package/glTF/1.0/glTFLoader.js +1814 -1815
  25. package/glTF/1.0/glTFLoader.js.map +1 -1
  26. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
  27. package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
  28. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  29. package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
  30. package/glTF/1.0/glTFLoaderUtils.js +250 -250
  31. package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
  32. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
  33. package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
  34. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
  35. package/glTF/1.0/index.d.ts +5 -5
  36. package/glTF/1.0/index.js +5 -5
  37. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
  38. package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
  39. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  40. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
  41. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
  42. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  43. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
  44. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
  45. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  46. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
  47. package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
  48. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  49. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
  50. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
  51. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  52. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
  53. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
  54. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
  56. package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
  57. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
  59. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
  60. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  61. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
  62. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
  63. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  64. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
  65. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
  66. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  67. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
  68. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
  69. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  70. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
  71. package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
  72. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  73. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
  74. package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
  75. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  76. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
  77. package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
  78. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  79. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
  80. package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
  81. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  82. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
  83. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
  84. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  85. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
  86. package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
  87. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  88. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
  89. package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
  90. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  91. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
  92. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
  93. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  94. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
  95. package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
  96. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  97. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
  98. package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
  99. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  100. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
  101. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
  102. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  103. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
  104. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
  105. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  106. package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
  107. package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
  108. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  109. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
  110. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
  111. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  112. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
  113. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
  114. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  115. package/glTF/2.0/Extensions/index.d.ts +26 -26
  116. package/glTF/2.0/Extensions/index.js +26 -26
  117. package/glTF/2.0/glTFLoader.d.ts +406 -405
  118. package/glTF/2.0/glTFLoader.js +2366 -2366
  119. package/glTF/2.0/glTFLoader.js.map +1 -1
  120. package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
  121. package/glTF/2.0/glTFLoaderExtension.js +1 -1
  122. package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
  123. package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
  124. package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
  125. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  126. package/glTF/2.0/index.d.ts +4 -4
  127. package/glTF/2.0/index.js +5 -4
  128. package/glTF/2.0/index.js.map +1 -1
  129. package/glTF/glTFFileLoader.d.ts +433 -433
  130. package/glTF/glTFFileLoader.js +927 -927
  131. package/glTF/glTFFileLoader.js.map +1 -1
  132. package/glTF/glTFValidation.d.ts +29 -29
  133. package/glTF/glTFValidation.js +123 -123
  134. package/glTF/glTFValidation.js.map +1 -1
  135. package/glTF/index.d.ts +5 -5
  136. package/glTF/index.js +6 -5
  137. package/glTF/index.js.map +1 -1
  138. package/index.d.ts +3 -3
  139. package/index.js +4 -3
  140. package/index.js.map +1 -1
  141. package/legacy/legacy-glTF.d.ts +2 -2
  142. package/legacy/legacy-glTF.js +18 -18
  143. package/legacy/legacy-glTF.js.map +1 -1
  144. package/legacy/legacy-glTF1.d.ts +2 -2
  145. package/legacy/legacy-glTF1.js +15 -14
  146. package/legacy/legacy-glTF1.js.map +1 -1
  147. package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
  148. package/legacy/legacy-glTF1FileLoader.js +3 -3
  149. package/legacy/legacy-glTF1FileLoader.js.map +1 -1
  150. package/legacy/legacy-glTF2.d.ts +2 -2
  151. package/legacy/legacy-glTF2.js +33 -32
  152. package/legacy/legacy-glTF2.js.map +1 -1
  153. package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
  154. package/legacy/legacy-glTF2FileLoader.js +3 -3
  155. package/legacy/legacy-glTF2FileLoader.js.map +1 -1
  156. package/legacy/legacy-glTFFileLoader.d.ts +3 -3
  157. package/legacy/legacy-glTFFileLoader.js +4 -4
  158. package/legacy/legacy-glTFFileLoader.js.map +1 -1
  159. package/legacy/legacy-objFileLoader.d.ts +1 -1
  160. package/legacy/legacy-objFileLoader.js +13 -12
  161. package/legacy/legacy-objFileLoader.js.map +1 -1
  162. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  163. package/legacy/legacy-stlFileLoader.js +13 -12
  164. package/legacy/legacy-stlFileLoader.js.map +1 -1
  165. package/legacy/legacy.d.ts +6 -6
  166. package/legacy/legacy.js +8 -7
  167. package/legacy/legacy.js.map +1 -1
  168. package/license.md +71 -0
  169. package/package.json +25 -6
@@ -1,370 +1,370 @@
1
- import { Observable } from "@babylonjs/core/Misc/observable.js";
2
- import { Deferred } from "@babylonjs/core/Misc/deferred.js";
3
- import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
4
- var NAME = "MSFT_lod";
5
- /**
6
- * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
7
- */
8
- var MSFT_lod = /** @class */ (function () {
9
- /**
10
- * @param loader
11
- * @hidden
12
- */
13
- function MSFT_lod(loader) {
14
- /**
15
- * The name of this extension.
16
- */
17
- this.name = NAME;
18
- /**
19
- * Defines a number that determines the order the extensions are applied.
20
- */
21
- this.order = 100;
22
- /**
23
- * Maximum number of LODs to load, starting from the lowest LOD.
24
- */
25
- this.maxLODsToLoad = 10;
26
- /**
27
- * Observable raised when all node LODs of one level are loaded.
28
- * The event data is the index of the loaded LOD starting from zero.
29
- * Dispose the loader to cancel the loading of the next level of LODs.
30
- */
31
- this.onNodeLODsLoadedObservable = new Observable();
32
- /**
33
- * Observable raised when all material LODs of one level are loaded.
34
- * The event data is the index of the loaded LOD starting from zero.
35
- * Dispose the loader to cancel the loading of the next level of LODs.
36
- */
37
- this.onMaterialLODsLoadedObservable = new Observable();
38
- this._bufferLODs = new Array();
39
- this._nodeIndexLOD = null;
40
- this._nodeSignalLODs = new Array();
41
- this._nodePromiseLODs = new Array();
42
- this._nodeBufferLODs = new Array();
43
- this._materialIndexLOD = null;
44
- this._materialSignalLODs = new Array();
45
- this._materialPromiseLODs = new Array();
46
- this._materialBufferLODs = new Array();
47
- this._loader = loader;
48
- this.enabled = this._loader.isExtensionUsed(NAME);
49
- }
50
- /** @hidden */
51
- MSFT_lod.prototype.dispose = function () {
52
- this._loader = null;
53
- this._nodeIndexLOD = null;
54
- this._nodeSignalLODs.length = 0;
55
- this._nodePromiseLODs.length = 0;
56
- this._nodeBufferLODs.length = 0;
57
- this._materialIndexLOD = null;
58
- this._materialSignalLODs.length = 0;
59
- this._materialPromiseLODs.length = 0;
60
- this._materialBufferLODs.length = 0;
61
- this.onMaterialLODsLoadedObservable.clear();
62
- this.onNodeLODsLoadedObservable.clear();
63
- };
64
- /** @hidden */
65
- MSFT_lod.prototype.onReady = function () {
66
- var _this = this;
67
- var _loop_1 = function (indexLOD) {
68
- var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
69
- if (indexLOD !== 0) {
70
- _this._loader.endPerformanceCounter("Node LOD ".concat(indexLOD));
71
- _this._loader.log("Loaded node LOD ".concat(indexLOD));
72
- }
73
- _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
74
- if (indexLOD !== _this._nodePromiseLODs.length - 1) {
75
- _this._loader.startPerformanceCounter("Node LOD ".concat(indexLOD + 1));
76
- _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
77
- if (_this._nodeSignalLODs[indexLOD]) {
78
- _this._nodeSignalLODs[indexLOD].resolve();
79
- }
80
- }
81
- });
82
- this_1._loader._completePromises.push(promise);
83
- };
84
- var this_1 = this;
85
- for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
86
- _loop_1(indexLOD);
87
- }
88
- var _loop_2 = function (indexLOD) {
89
- var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
90
- if (indexLOD !== 0) {
91
- _this._loader.endPerformanceCounter("Material LOD ".concat(indexLOD));
92
- _this._loader.log("Loaded material LOD ".concat(indexLOD));
93
- }
94
- _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
95
- if (indexLOD !== _this._materialPromiseLODs.length - 1) {
96
- _this._loader.startPerformanceCounter("Material LOD ".concat(indexLOD + 1));
97
- _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
98
- if (_this._materialSignalLODs[indexLOD]) {
99
- _this._materialSignalLODs[indexLOD].resolve();
100
- }
101
- }
102
- });
103
- this_2._loader._completePromises.push(promise);
104
- };
105
- var this_2 = this;
106
- for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
107
- _loop_2(indexLOD);
108
- }
109
- };
110
- /**
111
- * @param context
112
- * @param scene
113
- * @hidden
114
- */
115
- MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
116
- var promise = this._loader.loadSceneAsync(context, scene);
117
- this._loadBufferLOD(this._bufferLODs, 0);
118
- return promise;
119
- };
120
- /**
121
- * @param context
122
- * @param node
123
- * @param assign
124
- * @hidden
125
- */
126
- MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
127
- var _this = this;
128
- return GLTFLoader.LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
129
- var firstPromise;
130
- var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
131
- _this._loader.logOpen("".concat(extensionContext));
132
- var _loop_3 = function (indexLOD) {
133
- var nodeLOD = nodeLODs[indexLOD];
134
- if (indexLOD !== 0) {
135
- _this._nodeIndexLOD = indexLOD;
136
- _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new Deferred();
137
- }
138
- var assignWrap = function (babylonTransformNode) {
139
- assign(babylonTransformNode);
140
- babylonTransformNode.setEnabled(false);
141
- };
142
- var promise = _this._loader.loadNodeAsync("/nodes/".concat(nodeLOD.index), nodeLOD, assignWrap).then(function (babylonMesh) {
143
- if (indexLOD !== 0) {
144
- // TODO: should not rely on _babylonTransformNode
145
- var previousNodeLOD = nodeLODs[indexLOD - 1];
146
- if (previousNodeLOD._babylonTransformNode) {
147
- _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
148
- delete previousNodeLOD._babylonTransformNode;
149
- }
150
- }
151
- babylonMesh.setEnabled(true);
152
- return babylonMesh;
153
- });
154
- _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
155
- if (indexLOD === 0) {
156
- firstPromise = promise;
157
- }
158
- else {
159
- _this._nodeIndexLOD = null;
160
- _this._nodePromiseLODs[indexLOD].push(promise);
161
- }
162
- };
163
- for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
164
- _loop_3(indexLOD);
165
- }
166
- _this._loader.logClose();
167
- return firstPromise;
168
- });
169
- };
170
- /**
171
- * @param context
172
- * @param material
173
- * @param babylonMesh
174
- * @param babylonDrawMode
175
- * @param assign
176
- * @hidden
177
- */
178
- MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
179
- var _this = this;
180
- // Don't load material LODs if already loading a node LOD.
181
- if (this._nodeIndexLOD) {
182
- return null;
183
- }
184
- return GLTFLoader.LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
185
- var firstPromise;
186
- var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
187
- _this._loader.logOpen("".concat(extensionContext));
188
- var _loop_4 = function (indexLOD) {
189
- var materialLOD = materialLODs[indexLOD];
190
- if (indexLOD !== 0) {
191
- _this._materialIndexLOD = indexLOD;
192
- }
193
- var promise = _this._loader
194
- ._loadMaterialAsync("/materials/".concat(materialLOD.index), materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
195
- if (indexLOD === 0) {
196
- assign(babylonMaterial);
197
- }
198
- })
199
- .then(function (babylonMaterial) {
200
- if (indexLOD !== 0) {
201
- assign(babylonMaterial);
202
- // TODO: should not rely on _data
203
- var previousDataLOD = materialLODs[indexLOD - 1]._data;
204
- if (previousDataLOD[babylonDrawMode]) {
205
- _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
206
- delete previousDataLOD[babylonDrawMode];
207
- }
208
- }
209
- return babylonMaterial;
210
- });
211
- _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
212
- if (indexLOD === 0) {
213
- firstPromise = promise;
214
- }
215
- else {
216
- _this._materialIndexLOD = null;
217
- _this._materialPromiseLODs[indexLOD].push(promise);
218
- }
219
- };
220
- for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
221
- _loop_4(indexLOD);
222
- }
223
- _this._loader.logClose();
224
- return firstPromise;
225
- });
226
- };
227
- /**
228
- * @param context
229
- * @param property
230
- * @param uri
231
- * @hidden
232
- */
233
- MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
234
- var _this = this;
235
- // Defer the loading of uris if loading a node or material LOD.
236
- if (this._nodeIndexLOD !== null) {
237
- this._loader.log("deferred");
238
- var previousIndexLOD = this._nodeIndexLOD - 1;
239
- this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new Deferred();
240
- return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
241
- return _this._loader.loadUriAsync(context, property, uri);
242
- });
243
- }
244
- else if (this._materialIndexLOD !== null) {
245
- this._loader.log("deferred");
246
- var previousIndexLOD = this._materialIndexLOD - 1;
247
- this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new Deferred();
248
- return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
249
- return _this._loader.loadUriAsync(context, property, uri);
250
- });
251
- }
252
- return null;
253
- };
254
- /**
255
- * @param context
256
- * @param buffer
257
- * @param byteOffset
258
- * @param byteLength
259
- * @hidden
260
- */
261
- MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
262
- if (this._loader.parent.useRangeRequests && !buffer.uri) {
263
- if (!this._loader.bin) {
264
- throw new Error("".concat(context, ": Uri is missing or the binary glTF is missing its binary chunk"));
265
- }
266
- var loadAsync = function (bufferLODs, indexLOD) {
267
- var start = byteOffset;
268
- var end = start + byteLength - 1;
269
- var bufferLOD = bufferLODs[indexLOD];
270
- if (bufferLOD) {
271
- bufferLOD.start = Math.min(bufferLOD.start, start);
272
- bufferLOD.end = Math.max(bufferLOD.end, end);
273
- }
274
- else {
275
- bufferLOD = { start: start, end: end, loaded: new Deferred() };
276
- bufferLODs[indexLOD] = bufferLOD;
277
- }
278
- return bufferLOD.loaded.promise.then(function (data) {
279
- return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
280
- });
281
- };
282
- this._loader.log("deferred");
283
- if (this._nodeIndexLOD !== null) {
284
- return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
285
- }
286
- else if (this._materialIndexLOD !== null) {
287
- return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
288
- }
289
- else {
290
- return loadAsync(this._bufferLODs, 0);
291
- }
292
- }
293
- return null;
294
- };
295
- MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
296
- var bufferLOD = bufferLODs[indexLOD];
297
- if (bufferLOD) {
298
- this._loader.log("Loading buffer range [".concat(bufferLOD.start, "-").concat(bufferLOD.end, "]"));
299
- this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
300
- bufferLOD.loaded.resolve(data);
301
- }, function (error) {
302
- bufferLOD.loaded.reject(error);
303
- });
304
- }
305
- };
306
- /**
307
- * Gets an array of LOD properties from lowest to highest.
308
- * @param context
309
- * @param property
310
- * @param array
311
- * @param ids
312
- */
313
- MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
314
- if (this.maxLODsToLoad <= 0) {
315
- throw new Error("maxLODsToLoad must be greater than zero");
316
- }
317
- var properties = new Array();
318
- for (var i = ids.length - 1; i >= 0; i--) {
319
- properties.push(ArrayItem.Get("".concat(context, "/ids/").concat(ids[i]), array, ids[i]));
320
- if (properties.length === this.maxLODsToLoad) {
321
- return properties;
322
- }
323
- }
324
- properties.push(property);
325
- return properties;
326
- };
327
- MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
328
- var _this = this;
329
- var babylonMaterials = new Array();
330
- var babylonMaterial = babylonTransformNode.material;
331
- if (babylonMaterial) {
332
- babylonMaterials.push(babylonMaterial);
333
- }
334
- for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
335
- var babylonMesh = _a[_i];
336
- if (babylonMesh.material) {
337
- babylonMaterials.push(babylonMesh.material);
338
- }
339
- }
340
- babylonTransformNode.dispose();
341
- var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
342
- this._disposeMaterials(babylonMaterialsToDispose);
343
- };
344
- MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
345
- var babylonTextures = {};
346
- for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
347
- var babylonMaterial = babylonMaterials_1[_i];
348
- for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
349
- var babylonTexture = _b[_a];
350
- babylonTextures[babylonTexture.uniqueId] = babylonTexture;
351
- }
352
- babylonMaterial.dispose();
353
- }
354
- for (var uniqueId in babylonTextures) {
355
- for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
356
- var babylonMaterial = _d[_c];
357
- if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
358
- delete babylonTextures[uniqueId];
359
- }
360
- }
361
- }
362
- for (var uniqueId in babylonTextures) {
363
- babylonTextures[uniqueId].dispose();
364
- }
365
- };
366
- return MSFT_lod;
367
- }());
368
- export { MSFT_lod };
369
- GLTFLoader.RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
1
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
2
+ import { Deferred } from "@babylonjs/core/Misc/deferred.js";
3
+ import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
4
+ var NAME = "MSFT_lod";
5
+ /**
6
+ * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
7
+ */
8
+ var MSFT_lod = /** @class */ (function () {
9
+ /**
10
+ * @param loader
11
+ * @hidden
12
+ */
13
+ function MSFT_lod(loader) {
14
+ /**
15
+ * The name of this extension.
16
+ */
17
+ this.name = NAME;
18
+ /**
19
+ * Defines a number that determines the order the extensions are applied.
20
+ */
21
+ this.order = 100;
22
+ /**
23
+ * Maximum number of LODs to load, starting from the lowest LOD.
24
+ */
25
+ this.maxLODsToLoad = 10;
26
+ /**
27
+ * Observable raised when all node LODs of one level are loaded.
28
+ * The event data is the index of the loaded LOD starting from zero.
29
+ * Dispose the loader to cancel the loading of the next level of LODs.
30
+ */
31
+ this.onNodeLODsLoadedObservable = new Observable();
32
+ /**
33
+ * Observable raised when all material LODs of one level are loaded.
34
+ * The event data is the index of the loaded LOD starting from zero.
35
+ * Dispose the loader to cancel the loading of the next level of LODs.
36
+ */
37
+ this.onMaterialLODsLoadedObservable = new Observable();
38
+ this._bufferLODs = new Array();
39
+ this._nodeIndexLOD = null;
40
+ this._nodeSignalLODs = new Array();
41
+ this._nodePromiseLODs = new Array();
42
+ this._nodeBufferLODs = new Array();
43
+ this._materialIndexLOD = null;
44
+ this._materialSignalLODs = new Array();
45
+ this._materialPromiseLODs = new Array();
46
+ this._materialBufferLODs = new Array();
47
+ this._loader = loader;
48
+ this.enabled = this._loader.isExtensionUsed(NAME);
49
+ }
50
+ /** @hidden */
51
+ MSFT_lod.prototype.dispose = function () {
52
+ this._loader = null;
53
+ this._nodeIndexLOD = null;
54
+ this._nodeSignalLODs.length = 0;
55
+ this._nodePromiseLODs.length = 0;
56
+ this._nodeBufferLODs.length = 0;
57
+ this._materialIndexLOD = null;
58
+ this._materialSignalLODs.length = 0;
59
+ this._materialPromiseLODs.length = 0;
60
+ this._materialBufferLODs.length = 0;
61
+ this.onMaterialLODsLoadedObservable.clear();
62
+ this.onNodeLODsLoadedObservable.clear();
63
+ };
64
+ /** @hidden */
65
+ MSFT_lod.prototype.onReady = function () {
66
+ var _this = this;
67
+ var _loop_1 = function (indexLOD) {
68
+ var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
69
+ if (indexLOD !== 0) {
70
+ _this._loader.endPerformanceCounter("Node LOD ".concat(indexLOD));
71
+ _this._loader.log("Loaded node LOD ".concat(indexLOD));
72
+ }
73
+ _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
74
+ if (indexLOD !== _this._nodePromiseLODs.length - 1) {
75
+ _this._loader.startPerformanceCounter("Node LOD ".concat(indexLOD + 1));
76
+ _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
77
+ if (_this._nodeSignalLODs[indexLOD]) {
78
+ _this._nodeSignalLODs[indexLOD].resolve();
79
+ }
80
+ }
81
+ });
82
+ this_1._loader._completePromises.push(promise);
83
+ };
84
+ var this_1 = this;
85
+ for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
86
+ _loop_1(indexLOD);
87
+ }
88
+ var _loop_2 = function (indexLOD) {
89
+ var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
90
+ if (indexLOD !== 0) {
91
+ _this._loader.endPerformanceCounter("Material LOD ".concat(indexLOD));
92
+ _this._loader.log("Loaded material LOD ".concat(indexLOD));
93
+ }
94
+ _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
95
+ if (indexLOD !== _this._materialPromiseLODs.length - 1) {
96
+ _this._loader.startPerformanceCounter("Material LOD ".concat(indexLOD + 1));
97
+ _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
98
+ if (_this._materialSignalLODs[indexLOD]) {
99
+ _this._materialSignalLODs[indexLOD].resolve();
100
+ }
101
+ }
102
+ });
103
+ this_2._loader._completePromises.push(promise);
104
+ };
105
+ var this_2 = this;
106
+ for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
107
+ _loop_2(indexLOD);
108
+ }
109
+ };
110
+ /**
111
+ * @param context
112
+ * @param scene
113
+ * @hidden
114
+ */
115
+ MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
116
+ var promise = this._loader.loadSceneAsync(context, scene);
117
+ this._loadBufferLOD(this._bufferLODs, 0);
118
+ return promise;
119
+ };
120
+ /**
121
+ * @param context
122
+ * @param node
123
+ * @param assign
124
+ * @hidden
125
+ */
126
+ MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
127
+ var _this = this;
128
+ return GLTFLoader.LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
129
+ var firstPromise;
130
+ var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
131
+ _this._loader.logOpen("".concat(extensionContext));
132
+ var _loop_3 = function (indexLOD) {
133
+ var nodeLOD = nodeLODs[indexLOD];
134
+ if (indexLOD !== 0) {
135
+ _this._nodeIndexLOD = indexLOD;
136
+ _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new Deferred();
137
+ }
138
+ var assignWrap = function (babylonTransformNode) {
139
+ assign(babylonTransformNode);
140
+ babylonTransformNode.setEnabled(false);
141
+ };
142
+ var promise = _this._loader.loadNodeAsync("/nodes/".concat(nodeLOD.index), nodeLOD, assignWrap).then(function (babylonMesh) {
143
+ if (indexLOD !== 0) {
144
+ // TODO: should not rely on _babylonTransformNode
145
+ var previousNodeLOD = nodeLODs[indexLOD - 1];
146
+ if (previousNodeLOD._babylonTransformNode) {
147
+ _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
148
+ delete previousNodeLOD._babylonTransformNode;
149
+ }
150
+ }
151
+ babylonMesh.setEnabled(true);
152
+ return babylonMesh;
153
+ });
154
+ _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
155
+ if (indexLOD === 0) {
156
+ firstPromise = promise;
157
+ }
158
+ else {
159
+ _this._nodeIndexLOD = null;
160
+ _this._nodePromiseLODs[indexLOD].push(promise);
161
+ }
162
+ };
163
+ for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
164
+ _loop_3(indexLOD);
165
+ }
166
+ _this._loader.logClose();
167
+ return firstPromise;
168
+ });
169
+ };
170
+ /**
171
+ * @param context
172
+ * @param material
173
+ * @param babylonMesh
174
+ * @param babylonDrawMode
175
+ * @param assign
176
+ * @hidden
177
+ */
178
+ MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
179
+ var _this = this;
180
+ // Don't load material LODs if already loading a node LOD.
181
+ if (this._nodeIndexLOD) {
182
+ return null;
183
+ }
184
+ return GLTFLoader.LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
185
+ var firstPromise;
186
+ var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
187
+ _this._loader.logOpen("".concat(extensionContext));
188
+ var _loop_4 = function (indexLOD) {
189
+ var materialLOD = materialLODs[indexLOD];
190
+ if (indexLOD !== 0) {
191
+ _this._materialIndexLOD = indexLOD;
192
+ }
193
+ var promise = _this._loader
194
+ ._loadMaterialAsync("/materials/".concat(materialLOD.index), materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
195
+ if (indexLOD === 0) {
196
+ assign(babylonMaterial);
197
+ }
198
+ })
199
+ .then(function (babylonMaterial) {
200
+ if (indexLOD !== 0) {
201
+ assign(babylonMaterial);
202
+ // TODO: should not rely on _data
203
+ var previousDataLOD = materialLODs[indexLOD - 1]._data;
204
+ if (previousDataLOD[babylonDrawMode]) {
205
+ _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
206
+ delete previousDataLOD[babylonDrawMode];
207
+ }
208
+ }
209
+ return babylonMaterial;
210
+ });
211
+ _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
212
+ if (indexLOD === 0) {
213
+ firstPromise = promise;
214
+ }
215
+ else {
216
+ _this._materialIndexLOD = null;
217
+ _this._materialPromiseLODs[indexLOD].push(promise);
218
+ }
219
+ };
220
+ for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
221
+ _loop_4(indexLOD);
222
+ }
223
+ _this._loader.logClose();
224
+ return firstPromise;
225
+ });
226
+ };
227
+ /**
228
+ * @param context
229
+ * @param property
230
+ * @param uri
231
+ * @hidden
232
+ */
233
+ MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
234
+ var _this = this;
235
+ // Defer the loading of uris if loading a node or material LOD.
236
+ if (this._nodeIndexLOD !== null) {
237
+ this._loader.log("deferred");
238
+ var previousIndexLOD = this._nodeIndexLOD - 1;
239
+ this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new Deferred();
240
+ return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
241
+ return _this._loader.loadUriAsync(context, property, uri);
242
+ });
243
+ }
244
+ else if (this._materialIndexLOD !== null) {
245
+ this._loader.log("deferred");
246
+ var previousIndexLOD = this._materialIndexLOD - 1;
247
+ this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new Deferred();
248
+ return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
249
+ return _this._loader.loadUriAsync(context, property, uri);
250
+ });
251
+ }
252
+ return null;
253
+ };
254
+ /**
255
+ * @param context
256
+ * @param buffer
257
+ * @param byteOffset
258
+ * @param byteLength
259
+ * @hidden
260
+ */
261
+ MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
262
+ if (this._loader.parent.useRangeRequests && !buffer.uri) {
263
+ if (!this._loader.bin) {
264
+ throw new Error("".concat(context, ": Uri is missing or the binary glTF is missing its binary chunk"));
265
+ }
266
+ var loadAsync = function (bufferLODs, indexLOD) {
267
+ var start = byteOffset;
268
+ var end = start + byteLength - 1;
269
+ var bufferLOD = bufferLODs[indexLOD];
270
+ if (bufferLOD) {
271
+ bufferLOD.start = Math.min(bufferLOD.start, start);
272
+ bufferLOD.end = Math.max(bufferLOD.end, end);
273
+ }
274
+ else {
275
+ bufferLOD = { start: start, end: end, loaded: new Deferred() };
276
+ bufferLODs[indexLOD] = bufferLOD;
277
+ }
278
+ return bufferLOD.loaded.promise.then(function (data) {
279
+ return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
280
+ });
281
+ };
282
+ this._loader.log("deferred");
283
+ if (this._nodeIndexLOD !== null) {
284
+ return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
285
+ }
286
+ else if (this._materialIndexLOD !== null) {
287
+ return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
288
+ }
289
+ else {
290
+ return loadAsync(this._bufferLODs, 0);
291
+ }
292
+ }
293
+ return null;
294
+ };
295
+ MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
296
+ var bufferLOD = bufferLODs[indexLOD];
297
+ if (bufferLOD) {
298
+ this._loader.log("Loading buffer range [".concat(bufferLOD.start, "-").concat(bufferLOD.end, "]"));
299
+ this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
300
+ bufferLOD.loaded.resolve(data);
301
+ }, function (error) {
302
+ bufferLOD.loaded.reject(error);
303
+ });
304
+ }
305
+ };
306
+ /**
307
+ * Gets an array of LOD properties from lowest to highest.
308
+ * @param context
309
+ * @param property
310
+ * @param array
311
+ * @param ids
312
+ */
313
+ MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
314
+ if (this.maxLODsToLoad <= 0) {
315
+ throw new Error("maxLODsToLoad must be greater than zero");
316
+ }
317
+ var properties = new Array();
318
+ for (var i = ids.length - 1; i >= 0; i--) {
319
+ properties.push(ArrayItem.Get("".concat(context, "/ids/").concat(ids[i]), array, ids[i]));
320
+ if (properties.length === this.maxLODsToLoad) {
321
+ return properties;
322
+ }
323
+ }
324
+ properties.push(property);
325
+ return properties;
326
+ };
327
+ MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
328
+ var _this = this;
329
+ var babylonMaterials = new Array();
330
+ var babylonMaterial = babylonTransformNode.material;
331
+ if (babylonMaterial) {
332
+ babylonMaterials.push(babylonMaterial);
333
+ }
334
+ for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
335
+ var babylonMesh = _a[_i];
336
+ if (babylonMesh.material) {
337
+ babylonMaterials.push(babylonMesh.material);
338
+ }
339
+ }
340
+ babylonTransformNode.dispose();
341
+ var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
342
+ this._disposeMaterials(babylonMaterialsToDispose);
343
+ };
344
+ MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
345
+ var babylonTextures = {};
346
+ for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
347
+ var babylonMaterial = babylonMaterials_1[_i];
348
+ for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
349
+ var babylonTexture = _b[_a];
350
+ babylonTextures[babylonTexture.uniqueId] = babylonTexture;
351
+ }
352
+ babylonMaterial.dispose();
353
+ }
354
+ for (var uniqueId in babylonTextures) {
355
+ for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
356
+ var babylonMaterial = _d[_c];
357
+ if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
358
+ delete babylonTextures[uniqueId];
359
+ }
360
+ }
361
+ }
362
+ for (var uniqueId in babylonTextures) {
363
+ babylonTextures[uniqueId].dispose();
364
+ }
365
+ };
366
+ return MSFT_lod;
367
+ }());
368
+ export { MSFT_lod };
369
+ GLTFLoader.RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
370
370
  //# sourceMappingURL=MSFT_lod.js.map