Skip to content

Commit

Permalink
update to Bevy 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Jul 7, 2024
1 parent 28e4c62 commit 075e101
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ name = "bevy_mod_physx"
path = "src/lib.rs"

[dependencies]
bevy = "0.13.0"
bevy = "0.14.0"
derive_more = "0.99.17"
enumflags2 = "0.7.7"
physx = "0.19.0"
physx-sys = "0.11.5"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
bevy-inspector-egui = "0.23.0"
bevy-inspector-egui = "0.25.0"

[features]
serialize = ["dep:serde", "bevy/serialize"]
8 changes: 4 additions & 4 deletions examples/articulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn spawn_long_chain(
let mut position = Vec3::new(0., 24., 0.);
let primitive = Capsule3d::new(RADIUS, HALF_HEIGHT + RADIUS * 2.);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(1., 0.7, 0.));
let material = materials.add(Color::srgb(1., 0.7, 0.));

let px_geometry = px_geometries.add(primitive);
let mut parent_link = None;
Expand Down Expand Up @@ -129,7 +129,7 @@ fn spawn_long_chain(

let primitive = Cuboid::from_size(Vec3::splat(BOX_SIZE * 2.));
let box_mesh = meshes.add(primitive);
let box_material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let box_material = materials.add(Color::srgb(0.8, 0.7, 0.6));
let box_geometry = px_geometries.add(primitive);

commands.spawn_empty()
Expand Down Expand Up @@ -180,7 +180,7 @@ fn spawn_obstacle(

let primitive = Cuboid::new(HALF_X * 2., HALF_Y * 2., HALF_Z * 2.);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let material = materials.add(Color::srgb(0.8, 0.7, 0.6));

let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));
Expand Down Expand Up @@ -212,7 +212,7 @@ fn spawn_plane(
) {
let primitive = Plane3d::default();
let mesh = meshes.add(primitive.mesh().size(500., 500.));
let material = materials.add(Color::rgb(0.3, 0.5, 0.3));
let material = materials.add(Color::srgb(0.3, 0.5, 0.3));
let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));

Expand Down
22 changes: 18 additions & 4 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::time::Duration;

use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::input::common_conditions::input_toggle_active;
use bevy::pbr::{DirectionalLightShadowMap, ShadowFilteringMethod};
use bevy::pbr::DirectionalLightShadowMap;
use bevy::prelude::*;
use bevy_mod_physx::prelude::*;

Expand All @@ -42,7 +42,7 @@ impl Plugin for DemoUtils {
}));
app.add_plugins(DebugRenderPlugin);

app.insert_resource(ClearColor(Color::rgb(0., 0., 0.)));
app.insert_resource(ClearColor(Color::srgb(0., 0., 0.)));
app.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0 / 5.0f32,
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Plugin for DemoUtils {
app.add_systems(Startup, |mut time: ResMut<Time<Virtual>>| time.pause());
}

app.add_systems(Update, bevy::window::close_on_esc);
app.add_systems(Update, close_on_esc);
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ fn adjust_camera_settings(
let (yaw, pitch, _roll) = transform.rotation.to_euler(EulerRot::YXZ);

commands.entity(entity)
.insert(ShadowFilteringMethod::Jimenez14)
// .insert(ShadowFilteringMethod::Jimenez14)
.insert(OrbitCamera {
gimbal_x: -yaw,
gimbal_y: -pitch,
Expand All @@ -127,3 +127,17 @@ fn spacebar_pauses_simulation(
}
}
}

pub fn close_on_esc(
mut commands: Commands,
focused_windows: Query<(Entity, &Window)>,
input: Res<ButtonInput<KeyCode>>,
) {
for (window, focus) in focused_windows.iter() {
if !focus.focused { continue; }

if input.just_pressed(KeyCode::Escape) {
commands.entity(window).despawn();
}
}
}
6 changes: 3 additions & 3 deletions examples/cube_stacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn spawn_plane(
) {
let primitive = Plane3d::default();
let mesh = meshes.add(primitive.mesh().size(500., 500.));
let material = materials.add(Color::rgb(0.3, 0.5, 0.3));
let material = materials.add(Color::srgb(0.3, 0.5, 0.3));
let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));

Expand Down Expand Up @@ -59,7 +59,7 @@ fn spawn_stacks(

let primitive = Cuboid::from_size(Vec3::splat(WIDTH));
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let material = materials.add(Color::srgb(0.8, 0.7, 0.6));

let px_geometry = px_geometries.add(primitive);

Expand Down Expand Up @@ -106,7 +106,7 @@ fn spawn_dynamic(

let primitive = Sphere::new(RADIUS);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let material = materials.add(Color::srgb(0.8, 0.7, 0.6));

let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));
Expand Down
8 changes: 4 additions & 4 deletions examples/detect_contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ fn init_materials(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.insert_resource(DemoMaterials {
normal: materials.add(Color::rgb(0.8, 0.7, 0.6)),
highlighted: materials.add(Color::rgb(0.3, 0.4, 0.9)),
normal: materials.add(Color::srgb(0.8, 0.7, 0.6)),
highlighted: materials.add(Color::srgb(0.3, 0.4, 0.9)),
});
}

Expand All @@ -151,7 +151,7 @@ fn spawn_plane(
) {
let primitive = Plane3d::default();
let mesh = meshes.add(primitive.mesh().size(500., 500.));
let material = materials.add(Color::rgb(0.3, 0.5, 0.3));
let material = materials.add(Color::srgb(0.3, 0.5, 0.3));
let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));

Expand Down Expand Up @@ -222,7 +222,7 @@ fn spawn_dynamic(
) {
let primitive = Sphere::new(1.25);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let material = materials.add(Color::srgb(0.8, 0.7, 0.6));

let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0., 0., 1.));
Expand Down
8 changes: 4 additions & 4 deletions examples/kinematic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn spawn_table(

let primitive = Cuboid::new(SIZE, THICKNESS, SIZE);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.3, 0.5, 0.3));
let material = materials.add(Color::srgb(0.3, 0.5, 0.3));
let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));

Expand All @@ -72,7 +72,7 @@ fn spawn_table(

let primitive = Cuboid::new(SIZE + THICKNESS, SIDE_HEIGHT, THICKNESS);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.3, 0.5, 0.3));
let material = materials.add(Color::srgb(0.3, 0.5, 0.3));
let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));

Expand Down Expand Up @@ -108,7 +108,7 @@ fn spawn_pyramid(
) {
let primitive = Sphere::new(BALL_SIZE);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let material = materials.add(Color::srgb(0.8, 0.7, 0.6));

let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0., 0., 1.));
Expand Down Expand Up @@ -149,7 +149,7 @@ fn spawn_kinematic(
) {
let primitive = Cuboid::new(CUE_SIZE, CUE_SIZE, CUE_SIZE);
let mesh = meshes.add(primitive);
let material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let material = materials.add(Color::srgb(0.8, 0.7, 0.6));

let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0., 0., 1.));
Expand Down
6 changes: 3 additions & 3 deletions examples/raycast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fn init_materials(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.insert_resource(DemoMaterials {
normal: materials.add(Color::rgb(0.8, 0.7, 0.6)),
highlighted: materials.add(Color::rgb(0.3, 0.4, 0.9)),
normal: materials.add(Color::srgb(0.8, 0.7, 0.6)),
highlighted: materials.add(Color::srgb(0.3, 0.4, 0.9)),
});
}

Expand All @@ -61,7 +61,7 @@ fn spawn_plane(
) {
let primitive = Plane3d::default();
let mesh = meshes.add(primitive.mesh().size(500., 500.));
let material = materials.add(Color::rgb(0.3, 0.5, 0.3));
let material = materials.add(Color::srgb(0.3, 0.5, 0.3));
let px_geometry = px_geometries.add(primitive);
let px_material = px_materials.add(bpx::Material::new(&mut physics, 0.5, 0.5, 0.6));

Expand Down
4 changes: 2 additions & 2 deletions examples/test_articulation_drives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive.mesh().size(1000., 1000.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
}
));

let primitive_root = Cuboid::from_size(Vec3::splat(0.5));
let bevy_material = materials.add(Color::rgb(0.8, 0.7, 0.6));
let bevy_material = materials.add(Color::srgb(0.8, 0.7, 0.6));
let root_mesh = meshes.add(primitive_root);
let root_geometry = px_geometries.add(primitive_root);
let primitive_part = Sphere::new(0.2);
Expand Down
6 changes: 3 additions & 3 deletions examples/test_convex_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive.mesh().size(1000., 1000.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
}
));
Expand All @@ -102,7 +102,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(-2.0, 7.0, 0.0).with_rotation(Quat::from_rotation_z(-1.)),
..default()
},
Expand All @@ -129,7 +129,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(2.0, 7.0, 0.0).with_rotation(Quat::from_rotation_z(-1.)),
..default()
},
Expand Down
6 changes: 3 additions & 3 deletions examples/test_damping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive.mesh().size(1000., 1000.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
}
));
Expand All @@ -47,7 +47,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(-2.0, 7.0, 0.0),
..default()
},
Expand All @@ -65,7 +65,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(2.0, 7.0, 0.0),
..default()
},
Expand Down
4 changes: 2 additions & 2 deletions examples/test_fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive.mesh().size(1000., 1000.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
}
));
Expand All @@ -59,7 +59,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(2.0, 7.0, 0.0),
..default()
},
Expand Down
8 changes: 4 additions & 4 deletions examples/test_mass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive.mesh().size(1000., 1000.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
},
RigidBody::Static,
Expand All @@ -43,7 +43,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(-1.2, 5.0, 0.0),
..default()
},
Expand All @@ -59,7 +59,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(1.2, 5.0, 0.0),
..default()
},
Expand All @@ -75,7 +75,7 @@ pub fn spawn_scene(
commands.spawn((
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 1.0, 0.0),
..default()
},
Expand Down
6 changes: 3 additions & 3 deletions examples/test_restitution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive.mesh().size(1000., 1000.)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
}
));
Expand All @@ -53,7 +53,7 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(-2.0, 5.0, 0.0),
..default()
}
Expand All @@ -70,7 +70,7 @@ pub fn spawn_scene(
},
PbrBundle {
mesh: meshes.add(primitive),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(2.0, 5.0, 0.0),
..default()
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum GeometryInner {
// thus a lot of complications here
Plane {
plane: PxPlaneGeometry,
normal: Direction3d,
normal: Dir3,
},

// for convexmesh and triangle mesh we have to own the mesh,
Expand Down Expand Up @@ -94,7 +94,7 @@ impl From<PxSphereGeometry> for Geometry {
impl From<PxPlaneGeometry> for Geometry {
fn from(value: PxPlaneGeometry) -> Self {
// makes more sense to default normal to Y axis (ground), but physx defaults to X axis
Self { obj: GeometryInner::Plane { plane: value, normal: Direction3d::X } }
Self { obj: GeometryInner::Plane { plane: value, normal: Dir3::X } }
}
}

Expand Down Expand Up @@ -183,7 +183,7 @@ impl Geometry {
note = "please use Bevy's `Plane3d` primitive (e.g. using `Geometry::from`)"
)]
pub fn halfspace(outward_normal: Vec3) -> Self {
Plane3d::new(outward_normal).into()
Plane3d::new(outward_normal, Default::default()).into()
}

#[deprecated(
Expand Down
Loading

0 comments on commit 075e101

Please sign in to comment.