bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.75k stars 3.54k forks source link

Allow AssetServer load from internet url #5061

Open takkuumi opened 2 years ago

takkuumi commented 2 years ago

What solution would you like?

impl Material for CustomMaterial {
  // When creating a custom material, you need to define either a vertex shader, a fragment shader or both.
  // If you don't define one of them it will use the default mesh shader which can be found at
  // <https://github.com/bevyengine/bevy/blob/latest/crates/bevy_pbr/src/render/mesh.wgsl>

  // For this example we don't need a vertex shader
  // fn vertex_shader(asset_server: &AssetServer) -> Option<Handle<Shader>> {
  //     // Use the same path as the fragment shader since wgsl let's you define both shader in the same file
  //     Some(asset_server.load("shaders/custom_material.wgsl"))
  // }

  fn fragment_shader(asset_server: &AssetServer) -> Option<Handle<Shader>> {
    Some(asset_server.get("https://xxx/x.wgsl"))
  }

 //...
}
mockersf commented 2 years ago

For now, there is at least one third party plug-in providing that feature. You can check assets plugins at https://bevyengine.org/assets/#asset-loading

LikeLakers2 commented 1 year ago

Hi there.

I too assumed that you couldn't build a asset plugin that takes a URL. After all, AssetPath.path() returns a &Path, and AssetIo's various methods all take &Paths.

It turns out that bevy_web_asset takes advantage of how std::path::Path is implemented - in that it can hold pretty much anything a String can. This isn't very intuitive - after all, std::path::Path is meant for filesystem paths, not as another means of holding a String!

So if I could offer up a suggestion... Perhaps AssetPath and AssetIo could provide/take &strs rather than &Paths. While this would mean that an AssetIo has to do a little extra work to convert the given path by itself (i.e. to a std::path::Path), it would also make it more intuitive that an AssetIo can be given any format of path, not just a filesystem-like one.

Thoughts?

simbleau commented 2 weeks ago

A big gotcha is a URL like asset.svg?version=abc won't work since the ?version=... at the end counts for the asset extension. Thus, an asset loader with the svg extension won't load this one.