Merge pull request #40280 from madmiraal/PR40193-3.2

[3.2] Allow Area2D and 3D mouse events without a collision layer.
This commit is contained in:
Rémi Verschelde 2020-07-13 15:10:28 +02:00 committed by GitHub
commit e798cf81c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 13 deletions

View file

@ -216,8 +216,8 @@
</method> </method>
</methods> </methods>
<members> <members>
<member name="input_pickable" type="bool" setter="set_pickable" getter="is_pickable" default="true"> <member name="input_pickable" type="bool" setter="set_pickable" getter="is_pickable">
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.
</member> </member>
</members> </members>
<signals> <signals>
@ -229,17 +229,17 @@
<argument index="2" name="shape_idx" type="int"> <argument index="2" name="shape_idx" type="int">
</argument> </argument>
<description> <description>
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.
</description> </description>
</signal> </signal>
<signal name="mouse_entered"> <signal name="mouse_entered">
<description> <description>
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.
</description> </description>
</signal> </signal>
<signal name="mouse_exited"> <signal name="mouse_exited">
<description> <description>
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.
</description> </description>
</signal> </signal>
</signals> </signals>

View file

@ -57,7 +57,7 @@ bool GodotFilterCallback::needBroadphaseCollision(btBroadphaseProxy *proxy0, btB
bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) const {
const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); 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<btCollisionObject *>(proxy0->m_clientObject); btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject);
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer());

View file

@ -34,9 +34,9 @@
#include "core/project_settings.h" #include "core/project_settings.h"
#include "physics_server_sw.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; return false;
} }
@ -115,7 +115,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3 &p_from, const Vecto
for (int i = 0; i < amount; i++) { 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; continue;
if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable())) if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable()))

View file

@ -34,9 +34,9 @@
#include "core/os/os.h" #include "core/os/os.h"
#include "core/pair.h" #include "core/pair.h"
#include "physics_2d_server_sw.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; return false;
} }
@ -63,8 +63,7 @@ int Physics2DDirectSpaceStateSW::_intersect_point_impl(const Vector2 &p_point, S
int cc = 0; int cc = 0;
for (int i = 0; i < amount; i++) { 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, p_filter_by_canvas))
if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
continue; continue;
if (p_exclude.has(space->intersection_query_results[i]->get_self())) if (p_exclude.has(space->intersection_query_results[i]->get_self()))