update to bevy 0.15

This commit is contained in:
Joe Ardent 2024-12-15 14:11:06 -08:00
parent c03779aa62
commit 008ef5a3f8
6 changed files with 1507 additions and 788 deletions

2210
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
avian3d = "0.1.1" avian3d = { git = "https://github.com/Jondolf/avian.git" }
bevy = { version = "0.14.0", features = ["bevy_dev_tools"] } bevy = { version = "0.15", features = ["bevy_dev_tools"] }
bevy-inspector-egui = "0.25.1" bevy-inspector-egui = "0.28"
[features] [features]
no-mesh = [] no-mesh = []

View file

@ -35,7 +35,7 @@ fn spawn_bike(
Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8)); Collider::capsule_endpoints(0.5, Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8));
let bike = commands let bike = commands
.spawn(SpatialBundle::from_transform(xform)) .spawn((xform, Visibility::default()))
.insert(( .insert((
Name::new("body"), Name::new("body"),
RigidBody::Dynamic, RigidBody::Dynamic,
@ -56,12 +56,11 @@ fn spawn_bike(
let color = Color::srgb(0.7, 0.05, 0.7); let color = Color::srgb(0.7, 0.05, 0.7);
let mut rotation = Transform::default(); // Transform::from_rotation(Quat::from_rotation_y(FRAC_PI_2)); let mut rotation = Transform::default(); // Transform::from_rotation(Quat::from_rotation_y(FRAC_PI_2));
rotation.rotate_x(FRAC_PI_2); rotation.rotate_x(FRAC_PI_2);
let pbr_bundle = PbrBundle { let pbr_bundle = (
mesh: meshes.add(Capsule3d::new(0.5, 1.45)), Mesh3d(meshes.add(Capsule3d::new(0.5, 1.45))),
transform: rotation, rotation,
material: materials.add(color), MeshMaterial3d(materials.add(color)),
..Default::default() );
};
builder.spawn(pbr_bundle); builder.spawn(pbr_bundle);
}) })
.id(); .id();
@ -163,25 +162,19 @@ fn wheels_helper(
.spawn(( .spawn((
Name::new("hub"), Name::new("hub"),
RigidBody::Dynamic, RigidBody::Dynamic,
MassPropertiesBundle::new_computed(&Collider::sphere(0.1), 200.0), MassPropertiesBundle::from_shape(&Collider::sphere(0.1), 200.0),
PbrBundle { Mesh3d(meshes.add(hub_mesh)),
mesh: meshes.add(hub_mesh), MeshMaterial3d(materials.add(wheel_material.clone())),
material: materials.add(wheel_material.clone()), xform,
transform: xform,
..Default::default()
},
)) ))
.id(); .id();
let tire = commands let tire = commands
.spawn(( .spawn((
Name::new("tire"), Name::new("tire"),
PbrBundle { Mesh3d(meshes.add(tire_mesh)),
mesh: meshes.add(tire_mesh), MeshMaterial3d(materials.add(wheel_material.clone())),
material: materials.add(wheel_material.clone()), xform,
transform: xform,
..Default::default()
},
CyberWheel, CyberWheel,
RigidBody::Dynamic, RigidBody::Dynamic,
collider, collider,

View file

@ -23,9 +23,7 @@ impl Default for DebugCamOffset {
} }
fn spawn_camera(mut commands: Commands) { fn spawn_camera(mut commands: Commands) {
commands commands.spawn(Camera3d::default()).insert(CyberCameras);
.spawn(Camera3dBundle::default())
.insert(CyberCameras);
} }
fn update_camera_pos(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<ButtonInput<KeyCode>>) { fn update_camera_pos(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<ButtonInput<KeyCode>>) {

View file

@ -1,14 +1,14 @@
use avian3d::prelude::{ use avian3d::prelude::{
Collider, ColliderDensity, CollisionMargin, Friction, PhysicsGizmos, RigidBody, Collider, ColliderDensity, CollisionLayers, CollisionMargin, Friction, PhysicsGizmos, RigidBody,
}; };
use bevy::{ use bevy::{
self,
color::palettes::css::SILVER, color::palettes::css::SILVER,
pbr::MeshMaterial3d,
prelude::{ prelude::{
default, App, AppGizmoBuilder, Assets, BuildChildren, ButtonInput, Color, Commands, default, App, AppGizmoBuilder, Assets, BuildChildren, ButtonInput, ChildBuild, Color,
DefaultPlugins, Entity, GizmoConfig, KeyCode, Mesh, Meshable, PbrBundle, Plane3d, Commands, DefaultPlugins, Entity, GizmoConfig, KeyCode, Mesh, Mesh3d, Meshable, Plane3d,
PointLight, PointLightBundle, Query, Res, ResMut, SpatialBundle, Srgba, StandardMaterial, PointLight, Query, Res, ResMut, Srgba, StandardMaterial, Startup, Transform, Update, Vec3,
Startup, Transform, Update, Vec3, Window, Visibility, Window,
}, },
}; };
use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_inspector_egui::quick::WorldInspectorPlugin;
@ -52,34 +52,36 @@ fn ground_and_light(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let spatial_bundle = (Transform::default(), Visibility::default());
commands commands
.spawn(( .spawn((
SpatialBundle::default(), spatial_bundle,
RigidBody::Static, RigidBody::Static,
Collider::cuboid(50.0, 0.5, 50.0), Collider::cuboid(50.0, 5., 50.0),
CollisionMargin(0.1), CollisionMargin(0.1),
ColliderDensity(1000.0), ColliderDensity(1000.0),
CollisionLayers::ALL,
Friction::new(0.9), Friction::new(0.9),
)) ))
.with_children(|p| { .with_children(|p| {
p.spawn(PbrBundle { let bundle = (
mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)), Mesh3d(meshes.add(Plane3d::default().mesh().size(50.0, 50.0))),
material: materials.add(Color::from(SILVER)), MeshMaterial3d(materials.add(Color::from(SILVER))),
transform: Transform::from_xyz(0.0, 0.4, 0.0), Transform::from_xyz(0.0, 2.5, 0.0),
..default() Visibility::Visible,
}); );
p.spawn(bundle);
}); });
commands.spawn(PointLightBundle { commands.spawn((
point_light: PointLight { PointLight {
intensity: 8_000_000.0, intensity: 8_000_000.0,
range: 100., range: 100.,
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },
transform: Transform::from_xyz(8.0, 16.0, 8.0), Transform::from_xyz(8.0, 16.0, 8.0),
..default() ));
});
} }
fn close_on_esc( fn close_on_esc(

View file

@ -146,7 +146,7 @@ mod systems {
// only try to correct roll if we're not totally vertical // only try to correct roll if we're not totally vertical
if pitch_error.abs() < 0.95 { if pitch_error.abs() < 0.95 {
let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_seconds()); let (derivative, integral) = control_vars.update_roll(roll_error, time.delta_secs());
let mag = let mag =
(settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative); (settings.kp * roll_error) + (settings.ki * integral) + (settings.kd * derivative);
if mag.is_finite() { if mag.is_finite() {