diff --git a/source/__init__.py b/source/__init__.py index b18a987..1073d73 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -34,8 +34,8 @@ module_names = ( "pie_editor_switch", "pie_file", "pie_manipulator", - "pie_mesh_align", "pie_mesh_delete", + "pie_mesh_flatten", "pie_mesh_merge", "pie_object_parenting", "pie_proportional_editing", diff --git a/source/pie_mesh_align.py b/source/pie_mesh_flatten.py similarity index 51% rename from source/pie_mesh_align.py rename to source/pie_mesh_flatten.py index 3c3613d..c852cf4 100644 --- a/source/pie_mesh_align.py +++ b/source/pie_mesh_flatten.py @@ -8,72 +8,48 @@ from bpy.props import EnumProperty from .hotkeys import register_hotkey -class PIE_MT_mesh_align(Menu): - bl_idname = "PIE_MT_mesh_align" - bl_label = "Mesh Align" +class PIE_MT_mesh_flatten(Menu): + bl_idname = "PIE_MT_mesh_flatten" + bl_label = "Mesh Flatten" def draw(self, context): layout = self.layout pie = layout.menu_pie() # 4 - LEFT - box = pie.split().box().column() + box = pie.box().column(align=True) - row = box.row(align=True) - row.label(text="X") - align_1 = row.operator("transform.flatten_on_local_minmax", text="Neg") - align_1.axis = '0' - align_1.side = 'NEGATIVE' + box.label(text="Selection Bounds", icon='PIVOT_BOUNDBOX') + for axis in "XYZ": + row = box.row() + op = row.operator("transform.flatten_to_selection_bounding_box", text=f" -{axis}") + op.axis = axis + op.side = 'NEGATIVE' + op = row.operator("transform.flatten_to_selection_bounding_box", text=f" +{axis}") + op.axis = axis + op.side = 'POSITIVE' - row = box.row(align=True) - row.label(text="Y") - align_3 = row.operator("transform.flatten_on_local_minmax", text="Neg") - align_3.axis = '1' - align_3.side = 'NEGATIVE' - - row = box.row(align=True) - row.label(text="Z") - align_5 = row.operator("transform.flatten_on_local_minmax", text="Neg") - align_5.axis = '2' - align_5.side = 'NEGATIVE' # 6 - RIGHT - box = pie.split().box().column() + pie.separator() - row = box.row(align=True) - row.label(text="X") - align_2 = row.operator("transform.flatten_on_local_minmax", text="Pos") - align_2.axis = '0' - align_2.side = 'POSITIVE' - - row = box.row(align=True) - row.label(text="Y") - align_4 = row.operator("transform.flatten_on_local_minmax", text="Pos") - align_4.axis = '1' - align_4.side = 'POSITIVE' - - row = box.row(align=True) - row.label(text="Z") - align_6 = row.operator("transform.flatten_on_local_minmax", text="Pos") - align_6.axis = '2' - align_6.side = 'POSITIVE' # 2 - BOTTOM - pie.operator("transform.flatten_on_local_axis", text="Align To Y-0").axis = '1' + pie.operator("transform.flatten_to_origin", text="Origin Y", icon='OBJECT_ORIGIN').axis = 'Y' # 8 - TOP - pie.operator("transform.flatten_on_global_axis", text="Align Y").axis = 'Y' + pie.operator("transform.flatten_to_center", text="Center Y", icon='ORIENTATION_GLOBAL').axis = 'Y' # 7 - TOP - LEFT - pie.operator("transform.flatten_on_global_axis", text="Align X").axis = 'X' + pie.operator("transform.flatten_to_center", text="Center X", icon='ORIENTATION_GLOBAL').axis = 'X' # 9 - TOP - RIGHT - pie.operator("transform.flatten_on_global_axis", text="Align Z").axis = 'Z' + pie.operator("transform.flatten_to_center", text="Center Z", icon='ORIENTATION_GLOBAL').axis = 'Z' # 1 - BOTTOM - LEFT - pie.operator("transform.flatten_on_local_axis", text="Align To X-0").axis = '0' + pie.operator("transform.flatten_to_origin", text="Origin X", icon='OBJECT_ORIGIN').axis = 'X' # 3 - BOTTOM - RIGHT - pie.operator("transform.flatten_on_local_axis", text="Align To Z-0").axis = '2' + pie.operator("transform.flatten_to_origin", text="Origin Z", icon='OBJECT_ORIGIN').axis = 'Z' -class TRANSFORM_OT_flatten_on_global_axis(Operator): +class TRANSFORM_OT_flatten_to_center(Operator): """Flatten selection along a global axis""" - bl_idname = "transform.flatten_on_global_axis" - bl_label = "Flatten To Global Axis" + bl_idname = "transform.flatten_to_center" + bl_label = "Flatten to Center" bl_options = {'REGISTER', 'UNDO'} axis: EnumProperty( @@ -110,22 +86,22 @@ class TRANSFORM_OT_flatten_on_global_axis(Operator): return {'FINISHED'} -class TRANSFORM_OT_flatten_on_local_axis(Operator): - """Flatten selection along a local axis""" +class TRANSFORM_OT_flatten_to_object_origin(Operator): + """Flatten selection to the object's origin""" - bl_idname = "transform.flatten_on_local_axis" - bl_label = "Align To X, Y or Z = 0" + bl_idname = "transform.flatten_to_origin" + bl_label = "Flatten to Origin" bl_options = {'REGISTER', 'UNDO'} axis: EnumProperty( name="Axis", items=( - ('0', "X", "X Axis"), - ('1', "Y", "Y Axis"), - ('2', "Z", "Z Axis"), + ('X', "X", "X Axis"), + ('Y', "Y", "Y Axis"), + ('Z', "Z", "Z Axis"), ), description="Choose an axis for alignment", - default='0', + default='X', ) @classmethod @@ -135,31 +111,31 @@ class TRANSFORM_OT_flatten_on_local_axis(Operator): def execute(self, context): bpy.ops.object.mode_set(mode='OBJECT') - align = int(self.axis) + index = "XYZ".find(self.axis) for vert in bpy.context.object.data.vertices: if vert.select: - vert.co[align] = 0 + vert.co[index] = 0 bpy.ops.object.editmode_toggle() return {'FINISHED'} -class TRANSFORM_OT_flatten_on_local_minmax(Operator): - """Align to a Front or Back along the chosen Axis""" +class TRANSFORM_OT_flatten_to_selection_bounding_box(Operator): + """Flatten to bounding box of the selection""" - bl_idname = "transform.flatten_on_local_minmax" - bl_label = "Align to Front/Back Axis" + bl_idname = "transform.flatten_to_selection_bounding_box" + bl_label = "Flatten to Selection Bounding Box" bl_options = {'REGISTER', 'UNDO'} axis: EnumProperty( name="Axis", items=( - ('0', "X", "X Axis"), - ('1', "Y", "Y Axis"), - ('2', "Z", "Z Axis"), + ('X', "X", "X Axis"), + ('Y', "Y", "Y Axis"), + ('Z', "Z", "Z Axis"), ), description="Choose an axis for alignment", - default='0', + default='X', ) side: EnumProperty( name="Side", @@ -179,43 +155,43 @@ class TRANSFORM_OT_flatten_on_local_minmax(Operator): def execute(self, context): bpy.ops.object.mode_set(mode='OBJECT') count = 0 - axis = int(self.axis) + axis_idx = "XYZ".find(self.axis) for vert in bpy.context.object.data.vertices: if vert.select: if count == 0: - maxv = vert.co[axis] + maxv = vert.co[axis_idx] count += 1 continue count += 1 if self.side == 'POSITIVE': - if vert.co[axis] > maxv: - maxv = vert.co[axis] + if vert.co[axis_idx] > maxv: + maxv = vert.co[axis_idx] else: - if vert.co[axis] < maxv: - maxv = vert.co[axis] + if vert.co[axis_idx] < maxv: + maxv = vert.co[axis_idx] bpy.ops.object.mode_set(mode='OBJECT') for vert in bpy.context.object.data.vertices: if vert.select: - vert.co[axis] = maxv + vert.co[axis_idx] = maxv bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} registry = [ - PIE_MT_mesh_align, - TRANSFORM_OT_flatten_on_global_axis, - TRANSFORM_OT_flatten_on_local_axis, - TRANSFORM_OT_flatten_on_local_minmax, + PIE_MT_mesh_flatten, + TRANSFORM_OT_flatten_to_center, + TRANSFORM_OT_flatten_to_object_origin, + TRANSFORM_OT_flatten_to_selection_bounding_box, ] def register(): register_hotkey( 'wm.call_menu_pie', - op_kwargs={'name': 'PIE_MT_mesh_align'}, + op_kwargs={'name': 'PIE_MT_mesh_flatten'}, hotkey_kwargs={'type': "X", 'value': "PRESS", 'alt': True}, key_cat="Mesh", )