mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-12-23 08:04:10 +00:00
feat(bevy_gltf_blueprints): added new experimental asset structs
* also started moving code to a new "assets" mod in preparartion for bigger changes
This commit is contained in:
parent
ba25c3cb20
commit
37f4514b31
65
crates/bevy_gltf_blueprints/src/assets.rs
Normal file
65
crates/bevy_gltf_blueprints/src/assets.rs
Normal file
@ -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<MyAsset>);
|
||||
|
||||
/// 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<MyAsset>);
|
||||
|
||||
|
||||
|
||||
/// 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<String, Vec<String>>);
|
||||
|
||||
/// helper component, for tracking loaded assets's loading state, id , handle etc
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct AssetLoadTracker<T: bevy::prelude::Asset> {
|
||||
#[allow(dead_code)]
|
||||
pub name: String,
|
||||
pub id: AssetId<T>,
|
||||
pub loaded: bool,
|
||||
#[allow(dead_code)]
|
||||
pub handle: Handle<T>,
|
||||
}
|
||||
|
||||
/// helper component, for tracking loaded assets
|
||||
#[derive(Component, Debug)]
|
||||
pub(crate) struct AssetsToLoad<T: bevy::prelude::Asset> {
|
||||
pub all_loaded: bool,
|
||||
pub asset_infos: Vec<AssetLoadTracker<T>>,
|
||||
pub progress: f32,
|
||||
}
|
||||
impl<T: bevy::prelude::Asset> Default for AssetsToLoad<T> {
|
||||
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;
|
@ -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::<BlueprintName>()
|
||||
.register_type::<BlueprintPath>()
|
||||
.register_type::<MaterialInfo>()
|
||||
.register_type::<SpawnHere>()
|
||||
.register_type::<BlueprintAnimations>()
|
||||
@ -124,6 +130,12 @@ impl Plugin for BlueprintsPlugin {
|
||||
.register_type::<HashMap<String, HashMap<u32, Vec<String>>>>()
|
||||
.add_event::<AnimationMarkerReached>()
|
||||
.register_type::<BlueprintsList>()
|
||||
.register_type::<MyAsset>()
|
||||
.register_type::<Vec<MyAsset>>()
|
||||
.register_type::<Vec<String>>()
|
||||
.register_type::<LocalAssets>()
|
||||
.register_type::<AllAssets>()
|
||||
|
||||
.register_type::<HashMap<String, Vec<String>>>()
|
||||
.insert_resource(BluePrintsConfig {
|
||||
format: self.format,
|
||||
|
@ -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<Entity>);
|
||||
|
||||
/// 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<String, Vec<String>>);
|
||||
|
||||
/// helper component, for tracking loaded assets's loading state, id , handle etc
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct AssetLoadTracker<T: bevy::prelude::Asset> {
|
||||
#[allow(dead_code)]
|
||||
pub name: String,
|
||||
pub id: AssetId<T>,
|
||||
pub loaded: bool,
|
||||
#[allow(dead_code)]
|
||||
pub handle: Handle<T>,
|
||||
}
|
||||
|
||||
/// helper component, for tracking loaded assets
|
||||
#[derive(Component, Debug)]
|
||||
pub(crate) struct AssetsToLoad<T: bevy::prelude::Asset> {
|
||||
pub all_loaded: bool,
|
||||
pub asset_infos: Vec<AssetLoadTracker<T>>,
|
||||
pub progress: f32,
|
||||
}
|
||||
impl<T: bevy::prelude::Asset> Default for AssetsToLoad<T> {
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user