diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-10-12 14:07:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-12 14:07:55 +0200 |
commit | 26bbb26738ec94d2f74ad866b79e5f44ca62ca75 (patch) | |
tree | 06d03256a8142e3f4a76ebe765975569defb1a6d /modules/bullet/space_bullet.cpp | |
parent | 5d63cf161039b43c76ec70c57f27ae3cbf2e670a (diff) | |
parent | 655694b394bb27c031ab5e3b609010b45b80d69e (diff) |
Merge pull request #32641 from nekomatata/change-collision-layer
Fixed RigidBody stuttering when changing collision layer/mask
Diffstat (limited to 'modules/bullet/space_bullet.cpp')
-rw-r--r-- | modules/bullet/space_bullet.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index d2b16b0fd1..e74c29769f 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -42,6 +42,7 @@ #include "servers/physics_server.h" #include "soft_body_bullet.h" +#include <BulletCollision/BroadphaseCollision/btBroadphaseProxy.h> #include <BulletCollision/CollisionDispatch/btCollisionObject.h> #include <BulletCollision/CollisionDispatch/btGhostObject.h> #include <BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h> @@ -459,9 +460,13 @@ void SpaceBullet::remove_area(AreaBullet *p_area) { } void SpaceBullet::reload_collision_filters(AreaBullet *p_area) { - // This is necessary to change collision filter - dynamicsWorld->removeCollisionObject(p_area->get_bt_ghost()); - dynamicsWorld->addCollisionObject(p_area->get_bt_ghost(), p_area->get_collision_layer(), p_area->get_collision_mask()); + btGhostObject *ghost_object = p_area->get_bt_ghost(); + + btBroadphaseProxy *ghost_proxy = ghost_object->getBroadphaseHandle(); + ghost_proxy->m_collisionFilterGroup = p_area->get_collision_layer(); + ghost_proxy->m_collisionFilterMask = p_area->get_collision_mask(); + + dynamicsWorld->refreshBroadphaseProxy(ghost_object); } void SpaceBullet::add_rigid_body(RigidBodyBullet *p_body) { @@ -482,9 +487,13 @@ void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) { } void SpaceBullet::reload_collision_filters(RigidBodyBullet *p_body) { - // This is necessary to change collision filter - remove_rigid_body(p_body); - add_rigid_body(p_body); + btRigidBody *rigid_body = p_body->get_bt_rigid_body(); + + btBroadphaseProxy *body_proxy = rigid_body->getBroadphaseProxy(); + body_proxy->m_collisionFilterGroup = p_body->get_collision_layer(); + body_proxy->m_collisionFilterMask = p_body->get_collision_mask(); + + dynamicsWorld->refreshBroadphaseProxy(rigid_body); } void SpaceBullet::add_soft_body(SoftBodyBullet *p_body) { |