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
This commit is contained in:
Mark Moissette 2023-10-14 13:51:29 +02:00 committed by GitHub
parent f41a315563
commit bce6d43c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 28 deletions

2
Cargo.lock generated
View File

@ -721,7 +721,7 @@ dependencies = [
[[package]] [[package]]
name = "bevy_gltf_blueprints" name = "bevy_gltf_blueprints"
version = "0.1.3" version = "0.1.4"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_gltf_components 0.1.2", "bevy_gltf_components 0.1.2",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "bevy_gltf_blueprints" name = "bevy_gltf_blueprints"
version = "0.1.3" version = "0.1.4"
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

@ -10,7 +10,7 @@ pub use clone_entity::*;
use std::path::PathBuf; use std::path::PathBuf;
use bevy::prelude::*; use bevy::prelude::*;
use bevy_gltf_components::GltfComponentsSet; use bevy_gltf_components::{ComponentsFromGltfPlugin, GltfComponentsSet};
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
/// set for the two stages of blueprint based spawning : /// set for the two stages of blueprint based spawning :
@ -49,14 +49,15 @@ pub struct BlueprintsPlugin {
impl Default for BlueprintsPlugin { impl Default for BlueprintsPlugin {
fn default() -> Self { fn default() -> Self {
Self { Self {
library_folder: PathBuf::from("assets/models/library"), library_folder: PathBuf::from("models/library"),
} }
} }
} }
impl Plugin for BlueprintsPlugin { impl Plugin for BlueprintsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<BlueprintName>() app.add_plugins(ComponentsFromGltfPlugin)
.register_type::<BlueprintName>()
.register_type::<SpawnHere>() .register_type::<SpawnHere>()
.insert_resource(BluePrintsConfig { .insert_resource(BluePrintsConfig {
library_folder: self.library_folder.clone(), library_folder: self.library_folder.clone(),

View File

@ -51,13 +51,13 @@ pub(crate) fn spawn_from_blueprints(
blueprints_config: Res<BluePrintsConfig>, blueprints_config: Res<BluePrintsConfig>,
) { ) {
for (entity, name, blupeprint_name, global_transform) in spawn_placeholders.iter() { 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 what = &blupeprint_name.0;
let model_file_name = format!("{}.glb", &what); let model_file_name = format!("{}.glb", &what);
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()));
info!("attempting to spawn {:?}", model_path); debug!("attempting to spawn {:?}", model_path);
let scene: Handle<Gltf> = asset_server.load(model_path); let scene: Handle<Gltf> = asset_server.load(model_path);
// let scene = game_assets.models.get(&model_path).expect(&format!("no matching model {:?} found", model_path)); // let scene = game_assets.models.get(&model_path).expect(&format!("no matching model {:?} found", model_path));

View File

@ -124,12 +124,12 @@ pub(crate) fn cleanup_scene_instances(
for (entity, children) in scene_instances.iter() { for (entity, children) in scene_instances.iter() {
if children.len() == 0 { if children.len() == 0 {
// it seems this does not happen ? // 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(); commands.entity(entity).despawn_recursive();
} }
} }
for entity in without_children.iter() { 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(); commands.entity(entity).despawn_recursive();
} }
} }

View File

@ -1,4 +1,8 @@
pub mod physics_replace_proxies; pub mod physics_replace_proxies;
use bevy_rapier3d::{
prelude::{NoUserData, RapierPhysicsPlugin},
render::RapierDebugRenderPlugin,
};
pub use physics_replace_proxies::*; pub use physics_replace_proxies::*;
pub mod utils; pub mod utils;
@ -14,7 +18,11 @@ use bevy_gltf_blueprints::GltfBlueprintsSet;
pub struct PhysicsPlugin; pub struct PhysicsPlugin;
impl Plugin for PhysicsPlugin { impl Plugin for PhysicsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.register_type::<AutoAABBCollider>() app.add_plugins((
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
))
.register_type::<AutoAABBCollider>()
.register_type::<physics_replace_proxies::Collider>() .register_type::<physics_replace_proxies::Collider>()
// find a way to make serde's stuff serializable // find a way to make serde's stuff serializable
// .register_type::<bevy_rapier3d::dynamics::CoefficientCombineRule>() // .register_type::<bevy_rapier3d::dynamics::CoefficientCombineRule>()

View File

@ -1,8 +1,5 @@
use bevy::{asset::ChangeWatcher, gltf::Gltf, prelude::*}; use bevy::{asset::ChangeWatcher, prelude::*};
use bevy_editor_pls::prelude::*; use bevy_editor_pls::prelude::*;
use bevy_gltf_components::ComponentsFromGltfPlugin;
use bevy_rapier3d::prelude::*;
use std::time::Duration;
mod core; mod core;
use crate::core::*; use crate::core::*;
@ -31,11 +28,7 @@ fn main() {
}), }),
// editor // editor
EditorPlugin::default(), EditorPlugin::default(),
// physics
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
// our custom plugins // our custom plugins
ComponentsFromGltfPlugin,
StatePlugin, StatePlugin,
AssetsPlugin, AssetsPlugin,
CorePlugin, // reusable plugins CorePlugin, // reusable plugins