Add Easy_Weight
to Addons
#47
16
__init__.py
16
__init__.py
@ -48,29 +48,13 @@ modules = [
|
||||
rogue_weights
|
||||
]
|
||||
|
||||
class EasyWeightPreferences(AddonPreferences):
|
||||
bl_idname = __name__
|
||||
|
||||
debug_mode: BoolProperty(
|
||||
name='Debug UI',
|
||||
description='When enabled, add an EasyWeight panel to the Sidebar, used for debugging',
|
||||
default=False,
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.prop(self, 'debug_mode')
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
register_class(EasyWeightPreferences)
|
||||
for m in modules:
|
||||
importlib.reload(m)
|
||||
m.register()
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
unregister_class(EasyWeightPreferences)
|
||||
for m in modules:
|
||||
m.unregister()
|
@ -42,12 +42,6 @@ def enter_wp(context) -> bool:
|
||||
# If we are entering WP mode for the first time or if the last time
|
||||
# the operator was exiting WP mode, then save current shading info.
|
||||
if 'last_switch_in' not in wpt_as_dict or wpt_as_dict['last_switch_in']==False:
|
||||
wpt['shading_type'] = context.space_data.shading.type
|
||||
if context.space_data.shading.type=='SOLID':
|
||||
# These properties only exist when the shading type is SOLID.
|
||||
wpt['light'] = context.space_data.shading.light
|
||||
wpt['color_type'] = context.space_data.shading.color_type
|
||||
wpt['single_color'] = context.space_data.shading.single_color
|
||||
wpt['active_object'] = obj
|
||||
|
||||
# This flag indicates that the last time this operator ran, we were
|
||||
@ -55,12 +49,6 @@ def enter_wp(context) -> bool:
|
||||
wpt['last_switch_in'] = True
|
||||
wpt['mode'] = obj.mode
|
||||
|
||||
# Set shading
|
||||
if context.space_data.shading.type=='SOLID':
|
||||
context.space_data.shading.light = 'FLAT'
|
||||
context.space_data.shading.color_type = 'SINGLE'
|
||||
context.space_data.shading.single_color = (1,1,1)
|
||||
|
||||
# Enter WP mode.
|
||||
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
|
||||
|
||||
@ -120,16 +108,6 @@ def leave_wp(context):
|
||||
# Flag to save that the last time the operator ran we were EXITING wp mode.
|
||||
wm['wpt']['last_switch_in'] = False
|
||||
|
||||
# Restore shading options.
|
||||
if 'light' in wpt_as_dict: # If we stored solid view shading settings, restore those settings but don't restore the shading type.
|
||||
shading_type = context.space_data.shading.type
|
||||
context.space_data.shading.type = wpt_as_dict['shading_type']
|
||||
if context.space_data.shading.type=='SOLID':
|
||||
context.space_data.shading.light = wpt_as_dict['light']
|
||||
context.space_data.shading.color_type = wpt_as_dict['color_type']
|
||||
context.space_data.shading.single_color = wpt_as_dict['single_color']
|
||||
context.space_data.shading.type = shading_type
|
||||
|
||||
armature = get_armature_of_meshob(obj)
|
||||
if not armature:
|
||||
return
|
||||
@ -147,8 +125,9 @@ def leave_wp(context):
|
||||
context.scene.collection.objects.unlink(armature)
|
||||
|
||||
return
|
||||
|
||||
class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
|
||||
"""Toggle weight paint mode properly with a single operator. """
|
||||
"""Enter weight paint mode on a mesh object and pose mode on its armature"""
|
||||
bl_idname = "object.weight_paint_toggle"
|
||||
bl_label = "Toggle Weight Paint Mode"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
@ -174,39 +153,9 @@ class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
|
||||
leave_wp(context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class EASYWEIGHT_PT_Debug(bpy.types.Panel):
|
||||
"""For debugging the Toggle Weight Paint operator."""
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_category = 'EasyWeight'
|
||||
bl_idname = "EASYWEIGHT_PT_Debug"
|
||||
bl_label = "Debug Toggle WP"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.preferences.addons[__package__].preferences.debug_mode
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
wm = context.window_manager
|
||||
|
||||
if not 'wpt' in wm:
|
||||
return
|
||||
|
||||
wpt = wm['wpt'].to_dict()
|
||||
|
||||
for key in wpt.keys():
|
||||
split = layout.split(factor=0.4)
|
||||
value = wpt[key]
|
||||
if type(value)==bpy.types.Object:
|
||||
value = value.name
|
||||
split.label(text=key)
|
||||
split.label(text=str(value))
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
register_class(EASYWEIGHT_OT_toggle_weight_paint)
|
||||
register_class(EASYWEIGHT_PT_Debug)
|
||||
|
||||
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)
|
||||
@ -214,7 +163,6 @@ def register():
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
unregister_class(EASYWEIGHT_OT_toggle_weight_paint)
|
||||
unregister_class(EASYWEIGHT_PT_Debug)
|
||||
|
||||
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)
|
Loading…
Reference in New Issue
Block a user