Allow mathutils.bvhtree generation for entire scene
The
mathutils.bvhtree
module, mostly used for raycasting tasks, provides functions to generate BVHTrees for singular objects, BMeshes and Polygon-Lists, allowing for efficient repeated ray-casts on an object-level.
When wanting to ray-cast not just objects but entire scenes, there currently appear to only be two options:
1: use
scene.ray_cast()
, which appears to not use or cache a BVH internally, or
2: generate
BVHTree
s for each object in the scene and ray cast every one of these.
In complex scenes with many objects, neither of these options are preferable - raycasting without a BVH is expensive, and ray casting every object once can also be slow with increasing object count.
A cheaper solution would be to allow the generation of a BVHTree of the entire scene via the bpy API, which can then be ray cast like the object-level BVHTrees.
The API could mirror the
BVHTree.FromObject()
interface:
FromObject(object, depsgraph, deform=True, render=False, cage=False, epsilon=0.0)
FromScene(scene, depsgraph, deform=True, render=False, cage=False, epsilon=0.0)
0 Comments