bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust

Home Page:https://bevyengine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AssetServer.load_folder() fails in wasm while individual load() calls work

djeedai opened this issue · comments

Bevy version

0.5.0

Operating system & version

Windows 10

What you did

Build https://github.com/djeedai/libracity/tree/wasm in wasm.

cargo make serve

What you expected to happen

Can load both individual assets and entire folders when targeting wasm.

What actually happened

asset_server.load("models/file.gltf") loads fine with both wasm and native.

asset_server.load_folder("models") returns an error AssetFolderNotADirectory("models")' in wasm, but works in native.

Additional information

>rustc -V
rustc 1.55.0-nightly (150fad30e 2021-06-19)
>cargo -V
cargo 1.54.0-nightly (44456677b 2021-06-12)
>wasm-bindgen -V
wasm-bindgen 0.2.69

Loading an asset in wasm in Bevy is opinionated and is done as an http request for that file, which most servers should support out of the box.

Loading a folder would mean being able to list its content, which is even more opinionated and often blocked on servers. This doesn't work currently... as it's not even implemented in Bevy

fn read_directory(
&self,
_path: &Path,
) -> Result<Box<dyn Iterator<Item = PathBuf>>, AssetIoError> {
Ok(Box::new(std::iter::empty::<PathBuf>()))
}

Loading an asset in wasm in Bevy is opinionated and is done as an http request for that file

Do you mind developing what's opinionated here?

Loading a folder would mean being able to list its content, which is even more opinionated and often blocked on servers

I agree, I didn't think about this, obviously most server disallow listing content. I've replaced load_folder() with individual load() calls. However maybe the error returned should be more clear? Because currently AssetFolderNotADirectory which hints at a wrong path while configuring the build or deploying, whereas the actual error is it not being supported in the first place. I actually spent over a hour trying various things, changing paths, server configs, etc. until I filled that bug and replaced the call.

A warning was added in #5827, and it seems like there's not really a path forward to support load_folder on the web.

Should we close this?

@rparrett sounds good to me.

Loading an asset in wasm in Bevy is opinionated and is done as an http request for that file

Do you mind developing what's opinionated here?

Sorry, forgot to reply...

When loading an asset in wasm, Bevy does a http get request to the relative URL ./assets/path/to/asset.file. For me, this is opinionated has it uses http, and tries to load files from the same server. It could be hard to serve from a javascript blob if you want to get creative, or from a CDN or just another server for your static files, or using webdav, ...

Ah yes agreed. Well it's more than opinionated, it's very limited and should be improved, but I believe that's already planned as part of the asset work maybe? Or at least there's a Bevy architecture and third-party crates to work around that.