瀏覽代碼

Some doc comments, fixes

master
Palash Bansal 3 年之前
父節點
當前提交
501a5078b0
沒有連結到貢獻者的電子郵件帳戶。
共有 4 個檔案被更改,包括 70 行新增29 行删除
  1. 0
    5
      src/assetmanager/AssetImporter.ts
  2. 28
    8
      src/assetmanager/AssetManager.ts
  3. 41
    15
      src/assetmanager/IAssetImporter.ts
  4. 1
    1
      src/assetmanager/index.ts

+ 0
- 5
src/assetmanager/AssetImporter.ts 查看文件



if (options.processRaw === false) return [res] if (options.processRaw === false) return [res]


// todo;
// if (res.userData?.rootSceneModelRoot) {
// options._rootSceneImported = true // used in Dropzone
// }

if (res.assetImporterProcessed && !options.forceImporterReprocess) return [res] if (res.assetImporterProcessed && !options.forceImporterReprocess) return [res]


this.dispatchEvent({type: 'processRawStart', data: res, options}) this.dispatchEvent({type: 'processRawStart', data: res, options})

+ 28
- 8
src/assetmanager/AssetManager.ts 查看文件

IObject3D, IObject3D,
iObjectCommons, iObjectCommons,
ISceneEvent, ISceneEvent,
ITexture,
PerspectiveCamera2, PerspectiveCamera2,
upgradeTexture, upgradeTexture,
} from '../core' } from '../core'
import {GLTFExporter2} from './export' import {GLTFExporter2} from './export'


export interface AssetManagerOptions{ export interface AssetManagerOptions{
simpleCache?: boolean // simple memory based cache for downloaded files, default = false
storage?: Cache | Storage // cache storage for downloaded files, can use with `caches.open` default = undefined
/**
* simple memory based cache for downloaded files, default = false
*/
simpleCache?: boolean
/**
* cache storage for downloaded files, can use with `caches.open` default = undefined
*/
storage?: Cache | Storage
} }


export type ImportAddOptions = ImportAssetOptions & AddObjectOptions
export type AddRawOptions = ProcessRawOptions & AddObjectOptions
export type AddAssetOptions = AddObjectOptions & {
/**
* Automatically set any loaded HDR, EXR file as the scene environment map
* @default true
*/
autoSetEnvironment?: boolean
/**
* Automatically set any loaded image(ITexture) file as the scene background
*/
autoSetBackground?: boolean
}
export type ImportAddOptions = ImportAssetOptions & AddAssetOptions
export type AddRawOptions = ProcessRawOptions & AddAssetOptions




export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}, 'loadAsset'> { export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}, 'loadAsset'> {
// materials: IMaterial[] = [] // materials: IMaterial[] = []
// textures: ITexture[] = [] // textures: ITexture[] = []


async loadImported<T extends ValOrArr<ImportResult|undefined> = ImportResult>(imported: T, options?: AddObjectOptions): Promise<T | never[]> {
async loadImported<T extends ValOrArr<ImportResult|undefined> = ImportResult>(imported: T, {autoSetEnvironment = true, autoSetBackground = false, ...options}: AddAssetOptions = {}): Promise<T | never[]> {
const arr: (ImportResult|undefined)[] = Array.isArray(imported) ? imported : [imported] const arr: (ImportResult|undefined)[] = Array.isArray(imported) ? imported : [imported]


for (const obj of arr) { for (const obj of arr) {
this.materials.registerMaterial(<IMaterial>obj) this.materials.registerMaterial(<IMaterial>obj)
break break
case 'texture': case 'texture':
if (autoSetEnvironment && (
obj.__rootPath?.endsWith('.hdr') || obj.__rootPath?.endsWith('.exr')
)) this.viewer.scene.environment = <ITexture>obj
if (autoSetBackground) this.viewer.scene.background = <ITexture>obj
break break
case 'model': case 'model':
case 'light': case 'light':
* @param imported * @param imported
* @param options * @param options
*/ */
async addProcessedAssets<T extends ImportResult|undefined = ImportResult>(imported: (T|undefined)[], options?: AddObjectOptions): Promise<(T | undefined)[]> {
async addProcessedAssets<T extends ImportResult|undefined = ImportResult>(imported: (T|undefined)[], options?: AddAssetOptions): Promise<(T | undefined)[]> {
return this.loadImported(imported, options) return this.loadImported(imported, options)
} }


const viewer = this.viewer const viewer = this.viewer
if (!viewer) return if (!viewer) return


console.log(['mat', ...this.materials.templates.map(t=>t.typeSlug!).filter(v=>v)])
const importers: Importer[] = [ const importers: Importer[] = [
new Importer(TextureLoader, ['webp', 'png', 'jpeg', 'jpg', 'svg', 'ico', 'data:image'], [ new Importer(TextureLoader, ['webp', 'png', 'jpeg', 'jpg', 'svg', 'ico', 'data:image'], [
'image/webp', 'image/png', 'image/jpeg', 'image/svg+xml', 'image/gif', 'image/bmp', 'image/tiff', 'image/x-icon', 'image/webp', 'image/png', 'image/jpeg', 'image/svg+xml', 'image/gif', 'image/bmp', 'image/tiff', 'image/x-icon',
async importConfigResources(json: any, extraResources?: any) { async importConfigResources(json: any, extraResources?: any) {
if (!this.importer) throw 'Importer not initialized yet.' if (!this.importer) throw 'Importer not initialized yet.'


// console.log(json)
if (json.__isLoadedResources) return json if (json.__isLoadedResources) return json


return this.viewer?.loadConfigResources(json, extraResources) return this.viewer?.loadConfigResources(json, extraResources)

+ 41
- 15
src/assetmanager/IAssetImporter.ts 查看文件

export interface IImportResultUserData{ export interface IImportResultUserData{
rootPath?: string rootPath?: string


// eslin t-disable-next-line @typescript-eslint/naming-convention
__importData?: any // extra arbitrary data saved by the importer that can be used by the plugins (like gltf material variants)
// eslin t-disable-next-line @typescript-eslint/naming-convention
__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
// eslin t-disable-next-line @typescript-eslint/naming-convention
__sourceBuffer?: ArrayBuffer // Cache d source buffer for the asset (only cached when __needsSourceBuffer is set)
// eslin t-disable-next-line @typescript-eslint/naming-convention
__sourceBlob?: IFile // Cache d source blob for the asset
/**
* extra arbitrary data saved by the importer that can be used by the plugins (like gltf material variants)
*/
__importData?: any
/**
* 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
*/
__needsSourceBuffer?: boolean
/**
* Cached source buffer for the asset (only cached when __needsSourceBuffer is set)
*/
__sourceBuffer?: ArrayBuffer
/**
* Cached source blob for the asset
*/
__sourceBlob?: IFile
} }


export type ProcessRawOptions = { export type ProcessRawOptions = {
processRaw?: boolean, // defau lt = true, toggle to control the processing of the raw objects in the proecssRaw method
forceImporterReprocess?: boolean, // defau lt = false. If true, the importer will reprocess the imported objects, even if they are already processed.
/**
* default = true, toggle to control the processing of the raw objects in the proecssRaw method
*/
processRaw?: boolean,
/**
* default = false. If true, the importer will reprocess the imported objects, even if they are already processed.
*/
forceImporterReprocess?: boolean,


rootPath?: string, // internal use
/**
* internal use
*/
rootPath?: string,


generateMipmaps?: boolean|undefined, // defau lt = undefined, only used for textures
/**
* default = undefined, only used for textures
*/
generateMipmaps?: boolean|undefined,


autoImportZipContents?: boolean, // defau lt = true, if true, the importer will automatically import the contents of zip files, if zip importer is registered.
/**
* default = true, if true, the importer will automatically import the contents of zip files, if zip importer is registered.
*/
autoImportZipContents?: boolean,


// inter nal
_testDataTextureComplete?: boolean, // defau lt = false, if set to true, it will test if the data textures are complete. [internal use]
/**
* @internal
* default = false, if set to true, it will test if the data textures are complete. [internal use]
*/
_testDataTextureComplete?: boolean,


/** /**
* @deprecated use processRaw instead * @deprecated use processRaw instead

+ 1
- 1
src/assetmanager/index.ts 查看文件

export {AssetManager} from './AssetManager' export {AssetManager} from './AssetManager'
export {Importer} from './Importer' export {Importer} from './Importer'
export {MaterialManager} from './MaterialManager' export {MaterialManager} from './MaterialManager'
export type {AssetManagerOptions, AddRawOptions, ImportAddOptions} from './AssetManager'
export type {AssetManagerOptions, AddRawOptions, ImportAddOptions, AddAssetOptions} from './AssetManager'
export type {IAsset, IFile, IAssetID, IAssetList} from './IAsset' export type {IAsset, IFile, IAssetID, IAssetList} from './IAsset'
export type {ImportResult, IImportResultUserData, ImportResultObject, IAssetImporter, IAssetImporterEventTypes, ImportAssetOptions, ImportFilesOptions, LoadFileOptions, ProcessRawOptions, RootSceneImportResult, ImportResultExtras} from './IAssetImporter' export type {ImportResult, IImportResultUserData, ImportResultObject, IAssetImporter, IAssetImporterEventTypes, ImportAssetOptions, ImportFilesOptions, LoadFileOptions, ProcessRawOptions, RootSceneImportResult, ImportResultExtras} from './IAssetImporter'
export type {IAssetExporter, IExporter, IExportParser, ExportFileOptions, BlobExt} from './IExporter' export type {IAssetExporter, IExporter, IExportParser, ExportFileOptions, BlobExt} from './IExporter'

Loading…
取消
儲存