threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

IAssetImporter.ts 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {BaseEvent, EventDispatcher, LoadingManager, Object3D} from 'three'
  2. import {AnyOptions, IDisposable} from 'ts-browser-helpers'
  3. import {IAsset, IFile} from './IAsset'
  4. import {ILoader} from './IImporter'
  5. import {ICamera, IMaterial, IObject3D, ITexture} from '../core'
  6. import {ISerializedConfig, ISerializedViewerConfig} from '../viewer'
  7. import {GLTF} from 'three/examples/jsm/loaders/GLTFLoader.js'
  8. export interface RootSceneImportResult extends Object3D {
  9. readonly visible: true
  10. importedViewerConfig?: ISerializedViewerConfig
  11. userData: {
  12. rootSceneModelRoot?: true
  13. __importData?: any
  14. gltfExtras?: GLTF['userData']
  15. gltfAsset?: GLTF['asset']
  16. [key: string]: any
  17. }
  18. }
  19. export type ImportResultObject = IObject3D | ITexture | ICamera | ISerializedConfig | ISerializedViewerConfig | RootSceneImportResult | IMaterial
  20. export interface ImportResultExtras {
  21. constructor: any
  22. assetImporterProcessed?: boolean
  23. isObject3D?: boolean
  24. isCamera?: boolean
  25. isMaterial?: boolean
  26. isTexture?: boolean
  27. userData?: IImportResultUserData
  28. // eslin t-disable-next-line @typescript-eslint/naming-convention
  29. __rootPath?: string
  30. // eslin t-disable-next-line @typescript-eslint/naming-convention
  31. __rootBlob?: IFile
  32. // eslin t-disable-next-line @typescript-eslint/naming-convention
  33. __disposed?: boolean
  34. [key: string]: any
  35. }
  36. export type ImportResult = ImportResultObject & ImportResultExtras
  37. export interface IImportResultUserData{
  38. rootPath?: string
  39. // eslin t-disable-next-line @typescript-eslint/naming-convention
  40. __importData?: any // extra arbitrary data saved by the importer that can be used by the plugins (like gltf material variants)
  41. // eslin t-disable-next-line @typescript-eslint/naming-convention
  42. __needsSourceBuffer?: boolean // This can be set to true in the importer to indicate that the source buffer should be loaded and cached in the userdata during processRaw
  43. // eslin t-disable-next-line @typescript-eslint/naming-convention
  44. __sourceBuffer?: ArrayBuffer // Cache d source buffer for the asset (only cached when __needsSourceBuffer is set)
  45. // eslin t-disable-next-line @typescript-eslint/naming-convention
  46. __sourceBlob?: IFile // Cache d source blob for the asset
  47. }
  48. export type ProcessRawOptions = {
  49. processRaw?: boolean, // defau lt = true, toggle to control the processing of the raw objects in the proecssRaw method
  50. forceImporterReprocess?: boolean, // defau lt = false. If true, the importer will reprocess the imported objects, even if they are already processed.
  51. rootPath?: string, // internal use
  52. generateMipmaps?: boolean|undefined, // defau lt = undefined, only used for textures
  53. autoImportZipContents?: boolean, // defau lt = true, if true, the importer will automatically import the contents of zip files, if zip importer is registered.
  54. // inter nal
  55. _testDataTextureComplete?: boolean, // defau lt = false, if set to true, it will test if the data textures are complete. [internal use]
  56. /**
  57. * @deprecated use processRaw instead
  58. */
  59. processImported?: boolean, // same as processRaw
  60. } & AnyOptions
  61. export interface LoadFileOptions {
  62. fileHandler?: any, // custom {@link ILoader} for the file
  63. /**
  64. * Query string to add to the url. Default = undefined
  65. */
  66. queryString?: string,
  67. rootPath?: string, // internal use
  68. }
  69. export type ImportFilesOptions = ProcessRawOptions & LoadFileOptions & {allowedExtensions?: string[]}
  70. export type ImportAssetOptions = {
  71. /**
  72. * Default = false. If true, the asset will be imported again on subsequent calls, even if it is already imported.
  73. */
  74. forceImport?: boolean,
  75. /**
  76. * If true or not specified, and any of the assets is disposed(only root objects are checked, not children), all assets will be imported in this call. If false, old assets will be returned.
  77. * Default = true.
  78. */
  79. reimportDisposed?: boolean,
  80. /**
  81. * Path override to use for the asset. This will be used in the importer as override to path inside the asset/cached asset.
  82. */
  83. pathOverride?: string,
  84. /**
  85. * Mime type to use when importing the file, if not specified, it will be determined from the file extension.
  86. */
  87. mimeType?: string,
  88. /**
  89. * Pass a custom file to use for the import. This will be used in the importer, and nothing will be fetched from the path
  90. */
  91. importedFile?: IFile,
  92. } & ProcessRawOptions & LoadFileOptions & AnyOptions
  93. export type IAssetImporterEventTypes = 'onLoad' | 'onProgress' | 'onStop' | 'onError' | 'onStart' | 'loaderCreate' | 'importFile' | 'importFiles' | 'processRaw' | 'processRawStart'
  94. export interface IAssetImporter extends EventDispatcher<BaseEvent, IAssetImporterEventTypes>, IDisposable {
  95. readonly loadingManager: LoadingManager
  96. readonly cachedAssets: IAsset[]
  97. /**
  98. * Import single or multiple assets(like in case of zip files) from a path(url) or an {@link IAsset}.
  99. * @param assetOrPath - The path or asset to import
  100. * @param options - Options for the import
  101. */
  102. import<T extends ImportResult = ImportResult>(assetOrPath?: IAsset | string, options?: ImportAssetOptions): Promise<(T|undefined)[]>;
  103. /**
  104. * Import a single asset from a path(url) or an {@link IAsset}.
  105. * @param asset
  106. * @param options
  107. */
  108. importSingle<T extends ImportResult = ImportResult>(asset?: IAsset | string, options?: ImportAssetOptions): Promise<T|undefined>;
  109. /**
  110. * Import multiple local files/blobs from a map of files.
  111. * @param files
  112. * @param options
  113. */
  114. importFiles(files: Map<string, IFile>, options?: ImportFilesOptions): Promise<Map<string, any[]> | undefined>;
  115. /**
  116. * Register a file to a specific path, so this file will be used when importing the path.
  117. * @param path
  118. * @param file
  119. */
  120. registerFile(path: string, file?: IFile): ILoader | undefined;
  121. /**
  122. * Unregister a file from a specific path.
  123. * @param path
  124. */
  125. unregisterFile(path: string): void;
  126. /**
  127. * Process the raw output from the loaders and return the updated/patched-objects.
  128. * @param res
  129. * @param options
  130. */
  131. processRaw(res: any, options: ProcessRawOptions): Promise<any[]>
  132. }