Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force-update BVHs when updating query engine #271

Merged
merged 3 commits into from
Nov 21, 2019
Merged

Force-update BVHs when updating query engine #271

merged 3 commits into from
Nov 21, 2019

Conversation

doyubkim
Copy link
Owner

@doyubkim doyubkim commented Nov 15, 2019

This revision fixes the issue where internal BVH structures are not being updated even when updateQueryEngine is invoked. This issue can cause emitters or colliders to fetch old bounding boxes when one of the surface set types is used for geometry representation as reported in Issue #268.

@doyubkim doyubkim self-assigned this Nov 15, 2019
@kentbarber
Copy link
Contributor

Wouldn't invalidating the bvh of the TriangleMesh3 cause it to rebuild every frame? That may be quite expensive. Currently I am only manually invalidating the bvh for only those emitters and colliders that are dynamic. Any static ones are not invalidated. And I am not allowing moving of TriangleMesh3 objects since I had concerns with this as well, but I don't remember the exact details. I haven't checked the code yet to see if my concerns are valid, will do so this weekend.

@doyubkim
Copy link
Owner Author

Actually trimesh doesn’t need such an aggressive cache invalidation as it can figure out when the mesh has changed. I will revert that particular change.

@kentbarber
Copy link
Contributor

kentbarber commented Nov 15, 2019

The changes you added work for me. Although I haven't included invalidateCache() for the TriangleMesh. Note that I just manually moved across the changes for each file for this fix. I didn't use the full branch.

I will test Triangle Meshes at later date and make a note of the invalidateCache() issue. If the mesh itself doesn't change then it should be able to use its transform to update the boundbox directly without having to recalculate the BBox for every triangle or calling _bvh.build() at all. Perhaps a special case for TriangleMesh3 where it has a special flag to set if you want to recalculate if the points have changed, otherwise just transform the last calculated BBox using the new Transform. updateQueryEngine(DIRTYFLAGS::POINTS | DIRTYFLAGS::MATRIX) or perhaps just a SetDirtyPoints() method for a mesh, since I carry around a pointer to the mesh anyway so it doesn't need to be generic as a parameter to updateQueryEngine.

@codecov-io
Copy link

codecov-io commented Nov 15, 2019

Codecov Report

Merging #271 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #271      +/-   ##
==========================================
+ Coverage   87.89%   87.92%   +0.03%     
==========================================
  Files         549      549              
  Lines       37010    37082      +72     
==========================================
+ Hits        32529    32605      +76     
+ Misses       4481     4477       -4
Impacted Files Coverage Δ
src/jet/surface_set2.cpp 86.92% <100%> (+0.98%) ⬆️
include/jet/detail/bvh3-inl.h 86.74% <100%> (+0.05%) ⬆️
src/tests/unit_tests/surface_set3_tests.cpp 100% <100%> (ø) ⬆️
...c/tests/unit_tests/implicit_surface_set3_tests.cpp 100% <100%> (ø) ⬆️
...c/tests/unit_tests/implicit_surface_set2_tests.cpp 100% <100%> (ø) ⬆️
src/jet/implicit_surface_set3.cpp 86.39% <100%> (+0.87%) ⬆️
src/tests/unit_tests/surface_set2_tests.cpp 100% <100%> (ø) ⬆️
src/jet/implicit_surface_set2.cpp 86.39% <100%> (+0.87%) ⬆️
include/jet/detail/bvh2-inl.h 86.74% <100%> (+0.05%) ⬆️
src/jet/surface_set3.cpp 86.92% <100%> (+0.98%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d298e3...676d8ab. Read the comment docs.

@doyubkim
Copy link
Owner Author

Thanks for your suggestion, @kentbarber! Yes, dirty flag is one way to go. It does have similar flags, but not with such a finer level. For this particular fix/PR, I will focus on addressing surface set issues and think about a more generic way of controlling BVHs within the codebase.

Anyway, I also found a bug where BVH can be an ever-growing box without properly resetting root to null. I also added unit tests. Thus taking off the WIP label and making it mergeable.

@doyubkim doyubkim changed the title [WIP] Force-update BVHs when updating query engine Force-update BVHs when updating query engine Nov 15, 2019
@doyubkim doyubkim removed their assignment Nov 15, 2019
@doyubkim doyubkim mentioned this pull request Nov 15, 2019
@utilForever
Copy link
Collaborator

Sorry, I was very busy. I'll review it today. 🙏

Copy link
Collaborator

@utilForever utilForever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and verified all unit test code. LGTM.
Thanks for the fix! 🎉

@utilForever utilForever merged commit e46b019 into master Nov 21, 2019
@doyubkim doyubkim deleted the fix-268 branch November 21, 2019 06:02
@doyubkim
Copy link
Owner Author

Thanks @utilForever !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants