@babylonjs/core 7.19.1 → 7.20.0

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 (175) hide show
  1. package/Buffers/buffer.nonFloatVertexBuffers.js +1 -1
  2. package/Buffers/buffer.nonFloatVertexBuffers.js.map +1 -1
  3. package/Collisions/gpuPicker.d.ts +8 -2
  4. package/Collisions/gpuPicker.js +41 -20
  5. package/Collisions/gpuPicker.js.map +1 -1
  6. package/Engines/Processors/shaderProcessor.d.ts +1 -0
  7. package/Engines/Processors/shaderProcessor.js +1 -0
  8. package/Engines/Processors/shaderProcessor.js.map +1 -1
  9. package/Engines/WebGPU/Extensions/engine.rawTexture.js +1 -0
  10. package/Engines/WebGPU/Extensions/engine.rawTexture.js.map +1 -1
  11. package/Engines/WebGPU/webgpuShaderProcessingContext.d.ts +1 -1
  12. package/Engines/WebGPU/webgpuShaderProcessingContext.js +4 -2
  13. package/Engines/WebGPU/webgpuShaderProcessingContext.js.map +1 -1
  14. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.d.ts +2 -1
  15. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +12 -5
  16. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
  17. package/Engines/WebGPU/webgpuTextureManager.d.ts +1 -4
  18. package/Engines/WebGPU/webgpuTextureManager.js +90 -75
  19. package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
  20. package/Engines/abstractEngine.d.ts +2 -2
  21. package/Engines/abstractEngine.js +2 -2
  22. package/Engines/abstractEngine.js.map +1 -1
  23. package/Engines/nativeEngine.d.ts +1 -1
  24. package/Engines/nativeEngine.js +2 -1
  25. package/Engines/nativeEngine.js.map +1 -1
  26. package/Engines/thinEngine.d.ts +1 -1
  27. package/Engines/thinEngine.functions.d.ts +1 -1
  28. package/Engines/thinEngine.functions.js +2 -1
  29. package/Engines/thinEngine.functions.js.map +1 -1
  30. package/Engines/thinEngine.js +2 -2
  31. package/Engines/thinEngine.js.map +1 -1
  32. package/Engines/webgpuEngine.d.ts +9 -5
  33. package/Engines/webgpuEngine.js +35 -22
  34. package/Engines/webgpuEngine.js.map +1 -1
  35. package/Layers/effectLayer.d.ts +16 -1
  36. package/Layers/effectLayer.js +32 -2
  37. package/Layers/effectLayer.js.map +1 -1
  38. package/Layers/glowLayer.d.ts +1 -2
  39. package/Layers/glowLayer.js +16 -3
  40. package/Layers/glowLayer.js.map +1 -1
  41. package/Layers/highlightLayer.d.ts +5 -4
  42. package/Layers/highlightLayer.js +36 -11
  43. package/Layers/highlightLayer.js.map +1 -1
  44. package/Layers/index.d.ts +10 -0
  45. package/Layers/index.js +12 -0
  46. package/Layers/index.js.map +1 -1
  47. package/Lights/Shadows/index.d.ts +8 -0
  48. package/Lights/Shadows/index.js +9 -0
  49. package/Lights/Shadows/index.js.map +1 -1
  50. package/Lights/Shadows/shadowGenerator.d.ts +18 -5
  51. package/Lights/Shadows/shadowGenerator.js +44 -5
  52. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  53. package/Loading/sceneLoader.d.ts +155 -16
  54. package/Loading/sceneLoader.js +197 -99
  55. package/Loading/sceneLoader.js.map +1 -1
  56. package/Materials/Node/nodeMaterial.js +8 -1
  57. package/Materials/Node/nodeMaterial.js.map +1 -1
  58. package/Materials/Node/nodeMaterialBuildState.js +1 -1
  59. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  60. package/Materials/effect.functions.d.ts +1 -1
  61. package/Materials/effect.functions.js +6 -3
  62. package/Materials/effect.functions.js.map +1 -1
  63. package/Materials/effect.js +1 -1
  64. package/Materials/effect.js.map +1 -1
  65. package/Materials/standardMaterial.d.ts +1 -1
  66. package/Materials/standardMaterial.js +1 -1
  67. package/Materials/standardMaterial.js.map +1 -1
  68. package/Maths/math.constants.d.ts +1 -2
  69. package/Maths/math.constants.js +1 -2
  70. package/Maths/math.constants.js.map +1 -1
  71. package/Maths/math.like.d.ts +9 -0
  72. package/Maths/math.like.js.map +1 -1
  73. package/Maths/math.vector.d.ts +23 -23
  74. package/Maths/math.vector.js +43 -11
  75. package/Maths/math.vector.js.map +1 -1
  76. package/Misc/index.d.ts +4 -0
  77. package/Misc/index.js +5 -0
  78. package/Misc/index.js.map +1 -1
  79. package/Misc/rgbdTextureTools.d.ts +1 -0
  80. package/Misc/rgbdTextureTools.js +15 -2
  81. package/Misc/rgbdTextureTools.js.map +1 -1
  82. package/PostProcesses/blurPostProcess.d.ts +6 -0
  83. package/PostProcesses/blurPostProcess.js +21 -2
  84. package/PostProcesses/blurPostProcess.js.map +1 -1
  85. package/PostProcesses/index.d.ts +8 -0
  86. package/PostProcesses/index.js +10 -0
  87. package/PostProcesses/index.js.map +1 -1
  88. package/PostProcesses/passPostProcess.d.ts +2 -0
  89. package/PostProcesses/passPostProcess.js +26 -2
  90. package/PostProcesses/passPostProcess.js.map +1 -1
  91. package/PostProcesses/postProcess.d.ts +11 -2
  92. package/PostProcesses/postProcess.js +17 -1
  93. package/PostProcesses/postProcess.js.map +1 -1
  94. package/ShadersWGSL/ShadersInclude/bayerDitherFunctions.d.ts +5 -0
  95. package/ShadersWGSL/ShadersInclude/bayerDitherFunctions.js +17 -0
  96. package/ShadersWGSL/ShadersInclude/bayerDitherFunctions.js.map +1 -0
  97. package/ShadersWGSL/ShadersInclude/imageProcessingFunctions.js +1 -1
  98. package/ShadersWGSL/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  99. package/ShadersWGSL/ShadersInclude/kernelBlurFragment.d.ts +5 -0
  100. package/ShadersWGSL/ShadersInclude/kernelBlurFragment.js +20 -0
  101. package/ShadersWGSL/ShadersInclude/kernelBlurFragment.js.map +1 -0
  102. package/ShadersWGSL/ShadersInclude/kernelBlurFragment2.d.ts +5 -0
  103. package/ShadersWGSL/ShadersInclude/kernelBlurFragment2.js +19 -0
  104. package/ShadersWGSL/ShadersInclude/kernelBlurFragment2.js.map +1 -0
  105. package/ShadersWGSL/ShadersInclude/kernelBlurVaryingDeclaration.d.ts +5 -0
  106. package/ShadersWGSL/ShadersInclude/kernelBlurVaryingDeclaration.js +9 -0
  107. package/ShadersWGSL/ShadersInclude/kernelBlurVaryingDeclaration.js.map +1 -0
  108. package/ShadersWGSL/ShadersInclude/kernelBlurVertex.d.ts +5 -0
  109. package/ShadersWGSL/ShadersInclude/kernelBlurVertex.js +9 -0
  110. package/ShadersWGSL/ShadersInclude/kernelBlurVertex.js.map +1 -0
  111. package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js +4 -4
  112. package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js.map +1 -1
  113. package/ShadersWGSL/ShadersInclude/pbrBRDFFunctions.js +1 -1
  114. package/ShadersWGSL/ShadersInclude/pbrBRDFFunctions.js.map +1 -1
  115. package/ShadersWGSL/ShadersInclude/shadowMapFragment.js +5 -5
  116. package/ShadersWGSL/ShadersInclude/shadowMapFragment.js.map +1 -1
  117. package/ShadersWGSL/ShadersInclude/shadowMapFragmentExtraDeclaration.d.ts +7 -0
  118. package/ShadersWGSL/ShadersInclude/shadowMapFragmentExtraDeclaration.js +26 -0
  119. package/ShadersWGSL/ShadersInclude/shadowMapFragmentExtraDeclaration.js.map +1 -0
  120. package/ShadersWGSL/ShadersInclude/shadowMapFragmentSoftTransparentShadow.d.ts +5 -0
  121. package/ShadersWGSL/ShadersInclude/shadowMapFragmentSoftTransparentShadow.js +12 -0
  122. package/ShadersWGSL/ShadersInclude/shadowMapFragmentSoftTransparentShadow.js.map +1 -0
  123. package/ShadersWGSL/ShadersInclude/shadowMapVertexExtraDeclaration.d.ts +5 -0
  124. package/ShadersWGSL/ShadersInclude/shadowMapVertexExtraDeclaration.js +19 -0
  125. package/ShadersWGSL/ShadersInclude/shadowMapVertexExtraDeclaration.js.map +1 -0
  126. package/ShadersWGSL/ShadersInclude/shadowMapVertexMetric.js +4 -4
  127. package/ShadersWGSL/ShadersInclude/shadowMapVertexMetric.js.map +1 -1
  128. package/ShadersWGSL/ShadersInclude/shadowMapVertexNormalBias.d.ts +5 -0
  129. package/ShadersWGSL/ShadersInclude/shadowMapVertexNormalBias.js +17 -0
  130. package/ShadersWGSL/ShadersInclude/shadowMapVertexNormalBias.js.map +1 -0
  131. package/ShadersWGSL/default.fragment.js +2 -2
  132. package/ShadersWGSL/default.fragment.js.map +1 -1
  133. package/ShadersWGSL/depthBoxBlur.fragment.d.ts +5 -0
  134. package/ShadersWGSL/depthBoxBlur.fragment.js +14 -0
  135. package/ShadersWGSL/depthBoxBlur.fragment.js.map +1 -0
  136. package/ShadersWGSL/glowBlurPostProcess.fragment.d.ts +5 -0
  137. package/ShadersWGSL/glowBlurPostProcess.fragment.js +15 -0
  138. package/ShadersWGSL/glowBlurPostProcess.fragment.js.map +1 -0
  139. package/ShadersWGSL/glowMapGeneration.fragment.d.ts +8 -0
  140. package/ShadersWGSL/glowMapGeneration.fragment.js +74 -0
  141. package/ShadersWGSL/glowMapGeneration.fragment.js.map +1 -0
  142. package/ShadersWGSL/glowMapGeneration.vertex.d.ts +17 -0
  143. package/ShadersWGSL/glowMapGeneration.vertex.js +92 -0
  144. package/ShadersWGSL/glowMapGeneration.vertex.js.map +1 -0
  145. package/ShadersWGSL/glowMapMerge.fragment.d.ts +5 -0
  146. package/ShadersWGSL/glowMapMerge.fragment.js +32 -0
  147. package/ShadersWGSL/glowMapMerge.fragment.js.map +1 -0
  148. package/ShadersWGSL/glowMapMerge.vertex.d.ts +5 -0
  149. package/ShadersWGSL/glowMapMerge.vertex.js +16 -0
  150. package/ShadersWGSL/glowMapMerge.vertex.js.map +1 -0
  151. package/ShadersWGSL/kernelBlur.fragment.d.ts +9 -0
  152. package/ShadersWGSL/kernelBlur.fragment.js +48 -0
  153. package/ShadersWGSL/kernelBlur.fragment.js.map +1 -0
  154. package/ShadersWGSL/kernelBlur.vertex.d.ts +7 -0
  155. package/ShadersWGSL/kernelBlur.vertex.js +21 -0
  156. package/ShadersWGSL/kernelBlur.vertex.js.map +1 -0
  157. package/ShadersWGSL/pass.fragment.d.ts +5 -0
  158. package/ShadersWGSL/pass.fragment.js +12 -0
  159. package/ShadersWGSL/pass.fragment.js.map +1 -0
  160. package/ShadersWGSL/passCube.fragment.d.ts +5 -0
  161. package/ShadersWGSL/passCube.fragment.js +31 -0
  162. package/ShadersWGSL/passCube.fragment.js.map +1 -0
  163. package/ShadersWGSL/rgbdDecode.fragment.d.ts +6 -0
  164. package/ShadersWGSL/rgbdDecode.fragment.js +14 -0
  165. package/ShadersWGSL/rgbdDecode.fragment.js.map +1 -0
  166. package/ShadersWGSL/rgbdEncode.fragment.d.ts +6 -0
  167. package/ShadersWGSL/rgbdEncode.fragment.js +14 -0
  168. package/ShadersWGSL/rgbdEncode.fragment.js.map +1 -0
  169. package/ShadersWGSL/shadowMap.fragment.d.ts +9 -0
  170. package/ShadersWGSL/shadowMap.fragment.js +39 -0
  171. package/ShadersWGSL/shadowMap.fragment.js.map +1 -0
  172. package/ShadersWGSL/shadowMap.vertex.d.ts +22 -0
  173. package/ShadersWGSL/shadowMap.vertex.js +89 -0
  174. package/ShadersWGSL/shadowMap.vertex.js.map +1 -0
  175. package/package.json +1 -1
@@ -9,6 +9,7 @@ import { IsBase64DataUrl } from "../Misc/fileTools.js";
9
9
  import { RuntimeError, ErrorCodes } from "../Misc/error.js";
10
10
  import { RandomGUID } from "../Misc/guid.js";
11
11
  import { Engine } from "../Engines/engine.js";
12
+ import { AbstractEngine } from "../Engines/abstractEngine.js";
12
13
  /**
13
14
  * Mode that determines how to handle old animation groups before loading new ones.
14
15
  */
@@ -31,6 +32,9 @@ export var SceneLoaderAnimationGroupLoadingMode;
31
32
  */
32
33
  SceneLoaderAnimationGroupLoadingMode[SceneLoaderAnimationGroupLoadingMode["NoSync"] = 3] = "NoSync";
33
34
  })(SceneLoaderAnimationGroupLoadingMode || (SceneLoaderAnimationGroupLoadingMode = {}));
35
+ function isFile(value) {
36
+ return !!value.name;
37
+ }
34
38
  /**
35
39
  * Class used to load scene from various file formats using registered plugins
36
40
  * @see https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes
@@ -127,7 +131,7 @@ export class SceneLoader {
127
131
  }
128
132
  return errorMessage;
129
133
  }
130
- static _LoadData(fileInfo, scene, onSuccess, onProgress, onError, onDispose, pluginExtension, name) {
134
+ static _LoadData(fileInfo, scene, onSuccess, onProgress, onError, onDispose, pluginExtension, name, pluginOptions) {
131
135
  const directLoad = SceneLoader._GetDirectLoad(fileInfo.url);
132
136
  if (fileInfo.rawData && !pluginExtension) {
133
137
  // eslint-disable-next-line no-throw-literal
@@ -138,14 +142,20 @@ export class SceneLoader {
138
142
  : directLoad
139
143
  ? SceneLoader._GetPluginForDirectLoad(fileInfo.url)
140
144
  : SceneLoader._GetPluginForFilename(fileInfo.url);
145
+ if (pluginOptions?.[registeredPlugin.plugin.name]?.enabled === false) {
146
+ throw new Error(`The '${registeredPlugin.plugin.name}' plugin is disabled via the loader options passed to the loading operation.`);
147
+ }
141
148
  if (fileInfo.rawData && !registeredPlugin.isBinary) {
142
149
  // eslint-disable-next-line no-throw-literal
143
150
  throw "Loading from ArrayBufferView can not be used with plugins that don't support binary loading.";
144
151
  }
145
- const plugin = registeredPlugin.plugin.createPlugin?.() ?? registeredPlugin.plugin;
152
+ // For plugin factories, the plugin is instantiated on each SceneLoader operation. This makes options handling
153
+ // much simpler as we can just pass the options to the factory, rather than passing options through to every possible
154
+ // plugin call. Given this, options are only supported for plugins that provide a factory function.
155
+ const plugin = registeredPlugin.plugin.createPlugin?.(pluginOptions ?? {}) ?? registeredPlugin.plugin;
146
156
  if (!plugin) {
147
157
  // eslint-disable-next-line no-throw-literal
148
- throw "The loader plugin corresponding to the file type you are trying to load has not been found. If using es6, please import the plugin you wish to use before.";
158
+ throw `The loader plugin corresponding to the '${pluginExtension}' file type has not been found. If using es6, please import the plugin you wish to use before.`;
149
159
  }
150
160
  SceneLoader.OnPluginActivatedObservable.notifyObservers(plugin);
151
161
  // Check if we have a direct load url. If the plugin is registered to handle
@@ -226,33 +236,32 @@ export class SceneLoader {
226
236
  }
227
237
  return plugin;
228
238
  }
229
- static _GetFileInfo(rootUrl, sceneFilename) {
239
+ static _GetFileInfo(rootUrl, sceneSource) {
230
240
  let url;
231
241
  let name;
232
242
  let file = null;
233
243
  let rawData = null;
234
- if (!sceneFilename) {
244
+ if (!sceneSource) {
235
245
  url = rootUrl;
236
246
  name = Tools.GetFilename(rootUrl);
237
247
  rootUrl = Tools.GetFolderPath(rootUrl);
238
248
  }
239
- else if (sceneFilename.name) {
240
- const sceneFile = sceneFilename;
241
- url = `file:${sceneFile.name}`;
242
- name = sceneFile.name;
243
- file = sceneFile;
249
+ else if (isFile(sceneSource)) {
250
+ url = `file:${sceneSource.name}`;
251
+ name = sceneSource.name;
252
+ file = sceneSource;
244
253
  }
245
- else if (ArrayBuffer.isView(sceneFilename)) {
254
+ else if (ArrayBuffer.isView(sceneSource)) {
246
255
  url = "";
247
256
  name = RandomGUID();
248
- rawData = sceneFilename;
257
+ rawData = sceneSource;
249
258
  }
250
- else if (typeof sceneFilename === "string" && sceneFilename.startsWith("data:")) {
251
- url = sceneFilename;
259
+ else if (sceneSource.startsWith("data:")) {
260
+ url = sceneSource;
252
261
  name = "";
253
262
  }
254
- else {
255
- const filename = sceneFilename;
263
+ else if (rootUrl) {
264
+ const filename = sceneSource;
256
265
  if (filename.substr(0, 1) === "/") {
257
266
  Tools.Error("Wrong sceneFilename parameter");
258
267
  return null;
@@ -260,6 +269,11 @@ export class SceneLoader {
260
269
  url = rootUrl + filename;
261
270
  name = filename;
262
271
  }
272
+ else {
273
+ url = sceneSource;
274
+ name = Tools.GetFilename(sceneSource);
275
+ rootUrl = Tools.GetFolderPath(sceneSource);
276
+ }
263
277
  return {
264
278
  url: url,
265
279
  rootUrl: rootUrl,
@@ -320,7 +334,10 @@ export class SceneLoader {
320
334
  * @param name defines the name of the file, if the data is binary
321
335
  * @returns The loaded plugin
322
336
  */
323
- static ImportMesh(meshNames, rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "") {
337
+ static ImportMesh(meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name) {
338
+ return SceneLoader._ImportMesh(meshNames, rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name);
339
+ }
340
+ static _ImportMesh(meshNames, rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
324
341
  if (!scene) {
325
342
  Logger.Error("No scene available to import mesh to");
326
343
  return null;
@@ -394,22 +411,36 @@ export class SceneLoader {
394
411
  errorHandler(error.message, error);
395
412
  });
396
413
  }
397
- }, progressHandler, errorHandler, disposeHandler, pluginExtension, name);
414
+ }, progressHandler, errorHandler, disposeHandler, pluginExtension, name, pluginOptions);
398
415
  }
399
- /**
400
- * Import meshes into a scene
401
- * @param meshNames an array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
402
- * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
403
- * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
404
- * @param scene the instance of BABYLON.Scene to append to
405
- * @param onProgress a callback with a progress event for each file being loaded
406
- * @param pluginExtension the extension used to determine the plugin
407
- * @param name defines the name of the file
408
- * @returns The loaded list of imported meshes, particle systems, skeletons, and animation groups
409
- */
410
- static ImportMeshAsync(meshNames, rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onProgress = null, pluginExtension = null, name = "") {
416
+ static ImportMeshAsync(...args) {
417
+ let meshNames;
418
+ let rootUrl;
419
+ let sceneFilename;
420
+ let scene;
421
+ let onProgress;
422
+ let pluginExtension;
423
+ let name;
424
+ let pluginOptions;
425
+ // This is a user-defined type guard: https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
426
+ // This is the most type safe way to distinguish between the two possible argument arrays.
427
+ const isOptionsArgs = (maybeOptionsArgs) => {
428
+ // If the second argument is an object, then it must be the options overload.
429
+ return typeof maybeOptionsArgs[1] === "object";
430
+ };
431
+ if (isOptionsArgs(args)) {
432
+ // Source is mapped to sceneFileName
433
+ sceneFilename = args[0];
434
+ scene = args[1];
435
+ // Options determine the rest of the arguments
436
+ ({ meshNames, rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = args[2] ?? {});
437
+ }
438
+ else {
439
+ // For the legacy signature, we just directly map each argument
440
+ [meshNames, rootUrl, sceneFilename, scene, onProgress, pluginExtension, name] = args;
441
+ }
411
442
  return new Promise((resolve, reject) => {
412
- SceneLoader.ImportMesh(meshNames, rootUrl, sceneFilename, scene, (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights, spriteManagers) => {
443
+ SceneLoader._ImportMesh(meshNames, rootUrl, sceneFilename, scene, (meshes, particleSystems, skeletons, animationGroups, transformNodes, geometries, lights, spriteManagers) => {
413
444
  resolve({
414
445
  meshes: meshes,
415
446
  particleSystems: particleSystems,
@@ -422,7 +453,7 @@ export class SceneLoader {
422
453
  });
423
454
  }, onProgress, (scene, message, exception) => {
424
455
  reject(exception || new Error(message));
425
- }, pluginExtension, name);
456
+ }, pluginExtension, name, pluginOptions);
426
457
  });
427
458
  }
428
459
  /**
@@ -437,30 +468,47 @@ export class SceneLoader {
437
468
  * @param name defines the filename, if the data is binary
438
469
  * @returns The loaded plugin
439
470
  */
440
- static Load(rootUrl, sceneFilename = "", engine = EngineStore.LastCreatedEngine, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "") {
471
+ static Load(rootUrl, sceneFilename, engine, onSuccess, onProgress, onError, pluginExtension, name) {
472
+ return SceneLoader._Load(rootUrl, sceneFilename, engine, onSuccess, onProgress, onError, pluginExtension, name);
473
+ }
474
+ static _Load(rootUrl, sceneFilename = "", engine = EngineStore.LastCreatedEngine, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
441
475
  if (!engine) {
442
476
  Tools.Error("No engine available");
443
477
  return null;
444
478
  }
445
- return SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension, name);
479
+ return SceneLoader._Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension, name, pluginOptions);
446
480
  }
447
- /**
448
- * Load a scene
449
- * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
450
- * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
451
- * @param engine is the instance of BABYLON.Engine to use to create the scene
452
- * @param onProgress a callback with a progress event for each file being loaded
453
- * @param pluginExtension the extension used to determine the plugin
454
- * @param name defines the filename, if the data is binary
455
- * @returns The loaded scene
456
- */
457
- static LoadAsync(rootUrl, sceneFilename = "", engine = EngineStore.LastCreatedEngine, onProgress = null, pluginExtension = null, name = "") {
481
+ static LoadAsync(...args) {
482
+ let rootUrl;
483
+ let sceneFilename;
484
+ let engine;
485
+ let onProgress;
486
+ let pluginExtension;
487
+ let name;
488
+ let pluginOptions;
489
+ // This is a user-defined type guard: https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
490
+ // This is the most type safe way to distinguish between the two possible argument arrays.
491
+ const isOptionsArgs = (maybeOptionsArgs) => {
492
+ // If the second argument is an engine, then it must be the options overload.
493
+ return maybeOptionsArgs[1] instanceof AbstractEngine;
494
+ };
495
+ if (isOptionsArgs(args)) {
496
+ // Source is mapped to sceneFileName
497
+ sceneFilename = args[0];
498
+ engine = args[1];
499
+ // Options determine the rest of the arguments
500
+ ({ rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = args[2] ?? {});
501
+ }
502
+ else {
503
+ // For the legacy signature, we just directly map each argument
504
+ [rootUrl, sceneFilename, engine, onProgress, pluginExtension, name] = args;
505
+ }
458
506
  return new Promise((resolve, reject) => {
459
- SceneLoader.Load(rootUrl, sceneFilename, engine, (scene) => {
507
+ SceneLoader._Load(rootUrl, sceneFilename, engine, (scene) => {
460
508
  resolve(scene);
461
509
  }, onProgress, (scene, message, exception) => {
462
510
  reject(exception || new Error(message));
463
- }, pluginExtension, name);
511
+ }, pluginExtension, name, pluginOptions);
464
512
  });
465
513
  }
466
514
  /**
@@ -475,7 +523,10 @@ export class SceneLoader {
475
523
  * @param name defines the name of the file, if the data is binary
476
524
  * @returns The loaded plugin
477
525
  */
478
- static Append(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "") {
526
+ static Append(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name) {
527
+ return SceneLoader._Append(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name);
528
+ }
529
+ static _Append(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
479
530
  if (!scene) {
480
531
  Logger.Error("No scene available to append to");
481
532
  return null;
@@ -550,25 +601,39 @@ export class SceneLoader {
550
601
  errorHandler(error.message, error);
551
602
  });
552
603
  }
553
- }, progressHandler, errorHandler, disposeHandler, pluginExtension, name);
604
+ }, progressHandler, errorHandler, disposeHandler, pluginExtension, name, pluginOptions);
554
605
  }
555
- /**
556
- * Append a scene
557
- * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
558
- * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
559
- * @param scene is the instance of BABYLON.Scene to append to
560
- * @param onProgress a callback with a progress event for each file being loaded
561
- * @param pluginExtension the extension used to determine the plugin
562
- * @param name defines the name of the file, if the data is binary
563
- * @returns The given scene
564
- */
565
- static AppendAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onProgress = null, pluginExtension = null, name = "") {
606
+ static AppendAsync(...args) {
607
+ let rootUrl;
608
+ let sceneFilename;
609
+ let scene;
610
+ let onProgress;
611
+ let pluginExtension;
612
+ let name;
613
+ let pluginOptions;
614
+ // This is a user-defined type guard: https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
615
+ // This is the most type safe way to distinguish between the two possible argument arrays.
616
+ const isOptionsArgs = (maybeOptionsArgs) => {
617
+ // If the second argument is a Scene, then it must be the options overload.
618
+ return maybeOptionsArgs[1] instanceof Scene;
619
+ };
620
+ if (isOptionsArgs(args)) {
621
+ // Source is mapped to sceneFileName
622
+ sceneFilename = args[0];
623
+ scene = args[1];
624
+ // Options determine the rest of the arguments
625
+ ({ rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = args[2] ?? {});
626
+ }
627
+ else {
628
+ // For the legacy signature, we just directly map each argument
629
+ [rootUrl, sceneFilename, scene, onProgress, pluginExtension, name] = args;
630
+ }
566
631
  return new Promise((resolve, reject) => {
567
- SceneLoader.Append(rootUrl, sceneFilename, scene, (scene) => {
632
+ SceneLoader._Append(rootUrl, sceneFilename, scene, (scene) => {
568
633
  resolve(scene);
569
634
  }, onProgress, (scene, message, exception) => {
570
635
  reject(exception || new Error(message));
571
- }, pluginExtension, name);
636
+ }, pluginExtension, name, pluginOptions);
572
637
  });
573
638
  }
574
639
  /**
@@ -583,7 +648,10 @@ export class SceneLoader {
583
648
  * @param name defines the filename, if the data is binary
584
649
  * @returns The loaded plugin
585
650
  */
586
- static LoadAssetContainer(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "") {
651
+ static LoadAssetContainer(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name) {
652
+ return SceneLoader._LoadAssetContainer(rootUrl, sceneFilename, scene, onSuccess, onProgress, onError, pluginExtension, name);
653
+ }
654
+ static _LoadAssetContainer(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
587
655
  if (!scene) {
588
656
  Logger.Error("No scene available to load asset container to");
589
657
  return null;
@@ -656,24 +724,41 @@ export class SceneLoader {
656
724
  else {
657
725
  errorHandler("LoadAssetContainer is not supported by this plugin. Plugin did not provide a loadAssetContainer or loadAssetContainerAsync method.");
658
726
  }
659
- }, progressHandler, errorHandler, disposeHandler, pluginExtension, name);
727
+ }, progressHandler, errorHandler, disposeHandler, pluginExtension, name, pluginOptions);
660
728
  }
661
- /**
662
- * Load a scene into an asset container
663
- * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
664
- * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene (default: empty string)
665
- * @param scene is the instance of Scene to append to
666
- * @param onProgress a callback with a progress event for each file being loaded
667
- * @param pluginExtension the extension used to determine the plugin
668
- * @returns The loaded asset container
669
- */
670
- static LoadAssetContainerAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, onProgress = null, pluginExtension = null) {
729
+ // This is the single implementation that handles both the legacy many-parameters overload and the
730
+ // new source + config overload. Using a parameters array union is the most type safe way to handle this.
731
+ static LoadAssetContainerAsync(...args) {
732
+ let rootUrl;
733
+ let sceneFilename;
734
+ let scene;
735
+ let onProgress;
736
+ let pluginExtension;
737
+ let name;
738
+ let pluginOptions;
739
+ // This is a user-defined type guard: https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
740
+ // This is the most type safe way to distinguish between the two possible argument arrays.
741
+ const isOptionsArgs = (maybeOptionsArgs) => {
742
+ // If the second argument is a Scene, then it must be the options overload.
743
+ return maybeOptionsArgs[1] instanceof Scene;
744
+ };
745
+ if (isOptionsArgs(args)) {
746
+ // Source is mapped to sceneFileName
747
+ sceneFilename = args[0];
748
+ scene = args[1];
749
+ // Options determine the rest of the arguments
750
+ ({ rootUrl = "", onProgress, pluginExtension, name, pluginOptions } = args[2] ?? {});
751
+ }
752
+ else {
753
+ // For the legacy signature, we just directly map each argument
754
+ [rootUrl, sceneFilename, scene, onProgress, pluginExtension, name] = args;
755
+ }
671
756
  return new Promise((resolve, reject) => {
672
- SceneLoader.LoadAssetContainer(rootUrl, sceneFilename, scene, (assetContainer) => {
757
+ SceneLoader._LoadAssetContainer(rootUrl, sceneFilename, scene, (assetContainer) => {
673
758
  resolve(assetContainer);
674
759
  }, onProgress, (scene, message, exception) => {
675
760
  reject(exception || new Error(message));
676
- }, pluginExtension);
761
+ }, pluginExtension, name, pluginOptions);
677
762
  });
678
763
  }
679
764
  /**
@@ -688,8 +773,12 @@ export class SceneLoader {
688
773
  * @param onProgress a callback with a progress event for each file being loaded
689
774
  * @param onError a callback with the scene, a message, and possibly an exception when import fails
690
775
  * @param pluginExtension the extension used to determine the plugin
776
+ * @param name defines the filename, if the data is binary
691
777
  */
692
- static ImportAnimations(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = 0 /* SceneLoaderAnimationGroupLoadingMode.Clean */, targetConverter = null, onSuccess = null, onProgress = null, onError = null, pluginExtension = null) {
778
+ static ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onSuccess, onProgress, onError, pluginExtension, name) {
779
+ SceneLoader._ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, onSuccess, onProgress, onError, pluginExtension, name);
780
+ }
781
+ static _ImportAnimations(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = 0 /* SceneLoaderAnimationGroupLoadingMode.Clean */, targetConverter = null, onSuccess = null, onProgress = null, onError = null, pluginExtension = null, name = "", pluginOptions = {}) {
693
782
  if (!scene) {
694
783
  Logger.Error("No scene available to load animations to");
695
784
  return;
@@ -745,33 +834,42 @@ export class SceneLoader {
745
834
  onSuccess(scene);
746
835
  }
747
836
  };
748
- this.LoadAssetContainer(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError, pluginExtension);
837
+ this._LoadAssetContainer(rootUrl, sceneFilename, scene, onAssetContainerLoaded, onProgress, onError, pluginExtension, name, pluginOptions);
749
838
  }
750
- /**
751
- * Import animations from a file into a scene
752
- * @param rootUrl a string that defines the root url for the scene and resources or the concatenation of rootURL and filename (e.g. http://example.com/test.glb)
753
- * @param sceneFilename a string that defines the name of the scene file or starts with "data:" following by the stringified version of the scene or a File object (default: empty string)
754
- * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)
755
- * @param overwriteAnimations when true, animations are cleaned before importing new ones. Animations are appended otherwise
756
- * @param animationGroupLoadingMode defines how to handle old animations groups before importing new ones
757
- * @param targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)
758
- * @param onSuccess a callback with the scene when import succeeds
759
- * @param onProgress a callback with a progress event for each file being loaded
760
- * @param onError a callback with the scene, a message, and possibly an exception when import fails
761
- * @param pluginExtension the extension used to determine the plugin
762
- * @returns the updated scene with imported animations
763
- */
764
- static ImportAnimationsAsync(rootUrl, sceneFilename = "", scene = EngineStore.LastCreatedScene, overwriteAnimations = true, animationGroupLoadingMode = 0 /* SceneLoaderAnimationGroupLoadingMode.Clean */, targetConverter = null,
765
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
766
- onSuccess = null, onProgress = null,
767
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
768
- onError = null, pluginExtension = null) {
839
+ static ImportAnimationsAsync(...args) {
840
+ let rootUrl;
841
+ let sceneFilename;
842
+ let scene;
843
+ let overwriteAnimations;
844
+ let animationGroupLoadingMode;
845
+ let targetConverter;
846
+ let onProgress;
847
+ let pluginExtension;
848
+ let name;
849
+ let pluginOptions;
850
+ // This is a user-defined type guard: https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
851
+ // This is the most type safe way to distinguish between the two possible argument arrays.
852
+ const isOptionsArgs = (maybeOptionsArgs) => {
853
+ // If the second argument is a Scene, then it must be the options overload.
854
+ return maybeOptionsArgs[1] instanceof Scene;
855
+ };
856
+ if (isOptionsArgs(args)) {
857
+ // Source is mapped to sceneFileName
858
+ sceneFilename = args[0];
859
+ scene = args[1];
860
+ // Options determine the rest of the arguments
861
+ ({ rootUrl = "", overwriteAnimations, animationGroupLoadingMode, targetConverter, onProgress, pluginExtension, name, pluginOptions } = args[2] ?? {});
862
+ }
863
+ else {
864
+ // For the legacy signature, we just directly map each argument
865
+ [rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, , onProgress, , pluginExtension, name] = args;
866
+ }
769
867
  return new Promise((resolve, reject) => {
770
- SceneLoader.ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, (_scene) => {
868
+ SceneLoader._ImportAnimations(rootUrl, sceneFilename, scene, overwriteAnimations, animationGroupLoadingMode, targetConverter, (_scene) => {
771
869
  resolve(_scene);
772
870
  }, onProgress, (_scene, message, exception) => {
773
871
  reject(exception || new Error(message));
774
- }, pluginExtension);
872
+ }, pluginExtension, name, pluginOptions);
775
873
  });
776
874
  }
777
875
  }