feat(bevy_gltf_blueprints): added ability to also load gltf files, not just glb (#55)

* settable via a new field in the plugin configuration
 * updated examples & README
* closes #55
This commit is contained in:
Mark Moissette 2023-11-24 12:30:47 +01:00 committed by GitHub
parent 76f6a45fc4
commit 8e67f76d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 7 deletions

2
Cargo.lock generated
View File

@ -755,7 +755,7 @@ dependencies = [
[[package]] [[package]]
name = "bevy_gltf_blueprints" name = "bevy_gltf_blueprints"
version = "0.3.0" version = "0.3.1"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_gltf_components 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bevy_gltf_components 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "bevy_gltf_blueprints" name = "bevy_gltf_blueprints"
version = "0.3.0" version = "0.3.1"
authors = ["Mark 'kaosat-dev' Moissette"] 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." 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" homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"

View File

@ -37,7 +37,7 @@ use bevy_gltf_blueprints::*;
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(BlueprintsPlugin) .add_plugins(BlueprintsPlugin)
.run(); .run();
} }
@ -100,7 +100,8 @@ fn main() {
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin( .add_plugin(
BlueprintsPlugin{ BlueprintsPlugin{
library_folder: "advanced/models/library".into() // replace this with your blueprints library path , relative to the assets folder 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
} }
) )
.run(); .run();
@ -180,7 +181,7 @@ Typically , the order of systems should be
***bevy_gltf_components (GltfComponentsSet::Injection)*** => ***bevy_gltf_blueprints (GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)*** => ***replace_proxies*** ***bevy_gltf_components (GltfComponentsSet::Injection)*** => ***bevy_gltf_blueprints (GltfBlueprintsSet::Spawn, GltfBlueprintsSet::AfterSpawn)*** => ***replace_proxies***
see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/advanced for how to set it up correctly see https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/bevy_gltf_blueprints/basic for how to set it up correctly
@ -242,8 +243,10 @@ onward
## Examples ## Examples
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/advanced https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/basic
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/basic_xpbd_physics
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/animation https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/animation
https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/examples/multiple_levels
## Compatible Bevy versions ## Compatible Bevy versions

View File

@ -10,6 +10,7 @@ pub use animation::*;
pub mod clone_entity; pub mod clone_entity;
pub use clone_entity::*; pub use clone_entity::*;
use core::fmt;
use std::path::PathBuf; use std::path::PathBuf;
use bevy::prelude::*; use bevy::prelude::*;
@ -40,11 +41,34 @@ impl Default for BluePrintBundle {
#[derive(Clone, Resource)] #[derive(Clone, Resource)]
pub(crate) struct BluePrintsConfig { pub(crate) struct BluePrintsConfig {
pub(crate) format: GltfFormat,
pub(crate) library_folder: PathBuf, pub(crate) library_folder: PathBuf,
} }
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
pub enum GltfFormat {
#[default]
GLB,
GLTF
}
impl fmt::Display for GltfFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GltfFormat::GLB => {
write!(f, "glb", )
}
GltfFormat::GLTF => {
write!(f, "gltf")
}
}
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BlueprintsPlugin { pub struct BlueprintsPlugin {
pub format: GltfFormat,
/// The base folder where library/blueprints assets are loaded from, relative to the executable. /// The base folder where library/blueprints assets are loaded from, relative to the executable.
pub library_folder: PathBuf, pub library_folder: PathBuf,
} }
@ -52,6 +76,7 @@ pub struct BlueprintsPlugin {
impl Default for BlueprintsPlugin { impl Default for BlueprintsPlugin {
fn default() -> Self { fn default() -> Self {
Self { Self {
format: GltfFormat::GLB,
library_folder: PathBuf::from("models/library"), library_folder: PathBuf::from("models/library"),
} }
} }
@ -64,6 +89,7 @@ impl Plugin for BlueprintsPlugin {
.register_type::<SpawnHere>() .register_type::<SpawnHere>()
.register_type::<Animations>() .register_type::<Animations>()
.insert_resource(BluePrintsConfig { .insert_resource(BluePrintsConfig {
format: self.format.clone(),
library_folder: self.library_folder.clone(), library_folder: self.library_folder.clone(),
}) })
.configure_sets( .configure_sets(

View File

@ -53,7 +53,7 @@ pub(crate) fn spawn_from_blueprints(
for (entity, name, blupeprint_name, transform) in spawn_placeholders.iter() { for (entity, name, blupeprint_name, transform) in spawn_placeholders.iter() {
debug!("need to spawn {:?}", blupeprint_name.0); debug!("need to spawn {:?}", blupeprint_name.0);
let what = &blupeprint_name.0; let what = &blupeprint_name.0;
let model_file_name = format!("{}.glb", &what); let model_file_name = format!("{}.{}", &what, &blueprints_config.format);
let model_path = let model_path =
Path::new(&blueprints_config.library_folder).join(Path::new(model_file_name.as_str())); Path::new(&blueprints_config.library_folder).join(Path::new(model_file_name.as_str()));

View File

@ -22,6 +22,7 @@ impl Plugin for CorePlugin {
PhysicsPlugin, PhysicsPlugin,
BlueprintsPlugin { BlueprintsPlugin {
library_folder: "models/library".into(), library_folder: "models/library".into(),
..Default::default()
}, },
)); ));
} }

View File

@ -26,6 +26,8 @@ impl Plugin for CorePlugin {
// SaveLoadPlugin, // SaveLoadPlugin,
BlueprintsPlugin { BlueprintsPlugin {
library_folder: "models/library".into(), library_folder: "models/library".into(),
format: GltfFormat::GLB,
..Default::default()
}, },
)); ));
} }

View File

@ -22,6 +22,7 @@ impl Plugin for CorePlugin {
PhysicsPlugin, PhysicsPlugin,
BlueprintsPlugin { BlueprintsPlugin {
library_folder: "models/library".into(), library_folder: "models/library".into(),
..Default::default()
}, },
)); ));
} }

View File

@ -26,6 +26,7 @@ impl Plugin for CorePlugin {
// SaveLoadPlugin, // SaveLoadPlugin,
BlueprintsPlugin { BlueprintsPlugin {
library_folder: "models/library".into(), library_folder: "models/library".into(),
..Default::default()
}, },
)); ));
} }