summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorGuilherme Recchi Cardozo <gcardozo@esss.com.br>2018-10-24 16:32:55 -0300
committerGuilherme Recchi Cardozo <gcardozo@inf.ufsm.br>2018-11-01 06:41:34 -0300
commit3fb2069d39b2ccfb30c06cffcf802d73ce169d60 (patch)
treed33d96ede12e8d00fde999ae2979633c0fc55182 /scene/3d
parentd42fd8fa7936ab0f32e207063908cc41dc1ee7ab (diff)
Add method get_collision_exceptions
Adding this method to PhysicsBody, PhysicsBody2D and SoftBody. It returns a list of nodes included in collision exceptions. Fixes #23235, cheers!
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/physics_body.cpp18
-rw-r--r--scene/3d/physics_body.h1
-rw-r--r--scene/3d/soft_body.cpp19
-rw-r--r--scene/3d/soft_body.h1
4 files changed, 39 insertions, 0 deletions
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 0fb0869979..5b55c3d2a8 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -32,7 +32,10 @@
#include "core/core_string_names.h"
#include "core/engine.h"
+#include "core/list.h"
#include "core/method_bind_ext.gen.inc"
+#include "core/object.h"
+#include "core/rid.h"
#include "scene/scene_string_names.h"
#ifdef TOOLS_ENABLED
@@ -108,6 +111,20 @@ bool PhysicsBody::get_collision_layer_bit(int p_bit) const {
return get_collision_layer() & (1 << p_bit);
}
+Array PhysicsBody::get_collision_exceptions() {
+ List<RID> exceptions;
+ PhysicsServer::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions);
+ Array ret;
+ for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) {
+ RID body = E->get();
+ ObjectID instance_id = PhysicsServer::get_singleton()->body_get_object_instance_id(body);
+ Object *obj = ObjectDB::get_instance(instance_id);
+ PhysicsBody *physics_body = Object::cast_to<PhysicsBody>(obj);
+ ret.append(physics_body);
+ }
+ return ret;
+}
+
void PhysicsBody::add_collision_exception_with(Node *p_node) {
ERR_FAIL_NULL(p_node);
@@ -289,6 +306,7 @@ void StaticBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("_reload_physics_characteristics"), &StaticBody::_reload_physics_characteristics);
+ ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody::get_collision_exceptions);
ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody::add_collision_exception_with);
ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody::remove_collision_exception_with);
diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h
index ed9f41197b..fa319e6fbb 100644
--- a/scene/3d/physics_body.h
+++ b/scene/3d/physics_body.h
@@ -69,6 +69,7 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
+ Array get_collision_exceptions();
void add_collision_exception_with(Node *p_node); //must be physicsbody
void remove_collision_exception_with(Node *p_node);
diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body.cpp
index 4ebc941ebc..1e730d0b3d 100644
--- a/scene/3d/soft_body.cpp
+++ b/scene/3d/soft_body.cpp
@@ -29,8 +29,12 @@
/*************************************************************************/
#include "soft_body.h"
+#include "core/list.h"
+#include "core/object.h"
#include "core/os/os.h"
+#include "core/rid.h"
#include "scene/3d/collision_object.h"
+#include "scene/3d/physics_body.h"
#include "scene/3d/skeleton.h"
#include "servers/physics_server.h"
@@ -335,6 +339,7 @@ void SoftBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftBody::set_parent_collision_ignore);
ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftBody::get_parent_collision_ignore);
+ ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &SoftBody::get_collision_exceptions);
ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftBody::add_collision_exception_with);
ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftBody::remove_collision_exception_with);
@@ -547,6 +552,20 @@ PoolVector<SoftBody::PinnedPoint> SoftBody::get_pinned_points_indices() {
return pinned_points;
}
+Array SoftBody::get_collision_exceptions() {
+ List<RID> exceptions;
+ PhysicsServer::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions);
+ Array ret;
+ for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) {
+ RID body = E->get();
+ ObjectID instance_id = PhysicsServer::get_singleton()->body_get_object_instance_id(body);
+ Object *obj = ObjectDB::get_instance(instance_id);
+ PhysicsBody *physics_body = Object::cast_to<PhysicsBody>(obj);
+ ret.append(physics_body);
+ }
+ return ret;
+}
+
void SoftBody::add_collision_exception_with(Node *p_node) {
ERR_FAIL_NULL(p_node);
CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node);
diff --git a/scene/3d/soft_body.h b/scene/3d/soft_body.h
index ee3d8d87cf..b1e699e839 100644
--- a/scene/3d/soft_body.h
+++ b/scene/3d/soft_body.h
@@ -166,6 +166,7 @@ public:
void set_drag_coefficient(real_t p_drag_coefficient);
real_t get_drag_coefficient();
+ Array get_collision_exceptions();
void add_collision_exception_with(Node *p_node);
void remove_collision_exception_with(Node *p_node);