From db3a54633a196f23648be4eaa250eadf4fdec9d3 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Wed, 1 Jan 2025 12:06:52 +0100 Subject: [PATCH] fix liquid phantom collisions (#327) - Fixes https://github.com/appsinacup/godot-rapier-physics/issues/281 --- Cargo.lock | 149 ++++++++++++++++----------------- Cargo.toml | 2 +- src/fluids/rapier_fluid.rs | 6 +- src/rapier_wrapper/collider.rs | 22 +++-- src/rapier_wrapper/fluid.rs | 9 +- 5 files changed, 100 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2c1055c..d916758b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,9 +25,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.20" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "approx" @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.20.0" +version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" +checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" [[package]] name = "byteorder" @@ -153,18 +153,18 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.13" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -181,18 +181,18 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "downcast-rs" @@ -219,7 +219,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys", ] [[package]] @@ -274,15 +274,15 @@ checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "godot" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a90179fdd02c52d3d0ac1fbf724c5cb51391f4e207651d105de12e4bda1b6e" +checksum = "af1ef36742c735d052653908691bc7d3379c468201c40737b1cef418e41973ca" dependencies = [ "godot-core", "godot-macros", @@ -290,9 +290,9 @@ dependencies = [ [[package]] name = "godot-bindings" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4172322f6d35c46c657b3de80900a8bdc8937cff4bc3b8559d47c74eb91f0304" +checksum = "2b6d1fa1835f22e22e76e0f31d5bc60b5546a51fafc1968c89ca873079e2aac0" dependencies = [ "bindgen", "gdextension-api", @@ -302,15 +302,15 @@ dependencies = [ [[package]] name = "godot-cell" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5070ea39cbc64f6b7ed01c752a550999b08b5244aea4f3c4525e51a9f18a1" +checksum = "059990edd2ff438b242658aee04767a8416216198ad2e7cfff487556a3b641e2" [[package]] name = "godot-codegen" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22edb4e0e638be594ba199b860290bf092f83d1d166a18d03f75b9d3add66db9" +checksum = "981fb5e3c11f9dadb45328e5564feca2ede77cb3f1b0f143ddaaeed7d6196165" dependencies = [ "godot-bindings", "heck", @@ -322,9 +322,9 @@ dependencies = [ [[package]] name = "godot-core" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2111d99582c537ab65666b725697f85d5c9f8630ec7d0b1d2620c0e95e8e7182" +checksum = "b91f35b2e4490b8f4cb223e67488e9884abef7d25ed4bf696a03ee864e278576" dependencies = [ "glam", "godot-bindings", @@ -336,9 +336,9 @@ dependencies = [ [[package]] name = "godot-ffi" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b01c965bd5189988c7bc7c13ddb02fe4181856ed6a59072ae23029aacce4188" +checksum = "bea403db67ace1c1c41f96839a7f270be50e499af6aa2d2e9925f6933db0e583" dependencies = [ "gensym", "godot-bindings", @@ -349,9 +349,9 @@ dependencies = [ [[package]] name = "godot-macros" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0be00fe849f158b0f9e330fc54fc5d0f41385c30ea2ed1c59a2d031b3c43726" +checksum = "06424dae5bc4d417b8570c97d169af3fa15f80393bfbd26fe385be8eba7bf00a" dependencies = [ "godot-bindings", "markdown", @@ -423,18 +423,18 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -479,15 +479,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.166" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets", @@ -664,9 +664,9 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "ordered-float" -version = "4.5.0" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c65ee1f9701bf938026630b455d5315f490640234259037edb259798b3bcf85e" +checksum = "7bb71e1b3fa6ca1c61f383464aaf2bb0e2f8e772a1f01d486832464de363b951" dependencies = [ "num-traits", ] @@ -687,7 +687,7 @@ dependencies = [ "num-derive", "num-traits", "ordered-float", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "slab", @@ -712,7 +712,7 @@ dependencies = [ "num-derive", "num-traits", "ordered-float", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "slab", @@ -738,7 +738,7 @@ dependencies = [ "num-traits", "ordered-float", "rstar", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "slab", @@ -764,7 +764,7 @@ dependencies = [ "num-traits", "ordered-float", "rstar", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "slab", @@ -796,9 +796,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -821,7 +821,7 @@ dependencies = [ "ordered-float", "parry2d", "rayon", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "thiserror", @@ -846,7 +846,7 @@ dependencies = [ "ordered-float", "parry2d-f64", "rayon", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "thiserror", @@ -871,7 +871,7 @@ dependencies = [ "ordered-float", "parry3d", "rayon", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "thiserror", @@ -896,7 +896,7 @@ dependencies = [ "ordered-float", "parry3d-f64", "rayon", - "rustc-hash 2.0.0", + "rustc-hash 2.1.0", "serde", "simba", "thiserror", @@ -983,21 +983,21 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc-hash" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1008,9 +1008,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "safe_arch" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3460605018fdc9612bce72735cba0d27efbcd9904780d44c7e3a9948f96148a" +checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323" dependencies = [ "bytemuck", ] @@ -1018,9 +1018,10 @@ dependencies = [ [[package]] name = "salva2d" version = "0.9.0" -source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#526c7435bd8ac9b856e0d67eefab9c632c264c6c" dependencies = [ "approx", + "bitflags", "fnv", "generational-arena", "instant", @@ -1034,7 +1035,7 @@ dependencies = [ [[package]] name = "salva2d-f64" version = "0.9.0" -source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#526c7435bd8ac9b856e0d67eefab9c632c264c6c" dependencies = [ "approx", "fnv", @@ -1050,9 +1051,10 @@ dependencies = [ [[package]] name = "salva3d" version = "0.9.0" -source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#526c7435bd8ac9b856e0d67eefab9c632c264c6c" dependencies = [ "approx", + "bitflags", "fnv", "generational-arena", "instant", @@ -1066,7 +1068,7 @@ dependencies = [ [[package]] name = "salva3d-f64" version = "0.9.0" -source = "git+https://github.com/ughuuu/salva?branch=custom-changes#976a349989c6c146906ca31c6ca1909140b17e49" +source = "git+https://github.com/ughuuu/salva?branch=custom-changes#526c7435bd8ac9b856e0d67eefab9c632c264c6c" dependencies = [ "approx", "fnv", @@ -1081,18 +1083,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -1101,9 +1103,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.133" +version = "1.0.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" dependencies = [ "itoa", "memchr", @@ -1166,9 +1168,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" -version = "2.0.89" +version = "2.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" dependencies = [ "proc-macro2", "quote", @@ -1272,15 +1274,6 @@ dependencies = [ "safe_arch", ] -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index 355a7b92..4745ae93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ bincode = { version = "1", optional = true } hashbrown = { version = "0.14" } #godot = { git = "https://github.com/Ughuuu/gdext", branch = "remove-hook", features=["api-4-3", "register-docs", "experimental-threads"] } -godot = { version = "0.2", features=["register-docs"] } +godot = { version = "0.2.2", features=["register-docs"] } rapier2d = { git = "https://github.com/ughuuu/rapier", branch = "custom-changes", optional = true } rapier2d-f64 = { git = "https://github.com/ughuuu/rapier", branch = "custom-changes", optional = true} diff --git a/src/fluids/rapier_fluid.rs b/src/fluids/rapier_fluid.rs index ac82d702..55bf9422 100644 --- a/src/fluids/rapier_fluid.rs +++ b/src/fluids/rapier_fluid.rs @@ -246,7 +246,11 @@ impl RapierFluid { self.space = p_space; self.space_id = space.get_state().get_id(); if self.space_id != WorldHandle::default() { - self.fluid_handle = physics_engine.fluid_create(self.space_id, self.density); + self.fluid_handle = physics_engine.fluid_create( + self.space_id, + self.density, + salva::object::interaction_groups::InteractionGroups::all(), + ); } self.set_points(self.points.clone(), physics_engine); self.set_effects(self.effects.clone(), physics_engine); diff --git a/src/rapier_wrapper/collider.rs b/src/rapier_wrapper/collider.rs index b279f672..bb70e23c 100644 --- a/src/rapier_wrapper/collider.rs +++ b/src/rapier_wrapper/collider.rs @@ -305,10 +305,14 @@ impl PhysicsEngine { let collider_handle = physics_world.insert_collider(collider, body_handle); // register fluid coupling. Dynamic coupling doens't work for halfspace if !is_shape_halfspace { - let boundary_handle = physics_world - .fluids_pipeline - .liquid_world - .add_boundary(Boundary::new(Vec::new())); + let boundary_handle = + physics_world + .fluids_pipeline + .liquid_world + .add_boundary(Boundary::new( + Vec::new(), + salva::object::interaction_groups::InteractionGroups::all(), + )); physics_world.fluids_pipeline.coupling.register_coupling( boundary_handle, collider_handle, @@ -379,10 +383,16 @@ impl PhysicsEngine { pub fn collider_destroy(&mut self, world_handle: WorldHandle, collider_handle: ColliderHandle) { if let Some(physics_world) = self.get_mut_world(world_handle) { - physics_world + if let Some(boundary_handle) = physics_world .fluids_pipeline .coupling - .unregister_coupling(collider_handle); + .unregister_coupling(collider_handle) + { + physics_world + .fluids_pipeline + .liquid_world + .remove_boundary(boundary_handle); + } physics_world.remove_collider(collider_handle); } } diff --git a/src/rapier_wrapper/fluid.rs b/src/rapier_wrapper/fluid.rs index 0abd5824..b902cb5c 100644 --- a/src/rapier_wrapper/fluid.rs +++ b/src/rapier_wrapper/fluid.rs @@ -6,10 +6,15 @@ use salva::solver::*; use super::shape::point_array_to_vec; use crate::rapier_wrapper::prelude::*; impl PhysicsEngine { - pub fn fluid_create(&mut self, world_handle: WorldHandle, density: Real) -> HandleDouble { + pub fn fluid_create( + &mut self, + world_handle: WorldHandle, + density: Real, + interaction_groups: salva::object::interaction_groups::InteractionGroups, + ) -> HandleDouble { if let Some(physics_world) = self.get_mut_world(world_handle) { let particle_radius = physics_world.fluids_pipeline.liquid_world.particle_radius(); - let fluid = Fluid::new(Vec::new(), particle_radius, density); + let fluid = Fluid::new(Vec::new(), particle_radius, density, interaction_groups); return fluid_handle_to_handle( physics_world.fluids_pipeline.liquid_world.add_fluid(fluid), );