Add Lattice Magic to Addons #48

Merged
Nick Alberelli merged 36 commits from feature/lattice_magic into main 2023-05-17 20:48:52 +02:00
2 changed files with 63 additions and 3 deletions
Showing only changes of commit 585da4a74b - Show all commits

View File

@ -366,6 +366,59 @@ class CAMLAT_OT_ShapeKey_Add(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def shape_key_poll(context):
ob = context.object
if not ob or ob.type!='LATTICE':
return False
if not ob.data.shape_keys or len(ob.data.shape_keys.key_blocks) < 2:
return False
return True
class CAMLAT_OT_ShapeKey_Zero_All(bpy.types.Operator):
"""Set all shape key values to 0"""
bl_idname = "lattice.shape_keys_zero_all"
bl_label = "Zero All Shape Keys"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
@classmethod
def poll(cls, context):
return shape_key_poll(context)
def execute(self, context):
scene = context.scene
active_slot = scene.lattice_slots[scene.active_lattice_index]
lattice_ob = active_slot.lattice
lattice = lattice_ob.data
for sk in lattice.shape_keys.key_blocks:
sk.value = 0
return {'FINISHED'}
class CAMLAT_OT_ShapeKey_Keyframe_All(bpy.types.Operator):
"""Insert a keyframe on the current frame for all shape key values"""
bl_idname = "lattice.shape_keys_keyframe_all"
bl_label = "Keyframe All Shape Keys"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
@classmethod
def poll(cls, context):
return shape_key_poll(context)
def execute(self, context):
scene = context.scene
active_slot = scene.lattice_slots[scene.active_lattice_index]
lattice_ob = active_slot.lattice
lattice = lattice_ob.data
for sk in lattice.shape_keys.key_blocks:
sk.keyframe_insert('value')
return {'FINISHED'}
class CAMLAT_PT_Main(bpy.types.Panel): class CAMLAT_PT_Main(bpy.types.Panel):
bl_space_type = 'VIEW_3D' bl_space_type = 'VIEW_3D'
@ -441,6 +494,12 @@ class CAMLAT_PT_Main(bpy.types.Panel):
col = layout.column() col = layout.column()
row = layout.row(align=True)
row.operator('lattice.reset_points', text="", icon='RECOVER_LAST')
row.separator()
row.operator(CAMLAT_OT_ShapeKey_Zero_All.bl_idname, text="", icon='RADIOBUT_OFF')
row.operator(CAMLAT_OT_ShapeKey_Keyframe_All.bl_idname, text="", icon='HANDLETYPE_FREE_VEC')
row = layout.row() row = layout.row()
# Display the lattice's Shape Keys in a less cluttered way than in the Properties editor. # Display the lattice's Shape Keys in a less cluttered way than in the Properties editor.
@ -457,8 +516,6 @@ class CAMLAT_PT_Main(bpy.types.Panel):
col.operator(CAMLAT_OT_ShapeKey_Add.bl_idname, text="", icon='ADD') col.operator(CAMLAT_OT_ShapeKey_Add.bl_idname, text="", icon='ADD')
remove_op = col.operator('object.shape_key_remove', text="", icon='REMOVE') remove_op = col.operator('object.shape_key_remove', text="", icon='REMOVE')
col.operator(ShapeKey_OT_Reset.bl_idname, text="", icon='RECOVER_LAST')
col.separator() col.separator()
move_up_op = col.operator('object.shape_key_move', text="", icon='TRIA_UP') move_up_op = col.operator('object.shape_key_move', text="", icon='TRIA_UP')
move_up_op.type='UP' move_up_op.type='UP'
@ -477,6 +534,9 @@ classes = [
,CAMLAT_OT_Delete ,CAMLAT_OT_Delete
,CAMLAT_OT_ShapeKey_Add ,CAMLAT_OT_ShapeKey_Add
,CAMLAT_OT_ShapeKey_Zero_All
,CAMLAT_OT_ShapeKey_Keyframe_All
,CAMLAT_PT_Main ,CAMLAT_PT_Main
] ]

View File

@ -3,7 +3,7 @@ from bpy.props import FloatProperty
from .utils import get_lattice_point_original_position from .utils import get_lattice_point_original_position
class LATTICE_OT_Reset(bpy.types.Operator): class LATTICE_OT_Reset(bpy.types.Operator):
"""Reset selected lattice points to their default position.""" """Reset selected lattice points to their default position"""
bl_idname = "lattice.reset_points" bl_idname = "lattice.reset_points"
bl_label = "Reset Lattice Points" bl_label = "Reset Lattice Points"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}