commit
bb156cd4df
@ -517,7 +517,10 @@ file_watcher = ["bevy_internal/file_watcher"]
|
||||
embedded_watcher = ["bevy_internal/embedded_watcher"]
|
||||
|
||||
# Enables using assets from HTTP sources
|
||||
http_source = ["bevy_internal/http_source"]
|
||||
http = ["bevy_internal/http"]
|
||||
|
||||
# Enables using assets from HTTPS sources
|
||||
https = ["bevy_internal/https"]
|
||||
|
||||
# Assets downloaded from HTTP sources are cached
|
||||
http_source_cache = ["bevy_internal/http_source_cache"]
|
||||
@ -1902,7 +1905,7 @@ wasm = false
|
||||
name = "http_source"
|
||||
path = "examples/asset/http_source.rs"
|
||||
doc-scrape-examples = true
|
||||
required-features = ["http_source"]
|
||||
required-features = ["https"]
|
||||
|
||||
[package.metadata.example.http_source]
|
||||
name = "HTTP Asset Source"
|
||||
|
@ -14,7 +14,8 @@ keywords = ["bevy"]
|
||||
file_watcher = ["notify-debouncer-full", "watch", "multi_threaded"]
|
||||
embedded_watcher = ["file_watcher"]
|
||||
multi_threaded = ["bevy_tasks/multi_threaded"]
|
||||
http_source = ["ureq"]
|
||||
http = ["ureq"]
|
||||
https = ["ureq", "ureq/rustls"]
|
||||
http_source_cache = []
|
||||
asset_processor = []
|
||||
watch = []
|
||||
@ -93,10 +94,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev", default-featu
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
notify-debouncer-full = { version = "0.5.0", default-features = false, optional = true }
|
||||
# updating ureq: while ureq is semver stable, it depends on rustls which is not, meaning unlikely but possible breaking changes on minor releases. https://github.com/bevyengine/bevy/pull/16366#issuecomment-2572890794
|
||||
ureq = { version = "3", optional = true, default-features = false, features = [
|
||||
"gzip",
|
||||
"json",
|
||||
] }
|
||||
ureq = { version = "3", optional = true, default-features = false }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
@ -2,23 +2,41 @@ use crate::io::{AssetReader, AssetReaderError, Reader};
|
||||
use crate::io::{AssetSource, PathStream};
|
||||
use crate::AssetApp;
|
||||
use alloc::boxed::Box;
|
||||
use bevy_app::App;
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_tasks::ConditionalSendFuture;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Adds the `http` and `https` asset sources to the app.
|
||||
/// Any asset path that begins with `http` or `https` will be loaded from the web
|
||||
/// via `fetch`(wasm) or `ureq`(native).
|
||||
pub fn http_source_plugin(app: &mut App) {
|
||||
///
|
||||
/// Any asset path that begins with `http` (when the `http` feature is enabled) or `https` (when the
|
||||
/// `https` feature is enabled) will be loaded from the web via `fetch`(wasm) or `ureq`(native).
|
||||
pub struct HttpSourcePlugin;
|
||||
|
||||
impl Plugin for HttpSourcePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
#[cfg(feature = "http")]
|
||||
app.register_asset_source(
|
||||
"http",
|
||||
AssetSource::build().with_reader(|| Box::new(HttpSourceAssetReader::Http)),
|
||||
AssetSource::build()
|
||||
.with_reader(|| Box::new(HttpSourceAssetReader::Http))
|
||||
.with_processed_reader(|| Box::new(HttpSourceAssetReader::Http)),
|
||||
);
|
||||
|
||||
#[cfg(feature = "https")]
|
||||
app.register_asset_source(
|
||||
"https",
|
||||
AssetSource::build().with_reader(|| Box::new(HttpSourceAssetReader::Https)),
|
||||
AssetSource::build()
|
||||
.with_reader(|| Box::new(HttpSourceAssetReader::Https))
|
||||
.with_processed_reader(|| Box::new(HttpSourceAssetReader::Https)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for HttpSourcePlugin {
|
||||
fn default() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
/// Asset reader that treats paths as urls to load assets from.
|
||||
pub enum HttpSourceAssetReader {
|
||||
|
@ -186,8 +186,8 @@ mod reflect;
|
||||
mod render_asset;
|
||||
mod server;
|
||||
|
||||
#[cfg(feature = "http_source")]
|
||||
mod http_source;
|
||||
#[cfg(any(feature = "http", feature = "https"))]
|
||||
pub mod http_source;
|
||||
|
||||
pub use assets::*;
|
||||
pub use bevy_asset_macros::Asset;
|
||||
@ -348,9 +348,6 @@ impl AssetPlugin {
|
||||
|
||||
impl Plugin for AssetPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
#[cfg(feature = "http_source")]
|
||||
app.add_plugins(http_source::http_source_plugin);
|
||||
|
||||
let embedded = EmbeddedAssetRegistry::default();
|
||||
{
|
||||
let mut sources = app
|
||||
|
@ -218,8 +218,11 @@ debug_glam_assert = ["bevy_math/debug_glam_assert"]
|
||||
|
||||
default_font = ["bevy_text?/default_font"]
|
||||
|
||||
# Enables using assets from HTTP sources
|
||||
http_source = ["bevy_asset?/http_source"]
|
||||
# Enables downloading assets from HTTP sources
|
||||
http = ["bevy_asset?/http"]
|
||||
|
||||
# Enables downloading assets from HTTPS sources
|
||||
https = ["bevy_asset?/https"]
|
||||
|
||||
# Assets downloaded from HTTP sources are cached
|
||||
http_source_cache = ["bevy_asset?/http_source_cache"]
|
||||
|
@ -21,6 +21,10 @@ plugin_group! {
|
||||
#[cfg(feature = "std")]
|
||||
#[custom(cfg(any(all(unix, not(target_os = "horizon")), windows)))]
|
||||
bevy_app:::TerminalCtrlCHandlerPlugin,
|
||||
// NOTE: Load this before AssetPlugin to properly register http asset sources.
|
||||
#[cfg(feature = "bevy_asset")]
|
||||
#[custom(cfg(any(feature = "http", feature = "https")))]
|
||||
bevy_asset::http_source:::HttpSourcePlugin,
|
||||
#[cfg(feature = "bevy_asset")]
|
||||
bevy_asset:::AssetPlugin,
|
||||
#[cfg(feature = "bevy_scene")]
|
||||
|
@ -92,7 +92,8 @@ The default feature set enables most of the expected features of a game engine,
|
||||
|glam_assert|Enable assertions to check the validity of parameters passed to glam|
|
||||
|gltf_convert_coordinates_default|Enable converting glTF coordinates to Bevy's coordinate system by default. This will be Bevy's default behavior starting in 0.18.|
|
||||
|hotpatching|Enable hotpatching of Bevy systems|
|
||||
|http_source|Enables using assets from HTTP sources|
|
||||
|http|Enables downloading assets from HTTP sources|
|
||||
|https|Enables downloading assets from HTTPS sources|
|
||||
|http_source_cache|Assets downloaded from HTTP sources are cached|
|
||||
|ico|ICO image format support|
|
||||
|jpeg|JPEG image format support|
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Example usage of the `http` asset source to load assets from the web.
|
||||
//! Example usage of the `https` asset source to load assets from the web.
|
||||
//!
|
||||
//! Run with the feature `http_source`, and optionally `http_source_cache`
|
||||
//! Run with the feature `https`, and optionally `http_source_cache`
|
||||
//! for a simple caching mechanism that never invalidates.
|
||||
//!
|
||||
use bevy::prelude::*;
|
||||
|
Loading…
Reference in New Issue
Block a user