mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Lazy BVH tree construction in SnapObj
This commit is contained in:
@@ -377,6 +377,7 @@ class Raycast(bonsai.core.tool.Raycast):
|
|||||||
view3d_utils.location_3d_to_region_2d(region, rv3d, v) for v in snap_obj.verts_3d
|
view3d_utils.location_3d_to_region_2d(region, rv3d, v) for v in snap_obj.verts_3d
|
||||||
] # Numpy version is worst in performance
|
] # Numpy version is worst in performance
|
||||||
|
|
||||||
|
snap_obj._ensure_bvh()
|
||||||
intersected = snap_obj.raycast_boxes(
|
intersected = snap_obj.raycast_boxes(
|
||||||
context, event, snap_obj.root, intersected=[], rays=(ray_origin, ray_direction)
|
context, event, snap_obj.root, intersected=[], rays=(ray_origin, ray_direction)
|
||||||
)
|
)
|
||||||
@@ -936,12 +937,19 @@ class SnapObj:
|
|||||||
def __init__(self, obj: bpy.types.Object):
|
def __init__(self, obj: bpy.types.Object):
|
||||||
self.__class__.all.append(self)
|
self.__class__.all.append(self)
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.root = self._create_root_node()
|
self.root = None
|
||||||
self.root.edges = [e.index for e in obj.data.edges]
|
self._bvh_built = False
|
||||||
self.split_box(self.root, 0)
|
|
||||||
self.verts_3d = [obj.matrix_world @ v.co for v in obj.data.vertices]
|
self.verts_3d = [obj.matrix_world @ v.co for v in obj.data.vertices]
|
||||||
self.snap_points = []
|
self.snap_points = []
|
||||||
|
|
||||||
|
def _ensure_bvh(self):
|
||||||
|
if self._bvh_built:
|
||||||
|
return
|
||||||
|
self.root = self._create_root_node()
|
||||||
|
self.root.edges = [e.index for e in self.obj.data.edges]
|
||||||
|
self.split_box(self.root, 0)
|
||||||
|
self._bvh_built = True
|
||||||
|
|
||||||
def __clear_all__():
|
def __clear_all__():
|
||||||
for instance in SnapObj.all:
|
for instance in SnapObj.all:
|
||||||
del instance
|
del instance
|
||||||
|
|||||||
Reference in New Issue
Block a user