splatFileLoader.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
  2. import { GaussianSplattingMesh } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
  3. /**
  4. * @experimental
  5. * SPLAT file type loader.
  6. * This is a babylon scene loader plugin.
  7. */
  8. export class SPLATFileLoader {
  9. //private _loadingOptions: SPLATLoadingOptions;
  10. /**
  11. * Creates loader for gaussian splatting files
  12. */
  13. constructor() {
  14. /**
  15. * Defines the name of the plugin.
  16. */
  17. this.name = "splat";
  18. /**
  19. * Defines the extensions the splat loader is able to load.
  20. * force data to come in as an ArrayBuffer
  21. */
  22. this.extensions = {
  23. // eslint-disable-next-line @typescript-eslint/naming-convention
  24. ".splat": { isBinary: true },
  25. // eslint-disable-next-line @typescript-eslint/naming-convention
  26. ".ply": { isBinary: true },
  27. };
  28. }
  29. /**
  30. * Instantiates a gaussian splatting file loader plugin.
  31. * @returns the created plugin
  32. */
  33. createPlugin() {
  34. return new SPLATFileLoader();
  35. }
  36. /**
  37. * If the data string can be loaded directly.
  38. * @returns if the data can be loaded directly
  39. */
  40. canDirectLoad() {
  41. return false;
  42. }
  43. /**
  44. * Imports from the loaded gaussian splatting data and adds them to the scene
  45. * @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file
  46. * @param scene the scene the meshes should be added to
  47. * @param data the gaussian splatting data to load
  48. * @param rootUrl root url to load from
  49. * @param onProgress callback called while file is loading
  50. * @param fileName Defines the name of the file to load
  51. * @returns a promise containing the loaded meshes, particles, skeletons and animations
  52. */
  53. async importMeshAsync(_meshesNames, scene, data, rootUrl, onProgress, fileName) {
  54. const gaussianSplatting = new GaussianSplattingMesh("GaussianSplatting", null, scene);
  55. await gaussianSplatting.loadFileAsync(rootUrl + (fileName ?? ""));
  56. return {
  57. meshes: [gaussianSplatting],
  58. particleSystems: [],
  59. skeletons: [],
  60. animationGroups: [],
  61. transformNodes: [],
  62. geometries: [],
  63. lights: [],
  64. spriteManagers: [],
  65. };
  66. }
  67. /**
  68. * Imports all objects from the loaded gaussian splatting data and adds them to the scene
  69. * @param scene the scene the objects should be added to
  70. * @param data the gaussian splatting data to load
  71. * @param _rootUrl root url to load from
  72. * @returns a promise which completes when objects have been loaded to the scene
  73. */
  74. loadAsync(scene, data, _rootUrl) {
  75. const gaussianSplatting = new GaussianSplattingMesh("GaussianSplatting", null, scene);
  76. return gaussianSplatting.loadDataAsync(GaussianSplattingMesh.ConvertPLYToSplat(data));
  77. }
  78. // eslint-disable-next-line jsdoc/require-returns-check
  79. /**
  80. * Load into an asset container.
  81. * @param _scene The scene to load into
  82. * @param _data The data to import
  83. * @param _rootUrl The root url for scene and resources
  84. * @returns The loaded asset container
  85. */
  86. loadAssetContainerAsync(_scene, _data, _rootUrl) {
  87. throw new Error("loadAssetContainerAsync not implemented for Gaussian Splatting loading");
  88. }
  89. }
  90. if (SceneLoader) {
  91. //Add this loader into the register plugin
  92. SceneLoader.RegisterPlugin(new SPLATFileLoader());
  93. }
  94. //# sourceMappingURL=splatFileLoader.js.map