filesInput.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import type { Engine } from "../Engines/engine";
  2. import type { Scene } from "../scene";
  3. import type { ISceneLoaderProgressEvent } from "../Loading/sceneLoader";
  4. import type { Nullable } from "../types";
  5. /**
  6. * Class used to help managing file picking and drag-n-drop
  7. */
  8. export declare class FilesInput {
  9. readonly useAppend: boolean;
  10. /**
  11. * List of files ready to be loaded
  12. */
  13. static get FilesToLoad(): {
  14. [key: string]: File;
  15. };
  16. /**
  17. * Callback called when a file is processed
  18. * @returns false to abort the process
  19. */
  20. onProcessFileCallback: (file: File, name: string, extension: string, setSceneFileToLoad: (sceneFile: File) => void) => boolean;
  21. /**
  22. * If a loading UI should be displayed while loading a file
  23. */
  24. displayLoadingUI: boolean;
  25. /**
  26. * Function used when loading the scene file
  27. * @param sceneFile defines the file to load
  28. * @param onProgress onProgress callback called while loading the file
  29. * @returns a promise completing when the load is complete
  30. */
  31. loadAsync: (sceneFile: File, onProgress: Nullable<(event: ISceneLoaderProgressEvent) => void>) => Promise<Scene>;
  32. private _engine;
  33. private _currentScene;
  34. private _sceneLoadedCallback;
  35. private _progressCallback;
  36. private _additionalRenderLoopLogicCallback;
  37. private _textureLoadingCallback;
  38. private _startingProcessingFilesCallback;
  39. private _onReloadCallback;
  40. private _errorCallback;
  41. private _elementToMonitor;
  42. private _sceneFileToLoad;
  43. private _filesToLoad;
  44. /**
  45. * Creates a new FilesInput
  46. * @param engine defines the rendering engine
  47. * @param scene defines the hosting scene
  48. * @param sceneLoadedCallback callback called when scene (files provided) is loaded
  49. * @param progressCallback callback called to track progress
  50. * @param additionalRenderLoopLogicCallback callback called to add user logic to the rendering loop
  51. * @param textureLoadingCallback callback called when a texture is loading
  52. * @param startingProcessingFilesCallback callback called when the system is about to process all files
  53. * @param onReloadCallback callback called when a reload is requested
  54. * @param errorCallback callback call if an error occurs
  55. * @param useAppend defines if the file loaded must be appended (true) or have the scene replaced (false, default behavior)
  56. */
  57. constructor(engine: Engine, scene: Nullable<Scene>, sceneLoadedCallback: Nullable<(sceneFile: File, scene: Scene) => void>, progressCallback: Nullable<(progress: ISceneLoaderProgressEvent) => void>, additionalRenderLoopLogicCallback: Nullable<() => void>, textureLoadingCallback: Nullable<(remaining: number) => void>, startingProcessingFilesCallback: Nullable<(files?: File[]) => void>, onReloadCallback: Nullable<(sceneFile: File) => void>, errorCallback: Nullable<(sceneFile: File, scene: Nullable<Scene>, message: string) => void>, useAppend?: boolean);
  58. private _dragEnterHandler;
  59. private _dragOverHandler;
  60. private _dropHandler;
  61. /**
  62. * Calls this function to listen to drag'n'drop events on a specific DOM element
  63. * @param elementToMonitor defines the DOM element to track
  64. */
  65. monitorElementForDragNDrop(elementToMonitor: HTMLElement): void;
  66. /** Gets the current list of files to load */
  67. get filesToLoad(): File[];
  68. /**
  69. * Release all associated resources
  70. */
  71. dispose(): void;
  72. private _renderFunction;
  73. private _drag;
  74. private _drop;
  75. private _traverseFolder;
  76. private _processFiles;
  77. /**
  78. * Load files from a drop event
  79. * @param event defines the drop event to use as source
  80. */
  81. loadFiles(event: any): void;
  82. private _processReload;
  83. /**
  84. * Reload the current scene from the loaded files
  85. */
  86. reload(): void;
  87. }