Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
## Modified

- Update Bevy to `0.16`.
- Update from rapier `0.23` to rapier `0.24`,
- Update from rapier `0.23` to rapier `0.25`,
see [rapier's changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md).
- Notably, support and examples for parry's new `Voxels` shape have been added.
- `RapierContextInitialization::InitializeDefaultRapierContext` now has more fields for better control over default physics context.

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"]
[dependencies]
bevy = { version = "0.16.0", default-features = false, features = ["std"] }
nalgebra = { version = "0.33", features = ["convert-glam029"] }
rapier2d = "0.24"
rapier2d = "0.25"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
10 changes: 10 additions & 0 deletions bevy_rapier2d/examples/testbed2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod locked_rotations2;
mod multiple_colliders2;
mod player_movement2;
mod rope_joint2;
mod voxels2;

use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
Expand All @@ -22,6 +23,7 @@ pub enum Examples {
#[default]
None,
Boxes2,
Voxels2,
DebugToggle2,
RopeJoint2,
DebugDespawn2,
Expand Down Expand Up @@ -75,6 +77,7 @@ fn main() {
.init_state::<Examples>()
.insert_resource(ExampleSet(vec![
(Examples::Boxes2, "Boxes3").into(),
(Examples::Voxels2, "Voxels2").into(),
(Examples::RopeJoint2, "RopeJoint2").into(),
(Examples::DebugDespawn2, "DebugDespawn2").into(),
(Examples::Despawn2, "Despawn3").into(),
Expand All @@ -94,6 +97,13 @@ fn main() {
)
.add_systems(OnExit(Examples::Boxes2), cleanup)
//
//voxels2
.add_systems(
OnEnter(Examples::Voxels2),
(voxels2::setup_graphics, voxels2::setup_physics),
)
.add_systems(OnExit(Examples::Voxels2), cleanup)
//
// Debug toggle
.add_systems(
OnEnter(Examples::DebugToggle2),
Expand Down
105 changes: 105 additions & 0 deletions bevy_rapier2d/examples/voxels2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use nalgebra::{point, Vector2};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relying on nalgebra types here is not great, but I'm not sure duplicating API on library's side is great either 🤔

use rapier2d::prelude::{SharedShape, VoxelPrimitiveGeometry};

fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(
0xF9 as f32 / 255.0,
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_plugins((
DefaultPlugins,
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(10.0),
RapierDebugRenderPlugin::default(),
))
.add_systems(Startup, (setup_graphics, setup_physics))
.run();
}

pub fn setup_graphics(mut commands: Commands) {
commands.spawn((Camera2d, Transform::from_xyz(0.0, 20.0, 0.0)));
}

pub fn setup_physics(mut commands: Commands) {
let scale = 15f32;
/*
* Create dynamic objects to fall on voxels.
*/
let nx = 50;
for i in 0..nx {
for j in 0..10 {
let falling_objects = (j + i) % 3;

let ball_radius = 0.5 * scale;
let co = match falling_objects {
0 => Collider::ball(ball_radius),
1 => Collider::cuboid(ball_radius, ball_radius),
2 => Collider::capsule_y(ball_radius, ball_radius),
_ => unreachable!(),
};
commands.spawn((
Transform::from_xyz(
(i as f32 * 2.0 - nx as f32 / 2.0) * scale,
(20.0 + j as f32 * 2.0) * scale,
0.0,
),
RigidBody::Dynamic,
co,
));
}
}

/*
* Voxelization.
*/
let polyline = vec![
point![0.0, 0.0],
point![0.0, 10.0],
point![7.0, 4.0],
point![14.0, 10.0],
point![14.0, 0.0],
point![13.0, 7.0],
point![7.0, 2.0],
point![1.0, 7.0],
]
.iter()
.map(|p| p * scale)
.collect::<Vec<_>>();
let indices: Vec<_> = (0..polyline.len() as u32)
.map(|i| [i, (i + 1) % polyline.len() as u32])
.collect();

let shape = SharedShape::voxelized_mesh(
VoxelPrimitiveGeometry::PseudoCube,
&polyline,
&indices,
0.2 * scale,
FillMode::default(),
);
commands.spawn((
Transform::from_xyz(-20.0 * scale, -10.0 * scale, 0.0),
Collider::from(shape),
));

/*
* A voxel wavy floor.
*/
let voxel_size = Vector2::new(scale, scale);
let voxels: Vec<_> = (0..300)
.map(|i| {
let y = (i as f32 / 20.0).sin().clamp(-0.5, 0.5) * 20.0;
point![(i as f32 - 125.0) * voxel_size.x / 2.0, y * voxel_size.y]
})
.collect();
commands.spawn((
Transform::from_xyz(0.0, 0.0, 0.0),
Collider::from(rapier2d::prelude::SharedShape::voxels_from_points(
VoxelPrimitiveGeometry::PseudoCube,
voxel_size,
&voxels,
)),
));
}
2 changes: 1 addition & 1 deletion bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"]
[dependencies]
bevy = { version = "0.16.0", default-features = false, features = ["std"] }
nalgebra = { version = "0.33", features = ["convert-glam029"] }
rapier3d = "0.24"
rapier3d = "0.25"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
12 changes: 11 additions & 1 deletion bevy_rapier3d/examples/testbed3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod multiple_colliders3;
mod picking3;
mod ray_casting3;
mod static_trimesh3;
mod voxels3;

use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
Expand All @@ -22,6 +23,7 @@ pub enum Examples {
#[default]
None,
Boxes3,
Voxels3,
DebugToggle3,
Despawn3,
Events3,
Expand Down Expand Up @@ -76,6 +78,7 @@ fn main() {
.init_state::<Examples>()
.insert_resource(ExampleSet(vec![
(Examples::Boxes3, "Boxes3").into(),
(Examples::Voxels3, "Voxels3").into(),
(Examples::DebugToggle3, "DebugToggle3").into(),
(Examples::Despawn3, "Despawn3").into(),
(Examples::Events3, "Events3").into(),
Expand All @@ -89,13 +92,20 @@ fn main() {
]))
.init_resource::<ExampleSelected>()
//
//boxes2
// boxes3
.add_systems(
OnEnter(Examples::Boxes3),
(boxes3::setup_graphics, boxes3::setup_physics),
)
.add_systems(OnExit(Examples::Boxes3), cleanup)
//
// voxels3
.add_systems(
OnEnter(Examples::Voxels3),
(voxels3::setup_graphics, voxels3::setup_physics),
)
.add_systems(OnExit(Examples::Voxels3), cleanup)
//
// Debug toggle
.add_systems(
OnEnter(Examples::DebugToggle3),
Expand Down
104 changes: 104 additions & 0 deletions bevy_rapier3d/examples/voxels3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
use nalgebra::{point, Isometry, Vector3};
use rapier3d::prelude::VoxelPrimitiveGeometry;

fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(
0xF9 as f32 / 255.0,
0xF9 as f32 / 255.0,
0xFF as f32 / 255.0,
)))
.add_plugins((
DefaultPlugins,
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
))
.add_systems(Startup, (setup_graphics, setup_physics))
.run();
}

pub fn setup_graphics(mut commands: Commands) {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-100.0, 100.0, -100.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
));
}

pub fn setup_physics(mut commands: Commands) {
/*
* Create a voxelized wavy floor.
*/
let voxel_size = Vector3::new(1f32, 1f32, 1f32);
let mut samples = vec![];
let n = 200;
for i in 0..n {
for j in 0..n {
let y = (i as f32 / n as f32 * 10.0).sin().clamp(-0.8, 0.8)
* (j as f32 / n as f32 * 10.0).cos().clamp(-0.8, 0.8)
* 16.0;

samples.push(point![
i as f32 * voxel_size.x,
y * voxel_size.y,
j as f32 * voxel_size.z
]);

if i == 0 || i == n - 1 || j == 0 || j == n - 1 {
// Create walls so the object at the edge don’t fall into the infinite void.
for k in 0..4 {
samples.push(point![
i as f32 * voxel_size.x,
(y + k as f32) * voxel_size.y,
j as f32 * voxel_size.z
]);
}
}
}
}
let collider = rapier3d::prelude::SharedShape::voxels_from_points(
VoxelPrimitiveGeometry::PseudoCube,
voxel_size,
&samples,
);
let ground_position = Vec3::new(voxel_size.x / 2f32, 0.0, voxel_size.z / 2f32);
let floor_aabb = collider.compute_aabb(&Isometry::identity());
commands.spawn((
Transform::from_translation(ground_position),
Collider::from(collider),
));

/*
* Create dynamic objects to fall on voxels.
*/
let extents = floor_aabb.extents() * 0.75;
let margin = (floor_aabb.extents() - extents) / 2.0;
let nik = 30;
for i in 0..nik {
for j in 0..5 {
for k in 0..nik {
let falling_objects = (j + i + k) % 3;

let ball_radius = 0.5;
let co = match falling_objects {
0 => Collider::ball(ball_radius),
1 => Collider::cuboid(ball_radius, ball_radius, ball_radius),
2 => Collider::capsule_y(ball_radius, ball_radius),
_ => unreachable!(),
};
commands.spawn((
Transform::from_xyz(
floor_aabb.mins.x + margin.x + i as f32 * extents.x / nik as f32
- ground_position.x,
floor_aabb.maxs.y + j as f32 * 2.0 - ground_position.y,
floor_aabb.mins.z + margin.z + k as f32 * extents.z / nik as f32
- -ground_position.z,
),
RigidBody::Dynamic,
co,
));
}
}
}
}
2 changes: 1 addition & 1 deletion bevy_rapier_benches3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rapier3d = { features = ["profiler"], version = "0.23" }
rapier3d = { features = ["profiler"], version = "0.25" }
bevy_rapier3d = { version = "0.29", path = "../bevy_rapier3d" }
bevy = { version = "0.16.0", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier_benches3d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For short-lived benchmarks based on statistical analysis,
benchmarks can be run through the [divan](https://github.com/nvzqz/divan) bench harness.

```sh
cargo bench -p bevy_rapier3d
cargo bench -p bevy_rapier_benches3d
```

## Other resources
Expand Down
1 change: 0 additions & 1 deletion bevy_rapier_benches3d/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub fn default_app() -> App {
app.add_plugins((
MinimalPlugins,
TransformPlugin,
TransformPlugin,
RapierPhysicsPlugin::<()>::default(),
));

Expand Down
Loading
Loading