Add support and UI for Bonsai snap target.

The user can now select snap target for Bonsai polyline tool.
The options are shown in the bottom of Blender's Snapping panel.
This commit is contained in:
Bruno Perdigão
2025-01-20 10:51:39 -03:00
parent 9e81a3da17
commit 5649708ca4
4 changed files with 47 additions and 0 deletions
+3
View File
@@ -138,6 +138,7 @@ classes = [
prop.BIMMeshProperties,
prop.BIMFacet,
prop.BIMFilterGroup,
prop.BIMSnapProperties,
ui.BIM_UL_clipping_plane,
ui.BIM_UL_generic,
ui.BIM_UL_topics,
@@ -194,6 +195,7 @@ classes = [
ui.BIM_PT_section_plane,
ui.BIM_PT_section_with_cappings,
ui.BIM_PT_decorators_overlay,
ui.BIM_PT_snappping,
]
for mod in modules.values():
@@ -226,6 +228,7 @@ def register():
bpy.app.handlers.load_post.append(handler.load_post)
bpy.app.handlers.load_post.append(handler.loadIfcStore)
bpy.types.Scene.BIMProperties = bpy.props.PointerProperty(type=prop.BIMProperties)
bpy.types.Scene.BIMSnapProperties = bpy.props.PointerProperty(type=prop.BIMSnapProperties)
bpy.types.Screen.BIMAreaProperties = bpy.props.CollectionProperty(type=prop.BIMAreaProperties)
bpy.types.Screen.BIMTabProperties = bpy.props.PointerProperty(type=prop.BIMTabProperties)
bpy.types.Collection.BIMCollectionProperties = bpy.props.PointerProperty(type=prop.BIMCollectionProperties)
+7
View File
@@ -574,3 +574,10 @@ class BIMFacet(PropertyGroup):
class BIMFilterGroup(PropertyGroup):
filters: CollectionProperty(type=BIMFacet, name="filters")
class BIMSnapProperties(PropertyGroup):
vertex: BoolProperty(name="Vertex")
edge: BoolProperty(name="Edge")
edge_center: BoolProperty(name="Edge Center")
face: BoolProperty(name="Face")
+23
View File
@@ -1233,3 +1233,26 @@ class BIM_PT_decorators_overlay(Panel):
row.prop(model_props, "show_wall_axis", text="Wall Axis")
row = col.row(align=True)
row.prop(model_props, "show_slab_direction", text="Slab Direction")
class BIM_PT_snappping(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "HEADER"
bl_parent_id = "VIEW3D_PT_snapping"
bl_label = "Bonsai Snap Target"
@classmethod
def poll(cls, context):
return context.mode == "OBJECT"
def draw(self, context):
prop = context.scene.BIMSnapProperties
layout = self.layout
row = layout.row(align=True)
row.prop(prop, "vertex", toggle=True, icon="SNAP_VERTEX")
row = layout.row(align=True)
row.prop(prop, "edge", toggle=True, icon="SNAP_EDGE")
row = layout.row(align=True)
row.prop(prop, "edge_center", toggle=True, icon="SNAP_MIDPOINT")
row = layout.row(align=True)
row.prop(prop, "face", toggle=True, icon="SNAP_FACE")
+14
View File
@@ -496,6 +496,17 @@ class Snap(bonsai.core.tool.Snap):
@classmethod
def select_snapping_points(cls, context, event, tool_state, detected_snaps):
def filter_snapping_points_based_on_settings(snapping_points):
options = ["Plane"]
props = context.scene.BIMSnapProperties
for prop in props.__annotations__.keys():
if getattr(props, prop):
options.append(props.rna_type.properties[prop].name)
filtered_points = [point for point in snapping_points if point[1] in options]
return filtered_points
snapping_points = []
edges = [] # Get edges to create edge-intersection snap
for snap_group in detected_snaps:
@@ -550,6 +561,8 @@ class Snap(bonsai.core.tool.Snap):
if intersection[1]:
snapping_points.insert(0, (intersection[1], "Edge Intersection", None))
snapping_points = filter_snapping_points_based_on_settings(snapping_points)
# Make Axis first priority
if tool_state.lock_axis or tool_state.axis_method in {"X", "Y", "Z"}:
cls.update_snapping_ref(snapping_points[0][0], snapping_points[0][1])
@@ -567,6 +580,7 @@ class Snap(bonsai.core.tool.Snap):
cls.update_snapping_point(snapping_points[0][0], snapping_points[0][1], snapping_points[0][2])
return snapping_points
@classmethod
def modify_snapping_point_selection(cls, snapping_points, lock_axis=False):
shifted_list = snapping_points[1:] + snapping_points[:1]