Skip to content

Commit 6d687de

Browse files
committedDec 24, 2020
Fix BVH to world_aabb, and call update
The calls to the BVH need to use the world space AABB, rather than local space for it to work. Also, update was not being called which is required to update the AABB as objects move.
1 parent dbd00d9 commit 6d687de

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
 

‎core/math/dynamic_bvh.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,17 @@ void DynamicBVH::_update(Node *leaf, int lookahead) {
354354
void DynamicBVH::update(const ID &p_id, const AABB &p_box) {
355355
ERR_FAIL_COND(!p_id.is_valid());
356356
Node *leaf = p_id.node;
357-
Node *base = _remove_leaf(leaf);
357+
358358
Volume volume;
359359
volume.min = p_box.position;
360360
volume.max = p_box.position + p_box.size;
361+
362+
if ((leaf->volume.min == volume.min) && (leaf->volume.max == volume.max)) {
363+
// noop
364+
return;
365+
}
366+
367+
Node *base = _remove_leaf(leaf);
361368
if (base) {
362369
if (lkhd >= 0) {
363370
for (int i = 0; (i < lkhd) && base->parent; ++i) {

‎servers/rendering/renderer_scene_cull.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,15 @@ void RendererSceneCull::_update_instance(Instance *p_instance) {
10701070

10711071
if (!p_instance->indexer_id.is_valid()) {
10721072
if ((1 << p_instance->base_type) & RS::INSTANCE_GEOMETRY_MASK) {
1073-
p_instance->indexer_id = p_instance->scenario->indexers[Scenario::INDEXER_GEOMETRY].insert(p_instance->aabb, p_instance);
1073+
p_instance->indexer_id = p_instance->scenario->indexers[Scenario::INDEXER_GEOMETRY].insert(p_instance->transformed_aabb, p_instance);
10741074
} else {
1075-
p_instance->indexer_id = p_instance->scenario->indexers[Scenario::INDEXER_VOLUMES].insert(p_instance->aabb, p_instance);
1075+
p_instance->indexer_id = p_instance->scenario->indexers[Scenario::INDEXER_VOLUMES].insert(p_instance->transformed_aabb, p_instance);
1076+
}
1077+
} else {
1078+
if ((1 << p_instance->base_type) & RS::INSTANCE_GEOMETRY_MASK) {
1079+
p_instance->scenario->indexers[Scenario::INDEXER_GEOMETRY].update(p_instance->indexer_id, p_instance->transformed_aabb);
1080+
} else {
1081+
p_instance->scenario->indexers[Scenario::INDEXER_VOLUMES].update(p_instance->indexer_id, p_instance->transformed_aabb);
10761082
}
10771083
}
10781084

0 commit comments

Comments
 (0)
Please sign in to comment.