-
-
Notifications
You must be signed in to change notification settings - Fork 390
Closed
Labels
Description
There are lots of times where you need to pull in async dependencies on a per app or per component basis. I normally just do
const textureLoader = new THREE.TextureLoader()
const myImage = textureLoader.load('./foo.png')
and then use myImage
later in code. If it is not downloaded yet, component will show a blank black face, then suddenly get the texture. This is not ideal, I think we can make a generic module to handle loading component dependencies, and keeping track of their progress, so that a items loading bar would get automatically made and would expose a simple status()
API. Things that could be loaded are
- textures
- fonts
- sounds
- what else?
It could look something like:
import { App, LoaderModule, Box, TextureModule } from 'whs'
const loader = new LoaderModule()
const app = new App([
loader,
...
])
loader.on('change', ({ totalProgress, itemProgress, item, numItems }) => {
console.log(`${totalProgress}%: loading ${item} of ${numItems} - ${itemProgress}%`)
})
// hmm, this API needs to be discussed how to do
// I'm imagining attaching an instance of LoaderModule to modules
// and then component can somehow pull it out, the item it desires
// maybe loader.set returns the loader
const box = new Box({
material: new THREE.MeshBasicMaterial({
map: new TextureModule({
texture: (loader) => loader.get('crate')
modules: [ loader.set('crate', '/textures/crate.albedo.png' ]
})
})
box.addTo(app)
I hope my sketch gives an idea of what I'm looking for, lets discuss!
Version:
- v2.x.x
- v1.x.x
Issue type:
- Bug
- Proposal/Enhancement
- Question
Tested on:
Desktop
- Chrome
- Chrome Canary
- Chrome dev-channel
- Firefox
- Opera
- Microsoft IE
- Microsoft Edge
Android
- Chrome
- Firefox
- Opera
IOS
- Chrome
- Firefox
- Opera