Add Easy_Weight to Addons #47

Merged
Nick Alberelli merged 48 commits from feature/easy_weights into main 2023-05-17 22:13:57 +02:00
12 changed files with 30 additions and 21 deletions
Showing only changes of commit 150da62a53 - Show all commits

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@ import bpy
from bpy.props import *
from bpy.app.handlers import persistent
class ChangeWPBrush(bpy.types.Operator):
class EASYWEIGHT_OT_change_brush(bpy.types.Operator):
"""Change the weight paint brush to a specific brush."""
bl_idname = "brush.set_specific"
bl_label = "Set WP Brush"
@ -51,7 +51,7 @@ def register_brush_switch_hotkeys(dummy):
# Without this, the hotkeys' properties get reset whenever the addon is disabled, which results in having to set the Add, Subtract, Blur brushes on the hotkeys manually every time.
# However, with this, the hotkey cannot be changed, since this will forcibly re-create the original anyways.
active_keyconfig = bpy.data.window_managers[0].keyconfigs.active
active_keyconfig = bpy.context.window_manager.keyconfigs.active
if not active_keyconfig: return # Avoid error when running without UI.
wp_hotkeys = active_keyconfig.keymaps['Weight Paint'].keymap_items
@ -69,10 +69,11 @@ def register_brush_switch_hotkeys(dummy):
def register():
from bpy.utils import register_class
register_class(ChangeWPBrush)
register_class(EASYWEIGHT_OT_change_brush)
register_brush_switch_hotkeys(None)
bpy.app.handlers.load_post.append(register_brush_switch_hotkeys)
def unregister():
from bpy.utils import unregister_class
unregister_class(ChangeWPBrush)
unregister_class(EASYWEIGHT_OT_change_brush)
bpy.app.handlers.load_post.remove(register_brush_switch_hotkeys)

View File

@ -26,7 +26,7 @@ def flip_driver_targets(obj):
print("target: " + t.bone_target)
t.bone_target = utils.flip_name(t.bone_target)
class ForceApplyMirror(bpy.types.Operator):
class EASYWEIGHT_OT_force_apply_mirror(bpy.types.Operator):
""" Force apply mirror modifier by duplicating the object, flipping it on the X axis, merging into the original """
bl_idname = "object.force_apply_mirror_modifier"
bl_label = "Force Apply Mirror Modifier"
@ -227,8 +227,8 @@ class ForceApplyMirror(bpy.types.Operator):
def register():
from bpy.utils import register_class
register_class(ForceApplyMirror)
register_class(EASYWEIGHT_OT_force_apply_mirror)
def unregister():
from bpy.utils import unregister_class
unregister_class(ForceApplyMirror)
unregister_class(EASYWEIGHT_OT_force_apply_mirror)

View File

@ -159,7 +159,7 @@ w3_bone_dict_str = """{
'Hand_Def.R' : ['r_thumb_roll', 'r_pinky0', 'r_index_knuckleRoll', 'r_middle_knuckleRoll', 'r_ring_knuckleRoll'],
}"""
class SmartWeightTransferOperator(bpy.types.Operator):
class EASYWEIGHT_OT_smart_weight_transfer(bpy.types.Operator):
""" Transfer weights from active to selected objects based on weighted vert distances """
bl_idname = "object.smart_weight_transfer"
bl_label = "Smart Transfer Weights"
@ -203,7 +203,7 @@ class SmartWeightTransferOperator(bpy.types.Operator):
return (context.object is not None)# and (context.object.mode=='WEIGHT_PAINT')
def draw_smart_weight_transfer(self, context):
operator = self.layout.operator(SmartWeightTransferOperator.bl_idname, text=SmartWeightTransferOperator.bl_label)
operator = self.layout.operator(EASYWEIGHT_OT_smart_weight_transfer.bl_idname, text=EASYWEIGHT_OT_smart_weight_transfer.bl_label)
def execute(self, context):
assert len(context.selected_objects) > 1, "At least two objects must be selected. Select the source object last, and enter weight paint mode."
@ -253,10 +253,10 @@ class SmartWeightTransferOperator(bpy.types.Operator):
def register():
from bpy.utils import register_class
register_class(SmartWeightTransferOperator)
bpy.types.VIEW3D_MT_paint_weight.append(SmartWeightTransferOperator.draw_smart_weight_transfer)
register_class(EASYWEIGHT_OT_smart_weight_transfer)
bpy.types.VIEW3D_MT_paint_weight.append(EASYWEIGHT_OT_smart_weight_transfer.draw_smart_weight_transfer)
def unregister():
from bpy.utils import unregister_class
unregister_class(SmartWeightTransferOperator)
bpy.types.VIEW3D_MT_paint_weight.remove(SmartWeightTransferOperator.draw_smart_weight_transfer)
unregister_class(EASYWEIGHT_OT_smart_weight_transfer)
bpy.types.VIEW3D_MT_paint_weight.remove(EASYWEIGHT_OT_smart_weight_transfer.draw_smart_weight_transfer)

View File

@ -1,6 +1,6 @@
import bpy
# This operator is to make entering weight paint mode less of a pain in the ass.
# This operator is to make entering weight paint mode less of a pain.
# You just need to select a mesh, run the operator, and you should be ready to weight paint.
# It registers an operator called "Toggle Weight Paint Mode" that does the following:
@ -16,8 +16,8 @@ import bpy
coll_name = "temp_weight_paint_armature"
class ToggleWeightPaint(bpy.types.Operator):
""" Toggle weight paint mode properly with a single operator. """
class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
"""Toggle weight paint mode properly with a single operator. """
bl_idname = "object.weight_paint_toggle"
bl_label = "Toggle Weight Paint Mode"
bl_options = {'REGISTER', 'UNDO'}
@ -28,6 +28,9 @@ class ToggleWeightPaint(bpy.types.Operator):
def poll(cls, context):
return context.object and context.object.type=='MESH'
def draw(self, context):
self.layout.operator(EASYWEIGHT_OT_toggle_weight_paint.bl_idname)
def execute(self, context):
obj = context.object
@ -130,8 +133,12 @@ class ToggleWeightPaint(bpy.types.Operator):
def register():
from bpy.utils import register_class
register_class(ToggleWeightPaint)
register_class(EASYWEIGHT_OT_toggle_weight_paint)
bpy.types.VIEW3D_MT_paint_weight.append(EASYWEIGHT_OT_toggle_weight_paint.draw)
bpy.types.VIEW3D_MT_object.append(EASYWEIGHT_OT_toggle_weight_paint.draw)
def unregister():
from bpy.utils import unregister_class
unregister_class(ToggleWeightPaint)
unregister_class(EASYWEIGHT_OT_toggle_weight_paint)
bpy.types.VIEW3D_MT_paint_weight.remove(EASYWEIGHT_OT_toggle_weight_paint.draw)
bpy.types.VIEW3D_MT_object.remove(EASYWEIGHT_OT_toggle_weight_paint.draw)

View File

@ -2,7 +2,7 @@ import bpy
from bpy.props import *
from bpy.app.handlers import persistent
class WPContextMenu(bpy.types.Operator):
class EASYWEIGHT_OT_wp_context_menu(bpy.types.Operator):
""" Custom Weight Paint context menu """
bl_idname = "object.custom_weight_paint_context_menu"
bl_label = "Custom Weight Paint Context Menu"
@ -120,10 +120,11 @@ def start_cleaner(scene, depsgraph):
def register():
from bpy.utils import register_class
register_class(WPContextMenu)
register_class(EASYWEIGHT_OT_wp_context_menu)
start_cleaner(None, None)
bpy.app.handlers.load_post.append(start_cleaner)
def unregister():
from bpy.utils import unregister_class
unregister_class(WPContextMenu)
unregister_class(EASYWEIGHT_OT_wp_context_menu)
bpy.app.handlers.load_post.remove(start_cleaner)