feat(examples):

* updated & cleaned up examples some more
 * added features/feature flags to 'common' example boilerplate
 * moved xpbd physics to common, behind a flag too
 * updated xpbd example
 * updated code for bevy_asset_loader changed api
 * more cleanups
This commit is contained in:
kaosat.dev 2024-02-21 13:15:46 +01:00
parent dec0818222
commit 453b0b5d55
20 changed files with 42 additions and 107 deletions

View File

@ -7,6 +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" , default-features = false, features = ["blueprints", "physics_xpbd"]}
bevy_xpbd_3d = "0.4" bevy_xpbd_3d = "0.4"
rand = "0.8.5" rand = "0.8.5"

View File

@ -1,17 +1,10 @@
pub mod physics;
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,
//PhysicsDebugPlugin::default(),
BlueprintsPlugin { BlueprintsPlugin {
library_folder: "models/library".into(), library_folder: "models/library".into(),
..Default::default() ..Default::default()

View File

@ -1,10 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, GameWorldTag}; use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, GameWorldTag};
use bevy_gltf_worlflow_examples_common::{assets::GameAssets, GameState, InAppRunning}; use bevy_gltf_worlflow_examples_common::{assets::GameAssets, GameState, InAppRunning};
// use bevy_rapier3d::prelude::Velocity;
use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::prelude::*;
use rand::Rng; use rand::Rng;
pub fn setup_game( pub fn setup_game(
@ -13,7 +10,6 @@ pub fn setup_game(
models: Res<Assets<bevy::gltf::Gltf>>, models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>, mut next_game_state: ResMut<NextState<GameState>>,
) { ) {
println!("setting up all stuff");
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.2, brightness: 0.2,

View File

@ -11,7 +11,6 @@ pub fn setup_game(
models: Res<Assets<bevy::gltf::Gltf>>, models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>, mut next_game_state: ResMut<NextState<GameState>>,
) { ) {
println!("setting up all stuff");
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.2, brightness: 0.2,

View File

@ -11,7 +11,6 @@ pub fn setup_game(
models: Res<Assets<bevy::gltf::Gltf>>, models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>, mut next_game_state: ResMut<NextState<GameState>>,
) { ) {
println!("setting up all stuff");
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.2, brightness: 0.2,

View File

@ -11,7 +11,6 @@ pub fn setup_game(
models: Res<Assets<bevy::gltf::Gltf>>, models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>, mut next_game_state: ResMut<NextState<GameState>>,
) { ) {
println!("setting up all stuff");
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.2, brightness: 0.2,

View File

@ -4,10 +4,18 @@ version = "0.1.0"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[features]
blueprints=["dep:bevy_gltf_blueprints"]
physics_rapier = ["dep:bevy_rapier3d"]
physics_xpbd = ["dep:bevy_xpbd_3d"]
default = ["blueprints", "physics_rapier"]
[dependencies] [dependencies]
bevy="0.13" bevy="0.13"
bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints" } bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints", optional = true }
bevy_rapier3d = { version = "0.25.0", features = [ "serde-serialize", "debug-render-3d", "enhanced-determinism"] } bevy_rapier3d = { version = "0.25", features = [ "serde-serialize", "debug-render-3d", "enhanced-determinism"] , optional = true }
bevy_xpbd_3d = { version = "0.4", optional = true }
bevy_asset_loader = { version = "0.20", features = ["standard_dynamic_assets" ]} bevy_asset_loader = { version = "0.20", features = ["standard_dynamic_assets" ]}
#bevy_editor_pls = { version = "0.6" } #bevy_editor_pls = { version = "0.6" }
rand = "0.8.5" rand = "0.8.5"

View File

@ -15,21 +15,21 @@ impl Plugin for AssetsPlugin {
app app
// load core assets (ie assets needed in the main menu, and everywhere else before loading more assets in game) // load core assets (ie assets needed in the main menu, and everywhere else before loading more assets in game)
.add_loading_state( .add_loading_state(
LoadingState::new(AppState::CoreLoading).continue_to_state(AppState::MenuRunning), LoadingState::new(AppState::CoreLoading)
.continue_to_state(AppState::MenuRunning)
.with_dynamic_assets_file::<StandardDynamicAssetCollection>(
"assets_core.assets.ron",
)
.load_collection::<CoreAssets>()
) )
.add_dynamic_collection_to_loading_state::<_, StandardDynamicAssetCollection>(
AppState::CoreLoading,
"assets_core.assets.ron",
)
.add_collection_to_loading_state::<_, CoreAssets>(AppState::CoreLoading)
// load game assets // load game assets
.add_loading_state( .add_loading_state(
LoadingState::new(AppState::AppLoading).continue_to_state(AppState::AppRunning), LoadingState::new(AppState::AppLoading)
) .continue_to_state(AppState::AppRunning)
.add_dynamic_collection_to_loading_state::<_, StandardDynamicAssetCollection>( .with_dynamic_assets_file::<StandardDynamicAssetCollection>(
AppState::AppLoading, "assets_game.assets.ron",
"assets_game.assets.ron", )
) .load_collection::<GameAssets>()
.add_collection_to_loading_state::<_, GameAssets>(AppState::AppLoading); );
} }
} }

View File

@ -31,7 +31,7 @@ pub fn camera_replace_proxies(
for (entity, mut camera, mut exposure, bloom_settings, ssao_setting) in added_cameras.iter_mut() { for (entity, mut camera, mut exposure, bloom_settings, ssao_setting) in added_cameras.iter_mut() {
info!("detected added camera, updating proxy"); info!("detected added camera, updating proxy");
camera.hdr = true; camera.hdr = true;
// exposure.ev100 *= 0.8; exposure.ev100 *= 1.0;
commands commands
.entity(entity) .entity(entity)
.insert(DebandDither::Enabled) .insert(DebandDither::Enabled)

View File

@ -7,8 +7,16 @@ pub use lighting::*;
//pub mod relationships; //pub mod relationships;
//pub use relationships::*; //pub use relationships::*;
pub mod physics; #[cfg(feature = "physics_rapier")]
pub use physics::*; pub mod physics_rapier;
#[cfg(feature = "physics_rapier")]
pub use physics_rapier::*;
#[cfg(feature = "physics_xpbd")]
pub mod physics_xpbd;
#[cfg(feature = "physics_xpbd")]
pub use physics_xpbd::*;
use bevy::prelude::*; use bevy::prelude::*;

View File

@ -1,5 +1,5 @@
use bevy::ecs::system::Res; use bevy::ecs::system::Res;
use bevy::gizmos::config::{GizmoConfig, GizmoConfigStore}; use bevy::gizmos::config::GizmoConfigStore;
use bevy::input::keyboard::KeyCode; use bevy::input::keyboard::KeyCode;
use bevy::input::ButtonInput; use bevy::input::ButtonInput;
use bevy::log::info; use bevy::log::info;
@ -25,14 +25,6 @@ pub fn toggle_physics_debug(
if keycode.just_pressed(KeyCode::KeyD) { if keycode.just_pressed(KeyCode::KeyD) {
let config = config_store.config_mut::<PhysicsGizmos>().0; let config = config_store.config_mut::<PhysicsGizmos>().0;
config.enabled = !config.enabled; config.enabled = !config.enabled;
println!("BLAAA"); // config.aabb_color = Some(Color::WHITE);
/*
.insert_gizmo_group(
PhysicsGizmos {
aabb_color: Some(Color::WHITE),
..default()
},
GizmoConfig::default(),
)*/
} }
} }

View File

@ -10,7 +10,7 @@ use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::prelude::*;
use bevy_gltf_blueprints::GltfBlueprintsSet; use bevy_gltf_blueprints::GltfBlueprintsSet;
use bevy_gltf_worlflow_examples_common::GameState; use crate::state::GameState;
pub struct PhysicsPlugin; pub struct PhysicsPlugin;
impl Plugin for PhysicsPlugin { impl Plugin for PhysicsPlugin {

View File

@ -11,7 +11,6 @@ pub fn setup_game(
models: Res<Assets<bevy::gltf::Gltf>>, models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>, mut next_game_state: ResMut<NextState<GameState>>,
) { ) {
println!("setting up all stuff");
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.2, brightness: 0.2,
@ -41,12 +40,12 @@ pub fn setup_game(
struct UnregisteredComponent; struct UnregisteredComponent;
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];
@ -82,47 +81,3 @@ pub fn spawn_test(
commands.entity(world).add_child(new_entity); commands.entity(world).add_child(new_entity);
} }
} }
pub fn spawn_test_unregisted_components(
keycode: Res<Input<KeyCode>>,
mut commands: Commands,
mut game_world: Query<(Entity, &Children), With<GameWorldTag>>,
) {
if keycode.just_pressed(KeyCode::U) {
let world = game_world.single_mut();
let world = world.1[0];
let mut rng = rand::thread_rng();
let range = 5.5;
let x: f32 = rng.gen_range(-range..range);
let y: f32 = rng.gen_range(-range..range);
let mut rng = rand::thread_rng();
let range = 0.8;
let vel_x: f32 = rng.gen_range(-range..range);
let vel_y: f32 = rng.gen_range(2.0..2.5);
let vel_z: f32 = rng.gen_range(-range..range);
let name_index: u64 = rng.gen();
let new_entity = commands
.spawn((
BluePrintBundle {
blueprint: BlueprintName("Health_Pickup".to_string()),
..Default::default()
},
bevy::prelude::Name::from(format!("test{}", name_index)),
// BlueprintName("Health_Pickup".to_string()),
// SpawnHere,
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
Velocity {
linvel: Vec3::new(vel_x, vel_y, vel_z),
angvel: Vec3::new(0.0, 0.0, 0.0),
},
UnregisteredComponent,
))
.id();
commands.entity(world).add_child(new_entity);
}
}

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() })
} }
} }