diff --git a/crates/bevy_gltf_blueprints/README.md b/crates/bevy_gltf_blueprints/README.md index 31eeffb..fbad6b4 100644 --- a/crates/bevy_gltf_blueprints/README.md +++ b/crates/bevy_gltf_blueprints/README.md @@ -101,11 +101,8 @@ fn main() { App::new() .add_plugins(( BlueprintsPlugin{ - library_folder: "advanced/models/library".into() // replace this with your blueprints library path , relative to the assets folder, - format: GltfFormat::GLB,// optional, use either format: GltfFormat::GLB, or format: GltfFormat::GLTF, or ..Default::default() if you want to keep the default .glb extension, this sets what extensions/ gltf files will be looked for by the library aabbs: true, // defaults to false, enable this to automatically calculate aabb for the scene/blueprint material_library: true, // defaults to false, enable this to enable automatic injection of materials from material library files - material_library_folder: "materials".into() //defaults to "materials" the folder to look for for the material files ..Default::default() } )) @@ -294,7 +291,6 @@ Ie for example without this option, 56 different blueprints using the same mater you can configure this with the settings: ```rust material_library: true // defaults to false, enable this to enable automatic injection of materials from material library files -material_library_folder: "materials".into() //defaults to "materials" the folder to look for for the material files ``` > Important! you must take care of preloading your material librairy gltf files in advance, using for example ```bevy_asset_loader```since diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index abb9405..5741e86 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -51,12 +51,10 @@ impl Default for BluePrintBundle { #[derive(Clone, Resource)] pub struct BluePrintsConfig { pub(crate) format: GltfFormat, - pub(crate) library_folder: PathBuf, pub(crate) aabbs: bool, pub(crate) aabb_cache: HashMap, // cache for aabbs pub(crate) material_library: bool, - pub(crate) material_library_folder: PathBuf, pub(crate) material_library_cache: HashMap>, } @@ -84,23 +82,18 @@ impl fmt::Display for GltfFormat { /// Plugin for gltf blueprints pub struct BlueprintsPlugin { pub format: GltfFormat, - /// The base folder where library/blueprints assets are loaded from, relative to the executable. - pub library_folder: PathBuf, /// Automatically generate aabbs for the blueprints root objects pub aabbs: bool, /// pub material_library: bool, - pub material_library_folder: PathBuf, } impl Default for BlueprintsPlugin { fn default() -> Self { Self { format: GltfFormat::GLB, - library_folder: PathBuf::from("models/library"), aabbs: false, - material_library: false, - material_library_folder: PathBuf::from("materials"), + material_library: false } } } @@ -139,13 +132,11 @@ impl Plugin for BlueprintsPlugin { .register_type::>>() .insert_resource(BluePrintsConfig { format: self.format, - library_folder: self.library_folder.clone(), aabbs: self.aabbs, aabb_cache: HashMap::new(), material_library: self.material_library, - material_library_folder: self.material_library_folder.clone(), material_library_cache: HashMap::new(), }) .configure_sets( @@ -174,7 +165,7 @@ impl Plugin for BlueprintsPlugin { apply_deferred, ( materials_inject, - // check_for_material_loaded, + check_for_material_loaded, materials_inject2, ) .chain() diff --git a/crates/bevy_gltf_blueprints/src/materials.rs b/crates/bevy_gltf_blueprints/src/materials.rs index 7ca2cae..c6235cf 100644 --- a/crates/bevy_gltf_blueprints/src/materials.rs +++ b/crates/bevy_gltf_blueprints/src/materials.rs @@ -37,21 +37,16 @@ pub(crate) struct BlueprintMaterialAssetsNotLoaded; /// system that injects / replaces materials from material library pub(crate) fn materials_inject( blueprints_config: ResMut, - - ready_blueprints: Query<(Entity, &Children), (With)>, - material_infos: Query<(Entity, &MaterialInfo, &Parent), Added>, + material_infos: Query<(Entity, &MaterialInfo), Added>, asset_server: Res, mut commands: Commands, ) { - /*for(entity, children) in ready_blueprints.iter() { - println!("Blueprint ready !"); - } */ - for (entity, material_info, parent) in material_infos.iter() { + + for (entity, material_info) in material_infos.iter() { println!("Entity with material info {:?} {:?}", entity, material_info); - let parent_blueprint = ready_blueprints.get(parent.get()); - println!("Parent blueprint {:?}", parent_blueprint) - /*if blueprints_config + let material_full_path = format!("{}#{}", material_info.path, material_info.name); + if blueprints_config .material_library_cache .contains_key(&material_full_path) { @@ -64,12 +59,11 @@ pub(crate) fn materials_inject( .entity(entity) .insert(BlueprintMaterialAssetsLoaded); } else { - let material_file_handle: Handle = asset_server.load(materials_path.clone()); + let material_file_handle = asset_server.load_untyped(&material_info.path.clone()); // : Handle let material_file_id = material_file_handle.id(); - // FIXME: fix this stuff let asset_infos: Vec = vec![AssetLoadTracker { - name: material_full_path, + name: material_info.name.clone(), id: material_file_id, loaded: false, handle: material_file_handle.clone(), @@ -84,13 +78,11 @@ pub(crate) fn materials_inject( }) .insert(BlueprintMaterialAssetsNotLoaded); - } */ + } } } // TODO, merge with check_for_loaded, make generic ? -// FIXME: fix this: - pub(crate) fn check_for_material_loaded( mut blueprint_assets_to_load: Query< (Entity, &mut AssetsToLoad), @@ -150,15 +142,7 @@ pub(crate) fn materials_inject2( mut commands: Commands, ) { for (material_info, children) in material_infos.iter() { - let model_file_name = format!( - "{}_materials_library.{}", - &material_info.path, &blueprints_config.format - ); - let materials_path = Path::new(&blueprints_config.material_library_folder) - .join(Path::new(model_file_name.as_str())); - let material_name = &material_info.name; - - let material_full_path = materials_path.to_str().unwrap().to_string() + "#" + material_name; // TODO: yikes, cleanup + let material_full_path = format!("{}#{}", material_info.path, material_info.name); let mut material_found: Option<&Handle> = None; if blueprints_config @@ -172,14 +156,14 @@ pub(crate) fn materials_inject2( .expect("we should have the material available"); material_found = Some(material); } else { - let model_handle: Handle = asset_server.load(materials_path.clone()); // FIXME: kinda weird now + let model_handle: Handle = asset_server.load(material_info.path.clone()); // FIXME: kinda weird now let mat_gltf = assets_gltf .get(model_handle.id()) .expect("material should have been preloaded"); - if mat_gltf.named_materials.contains_key(material_name) { + if mat_gltf.named_materials.contains_key(&material_info.name) { let material = mat_gltf .named_materials - .get(material_name) + .get(&material_info.name) .expect("this material should have been loaded"); blueprints_config .material_library_cache @@ -193,8 +177,8 @@ pub(crate) fn materials_inject2( if with_materials_and_meshes.contains(*child) { debug!( "injecting material {}, path: {:?}", - material_name, - materials_path.clone() + material_info.name, + material_info.path.clone() ); commands.entity(*child).insert(material.clone()); diff --git a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs index bf2d236..92ffc40 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs @@ -264,9 +264,6 @@ pub(crate) fn spawn_from_blueprints2( blupeprint_name.0, name, entity, original_parent ); - let what = &blupeprint_name.0; - let model_file_name = format!("{}.{}", &what, &blueprints_config.format); - // info!("attempting to spawn {:?}", model_path); let model_handle: Handle = asset_server.load(blueprint_path.0.clone()); // FIXME: kinda weird now diff --git a/crates/bevy_gltf_save_load/README.md b/crates/bevy_gltf_save_load/README.md index 43aec04..7079e16 100644 --- a/crates/bevy_gltf_save_load/README.md +++ b/crates/bevy_gltf_save_load/README.md @@ -191,7 +191,6 @@ fn main() { }, // you need to configure the blueprints plugin as well (might be pre_configured in the future, but for now you need to do it manually) BlueprintsPlugin { - library_folder: "models/library".into(), format: GltfFormat::GLB, aabbs: true, ..Default::default() diff --git a/examples/bevy_gltf_blueprints/animation/src/core/mod.rs b/examples/bevy_gltf_blueprints/animation/src/core/mod.rs index 6db036e..cfa44d0 100644 --- a/examples/bevy_gltf_blueprints/animation/src/core/mod.rs +++ b/examples/bevy_gltf_blueprints/animation/src/core/mod.rs @@ -5,8 +5,6 @@ pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { app.add_plugins((BlueprintsPlugin { - library_folder: "models/library".into(), - format: GltfFormat::GLB, aabbs: true, ..Default::default() },)); diff --git a/examples/bevy_gltf_blueprints/basic/src/core/mod.rs b/examples/bevy_gltf_blueprints/basic/src/core/mod.rs index 6db036e..1bb6c2d 100644 --- a/examples/bevy_gltf_blueprints/basic/src/core/mod.rs +++ b/examples/bevy_gltf_blueprints/basic/src/core/mod.rs @@ -5,7 +5,6 @@ pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { app.add_plugins((BlueprintsPlugin { - library_folder: "models/library".into(), format: GltfFormat::GLB, aabbs: true, ..Default::default() diff --git a/examples/bevy_gltf_blueprints/basic_xpbd_physics/src/core/mod.rs b/examples/bevy_gltf_blueprints/basic_xpbd_physics/src/core/mod.rs index 0b481ac..1ed6e81 100644 --- a/examples/bevy_gltf_blueprints/basic_xpbd_physics/src/core/mod.rs +++ b/examples/bevy_gltf_blueprints/basic_xpbd_physics/src/core/mod.rs @@ -5,7 +5,6 @@ pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { app.add_plugins((BlueprintsPlugin { - library_folder: "models/library".into(), ..Default::default() },)); } diff --git a/examples/bevy_gltf_blueprints/materials/src/core/mod.rs b/examples/bevy_gltf_blueprints/materials/src/core/mod.rs index 37d9f8c..be162a5 100644 --- a/examples/bevy_gltf_blueprints/materials/src/core/mod.rs +++ b/examples/bevy_gltf_blueprints/materials/src/core/mod.rs @@ -5,7 +5,6 @@ pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { app.add_plugins((BlueprintsPlugin { - library_folder: "models/library".into(), material_library: true, ..Default::default() },)); diff --git a/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles/src/core/mod.rs b/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles/src/core/mod.rs index 37d9f8c..be162a5 100644 --- a/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles/src/core/mod.rs +++ b/examples/bevy_gltf_blueprints/multiple_levels_multiple_blendfiles/src/core/mod.rs @@ -5,7 +5,6 @@ pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { app.add_plugins((BlueprintsPlugin { - library_folder: "models/library".into(), material_library: true, ..Default::default() },)); diff --git a/examples/bevy_gltf_save_load/basic/src/core/mod.rs b/examples/bevy_gltf_save_load/basic/src/core/mod.rs index c6173bb..59bbda1 100644 --- a/examples/bevy_gltf_save_load/basic/src/core/mod.rs +++ b/examples/bevy_gltf_save_load/basic/src/core/mod.rs @@ -35,8 +35,6 @@ impl Plugin for CorePlugin { ..Default::default() }, BlueprintsPlugin { - library_folder: "models/library".into(), - format: GltfFormat::GLB, aabbs: true, ..Default::default() }, diff --git a/examples/bevy_registry_export/basic/src/core/mod.rs b/examples/bevy_registry_export/basic/src/core/mod.rs index de9b473..4430462 100644 --- a/examples/bevy_registry_export/basic/src/core/mod.rs +++ b/examples/bevy_registry_export/basic/src/core/mod.rs @@ -11,8 +11,6 @@ impl Plugin for CorePlugin { ..Default::default() }, BlueprintsPlugin { - library_folder: "models/library".into(), - format: GltfFormat::GLB, aabbs: true, ..Default::default() },