chore(examples): updated basic_xpbd example to use v0.13

This commit is contained in:
kaosat.dev 2024-02-20 21:25:36 +01:00
parent a28505fc39
commit dec0818222
8 changed files with 36 additions and 23 deletions

View File

@ -7,4 +7,6 @@ license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
bevy="0.13" bevy="0.13"
bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" } bevy_gltf_blueprints = { path = "../../../crates/bevy_gltf_blueprints" }
bevy_gltf_worlflow_examples_common = { path = "../../common" } bevy_gltf_worlflow_examples_common = { path = "../../common" }
bevy_xpbd_3d = "0.4"
rand = "0.8.5"

View File

@ -4,11 +4,14 @@ pub use physics::*;
use bevy::prelude::*; use bevy::prelude::*;
use bevy_gltf_blueprints::*; use bevy_gltf_blueprints::*;
use bevy_xpbd_3d::plugins::PhysicsDebugPlugin;
pub struct CorePlugin; pub struct CorePlugin;
impl Plugin for CorePlugin { impl Plugin for CorePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_plugins(( app.add_plugins((
PhysicsPlugin, PhysicsPlugin,
//PhysicsDebugPlugin::default(),
BlueprintsPlugin { BlueprintsPlugin {
library_folder: "models/library".into(), library_folder: "models/library".into(),
..Default::default() ..Default::default()

View File

@ -1,5 +1,10 @@
use bevy::ecs::system::Res;
use bevy::gizmos::config::{GizmoConfig, GizmoConfigStore};
use bevy::input::keyboard::KeyCode;
use bevy::input::ButtonInput;
use bevy::log::info; use bevy::log::info;
use bevy::{prelude::ResMut, time::Time}; use bevy::{prelude::ResMut, time::Time};
use bevy_xpbd_3d::prelude::Physics; use bevy_xpbd_3d::prelude::Physics;
use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::prelude::*;
@ -12,3 +17,22 @@ pub fn resume_physics(mut time: ResMut<Time<Physics>>) {
info!("unpausing physics"); info!("unpausing physics");
time.unpause(); time.unpause();
} }
pub fn toggle_physics_debug(
mut config_store: ResMut<GizmoConfigStore>,
keycode: Res<ButtonInput<KeyCode>>,
) {
if keycode.just_pressed(KeyCode::KeyD) {
let config = config_store.config_mut::<PhysicsGizmos>().0;
config.enabled = !config.enabled;
println!("BLAAA");
/*
.insert_gizmo_group(
PhysicsGizmos {
aabb_color: Some(Color::WHITE),
..default()
},
GizmoConfig::default(),
)*/
}
}

View File

@ -22,6 +22,7 @@ impl Plugin for PhysicsPlugin {
Update, Update,
physics_replace_proxies.after(GltfBlueprintsSet::AfterSpawn), physics_replace_proxies.after(GltfBlueprintsSet::AfterSpawn),
) )
.add_systems(Update, toggle_physics_debug)
.add_systems(OnEnter(GameState::InGame), resume_physics) .add_systems(OnEnter(GameState::InGame), resume_physics)
.add_systems(OnExit(GameState::InGame), pause_physics); .add_systems(OnExit(GameState::InGame), pause_physics);
} }

View File

@ -48,7 +48,7 @@ pub fn physics_replace_proxies(
match collider_proxy { match collider_proxy {
Collider::Ball(radius) => { Collider::Ball(radius) => {
info!("generating collider from proxy: ball"); info!("generating collider from proxy: ball");
xpbd_collider = XpbdCollider::ball(*radius); xpbd_collider = XpbdCollider::sphere(*radius);
commands.entity(entity) commands.entity(entity)
.insert(xpbd_collider) .insert(xpbd_collider)
//.insert(ActiveEvents::COLLISION_EVENTS) // FIXME: this is just for demo purposes (also is there something like that in xpbd ?) !!! //.insert(ActiveEvents::COLLISION_EVENTS) // FIXME: this is just for demo purposes (also is there something like that in xpbd ?) !!!

View File

@ -39,12 +39,12 @@ pub fn setup_game(
} }
pub fn spawn_test( pub fn spawn_test(
keycode: Res<Input<KeyCode>>, keycode: Res<ButtonInput<KeyCode>>,
mut commands: Commands, mut commands: Commands,
mut game_world: Query<(Entity, &Children), With<GameWorldTag>>, mut game_world: Query<(Entity, &Children), With<GameWorldTag>>,
) { ) {
if keycode.just_pressed(KeyCode::T) { if keycode.just_pressed(KeyCode::KeyT) {
let world = game_world.single_mut(); let world = game_world.single_mut();
let world = world.1[0]; let world = world.1[0];

View File

@ -89,24 +89,10 @@ pub fn teardown_main_menu(bla: Query<Entity, With<InMainMenu>>, mut commands: Co
} }
pub fn main_menu( pub fn main_menu(
keycode: Res<Input<KeyCode>>, keycode: Res<ButtonInput<KeyCode>>,
mut next_app_state: ResMut<NextState<AppState>>, mut next_app_state: ResMut<NextState<AppState>>,
// mut next_game_state: ResMut<NextState<GameState>>,
// mut save_requested_events: EventWriter<SaveRequest>,
// mut load_requested_events: EventWriter<LoadRequest>,
) { ) {
if keycode.just_pressed(KeyCode::Return) { if keycode.just_pressed(KeyCode::Enter) {
next_app_state.set(AppState::AppLoading); next_app_state.set(AppState::AppLoading);
// next_game_state.set(GameState::None);
}
if keycode.just_pressed(KeyCode::L) {
next_app_state.set(AppState::AppLoading);
// load_requested_events.send(LoadRequest { path: "toto".into() })
}
if keycode.just_pressed(KeyCode::S) {
// save_requested_events.send(SaveRequest { path: "toto".into() })
} }
} }

View File

@ -1,5 +1,4 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_editor_pls::prelude::*;
use bevy_gltf_worlflow_examples_common::CommonPlugin; use bevy_gltf_worlflow_examples_common::CommonPlugin;
mod core; mod core;
@ -15,8 +14,6 @@ fn main() {
App::new() App::new()
.add_plugins(( .add_plugins((
DefaultPlugins.set(AssetPlugin::default()), DefaultPlugins.set(AssetPlugin::default()),
// editor
EditorPlugin::default(),
// our custom plugins // our custom plugins
CommonPlugin, CommonPlugin,
CorePlugin, // reusable plugins CorePlugin, // reusable plugins