threepipe
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

IAssetImporter.ts 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. /**
  40. * extra arbitrary data saved by the importer that can be used by the plugins (like gltf material variants)
  41. */
  42. __importData?: any
  43. /**
  44. * 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
  45. */
  46. __needsSourceBuffer?: boolean
  47. /**
  48. * Cached source buffer for the asset (only cached when __needsSourceBuffer is set)
  49. */
  50. __sourceBuffer?: ArrayBuffer
  51. /**
  52. * Cached source blob for the asset
  53. */
  54. __sourceBlob?: IFile
  55. }
  56. export type ProcessRawOptions = {
  57. /**
  58. * default = true, toggle to control the processing of the raw objects in the proecssRaw method
  59. */
  60. processRaw?: boolean,
  61. /**
  62. * default = false. If true, the importer will reprocess the imported objects, even if they are already processed.
  63. */
  64. forceImporterReprocess?: boolean,
  65. /**
  66. * internal use
  67. */
  68. rootPath?: string,
  69. /**
  70. * default = undefined, only used for textures
  71. */
  72. generateMipmaps?: boolean|undefined,
  73. /**
  74. * default = true, if true, the importer will automatically import the contents of zip files, if zip importer is registered.
  75. */
  76. autoImportZipContents?: boolean,
  77. /**
  78. * @internal
  79. * default = false, if set to true, it will test if the data textures are complete. [internal use]
  80. */
  81. _testDataTextureComplete?: boolean,
  82. /**
  83. * @deprecated use processRaw instead
  84. */
  85. processImported?: boolean, // same as processRaw
  86. } & AnyOptions
  87. export interface LoadFileOptions {
  88. fileHandler?: any, // custom {@link ILoader} for the file
  89. /**
  90. * Query string to add to the url. Default = undefined
  91. */
  92. queryString?: string,
  93. rootPath?: string, // internal use
  94. }
  95. export type ImportFilesOptions = ProcessRawOptions & LoadFileOptions & {allowedExtensions?: string[]}
  96. export type ImportAssetOptions = {
  97. /**
  98. * Default = false. If true, the asset will be imported again on subsequent calls, even if it is already imported.
  99. */
  100. forceImport?: boolean,
  101. /**
  102. * 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.
  103. * Default = true.
  104. */
  105. reimportDisposed?: boolean,
  106. /**
  107. * Path override to use for the asset. This will be used in the importer as override to path inside the asset/cached asset.
  108. */
  109. pathOverride?: string,
  110. /**
  111. * Mime type to use when importing the file, if not specified, it will be determined from the file extension.
  112. */
  113. mimeType?: string,
  114. /**
  115. * Pass a custom file to use for the import. This will be used in the importer, and nothing will be fetched from the path
  116. */
  117. importedFile?: IFile,
  118. } & ProcessRawOptions & LoadFileOptions & AnyOptions
  119. export type IAssetImporterEventTypes = 'onLoad' | 'onProgress' | 'onStop' | 'onError' | 'onStart' | 'loaderCreate' | 'importFile' | 'importFiles' | 'processRaw' | 'processRawStart'
  120. export interface IAssetImporter extends EventDispatcher<BaseEvent, IAssetImporterEventTypes>, IDisposable {
  121. readonly loadingManager: LoadingManager
  122. readonly cachedAssets: IAsset[]
  123. /**
  124. * Import single or multiple assets(like in case of zip files) from a path(url) or an {@link IAsset}.
  125. * @param assetOrPath - The path or asset to import
  126. * @param options - Options for the import
  127. */
  128. import<T extends ImportResult = ImportResult>(assetOrPath?: IAsset | string, options?: ImportAssetOptions): Promise<(T|undefined)[]>;
  129. /**
  130. * Import a single asset from a path(url) or an {@link IAsset}.
  131. * @param asset
  132. * @param options
  133. */
  134. importSingle<T extends ImportResult = ImportResult>(asset?: IAsset | string, options?: ImportAssetOptions): Promise<T|undefined>;
  135. /**
  136. * Import multiple local files/blobs from a map of files.
  137. * @param files
  138. * @param options
  139. */
  140. importFiles(files: Map<string, IFile>, options?: ImportFilesOptions): Promise<Map<string, any[]> | undefined>;
  141. /**
  142. * Register a file to a specific path, so this file will be used when importing the path.
  143. * @param path
  144. * @param file
  145. */
  146. registerFile(path: string, file?: IFile): ILoader | undefined;
  147. /**
  148. * Unregister a file from a specific path.
  149. * @param path
  150. */
  151. unregisterFile(path: string): void;
  152. /**
  153. * Process the raw output from the loaders and return the updated/patched-objects.
  154. * @param res
  155. * @param options
  156. */
  157. processRaw(res: any, options: ProcessRawOptions): Promise<any[]>
  158. }