@babylonjs/loaders 5.0.0-rc.1 → 5.0.0-rc.10

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