Skip to content

Commit 8acf11e

Browse files
committed
wip rapier_0.27
1 parent 4efc34b commit 8acf11e

File tree

15 files changed

+307
-642
lines changed

15 files changed

+307
-642
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
- Expose `RapierBevyComponentApply`, to help with creating your own schedules when you set `default_system_setup` to `false`.
88
- Add `set_local_axis1` and `set_local_axis2` to `RevoluteJoint` and `RevoluteJointBuilder`. [#666](https://github.com/dimforge/bevy_rapier/pull/666)
99

10+
### Modified
11+
12+
- Update from rapier `0.25` to rapier `0.27`,
13+
see [rapier's changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md).
14+
1015
### Fix
1116

1217
- Fix scale being applied with a frame delay. [#659](https://github.com/dimforge/bevy_rapier/pull/659)

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ codegen-units = 1
1313
#nalgebra = { path = "../nalgebra" }
1414
#parry2d = { path = "../parry/crates/parry2d" }
1515
#parry3d = { path = "../parry/crates/parry3d" }
16-
# rapier2d = { path = "../rapier/crates/rapier2d" }
17-
# rapier3d = { path = "../rapier/crates/rapier3d" }
16+
rapier2d = { path = "../rapier/crates/rapier2d" }
17+
rapier3d = { path = "../rapier/crates/rapier3d" }
1818
#nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "dev" }
1919
#parry2d = { git = "https://github.com/dimforge/parry", branch = "master" }
2020
#parry3d = { git = "https://github.com/dimforge/parry", branch = "master" }

bevy_rapier2d/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"]
6666
[dependencies]
6767
bevy = { version = "0.16.0", default-features = false, features = ["std"] }
6868
nalgebra = { version = "0.33", features = ["convert-glam029"] }
69-
rapier2d = "0.25"
69+
rapier2d = "0.27.0-beta.0"
7070
bitflags = "2.4"
7171
log = "0.4"
7272
serde = { version = "1", features = ["derive"], optional = true }

bevy_rapier2d/examples/voxels2.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bevy::prelude::*;
22
use bevy_rapier2d::prelude::*;
3-
use rapier2d::prelude::VoxelPrimitiveGeometry;
43

54
fn main() {
65
App::new()
@@ -73,13 +72,7 @@ pub fn setup_physics(mut commands: Commands) {
7372

7473
commands.spawn((
7574
Transform::from_xyz(-20.0 * scale, -10.0 * scale, 0.0),
76-
Collider::voxelized_mesh(
77-
VoxelPrimitiveGeometry::PseudoCube,
78-
&polyline,
79-
&indices,
80-
0.2 * scale,
81-
FillMode::default(),
82-
),
75+
Collider::voxelized_mesh(&polyline, &indices, 0.2 * scale, FillMode::default()),
8376
));
8477

8578
/*
@@ -94,6 +87,6 @@ pub fn setup_physics(mut commands: Commands) {
9487
.collect();
9588
commands.spawn((
9689
Transform::from_xyz(0.0, 0.0, 0.0),
97-
Collider::voxels_from_points(VoxelPrimitiveGeometry::PseudoCube, voxel_size, &voxels),
90+
Collider::voxels_from_points(voxel_size, &voxels),
9891
));
9992
}

bevy_rapier3d/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"]
6767
[dependencies]
6868
bevy = { version = "0.16.0", default-features = false, features = ["std"] }
6969
nalgebra = { version = "0.33", features = ["convert-glam029"] }
70-
rapier3d = "0.25"
70+
rapier3d = "0.27.0-beta.0"
7171
bitflags = "2.4"
7272
log = "0.4"
7373
serde = { version = "1", features = ["derive"], optional = true }

bevy_rapier_benches3d/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
rapier3d = { features = ["profiler"], version = "0.25" }
12+
rapier3d = { features = ["profiler"], version = "0.27.0-beta.0" }
1313
bevy_rapier3d = { version = "0.30", path = "../bevy_rapier3d" }
1414
bevy = { version = "0.16.0", default-features = false }
1515

src/geometry/collider_impl.rs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88

99
use rapier::{
1010
parry::transformation::voxelization::FillMode,
11-
prelude::{FeatureId, Point, Ray, SharedShape, Vector, VoxelPrimitiveGeometry, Voxels, DIM},
11+
prelude::{FeatureId, Point, Ray, SharedShape, Vector, Voxels, DIM},
1212
};
1313

1414
use super::{get_snapped_scale, shape_views::*};
@@ -183,15 +183,10 @@ impl Collider {
183183
/// For initializing a voxels shape from a mesh to voxelize, see [`Self::voxelized_mesh`].
184184
/// For initializing multiple voxels shape from the convex decomposition of a mesh, see
185185
/// [`Self::voxelized_convex_decomposition`].
186-
pub fn voxels(
187-
primitive_geometry: VoxelPrimitiveGeometry,
188-
voxel_size: Vect,
189-
grid_coords: &[IVect],
190-
) -> Self {
186+
pub fn voxels(voxel_size: Vect, grid_coordinates: &[IVect]) -> Self {
191187
let shape = Voxels::new(
192-
primitive_geometry,
193188
voxel_size.into(),
194-
&Self::ivec_array_from_point_int_array(grid_coords),
189+
&Self::ivec_array_from_point_int_array(grid_coordinates),
195190
);
196191
SharedShape::new(shape).into()
197192
}
@@ -200,13 +195,8 @@ impl Collider {
200195
///
201196
/// Each voxel has the size `voxel_size` and contains at least one point from `centers`.
202197
/// The `primitive_geometry` controls the behavior of collision detection at voxels boundaries.
203-
pub fn voxels_from_points(
204-
primitive_geometry: VoxelPrimitiveGeometry,
205-
voxel_size: Vect,
206-
points: &[Vect],
207-
) -> Self {
198+
pub fn voxels_from_points(voxel_size: Vect, points: &[Vect]) -> Self {
208199
SharedShape::voxels_from_points(
209-
primitive_geometry,
210200
voxel_size.into(),
211201
&Self::vec_array_from_point_float_array(points),
212202
)
@@ -216,32 +206,19 @@ impl Collider {
216206
/// Initializes a voxels shape obtained from the decomposition of the given trimesh (in 3D)
217207
/// or polyline (in 2D) into voxelized convex parts.
218208
pub fn voxelized_mesh(
219-
primitive_geometry: VoxelPrimitiveGeometry,
220209
vertices: &[Vect],
221210
indices: &[[u32; DIM]],
222211
voxel_size: Real,
223212
fill_mode: FillMode,
224213
) -> Self {
225214
let vertices = Self::vec_array_from_point_float_array(vertices);
226-
SharedShape::voxelized_mesh(
227-
primitive_geometry,
228-
&vertices,
229-
indices,
230-
voxel_size,
231-
fill_mode,
232-
)
233-
.into()
215+
SharedShape::voxelized_mesh(&vertices, indices, voxel_size, fill_mode).into()
234216
}
235217

236218
/// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D)
237219
/// or polyline (in 2D) into voxelized convex parts.
238-
pub fn voxelized_convex_decomposition(
239-
primitive_geometry: VoxelPrimitiveGeometry,
240-
vertices: &[Vect],
241-
indices: &[[u32; DIM]],
242-
) -> Vec<Self> {
220+
pub fn voxelized_convex_decomposition(vertices: &[Vect], indices: &[[u32; DIM]]) -> Vec<Self> {
243221
Self::voxelized_convex_decomposition_with_params(
244-
primitive_geometry,
245222
vertices,
246223
indices,
247224
&VHACDParameters::default(),
@@ -251,13 +228,11 @@ impl Collider {
251228
/// Initializes a compound shape obtained from the decomposition of the given trimesh (in 3D)
252229
/// or polyline (in 2D) into voxelized convex parts.
253230
pub fn voxelized_convex_decomposition_with_params(
254-
primitive_geometry: VoxelPrimitiveGeometry,
255231
vertices: &[Vect],
256232
indices: &[[u32; DIM]],
257233
params: &VHACDParameters,
258234
) -> Vec<Self> {
259235
SharedShape::voxelized_convex_decomposition_with_params(
260-
primitive_geometry,
261236
&Self::vec_array_from_point_float_array(vertices),
262237
indices,
263238
params,

src/geometry/shape_views/collider_view.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,7 @@ impl<'a> ColliderView<'a> {
279279
},
280280
ColliderView::Segment(s) => SharedShape::new(s.raw.scaled(&scale.into())),
281281
ColliderView::Triangle(t) => SharedShape::new(t.raw.scaled(&scale.into())),
282-
ColliderView::Voxels(cp) => match cp.raw.clone().scaled(&scale.into()) {
283-
None => {
284-
log::error!("Failed to apply scale {scale} to Voxels shape.");
285-
SharedShape::ball(0.0)
286-
}
287-
Some(scaled) => SharedShape::new(scaled),
288-
},
282+
ColliderView::Voxels(cp) => SharedShape::new(cp.raw.clone().scaled(&scale.into())),
289283
ColliderView::RoundTriangle(t) => SharedShape::new(RoundShape {
290284
border_radius: t.raw.border_radius,
291285
inner_shape: t.raw.inner_shape.scaled(&scale.into()),

src/picking_backend/mod.rs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use bevy::picking::{
1515
use bevy::prelude::PickingPlugin;
1616
use bevy::reflect::prelude::*;
1717
use bevy::render::{prelude::*, view::RenderLayers};
18+
use rapier::parry::query::DefaultQueryDispatcher;
1819

1920
/// How a ray cast should handle [`Visibility`].
2021
#[derive(Clone, Copy, Reflect)]
@@ -85,7 +86,7 @@ pub fn update_hits(
8586
rapier_context: Query<(
8687
&crate::prelude::RapierContextColliders,
8788
&crate::prelude::RapierRigidBodySet,
88-
&crate::prelude::RapierQueryPipeline,
89+
&crate::prelude::RapierContextSimulation,
8990
)>,
9091
mut output: EventWriter<PointerHits>,
9192
) {
@@ -97,7 +98,7 @@ pub fn update_hits(
9798
continue;
9899
}
99100
let order = camera.order as f32;
100-
for (colliders, bodies, query_pipeline) in rapier_context.iter() {
101+
for (colliders, bodies, simulation) in rapier_context.iter() {
101102
let predicate = |entity| {
102103
let marker_requirement =
103104
!backend_settings.require_markers || marked_targets.get(entity).is_ok();
@@ -130,45 +131,56 @@ pub fn update_hits(
130131

131132
true
132133
};
134+
// FIXME: Due to "limitations in the borrow checker",
135+
// it's challenging to make a function to help with creating a rapier filter.
136+
let rapier_predicate =
137+
|h: rapier::prelude::ColliderHandle, _: &rapier::prelude::Collider| {
138+
crate::prelude::RapierContextColliders::collider_entity_with_set(
139+
&colliders.colliders,
140+
h,
141+
)
142+
.map(&predicate)
143+
.unwrap_or(false)
144+
};
145+
let filter = rapier::prelude::QueryFilter::default().predicate(&rapier_predicate);
146+
let query_pipeline = crate::prelude::RapierQueryPipeline {
147+
query_pipeline: simulation.broad_phase.as_query_pipeline(
148+
&DefaultQueryDispatcher,
149+
&bodies.bodies,
150+
&colliders.colliders,
151+
filter.predicate(&rapier_predicate),
152+
),
153+
};
133154

134155
let mut picks = Vec::new();
135156
#[cfg(feature = "dim2")]
136-
query_pipeline.intersections_with_point(
137-
colliders,
138-
bodies,
139-
bevy::math::Vec2::new(ray.origin.x, ray.origin.y),
140-
crate::prelude::QueryFilter::default().predicate(&predicate),
141-
|entity| {
142-
let hit_data = HitData {
143-
camera: ray_id.camera,
144-
position: Some(bevy::math::Vec3::new(ray.origin.x, ray.origin.y, 0.0)),
145-
normal: None,
146-
depth: 0.0,
147-
};
148-
picks.push((entity, hit_data));
149-
true
150-
},
151-
);
157+
for entity in query_pipeline
158+
.intersect_point(colliders, bevy::math::Vec2::new(ray.origin.x, ray.origin.y))
159+
{
160+
let hit_data = HitData {
161+
camera: ray_id.camera,
162+
position: Some(bevy::math::Vec3::new(ray.origin.x, ray.origin.y, 0.0)),
163+
normal: None,
164+
depth: 0.0,
165+
};
166+
picks.push((entity, hit_data));
167+
}
152168
#[cfg(feature = "dim3")]
153-
query_pipeline.intersections_with_ray(
169+
for (entity, intersection) in query_pipeline.intersect_ray(
154170
colliders,
155-
bodies,
156171
ray.origin,
157172
ray.direction.into(),
158173
f32::MAX,
159174
true,
160-
crate::prelude::QueryFilter::default().predicate(&predicate),
161-
|entity, intersection| {
162-
let hit_data = HitData {
163-
camera: ray_id.camera,
164-
position: Some(intersection.point),
165-
normal: Some(intersection.normal),
166-
depth: intersection.time_of_impact,
167-
};
168-
picks.push((entity, hit_data));
169-
true
170-
},
171-
);
175+
) {
176+
let hit_data = HitData {
177+
camera: ray_id.camera,
178+
position: Some(intersection.point),
179+
normal: Some(intersection.normal),
180+
depth: intersection.time_of_impact,
181+
};
182+
picks.push((entity, hit_data));
183+
}
172184

173185
if !picks.is_empty() {
174186
output.write(PointerHits::new(ray_id.pointer, picks, order));

src/pipeline/query_filter.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use crate::geometry::CollisionGroups;
88
use crate::prelude::RapierRigidBodySet;
99

1010
/// A filter that describes what collider should be included or excluded from a scene query.
11-
///
12-
/// For testing manually check [`RapierRigidBodySet::with_query_filter`].
1311
#[derive(Copy, Clone, Default)]
1412
pub struct QueryFilter<'a> {
1513
/// Flags indicating what particular type of colliders should be excluded.

0 commit comments

Comments
 (0)