Skip to content

Commit

Permalink
feat: add 3 point view-plane creation via vertex select mode in view_…
Browse files Browse the repository at this point in the history
…align operator
  • Loading branch information
tristan-hm committed Feb 7, 2022
1 parent 83bc45d commit 3406bd3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions sketching/view_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@ def set_custom_transform_orientation(self):


def prepare_view_align(self, context):
mesh = bmesh.from_edit_mesh(context.object.data)
world_matrix = context.object.matrix_world

if self.selection_type == 0:
selected_vertices = len([v for v in mesh.verts if v.select])
if selected_vertices == 3:
bpy.ops.mesh.edge_face_add()
context.tool_settings.mesh_select_mode = (False, False, True)
self.selection_type = 2

bpy.ops.view3d.view_axis(type='TOP', align_active=True)

self.set_custom_transform_orientation()

mesh = bmesh.from_edit_mesh(context.object.data)
world_matrix = context.object.matrix_world

if self.selection_type == 0:
(location, rotation) = self.set_3d_cursor_to_vertex(mesh, world_matrix)
set_3d_cursor(location, rotation.to_quaternion())
Expand All @@ -177,7 +184,7 @@ def has_invalid_selection(self, context):
selected_faces = len([f for f in mesh.faces if f.select])

if self.selection_type == 0:
return selected_vertices != 1
return selected_vertices != 1 and selected_vertices != 3
elif self.selection_type == 1:
return selected_edges != 1
elif self.selection_type == 2:
Expand All @@ -189,7 +196,10 @@ def has_invalid_selection(self, context):
def finish(self, context):
if self.has_invalid_selection(context):
self.clean_up(context)
self.report({'ERROR_INVALID_INPUT'}, "Ensure a single peice of geometry is selected.")
if self.selection_type == 0:
self.report({'ERROR_INVALID_INPUT'}, "Ensure only a single vertex, or exactly 3 vertices are selected.")
else:
self.report({'ERROR_INVALID_INPUT'}, "Ensure only a single edge or face is selected.")

return {'CANCELLED'}

Expand Down

0 comments on commit 3406bd3

Please sign in to comment.