Split rigid-bodies and colliders into multiple components
This commit is contained in:
@@ -158,8 +158,8 @@ impl Box2dWorld {
|
||||
let center = na_vec_to_b2_vec(collider.position_wrt_parent().translation.vector);
|
||||
let mut fixture_def = b2::FixtureDef::new();
|
||||
|
||||
fixture_def.restitution = collider.restitution;
|
||||
fixture_def.friction = collider.friction;
|
||||
fixture_def.restitution = collider.material().restitution;
|
||||
fixture_def.friction = collider.material().friction;
|
||||
fixture_def.density = collider.density().unwrap_or(1.0);
|
||||
fixture_def.is_sensor = collider.is_sensor();
|
||||
fixture_def.filter = b2::Filter::new();
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
};
|
||||
use kiss3d::window::Window;
|
||||
use plugin::HarnessPlugin;
|
||||
use rapier::dynamics::{CCDSolver, IntegrationParameters, JointSet, RigidBodySet};
|
||||
use rapier::dynamics::{CCDSolver, IntegrationParameters, IslandManager, JointSet, RigidBodySet};
|
||||
use rapier::geometry::{BroadPhase, ColliderSet, NarrowPhase};
|
||||
use rapier::math::Vector;
|
||||
use rapier::pipeline::{ChannelEventCollector, PhysicsHooks, PhysicsPipeline, QueryPipeline};
|
||||
@@ -120,7 +120,7 @@ impl Harness {
|
||||
colliders: ColliderSet,
|
||||
joints: JointSet,
|
||||
gravity: Vector<f32>,
|
||||
hooks: impl PhysicsHooks + 'static,
|
||||
hooks: impl PhysicsHooks<RigidBodySet, ColliderSet> + 'static,
|
||||
) {
|
||||
// println!("Num bodies: {}", bodies.len());
|
||||
// println!("Num joints: {}", joints.len());
|
||||
@@ -130,6 +130,7 @@ impl Harness {
|
||||
self.physics.joints = joints;
|
||||
self.physics.hooks = Box::new(hooks);
|
||||
|
||||
self.physics.islands = IslandManager::new();
|
||||
self.physics.broad_phase = BroadPhase::new();
|
||||
self.physics.narrow_phase = NarrowPhase::new();
|
||||
self.state.timestep_id = 0;
|
||||
@@ -191,6 +192,7 @@ impl Harness {
|
||||
self.physics.pipeline.step(
|
||||
&self.physics.gravity,
|
||||
&self.physics.integration_parameters,
|
||||
&mut self.physics.islands,
|
||||
&mut self.physics.broad_phase,
|
||||
&mut self.physics.narrow_phase,
|
||||
&mut self.physics.bodies,
|
||||
@@ -201,9 +203,11 @@ impl Harness {
|
||||
&self.event_handler,
|
||||
);
|
||||
|
||||
self.physics
|
||||
.query_pipeline
|
||||
.update(&self.physics.bodies, &self.physics.colliders);
|
||||
self.physics.query_pipeline.update(
|
||||
&self.physics.islands,
|
||||
&self.physics.bodies,
|
||||
&self.physics.colliders,
|
||||
);
|
||||
|
||||
for plugin in &mut self.plugins {
|
||||
plugin.step(&mut self.physics, &self.state)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crossbeam::channel::Receiver;
|
||||
use rapier::dynamics::{CCDSolver, IntegrationParameters, JointSet, RigidBodySet};
|
||||
use rapier::dynamics::{CCDSolver, IntegrationParameters, IslandManager, JointSet, RigidBodySet};
|
||||
use rapier::geometry::{BroadPhase, ColliderSet, ContactEvent, IntersectionEvent, NarrowPhase};
|
||||
use rapier::math::Vector;
|
||||
use rapier::pipeline::{PhysicsHooks, PhysicsPipeline, QueryPipeline};
|
||||
@@ -68,6 +68,7 @@ impl PhysicsSnapshot {
|
||||
}
|
||||
|
||||
pub struct PhysicsState {
|
||||
pub islands: IslandManager,
|
||||
pub broad_phase: BroadPhase,
|
||||
pub narrow_phase: NarrowPhase,
|
||||
pub bodies: RigidBodySet,
|
||||
@@ -78,12 +79,13 @@ pub struct PhysicsState {
|
||||
pub query_pipeline: QueryPipeline,
|
||||
pub integration_parameters: IntegrationParameters,
|
||||
pub gravity: Vector<f32>,
|
||||
pub hooks: Box<dyn PhysicsHooks>,
|
||||
pub hooks: Box<dyn PhysicsHooks<RigidBodySet, ColliderSet>>,
|
||||
}
|
||||
|
||||
impl PhysicsState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
islands: IslandManager::new(),
|
||||
broad_phase: BroadPhase::new(),
|
||||
narrow_phase: NarrowPhase::new(),
|
||||
bodies: RigidBodySet::new(),
|
||||
|
||||
@@ -520,9 +520,9 @@ fn physx_collider_from_rapier_collider(
|
||||
};
|
||||
let mut material = physics
|
||||
.create_material(
|
||||
collider.friction,
|
||||
collider.friction,
|
||||
collider.restitution,
|
||||
collider.co_material.friction,
|
||||
collider.co_material.friction,
|
||||
collider.co_material.restitution,
|
||||
(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -19,7 +19,7 @@ use kiss3d::text::Font;
|
||||
use kiss3d::window::{State, Window};
|
||||
use na::{self, Point2, Point3, Vector3};
|
||||
use rapier::dynamics::{
|
||||
ActivationStatus, IntegrationParameters, JointSet, RigidBodyHandle, RigidBodySet,
|
||||
IntegrationParameters, JointSet, RigidBodyActivation, RigidBodyHandle, RigidBodySet,
|
||||
};
|
||||
use rapier::geometry::{ColliderHandle, ColliderSet, NarrowPhase};
|
||||
#[cfg(feature = "dim3")]
|
||||
@@ -245,7 +245,7 @@ impl Testbed {
|
||||
colliders: ColliderSet,
|
||||
joints: JointSet,
|
||||
gravity: Vector<f32>,
|
||||
hooks: impl PhysicsHooks + 'static,
|
||||
hooks: impl PhysicsHooks<RigidBodySet, ColliderSet> + 'static,
|
||||
) {
|
||||
self.harness
|
||||
.set_world_with_params(bodies, colliders, joints, gravity, hooks);
|
||||
@@ -586,6 +586,7 @@ impl Testbed {
|
||||
for to_delete in &colliders[..num_to_delete] {
|
||||
self.harness.physics.colliders.remove(
|
||||
to_delete[0],
|
||||
&mut self.harness.physics.islands,
|
||||
&mut self.harness.physics.bodies,
|
||||
true,
|
||||
);
|
||||
@@ -605,6 +606,7 @@ impl Testbed {
|
||||
for to_delete in &dynamic_bodies[..num_to_delete] {
|
||||
self.harness.physics.bodies.remove(
|
||||
*to_delete,
|
||||
&mut self.harness.physics.islands,
|
||||
&mut self.harness.physics.colliders,
|
||||
&mut self.harness.physics.joints,
|
||||
);
|
||||
@@ -617,6 +619,7 @@ impl Testbed {
|
||||
for to_delete in &joints[..num_to_delete] {
|
||||
self.harness.physics.joints.remove(
|
||||
*to_delete,
|
||||
&mut self.harness.physics.islands,
|
||||
&mut self.harness.physics.bodies,
|
||||
true,
|
||||
);
|
||||
@@ -1205,13 +1208,13 @@ impl State for Testbed {
|
||||
!= self.state.flags.contains(TestbedStateFlags::SLEEP)
|
||||
{
|
||||
if self.state.flags.contains(TestbedStateFlags::SLEEP) {
|
||||
for (_, mut body) in self.harness.physics.bodies.iter_mut() {
|
||||
body.activation.threshold = ActivationStatus::default_threshold();
|
||||
for (_, body) in self.harness.physics.bodies.iter_mut() {
|
||||
body.activation_mut().threshold = RigidBodyActivation::default_threshold();
|
||||
}
|
||||
} else {
|
||||
for (_, mut body) in self.harness.physics.bodies.iter_mut() {
|
||||
for (_, body) in self.harness.physics.bodies.iter_mut() {
|
||||
body.wake_up(true);
|
||||
body.activation.threshold = -1.0;
|
||||
body.activation_mut().threshold = -1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user