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

Rename IExportParser to IExportWriter

master
Palash Bansal 1 год назад
Родитель
Сommit
25547281b0
Аккаунт пользователя с таким Email не найден

+ 2
- 2
plugins/gltf-transform/src/GLTFDracoExporter.ts Просмотреть файл

@@ -14,14 +14,14 @@ import {
} from '@gltf-transform/core'
import {EncoderOptions} from '@gltf-transform/extensions/dist/khr-draco-mesh-compression/encoder'
import {ALL_EXTENSIONS, KHRDracoMeshCompression} from '@gltf-transform/extensions'
import {DRACOLoader2, GLTFExporter2, GLTFExporter2Options, GLTFViewerConfigExtension, IExportParser} from 'threepipe'
import {DRACOLoader2, GLTFExporter2, GLTFExporter2Options, GLTFViewerConfigExtension, IExportWriter} from 'threepipe'

/**
* GLTF Draco Exporter
*
* Extension of GLTFExporter2 that runs the output through gltf-transform for draco compression.
*/
export class GLTFDracoExporter extends GLTFExporter2 implements IExportParser {
export class GLTFDracoExporter extends GLTFExporter2 implements IExportWriter {
public loader?: DRACOLoader2 // required for loading draco libs.
private _io: WebIO
private _loadedLibs = false

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

@@ -1,11 +1,11 @@
import {EventDispatcher, WebGLRenderTarget} from 'three'
import {IMaterial, IObject3D, ITexture} from '../core'
import {BlobExt, ExportFileOptions, IAssetExporter, IExporter, IExportParser} from './IExporter'
import {BlobExt, ExportFileOptions, IAssetExporter, IExporter, IExportWriter} from './IExporter'
import {EXRExporter2, SimpleJSONExporter, SimpleTextExporter} from './export'
import {IRenderTarget} from '../rendering'

export interface AssetExporterEventMap {
exporterCreate: {exporter: IExporter, parser: IExportParser}
exporterCreate: {exporter: IExporter, parser: IExportWriter} // todo rename parser to writer
exportFile: {
obj: IObject3D|IMaterial|ITexture|IRenderTarget,
state: 'processing'|'exporting'|'done'|'error',
@@ -94,7 +94,7 @@ export class AssetExporter extends EventDispatcher<AssetExporterEventMap> implem
}
if (processed.blob) res = processed.blob
else {
const parser = this._getParser(ext)
const parser = this._getWriter(ext)

this.dispatchEvent({type: 'exportFile', obj, state:'exporting', exportOptions: options})
res = await parser.parseAsync(processed.obj, {exportExt: processed.ext ?? ext, ...options}) as BlobExt
@@ -116,19 +116,19 @@ export class AssetExporter extends EventDispatcher<AssetExporterEventMap> implem
return res
}

private _createParser(ext: string): IExportParser {
private _createParser(ext: string): IExportWriter {
const exporter = this.exporters.find(e => e.ext.includes(ext))
if (!exporter)
throw new Error(`No exporter found for extension ${ext}`)
const parser = exporter?.ctor(this, exporter)
if (!parser) throw new Error(`Unable to create parser for extension ${ext}`)
this._cachedParsers.push({ext: exporter.ext, parser})
this._cachedWriters.push({ext: exporter.ext, parser})
this.dispatchEvent({type: 'exporterCreate', exporter, parser})
return parser
}
private _cachedParsers: {parser: IExportParser, ext: string[]}[] = []
private _getParser(ext: string): IExportParser {
return this._cachedParsers.find(e => e.ext.includes(ext))?.parser ?? this._createParser(ext)
private _cachedWriters: {parser: IExportWriter, ext: string[]}[] = []
private _getWriter(ext: string): IExportWriter {
return this._cachedWriters.find(e => e.ext.includes(ext))?.parser ?? this._createParser(ext)
}

public async processBeforeExport(obj: IObject3D|IMaterial|ITexture|IRenderTarget, options: ExportFileOptions = {}): Promise<{obj:any, ext:string, typeExt?:string, blob?: BlobExt}|undefined> {

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

@@ -4,14 +4,14 @@ import {GLTFExporter2Options} from './export/GLTFExporter2'

export type BlobExt = Blob&{ext:string}

export interface IExportParser {
export interface IExportWriter {
// parse(obj: any, options: AnyOptions): any;
parseAsync(obj: any, options: AnyOptions): Promise<Blob>
}
export interface IExporter {
extensions?: any[]
ext: string[];
ctor: (assetExporter: IAssetExporter, exporter: IExporter)=>IExportParser|undefined;
ctor: (assetExporter: IAssetExporter, exporter: IExporter)=>IExportWriter|undefined;
}

export type ExportFileOptions = {

+ 2
- 2
src/assetmanager/export/EXRExporter2.ts Просмотреть файл

@@ -1,9 +1,9 @@
import {DataTexture, WebGLRenderTarget} from 'three'
import {EXRExporter, EXRExporterParseOptions} from 'three/examples/jsm/exporters/EXRExporter.js'
import {IExportParser} from '../IExporter'
import {IExportWriter} from '../IExporter'
import {IRenderTarget} from '../../rendering'

export class EXRExporter2 extends EXRExporter implements IExportParser {
export class EXRExporter2 extends EXRExporter implements IExportWriter {
async parseAsync(obj: IRenderTarget|DataTexture, options: EXRExporterParseOptions): Promise<Blob> {
const target = <IRenderTarget>obj
if (target.isWebGLRenderTarget && !target.renderManager) throw new Error('No renderManager on renderTarget')

+ 2
- 2
src/assetmanager/export/GLTFExporter2.ts Просмотреть файл

@@ -1,5 +1,5 @@
import {GLTFExporter, GLTFExporterPlugin} from 'three/examples/jsm/exporters/GLTFExporter.js'
import {IExportParser} from '../IExporter'
import {IExportWriter} from '../IExporter'
import {GLTFWriter2} from './GLTFWriter2'
import {AnimationClip, Object3D} from 'three'
import {ThreeViewer} from '../../viewer'
@@ -109,7 +109,7 @@ export interface GLTFExporter2Options {
[key: string]: any
}

export class GLTFExporter2 extends GLTFExporter implements IExportParser {
export class GLTFExporter2 extends GLTFExporter implements IExportWriter {

constructor() {
super()

+ 2
- 2
src/assetmanager/export/SimpleJSONExporter.ts Просмотреть файл

@@ -1,6 +1,6 @@
import {IExportParser} from '../IExporter'
import {IExportWriter} from '../IExporter'

export class SimpleJSONExporter implements IExportParser {
export class SimpleJSONExporter implements IExportWriter {
async parseAsync(obj: any, {jsonSpaces = 2}): Promise<Blob> {
return new Blob([JSON.stringify(obj, null, jsonSpaces)], {type: 'application/json'})
}

+ 2
- 2
src/assetmanager/export/SimpleTextExporter.ts Просмотреть файл

@@ -1,7 +1,7 @@
import {IExportParser} from '../IExporter'
import {IExportWriter} from '../IExporter'
import {AnyOptions} from 'ts-browser-helpers'

export class SimpleTextExporter implements IExportParser {
export class SimpleTextExporter implements IExportWriter {
async parseAsync(obj: any, _: AnyOptions): Promise<Blob> {
return new Blob([obj], {type: 'text/plain'})
}

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

@@ -6,7 +6,7 @@ export {MaterialManager} from './MaterialManager'
export type {AssetManagerOptions, AddRawOptions, ImportAddOptions, AddAssetOptions} from './AssetManager'
export type {IAsset, IFile, IAssetID, IAssetList} from './IAsset'
export type {ImportResult, IImportResultUserData, ImportResultObject, IAssetImporter, IAssetImporterEventMap, ImportAssetOptions, ImportFilesOptions, LoadFileOptions, ProcessRawOptions, RootSceneImportResult, ImportResultExtras} from './IAssetImporter'
export type {IAssetExporter, IExporter, IExportParser, ExportFileOptions, BlobExt} from './IExporter'
export type {IAssetExporter, IExporter, IExportWriter, ExportFileOptions, BlobExt} from './IExporter'
export type {IImporter, ILoader} from './IImporter'

export * from './import/index'

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