Skip to content

Feature: Upstream bevy_web_asset, allowing assets loaded via http #16307

Open
@mrchantey

Description

@mrchantey

What problem does this solve or what need does it fill?

Being able to load assets from http and https urls.
This is particulary relevant for examples, files that are too big for source control are often stored in external zip files requiring awkward download & extract workflows for people just getting started with a crate.
It also makes both wasm and native binaries more portable, as the additional 'assets' folder isnt required to always be placed alongside them, a big win for game jams etc.

What solution would you like?

For url assets to 'just work', meaning if a path starts with http/https the asset will be loaded via the http client:

# intercepted by http client
asset_server.load("http://example.com/fox.glb");
# https also accepted
asset_server.load("https://example.com/fox.glb");
# load normally
asset_server.load("/fox.glb");

What alternative(s) have you considered?

Keep this as a third party crate

Pros:

  • No changes/maintenance needed for bevy core

Cons:

  • Bevy examples face same pain point mentioned above
  • No blessed solution for this issue in ecosystem crates

Additional context

Considerations

  • Disk Caching: Browsers usually quietly (and unpredictably) cache files on disk so that they arent fetched on every reload, we will need something similar for native builds, and possibly a more predictable implementation on wasm builds, for example using IndexedDB.
  • Choice of HTTP client: It makes sense to go with the same client used elsewhere in Bevy, ie bevy_remote, unless it is missing some critical feature.
  • Feature Flags: Because this adds a http client to bevy_asset it should be behind a feature flag, we will need to decide whether this is to be included by default, in my opinion it should be.
  • CORS: files fetched by native builds dont need cors enabled but it will be required for wasm builds to work, this creates an inconsistency that we may want to flag on native builds if the headers are not present.
  • Work: @johanhelsing has mentioned that they dont have the capacity to work on this at the moment. I'm happy to get the ball rolling when I get some time, though this will be my most contraversial PR so I may need some mentorship.

bevy_web_asset is a tiny crate, with <250 lines of code. I guess the most work required here will be a caching solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-ContentiousThere are nontrivial implications that should be thought through

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions