feat: reduce the amount of duplicate work the broad-phase is doing for user changes and CCD + release v0.28.0 (#872)
* feat: reduce the amount of duplicate work the broad-phase is doing for user changes and CCD * Release v0.28.0 * chore: fix warnings * chore: clippy fixes * chore: more clippy fixes
This commit is contained in:
@@ -14,7 +14,6 @@ use rapier::math::{Isometry, Real, Vector};
|
||||
//use crate::objects::polyline::Polyline;
|
||||
// use crate::objects::mesh::Mesh;
|
||||
use crate::testbed::TestbedStateFlags;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand_pcg::Pcg32;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -97,7 +96,7 @@ pub struct GraphicsManager {
|
||||
impl GraphicsManager {
|
||||
pub fn new() -> GraphicsManager {
|
||||
GraphicsManager {
|
||||
rand: Pcg32::seed_from_u64(0),
|
||||
rand: Pcg32::new(0, 1),
|
||||
b2sn: HashMap::new(),
|
||||
b2color: HashMap::new(),
|
||||
c2color: HashMap::new(),
|
||||
@@ -128,7 +127,7 @@ impl GraphicsManager {
|
||||
self.c2color.clear();
|
||||
self.b2color.clear();
|
||||
self.b2wireframe.clear();
|
||||
self.rand = Pcg32::seed_from_u64(0);
|
||||
self.rand = Pcg32::new(0, 1);
|
||||
}
|
||||
|
||||
pub fn remove_collider_nodes(
|
||||
@@ -236,7 +235,8 @@ impl GraphicsManager {
|
||||
}
|
||||
|
||||
fn gen_color(rng: &mut Pcg32) -> Point3<f32> {
|
||||
let mut color: Point3<f32> = rng.r#gen();
|
||||
use rand::Rng;
|
||||
let mut color: Point3<f32> = rng.random();
|
||||
|
||||
// Quantize the colors a bit to get some amount of auto-instancing from bevy.
|
||||
color.x = (color.x * 5.0).round() / 5.0;
|
||||
|
||||
@@ -9,9 +9,7 @@ use rapier::dynamics::{
|
||||
CCDSolver, ImpulseJointSet, IntegrationParameters, IslandManager, MultibodyJointSet,
|
||||
RigidBodySet,
|
||||
};
|
||||
use rapier::geometry::{
|
||||
BroadPhase, BroadPhaseBvh, BvhOptimizationStrategy, ColliderSet, NarrowPhase,
|
||||
};
|
||||
use rapier::geometry::{BroadPhaseBvh, BvhOptimizationStrategy, ColliderSet, NarrowPhase};
|
||||
use rapier::math::{Real, Vector};
|
||||
use rapier::pipeline::{ChannelEventCollector, PhysicsHooks, PhysicsPipeline};
|
||||
|
||||
@@ -25,16 +23,14 @@ pub enum RapierBroadPhaseType {
|
||||
}
|
||||
|
||||
impl RapierBroadPhaseType {
|
||||
pub fn init_broad_phase(self) -> Box<dyn BroadPhase> {
|
||||
pub fn init_broad_phase(self) -> BroadPhaseBvh {
|
||||
match self {
|
||||
RapierBroadPhaseType::BvhSubtreeOptimizer => {
|
||||
Box::new(BroadPhaseBvh::with_optimization_strategy(
|
||||
BvhOptimizationStrategy::SubtreeOptimizer,
|
||||
))
|
||||
BroadPhaseBvh::with_optimization_strategy(BvhOptimizationStrategy::SubtreeOptimizer)
|
||||
}
|
||||
RapierBroadPhaseType::BvhWithoutOptimization => {
|
||||
BroadPhaseBvh::with_optimization_strategy(BvhOptimizationStrategy::None)
|
||||
}
|
||||
RapierBroadPhaseType::BvhWithoutOptimization => Box::new(
|
||||
BroadPhaseBvh::with_optimization_strategy(BvhOptimizationStrategy::None),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,7 +246,7 @@ impl Harness {
|
||||
&physics.gravity,
|
||||
&physics.integration_parameters,
|
||||
&mut physics.islands,
|
||||
&mut *physics.broad_phase,
|
||||
&mut physics.broad_phase,
|
||||
&mut physics.narrow_phase,
|
||||
&mut physics.bodies,
|
||||
&mut physics.colliders,
|
||||
@@ -268,7 +264,7 @@ impl Harness {
|
||||
&self.physics.gravity,
|
||||
&self.physics.integration_parameters,
|
||||
&mut self.physics.islands,
|
||||
&mut *self.physics.broad_phase,
|
||||
&mut self.physics.broad_phase,
|
||||
&mut self.physics.narrow_phase,
|
||||
&mut self.physics.bodies,
|
||||
&mut self.physics.colliders,
|
||||
|
||||
@@ -3,7 +3,7 @@ use rapier::dynamics::{
|
||||
RigidBodySet,
|
||||
};
|
||||
use rapier::geometry::{
|
||||
BroadPhase, ColliderSet, CollisionEvent, ContactForceEvent, DefaultBroadPhase, NarrowPhase,
|
||||
BroadPhaseBvh, ColliderSet, CollisionEvent, ContactForceEvent, DefaultBroadPhase, NarrowPhase,
|
||||
};
|
||||
use rapier::math::{Real, Vector};
|
||||
use rapier::pipeline::{PhysicsHooks, PhysicsPipeline};
|
||||
@@ -89,7 +89,7 @@ impl PhysicsSnapshot {
|
||||
|
||||
pub struct PhysicsState {
|
||||
pub islands: IslandManager,
|
||||
pub broad_phase: Box<dyn BroadPhase>,
|
||||
pub broad_phase: BroadPhaseBvh,
|
||||
pub narrow_phase: NarrowPhase,
|
||||
pub bodies: RigidBodySet,
|
||||
pub colliders: ColliderSet,
|
||||
@@ -112,7 +112,7 @@ impl PhysicsState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
islands: IslandManager::new(),
|
||||
broad_phase: Box::new(DefaultBroadPhase::default()),
|
||||
broad_phase: DefaultBroadPhase::default(),
|
||||
narrow_phase: NarrowPhase::new(),
|
||||
bodies: RigidBodySet::new(),
|
||||
colliders: ColliderSet::new(),
|
||||
|
||||
@@ -23,7 +23,7 @@ use rapier::dynamics::{
|
||||
RigidBodyHandle, RigidBodySet,
|
||||
};
|
||||
#[cfg(feature = "dim3")]
|
||||
use rapier::geometry::{BroadPhaseBvh, Ray};
|
||||
use rapier::geometry::Ray;
|
||||
use rapier::geometry::{ColliderHandle, ColliderSet, NarrowPhase};
|
||||
use rapier::math::{Real, Vector};
|
||||
use rapier::pipeline::PhysicsHooks;
|
||||
@@ -814,21 +814,12 @@ impl Testbed<'_, '_, '_, '_, '_, '_, '_, '_, '_, '_, '_, '_, '_> {
|
||||
wheels[1].engine_force = engine_force;
|
||||
wheels[1].steering = steering_angle;
|
||||
|
||||
let query_pipeline = if let Some(bf) = self
|
||||
.harness
|
||||
.physics
|
||||
.broad_phase
|
||||
.downcast_ref::<BroadPhaseBvh>()
|
||||
{
|
||||
bf.as_query_pipeline_mut(
|
||||
self.harness.physics.narrow_phase.query_dispatcher(),
|
||||
&mut self.harness.physics.bodies,
|
||||
&mut self.harness.physics.colliders,
|
||||
QueryFilter::exclude_dynamic().exclude_rigid_body(vehicle.chassis),
|
||||
)
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let query_pipeline = self.harness.physics.broad_phase.as_query_pipeline_mut(
|
||||
self.harness.physics.narrow_phase.query_dispatcher(),
|
||||
&mut self.harness.physics.bodies,
|
||||
&mut self.harness.physics.colliders,
|
||||
QueryFilter::exclude_dynamic().exclude_rigid_body(vehicle.chassis),
|
||||
);
|
||||
|
||||
vehicle.update_vehicle(
|
||||
self.harness.physics.integration_parameters.dt,
|
||||
@@ -1353,7 +1344,7 @@ fn update_testbed(
|
||||
}
|
||||
|
||||
harness.state.timestep_id = timestep_id;
|
||||
harness.physics.broad_phase = Box::new(broad_phase);
|
||||
harness.physics.broad_phase = broad_phase;
|
||||
harness.physics.narrow_phase = narrow_phase;
|
||||
harness.physics.islands = island_manager;
|
||||
harness.physics.bodies = bodies;
|
||||
@@ -1630,16 +1621,12 @@ fn highlight_hovered_body(
|
||||
let ray_dir = Vector3::new(ray_dir.x as Real, ray_dir.y as Real, ray_dir.z as Real);
|
||||
|
||||
let ray = Ray::new(ray_origin, ray_dir);
|
||||
let query_pipeline = if let Some(bf) = physics.broad_phase.downcast_ref::<BroadPhaseBvh>() {
|
||||
bf.as_query_pipeline(
|
||||
physics.narrow_phase.query_dispatcher(),
|
||||
&physics.bodies,
|
||||
&physics.colliders,
|
||||
QueryFilter::only_dynamic(),
|
||||
)
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let query_pipeline = physics.broad_phase.as_query_pipeline(
|
||||
physics.narrow_phase.query_dispatcher(),
|
||||
&physics.bodies,
|
||||
&physics.colliders,
|
||||
QueryFilter::only_dynamic(),
|
||||
);
|
||||
|
||||
let hit = query_pipeline.cast_ray(&ray, Real::MAX, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user