瀏覽代碼

Add path to processRawStart and processRawEnd event in AssetImporter

master
Palash Bansal 2 年之前
父節點
當前提交
b992834ff5
No account linked to committer's email address
共有 1 個文件被更改,包括 15 次插入13 次删除
  1. 15
    13
      src/assetmanager/AssetImporter.ts

+ 15
- 13
src/assetmanager/AssetImporter.ts 查看文件

if (!result && asset?.preImportedRaw) { if (!result && asset?.preImportedRaw) {
result = await asset.preImportedRaw result = await asset.preImportedRaw
} }

const path = options.pathOverride || asset.path
// console.log(result) // console.log(result)
if (!options.forceImport && result) { if (!options.forceImport && result) {
const results = await this.processRaw<T>(result, options) // just in case its not processed. Internal check is done to ensure it's not processed twice
const results = await this.processRaw<T>(result, options, path) // just in case its not processed. Internal check is done to ensure it's not processed twice
// let isDisposed = false // if any of the objects is disposed // let isDisposed = false // if any of the objects is disposed
// for (const r of results) { // for (const r of results) {
// // todo: check if this is still required. // // todo: check if this is still required.
} }


// todo: add support to get cloned asset? if we want to import multiple times and everytime return a cloned asset // todo: add support to get cloned asset? if we want to import multiple times and everytime return a cloned asset
asset.preImportedRaw = this._loadFile(options.pathOverride || asset.path, typeof asset.file?.arrayBuffer === 'function' ? asset.file : undefined, options, onDownloadProgress)
asset.preImportedRaw = this._loadFile(path, typeof asset.file?.arrayBuffer === 'function' ? asset.file : undefined, options, onDownloadProgress)
result = await asset.preImportedRaw result = await asset.preImportedRaw


if (result) result = await this.processRaw(result, options)
if (result) result = await this.processRaw(result, options, path)
if (result) { if (result) {
if (options.processRaw !== false) asset.preImported = result if (options.processRaw !== false) asset.preImported = result


if (baseFiles.length > 0) { if (baseFiles.length > 0) {
for (const value of baseFiles) { for (const value of baseFiles) {
let res = await this._loadFile(value, undefined, options) let res = await this._loadFile(value, undefined, options)
if (res) res = await this.processRaw(res, options)
if (res) res = await this.processRaw(res, options, value)
loaded.set(value, res) loaded.set(value, res)
} }
} else { } else {
for (const value of altFiles) { for (const value of altFiles) {
let res = await this._loadFile(value, undefined, options) let res = await this._loadFile(value, undefined, options)
if (res) res = await this.processRaw(res, options)
if (res) res = await this.processRaw(res, options, value)
loaded.set(value, res) loaded.set(value, res)
} }




// region processRaw // region processRaw


public async processRaw<T extends (ImportResult|undefined) = ImportResult>(res: T|T[], options: ProcessRawOptions): Promise<T[]> {
public async processRaw<T extends (ImportResult|undefined) = ImportResult>(res: T|T[], options: ProcessRawOptions, path?: string): Promise<T[]> {
if (!res) return [] if (!res) return []


// legacy // legacy
if (Array.isArray(res)) { if (Array.isArray(res)) {
const r: any[] = [] const r: any[] = []
for (const re of res) { // todo: can we parallelize? for (const re of res) { // todo: can we parallelize?
r.push(...await this.processRaw(re, options))
r.push(...await this.processRaw(re, options, path))
} }
return r return r
} }


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, path})


// for testing only // for testing only
if (res.isTexture && options._testDataTextureComplete) { if (res.isTexture && options._testDataTextureComplete) {
// if (res.assetType) // todo: why if? // if (res.assetType) // todo: why if?
res.assetImporterProcessed = true // this should not be put in userData res.assetImporterProcessed = true // this should not be put in userData


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


// special for zip files. ZipLoader gives this // special for zip files. ZipLoader gives this
if ((<any>res) instanceof Map && options.autoImportZipContents !== false) { if ((<any>res) instanceof Map && options.autoImportZipContents !== false) {


} }


public async processRawSingle<T extends (ImportResult|undefined) = ImportResult>(res: T, options: ProcessRawOptions): Promise<T> {
return (await this.processRaw(res, options))[0]
public async processRawSingle<T extends (ImportResult|undefined) = ImportResult>(res: T, options: ProcessRawOptions, path?: string): Promise<T> {
return (await this.processRaw(res, options, path))[0]
} }


// endregion // endregion
* @param res * @param res
* @param options * @param options
*/ */
public async processImported(res: any, options: ProcessRawOptions): Promise<any[]> {
public async processImported(res: any, options: ProcessRawOptions, path?: string): Promise<any[]> {
console.error('processImported is deprecated. Use processRaw instead.') console.error('processImported is deprecated. Use processRaw instead.')
return await this.processRaw(res, options)
return await this.processRaw(res, options, path)
} }


// endregion // endregion

Loading…
取消
儲存