Skip to content

Commit

Permalink
feat: add decimate and weld operators under the new simplify menu
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed May 26, 2022
1 parent c44e0b1 commit 1c7b454
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
2 changes: 2 additions & 0 deletions interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from . import fast_menu
from . import boolean_menu
from . import bevel_menu
from . import simplify_menu
from . import extrude_menu
from . import replicate_menu
from . import deform_menu
Expand All @@ -46,6 +47,7 @@
fast_menu,
boolean_menu,
bevel_menu,
simplify_menu,
extrude_menu,
replicate_menu,
deform_menu,
Expand Down
1 change: 1 addition & 0 deletions interface/main_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def draw(self, context):
layout.menu("ND_MT_extrude_menu", icon='MOD_SOLIDIFY')
layout.menu("ND_MT_replicate_menu", icon='MOD_ARRAY')
layout.menu("ND_MT_deform_menu", icon='MOD_SIMPLEDEFORM')
layout.menu("ND_MT_simplify_menu", icon='MOD_REMESH')
layout.separator()
layout.operator("nd.recon_poly", icon='SURFACE_NCURVE')
layout.operator("nd.screw_head", icon='CANCEL')
Expand Down
2 changes: 2 additions & 0 deletions interface/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
("nd.mirror", 'MOD_MIRROR', None, None, False),
("nd.lattice", 'MOD_LATTICE', None, None, False),
("nd.simple_deform", 'MOD_SIMPLEDEFORM', None, None, False),
("nd.decimate", 'MOD_DECIM', None, None, False),
("nd.weld", 'AUTOMERGE_ON', None, None, False),
]

generator_ops = [
Expand Down
47 changes: 47 additions & 0 deletions interface/simplify_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ███╗ ██╗██████╗
# ████╗ ██║██╔══██╗
# ██╔██╗ ██║██║ ██║
# ██║╚██╗██║██║ ██║
# ██║ ╚████║██████╔╝
# ╚═╝ ╚═══╝╚═════╝
#
# “Commons Clause” License Condition v1.0
#
# See LICENSE for license details. If you did not receive a copy of the license,
# it may be obtained at https://github.com/hugemenace/nd/blob/main/LICENSE.
#
# Software: ND Blender Addon
# License: MIT
# Licensor: T.S. & I.J. (HugeMenace)
#
# ---
# Contributors: Tristo (HM)
# ---

import bpy
from .. import bl_info


class ND_MT_simplify_menu(bpy.types.Menu):
bl_label = "Simplify"
bl_idname = "ND_MT_simplify_menu"


def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_DEFAULT'
layout.operator("nd.decimate", icon='MOD_DECIM')
layout.operator("nd.weld", icon='AUTOMERGE_ON')


def draw_item(self, context):
layout = self.layout
layout.menu(ND_MT_simplify_menu.bl_idname)


def register():
bpy.utils.register_class(ND_MT_simplify_menu)


def unregister():
bpy.utils.unregister_class(ND_MT_simplify_menu)
4 changes: 4 additions & 0 deletions power_mods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from . import mirror
from . import lattice
from . import simple_deform
from . import decimate
from . import weld
from . import profile_extrude
from . import circular_array
from . import array_cubed
Expand All @@ -41,6 +43,8 @@
mirror,
lattice,
simple_deform,
decimate,
weld,
profile_extrude,
circular_array,
array_cubed,
Expand Down
51 changes: 51 additions & 0 deletions power_mods/decimate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ███╗ ██╗██████╗
# ████╗ ██║██╔══██╗
# ██╔██╗ ██║██║ ██║
# ██║╚██╗██║██║ ██║
# ██║ ╚████║██████╔╝
# ╚═╝ ╚═══╝╚═════╝
#
# “Commons Clause” License Condition v1.0
#
# See LICENSE for license details. If you did not receive a copy of the license,
# it may be obtained at https://github.com/hugemenace/nd/blob/main/LICENSE.
#
# Software: ND Blender Addon
# License: MIT
# Licensor: T.S. & I.J. (HugeMenace)
#
# ---
# Contributors: Tristo (HM)
# ---

import bpy
from math import radians

class ND_OT_decimate(bpy.types.Operator):
bl_idname = "nd.decimate"
bl_label = "Decimate"
bl_description = "Add a decimate modifier to the selected objects"
bl_options = {'UNDO'}


@classmethod
def poll(cls, context):
if context.mode == 'OBJECT' and len(context.selected_objects) > 0:
return all(obj.type == 'MESH' for obj in context.selected_objects)


def invoke(self, context, event):
for obj in context.selected_objects:
modifier = obj.modifiers.new('Decimate — ND', 'DECIMATE')
modifier.decimate_type = 'DISSOLVE'
modifier.angle_limit = radians(1)

return {'FINISHED'}


def register():
bpy.utils.register_class(ND_OT_decimate)


def unregister():
bpy.utils.unregister_class(ND_OT_decimate)
50 changes: 50 additions & 0 deletions power_mods/weld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ███╗ ██╗██████╗
# ████╗ ██║██╔══██╗
# ██╔██╗ ██║██║ ██║
# ██║╚██╗██║██║ ██║
# ██║ ╚████║██████╔╝
# ╚═╝ ╚═══╝╚═════╝
#
# “Commons Clause” License Condition v1.0
#
# See LICENSE for license details. If you did not receive a copy of the license,
# it may be obtained at https://github.com/hugemenace/nd/blob/main/LICENSE.
#
# Software: ND Blender Addon
# License: MIT
# Licensor: T.S. & I.J. (HugeMenace)
#
# ---
# Contributors: Tristo (HM)
# ---

import bpy


class ND_OT_weld(bpy.types.Operator):
bl_idname = "nd.weld"
bl_label = "Weld"
bl_description = "Add a weld modifier to the selected objects"
bl_options = {'UNDO'}


@classmethod
def poll(cls, context):
if context.mode == 'OBJECT' and len(context.selected_objects) > 0:
return all(obj.type == 'MESH' for obj in context.selected_objects)


def invoke(self, context, event):
for obj in context.selected_objects:
modifier = obj.modifiers.new('Weld — ND', 'WELD')
modifier.merge_threshold = 0.001

return {'FINISHED'}


def register():
bpy.utils.register_class(ND_OT_weld)


def unregister():
bpy.utils.unregister_class(ND_OT_weld)

0 comments on commit 1c7b454

Please sign in to comment.