From 37f4514b31d4a555f6dfc72d529b27b2939a4dca Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Sat, 8 Jun 2024 11:55:01 +0200 Subject: [PATCH] feat(bevy_gltf_blueprints): added new experimental asset structs * also started moving code to a new "assets" mod in preparartion for bigger changes --- crates/bevy_gltf_blueprints/src/assets.rs | 65 +++++++++++++++++++ crates/bevy_gltf_blueprints/src/lib.rs | 12 ++++ .../src/spawn_from_blueprints.rs | 47 ++------------ 3 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 crates/bevy_gltf_blueprints/src/assets.rs diff --git a/crates/bevy_gltf_blueprints/src/assets.rs b/crates/bevy_gltf_blueprints/src/assets.rs new file mode 100644 index 0000000..8a60cba --- /dev/null +++ b/crates/bevy_gltf_blueprints/src/assets.rs @@ -0,0 +1,65 @@ +use std::path::{Path, PathBuf}; + +use bevy::{gltf::Gltf, prelude::*, utils::HashMap}; + +use crate::{BluePrintsConfig, BlueprintAnimations}; + +/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints +#[derive(Component, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct MyAsset{ + pub name: String, + pub path: String +} + +/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints +#[derive(Component, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct LocalAssets(pub Vec); + +/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints +#[derive(Component, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct AllAssets(pub Vec); + + + +/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints +#[derive(Component, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct BlueprintsList(pub HashMap>); + +/// helper component, for tracking loaded assets's loading state, id , handle etc +#[derive(Default, Debug)] +pub(crate) struct AssetLoadTracker { + #[allow(dead_code)] + pub name: String, + pub id: AssetId, + pub loaded: bool, + #[allow(dead_code)] + pub handle: Handle, +} + +/// helper component, for tracking loaded assets +#[derive(Component, Debug)] +pub(crate) struct AssetsToLoad { + pub all_loaded: bool, + pub asset_infos: Vec>, + pub progress: f32, +} +impl Default for AssetsToLoad { + fn default() -> Self { + Self { + all_loaded: Default::default(), + asset_infos: Default::default(), + progress: Default::default(), + } + } +} + +/// flag component, usually added when a blueprint is loaded +#[derive(Component)] +pub(crate) struct BlueprintAssetsLoaded; +/// flag component +#[derive(Component)] +pub(crate) struct BlueprintAssetsNotLoaded; diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index 4bb5d32..2bfd298 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -10,6 +10,9 @@ pub use animation::*; pub mod aabb; pub use aabb::*; +pub mod assets; +pub use assets::*; + pub mod materials; pub use materials::*; @@ -32,12 +35,14 @@ pub enum GltfBlueprintsSet { #[derive(Bundle)] pub struct BluePrintBundle { pub blueprint: BlueprintName, + pub blueprint_path: BlueprintPath, pub spawn_here: SpawnHere, } impl Default for BluePrintBundle { fn default() -> Self { BluePrintBundle { blueprint: BlueprintName("default".into()), + blueprint_path: BlueprintPath("".into()), spawn_here: SpawnHere, } } @@ -112,6 +117,7 @@ impl Plugin for BlueprintsPlugin { fn build(&self, app: &mut App) { app.add_plugins(ComponentsFromGltfPlugin {}) .register_type::() + .register_type::() .register_type::() .register_type::() .register_type::() @@ -124,6 +130,12 @@ impl Plugin for BlueprintsPlugin { .register_type::>>>() .add_event::() .register_type::() + .register_type::() + .register_type::>() + .register_type::>() + .register_type::() + .register_type::() + .register_type::>>() .insert_resource(BluePrintsConfig { format: self.format, diff --git a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs index 16367df..5165962 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use bevy::{gltf::Gltf, prelude::*, utils::HashMap}; -use crate::{BluePrintsConfig, BlueprintAnimations}; +use crate::{BluePrintsConfig, BlueprintAnimations, BlueprintsList, AssetLoadTracker, AssetsToLoad, BlueprintAssetsNotLoaded, BlueprintAssetsLoaded}; /// this is a flag component for our levels/game world #[derive(Component)] @@ -13,6 +13,11 @@ pub struct GameWorldTag; #[reflect(Component)] pub struct BlueprintName(pub String); +/// path component for the blueprints +#[derive(Component, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct BlueprintPath(pub String); + /// flag component needed to signify the intent to spawn a Blueprint #[derive(Component, Reflect, Default, Debug)] #[reflect(Component)] @@ -46,46 +51,6 @@ pub struct AddToGameWorld; /// helper component, just to transfer child data pub(crate) struct OriginalChildren(pub Vec); -/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints -#[derive(Component, Reflect, Default, Debug)] -#[reflect(Component)] -pub struct BlueprintsList(pub HashMap>); - -/// helper component, for tracking loaded assets's loading state, id , handle etc -#[derive(Default, Debug)] -pub(crate) struct AssetLoadTracker { - #[allow(dead_code)] - pub name: String, - pub id: AssetId, - pub loaded: bool, - #[allow(dead_code)] - pub handle: Handle, -} - -/// helper component, for tracking loaded assets -#[derive(Component, Debug)] -pub(crate) struct AssetsToLoad { - pub all_loaded: bool, - pub asset_infos: Vec>, - pub progress: f32, -} -impl Default for AssetsToLoad { - fn default() -> Self { - Self { - all_loaded: Default::default(), - asset_infos: Default::default(), - progress: Default::default(), - } - } -} - -/// flag component, usually added when a blueprint is loaded -#[derive(Component)] -pub(crate) struct BlueprintAssetsLoaded; -/// flag component -#[derive(Component)] -pub(crate) struct BlueprintAssetsNotLoaded; - /// spawning prepare function, /// * also takes into account the already exisiting "override" components, ie "override components" > components from blueprint pub(crate) fn prepare_blueprints(