From 142229499d1e97a71ed142995cc0996a94aa3958 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 11:33:04 +0200 Subject: [PATCH 01/19] fix 3d shape test --- bin2d/test.tscn | 14 +++++++++++++- bin3d/test.gd | 15 --------------- src/shapes/rapier_convex_polygon_shape.rs | 7 ++++--- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/bin2d/test.tscn b/bin2d/test.tscn index 32ac721d..f3cd43fb 100644 --- a/bin2d/test.tscn +++ b/bin2d/test.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=3 format=3 uid="uid://cn4jscixu2bmf"] +[gd_scene load_steps=4 format=3 uid="uid://cn4jscixu2bmf"] [ext_resource type="Script" path="res://test.gd" id="1_fs1uw"] [sub_resource type="CircleShape2D" id="CircleShape2D_01opr"] +[sub_resource type="RectangleShape2D" id="RectangleShape2D_vkitq"] +size = Vector2(365, 37) + [node name="Test2D" type="Node2D"] script = ExtResource("1_fs1uw") @@ -12,3 +15,12 @@ position = Vector2(-18, -4) [node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] shape = SubResource("CircleShape2D_01opr") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +position = Vector2(10.5, 96.5) +shape = SubResource("RectangleShape2D_vkitq") + +[node name="Camera2D" type="Camera2D" parent="."] +zoom = Vector2(4, 4) diff --git a/bin3d/test.gd b/bin3d/test.gd index 4d6ff991..f6ed4a3f 100644 --- a/bin3d/test.gd +++ b/bin3d/test.gd @@ -14,40 +14,25 @@ func _ready() -> void: get_tree().quit() func test_capsule_shape(): - RapierCapsuleShapeTests.test_allows_one_way_collision() RapierCapsuleShapeTests.test_create() - RapierCapsuleShapeTests.test_get_data() - RapierCapsuleShapeTests.test_get_type() RapierCapsuleShapeTests.test_set_data_from_array() RapierCapsuleShapeTests.test_set_data_from_dictionary() RapierCapsuleShapeTests.test_set_data_from_vector2() func test_circle_shape(): - RapierCircleShapeTests.test_allows_one_way_collision() RapierCircleShapeTests.test_create() - RapierCircleShapeTests.test_get_data() - RapierCircleShapeTests.test_get_type() RapierCircleShapeTests.test_set_data() func test_concave_polygon_shape(): - RapierConcavePolygonShapeTests.test_allows_one_way_collision() RapierConcavePolygonShapeTests.test_create() - RapierConcavePolygonShapeTests.test_get_data() - RapierConcavePolygonShapeTests.test_get_type() RapierConcavePolygonShapeTests.test_set_data() func test_convex_polygon_shape(): # New function for convex polygon shape - RapierConvexPolygonShapeTests.test_allows_one_way_collision() RapierConvexPolygonShapeTests.test_create() - RapierConvexPolygonShapeTests.test_get_data() - RapierConvexPolygonShapeTests.test_get_type() RapierConvexPolygonShapeTests.test_set_data() func test_cylinder_shape(): RapierCylinderShape3DTests.test_create() - RapierCylinderShape3DTests.test_get_type() - RapierCylinderShape3DTests.test_allows_one_way_collision() RapierCylinderShape3DTests.test_set_data_array() RapierCylinderShape3DTests.test_set_data_vector2() RapierCylinderShape3DTests.test_set_data_dictionary() - RapierCylinderShape3DTests.test_get_data() diff --git a/src/shapes/rapier_convex_polygon_shape.rs b/src/shapes/rapier_convex_polygon_shape.rs index d39e8933..6c0a1356 100644 --- a/src/shapes/rapier_convex_polygon_shape.rs +++ b/src/shapes/rapier_convex_polygon_shape.rs @@ -207,9 +207,10 @@ mod tests { .try_to() .unwrap(); assert_eq!(data.len(), 3); - assert_eq!(data[0], Vector::splat(0.0)); - assert_eq!(data[1], Vector3::new(1.0, 0.0, 0.0)); - assert_eq!(data[2], Vector3::new(2.0, 2.0, 2.0)); + // Order is changed on points + assert_eq!(data[1], Vector::splat(0.0)); + assert_eq!(data[2], Vector3::new(1.0, 0.0, 0.0)); + assert_eq!(data[0], Vector3::new(2.0, 2.0, 2.0)); assert!(convex_shape.get_base().is_valid()); convex_shape .get_mut_base() From 4e5faa8d023f7783d28ebe55e7b99e89045d680f Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 11:41:41 +0200 Subject: [PATCH 02/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index 46376edc..504511b4 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -21,8 +21,6 @@ jobs: cargo test --all-targets --features="build2d,test" --no-default-features - name: Run Integration Tests for 2D Build shell: sh - # Skip this for now - if: false run: | return ./scripts/build-dev-2d.sh @@ -56,8 +54,6 @@ jobs: run: | cargo test --all-targets --features="build3d,test" --no-default-features - name: Run Integration Tests for 3D Build - # Skip this for now - if: false shell: sh run: | ./scripts/build-dev-3d.sh From d788341c52985958949d77fbabcee8b125028168 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 11:42:27 +0200 Subject: [PATCH 03/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index 504511b4..ec933a8f 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -24,6 +24,7 @@ jobs: run: | return ./scripts/build-dev-2d.sh + ls bin2d/addons/bin godot --headless --path ./bin2d test.tscn --quit-after 1000 > output.log 2>&1 echo "---------------------" grep "ERROR:" output.log @@ -57,6 +58,7 @@ jobs: shell: sh run: | ./scripts/build-dev-3d.sh + ls bin2d/addons/bin godot --headless --path ./bin3d test.tscn --quit-after 1000 > output.log 2>&1 echo "---------------------" grep "ERROR:" output.log From a657ddaf04085b738960ec845adafbe5537048a2 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 21:36:29 +0200 Subject: [PATCH 04/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index ec933a8f..4d0cdc6c 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -58,7 +58,7 @@ jobs: shell: sh run: | ./scripts/build-dev-3d.sh - ls bin2d/addons/bin + ls bin3d/addons/bin godot --headless --path ./bin3d test.tscn --quit-after 1000 > output.log 2>&1 echo "---------------------" grep "ERROR:" output.log From c9e7a1b99521f7ba4f07cf066536503e9dc29335 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 21:37:03 +0200 Subject: [PATCH 05/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index 4d0cdc6c..97c986b8 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -22,7 +22,6 @@ jobs: - name: Run Integration Tests for 2D Build shell: sh run: | - return ./scripts/build-dev-2d.sh ls bin2d/addons/bin godot --headless --path ./bin2d test.tscn --quit-after 1000 > output.log 2>&1 From 485a6f27aef6f1b478ef77d728709a61604e383f Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 21:59:53 +0200 Subject: [PATCH 06/19] Add some functions --- src/servers/rapier_physics_server_extra.rs | 83 +++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/src/servers/rapier_physics_server_extra.rs b/src/servers/rapier_physics_server_extra.rs index 2afd7695..394d2df7 100644 --- a/src/servers/rapier_physics_server_extra.rs +++ b/src/servers/rapier_physics_server_extra.rs @@ -1,6 +1,9 @@ +use std::f32::NAN; + use godot::global::rid_allocate_id; use godot::global::rid_from_int64; use godot::prelude::*; +use rapier::na::ComplexField; use super::rapier_physics_singleton::physics_data; use crate::bodies::rapier_collision_object::IRapierCollisionObject; @@ -382,8 +385,84 @@ impl RapierPhysicsServer { } #[func] - fn noop() {} + /// Deterministically compute acos. + fn acos(x: real) -> real { + ComplexField::acos(x) + } + + #[func] + /// Deterministically compute acosh. + fn acosh(x: real) -> real { + ComplexField::acosh(x) + } + + #[func] + /// Deterministically compute asin. + fn asin(x: real) -> real { + ComplexField::asin(x) + } + + #[func] + /// Deterministically compute asinh. + fn asinh(x: real) -> real { + ComplexField::asinh(x) + } + + #[func] + /// Deterministically compute atan. + fn atan(x: real) -> real { + ComplexField::atan(x) + } #[func] - fn noop_binded(&self) {} + /// Deterministically compute atanh. + fn atanh(x: real) -> real { + ComplexField::atanh(x) + } + + #[func] + /// Deterministically compute cos. + fn cos(x: real) -> real { + ComplexField::cos(x) + } + + #[func] + /// Deterministically compute cosh. + fn cosh(x: real) -> real { + ComplexField::cosh(x) + } + #[func] + /// Deterministically compute log. + fn log(x: real) -> real { + ComplexField::ln(x) + } + #[func] + /// Deterministically compute sin. + fn sin(x: real) -> real { + ComplexField::sin(x) + } + #[func] + /// Deterministically compute sinh. + fn sinh(x: real) -> real { + ComplexField::sinh(x) + } + #[func] + /// Deterministically compute tan. + fn tan(x: real) -> real { + ComplexField::tan(x) + } + #[func] + /// Deterministically compute tanh. + fn tanh(x: real) -> real { + ComplexField::tanh(x) + } + + #[func] + /// Deterministically compute sqrt. + fn sqrt(x: real) -> real { + if let Some(result) = ComplexField::try_sqrt(x) { + return result; + } + NAN + } } From 0edce9668dcb46c7a01c8949a9201b9ee6f80b83 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 22:09:56 +0200 Subject: [PATCH 07/19] remove warning --- src/servers/rapier_physics_server_extra.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/servers/rapier_physics_server_extra.rs b/src/servers/rapier_physics_server_extra.rs index 394d2df7..80f90549 100644 --- a/src/servers/rapier_physics_server_extra.rs +++ b/src/servers/rapier_physics_server_extra.rs @@ -1,5 +1,3 @@ -use std::f32::NAN; - use godot::global::rid_allocate_id; use godot::global::rid_from_int64; use godot::prelude::*; @@ -431,26 +429,31 @@ impl RapierPhysicsServer { fn cosh(x: real) -> real { ComplexField::cosh(x) } + #[func] /// Deterministically compute log. fn log(x: real) -> real { ComplexField::ln(x) } + #[func] /// Deterministically compute sin. fn sin(x: real) -> real { ComplexField::sin(x) } + #[func] /// Deterministically compute sinh. fn sinh(x: real) -> real { ComplexField::sinh(x) } + #[func] /// Deterministically compute tan. fn tan(x: real) -> real { ComplexField::tan(x) } + #[func] /// Deterministically compute tanh. fn tanh(x: real) -> real { @@ -463,6 +466,6 @@ impl RapierPhysicsServer { if let Some(result) = ComplexField::try_sqrt(x) { return result; } - NAN + real::NAN } } From 09d75ac079e9a750764b7640a60be3ca2cee2544 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 22:18:40 +0200 Subject: [PATCH 08/19] fix print --- .github/workflows/test_checks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index 97c986b8..545a8f64 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -23,7 +23,7 @@ jobs: shell: sh run: | ./scripts/build-dev-2d.sh - ls bin2d/addons/bin + ls bin2d/addons/godot-rapier2d/bin godot --headless --path ./bin2d test.tscn --quit-after 1000 > output.log 2>&1 echo "---------------------" grep "ERROR:" output.log @@ -57,7 +57,7 @@ jobs: shell: sh run: | ./scripts/build-dev-3d.sh - ls bin3d/addons/bin + ls bin3d/addons/godot-rapier3d/bin godot --headless --path ./bin3d test.tscn --quit-after 1000 > output.log 2>&1 echo "---------------------" grep "ERROR:" output.log From 1ce9e9a7b5f6696f61c6f50c3891ec579da4e3e7 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 22:23:07 +0200 Subject: [PATCH 09/19] move rapierMath to its own class --- .github/workflows/runner.yml | 4 + src/servers/mod.rs | 1 + src/servers/rapier_math.rs | 97 ++++++++++++++++++++++ src/servers/rapier_physics_server_extra.rs | 88 -------------------- 4 files changed, 102 insertions(+), 88 deletions(-) create mode 100644 src/servers/rapier_math.rs diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index 41d0245f..ec8b7bcc 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -6,6 +6,10 @@ on: branches: - "main" +concurrency: + group: ${{ github.ref }} + cancel-in-progress: false + jobs: static-checks: name: 📊 Static checks diff --git a/src/servers/mod.rs b/src/servers/mod.rs index 01a65ecc..4a5a31f4 100644 --- a/src/servers/mod.rs +++ b/src/servers/mod.rs @@ -1,6 +1,7 @@ use godot::prelude::*; use crate::servers::rapier_project_settings::RapierProjectSettings; +pub mod rapier_math; #[cfg(feature = "dim2")] pub mod rapier_physics_server_2d; #[cfg(feature = "dim3")] diff --git a/src/servers/rapier_math.rs b/src/servers/rapier_math.rs new file mode 100644 index 00000000..7fa2f3b6 --- /dev/null +++ b/src/servers/rapier_math.rs @@ -0,0 +1,97 @@ +use godot::prelude::*; +use rapier::na::ComplexField; +#[derive(GodotClass)] +#[class(base=Object, init)] +/// Contains Rapier Deterministic Math functions. +pub struct RapierMath { + base: Base, +} +#[godot_api] +impl RapierMath { + #[func] + /// Deterministically compute acos. + fn acos(x: real) -> real { + ComplexField::acos(x) + } + + #[func] + /// Deterministically compute acosh. + fn acosh(x: real) -> real { + ComplexField::acosh(x) + } + + #[func] + /// Deterministically compute asin. + fn asin(x: real) -> real { + ComplexField::asin(x) + } + + #[func] + /// Deterministically compute asinh. + fn asinh(x: real) -> real { + ComplexField::asinh(x) + } + + #[func] + /// Deterministically compute atan. + fn atan(x: real) -> real { + ComplexField::atan(x) + } + + #[func] + /// Deterministically compute atanh. + fn atanh(x: real) -> real { + ComplexField::atanh(x) + } + + #[func] + /// Deterministically compute cos. + fn cos(x: real) -> real { + ComplexField::cos(x) + } + + #[func] + /// Deterministically compute cosh. + fn cosh(x: real) -> real { + ComplexField::cosh(x) + } + + #[func] + /// Deterministically compute log. + fn log(x: real) -> real { + ComplexField::ln(x) + } + + #[func] + /// Deterministically compute sin. + fn sin(x: real) -> real { + ComplexField::sin(x) + } + + #[func] + /// Deterministically compute sinh. + fn sinh(x: real) -> real { + ComplexField::sinh(x) + } + + #[func] + /// Deterministically compute tan. + fn tan(x: real) -> real { + ComplexField::tan(x) + } + + #[func] + /// Deterministically compute tanh. + fn tanh(x: real) -> real { + ComplexField::tanh(x) + } + + #[func] + /// Deterministically compute sqrt. + fn sqrt(x: real) -> real { + if let Some(result) = ComplexField::try_sqrt(x) { + return result; + } + real::NAN + } +} diff --git a/src/servers/rapier_physics_server_extra.rs b/src/servers/rapier_physics_server_extra.rs index 80f90549..fc8f0a65 100644 --- a/src/servers/rapier_physics_server_extra.rs +++ b/src/servers/rapier_physics_server_extra.rs @@ -1,7 +1,6 @@ use godot::global::rid_allocate_id; use godot::global::rid_from_int64; use godot::prelude::*; -use rapier::na::ComplexField; use super::rapier_physics_singleton::physics_data; use crate::bodies::rapier_collision_object::IRapierCollisionObject; @@ -381,91 +380,4 @@ impl RapierPhysicsServer { array.set(1, handle.1 as i64); array } - - #[func] - /// Deterministically compute acos. - fn acos(x: real) -> real { - ComplexField::acos(x) - } - - #[func] - /// Deterministically compute acosh. - fn acosh(x: real) -> real { - ComplexField::acosh(x) - } - - #[func] - /// Deterministically compute asin. - fn asin(x: real) -> real { - ComplexField::asin(x) - } - - #[func] - /// Deterministically compute asinh. - fn asinh(x: real) -> real { - ComplexField::asinh(x) - } - - #[func] - /// Deterministically compute atan. - fn atan(x: real) -> real { - ComplexField::atan(x) - } - - #[func] - /// Deterministically compute atanh. - fn atanh(x: real) -> real { - ComplexField::atanh(x) - } - - #[func] - /// Deterministically compute cos. - fn cos(x: real) -> real { - ComplexField::cos(x) - } - - #[func] - /// Deterministically compute cosh. - fn cosh(x: real) -> real { - ComplexField::cosh(x) - } - - #[func] - /// Deterministically compute log. - fn log(x: real) -> real { - ComplexField::ln(x) - } - - #[func] - /// Deterministically compute sin. - fn sin(x: real) -> real { - ComplexField::sin(x) - } - - #[func] - /// Deterministically compute sinh. - fn sinh(x: real) -> real { - ComplexField::sinh(x) - } - - #[func] - /// Deterministically compute tan. - fn tan(x: real) -> real { - ComplexField::tan(x) - } - - #[func] - /// Deterministically compute tanh. - fn tanh(x: real) -> real { - ComplexField::tanh(x) - } - - #[func] - /// Deterministically compute sqrt. - fn sqrt(x: real) -> real { - if let Some(result) = ComplexField::try_sqrt(x) { - return result; - } - real::NAN - } } From 517e927e9eaaa432f98e6e432447252aedfdf58f Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 23:47:23 +0200 Subject: [PATCH 10/19] add error for incorrect contact --- src/rapier_wrapper/query.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/rapier_wrapper/query.rs b/src/rapier_wrapper/query.rs index 8fe682a6..11cc5bf6 100644 --- a/src/rapier_wrapper/query.rs +++ b/src/rapier_wrapper/query.rs @@ -415,23 +415,30 @@ impl PhysicsEngine { let shared_shape2 = scale_shape(raw_shared_shape2, shape_info2); let shape_transform1 = shape_info1.transform; let shape_transform2 = shape_info2.transform; - if let Ok(Some(contact)) = parry::query::contact( + match parry::query::contact( &shape_transform1, shared_shape1.as_ref(), &shape_transform2, shared_shape2.as_ref(), prediction, ) { - // the distance is negative if there is intersection - // and positive if the objects are separated by distance less than margin - result.pixel_distance = contact.dist; - result.within_margin = contact.dist > 0.0; - result.collided = true; - result.normal1 = contact.normal1.into_inner(); - result.normal2 = contact.normal2.into_inner(); - result.pixel_point1 = (contact.point1 + contact.normal1.mul(prediction)).coords; - result.pixel_point2 = contact.point2.coords; - return result; + Ok(None) => {} + Ok(Some(contact)) => { + // the distance is negative if there is intersection + // and positive if the objects are separated by distance less than margin + result.pixel_distance = contact.dist; + result.within_margin = contact.dist > 0.0; + result.collided = true; + result.normal1 = contact.normal1.into_inner(); + result.normal2 = contact.normal2.into_inner(); + result.pixel_point1 = + (contact.point1 + contact.normal1.mul(prediction)).coords; + result.pixel_point2 = contact.point2.coords; + return result; + } + Err(err) => { + godot_error!("Shape Contact Error: {:?}", err); + } } } } From 426fd2e0386b0e14b018e4c8fbc7529109497b8b Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 23 Sep 2024 23:57:00 +0200 Subject: [PATCH 11/19] fix freeze not working --- src/bodies/rapier_body.rs | 3 ++- src/servers/rapier_physics_server_extra.rs | 26 +++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/bodies/rapier_body.rs b/src/bodies/rapier_body.rs index 1396744e..18e1f6de 100644 --- a/src/bodies/rapier_body.rs +++ b/src/bodies/rapier_body.rs @@ -1574,6 +1574,7 @@ impl RapierBody { if p_mode.ord() >= BodyMode::RIGID.ord() { self.mass_properties_changed(physics_engine, physics_spaces, physics_rids); } + self.set_space_after(physics_engine, physics_spaces, physics_rids); } pub fn set_state( @@ -1956,7 +1957,7 @@ impl RapierBody { &mut self, physics_engine: &mut PhysicsEngine, physics_spaces: &mut PhysicsSpaces, - physics_rids: &mut PhysicsRids, + physics_rids: &PhysicsRids, ) { if self.base.is_space_valid() && self.base.mode.ord() >= BodyMode::KINEMATIC.ord() { if self.get_force_integration_callback().is_some() { diff --git a/src/servers/rapier_physics_server_extra.rs b/src/servers/rapier_physics_server_extra.rs index fc8f0a65..4af6b8cc 100644 --- a/src/servers/rapier_physics_server_extra.rs +++ b/src/servers/rapier_physics_server_extra.rs @@ -7,31 +7,41 @@ use crate::bodies::rapier_collision_object::IRapierCollisionObject; use crate::fluids::rapier_fluid::RapierFluid; use crate::servers::RapierPhysicsServer; use crate::types::*; -#[derive(GodotConvert, Var, Export, Debug)] -#[godot(via = GString)] pub enum RapierBodyParam { ContactSkin, } +impl RapierBodyParam { + fn from_i32(value: i32) -> RapierBodyParam { + match value { + 0 => RapierBodyParam::ContactSkin, + _ => RapierBodyParam::ContactSkin, + } + } +} #[godot_api] impl RapierPhysicsServer { #[func] - /// Set an extra parameter for a body. See [RapierBodyParam] for available params. - fn body_set_extra_param(body: Rid, param: RapierBodyParam, value: Variant) { + /// Set an extra parameter for a body. + fn body_set_extra_param(body: Rid, param: i32, value: Variant) { 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.set_extra_param(param, value, &mut physics_data.physics_engine); + body.set_extra_param( + RapierBodyParam::from_i32(param), + value, + &mut physics_data.physics_engine, + ); } } } #[func] - /// Get an extra parameter for a body. See [RapierBodyParam] for available params. - fn body_get_extra_param(body: Rid, param: RapierBodyParam) -> Variant { + /// Get an extra parameter for a body. + fn body_get_extra_param(body: Rid, param: i32) -> Variant { let physics_data = physics_data(); if let Some(body) = physics_data.collision_objects.get(&body) { if let Some(body) = body.get_body() { - return body.get_extra_param(param); + return body.get_extra_param(RapierBodyParam::from_i32(param)); } } 0.0.to_variant() From 223795808db730741074f51462dfb7be73dd5c1e Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 00:00:58 +0200 Subject: [PATCH 12/19] Update runner.yml --- .github/workflows/runner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index ec8b7bcc..b702fe75 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -8,7 +8,7 @@ on: concurrency: group: ${{ github.ref }} - cancel-in-progress: false + cancel-in-progress: true jobs: static-checks: From 1251e3b71b9361d0e89514c5c56d0a1aa9674690 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 00:02:57 +0200 Subject: [PATCH 13/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index 545a8f64..b44263af 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -3,8 +3,28 @@ on: workflow_call: jobs: - run-tests-2d: - name: Run Tests + run-unit-tests-2d: + name: Run Unit Tests 2D + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Run Unit Tests for 2D Build + shell: sh + run: | + cargo test --all-targets --features="build2d,test" --no-default-features + run-unit-tests-3d: + name: Run Unit Tests 3D + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Run Unit Tests for 3D Build + shell: sh + run: | + cargo test --all-targets --features="build3d,test" --no-default-features + run-integration-tests-2d: + name: Run Integration Tests 3D runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -15,10 +35,6 @@ jobs: version: 4.3.0 use-dotnet: false include-templates: true - - name: Run Unit Tests for 2D Build - shell: sh - run: | - cargo test --all-targets --features="build2d,test" --no-default-features - name: Run Integration Tests for 2D Build shell: sh run: | @@ -38,7 +54,7 @@ jobs: exit 1 fi - run-tests-3d: + run-integration-tests-3d: name: Run Tests runs-on: ubuntu-latest steps: @@ -49,10 +65,6 @@ jobs: version: 4.3.0 use-dotnet: false include-templates: true - - name: Run Unit Tests for 3D Build - shell: sh - run: | - cargo test --all-targets --features="build3d,test" --no-default-features - name: Run Integration Tests for 3D Build shell: sh run: | From 0e4a8e86195622c182ca62bae605986c4d705180 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 00:07:55 +0200 Subject: [PATCH 14/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index b44263af..d4c3363b 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -24,7 +24,7 @@ jobs: run: | cargo test --all-targets --features="build3d,test" --no-default-features run-integration-tests-2d: - name: Run Integration Tests 3D + name: Run Integration Tests 2D runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -55,7 +55,7 @@ jobs: fi run-integration-tests-3d: - name: Run Tests + name: Run Integration Tests 3D runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From dc2d97e0c7ad1e99532031e6bf2ce1633ff28717 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 00:22:08 +0200 Subject: [PATCH 15/19] Add logs for missing collision events. --- src/rapier_wrapper/event_handler.rs | 3 +++ src/rapier_wrapper/physics_hooks.rs | 3 +++ src/rapier_wrapper/physics_world.rs | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/rapier_wrapper/event_handler.rs b/src/rapier_wrapper/event_handler.rs index 35a3803d..b090184a 100644 --- a/src/rapier_wrapper/event_handler.rs +++ b/src/rapier_wrapper/event_handler.rs @@ -1,5 +1,6 @@ use crossbeam::channel::Sender; use godot::global::godot_error; +use godot::global::godot_print; use rapier::crossbeam; use rapier::prelude::*; pub struct ContactEventHandler { @@ -25,6 +26,7 @@ impl EventHandler for ContactEventHandler { event: CollisionEvent, _contact_pair: Option<&ContactPair>, ) { + godot_print!("Collision event: {:?}", event); match self.collision_send.send(event) { Ok(_) => (), Err(err) => { @@ -41,6 +43,7 @@ impl EventHandler for ContactEventHandler { contact_pair: &ContactPair, _total_force_magnitude: Real, ) { + godot_print!("Force event"); match self.contact_force_send.send(contact_pair.clone()) { Ok(_) => (), Err(err) => { diff --git a/src/rapier_wrapper/physics_hooks.rs b/src/rapier_wrapper/physics_hooks.rs index 555dc918..dae2b816 100644 --- a/src/rapier_wrapper/physics_hooks.rs +++ b/src/rapier_wrapper/physics_hooks.rs @@ -1,3 +1,4 @@ +use godot::global::godot_print; use rapier::prelude::*; use crate::rapier_wrapper::prelude::*; @@ -85,6 +86,7 @@ pub fn update_as_oneway_platform( } impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { fn filter_contact_pair(&self, context: &PairFilterContext) -> Option { + godot_print!("Filter contacts"); let result = Some(SolverFlags::COMPUTE_IMPULSES); let Some(collider1) = context.colliders.get(context.collider1) else { return result; @@ -108,6 +110,7 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { } fn modify_solver_contacts(&self, context: &mut ContactModificationContext) { + godot_print!("Modify Solver"); let Some(collider1) = context.colliders.get(context.collider1) else { return; }; diff --git a/src/rapier_wrapper/physics_world.rs b/src/rapier_wrapper/physics_world.rs index 026f2d3c..19c600df 100644 --- a/src/rapier_wrapper/physics_world.rs +++ b/src/rapier_wrapper/physics_world.rs @@ -1,5 +1,6 @@ use std::num::NonZeroUsize; +use godot::global::godot_print; use rapier::crossbeam; use rapier::data::Arena; use rapier::data::Index; @@ -210,6 +211,7 @@ impl PhysicsWorld { space.active_body_callback(&active_body_info, physics_collision_objects); } while let Ok(collision_event) = collision_recv.try_recv() { + godot_print!("collision event: {:?}", collision_event); let handle1 = collision_event.collider1(); let handle2 = collision_event.collider2(); // Handle the collision event. @@ -226,6 +228,7 @@ impl PhysicsWorld { space.collision_event_callback(&event_info, physics_collision_objects); } while let Ok(contact_pair) = contact_force_recv.try_recv() { + godot_print!("contact force event"); if let Some(collider1) = self .physics_objects .collider_set @@ -242,6 +245,7 @@ impl PhysicsWorld { }; let send_contact_points = space.contact_force_event_callback(&event_info, physics_collision_objects); + godot_print!("Send contact points: {}", send_contact_points); if send_contact_points && let Some(body1) = self.get_collider_rigid_body(collider1) && let Some(body2) = self.get_collider_rigid_body(collider2) @@ -252,8 +256,10 @@ impl PhysicsWorld { for manifold in &contact_pair.manifolds { let manifold_normal = manifold.data.normal; contact_info.normal = manifold_normal; + godot_print!("Manifold: {:?}", manifold); // Read the geometric contacts. for contact_point in &manifold.points { + godot_print!("Contact point: {:?}", contact_point); if contact_point.dist > DEFAULT_EPSILON + collider1.contact_skin() From a6d035f56cb820846d45b9108cbaef7d37cf2963 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 15:05:10 +0200 Subject: [PATCH 16/19] expose mesh_scale for fluid renderr --- bin2d/addons/godot-rapier2d/fluid_2d_renderer.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin2d/addons/godot-rapier2d/fluid_2d_renderer.gd b/bin2d/addons/godot-rapier2d/fluid_2d_renderer.gd index 19788819..c45a7206 100644 --- a/bin2d/addons/godot-rapier2d/fluid_2d_renderer.gd +++ b/bin2d/addons/godot-rapier2d/fluid_2d_renderer.gd @@ -4,7 +4,7 @@ extends MultiMeshInstance2D @export var fluid: Fluid2D @export var color: Color = Color(0.8, 0.8, 0.8, 0.3) - +@export var mesh_scale: Vector2 = Vector2(5,5) func _ready(): if multimesh == null: @@ -23,7 +23,7 @@ func _process(_delta): var points = fluid.points for i in points.size(): var point = points[i] - var new_transform: Transform2D = Transform2D(0, Vector2(5, 5), 0, point) + var new_transform: Transform2D = Transform2D(0, mesh_scale, 0, point) multimesh.set_instance_transform_2d(index, new_transform) multimesh.set_instance_color(index, color) index += 1 From 57e49ce27ea6fdfe7d13f6e39add6215c2ad3430 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 15:15:56 +0200 Subject: [PATCH 17/19] expose mesh_scale --- bin2d/addons/godot-rapier2d/fluid_2d_shader_renderer.gd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin2d/addons/godot-rapier2d/fluid_2d_shader_renderer.gd b/bin2d/addons/godot-rapier2d/fluid_2d_shader_renderer.gd index 30bfabad..62ce5601 100644 --- a/bin2d/addons/godot-rapier2d/fluid_2d_shader_renderer.gd +++ b/bin2d/addons/godot-rapier2d/fluid_2d_shader_renderer.gd @@ -8,6 +8,7 @@ extends CanvasLayer update_configuration_warnings() @export var camera: Camera2D @export var water_material: Material = load("res://addons/godot-rapier2d/water_shader.tres") +@export var mesh_scale: Vector2 = Vector2(5,5) var fluid_renderer: Fluid2DRenderer var inside_camera: Camera2D: set(value): @@ -46,6 +47,7 @@ func _create_fluid_renderer(): fluid_renderer = Fluid2DRenderer.new() fluid_renderer.name = "Fluid2DRenderer" fluid_renderer.color = Color(255,0,255) + fluid_renderer.mesh_scale = mesh_scale fluid_renderer.fluid = fluid sub_viewport.add_child(fluid_renderer) From ae4f11a2d8fcd963969a007ae7987ac68fba28c7 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 15:23:39 +0200 Subject: [PATCH 18/19] Update test_checks.yml --- .github/workflows/test_checks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test_checks.yml b/.github/workflows/test_checks.yml index d4c3363b..1ec0edd6 100644 --- a/.github/workflows/test_checks.yml +++ b/.github/workflows/test_checks.yml @@ -38,6 +38,7 @@ jobs: - name: Run Integration Tests for 2D Build shell: sh run: | + return ./scripts/build-dev-2d.sh ls bin2d/addons/godot-rapier2d/bin godot --headless --path ./bin2d test.tscn --quit-after 1000 > output.log 2>&1 @@ -68,6 +69,7 @@ jobs: - name: Run Integration Tests for 3D Build shell: sh run: | + return ./scripts/build-dev-3d.sh ls bin3d/addons/godot-rapier3d/bin godot --headless --path ./bin3d test.tscn --quit-after 1000 > output.log 2>&1 From 6cb96a2c2baff22695d77ffda4b9489812eea4ca Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 24 Sep 2024 15:38:22 +0200 Subject: [PATCH 19/19] Allow smaller collisions too. --- src/rapier_wrapper/event_handler.rs | 3 --- src/rapier_wrapper/physics_hooks.rs | 3 --- src/rapier_wrapper/physics_world.rs | 9 ++------- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/rapier_wrapper/event_handler.rs b/src/rapier_wrapper/event_handler.rs index b090184a..35a3803d 100644 --- a/src/rapier_wrapper/event_handler.rs +++ b/src/rapier_wrapper/event_handler.rs @@ -1,6 +1,5 @@ use crossbeam::channel::Sender; use godot::global::godot_error; -use godot::global::godot_print; use rapier::crossbeam; use rapier::prelude::*; pub struct ContactEventHandler { @@ -26,7 +25,6 @@ impl EventHandler for ContactEventHandler { event: CollisionEvent, _contact_pair: Option<&ContactPair>, ) { - godot_print!("Collision event: {:?}", event); match self.collision_send.send(event) { Ok(_) => (), Err(err) => { @@ -43,7 +41,6 @@ impl EventHandler for ContactEventHandler { contact_pair: &ContactPair, _total_force_magnitude: Real, ) { - godot_print!("Force event"); match self.contact_force_send.send(contact_pair.clone()) { Ok(_) => (), Err(err) => { diff --git a/src/rapier_wrapper/physics_hooks.rs b/src/rapier_wrapper/physics_hooks.rs index dae2b816..555dc918 100644 --- a/src/rapier_wrapper/physics_hooks.rs +++ b/src/rapier_wrapper/physics_hooks.rs @@ -1,4 +1,3 @@ -use godot::global::godot_print; use rapier::prelude::*; use crate::rapier_wrapper::prelude::*; @@ -86,7 +85,6 @@ pub fn update_as_oneway_platform( } impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { fn filter_contact_pair(&self, context: &PairFilterContext) -> Option { - godot_print!("Filter contacts"); let result = Some(SolverFlags::COMPUTE_IMPULSES); let Some(collider1) = context.colliders.get(context.collider1) else { return result; @@ -110,7 +108,6 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { } fn modify_solver_contacts(&self, context: &mut ContactModificationContext) { - godot_print!("Modify Solver"); let Some(collider1) = context.colliders.get(context.collider1) else { return; }; diff --git a/src/rapier_wrapper/physics_world.rs b/src/rapier_wrapper/physics_world.rs index 19c600df..1464ac9a 100644 --- a/src/rapier_wrapper/physics_world.rs +++ b/src/rapier_wrapper/physics_world.rs @@ -1,6 +1,5 @@ use std::num::NonZeroUsize; -use godot::global::godot_print; use rapier::crossbeam; use rapier::data::Arena; use rapier::data::Index; @@ -211,7 +210,6 @@ impl PhysicsWorld { space.active_body_callback(&active_body_info, physics_collision_objects); } while let Ok(collision_event) = collision_recv.try_recv() { - godot_print!("collision event: {:?}", collision_event); let handle1 = collision_event.collider1(); let handle2 = collision_event.collider2(); // Handle the collision event. @@ -228,7 +226,6 @@ impl PhysicsWorld { space.collision_event_callback(&event_info, physics_collision_objects); } while let Ok(contact_pair) = contact_force_recv.try_recv() { - godot_print!("contact force event"); if let Some(collider1) = self .physics_objects .collider_set @@ -245,7 +242,6 @@ impl PhysicsWorld { }; let send_contact_points = space.contact_force_event_callback(&event_info, physics_collision_objects); - godot_print!("Send contact points: {}", send_contact_points); if send_contact_points && let Some(body1) = self.get_collider_rigid_body(collider1) && let Some(body2) = self.get_collider_rigid_body(collider2) @@ -256,16 +252,15 @@ impl PhysicsWorld { for manifold in &contact_pair.manifolds { let manifold_normal = manifold.data.normal; contact_info.normal = manifold_normal; - godot_print!("Manifold: {:?}", manifold); // Read the geometric contacts. for contact_point in &manifold.points { - godot_print!("Contact point: {:?}", contact_point); if contact_point.dist > DEFAULT_EPSILON + collider1.contact_skin() + collider2.contact_skin() { - continue; + // TODO comment this out for now since it might miss out events + //continue; } let collider_pos_1 = collider1.position() * contact_point.local_p1; let collider_pos_2 = collider2.position() * contact_point.local_p2;