From 94b20bdf0e6b41960aae83dfec8323d9a97fe1dd Mon Sep 17 00:00:00 2001 From: Mark Moissette Date: Tue, 3 Oct 2023 20:37:30 +0200 Subject: [PATCH] feat(bevy_gltf_blueprints): library_folder is now using path/pathbuf instead of strings (#15) * feat(bevy_gltf_blueprints): library_folder is now using path/pathbuf instead of strings * chore(bevy_gltf_blueprints): bumped version --- Cargo.lock | 2 +- crates/bevy_gltf_blueprints/Cargo.toml | 2 +- crates/bevy_gltf_blueprints/src/lib.rs | 11 +++++++---- .../bevy_gltf_blueprints/src/spawn_from_blueprints.rs | 11 ++++++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5ad8a4..ae47dac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -721,7 +721,7 @@ dependencies = [ [[package]] name = "bevy_gltf_blueprints" -version = "0.1.2" +version = "0.1.3" dependencies = [ "bevy", "bevy_gltf_components 0.1.2", diff --git a/crates/bevy_gltf_blueprints/Cargo.toml b/crates/bevy_gltf_blueprints/Cargo.toml index b0aae83..ddbeccb 100644 --- a/crates/bevy_gltf_blueprints/Cargo.toml +++ b/crates/bevy_gltf_blueprints/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_gltf_blueprints" -version = "0.1.2" +version = "0.1.3" authors = ["Mark 'kaosat-dev' Moissette"] description = "Adds the ability to define Blueprints/Prefabs for [Bevy](https://bevyengine.org/) inside gltf files and spawn them in Bevy." homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow" diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index dac0f4e..b77c7be 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -1,6 +1,6 @@ + pub mod spawn_from_blueprints; -use bevy_gltf_components::GltfComponentsSet; pub use spawn_from_blueprints::*; pub mod spawn_post_process; @@ -9,7 +9,10 @@ pub use spawn_post_process::*; pub mod clone_entity; pub use clone_entity::*; +use std::path::PathBuf; + use bevy::prelude::*; +use bevy_gltf_components::GltfComponentsSet; #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] /// set for the two stages of blueprint based spawning : @@ -37,19 +40,19 @@ impl Default for BluePrintBundle { #[derive(Clone, Resource)] pub(crate) struct BluePrintsConfig { - pub(crate) library_folder: String, + pub(crate) library_folder: PathBuf, } #[derive(Debug, Clone)] pub struct BlueprintsPlugin { /// The base folder where library/blueprints assets are loaded from, relative to the executable. - pub library_folder: String, + pub library_folder: PathBuf, } impl Default for BlueprintsPlugin { fn default() -> Self { Self { - library_folder: "assets/models/library".to_string(), + library_folder: PathBuf::from("assets/models/library"), } } } diff --git a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs index 9f9118c..ed379f5 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use bevy::{prelude::*, gltf::Gltf}; use crate::BluePrintsConfig; @@ -45,10 +47,13 @@ pub(crate) fn spawn_from_blueprints( for (entity, name, blupeprint_name, global_transform) in spawn_placeholders.iter() { info!("need to spawn {:?}", blupeprint_name.0); let what = &blupeprint_name.0; - let model_path = format!("{}/{}.glb", &blueprints_config.library_folder, &what); // FIXME: needs to be platform agnostic - let scene:Handle = asset_server.load(&model_path); - // let scene = game_assets.models.get(&model_path).expect(&format!("no matching model {:?} found", model_path)); + let model_file_name = format!("{}.glb",&what); + let model_path = Path::new(&blueprints_config.library_folder) + .join(Path::new(model_file_name.as_str())); + info!("attempting to spawn {:?}",model_path); + let scene:Handle = asset_server.load(model_path); + // let scene = game_assets.models.get(&model_path).expect(&format!("no matching model {:?} found", model_path)); let world = game_world.single_mut(); let world = world.1[0]; // FIXME: dangerous hack because our gltf data have a single child like this, but might not always be the case