Fixed bevy_blender plugin not adding some components when something is spawned before it

This commit is contained in:
Franklin Blanco 2023-11-16 13:02:46 -08:00
parent e7aed2f974
commit ca0987bbe3
6 changed files with 37 additions and 21 deletions

View File

@ -1,6 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
// use bevy::render::primitives::Aabb; // use bevy::render::primitives::Aabb;
use bevy_rapier3d::geometry::Collider as RapierCollider; use bevy_rapier3d::geometry::{Collider as RapierCollider, Sensor};
use bevy_rapier3d::prelude::{ActiveCollisionTypes, ActiveEvents, ComputedColliderShape}; use bevy_rapier3d::prelude::{ActiveCollisionTypes, ActiveEvents, ComputedColliderShape};
use super::utils::*; use super::utils::*;
@ -82,18 +82,12 @@ pub fn physics_replace_proxies(
.unwrap(); .unwrap();
commands commands
.entity(entity) .entity(entity)
.insert(rapier_collider) .insert(rapier_collider);
// FIXME: this is just for demo purposes !!! // FIXME: this is just for demo purposes !!!;
.insert( //.insert(ActiveEvents::COLLISION_EVENTS);
ActiveCollisionTypes::default()
| ActiveCollisionTypes::KINEMATIC_STATIC
| ActiveCollisionTypes::STATIC_STATIC
| ActiveCollisionTypes::DYNAMIC_STATIC,
)
.insert(ActiveEvents::COLLISION_EVENTS);
// .insert(ActiveEvents::COLLISION_EVENTS) // .insert(ActiveEvents::COLLISION_EVENTS)
// break; // break;
// RapierCollider::convex_hull(points)
} }
} }
} }

View File

@ -1,5 +1,7 @@
use bevy::app::{Plugin, Update}; use bevy::app::{Plugin, Update};
use crate::setup::load_state::update_game_load_state;
use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::PlayerEye, in_player_hands_parent::InPlayerHandsParent}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}}; use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::PlayerEye, in_player_hands_parent::InPlayerHandsParent}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}};
@ -15,9 +17,8 @@ impl Plugin for ProxyComponentsPlugin {
app.register_type::<InPlayerHandsParent>(); app.register_type::<InPlayerHandsParent>();
// Physics // Physics
app app.register_type::<AutoAABBCollider>();
.register_type::<AutoAABBCollider>() app.register_type::<physics::rapier::Collider>();
.register_type::<physics::rapier::Collider>() app.add_systems(Update, (physics_replace_proxies, update_game_load_state));
.add_systems(Update, physics_replace_proxies);
} }
} }

View File

@ -1,5 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use crate::comps::core::markers::proxy::physics::rapier::physics_replace_proxies;
use super::{ use super::{
item::{item_spawner, ItemSpawnPointPlugin}, item::{item_spawner, ItemSpawnPointPlugin},
player::player_spawner, player::player_spawner,

View File

@ -37,7 +37,7 @@ fn setup_plugins(application: &mut App) {
.add_plugins(proxy::plugin::ProxyComponentsPlugin) .add_plugins(proxy::plugin::ProxyComponentsPlugin)
.add_plugins(MainGameUIPlugin) .add_plugins(MainGameUIPlugin)
.add_plugins(MainEditorUiPlugin) .add_plugins(MainEditorUiPlugin)
.add_plugins(RapierDebugRenderPlugin::default()); ;//.add_plugins(RapierDebugRenderPlugin::default());
} }
fn load(application: &mut App) { fn load(application: &mut App) {

View File

@ -30,7 +30,7 @@ pub struct GltfAsset {
pub fn load_all_assets( pub fn load_all_assets(
mut commands: Commands, mut commands: Commands,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut game_load_state: ResMut<GameLoadState>, //mut game_load_state: ResMut<GameLoadState>,
) { ) {
let skybox_handle: Handle<Image> = asset_server.load(CUBEMAPS[0].0); let skybox_handle: Handle<Image> = asset_server.load(CUBEMAPS[0].0);
commands.insert_resource(Cubemap { commands.insert_resource(Cubemap {
@ -52,9 +52,6 @@ pub fn load_all_assets(
commands.insert_resource(GltfAssets { commands.insert_resource(GltfAssets {
assets: Vec::from([m4a1_gltf_asset, glock17_gltf_asset, main_character_asset]), assets: Vec::from([m4a1_gltf_asset, glock17_gltf_asset, main_character_asset]),
}); });
game_load_state.assets_loaded = true;
// This works becaue this system is called on startup, so commands will finish running when game starts the update phase.
// Meaning assets will be finished loading as soon as the first update system runs.
} }
impl GltfAssetType { impl GltfAssetType {

View File

@ -1,9 +1,12 @@
use bevy::prelude::*; use bevy::{prelude::*, gltf::Gltf};
use super::assets::GltfAssets;
#[derive(Resource, Default, Reflect)] #[derive(Resource, Default, Reflect)]
#[reflect(Resource)] #[reflect(Resource)]
pub struct GameLoadState { pub struct GameLoadState {
pub assets_loaded: bool, pub assets_loaded: bool,
pub loaded_assets: Vec<AssetId<Gltf>>,
pub animations_loaded: bool, pub animations_loaded: bool,
pub player_loaded: bool, pub player_loaded: bool,
} }
@ -13,3 +16,22 @@ impl GameLoadState {
self.assets_loaded && self.animations_loaded self.assets_loaded && self.animations_loaded
} }
} }
pub fn update_game_load_state(
mut game_state: ResMut<GameLoadState>,
mut asset_event_reader: EventReader<AssetEvent<Gltf>>,
gltf_assets: Res<GltfAssets>,
) {
if let Some(asset_event) = asset_event_reader.read().next() {
match asset_event {
AssetEvent::Added { id } => {
game_state.loaded_assets.push(*id);
if gltf_assets.assets.len() == game_state.loaded_assets.len() {
game_state.assets_loaded = true;
}
}
_ => ()
}
}
}