Giter Club home page Giter Club logo

bevy_web_asset's Introduction

Bevy Web Asset

crates.io MIT/Apache 2.0 crates.io docs.rs

This is a tiny crate that that adds the ability to load assets from http and https urls.

Supports both wasm (web-sys) and native.

This is nice if you want to keep your content on a server, even when developing native games. Use cases can be:

  • Tuning game balance post-launch
  • Seasonal events (halloween theme etc.)
  • Downloading dynamic content from 3rd party services (lospec, gltf repositories etc.)
  • Sharing user-created assets/mods over some service (level editor etc.)
  • Keeping initial download size small
  • Testing with different online assets during development

Usage

NOTE: You need to add the plugin before AssetPlugin:

use bevy::prelude::*;
use bevy_web_asset::WebAssetPlugin;

fn main() {
    App::new()
        // The `WebAssetPlugin` must be inserted before the `AssetPlugin`
        .add_plugins((
            WebAssetPlugin::default(),
            DefaultPlugins
        ))
        // ...
        .run();
}

But using it is quite simple, just use http urls instead of regular asset paths.

let font: Handle<Font> = asset_server.load("https://example.com/fonts/quicksand-light.ttf");

Or:

commands.spawn(SpriteBundle {
    // Simply use a url where you would normally use an asset folder relative path
    texture: asset_server.load("https://johanhelsing.studio/assets/favicon.png"),
    ..default()
});

Bevy version support

I intend to support the latest bevy release in the main branch.

bevy bevy_web_asset
0.13 0.8, main
0.12 0.7
0.9 0.5
0.8 0.4
0.7 0.3
0.6 0.2
0.5 0.1

License

bevy_web_asset is dual-licensed under either

at your option.

Contributions

PRs welcome!

bevy_web_asset's People

Contributors

johanhelsing avatar joverwey avatar sbesh91 avatar voidentente avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bevy_web_asset's Issues

Error when fetching images on V0.7

I've got a weird double image fetching error going on locally. Building for wasm and testing in firefox on M1.

Hey, here's the screenshot of what I'm seeing.
image
Essentially it looks like there's a second request getting kicked off that will always take any url and append .meta on the end.
someurl.jpg -> someurl.jpg.meta

Going forward with Bevy 0.12

Bevy 0.12 adds native support for remote asset sources, making most code here redundant.
Will bevy_web_asset become a legacy crate, or will it provide boilerplate implementations for http/https?

app.register_asset_source("http", ..);
app.register_asset_source("https", ..);

Handle http error codes

Currently, if the response is a http error, we just blindly pass the payload on to the asset loader, which will most likely fail.

On certain http error codes it probably makes sense to retry, on others it probably makes sense to log a warning/error and return and AssetIoError.

Split from: #4
Related to: #6

Doesn't build on stable rust

bevy_web_asset main↑1 cargo run --example web_image
    Blocking waiting for file lock on build directory
   Compiling proc-macro2 v1.0.78
   Compiling thiserror v1.0.57
   Compiling num-traits v0.2.18
   Compiling aho-corasick v1.1.2
   Compiling windows v0.52.0
   Compiling crc32fast v1.4.0
   Compiling khronos-egl v6.0.0
   Compiling miniz_oxide v0.7.2
   Compiling profiling v1.0.15
   Compiling ring v0.16.20
   Compiling fdeflate v0.3.4
   Compiling blake3 v1.5.0
   Compiling polling v2.8.0
   Compiling rustix v0.37.27
   Compiling anyhow v1.0.80
   Compiling accesskit_consumer v0.16.1
error[E0554]: `#![feature]` may not be used on the stable release channel
   --> C:\Users\Johan\.cargo\registry\src\index.crates.io-6f17d22bba15001f\rustix-0.37.27\src\lib.rs:101:26
    |
101 | #![cfg_attr(rustc_attrs, feature(rustc_attrs))]
    |                          ^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `rustix` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

android support

isahc is not easily usable on android, because it always uses openssl and doesn't have a published version that can opt-out of that (sagebind/isahc#199).

I read #18 (comment), but it's not clear to me why isahc was preferred over surf, when both appear to not have the issue with loading some urls.

I can do the work and switch back to surf (and set it up so it works with rustls) if that is ok with y'all

Warn and retry when the server can't be reached

When the user has a poor connection and the server can't be reached, we just warn and report the asset as AssetIoError::NotFound.

However, it probably makes sense to retry if we couldn't reach the server.

We should probably add a loop inside WebAssetIo::load_path to retry in those cases.

Split from: #4

IoTaskPool resource not found in browser

Got: panicked at 'IoTaskPool resource not found'.

Anyone seen this error before? I'm on bevy 0.7 at the moment (waiting a bit longer to upgrade to 0.8).

Is there some additional setup to do for wasm given things are a tad different on the browser?

ocasional panic

The unwrap here is causing a panic occasionally:

let resp_value = JsFuture::from(window.fetch_with_str(uri)).await.unwrap();

panicked at 'called `Result::unwrap()` on an `Err` value: JsValue(TypeError: NetworkError when attempting to fetch resource.
)', /home/gilescope/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_web_asset-0.4.0/src/web_asset_io.rs:26:83

WASM Issues for Images

When trying to load an Image in a WASM game following error is output to the console

WARN C:\Users\Jay\.cargo\registry\src\github.com-1ecc6299db9ec823\bevy_asset-0.9.1\src\asset_server.rs:454 encountered an error while loading an asset: Error reading image file https://i.pinimg.com/originals/b5/41/b3/b541b339d5fee0af74e95d3fe7bbf038.png: failed to load an image: Format error decoding Png: Unexpected end of data before image end., this is an error in `bevy_render`.

Trouble loading assets from localhost while doing development

I've been working with this library using an image pulled from S3 as a testing URL.

This image parses in just fine, but I'm running into an asset path parsing error when sending in a url that contains a port.

Ideally, I'd like to use pre-signed urls from S3 and that would look something like this.

The error I'm seeing so far looks like this.

/bevy_asset-0.12.1/src/path.rs:104:37: called `Result::unwrap()` on an `Err` value: InvalidSourceSyntax

I tracked down where I think this is being thrown to the while loop that parses paths looking for :. Since there is a second : in the url containing a path, it seems to throw that InvalidSourceSyntax error.

    while let Some((index, char)) = chars.next() {
          match char {
              ':' => {
                  let (_, char) = chars
                      .next()
                      .ok_or(ParseAssetPathError::InvalidSourceSyntax)?;
                  if char != '/' {
                      return Err(ParseAssetPathError::InvalidSourceSyntax);
                  }
                  let (index, char) = chars
                      .next()
                      .ok_or(ParseAssetPathError::InvalidSourceSyntax)?;
                  if char != '/' {
                      return Err(ParseAssetPathError::InvalidSourceSyntax);
                  }
                  source_range = Some(0..index - 2);
                  path_range.start = index + 1;
              }
              '#' => {
                  path_range.end = index;
                  label_range = Some(index + 1..asset_path.len());
                  break;
              }
              _ => {}
          }
      }

MIT License

Hi, do you mind adding a permissive license like MIT / Apache?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.