updated to rapier 0.28 + nalgebra 0.34

This commit is contained in:
Dmitry Stepanov
2025-08-10 10:04:59 +03:00
parent c8c2612de7
commit 9dbfdfc694
5 changed files with 62 additions and 92 deletions
+1 -1
View File
@@ -14,6 +14,6 @@ readme = "README.md"
include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"]
[dependencies]
nalgebra = { version = "0.33", features = ["bytemuck"] }
nalgebra = { version = "0.34", features = ["bytemuck"] }
fxhash = "0.2.1"
rand = "0.8.5"
+1 -1
View File
@@ -22,7 +22,7 @@ byteorder = "1.4.3"
rand = "0.8.4"
memoffset = "0.9.0"
lazy_static = "1.4.0"
nalgebra = { version = "0.33", features = ["bytemuck"] }
nalgebra = { version = "0.34", features = ["bytemuck"] }
arrayvec = "0.7.2"
futures = { version = "0.3.17", features = ["thread-pool"] }
uuid = { version = "1", features = ["v4", "js"] }
+4 -4
View File
@@ -27,8 +27,8 @@ fyrox-graphics-gl = { path = "../fyrox-graphics-gl", version = "1.0.0-rc.1" }
fyrox-texture = { path = "../fyrox-texture", version = "1.0.0-rc.1" }
fyrox-autotile = { path = "../fyrox-autotile", version = "1.0.0-rc.1" }
fyrox-material = { path = "../fyrox-material", version = "1.0.0-rc.1" }
rapier2d = { version = "0.23", features = ["debug-render"] }
rapier3d = { version = "0.23", features = ["debug-render"] }
rapier2d = { version = "0.28", features = ["debug-render"] }
rapier3d = { version = "0.28", features = ["debug-render"] }
image = { version = "0.25.1", default-features = false, features = ["gif", "jpeg", "png", "tga", "tiff", "bmp"] }
inflate = "0.4.5"
serde = { version = "1", features = ["derive"] }
@@ -44,8 +44,8 @@ clap = { version = "4", features = ["derive"] }
winit = { version = "0.29.2", features = ["serde"] }
half = { version = "2.2.1", features = ["bytemuck"] }
base64 = "0.22.1"
uvgen = "0.2.0"
lightmap = "0.2"
uvgen = "0.3.0"
lightmap = "0.3.0"
libloading = "0.8.1"
gltf = { version = "1.4.0", default-features = false, features = ["names", "utils", "extras"] }
bytemuck = { version = "1.23.2", features = ["derive"] }
+28 -44
View File
@@ -20,6 +20,7 @@
//! Scene physics module.
use super::collider::GeometrySource;
use crate::{
core::{
algebra::{
@@ -56,6 +57,7 @@ use crate::{
},
};
pub use rapier2d::geometry::shape::*;
use rapier2d::parry::query::DefaultQueryDispatcher;
use rapier2d::{
dynamics::{
CCDSolver, GenericJoint, GenericJointBuilder, ImpulseJointHandle, ImpulseJointSet,
@@ -68,10 +70,9 @@ use rapier2d::{
InteractionGroups, NarrowPhase, Ray, SharedShape,
},
parry::query::ShapeCastOptions,
pipeline::{DebugRenderPipeline, EventHandler, PhysicsPipeline, QueryPipeline},
pipeline::{DebugRenderPipeline, EventHandler, PhysicsPipeline},
};
use std::{
cell::RefCell,
cmp::Ordering,
fmt::{Debug, Formatter},
hash::Hash,
@@ -79,8 +80,6 @@ use std::{
sync::Arc,
};
use super::collider::GeometrySource;
/// A trait for ray cast results storage. It has two implementations: Vec and ArrayVec.
/// Latter is needed for the cases where you need to avoid runtime memory allocations
/// and do everything on stack.
@@ -506,9 +505,6 @@ pub struct PhysicsWorld {
event_handler: Box<dyn EventHandler>,
#[visit(skip)]
#[reflect(hidden)]
query: RefCell<QueryPipeline>,
#[visit(skip)]
#[reflect(hidden)]
debug_render_pipeline: Mutex<DebugRenderPipeline>,
}
@@ -616,7 +612,6 @@ impl PhysicsWorld {
map: Default::default(),
},
event_handler: Box::new(()),
query: RefCell::new(Default::default()),
performance_statistics: Default::default(),
debug_render_pipeline: Default::default(),
}
@@ -657,8 +652,6 @@ impl PhysicsWorld {
max_ccd_substeps: self.integration_parameters.max_ccd_substeps as usize,
};
let mut query = self.query.borrow_mut();
self.pipeline.step(
&self.gravity,
&integration_parameters,
@@ -670,7 +663,6 @@ impl PhysicsWorld {
&mut self.joints.set,
&mut self.multibody_joints.set,
&mut self.ccd_solver,
Some(&mut query),
&(),
&*self.event_handler,
);
@@ -747,7 +739,15 @@ impl PhysicsWorld {
pub fn cast_ray<S: QueryResultsStorage>(&self, opts: RayCastOptions, query_buffer: &mut S) {
let time = instant::Instant::now();
let query = self.query.borrow_mut();
let query = self.broad_phase.as_query_pipeline(
&DefaultQueryDispatcher,
&self.bodies,
&self.colliders,
rapier2d::pipeline::QueryFilter::new().groups(InteractionGroups::new(
u32_to_group(opts.groups.memberships.0),
u32_to_group(opts.groups.filter.0),
)),
);
query_buffer.clear();
let ray = Ray::new(
@@ -756,28 +756,15 @@ impl PhysicsWorld {
.try_normalize(f32::EPSILON)
.unwrap_or_default(),
);
query.intersections_with_ray(
&self.bodies,
&self.colliders,
&ray,
opts.max_len,
true,
rapier2d::pipeline::QueryFilter::new().groups(InteractionGroups::new(
u32_to_group(opts.groups.memberships.0),
u32_to_group(opts.groups.filter.0),
)),
|handle, intersection| {
query_buffer.push(Intersection {
collider: Handle::decode_from_u128(
self.colliders.get(handle).unwrap().user_data,
),
normal: intersection.normal,
position: ray.point_at(intersection.time_of_impact),
feature: intersection.feature.into(),
toi: intersection.time_of_impact,
})
},
);
for (_, collider, intersection) in query.intersect_ray(ray, opts.max_len, true) {
query_buffer.push(Intersection {
collider: Handle::decode_from_u128(collider.user_data),
normal: intersection.normal,
position: ray.point_at(intersection.time_of_impact),
feature: intersection.feature.into(),
toi: intersection.time_of_impact,
});
}
if opts.sort_results {
query_buffer.sort_intersections_by(|a, b| {
if a.toi > b.toi {
@@ -855,7 +842,12 @@ impl PhysicsWorld {
predicate: Some(&predicate),
};
let query = self.query.borrow_mut();
let query = self.broad_phase.as_query_pipeline(
&DefaultQueryDispatcher,
&self.bodies,
&self.colliders,
filter,
);
let opts = ShapeCastOptions {
max_time_of_impact: max_toi,
@@ -865,15 +857,7 @@ impl PhysicsWorld {
};
query
.cast_shape(
&self.bodies,
&self.colliders,
shape_pos,
shape_vel,
shape,
opts,
filter,
)
.cast_shape(shape_pos, shape_vel, shape, opts)
.map(|(handle, toi)| {
(
Handle::decode_from_u128(self.colliders.get(handle).unwrap().user_data),
+28 -42
View File
@@ -65,11 +65,11 @@ use rapier3d::{
InteractionGroups, NarrowPhase, Ray, SharedShape,
},
parry::{query::ShapeCastOptions, shape::HeightField},
pipeline::{DebugRenderPipeline, EventHandler, PhysicsPipeline, QueryPipeline},
pipeline::{DebugRenderPipeline, EventHandler, PhysicsPipeline},
prelude::{HeightFieldCellStatus, JointAxis, MassProperties},
};
use std::{
cell::{Cell, RefCell},
cell::Cell,
cmp::Ordering,
fmt::{Debug, Formatter},
hash::Hash,
@@ -81,6 +81,7 @@ use strum_macros::{AsRefStr, EnumString, VariantNames};
use fyrox_graph::{BaseSceneGraph, SceneGraphNode};
pub use rapier3d::geometry::shape::*;
use rapier3d::parry::query::DefaultQueryDispatcher;
/// Shape-dependent identifier.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
@@ -1041,9 +1042,6 @@ pub struct PhysicsWorld {
event_handler: Box<dyn EventHandler>,
#[visit(skip)]
#[reflect(hidden)]
query: RefCell<QueryPipeline>,
#[visit(skip)]
#[reflect(hidden)]
debug_render_pipeline: Mutex<DebugRenderPipeline>,
}
@@ -1152,7 +1150,6 @@ impl PhysicsWorld {
map: Default::default(),
},
event_handler: Box::new(()),
query: RefCell::new(Default::default()),
performance_statistics: Default::default(),
debug_render_pipeline: Default::default(),
}
@@ -1193,8 +1190,6 @@ impl PhysicsWorld {
max_ccd_substeps: self.integration_parameters.max_ccd_substeps as usize,
};
let mut query = self.query.borrow_mut();
self.pipeline.step(
&self.gravity,
&integration_parameters,
@@ -1206,7 +1201,6 @@ impl PhysicsWorld {
&mut self.joints.set,
&mut self.multibody_joints.set,
&mut self.ccd_solver,
Some(&mut query),
&(),
&*self.event_handler,
);
@@ -1283,7 +1277,15 @@ impl PhysicsWorld {
pub fn cast_ray<S: QueryResultsStorage>(&self, opts: RayCastOptions, query_buffer: &mut S) {
let time = instant::Instant::now();
let query = self.query.borrow_mut();
let query = self.broad_phase.as_query_pipeline(
&DefaultQueryDispatcher,
&self.bodies,
&self.colliders,
rapier3d::pipeline::QueryFilter::new().groups(InteractionGroups::new(
u32_to_group(opts.groups.memberships.0),
u32_to_group(opts.groups.filter.0),
)),
);
query_buffer.clear();
let ray = Ray::new(
@@ -1292,28 +1294,15 @@ impl PhysicsWorld {
.try_normalize(f32::EPSILON)
.unwrap_or_default(),
);
query.intersections_with_ray(
&self.bodies,
&self.colliders,
&ray,
opts.max_len,
true,
rapier3d::pipeline::QueryFilter::new().groups(InteractionGroups::new(
u32_to_group(opts.groups.memberships.0),
u32_to_group(opts.groups.filter.0),
)),
|handle, intersection| {
query_buffer.push(Intersection {
collider: Handle::decode_from_u128(
self.colliders.get(handle).unwrap().user_data,
),
normal: intersection.normal,
position: ray.point_at(intersection.time_of_impact),
feature: intersection.feature.into(),
toi: intersection.time_of_impact,
})
},
);
for (_, collider, intersection) in query.intersect_ray(ray, opts.max_len, true) {
query_buffer.push(Intersection {
collider: Handle::decode_from_u128(collider.user_data),
normal: intersection.normal,
position: ray.point_at(intersection.time_of_impact),
feature: intersection.feature.into(),
toi: intersection.time_of_impact,
});
}
if opts.sort_results {
query_buffer.sort_intersections_by(|a, b| {
if a.toi > b.toi {
@@ -1391,7 +1380,12 @@ impl PhysicsWorld {
predicate: Some(&predicate),
};
let query = self.query.borrow_mut();
let query = self.broad_phase.as_query_pipeline(
&DefaultQueryDispatcher,
&self.bodies,
&self.colliders,
filter,
);
let opts = ShapeCastOptions {
max_time_of_impact: max_toi,
@@ -1401,15 +1395,7 @@ impl PhysicsWorld {
};
query
.cast_shape(
&self.bodies,
&self.colliders,
shape_pos,
shape_vel,
shape,
opts,
filter,
)
.cast_shape(shape_pos, shape_vel, shape, opts)
.map(|(handle, toi)| {
(
Handle::decode_from_u128(self.colliders.get(handle).unwrap().user_data),