Add Lattice Magic
to Addons
#48
@ -221,7 +221,7 @@ class TWEAKLAT_OT_Duplicate(Operator):
|
|||||||
bpy.ops.object.duplicate()
|
bpy.ops.object.duplicate()
|
||||||
new_hook, new_lattice, new_root = get_tweak_setup(context.object)
|
new_hook, new_lattice, new_root = get_tweak_setup(context.object)
|
||||||
|
|
||||||
for key, value in new_hook.items():
|
for key, value in list(new_hook.items()):
|
||||||
if key.startswith("object_"):
|
if key.startswith("object_"):
|
||||||
del new_hook[key]
|
del new_hook[key]
|
||||||
|
|
||||||
@ -632,34 +632,45 @@ def add_objects_to_lattice(
|
|||||||
simple_driver(m, 'strength', hook, '["Tweak Lattice"]')
|
simple_driver(m, 'strength', hook, '["Tweak Lattice"]')
|
||||||
|
|
||||||
|
|
||||||
|
def remove_object_from_lattice(hook: Object, obj: Object):
|
||||||
|
"""Cleanly remove an object from a Tweak Lattice set-up's influence."""
|
||||||
|
hook, lattice, root = get_tweak_setup(hook)
|
||||||
|
|
||||||
|
# Remove the custom property pointing from the Hook to the Object.
|
||||||
|
for key, value in list(hook.items()):
|
||||||
|
if value == obj:
|
||||||
|
del hook[key]
|
||||||
|
break
|
||||||
|
|
||||||
|
# Remove the Lattice modifier (and its driver) deforming the Object.
|
||||||
|
for m in obj.modifiers:
|
||||||
|
if m.type != 'LATTICE':
|
||||||
|
continue
|
||||||
|
if m.object == lattice:
|
||||||
|
m.driver_remove('strength')
|
||||||
|
obj.modifiers.remove(m)
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def remove_objects_from_lattice(hook: Object, objects_to_remove: List[Object]) -> List[Object]:
|
||||||
|
"""Cleanly remove several objects from a Tweak Lattice set-up's influence."""
|
||||||
|
objs_removed = []
|
||||||
|
for key, value in list(hook.items()):
|
||||||
|
if value in objects_to_remove:
|
||||||
|
remove_object_from_lattice(hook, value)
|
||||||
|
objs_removed.append(value)
|
||||||
|
|
||||||
|
return objs_removed
|
||||||
|
|
||||||
|
|
||||||
def remove_all_objects_from_lattice(hook: Object) -> List[Object]:
|
def remove_all_objects_from_lattice(hook: Object) -> List[Object]:
|
||||||
lattice_ob = hook['Lattice']
|
"""Cleanly remove all objects from a Tweak Lattice set-up's influence."""
|
||||||
objs = []
|
objs_to_remove = []
|
||||||
ob_count = 0
|
for key, value in list(hook.items()):
|
||||||
ob_prop_name = "object_"+str(ob_count)
|
if key.startswith("object_"):
|
||||||
while ob_prop_name in hook:
|
objs_to_remove.append(value)
|
||||||
ob = hook[ob_prop_name]
|
|
||||||
for m in ob.modifiers:
|
|
||||||
if m.type != 'LATTICE':
|
|
||||||
continue
|
|
||||||
if m.object == lattice_ob:
|
|
||||||
m.driver_remove('strength')
|
|
||||||
ob.modifiers.remove(m)
|
|
||||||
break
|
|
||||||
ob_count += 1
|
|
||||||
objs.append(ob)
|
|
||||||
del hook[ob_prop_name]
|
|
||||||
ob_prop_name = "object_"+str(ob_count)
|
|
||||||
return objs
|
|
||||||
|
|
||||||
|
return remove_objects_from_lattice(hook, objs_to_remove)
|
||||||
def remove_objects_from_lattice(hook, objects):
|
|
||||||
new_objs = []
|
|
||||||
prev_objs = remove_all_objects_from_lattice(hook)
|
|
||||||
for o in prev_objs:
|
|
||||||
if o not in objects:
|
|
||||||
new_objs.append(o)
|
|
||||||
add_objects_to_lattice(hook, new_objs)
|
|
||||||
|
|
||||||
|
|
||||||
classes = [
|
classes = [
|
||||||
|
Loading…
Reference in New Issue
Block a user