Merge pull request #23294 from gcardozo123/issue-23235-get-collision-exceptions
Add method get_collision_exceptions to PhysicsBody2D
This commit is contained in:
commit
200c2e7451
9 changed files with 80 additions and 0 deletions
|
@ -21,6 +21,13 @@
|
|||
Adds a body to the list of bodies that this body can't collide with.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_exceptions">
|
||||
<return type="Array">
|
||||
</return>
|
||||
<description>
|
||||
Returns an array of nodes that were added as collision exceptions for this body.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_layer_bit" qualifiers="const">
|
||||
<return type="bool">
|
||||
</return>
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
Adds a body to the list of bodies that this body can't collide with.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_exceptions">
|
||||
<return type="Array">
|
||||
</return>
|
||||
<description>
|
||||
Returns an array of nodes that were added as collision exceptions for this body.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_layer_bit" qualifiers="const">
|
||||
<return type="bool">
|
||||
</return>
|
||||
|
|
|
@ -20,6 +20,13 @@
|
|||
Adds a body to the list of bodies that this body can't collide with.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_exceptions">
|
||||
<return type="Array">
|
||||
</return>
|
||||
<description>
|
||||
Returns an array of nodes that were added as collision exceptions for this body.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_layer_bit" qualifiers="const">
|
||||
<return type="bool">
|
||||
</return>
|
||||
|
|
|
@ -32,8 +32,11 @@
|
|||
|
||||
#include "core/core_string_names.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/list.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/method_bind_ext.gen.inc"
|
||||
#include "core/object.h"
|
||||
#include "core/rid.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
|
||||
void PhysicsBody2D::_notification(int p_what) {
|
||||
|
@ -65,6 +68,8 @@ void PhysicsBody2D::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody2D::_set_layers);
|
||||
ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody2D::_get_layers);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody2D::get_collision_exceptions);
|
||||
ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody2D::add_collision_exception_with);
|
||||
ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody2D::remove_collision_exception_with);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_2D_PHYSICS, "", 0), "_set_layers", "_get_layers"); //for backwards compat
|
||||
|
@ -134,6 +139,20 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) :
|
|||
set_pickable(false);
|
||||
}
|
||||
|
||||
Array PhysicsBody2D::get_collision_exceptions() {
|
||||
List<RID> exceptions;
|
||||
Physics2DServer::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 = Physics2DServer::get_singleton()->body_get_object_instance_id(body);
|
||||
Object *obj = ObjectDB::get_instance(instance_id);
|
||||
PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(obj);
|
||||
ret.append(physics_body);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void PhysicsBody2D::add_collision_exception_with(Node *p_node) {
|
||||
|
||||
ERR_FAIL_NULL(p_node);
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
void set_collision_layer_bit(int p_bit, bool p_value);
|
||||
bool get_collision_layer_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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue