Skip to content

Commit

Permalink
Added ObjectLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed Jun 27, 2020
1 parent eb24625 commit e32baa8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/threeGraphics/src/plugins/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import {
SVGResult,
RGBAFormat,
FileLoader,
ImageLoader
ImageLoader,
ObjectLoader
} from '@enable3d/three-wrapper/dist/index'

export default class Loaders {
private _fileLoader: FileLoader
private _imgLoader: ImageLoader
private _svgLoader: SVGLoader
private _textureLoader: TextureLoader
private _objectLoader: ObjectLoader
private _gltfLoader: GLTFLoader
private _fbxLoader: FBXLoader

Expand All @@ -45,6 +47,10 @@ export default class Loaders {
if (!this._textureLoader) this._textureLoader = new TextureLoader()
return this._textureLoader
}
private get objectLoader() {
if (!this._objectLoader) this._objectLoader = new ObjectLoader()
return this._objectLoader
}
private get gltfLoader() {
if (!this._gltfLoader) this._gltfLoader = new GLTFLoader()
return this._gltfLoader
Expand Down Expand Up @@ -113,6 +119,18 @@ export default class Loaders {
})
}

// examples: https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4
public object(url: string): Promise<any> {
const key = this.cache.get(url)
url = key ? key : url

return new Promise(resolve => {
this.objectLoader.load(url, (json: any) => {
resolve(json)
})
})
}

public gltf(url: string): Promise<GLTF> {
const key = this.cache.get(url)
url = key ? key : url
Expand Down

0 comments on commit e32baa8

Please sign in to comment.