Просмотр исходного кода

Some doc comments, fixes

master
Palash Bansal 3 лет назад
Родитель
Сommit
501a5078b0
Аккаунт пользователя с таким Email не найден

+ 0
- 5
src/assetmanager/AssetImporter.ts Просмотреть файл

@@ -362,11 +362,6 @@ export class AssetImporter extends EventDispatcher<IAssetImporterEvent, IAssetIm

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

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

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

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

+ 28
- 8
src/assetmanager/AssetManager.ts Просмотреть файл

@@ -23,6 +23,7 @@ import {
IObject3D,
iObjectCommons,
ISceneEvent,
ITexture,
PerspectiveCamera2,
upgradeTexture,
} from '../core'
@@ -39,12 +40,29 @@ import {IExporter} from './IExporter'
import {GLTFExporter2} from './export'

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'> {
@@ -176,7 +194,7 @@ export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}
// materials: IMaterial[] = []
// 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]

for (const obj of arr) {
@@ -187,6 +205,10 @@ export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}
this.materials.registerMaterial(<IMaterial>obj)
break
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
case 'model':
case 'light':
@@ -216,7 +238,7 @@ export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}
* @param imported
* @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)
}

@@ -272,7 +294,6 @@ export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}
const viewer = this.viewer
if (!viewer) return

console.log(['mat', ...this.materials.templates.map(t=>t.typeSlug!).filter(v=>v)])
const importers: Importer[] = [
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',
@@ -426,7 +447,6 @@ export class AssetManager extends EventDispatcher<BaseEvent&{data: ImportResult}
async importConfigResources(json: any, extraResources?: any) {
if (!this.importer) throw 'Importer not initialized yet.'

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

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

+ 41
- 15
src/assetmanager/IAssetImporter.ts Просмотреть файл

@@ -44,28 +44,54 @@ export type ImportResult = ImportResultObject & ImportResultExtras
export interface IImportResultUserData{
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 = {
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

+ 1
- 1
src/assetmanager/index.ts Просмотреть файл

@@ -3,7 +3,7 @@ export {AssetExporter} from './AssetExporter'
export {AssetManager} from './AssetManager'
export {Importer} from './Importer'
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 {ImportResult, IImportResultUserData, ImportResultObject, IAssetImporter, IAssetImporterEventTypes, ImportAssetOptions, ImportFilesOptions, LoadFileOptions, ProcessRawOptions, RootSceneImportResult, ImportResultExtras} from './IAssetImporter'
export type {IAssetExporter, IExporter, IExportParser, ExportFileOptions, BlobExt} from './IExporter'

Загрузка…
Отмена
Сохранить