Skip to content

Commit

Permalink
bevy: get working on bevy 0.15.0-rc.3
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Nov 24, 2024
1 parent e7a6f27 commit e08cf94
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 319 deletions.
28 changes: 6 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ edition = "2021"
readme = "README.md"
license-file = "LICENSE"

[[bin]]
name = "yahs"
path = "src/main.rs"

[features]
default = [
# Default to a native dev build.
Expand All @@ -22,33 +26,13 @@ dev_native = [
"dev",
# Enable system information plugin for native dev builds.
"bevy/sysinfo_plugin",
"iyes_perf_ui/sysinfo",
]
config-files = ["ron", "bevy_common_assets", "serde"]
inspect = ["bevy-inspector-egui", "bevy_panorbit_camera/bevy_egui"]

[dependencies]
# core dependencies
bevy = "0.15.0-rc.3"
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy.git" }
bevy-trait-query = "0.6.0"
# physics dependencies
avian3d = { version = "0.1.2", features = ["debug-plugin"] }
# ui dependencies
bevy_panorbit_camera = { version = "0.20.0" }
bevy-inspector-egui = { version = "0.27.0", features = ["highlight_changes"], optional = true }
iyes_perf_ui = "0.3.0"
# file io dependencies
bevy_common_assets = { version = "0.11.0", features = ["ron"], optional = true }
ron = { version = "0.8.1", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
parry3d = { version = "0.17.2", features = ["parallel"] }
avian3d = { git = "https://github.com/Jondolf/avian.git", branch = "bevy-0.15", features = ["debug-plugin"] }
thiserror = "2.0.3"

[[bin]]
name = "yahs"
path = "src/main.rs"

# -----------------------------------------------------------------------------
# Some Bevy optimizations
# -----------------------------------------------------------------------------
Expand All @@ -68,7 +52,7 @@ type_complexity = "allow"
# Compile with Performance Optimizations:
# https://bevyengine.org/learn/quick-start/getting-started/setup/#compile-with-performance-optimizations

# Enable a small amount of optimization in the dev profile.
# Enable a small amount of optimization in the dev profile for our code.
[profile.dev]
opt-level = 1

Expand Down
41 changes: 40 additions & 1 deletion docs/devlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,46 @@ out it is not that simple and having them as separate components is useful and
clean. It is much simpler to write systems that update these components.

[Migrating to Bevy `0.15.0-rc.3`](https://github.com/bevyengine/bevy-website/tree/main/release-content/0.15/migration-guides)
is proving to be a bit of a challenge.
is proving to be a bit of a challenge. The main feature from it that I want to
use is the new separation of meshes from rendering, since then we can use meshes
for calculations like volume and drag even if we want to use a CLI and don't
want to render anything. This feature also led to some welcome improvements to
Bevy's meshing tools.

Something about 0.15 seems to have broken bundles. I wonder if the API changed
or if there's some old garbage hanging around that is causing issues. I wiped
the cache and rebuilt the project (`cargo clean && cargo build`). It turns out
the reason that builds are failing is because some of the 3rd party dependencies
I'm using are not compatible with the new Bevy version. I need to go through and
update them or remove them.

- [x] `avian3d` -> branch `bevy-0.15`
- [ ] ~~`bevy_heavy`~~ remove for now
- [ ] ~~`bevy-trait-query`~~ remove for now
- [ ] ~~`bevy_common_assets`~~ remove for now
- [ ] ~~`bevy_panorbit_camera`~~ remove for now
- [ ] ~~`iyes_perf_ui`~~ remove for now
- [ ] ~~`bevy-inspector-egui`~~ remove for now

I also removed `serde` from the dependencies. I won't be getting to config files
any time soon.

It's probably better to not use so many 3rd party plugins. Fortunately most of
these are debug tools and not essential to the simulator.

This demo does a great job using Egui and debug vectors:
[bevy_motion_matching](https://github.com/kahboon0425/bevy_motion_matching)
something to look into later.

I'm gonna do it. I'm going to make the simulator and the 3D app separate crates.
There are three reasons for this:

1. The simulator crate can be used as a library in other projects.
2. The 3D app can be built and run independently of the rest of the code.
3. I want faster compile times.

Nevermind, it complicated things way too much and was distracting. In the future
it might be worthwhile but it's probably best to just use feature flags anyway.

## 2024-11-18 again

Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/app3d/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod scene;
mod ui;
pub mod controls;

// Re-export the plugins so they can be added to the app with `app.add_plugins`.
pub use scene::ScenePlugin;
pub use ui::InterfacePlugins;
pub use controls::ControlsPlugin;
53 changes: 4 additions & 49 deletions src/app3d/scene/camera.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,20 @@
use bevy::prelude::*;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use avian3d::math::TAU;

use crate::controls::KeyBindingsConfig;
// use crate::controls::CameraControls;

pub struct CameraPlugin;

impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(PanOrbitCameraPlugin);
app.add_systems(Startup, setup);
app.add_systems(Update, toggle_camera_controls_system);
}
}

fn setup(mut commands: Commands, key_bindings: Res<KeyBindingsConfig>) {
fn setup(mut commands: Commands) {
commands.spawn((
// Note we're setting the initial position below with yaw, pitch, and radius, hence
// we don't set transform on the camera.
Camera3dBundle::default(),
PanOrbitCamera {
// Set focal point (what the camera should look at)
focus: Vec3::new(0.0, 1.0, 0.0),
// Set the starting position, relative to focus (overrides camera's transform).
yaw: Some(TAU / 8.0),
pitch: Some(TAU / 8.0),
radius: Some(5.0),
// Set limits on rotation and zoom
yaw_upper_limit: Some(TAU / 4.0),
yaw_lower_limit: Some(-TAU / 4.0),
pitch_upper_limit: Some(TAU / 3.0),
pitch_lower_limit: Some(-TAU / 3.0),
zoom_upper_limit: Some(100.0),
zoom_lower_limit: 1.0,
// Adjust sensitivity of controls
orbit_sensitivity: 1.5,
pan_sensitivity: 0.5,
zoom_sensitivity: 0.5,
// Allow the camera to go upside down
allow_upside_down: true,
// Change the controls (these match Blender)
button_orbit: key_bindings.camera_controls.button_orbit,
button_pan: key_bindings.camera_controls.button_pan,
modifier_pan: key_bindings.camera_controls.modifier_pan,
// Reverse the zoom direction
reversed_zoom: false,
..default()
},
Camera3d::default(),
Transform::from_xyz(0.0, 20., 14.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y),
));
}

// This is how you can change config at runtime.
// Press 'T' to toggle the camera zoom direction.
fn toggle_camera_controls_system(
key_input: Res<ButtonInput<KeyCode>>,
key_bindings: Res<KeyBindingsConfig>,
mut pan_orbit_query: Query<&mut PanOrbitCamera>,
) {
if key_input.just_pressed(key_bindings.camera_controls.toggle_zoom_direction) {
for mut pan_orbit in pan_orbit_query.iter_mut() {
pan_orbit.reversed_zoom = !pan_orbit.reversed_zoom;
}
}
}
67 changes: 47 additions & 20 deletions src/app3d/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ mod camera;
use avian3d::prelude::*;
use bevy::prelude::*;

use crate::simulator::*;

pub struct ScenePlugin;

impl Plugin for ScenePlugin {
fn build(&self, app: &mut App) {
app.add_plugins(camera::CameraPlugin);
app.add_systems(Startup, simple_scene);
app.add_systems(Startup, (simple_scene, spawn_balloon));
}
}

Expand All @@ -18,40 +20,65 @@ fn simple_scene(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let ground_size = Vec3::new(50.0, 0.1, 50.0);
let plane = meshes.add(Plane3d::default().mesh().size(ground_size.x, ground_size.z).subdivisions(10));
let plane_material = materials.add(StandardMaterial::default());

// light
commands.spawn((
Name::new("Light"),
PointLightBundle {
point_light: PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
PointLight {
intensity: 1500.0,
..default()
},
));

// ground
let ground_size = Vec3::new(4.0, 0.1, 4.0);
commands.spawn((
Name::new("Ground"),
PbrBundle {
mesh: meshes.add(Cuboid::new(ground_size.x, ground_size.y, ground_size.z)),
material: materials.add(Color::srgba(0.75, 0.75, 0.75, 0.1)),
transform: Transform::from_translation(Vec3::new(0.0, -2.0, 0.0)),
..default()
},
RigidBody::Static,
Collider::cuboid(ground_size.x, ground_size.y, ground_size.z),
Mesh3d(plane.clone()),
MeshMaterial3d(plane_material.clone()),
));

// ceiling
commands.spawn((
Name::new("Ceiling"),
PbrBundle {
mesh: meshes.add(Cuboid::new(ground_size.x, ground_size.y, ground_size.z)),
material: materials.add(Color::srgba(0.75, 0.75, 0.75, 0.1)),
transform: Transform::from_translation(Vec3::new(0.0, 3.0, 0.0)),
..default()
},
RigidBody::Static,
Collider::cuboid(ground_size.x, ground_size.y, ground_size.z),
Mesh3d(plane.clone()),
MeshMaterial3d(plane_material.clone()),
));
}

pub fn spawn_balloon(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let debug_material = materials.add(StandardMaterial {
base_color: Color::srgb(1.0, 0.0, 0.0),
..default()
});
let shape = meshes.add(Sphere::default().mesh().ico(5).unwrap());
commands.spawn((
Name::new("Balloon"),
SimulatedBody,
BalloonBundle {
balloon: Balloon::default(),
gas: IdealGasBundle {
species: GasSpecies::helium(),
gas: IdealGas {
temperature: Temperature::STANDARD,
pressure: Pressure::STANDARD,
mass: Mass::new(1.0),
},
},
},
RigidBody::Dynamic,
Mesh3d(shape),
MeshMaterial3d(debug_material),
));

}
8 changes: 4 additions & 4 deletions src/app3d/ui/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{app::PluginGroupBuilder, prelude::*};
use iyes_perf_ui::prelude::*;
// use iyes_perf_ui::prelude::*;

use crate::controls::KeyBindingsConfig;
use crate::app3d::controls::KeyBindingsConfig;
use crate::simulator::SimState;

use super::*;
Expand All @@ -14,7 +14,7 @@ impl PluginGroup for InterfacePlugins {
PluginGroupBuilder::start::<Self>()
.add(CoreUiPlugin)
.add(PausePlayPlugin)
.add(monitors::MonitorsPlugin)
// .add(monitors::MonitorsPlugin)
}
}

Expand All @@ -25,7 +25,7 @@ pub struct CoreUiPlugin;
impl Plugin for CoreUiPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
PerfUiPlugin,
// PerfUiPlugin,
#[cfg(feature = "dev")]
dev_tools::plugin,
));
Expand Down
Loading

0 comments on commit e08cf94

Please sign in to comment.