snap: black formatting

This commit is contained in:
Bruno Perdigão
2026-08-22 21:09:36 -03:00
committed by Bruno Perdigão
parent 105d186a34
commit e9c7203c23
2 changed files with 66 additions and 52 deletions
+21 -7
View File
@@ -42,7 +42,6 @@ import bonsai.tool as tool
from bonsai.bim.module.drawing.data import DecoratorData from bonsai.bim.module.drawing.data import DecoratorData
from bonsai.bim.module.drawing.decoration import CutDecorator from bonsai.bim.module.drawing.decoration import CutDecorator
_wireframe_batch_cache: dict[int, dict[str, tuple[GPUBatch, int, list]]] = {} _wireframe_batch_cache: dict[int, dict[str, tuple[GPUBatch, int, list]]] = {}
_wireframe_vert_fmt: GPUVertFormat | None = None _wireframe_vert_fmt: GPUVertFormat | None = None
_triangle_batch_cache: dict[int, tuple[GPUBatch, int]] = {} _triangle_batch_cache: dict[int, tuple[GPUBatch, int]] = {}
@@ -158,6 +157,7 @@ def _get_solid_triangles(obj: bpy.types.Object) -> list[tuple[tuple, tuple, tupl
eval_obj.to_mesh_clear() eval_obj.to_mesh_clear()
return tris return tris
def _get_cut_object_solid_triangles(obj: bpy.types.Object) -> list[tuple[tuple, tuple, tuple]]: def _get_cut_object_solid_triangles(obj: bpy.types.Object) -> list[tuple[tuple, tuple, tuple]]:
""" """
Gets all the triangles from cut decorator fill, in local space Gets all the triangles from cut decorator fill, in local space
@@ -306,6 +306,7 @@ def _get_boundary_features(obj: bpy.types.Object) -> tuple[list[tuple[float, flo
eval_obj.to_mesh_clear() eval_obj.to_mesh_clear()
return verts, edge_pairs return verts, edge_pairs
def _get_cut_object_features( def _get_cut_object_features(
obj: bpy.types.Object, obj: bpy.types.Object,
) -> (list[tuple[float, float, float]], list[tuple[tuple[float, float, float], tuple[float, float, float]]]): ) -> (list[tuple[float, float, float]], list[tuple[tuple[float, float, float], tuple[float, float, float]]]):
@@ -322,7 +323,11 @@ def _get_cut_object_features(
model_props = tool.Model.get_model_props() model_props = tool.Model.get_model_props()
if not (element := tool.Ifc.get_entity(obj)): if not (element := tool.Ifc.get_entity(obj)):
return [], [] return [], []
if model_props.show_cut_decorator and element.id() in DecoratorData.cut_cache and (hasattr(obj.data, "polygons") and len(obj.data.polygons) > 0): if (
model_props.show_cut_decorator
and element.id() in DecoratorData.cut_cache
and (hasattr(obj.data, "polygons") and len(obj.data.polygons) > 0)
):
verts, edges = DecoratorData.cut_cache[element.id()] verts, edges = DecoratorData.cut_cache[element.id()]
if not verts or not edges: if not verts or not edges:
return {}, {} return {}, {}
@@ -373,8 +378,6 @@ def _ensure_wireframe_batches(obj: bpy.types.Object) -> dict[str, tuple[GPUBatch
all_vert_coords, edge_pairs = _get_boundary_features(obj) all_vert_coords, edge_pairs = _get_boundary_features(obj)
batches: dict[str, tuple[GPUBatch, int, list]] = {} batches: dict[str, tuple[GPUBatch, int, list]] = {}
# POINTS batch (all wireframe vertices) # POINTS batch (all wireframe vertices)
@@ -410,6 +413,7 @@ def _ensure_wireframe_batches(obj: bpy.types.Object) -> dict[str, tuple[GPUBatch
_wireframe_batch_cache[cache_key] = batches _wireframe_batch_cache[cache_key] = batches
return batches return batches
def _get_tris_render_ops(objs_to_raycast: list[bpy.types.Object]) -> list[tuple[GPUBatch, Matrix, int]]: def _get_tris_render_ops(objs_to_raycast: list[bpy.types.Object]) -> list[tuple[GPUBatch, Matrix, int]]:
"""Build render ops for solid (triangle) objects to raycast. """Build render ops for solid (triangle) objects to raycast.
@@ -447,7 +451,10 @@ def _get_tris_render_ops(objs_to_raycast: list[bpy.types.Object]) -> list[tuple[
render_ops.append((batch, snap_obj.matrix_world.copy(), slot_base)) render_ops.append((batch, snap_obj.matrix_world.copy(), slot_base))
return render_ops return render_ops
def _create_tris_snaps(context: bpy.types.Context, event: bpy.types.Event, mouse_read_rect, buffers_list, last_buf, xray_mode) -> tuple[list[dict], bpy.types.Object | None]:
def _create_tris_snaps(
context: bpy.types.Context, event: bpy.types.Event, mouse_read_rect, buffers_list, last_buf, xray_mode
) -> tuple[list[dict], bpy.types.Object | None]:
"""Decode the triangle readback buffer(s) into face snaps. """Decode the triangle readback buffer(s) into face snaps.
In xray mode each object is read back as a single pixel under the In xray mode each object is read back as a single pixel under the
@@ -537,7 +544,10 @@ def _create_tris_snaps(context: bpy.types.Context, event: bpy.types.Event, mouse
return snaps, closest_obj return snaps, closest_obj
def _get_wireframe_render_ops(objs_to_raycast: list[bpy.types.Objects]) -> tuple[list[tuple[GPUBatch, Matrix, int]], list[tuple]]:
def _get_wireframe_render_ops(
objs_to_raycast: list[bpy.types.Objects],
) -> tuple[list[tuple[GPUBatch, Matrix, int]], list[tuple]]:
"""Build render ops for wireframe (non-solid) objects. """Build render ops for wireframe (non-solid) objects.
Boundary points and lines of each object are assigned sequential slot Boundary points and lines of each object are assigned sequential slot
@@ -589,7 +599,10 @@ def _get_wireframe_render_ops(objs_to_raycast: list[bpy.types.Objects]) -> tuple
return render_ops, obj_slots return render_ops, obj_slots
def _create_wireframe_snaps(context: bpy.types.Context, event: bpy.types.Event, mouse_read_rect, obj_slots, last_buf) -> tuple[list[dict], None]:
def _create_wireframe_snaps(
context: bpy.types.Context, event: bpy.types.Event, mouse_read_rect, obj_slots, last_buf
) -> tuple[list[dict], None]:
"""Decode the wireframe readback buffer into vertex/edge snaps. """Decode the wireframe readback buffer into vertex/edge snaps.
Finds the closest non-zero pixel to the cursor, maps its encoded slot ID Finds the closest non-zero pixel to the cursor, maps its encoded slot ID
@@ -723,6 +736,7 @@ def _create_wireframe_snaps(context: bpy.types.Context, event: bpy.types.Event,
return snaps, None return snaps, None
class Raycast(bonsai.core.tool.Raycast): class Raycast(bonsai.core.tool.Raycast):
offset = 10 offset = 10
mouse_offset = ( mouse_offset = (