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 29 additions and 47 deletions
Showing only changes of commit a671fd32e0 - Show all commits

View File

@ -28,19 +28,24 @@ bl_info = {
from . import camera_lattice
from . import tweak_lattice
from . import operators
from . import utils # Just for importlib.reload()
import importlib
modules = [
camera_lattice
,tweak_lattice
,operators
,utils
]
def register():
for m in modules:
importlib.reload(m)
if hasattr(m, 'register'):
m.register()
def unregister():
for m in modules:
m.unregister()
if hasattr(m, 'unregister'):
m.unregister()

View File

@ -33,13 +33,12 @@ class LATTICE_OT_Reset(bpy.types.Operator):
basis_block = key_blocks[0]
if active_index > 0:
for i, skp in enumerate(active_block.data):
point = ob.data.points[i]
if not point.select: continue
mix = skp.co.lerp(basis_block.data[i].co, self.factor)
skp.co = mix
if not ob.data.points[i].select: continue
skp.co = skp.co.lerp(basis_block.data[i].co, self.factor)
continue
else:
for i, skp in enumerate(active_block.data):
if not ob.data.points[i].select: continue
base = get_lattice_point_original_position(ob.data, i)
# Resetting the Basis shape
mix = basis_block.data[i].co.lerp(base, self.factor)
@ -49,54 +48,30 @@ class LATTICE_OT_Reset(bpy.types.Operator):
# Otherwise, reset the actual points.
for i in range(len(ob.data.points)):
point = ob.data.points[i]
if not point.select:
continue
if not point.select: continue
base = get_lattice_point_original_position(ob.data, i)
mix = point.co_deform.lerp(base, self.factor)
point.co_deform = base
point.co_deform = mix
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
class ShapeKey_OT_Reset(bpy.types.Operator):
"""Reset shape of the active shape key of the active object"""
bl_idname = "object.reset_shape_key"
bl_label = "Reset Shape Key"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
ob = context.object
if not ob:
return False
if not ob.data.shape_keys:
return False
if len(ob.data.shape_keys.key_blocks)<2:
return False
if ob.active_shape_key_index==0:
return False
return True
def execute(self, context):
ob = context.object
active_index = ob.active_shape_key_index
key_blocks = ob.data.shape_keys.key_blocks
active_block = key_blocks[active_index]
basis_block = key_blocks[0]
for i, skp in enumerate(active_block.data):
skp.co = basis_block.data[i].co
return { 'FINISHED' }
def draw_shape_key_reset(self, context):
self.layout.operator(ShapeKey_OT_Reset.bl_idname, text="Reset Shape Key", icon='FILE_REFRESH')
layout = self.layout
ob = context.object
if ob.type=='MESH':
op = layout.operator('mesh.blend_from_shape', text='Reset Shape Key', icon='FILE_REFRESH')
op.shape = ob.data.shape_keys.key_blocks[0].name
op.blend = 1
op.add = False
else:
layout.operator(LATTICE_OT_Reset.bl_idname, text="Reset Shape Key", icon='FILE_REFRESH')
def draw_lattice_reset(self, context):
self.layout.operator(LATTICE_OT_Reset.bl_idname, text="Reset Point Positions", icon='FILE_REFRESH')
classes = [
ShapeKey_OT_Reset
,LATTICE_OT_Reset
LATTICE_OT_Reset
]
def register():
@ -104,6 +79,7 @@ def register():
for c in classes:
register_class(c)
bpy.types.MESH_MT_shape_key_context_menu.append(draw_shape_key_reset)
bpy.types.VIEW3D_MT_edit_lattice.append(draw_lattice_reset)
def unregister():
from bpy.utils import unregister_class
@ -111,3 +87,4 @@ def unregister():
unregister_class(c)
bpy.types.MESH_MT_shape_key_context_menu.remove(draw_shape_key_reset)
bpy.types.VIEW3D_MT_edit_lattice.remove(draw_lattice_reset)