Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix concave shapes for 2d. #155

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
crate-type = ["cdylib"]

[features]
default = ["single-dim3", "serde-serialize", "parallel", "simd-stable"]
default = ["single-dim2", "serde-serialize", "parallel", "simd-stable"]
dim2 = []
dim3 = []
single = []
Expand Down
4 changes: 1 addition & 3 deletions src/bodies/rapier_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,15 +886,14 @@ impl RapierBody {
pub fn force_mass_update(
&mut self,
physics_spaces: &mut PhysicsSpaces,
physics_shapes: &mut PhysicsShapes,
physics_engine: &mut PhysicsEngine,
) {
if self.mass_properties_update_pending {
// Force update internal mass properties to calculate proper impulse
if let Some(space) = physics_spaces.get_mut(&self.base.get_space()) {
space.body_remove_from_mass_properties_update_list(self.base.get_rid());
}
self.update_mass_properties(true, physics_shapes, physics_engine);
self.update_mass_properties(true, physics_engine);
}
}

Expand Down Expand Up @@ -1628,7 +1627,6 @@ impl RapierBody {
pub fn update_mass_properties(
&mut self,
force_update: bool,
physics_shapes: &mut PhysicsShapes,
physics_engine: &mut PhysicsEngine,
) {
self.mass_properties_update_pending = false;
Expand Down
2 changes: 0 additions & 2 deletions src/bodies/rapier_direct_body_state_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::types::*;
#[class(base=PhysicsDirectBodyState2DExtension,tool)]
pub struct RapierDirectBodyState2D {
implementation: RapierDirectBodyStateImpl,
transform: Transform,
base: Base<PhysicsDirectBodyState2DExtension>,
}
impl RapierDirectBodyState2D {
Expand All @@ -22,7 +21,6 @@ impl IPhysicsDirectBodyState2DExtension for RapierDirectBodyState2D {
fn init(base: Base<PhysicsDirectBodyState2DExtension>) -> Self {
Self {
implementation: RapierDirectBodyStateImpl::default(),
transform: Transform::IDENTITY,
base,
}
}
Expand Down
66 changes: 11 additions & 55 deletions src/bodies/rapier_direct_body_state_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_central_impulse(impulse, &mut physics_data.physics_engine)
}
}
Expand All @@ -217,11 +213,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_impulse(impulse, position, &mut physics_data.physics_engine)
}
}
Expand All @@ -231,11 +223,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_torque_impulse(impulse, &mut physics_data.physics_engine)
}
}
Expand All @@ -245,11 +233,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_central_force(force, &mut physics_data.physics_engine)
}
}
Expand All @@ -259,11 +243,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_force(force, position, &mut physics_data.physics_engine)
}
}
Expand All @@ -273,11 +253,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_torque(torque, &mut physics_data.physics_engine)
}
}
Expand All @@ -287,11 +263,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.add_constant_central_force(force, &mut physics_data.physics_engine)
}
}
Expand All @@ -301,11 +273,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.add_constant_force(force, position, &mut physics_data.physics_engine)
}
}
Expand All @@ -315,11 +283,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.add_constant_torque(torque, &mut physics_data.physics_engine)
}
}
Expand All @@ -329,11 +293,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.set_constant_force(force, &mut physics_data.physics_engine)
}
}
Expand All @@ -353,11 +313,7 @@ impl RapierDirectBodyStateImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&self.body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.set_constant_torque(torque, &mut physics_data.physics_engine)
}
}
Expand Down
68 changes: 13 additions & 55 deletions src/servers/rapier_physics_server_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ impl RapierPhysicsServerImpl {
ShapeType::CUSTOM
}

#[cfg(feature = "dim3")]
pub(super) fn shape_set_margin(&mut self, _shape: Rid, _margin: real) {}

#[cfg(feature = "dim3")]
pub(super) fn shape_get_margin(&self, _shape: Rid) -> real {
0.0
}
Expand Down Expand Up @@ -1038,11 +1040,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_central_impulse(impulse, &mut physics_data.physics_engine);
}
}
Expand All @@ -1052,11 +1050,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_torque_impulse(impulse, &mut physics_data.physics_engine);
}
}
Expand All @@ -1066,11 +1060,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_impulse(impulse, position, &mut physics_data.physics_engine);
}
}
Expand All @@ -1080,11 +1070,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_central_force(force, &mut physics_data.physics_engine);
}
}
Expand All @@ -1094,11 +1080,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_force(force, position, &mut physics_data.physics_engine);
}
}
Expand All @@ -1108,11 +1090,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.apply_torque(torque, &mut physics_data.physics_engine);
}
}
Expand All @@ -1122,11 +1100,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.add_constant_central_force(force, &mut physics_data.physics_engine);
}
}
Expand All @@ -1136,11 +1110,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.add_constant_force(force, position, &mut physics_data.physics_engine);
}
}
Expand All @@ -1150,11 +1120,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.add_constant_torque(torque, &mut physics_data.physics_engine);
}
}
Expand All @@ -1164,11 +1130,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.set_constant_force(force, &mut physics_data.physics_engine);
}
}
Expand All @@ -1188,11 +1150,7 @@ impl RapierPhysicsServerImpl {
let physics_data = physics_data();
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
if let Some(body) = body.get_mut_body() {
body.force_mass_update(
&mut physics_data.spaces,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.force_mass_update(&mut physics_data.spaces, &mut physics_data.physics_engine);
body.set_constant_torque(torque, &mut physics_data.physics_engine);
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/servers/rapier_project_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ impl RapierProjectSettings {
setting_value.to::<i64>()
}

fn get_setting_bool(p_setting: &str) -> bool {
let project_settings = ProjectSettings::singleton();
let setting_value = project_settings.get_setting_with_override(p_setting.into());
setting_value.to::<bool>()
}

fn get_setting_double(p_setting: &str) -> f64 {
let project_settings = ProjectSettings::singleton();
let setting_value = project_settings.get_setting_with_override(p_setting.into());
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/rapier_concave_polygon_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl IRapierShape for RapierConcavePolygonShape {
#[cfg(feature = "dim2")]
VariantType::PACKED_VECTOR2_ARRAY => {
if let Ok(arr) = data.try_to::<PackedVector2Array>() {
let len = self.points.len();
let len = arr.len();
if len == 0 {
return;
}
Expand Down
6 changes: 1 addition & 5 deletions src/spaces/rapier_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,7 @@ impl RapierSpace {
if let Some(body) = physics_data.collision_objects.get_mut(body)
&& let Some(body) = body.get_mut_body()
{
body.update_mass_properties(
false,
&mut physics_data.shapes,
&mut physics_data.physics_engine,
);
body.update_mass_properties(false, &mut physics_data.physics_engine);
}
}
space.reset_mass_properties_update_list();
Expand Down
Loading