Add Easy_Weight
to Addons
#47
@ -19,26 +19,7 @@ def get_armature_of_meshob(obj: bpy.types.Object):
|
||||
if m.type=='ARMATURE':
|
||||
return m.object
|
||||
|
||||
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'}
|
||||
|
||||
# local_view: bpy.props.BoolProperty(
|
||||
# name = "Local View"
|
||||
# ,description = "Enter Local view with the mesh and armature"
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
ob = context.object
|
||||
return ob and ob.type=='MESH'
|
||||
|
||||
def draw(self, context):
|
||||
self.layout.operator(EASYWEIGHT_OT_toggle_weight_paint.bl_idname)
|
||||
|
||||
def enter_wp(self, context):
|
||||
def enter_wp(context) -> bool:
|
||||
"""Enter weight paint mode, change the necessary settings, and save their
|
||||
original states so they can be restored when leaving wp mode."""
|
||||
|
||||
@ -86,7 +67,7 @@ class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
|
||||
### ENSURING ARMATURE VISIBILITY
|
||||
armature = get_armature_of_meshob(obj)
|
||||
if not armature:
|
||||
return {'FINISHED'}
|
||||
return
|
||||
# Save all object visibility related info so it can be restored later.
|
||||
wpt['arm_enabled'] = armature.hide_viewport
|
||||
wpt['arm_hide'] = armature.hide_get()
|
||||
@ -104,16 +85,14 @@ class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
|
||||
context.scene.collection.objects.link(armature)
|
||||
wpt['arm_coll_assigned'] = True
|
||||
|
||||
if not armature.visible_get():
|
||||
self.report({'WARNING'}, "Failed to make the armature visible. Curse you, Blender!!!")
|
||||
else:
|
||||
if armature.visible_get():
|
||||
context.view_layer.objects.active = armature
|
||||
bpy.ops.object.mode_set(mode='POSE')
|
||||
|
||||
context.view_layer.objects.active = obj
|
||||
return {'FINISHED'}
|
||||
return armature.visible_get()
|
||||
|
||||
def leave_wp(self, context):
|
||||
def leave_wp(context):
|
||||
"""Leave weight paint mode, then find, restore, and delete the data
|
||||
that was stored about shading settings in enter_wp()."""
|
||||
|
||||
@ -153,7 +132,7 @@ class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
|
||||
|
||||
armature = get_armature_of_meshob(obj)
|
||||
if not armature:
|
||||
return {'FINISHED'}
|
||||
return
|
||||
# If an armature was un-hidden, hide it again.
|
||||
armature.hide_viewport = wpt_as_dict['arm_enabled']
|
||||
armature.hide_set(wpt_as_dict['arm_hide'])
|
||||
@ -167,15 +146,33 @@ class EASYWEIGHT_OT_toggle_weight_paint(bpy.types.Operator):
|
||||
if wpt_as_dict['arm_coll_assigned']:
|
||||
context.scene.collection.objects.unlink(armature)
|
||||
|
||||
return {'FINISHED'}
|
||||
return
|
||||
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'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
ob = context.object
|
||||
return ob and ob.type=='MESH'
|
||||
|
||||
def draw(self, context):
|
||||
self.layout.operator(EASYWEIGHT_OT_toggle_weight_paint.bl_idname)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
|
||||
if obj.mode != 'WEIGHT_PAINT':
|
||||
return self.enter_wp(context)
|
||||
armature_visible = enter_wp(context)
|
||||
if armature_visible == False:
|
||||
# This should never happen, but it also doesn't break anything.
|
||||
self.report({'WARNING'}, "Could not make Armature visible.")
|
||||
return {'FINISHED'}
|
||||
else:
|
||||
return self.leave_wp(context)
|
||||
leave_wp(context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class EASYWEIGHT_PT_Debug(bpy.types.Panel):
|
||||
"""For debugging the Toggle Weight Paint operator."""
|
||||
|
Loading…
Reference in New Issue
Block a user