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