From bce6d43c50b2243d2392ebf4881e4d858b82ab2f Mon Sep 17 00:00:00 2001 From: Mark Moissette Date: Sat, 14 Oct 2023 13:51:29 +0200 Subject: [PATCH] Bevy gltf blueprints fixes and tweaks (#24) * fixed bad default path for library * added missing ComponentsFromGltfPlugin which causes the blueprint plugin not to work as expected if ComponentsFromGltfPlugin is not added elsewhere * all info! calls are now debug! for a less spammy debugging experience * refactor(examples:advanced): * removed ComponentsFromGltfPlugin as that is now included directly in the blueprints plugin * moved all physics (rapier) related code to the core/physics module --- Cargo.lock | 2 +- crates/bevy_gltf_blueprints/Cargo.toml | 2 +- crates/bevy_gltf_blueprints/src/lib.rs | 7 +++-- .../src/spawn_from_blueprints.rs | 4 +-- .../src/spawn_post_process.rs | 4 +-- examples/advanced/core/physics/mod.rs | 30 ++++++++++++------- examples/advanced/main.rs | 9 +----- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae47dac..25f9f0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -721,7 +721,7 @@ dependencies = [ [[package]] name = "bevy_gltf_blueprints" -version = "0.1.3" +version = "0.1.4" 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 ddbeccb..da142d6 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.3" +version = "0.1.4" 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 b363262..6559280 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -10,7 +10,7 @@ pub use clone_entity::*; use std::path::PathBuf; use bevy::prelude::*; -use bevy_gltf_components::GltfComponentsSet; +use bevy_gltf_components::{ComponentsFromGltfPlugin, GltfComponentsSet}; #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] /// set for the two stages of blueprint based spawning : @@ -49,14 +49,15 @@ pub struct BlueprintsPlugin { impl Default for BlueprintsPlugin { fn default() -> Self { Self { - library_folder: PathBuf::from("assets/models/library"), + library_folder: PathBuf::from("models/library"), } } } impl Plugin for BlueprintsPlugin { fn build(&self, app: &mut App) { - app.register_type::() + app.add_plugins(ComponentsFromGltfPlugin) + .register_type::() .register_type::() .insert_resource(BluePrintsConfig { library_folder: self.library_folder.clone(), diff --git a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs index 2e7c6e5..3e13173 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs @@ -51,13 +51,13 @@ pub(crate) fn spawn_from_blueprints( blueprints_config: Res, ) { for (entity, name, blupeprint_name, global_transform) in spawn_placeholders.iter() { - info!("need to spawn {:?}", blupeprint_name.0); + debug!("need to spawn {:?}", blupeprint_name.0); let what = &blupeprint_name.0; 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); + debug!("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)); diff --git a/crates/bevy_gltf_blueprints/src/spawn_post_process.rs b/crates/bevy_gltf_blueprints/src/spawn_post_process.rs index 012bb06..9944839 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_post_process.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_post_process.rs @@ -124,12 +124,12 @@ pub(crate) fn cleanup_scene_instances( for (entity, children) in scene_instances.iter() { if children.len() == 0 { // it seems this does not happen ? - info!("cleaning up emptied spawned scene instance"); + debug!("cleaning up emptied spawned scene instance"); commands.entity(entity).despawn_recursive(); } } for entity in without_children.iter() { - info!("cleaning up emptied spawned scene instance"); + debug!("cleaning up emptied spawned scene instance"); commands.entity(entity).despawn_recursive(); } } diff --git a/examples/advanced/core/physics/mod.rs b/examples/advanced/core/physics/mod.rs index ac2e616..cd7d523 100644 --- a/examples/advanced/core/physics/mod.rs +++ b/examples/advanced/core/physics/mod.rs @@ -1,4 +1,8 @@ pub mod physics_replace_proxies; +use bevy_rapier3d::{ + prelude::{NoUserData, RapierPhysicsPlugin}, + render::RapierDebugRenderPlugin, +}; pub use physics_replace_proxies::*; pub mod utils; @@ -14,16 +18,20 @@ use bevy_gltf_blueprints::GltfBlueprintsSet; pub struct PhysicsPlugin; impl Plugin for PhysicsPlugin { fn build(&self, app: &mut App) { - app.register_type::() - .register_type::() - // find a way to make serde's stuff serializable - // .register_type::() - //bevy_rapier3d::dynamics::CoefficientCombineRule - .add_systems( - Update, - physics_replace_proxies.after(GltfBlueprintsSet::AfterSpawn), - ) - .add_systems(OnEnter(GameState::InGame), resume_physics) - .add_systems(OnExit(GameState::InGame), pause_physics); + app.add_plugins(( + RapierPhysicsPlugin::::default(), + RapierDebugRenderPlugin::default(), + )) + .register_type::() + .register_type::() + // find a way to make serde's stuff serializable + // .register_type::() + //bevy_rapier3d::dynamics::CoefficientCombineRule + .add_systems( + Update, + physics_replace_proxies.after(GltfBlueprintsSet::AfterSpawn), + ) + .add_systems(OnEnter(GameState::InGame), resume_physics) + .add_systems(OnExit(GameState::InGame), pause_physics); } } diff --git a/examples/advanced/main.rs b/examples/advanced/main.rs index c13d6f2..b2253d9 100644 --- a/examples/advanced/main.rs +++ b/examples/advanced/main.rs @@ -1,8 +1,5 @@ -use bevy::{asset::ChangeWatcher, gltf::Gltf, prelude::*}; +use bevy::{asset::ChangeWatcher, prelude::*}; use bevy_editor_pls::prelude::*; -use bevy_gltf_components::ComponentsFromGltfPlugin; -use bevy_rapier3d::prelude::*; -use std::time::Duration; mod core; use crate::core::*; @@ -31,11 +28,7 @@ fn main() { }), // editor EditorPlugin::default(), - // physics - RapierPhysicsPlugin::::default(), - RapierDebugRenderPlugin::default(), // our custom plugins - ComponentsFromGltfPlugin, StatePlugin, AssetsPlugin, CorePlugin, // reusable plugins