Add Lattice Magic
to Addons
#48
@ -4,17 +4,8 @@
|
||||
# A root empty is also created that can be (manually) parented to a rig in order to use this for animation.
|
||||
|
||||
# TODO:
|
||||
# Merge this and Camera Lattice into one addon
|
||||
# Re-organize the code
|
||||
|
||||
# Automagically determining the initial radius based on the selected objects' bounding box would be interesting
|
||||
|
||||
# More things:
|
||||
# Mirror selected positions(along any axis, with pickable left/right up/down front/back preference)
|
||||
# Grow selection
|
||||
|
||||
# Add operators to the UI wherever possible.
|
||||
|
||||
import bpy
|
||||
from bpy.props import FloatProperty, IntVectorProperty, FloatVectorProperty, BoolProperty, PointerProperty, StringProperty, EnumProperty
|
||||
from typing import List
|
||||
@ -79,6 +70,12 @@ def get_objects_of_lattice(hook: bpy.types.Object) -> List[bpy.types.Object]:
|
||||
objs.append(hook[ob_prop_name])
|
||||
return objs
|
||||
|
||||
def get_lattice_modifier_of_object(obj, lattice) -> bpy.types.Modifier:
|
||||
"""Find the lattice modifier on the object that uses this lattice"""
|
||||
for m in obj.modifiers:
|
||||
if m.type == 'LATTICE' and m.object == lattice:
|
||||
return m
|
||||
|
||||
def add_objects_to_lattice(
|
||||
hook: bpy.types.Object,
|
||||
objects: List[bpy.types.Object]):
|
||||
@ -482,12 +479,14 @@ class TWEAKLAT_PT_Main(bpy.types.Panel):
|
||||
layout.separator()
|
||||
layout.label(text="Affected Objects")
|
||||
|
||||
ob_count = 0
|
||||
ob_prop_name = "object_"+str(ob_count)
|
||||
while ob_prop_name in hook:
|
||||
layout.prop(hook, f'["{ob_prop_name}"]', text="")
|
||||
ob_count += 1
|
||||
ob_prop_name = "object_"+str(ob_count)
|
||||
objects_and_keys = [(hook[key], key) for key in hook.keys() if "object_" in key]
|
||||
objects_and_keys.sort(key=lambda o_and_k: o_and_k[1])
|
||||
for ob, key in objects_and_keys:
|
||||
row = layout.row(align=True)
|
||||
row.prop(hook, f'["{key}"]', text="")
|
||||
mod = get_lattice_modifier_of_object(ob, hook['Lattice'])
|
||||
row.prop_search(mod, 'vertex_group', ob, 'vertex_groups', text="", icon='GROUP_VERTEX')
|
||||
|
||||
|
||||
classes = [
|
||||
TWEAKLAT_OT_Create
|
||||
@ -504,7 +503,9 @@ def register():
|
||||
register_class(c)
|
||||
|
||||
bpy.types.Scene.tweak_lattice_radius = FloatProperty(name="Radius", default=0.1, min=0.0001, max=1000, soft_max=2)
|
||||
bpy.types.Scene.tweak_lattice_parent_ob = PointerProperty(type=bpy.types.Object, name="Parent") # Maybe it would be safer to make this a StringProperty but whatever.
|
||||
# This Pointer might cause a "deleted" (unlinked) object to stick around in a .blend file,
|
||||
# but if we don't use a Pointer, then we can't differentiate between linked vs local objects.
|
||||
bpy.types.Scene.tweak_lattice_parent_ob = PointerProperty(type=bpy.types.Object, name="Parent")
|
||||
bpy.types.Scene.tweak_lattice_parent_bone = StringProperty(name="Bone")
|
||||
bpy.types.Scene.tweak_lattice_location = EnumProperty(name="Location", items=[
|
||||
('CURSOR', "3D Cursor", "Create at the location and orientation of the 3D cursor.")
|
||||
|
Loading…
Reference in New Issue
Block a user