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]
bevy="0.13"
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"
rand = "0.8.5"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,10 +4,18 @@ version = "0.1.0"
edition = "2021"
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]
bevy="0.13"
bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints" }
bevy_rapier3d = { version = "0.25.0", features = [ "serde-serialize", "debug-render-3d", "enhanced-determinism"] }
bevy_gltf_blueprints = { path = "../../crates/bevy_gltf_blueprints", optional = true }
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_editor_pls = { version = "0.6" }
rand = "0.8.5"

View File

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

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() {
info!("detected added camera, updating proxy");
camera.hdr = true;
// exposure.ev100 *= 0.8;
exposure.ev100 *= 1.0;
commands
.entity(entity)
.insert(DebandDither::Enabled)

View File

@ -7,8 +7,16 @@ pub use lighting::*;
//pub mod relationships;
//pub use relationships::*;
pub mod physics;
pub use physics::*;
#[cfg(feature = "physics_rapier")]
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::*;

View File

@ -1,5 +1,5 @@
use bevy::ecs::system::Res;
use bevy::gizmos::config::{GizmoConfig, GizmoConfigStore};
use bevy::gizmos::config::GizmoConfigStore;
use bevy::input::keyboard::KeyCode;
use bevy::input::ButtonInput;
use bevy::log::info;
@ -25,14 +25,6 @@ pub fn toggle_physics_debug(
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(),
)*/
// config.aabb_color = Some(Color::WHITE);
}
}

View File

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

View File

@ -11,7 +11,6 @@ pub fn setup_game(
models: Res<Assets<bevy::gltf::Gltf>>,
mut next_game_state: ResMut<NextState<GameState>>,
) {
println!("setting up all stuff");
commands.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 0.2,
@ -41,12 +40,12 @@ pub fn setup_game(
struct UnregisteredComponent;
pub fn spawn_test(
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
mut commands: Commands,
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 = world.1[0];
@ -82,47 +81,3 @@ pub fn spawn_test(
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(
keycode: Res<Input<KeyCode>>,
keycode: Res<ButtonInput<KeyCode>>,
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_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() })
}
}