Add Lattice Magic
to Addons
#48
@ -16,7 +16,7 @@
|
||||
# Add operators to the UI wherever possible.
|
||||
|
||||
import bpy
|
||||
from bpy.props import FloatProperty, IntVectorProperty, FloatVectorProperty, BoolProperty
|
||||
from bpy.props import FloatProperty, IntVectorProperty, FloatVectorProperty, BoolProperty, PointerProperty, StringProperty
|
||||
from typing import List
|
||||
from mathutils import Vector
|
||||
from rna_prop_ui import rna_idprop_ui_create
|
||||
@ -132,6 +132,17 @@ class TWEAKLAT_OT_Create(bpy.types.Operator):
|
||||
root.hide_viewport = True
|
||||
hook['Root'] = root
|
||||
|
||||
# Parent the root
|
||||
scene = context.scene
|
||||
matrix_backup = root.matrix_world.copy()
|
||||
root.parent = scene.tweak_lattice_parent_ob
|
||||
if root.parent and root.parent.type=='ARMATURE':
|
||||
bone = root.parent.pose.bones.get(scene.tweak_lattice_parent_bone)
|
||||
if bone:
|
||||
root.parent_type = 'BONE'
|
||||
root.parent_bone = bone.name
|
||||
root.matrix_world = matrix_backup
|
||||
|
||||
# Parent lattice and hook to root
|
||||
lattice_ob.parent = root
|
||||
|
||||
@ -280,8 +291,17 @@ class TWEAKLAT_PT_Main(bpy.types.Panel):
|
||||
layout.use_property_decorate = False
|
||||
|
||||
hook = context.object
|
||||
layout = layout.column()
|
||||
if hook.type!='EMPTY' or 'Tweak Lattice' not in hook:
|
||||
layout.operator(TWEAKLAT_OT_Create.bl_idname, icon='OUTLINER_OB_LATTICE')
|
||||
scene = context.scene
|
||||
layout.prop(scene, 'tweak_lattice_radius', slider=True)
|
||||
layout.separator()
|
||||
layout.prop(scene, 'tweak_lattice_parent_ob')
|
||||
if scene.tweak_lattice_parent_ob and scene.tweak_lattice_parent_ob.type=='ARMATURE':
|
||||
layout.prop_search(scene, 'tweak_lattice_parent_bone', scene.tweak_lattice_parent_ob.data, 'bones')
|
||||
layout.separator()
|
||||
op = layout.operator(TWEAKLAT_OT_Create.bl_idname, icon='OUTLINER_OB_LATTICE')
|
||||
op.radius = scene.tweak_lattice_radius
|
||||
return
|
||||
|
||||
layout.prop(hook, '["Tweak Lattice"]', slider=True, text="Influence")
|
||||
@ -323,7 +343,15 @@ def register():
|
||||
for c in classes:
|
||||
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.
|
||||
bpy.types.Scene.tweak_lattice_parent_bone = StringProperty(name="Bone")
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for c in reversed(classes):
|
||||
unregister_class(c)
|
||||
unregister_class(c)
|
||||
|
||||
del bpy.types.Scene.tweak_lattice_radius
|
||||
del bpy.types.Scene.tweak_lattice_parent_ob
|
||||
del bpy.types.Scene.tweak_lattice_parent_bone
|
Loading…
Reference in New Issue
Block a user