mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Snap - Filter out 2D bounding boxes that are too far from the camera view.
This commit is contained in:
@@ -65,6 +65,8 @@ class Raycast(bonsai.core.tool.Raycast):
|
|||||||
def get_on_screen_2d_bounding_boxes(
|
def get_on_screen_2d_bounding_boxes(
|
||||||
cls, context: bpy.types.Context, obj: bpy.types.Object
|
cls, context: bpy.types.Context, obj: bpy.types.Object
|
||||||
) -> Union[tuple[bpy.types.Object, list[float]], None]:
|
) -> Union[tuple[bpy.types.Object, list[float]], None]:
|
||||||
|
rv3d = context.region_data
|
||||||
|
view_location = rv3d.view_matrix.inverted().translation
|
||||||
obj_matrix = obj.matrix_world.copy()
|
obj_matrix = obj.matrix_world.copy()
|
||||||
bbox = [obj_matrix @ Vector(v) for v in obj.bound_box]
|
bbox = [obj_matrix @ Vector(v) for v in obj.bound_box]
|
||||||
|
|
||||||
@@ -75,6 +77,19 @@ class Raycast(bonsai.core.tool.Raycast):
|
|||||||
assert isinstance(context.space_data, bpy.types.SpaceView3D)
|
assert isinstance(context.space_data, bpy.types.SpaceView3D)
|
||||||
assert context.space_data.region_3d
|
assert context.space_data.region_3d
|
||||||
|
|
||||||
|
# Do not include objects too far from camera view
|
||||||
|
if rv3d.view_perspective == "PERSP":
|
||||||
|
threshold = 200
|
||||||
|
min_distance = float('inf')
|
||||||
|
closest_distance: float = None
|
||||||
|
for point in bbox:
|
||||||
|
distance = (view_location - point).length
|
||||||
|
if distance < min_distance:
|
||||||
|
min_distance = distance
|
||||||
|
closest_distance = distance
|
||||||
|
if closest_distance > threshold:
|
||||||
|
return None
|
||||||
|
|
||||||
for v in bbox:
|
for v in bbox:
|
||||||
coord_2d = view3d_utils.location_3d_to_region_2d(context.region, context.space_data.region_3d, v)
|
coord_2d = view3d_utils.location_3d_to_region_2d(context.region, context.space_data.region_3d, v)
|
||||||
if coord_2d is not None:
|
if coord_2d is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user