Add Easy_Weight
to Addons
#47
58
__init__.py
58
__init__.py
@ -24,6 +24,8 @@ bl_info = {
|
||||
}
|
||||
|
||||
import importlib
|
||||
from bpy.utils import register_class, unregister_class
|
||||
from typing import List
|
||||
|
||||
from . import smart_weight_transfer
|
||||
from . import force_apply_mirror
|
||||
@ -32,6 +34,7 @@ from . import weight_paint_context_menu
|
||||
from . import vertex_group_operators
|
||||
from . import vertex_group_menu
|
||||
from . import rogue_weights
|
||||
from . import util
|
||||
|
||||
# Each module is expected to have a register() and unregister() function.
|
||||
modules = [
|
||||
@ -41,14 +44,61 @@ modules = [
|
||||
weight_paint_context_menu,
|
||||
vertex_group_operators,
|
||||
vertex_group_menu,
|
||||
rogue_weights
|
||||
rogue_weights,
|
||||
util
|
||||
]
|
||||
|
||||
def register():
|
||||
|
||||
def register_unregister_modules(modules: List, register: bool):
|
||||
"""Recursively register or unregister modules by looking for either
|
||||
un/register() functions or lists named `registry` which should be a list of
|
||||
registerable classes.
|
||||
"""
|
||||
register_func = register_class if register else unregister_class
|
||||
|
||||
for m in modules:
|
||||
if register:
|
||||
importlib.reload(m)
|
||||
if hasattr(m, 'registry'):
|
||||
for c in m.registry:
|
||||
try:
|
||||
register_func(c)
|
||||
except Exception as e:
|
||||
un = 'un' if not register else ''
|
||||
print(f"Warning: CloudRig failed to {un}register class: {c.__name__}")
|
||||
print(e)
|
||||
|
||||
if hasattr(m, 'modules'):
|
||||
register_unregister_modules(m.modules, register)
|
||||
|
||||
if register and hasattr(m, 'register'):
|
||||
m.register()
|
||||
elif hasattr(m, 'unregister'):
|
||||
m.unregister()
|
||||
|
||||
|
||||
def register():
|
||||
register_unregister_modules(modules, True)
|
||||
|
||||
print("Registering Easy Weight Hotkeys")
|
||||
util.register_hotkey('paint.weight_paint'
|
||||
,hotkey_kwargs = {'type': 'LEFTMOUSE', 'value': 'PRESS'}
|
||||
,key_cat = 'Weight Paint'
|
||||
,space_type = 'VIEW_3D'
|
||||
,mode = 'NORMAL'
|
||||
)
|
||||
util.register_hotkey('paint.weight_paint'
|
||||
,hotkey_kwargs = {'type': 'LEFTMOUSE', 'value': 'PRESS', 'ctrl' : True}
|
||||
,key_cat = 'Weight Paint'
|
||||
,space_type = 'VIEW_3D'
|
||||
,mode = 'INVERT'
|
||||
)
|
||||
util.register_hotkey('paint.weight_paint'
|
||||
,hotkey_kwargs = {'type': 'LEFTMOUSE', 'value': 'PRESS', 'shift' : True}
|
||||
,key_cat = 'Weight Paint'
|
||||
,space_type = 'VIEW_3D'
|
||||
,mode = 'SMOOTH'
|
||||
)
|
||||
|
||||
def unregister():
|
||||
for m in modules:
|
||||
m.unregister()
|
||||
register_unregister_modules(modules, False)
|
@ -17,6 +17,7 @@ All functionality can be found in the Sidebar->EasyWeight->Weight Islands panel.
|
||||
|
||||
# TODO:
|
||||
# UIList: Filtering options, explanations as to what the numbers mean. Maybe a warning for Calculate Islands operator when the mesh has a lot of verts or vgroups.
|
||||
# Take the ProgressTracker class from Dependency Graph add-on and use it to give user feedback on weight island calculation progress.
|
||||
|
||||
class VertIndex(PropertyGroup):
|
||||
index: IntProperty()
|
||||
|
21
util.py
Normal file
21
util.py
Normal file
@ -0,0 +1,21 @@
|
||||
import bpy
|
||||
|
||||
def register_hotkey(bl_idname, hotkey_kwargs, *, key_cat='Window', space_type='EMPTY', **op_kwargs):
|
||||
wm = bpy.context.window_manager
|
||||
addon_keyconfig = wm.keyconfigs.addon
|
||||
if not addon_keyconfig:
|
||||
# This happens when running Blender in background mode.
|
||||
return
|
||||
keymaps = addon_keyconfig.keymaps
|
||||
|
||||
km = keymaps.get(key_cat)
|
||||
if not km:
|
||||
km = keymaps.new(name=key_cat, space_type=space_type)
|
||||
if bl_idname not in km.keymap_items:
|
||||
kmi = km.keymap_items.new(bl_idname, **hotkey_kwargs)
|
||||
else:
|
||||
kmi = km.keymap_items[bl_idname]
|
||||
|
||||
for key in op_kwargs:
|
||||
value = op_kwargs[key]
|
||||
setattr(kmi.properties, key, value)
|
Loading…
Reference in New Issue
Block a user