chore(): cargo fmt & co
This commit is contained in:
parent
ddc17ed2c3
commit
877c29b63c
|
@ -122,8 +122,7 @@ impl Plugin for BlueprintsPlugin {
|
|||
.register_type::<Animations>()
|
||||
.register_type::<BlueprintsList>()
|
||||
.register_type::<Vec<String>>()
|
||||
.register_type::<HashMap<String,Vec<String>>>()
|
||||
|
||||
.register_type::<HashMap<String, Vec<String>>>()
|
||||
.insert_resource(BluePrintsConfig {
|
||||
format: self.format,
|
||||
library_folder: self.library_folder.clone(),
|
||||
|
@ -144,26 +143,21 @@ impl Plugin for BlueprintsPlugin {
|
|||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
(
|
||||
(
|
||||
prepare_blueprints,
|
||||
check_for_loaded,
|
||||
spawn_from_blueprints,
|
||||
apply_deferred
|
||||
spawn_from_blueprints,
|
||||
apply_deferred,
|
||||
)
|
||||
.chain(),
|
||||
(
|
||||
compute_scene_aabbs,
|
||||
apply_deferred
|
||||
)
|
||||
(compute_scene_aabbs, apply_deferred)
|
||||
.chain()
|
||||
.run_if(aabbs_enabled),
|
||||
|
||||
apply_deferred,
|
||||
|
||||
(
|
||||
materials_inject,
|
||||
check_for_material_loaded,
|
||||
materials_inject2
|
||||
materials_inject2,
|
||||
)
|
||||
.chain()
|
||||
.run_if(materials_library_enabled),
|
||||
|
|
|
@ -3,7 +3,11 @@ use std::path::Path;
|
|||
use bevy::{
|
||||
asset::{AssetId, AssetServer, Assets, Handle},
|
||||
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,
|
||||
hierarchy::{Children, Parent},
|
||||
|
@ -59,25 +63,23 @@ pub(crate) fn materials_inject(
|
|||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintMaterialAssetsLoaded);
|
||||
|
||||
} else {
|
||||
let material_file_handle: Handle<Gltf> = asset_server.load(materials_path.clone());
|
||||
let material_file_id = material_file_handle.id();
|
||||
let mut asset_infos:Vec<AssetLoadTracker<Gltf>> = vec![];
|
||||
let mut asset_infos: Vec<AssetLoadTracker<Gltf>> = vec![];
|
||||
|
||||
asset_infos.push(AssetLoadTracker {
|
||||
name: material_full_path,
|
||||
id: material_file_id,
|
||||
loaded: false,
|
||||
handle: material_file_handle.clone()
|
||||
handle: material_file_handle.clone(),
|
||||
});
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(AssetsToLoad{
|
||||
.insert(AssetsToLoad {
|
||||
all_loaded: false,
|
||||
asset_infos: asset_infos,
|
||||
progress: 0.0
|
||||
//..Default::default()
|
||||
progress: 0.0, //..Default::default()
|
||||
})
|
||||
.insert(BlueprintMaterialAssetsNotLoaded);
|
||||
/**/
|
||||
|
@ -87,41 +89,50 @@ pub(crate) fn materials_inject(
|
|||
|
||||
// TODO, merge with check_for_loaded, make generic ?
|
||||
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>,
|
||||
mut commands: Commands,
|
||||
){
|
||||
for (entity, mut assets_to_load) in blueprint_assets_to_load.iter_mut(){
|
||||
) {
|
||||
for (entity, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
||||
let mut all_loaded = true;
|
||||
let mut loaded_amount = 0;
|
||||
let total = assets_to_load.asset_infos.len();
|
||||
for tracker in assets_to_load.asset_infos.iter_mut(){
|
||||
for tracker in assets_to_load.asset_infos.iter_mut() {
|
||||
let asset_id = tracker.id;
|
||||
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
|
||||
tracker.loaded = loaded;
|
||||
if loaded {
|
||||
loaded_amount += 1;
|
||||
}else{
|
||||
} else {
|
||||
all_loaded = false;
|
||||
}
|
||||
}
|
||||
let progress:f32 = loaded_amount as f32 / total as f32;
|
||||
let progress: f32 = loaded_amount as f32 / total as f32;
|
||||
assets_to_load.progress = progress;
|
||||
|
||||
if all_loaded {
|
||||
assets_to_load.all_loaded = true;
|
||||
commands.entity(entity)
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintMaterialAssetsLoaded)
|
||||
.remove::<BlueprintMaterialAssetsNotLoaded>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// system that injects / replaces materials from material library
|
||||
pub(crate) fn materials_inject2(
|
||||
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<
|
||||
(),
|
||||
(
|
||||
|
@ -157,8 +168,8 @@ pub(crate) fn materials_inject2(
|
|||
.get(&material_full_path)
|
||||
.expect("we should have the material available");
|
||||
material_found = Some(material);
|
||||
}else {
|
||||
let model_handle: Handle<Gltf> = asset_server.load(materials_path.clone());// FIXME: kinda weird now
|
||||
} else {
|
||||
let model_handle: Handle<Gltf> = asset_server.load(materials_path.clone()); // FIXME: kinda weird now
|
||||
let mat_gltf = assets_gltf
|
||||
.get(model_handle.id())
|
||||
.expect("material should have been preloaded");
|
||||
|
|
|
@ -48,23 +48,22 @@ pub(crate) struct OriginalChildren(pub Vec<Entity>);
|
|||
|
||||
#[derive(Component, Reflect, Default, Debug)]
|
||||
#[reflect(Component)]
|
||||
pub struct BlueprintsList(pub HashMap<String,Vec<String>>);
|
||||
pub struct BlueprintsList(pub HashMap<String, Vec<String>>);
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct AssetLoadTracker<T:bevy::prelude::Asset>{
|
||||
pub(crate) struct AssetLoadTracker<T: bevy::prelude::Asset> {
|
||||
pub name: String,
|
||||
pub id: AssetId<T>,
|
||||
pub loaded: bool,
|
||||
pub handle: Handle<T>
|
||||
pub handle: Handle<T>,
|
||||
}
|
||||
#[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 asset_infos: Vec<AssetLoadTracker<T>>,
|
||||
pub progress: f32
|
||||
pub progress: f32,
|
||||
}
|
||||
|
||||
|
||||
/// flag component
|
||||
#[derive(Component)]
|
||||
pub(crate) struct BlueprintAssetsLoaded;
|
||||
|
@ -91,15 +90,8 @@ pub(crate) fn prepare_blueprints(
|
|||
asset_server: Res<AssetServer>,
|
||||
blueprints_config: Res<BluePrintsConfig>,
|
||||
) {
|
||||
for (
|
||||
entity,
|
||||
blupeprint_name,
|
||||
original_parent,
|
||||
library_override,
|
||||
name,
|
||||
|
||||
blueprints_list,
|
||||
) in spawn_placeholders.iter()
|
||||
for (entity, blupeprint_name, original_parent, library_override, name, blueprints_list) in
|
||||
spawn_placeholders.iter()
|
||||
{
|
||||
debug!(
|
||||
"requesting to spawn {:?} for entity {:?}, id: {:?}, parent:{:?}",
|
||||
|
@ -110,19 +102,10 @@ pub(crate) fn prepare_blueprints(
|
|||
if blueprints_list.is_some() {
|
||||
let blueprints_list = blueprints_list.unwrap();
|
||||
// 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() {
|
||||
/*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_path = Path::new(&library_path).join(Path::new(model_file_name.as_str()));
|
||||
|
||||
|
@ -134,61 +117,60 @@ pub(crate) fn prepare_blueprints(
|
|||
name: model_path.to_string_lossy().into(),
|
||||
id: model_id,
|
||||
loaded: false,
|
||||
handle: model_handle.clone()
|
||||
handle: model_handle.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
// if not all assets are already loaded, inject a component to signal that we need them to be loaded
|
||||
if asset_infos.len() > 0 {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(AssetsToLoad{
|
||||
all_loaded: false,
|
||||
asset_infos: asset_infos,
|
||||
progress: 0.0
|
||||
//..Default::default()
|
||||
})
|
||||
.insert(BlueprintAssetsNotLoaded);
|
||||
}else {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintAssetsLoaded);
|
||||
.entity(entity)
|
||||
.insert(AssetsToLoad {
|
||||
all_loaded: false,
|
||||
asset_infos: asset_infos,
|
||||
progress: 0.0, //..Default::default()
|
||||
})
|
||||
.insert(BlueprintAssetsNotLoaded);
|
||||
} else {
|
||||
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
||||
}
|
||||
}
|
||||
else { // in case there are no blueprintsList
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintAssetsLoaded);
|
||||
} else {
|
||||
// in case there are no blueprintsList
|
||||
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>,
|
||||
mut commands: Commands,
|
||||
){
|
||||
for (entity, mut assets_to_load) in blueprint_assets_to_load.iter_mut(){
|
||||
) {
|
||||
for (entity, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
||||
let mut all_loaded = true;
|
||||
let mut loaded_amount = 0;
|
||||
let total = assets_to_load.asset_infos.len();
|
||||
for tracker in assets_to_load.asset_infos.iter_mut(){
|
||||
for tracker in assets_to_load.asset_infos.iter_mut() {
|
||||
let asset_id = tracker.id;
|
||||
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
|
||||
tracker.loaded = loaded;
|
||||
if loaded {
|
||||
loaded_amount += 1;
|
||||
}else{
|
||||
} else {
|
||||
all_loaded = false;
|
||||
}
|
||||
}
|
||||
let progress:f32 = loaded_amount as f32 / total as f32;
|
||||
let progress: f32 = loaded_amount as f32 / total as f32;
|
||||
// println!("progress: {}",progress);
|
||||
assets_to_load.progress = progress;
|
||||
|
||||
if all_loaded {
|
||||
assets_to_load.all_loaded = true;
|
||||
commands.entity(entity)
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintAssetsLoaded)
|
||||
.remove::<BlueprintAssetsNotLoaded>();
|
||||
}
|
||||
|
@ -197,16 +179,20 @@ pub(crate) fn check_for_loaded(
|
|||
|
||||
pub(crate) fn spawn_from_blueprints(
|
||||
spawn_placeholders: Query<
|
||||
(
|
||||
Entity,
|
||||
&BlueprintName,
|
||||
Option<&Transform>,
|
||||
Option<&Parent>,
|
||||
Option<&Library>,
|
||||
Option<&AddToGameWorld>,
|
||||
Option<&Name>,
|
||||
),
|
||||
(With<BlueprintAssetsLoaded>, Added<BlueprintAssetsLoaded>, Without<BlueprintAssetsNotLoaded>),
|
||||
(
|
||||
Entity,
|
||||
&BlueprintName,
|
||||
Option<&Transform>,
|
||||
Option<&Parent>,
|
||||
Option<&Library>,
|
||||
Option<&AddToGameWorld>,
|
||||
Option<&Name>,
|
||||
),
|
||||
(
|
||||
With<BlueprintAssetsLoaded>,
|
||||
Added<BlueprintAssetsLoaded>,
|
||||
Without<BlueprintAssetsNotLoaded>,
|
||||
),
|
||||
>,
|
||||
|
||||
mut commands: Commands,
|
||||
|
@ -217,8 +203,7 @@ pub(crate) fn spawn_from_blueprints(
|
|||
blueprints_config: Res<BluePrintsConfig>,
|
||||
|
||||
children: Query<&Children>,
|
||||
){
|
||||
|
||||
) {
|
||||
for (
|
||||
entity,
|
||||
blupeprint_name,
|
||||
|
@ -227,7 +212,6 @@ pub(crate) fn spawn_from_blueprints(
|
|||
library_override,
|
||||
add_to_world,
|
||||
name,
|
||||
|
||||
) in spawn_placeholders.iter()
|
||||
{
|
||||
info!(
|
||||
|
@ -244,7 +228,7 @@ pub(crate) fn spawn_from_blueprints(
|
|||
let model_path = Path::new(&library_path).join(Path::new(model_file_name.as_str()));
|
||||
|
||||
// info!("attempting to spawn {:?}", model_path);
|
||||
let model_handle: Handle<Gltf> = asset_server.load(model_path);// FIXME: kinda weird now
|
||||
let model_handle: Handle<Gltf> = asset_server.load(model_path); // FIXME: kinda weird now
|
||||
|
||||
let gltf = assets_gltf
|
||||
.get(&model_handle)
|
||||
|
@ -291,4 +275,4 @@ pub(crate) fn spawn_from_blueprints(
|
|||
commands.entity(world).add_child(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ use bevy::scene::SceneInstance;
|
|||
|
||||
use super::{AnimationPlayerLink, Animations};
|
||||
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
|
||||
/// - it removes one level of useless nesting
|
||||
|
@ -90,7 +93,7 @@ pub(crate) fn spawned_blueprint_post_process(
|
|||
commands.entity(original).remove::<SpawnHere>();
|
||||
commands.entity(original).remove::<Spawned>();
|
||||
commands.entity(original).remove::<Handle<Scene>>();
|
||||
commands.entity(original).remove::<AssetsToLoad<Gltf>>();// also clear the sub assets tracker to free up handles, perhaps just freeing up the handles and leave the rest would be better ?
|
||||
commands.entity(original).remove::<AssetsToLoad<Gltf>>(); // also clear the sub assets tracker to free up handles, perhaps just freeing up the handles and leave the rest would be better ?
|
||||
commands.entity(original).remove::<BlueprintAssetsLoaded>();
|
||||
commands.entity(root_entity).despawn_recursive();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ impl Plugin for CorePlugin {
|
|||
legacy_mode: false,
|
||||
library_folder: "models/library".into(),
|
||||
format: GltfFormat::GLB,
|
||||
material_library:true,
|
||||
material_library: true,
|
||||
aabbs: true,
|
||||
..Default::default()
|
||||
},
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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_rapier3d::prelude::Velocity;
|
||||
|
@ -12,7 +14,7 @@ pub fn setup_game(
|
|||
) {
|
||||
// here we actually spawn our game world/level
|
||||
commands.spawn((
|
||||
SceneBundle{
|
||||
SceneBundle {
|
||||
scene: asset_server.load("models/World.glb#Scene0"),
|
||||
..default()
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue