Skip to content

Commit

Permalink
Merge pull request #68 from voximity/migrate-0.15
Browse files Browse the repository at this point in the history
Migrate to Bevy 0.15
  • Loading branch information
idanarye authored Dec 12, 2024
2 parents 89c9653 + 133f7b3 commit 9cf0707
Show file tree
Hide file tree
Showing 27 changed files with 163 additions and 219 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ exclude = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "^0.14", default-features = false }
bevy = { version = "^0.15", default-features = false }
bevy-tnua-physics-integration-layer = { version = "0.4.0", path = "physics-integration-layer" }
thiserror = "1.0.53"

[dev-dependencies]
bevy = { version = "^0.14", default-features = false, features = [
bevy = { version = "^0.15", default-features = false, features = [
"animation",
"bevy_asset",
# "bevy_audio",
Expand All @@ -58,7 +58,7 @@ bevy = { version = "^0.14", default-features = false, features = [
"x11",
# "filesystem_watcher",
] }
avian3d = { version = "^0.1", features = ["3d", "debug-plugin", "parallel", "parry-f32"] }
avian3d = { git = "https://github.com/Jondolf/avian", features = ["3d", "debug-plugin", "parallel", "parry-f32"] }
bevy-tnua-avian3d = { path = "avian3d" }

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions avian2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ documentation = "https://docs.rs/bevy-tnua-avian2d"
readme = "../README.md"

[dependencies]
bevy = { version = "^0.14", default-features = false }
avian2d = {version = "^0.1", default-features = false, features = ["2d", "debug-plugin", "parallel"]}
bevy = { version = "^0.15", default-features = false }
avian2d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["2d", "debug-plugin", "parallel"]}
bevy-tnua-physics-integration-layer = { version = "^0.4", path = "../physics-integration-layer" }

[package.metadata.docs.rs]
Expand Down
19 changes: 11 additions & 8 deletions avian2d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,17 @@ fn update_proximity_sensors_system(
cast_origin.truncate().adjust_precision(),
0.0,
cast_direction_2d,
sensor.cast_range,
true,
query_filter,
&ShapeCastConfig {
max_distance: sensor.cast_range,
ignore_origin_penetration: true,
..default()
},
&query_filter,
#[allow(clippy::useless_conversion)]
|shape_hit_data| {
apply_cast(CastResult {
entity: shape_hit_data.entity,
proximity: shape_hit_data.time_of_impact,
proximity: shape_hit_data.distance,
intersection_point: shape_hit_data.point1,
normal: Dir3::new(shape_hit_data.normal1.extend(0.0).f32())
.unwrap_or_else(|_| -cast_direction),
Expand All @@ -275,13 +278,13 @@ fn update_proximity_sensors_system(
cast_direction_2d,
sensor.cast_range,
true,
query_filter,
&query_filter,
|ray_hit_data| {
apply_cast(CastResult {
entity: ray_hit_data.entity,
proximity: ray_hit_data.time_of_impact,
proximity: ray_hit_data.distance,
intersection_point: cast_origin.truncate().adjust_precision()
+ ray_hit_data.time_of_impact.adjust_precision()
+ ray_hit_data.distance.adjust_precision()
* cast_direction_2d.adjust_precision(),
normal: Dir3::new(ray_hit_data.normal.extend(0.0).f32())
.unwrap_or_else(|_| -cast_direction),
Expand All @@ -301,7 +304,7 @@ fn apply_motors_system(
&mut LinearVelocity,
&mut AngularVelocity,
&Mass,
&Inertia,
&AngularInertia,
&mut ExternalForce,
&mut ExternalTorque,
Option<&TnuaToggle>,
Expand Down
4 changes: 2 additions & 2 deletions avian3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ documentation = "https://docs.rs/bevy-tnua-avian3d"
readme = "../README.md"

[dependencies]
bevy = { version = "^0.14", default-features = false }
avian3d = {version = "^0.1", default-features = false, features = ["3d", "debug-plugin", "parallel"] }
bevy = { version = "^0.15", default-features = false }
avian3d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["3d", "debug-plugin", "parallel"] }
bevy-tnua-physics-integration-layer = { version = "^0.4", path = "../physics-integration-layer" }

[package.metadata.docs.rs]
Expand Down
26 changes: 16 additions & 10 deletions avian3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//! * Optionally: Add [`TnuaAvian3dSensorShape`] to the sensor entities. This means the entity of
//! the characters controlled by Tnua, but also other things like the entity generated by
//! `TnuaCrouchEnforcer`, that can be affected with a closure.
use avian3d::{prelude::*, schedule::PhysicsStepSet};
use avian3d::{
dynamics::rigid_body::mass_properties::components::GlobalAngularInertia, prelude::*,
schedule::PhysicsStepSet,
};
use bevy::ecs::schedule::{InternedScheduleLabel, ScheduleLabel};
use bevy::prelude::*;
use bevy_tnua_physics_integration_layer::math::AdjustPrecision;
Expand Down Expand Up @@ -265,13 +268,16 @@ fn update_proximity_sensors_system(
cast_origin,
owner_rotation.adjust_precision(),
cast_direction,
sensor.cast_range,
true,
query_filter,
&ShapeCastConfig {
max_distance: sensor.cast_range,
ignore_origin_penetration: true,
..default()
},
&query_filter,
|shape_hit_data| {
apply_cast(CastResult {
entity: shape_hit_data.entity,
proximity: shape_hit_data.time_of_impact,
proximity: shape_hit_data.distance,
intersection_point: shape_hit_data.point1,
normal: Dir3::new(shape_hit_data.normal1.f32())
.unwrap_or_else(|_| -cast_direction),
Expand All @@ -284,13 +290,13 @@ fn update_proximity_sensors_system(
cast_direction,
sensor.cast_range,
true,
query_filter,
&query_filter,
|ray_hit_data| {
apply_cast(CastResult {
entity: ray_hit_data.entity,
proximity: ray_hit_data.time_of_impact,
proximity: ray_hit_data.distance,
intersection_point: cast_origin
+ ray_hit_data.time_of_impact * cast_direction.adjust_precision(),
+ ray_hit_data.distance * cast_direction.adjust_precision(),
normal: Dir3::new(ray_hit_data.normal.f32())
.unwrap_or_else(|_| -cast_direction),
})
Expand All @@ -309,7 +315,7 @@ fn apply_motors_system(
&mut LinearVelocity,
&mut AngularVelocity,
&Mass,
&Inertia,
&GlobalAngularInertia,
&mut ExternalForce,
&mut ExternalTorque,
Option<&TnuaToggle>,
Expand Down Expand Up @@ -346,7 +352,7 @@ fn apply_motors_system(
external_torque.set_torque(
// NOTE: I did not actually verify that this is the correct formula. Nothing uses
// angular acceleration yet - only angular impulses.
inertia.0 * motor.ang.acceleration,
inertia.value() * motor.ang.acceleration,
);
}
}
Expand Down
18 changes: 10 additions & 8 deletions demos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ avian2d = ["avian", "dep:avian2d", "dep:bevy-tnua-avian2d"]
avian3d = ["avian", "dep:avian3d", "dep:bevy-tnua-avian3d"]

[dependencies]
bevy = { version = "^0.14", default-features = false, features = [
bevy = { version = "^0.15", default-features = false, features = [
"animation",
"bevy_asset",
# "bevy_audio",
Expand All @@ -44,6 +44,8 @@ bevy = { version = "^0.14", default-features = false, features = [
"zstd",
"tonemapping_luts",
"bevy_text",
"bevy_window",
"bevy_ui",
# "png",
# "hdr",
# "vorbis",
Expand All @@ -53,21 +55,21 @@ bevy = { version = "^0.14", default-features = false, features = [
bevy-tnua = { path = ".." }
bevy-tnua-physics-integration-layer = { path = "../physics-integration-layer" }

bevy_rapier2d = { version = "^0.27", features = ["debug-render-2d"], optional = true }
bevy_rapier2d = { version = "^0.28", features = ["debug-render-2d"], optional = true }
bevy-tnua-rapier2d = { path = "../rapier2d", optional = true }

bevy_rapier3d = { version = "^0.27", features = ["debug-render-3d"], optional = true }
bevy_rapier3d = { version = "^0.28", features = ["debug-render-3d"], optional = true }
bevy-tnua-rapier3d = { path = "../rapier3d", optional = true }

avian2d = {version = "^0.1", default-features = false, features = ["2d","debug-plugin", "parallel"], optional = true}
avian2d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["2d","debug-plugin", "parallel"], optional = true}
bevy-tnua-avian2d = { path = "../avian2d", default-features = false, optional = true }

avian3d = {version = "^0.1", default-features = false, features = ["3d","debug-plugin", "parallel"], optional = true }
avian3d = { git = "https://github.com/Jondolf/avian", default-features = false, features = ["3d","debug-plugin", "parallel"], optional = true }
bevy-tnua-avian3d = { path = "../avian3d", default-features = false, optional = true }

bevy_egui = { version = "0.28", optional = true, default-features = false, features = ["default_fonts", "render"] }
egui_plot = { version = "0.28", optional = true }
egui_extras = { version = "0.28", optional = true }
bevy_egui = { version = "0.31", optional = true, default-features = false, features = ["default_fonts", "render"] }
egui_plot = { version = "0.29", optional = true }
egui_extras = { version = "0.29", optional = true }

bevy_framepace = { version = "0.17", optional = true }

Expand Down
21 changes: 9 additions & 12 deletions demos/src/bin/platformer_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn main() {
}
ScheduleToUse::PhysicsSchedule => {
app.add_plugins(PhysicsPlugins::default());
app.insert_resource(Time::new_with(Physics::fixed_hz(144.0)));
app.insert_resource(Time::from_hz(144.0));
app.add_plugins(TnuaAvian2dPlugin::new(PhysicsSchedule));
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ fn main() {
app.add_plugins(LevelMechanicsPlugin);
#[cfg(feature = "rapier2d")]
{
app.add_systems(Startup, |mut cfg: ResMut<RapierConfiguration>| {
app.add_systems(Startup, |mut cfg: Single<&mut RapierConfiguration>| {
// For some odd reason, Rapier 2D defaults to a gravity of 98.1
cfg.gravity = Vec2::Y * -9.81;
});
Expand All @@ -145,23 +145,20 @@ fn main() {
}

fn setup_camera_and_lights(mut commands: Commands) {
commands.spawn(Camera2dBundle {
transform: Transform::from_xyz(0.0, 14.0, 30.0)
commands.spawn((
Camera2d,
Transform::from_xyz(0.0, 14.0, 30.0)
.with_scale((0.05 * Vec2::ONE).extend(1.0))
.looking_at(Vec3::new(0.0, 14.0, 0.0), Vec3::Y),
..Default::default()
});
));

commands.spawn(PointLightBundle {
transform: Transform::from_xyz(5.0, 5.0, 5.0),
..default()
});
commands.spawn((PointLight::default(), Transform::from_xyz(5.0, 5.0, 5.0)));
}

fn setup_player(mut commands: Commands) {
let mut cmd = commands.spawn(IsPlayer);
cmd.insert(TransformBundle::default());
cmd.insert(VisibilityBundle::default());
cmd.insert(Transform::default());
cmd.insert(Visibility::default());

// The character entity must be configured as a dynamic rigid body of the physics backend.
#[cfg(feature = "rapier2d")]
Expand Down
30 changes: 11 additions & 19 deletions demos/src/bin/platformer_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn main() {
}
ScheduleToUse::PhysicsSchedule => {
app.add_plugins(PhysicsPlugins::default());
app.insert_resource(Time::new_with(Physics::fixed_hz(144.0)));
app.insert_resource(Time::from_hz(144.0));
app.add_plugins(TnuaAvian3dPlugin::new(PhysicsSchedule));
}
}
Expand Down Expand Up @@ -148,34 +148,26 @@ fn main() {
}

fn setup_camera_and_lights(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 16.0, 40.0)
.looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y),
..Default::default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 16.0, 40.0).looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y),
));

commands.spawn(PointLightBundle {
transform: Transform::from_xyz(5.0, 5.0, 5.0),
..default()
});
commands.spawn((PointLight::default(), Transform::from_xyz(5.0, 5.0, 5.0)));

commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
commands.spawn((
DirectionalLight {
illuminance: 4000.0,
shadows_enabled: true,
..Default::default()
},
transform: Transform::default().looking_at(-Vec3::Y, Vec3::Z),
..Default::default()
});
Transform::default().looking_at(-Vec3::Y, Vec3::Z),
));
}

fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
let mut cmd = commands.spawn(IsPlayer);
cmd.insert(SceneBundle {
scene: asset_server.load("player.glb#Scene0"),
..Default::default()
});
cmd.insert(SceneRoot(asset_server.load("player.glb#Scene0")));
cmd.insert(GltfSceneHandler {
names_from: asset_server.load("player.glb"),
});
Expand Down
Loading

0 comments on commit 9cf0707

Please sign in to comment.