BVH fix pairing AABB init and mask checks
Fix bug whereby AABBs were reused from previous items due to use of a pool, resulting in missed collisions. Also use full mask collision checks for all cases except generic update.
This commit is contained in:
parent
bc90bcb65c
commit
df18f72384
@ -90,10 +90,10 @@ public:
|
||||
|
||||
BVHHandle create(T *p_userdata, const AABB &p_aabb = AABB(), int p_subindex = 0, bool p_pairable = false, uint32_t p_pairable_type = 0, uint32_t p_pairable_mask = 1) {
|
||||
|
||||
// not completely sure why, but the order of the pairing callbacks seems to be causing problems in
|
||||
// the render tree unless these are flushed before creating a new object
|
||||
// not sure if absolutely necessary to flush collisions here. It will cost performance to, instead
|
||||
// of waiting for update, so only uncomment this if there are bugs.
|
||||
if (USE_PAIRS) {
|
||||
_check_for_collisions();
|
||||
//_check_for_collisions();
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
@ -107,7 +107,15 @@ public:
|
||||
BVHHandle h = tree.item_add(p_userdata, p_aabb, p_subindex, p_pairable, p_pairable_type, p_pairable_mask);
|
||||
|
||||
if (USE_PAIRS) {
|
||||
_add_changed_item(h, p_aabb);
|
||||
// for safety initialize the expanded AABB
|
||||
AABB &expanded_aabb = tree._pairs[h.id()].expanded_aabb;
|
||||
expanded_aabb = p_aabb;
|
||||
expanded_aabb.grow_by(tree._pairing_expansion);
|
||||
|
||||
// force a collision check no matter the AABB
|
||||
_add_changed_item(h, p_aabb, false);
|
||||
|
||||
_check_for_collisions(true);
|
||||
}
|
||||
|
||||
return h;
|
||||
@ -170,6 +178,8 @@ public:
|
||||
}
|
||||
|
||||
tree.item_remove(p_handle);
|
||||
|
||||
_check_for_collisions(true);
|
||||
}
|
||||
|
||||
// call e.g. once per frame (this does a trickle optimize)
|
||||
@ -192,11 +202,9 @@ public:
|
||||
|
||||
if (USE_PAIRS) {
|
||||
|
||||
// not completely sure why, but the order of the pairing callbacks seems to be causing problems in
|
||||
// the render tree unless these are flushed before creating a new object.. we will do this for set_pairable
|
||||
// to just in case. This may not be required, and may slow things down slightly when there are a lot
|
||||
// of visibility changes in a frame
|
||||
_check_for_collisions();
|
||||
// not sure if absolutely necessary to flush collisions here. It will cost performance to, instead
|
||||
// of waiting for update, so only uncomment this if there are bugs.
|
||||
//_check_for_collisions();
|
||||
|
||||
// when the pairable state changes, we need to force a collision check because newly pairable
|
||||
// items may be in collision, and unpairable items might move out of collision.
|
||||
|
@ -14,6 +14,7 @@ struct ItemPairs {
|
||||
void clear() {
|
||||
num_pairs = 0;
|
||||
extended_pairs.reset();
|
||||
expanded_aabb = AABB();
|
||||
}
|
||||
|
||||
AABB expanded_aabb;
|
||||
|
Loading…
Reference in New Issue
Block a user