From 15850687a8024b9ebf60564a12b9ce4d1a5b8014 Mon Sep 17 00:00:00 2001 From: Tomasz Chabora Date: Wed, 8 Jul 2020 00:51:25 +0200 Subject: [PATCH] Allow Area2D and 3D mouse events without a collision layer Co-authored-by: Tomasz Chabora --- doc/classes/CollisionObject2D.xml | 10 +++++----- modules/bullet/godot_result_callbacks.cpp | 2 +- servers/physics/space_sw.cpp | 6 +++--- servers/physics_2d/space_2d_sw.cpp | 7 +++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/doc/classes/CollisionObject2D.xml b/doc/classes/CollisionObject2D.xml index 4fae55ed4ca..4fdead27b97 100644 --- a/doc/classes/CollisionObject2D.xml +++ b/doc/classes/CollisionObject2D.xml @@ -216,8 +216,8 @@ - - If [code]true[/code], this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one [code]collision_layer[/code] bit to be set. + + If [code]true[/code], this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. @@ -229,17 +229,17 @@ - Emitted when an input event occurs. Requires [member input_pickable] to be [code]true[/code] and at least one [code]collision_layer[/code] bit to be set. See [method _input_event] for details. + Emitted when an input event occurs and [code]input_pickable[/code] is [code]true[/code]. See [method _input_event] for details. - Emitted when the mouse pointer enters any of this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [code]collision_layer[/code] bit to be set. + Emitted when the mouse pointer enters any of this object's shapes. - Emitted when the mouse pointer exits all this object's shapes. Requires [member input_pickable] to be [code]true[/code] and at least one [code]collision_layer[/code] bit to be set. + Emitted when the mouse pointer exits all this object's shapes. diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index 6e54d10abf7..e8a4abe266d 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -57,7 +57,7 @@ bool GodotFilterCallback::needBroadphaseCollision(btBroadphaseProxy *proxy0, btB bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_pickRay || needs) { btCollisionObject *btObj = static_cast(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast(btObj->getUserPointer()); diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index ba1070a3cb8..5244e83e86e 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -34,9 +34,9 @@ #include "core/project_settings.h" #include "physics_server_sw.h" -_FORCE_INLINE_ static bool _can_collide_with(CollisionObjectSW *p_object, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { +_FORCE_INLINE_ static bool _can_collide_with(CollisionObjectSW *p_object, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_ignore_layers = false) { - if (!(p_object->get_collision_layer() & p_collision_mask)) { + if (!p_ignore_layers && !(p_object->get_collision_layer() & p_collision_mask)) { return false; } @@ -115,7 +115,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto for (int i = 0; i < amount; i++) { - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas, p_pick_ray)) continue; if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable())) diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 4748094fe26..9cd67256fb2 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -34,9 +34,9 @@ #include "core/os/os.h" #include "core/pair.h" #include "physics_2d_server_sw.h" -_FORCE_INLINE_ static bool _can_collide_with(CollisionObject2DSW *p_object, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - if (!(p_object->get_collision_layer() & p_collision_mask)) { +_FORCE_INLINE_ static bool _can_collide_with(CollisionObject2DSW *p_object, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_ignore_layers = false) { + if (!p_ignore_layers && !(p_object->get_collision_layer() & p_collision_mask)) { return false; } @@ -63,8 +63,7 @@ int Physics2DDirectSpaceStateSW::_intersect_point_impl(const Vector2 &p_point, S int cc = 0; for (int i = 0; i < amount; i++) { - - if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) + if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas, p_filter_by_canvas)) continue; if (p_exclude.has(space->intersection_query_results[i]->get_self()))