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:
parent
76f6a45fc4
commit
8e67f76d28
|
@ -755,7 +755,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bevy_gltf_blueprints"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_gltf_components 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bevy_gltf_blueprints"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
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"
|
||||
|
|
|
@ -37,7 +37,7 @@ use bevy_gltf_blueprints::*;
|
|||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(BlueprintsPlugin)
|
||||
.add_plugins(BlueprintsPlugin)
|
||||
|
||||
.run();
|
||||
}
|
||||
|
@ -100,7 +100,8 @@ fn main() {
|
|||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(
|
||||
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();
|
||||
|
@ -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***
|
||||
|
||||
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
|
||||
|
||||
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/multiple_levels
|
||||
|
||||
|
||||
## Compatible Bevy versions
|
||||
|
|
|
@ -10,6 +10,7 @@ pub use animation::*;
|
|||
pub mod clone_entity;
|
||||
pub use clone_entity::*;
|
||||
|
||||
use core::fmt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
@ -40,11 +41,34 @@ impl Default for BluePrintBundle {
|
|||
|
||||
#[derive(Clone, Resource)]
|
||||
pub(crate) struct BluePrintsConfig {
|
||||
pub(crate) format: GltfFormat,
|
||||
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)]
|
||||
pub struct BlueprintsPlugin {
|
||||
pub format: GltfFormat,
|
||||
/// The base folder where library/blueprints assets are loaded from, relative to the executable.
|
||||
pub library_folder: PathBuf,
|
||||
}
|
||||
|
@ -52,6 +76,7 @@ pub struct BlueprintsPlugin {
|
|||
impl Default for BlueprintsPlugin {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
format: GltfFormat::GLB,
|
||||
library_folder: PathBuf::from("models/library"),
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +89,7 @@ impl Plugin for BlueprintsPlugin {
|
|||
.register_type::<SpawnHere>()
|
||||
.register_type::<Animations>()
|
||||
.insert_resource(BluePrintsConfig {
|
||||
format: self.format.clone(),
|
||||
library_folder: self.library_folder.clone(),
|
||||
})
|
||||
.configure_sets(
|
||||
|
|
|
@ -53,7 +53,7 @@ pub(crate) fn spawn_from_blueprints(
|
|||
for (entity, name, blupeprint_name, transform) in spawn_placeholders.iter() {
|
||||
debug!("need to spawn {:?}", 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 =
|
||||
Path::new(&blueprints_config.library_folder).join(Path::new(model_file_name.as_str()));
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ impl Plugin for CorePlugin {
|
|||
PhysicsPlugin,
|
||||
BlueprintsPlugin {
|
||||
library_folder: "models/library".into(),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ impl Plugin for CorePlugin {
|
|||
// SaveLoadPlugin,
|
||||
BlueprintsPlugin {
|
||||
library_folder: "models/library".into(),
|
||||
format: GltfFormat::GLB,
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ impl Plugin for CorePlugin {
|
|||
PhysicsPlugin,
|
||||
BlueprintsPlugin {
|
||||
library_folder: "models/library".into(),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ impl Plugin for CorePlugin {
|
|||
// SaveLoadPlugin,
|
||||
BlueprintsPlugin {
|
||||
library_folder: "models/library".into(),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue