chore(): cargo fmt & co

This commit is contained in:
kaosat.dev 2024-03-13 12:15:53 +01:00
parent ddc17ed2c3
commit 877c29b63c
6 changed files with 96 additions and 102 deletions

View File

@ -123,7 +123,6 @@ impl Plugin for BlueprintsPlugin {
.register_type::<BlueprintsList>() .register_type::<BlueprintsList>()
.register_type::<Vec<String>>() .register_type::<Vec<String>>()
.register_type::<HashMap<String, Vec<String>>>() .register_type::<HashMap<String, Vec<String>>>()
.insert_resource(BluePrintsConfig { .insert_resource(BluePrintsConfig {
format: self.format, format: self.format,
library_folder: self.library_folder.clone(), library_folder: self.library_folder.clone(),
@ -148,22 +147,17 @@ impl Plugin for BlueprintsPlugin {
prepare_blueprints, prepare_blueprints,
check_for_loaded, check_for_loaded,
spawn_from_blueprints, spawn_from_blueprints,
apply_deferred apply_deferred,
) )
.chain(), .chain(),
( (compute_scene_aabbs, apply_deferred)
compute_scene_aabbs,
apply_deferred
)
.chain() .chain()
.run_if(aabbs_enabled), .run_if(aabbs_enabled),
apply_deferred, apply_deferred,
( (
materials_inject, materials_inject,
check_for_material_loaded, check_for_material_loaded,
materials_inject2 materials_inject2,
) )
.chain() .chain()
.run_if(materials_library_enabled), .run_if(materials_library_enabled),

View File

@ -3,7 +3,11 @@ use std::path::Path;
use bevy::{ use bevy::{
asset::{AssetId, AssetServer, Assets, Handle}, asset::{AssetId, AssetServer, Assets, Handle},
ecs::{ ecs::{
component::Component, entity::Entity, query::{Added, With}, reflect::ReflectComponent, system::{Commands, Query, Res, ResMut} component::Component,
entity::Entity,
query::{Added, With},
reflect::ReflectComponent,
system::{Commands, Query, Res, ResMut},
}, },
gltf::Gltf, gltf::Gltf,
hierarchy::{Children, Parent}, hierarchy::{Children, Parent},
@ -59,7 +63,6 @@ pub(crate) fn materials_inject(
commands commands
.entity(entity) .entity(entity)
.insert(BlueprintMaterialAssetsLoaded); .insert(BlueprintMaterialAssetsLoaded);
} else { } else {
let material_file_handle: Handle<Gltf> = asset_server.load(materials_path.clone()); let material_file_handle: Handle<Gltf> = asset_server.load(materials_path.clone());
let material_file_id = material_file_handle.id(); let material_file_id = material_file_handle.id();
@ -69,15 +72,14 @@ pub(crate) fn materials_inject(
name: material_full_path, name: material_full_path,
id: material_file_id, id: material_file_id,
loaded: false, loaded: false,
handle: material_file_handle.clone() handle: material_file_handle.clone(),
}); });
commands commands
.entity(entity) .entity(entity)
.insert(AssetsToLoad { .insert(AssetsToLoad {
all_loaded: false, all_loaded: false,
asset_infos: asset_infos, asset_infos: asset_infos,
progress: 0.0 progress: 0.0, //..Default::default()
//..Default::default()
}) })
.insert(BlueprintMaterialAssetsNotLoaded); .insert(BlueprintMaterialAssetsNotLoaded);
/**/ /**/
@ -87,7 +89,10 @@ pub(crate) fn materials_inject(
// TODO, merge with check_for_loaded, make generic ? // TODO, merge with check_for_loaded, make generic ?
pub(crate) fn check_for_material_loaded( pub(crate) fn check_for_material_loaded(
mut blueprint_assets_to_load: Query<(Entity, &mut AssetsToLoad<Gltf>),With<BlueprintMaterialAssetsNotLoaded>>, mut blueprint_assets_to_load: Query<
(Entity, &mut AssetsToLoad<Gltf>),
With<BlueprintMaterialAssetsNotLoaded>,
>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut commands: Commands, mut commands: Commands,
) { ) {
@ -110,18 +115,24 @@ pub(crate) fn check_for_material_loaded(
if all_loaded { if all_loaded {
assets_to_load.all_loaded = true; assets_to_load.all_loaded = true;
commands.entity(entity) commands
.entity(entity)
.insert(BlueprintMaterialAssetsLoaded) .insert(BlueprintMaterialAssetsLoaded)
.remove::<BlueprintMaterialAssetsNotLoaded>(); .remove::<BlueprintMaterialAssetsNotLoaded>();
} }
} }
} }
/// system that injects / replaces materials from material library /// system that injects / replaces materials from material library
pub(crate) fn materials_inject2( pub(crate) fn materials_inject2(
mut blueprints_config: ResMut<BluePrintsConfig>, mut blueprints_config: ResMut<BluePrintsConfig>,
material_infos: Query<(&MaterialInfo, &Children, ), (Added<BlueprintMaterialAssetsLoaded>, With<BlueprintMaterialAssetsLoaded>)>, material_infos: Query<
(&MaterialInfo, &Children),
(
Added<BlueprintMaterialAssetsLoaded>,
With<BlueprintMaterialAssetsLoaded>,
),
>,
with_materials_and_meshes: Query< with_materials_and_meshes: Query<
(), (),
( (

View File

@ -55,16 +55,15 @@ pub(crate) struct AssetLoadTracker<T:bevy::prelude::Asset>{
pub name: String, pub name: String,
pub id: AssetId<T>, pub id: AssetId<T>,
pub loaded: bool, pub loaded: bool,
pub handle: Handle<T> pub handle: Handle<T>,
} }
#[derive(Component, Default, Debug)] #[derive(Component, Default, Debug)]
pub(crate) struct AssetsToLoad<T: bevy::prelude::Asset> { pub(crate) struct AssetsToLoad<T: bevy::prelude::Asset> {
pub all_loaded: bool, pub all_loaded: bool,
pub asset_infos: Vec<AssetLoadTracker<T>>, pub asset_infos: Vec<AssetLoadTracker<T>>,
pub progress: f32 pub progress: f32,
} }
/// flag component /// flag component
#[derive(Component)] #[derive(Component)]
pub(crate) struct BlueprintAssetsLoaded; pub(crate) struct BlueprintAssetsLoaded;
@ -91,15 +90,8 @@ pub(crate) fn prepare_blueprints(
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
blueprints_config: Res<BluePrintsConfig>, blueprints_config: Res<BluePrintsConfig>,
) { ) {
for ( for (entity, blupeprint_name, original_parent, library_override, name, blueprints_list) in
entity, spawn_placeholders.iter()
blupeprint_name,
original_parent,
library_override,
name,
blueprints_list,
) in spawn_placeholders.iter()
{ {
debug!( debug!(
"requesting to spawn {:?} for entity {:?}, id: {:?}, parent:{:?}", "requesting to spawn {:?} for entity {:?}, id: {:?}, parent:{:?}",
@ -111,18 +103,9 @@ pub(crate) fn prepare_blueprints(
let blueprints_list = blueprints_list.unwrap(); let blueprints_list = blueprints_list.unwrap();
// println!("blueprints list {:?}", blueprints_list.0.keys()); // println!("blueprints list {:?}", blueprints_list.0.keys());
let mut asset_infos: Vec<AssetLoadTracker<Gltf>> = vec![]; let mut asset_infos: Vec<AssetLoadTracker<Gltf>> = vec![];
let library_path =
library_override.map_or_else(|| &blueprints_config.library_folder, |l| &l.0);
for (blueprint_name, _) in blueprints_list.0.iter() { for (blueprint_name, _) in blueprints_list.0.iter() {
/*if blueprint_name == what {
println!("WHOLY MOLLY !")
}*/
// println!("library path {:?}", library_path);
let mut library_path = &blueprints_config.library_folder; // TODO: we cannot use the overriden library path
// FIXME: hack
if blueprint_name == "World" {
library_path= &library_override.unwrap().0;
}
let model_file_name = format!("{}.{}", &blueprint_name, &blueprints_config.format); let model_file_name = format!("{}.{}", &blueprint_name, &blueprints_config.format);
let model_path = Path::new(&library_path).join(Path::new(model_file_name.as_str())); let model_path = Path::new(&library_path).join(Path::new(model_file_name.as_str()));
@ -134,7 +117,7 @@ pub(crate) fn prepare_blueprints(
name: model_path.to_string_lossy().into(), name: model_path.to_string_lossy().into(),
id: model_id, id: model_id,
loaded: false, loaded: false,
handle: model_handle.clone() handle: model_handle.clone(),
}) })
} }
} }
@ -145,26 +128,24 @@ pub(crate) fn prepare_blueprints(
.insert(AssetsToLoad { .insert(AssetsToLoad {
all_loaded: false, all_loaded: false,
asset_infos: asset_infos, asset_infos: asset_infos,
progress: 0.0 progress: 0.0, //..Default::default()
//..Default::default()
}) })
.insert(BlueprintAssetsNotLoaded); .insert(BlueprintAssetsNotLoaded);
} else { } else {
commands commands.entity(entity).insert(BlueprintAssetsLoaded);
.entity(entity)
.insert(BlueprintAssetsLoaded);
} }
} } else {
else { // in case there are no blueprintsList // in case there are no blueprintsList
commands commands.entity(entity).insert(BlueprintAssetsLoaded);
.entity(entity)
.insert(BlueprintAssetsLoaded);
} }
} }
} }
pub(crate) fn check_for_loaded( pub(crate) fn check_for_loaded(
mut blueprint_assets_to_load: Query<(Entity, &mut AssetsToLoad<Gltf>), With<BlueprintAssetsNotLoaded>>, mut blueprint_assets_to_load: Query<
(Entity, &mut AssetsToLoad<Gltf>),
With<BlueprintAssetsNotLoaded>,
>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut commands: Commands, mut commands: Commands,
) { ) {
@ -188,7 +169,8 @@ pub(crate) fn check_for_loaded(
if all_loaded { if all_loaded {
assets_to_load.all_loaded = true; assets_to_load.all_loaded = true;
commands.entity(entity) commands
.entity(entity)
.insert(BlueprintAssetsLoaded) .insert(BlueprintAssetsLoaded)
.remove::<BlueprintAssetsNotLoaded>(); .remove::<BlueprintAssetsNotLoaded>();
} }
@ -206,7 +188,11 @@ pub(crate) fn spawn_from_blueprints(
Option<&AddToGameWorld>, Option<&AddToGameWorld>,
Option<&Name>, Option<&Name>,
), ),
(With<BlueprintAssetsLoaded>, Added<BlueprintAssetsLoaded>, Without<BlueprintAssetsNotLoaded>), (
With<BlueprintAssetsLoaded>,
Added<BlueprintAssetsLoaded>,
Without<BlueprintAssetsNotLoaded>,
),
>, >,
mut commands: Commands, mut commands: Commands,
@ -218,7 +204,6 @@ pub(crate) fn spawn_from_blueprints(
children: Query<&Children>, children: Query<&Children>,
) { ) {
for ( for (
entity, entity,
blupeprint_name, blupeprint_name,
@ -227,7 +212,6 @@ pub(crate) fn spawn_from_blueprints(
library_override, library_override,
add_to_world, add_to_world,
name, name,
) in spawn_placeholders.iter() ) in spawn_placeholders.iter()
{ {
info!( info!(

View File

@ -7,7 +7,10 @@ use bevy::scene::SceneInstance;
use super::{AnimationPlayerLink, Animations}; use super::{AnimationPlayerLink, Animations};
use super::{SpawnHere, Spawned}; use super::{SpawnHere, Spawned};
use crate::{AssetsToLoad, BlueprintAssetsLoaded, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren}; use crate::{
AssetsToLoad, BlueprintAssetsLoaded, CopyComponents, InBlueprint, NoInBlueprint,
OriginalChildren,
};
/// this system is in charge of doing any necessary post processing after a blueprint scene has been spawned /// this system is in charge of doing any necessary post processing after a blueprint scene has been spawned
/// - it removes one level of useless nesting /// - it removes one level of useless nesting

View File

@ -1,5 +1,7 @@
use bevy::{prelude::*, utils::hashbrown::HashMap}; use bevy::{prelude::*, utils::hashbrown::HashMap};
use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, BlueprintsList, GameWorldTag, Library, SpawnHere}; use bevy_gltf_blueprints::{
BluePrintBundle, BlueprintName, BlueprintsList, GameWorldTag, Library, SpawnHere,
};
use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning}; use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning};
use bevy_rapier3d::prelude::Velocity; use bevy_rapier3d::prelude::Velocity;