Page MenuHome

Refactor: Clarify object bounding boxes, cache bounds in data (WIP)
AbandonedPublic

Authored by Hans Goudey (HooglyBoogly) on Dec 16 2021, 8:16 PM.

Details

Reviewers
None
Summary

This patch is an exploration of a few changes:

  • More consistent handling of bounding boxes between object types
  • Bounds cache is stored as min and max on object data
  • Objects no longer have a bounding box pointer, instead the can generate a bounding box with the cached min and max on object data.
    • API to retrieve a bounding box returns by value to make it clear there is no caching and to simplify code.
  • BoundBox moves to BLI, since it is runtime data.

TODO/For futher investigation:

  • Make sure the bounding box means the same thing on all object types (i.e. use the evaluated geometry set on relevant object types).
  • Remove object level functions like BKE_hair_boundbox_get in favor of a single object level function and only "minmax" functions on object data.
  • Split off a few cleanup changes
  • Handle copying back to original data:
    • SCULPT_update_object_bounding_box
    • object_sync_boundbox_to_original

I'm posting this as a patch now to get more design feedback before
putting too much work into this.

Diff Detail

Repository
rB Blender
Branch
cleanup-bounding-boxes (branched from master)
Build Status
Buildable 19490
Build 19490: arc lint + arc unit

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Dec 16 2021, 8:16 PM
Hans Goudey (HooglyBoogly) created this revision.
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)

Good to see the simplification and the solution of some inconsistencies. Really the status of Bounding Boxes should be reevaluated :)

  • API to retrieve a bounding box returns by value to make it clear there is no caching and to simplify code.

This approach is a bit strange, especially since the BoundBox struct isn't that small (8 x 3 x float + bool + pad).
Another option would be to pass the reference as a pointer as an *r_bb arg.
I think passing it by reference makes it clearer that the BoundBox is a struct and not a simple type.
But that's not really a problem.

Also on style, I noticed that some "_get" suffixes suggest, at least to me, that the boundbox is cached (which is not the case for example with BKE_armature_boundbox_get). Maybe it's more convenient to rename to "_calc"?

Also I fear that the lack of boundbox caching support in some types might impact the performance of some modal operators like the transform whose snapping reads the boundboxes of all objects in the scene.
For simplicity, in order to avoid creating a new flag for each type, perhaps we could indicate that only the boundbox of the object is cached. And avoid calling functions like BKE_armature_boundbox_get?
(Or everything could be cached).

Anyway the patch is still WIP, maybe it's too early for these suggestions.

(Also I think the bool valid member of the struct BoundBox is out of place).

Hans Goudey (HooglyBoogly) planned changes to this revision.Apr 2 2022, 12:49 AM

I'm planning to do this refactor in smaller steps, starting with D16204.