2010-01-10 19:20:48 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-01-10 19:20:48 +00:00
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
|
|
|
import bpy
|
2010-01-19 19:07:09 +00:00
|
|
|
from rna_prop_ui import rna_idprop_ui_prop_get
|
|
|
|
from math import acos, pi
|
2010-04-11 14:22:27 +00:00
|
|
|
from mathutils import Vector
|
2010-01-31 14:33:27 +00:00
|
|
|
from rigify import RigifyError
|
|
|
|
from rigify_utils import copy_bone_simple
|
2010-01-10 19:20:48 +00:00
|
|
|
|
|
|
|
#METARIG_NAMES = ("cpy",)
|
|
|
|
RIG_TYPE = "mouth"
|
|
|
|
|
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
def mark_actions():
|
|
|
|
for action in bpy.data.actions:
|
|
|
|
action.tag = True
|
|
|
|
|
|
|
|
def get_unmarked_action():
|
|
|
|
for action in bpy.data.actions:
|
|
|
|
if action.tag != True:
|
|
|
|
return action
|
|
|
|
return None
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
def add_action(name=None):
|
|
|
|
mark_actions()
|
|
|
|
bpy.ops.action.new()
|
|
|
|
action = get_unmarked_action()
|
|
|
|
if name is not None:
|
|
|
|
action.name = name
|
|
|
|
return action
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
def addget_shape_key(obj, name="Key"):
|
|
|
|
""" Fetches a shape key, or creates it if it doesn't exist
|
|
|
|
"""
|
|
|
|
# Create a shapekey set if it doesn't already exist
|
|
|
|
if obj.data.shape_keys is None:
|
|
|
|
shape = obj.add_shape_key(name="Basis", from_mix=False)
|
|
|
|
obj.active_shape_key_index = 0
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Get the shapekey, or create it if it doesn't already exist
|
|
|
|
if name in obj.data.shape_keys.keys:
|
|
|
|
shape_key = obj.data.shape_keys.keys[name]
|
|
|
|
else:
|
|
|
|
shape_key = obj.add_shape_key(name=name, from_mix=False)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
return shape_key
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
def addget_shape_key_driver(obj, name="Key"):
|
|
|
|
""" Fetches the driver for the shape key, or creates it if it doesn't
|
|
|
|
already exist.
|
|
|
|
"""
|
|
|
|
driver_path = 'keys["' + name + '"].value'
|
|
|
|
fcurve = None
|
|
|
|
driver = None
|
2010-02-02 17:57:12 +00:00
|
|
|
new = False
|
2010-01-19 19:07:09 +00:00
|
|
|
if obj.data.shape_keys.animation_data is not None:
|
|
|
|
for driver_s in obj.data.shape_keys.animation_data.drivers:
|
|
|
|
if driver_s.data_path == driver_path:
|
|
|
|
fcurve = driver_s
|
|
|
|
if fcurve == None:
|
|
|
|
fcurve = obj.data.shape_keys.keys[name].driver_add("value", 0)
|
2010-02-02 17:57:12 +00:00
|
|
|
fcurve.driver.type = 'AVERAGE'
|
|
|
|
new = True
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
return fcurve, new
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
def metarig_template():
|
|
|
|
# generated by rigify.write_meta_rig
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
obj = bpy.context.active_object
|
|
|
|
arm = obj.data
|
|
|
|
bone = arm.edit_bones.new('Bone')
|
|
|
|
bone.head[:] = 0.0000, 0.0000, 0.0000
|
|
|
|
bone.tail[:] = 0.0000, 0.0000, 1.0000
|
|
|
|
bone.roll = 0.0000
|
|
|
|
bone.connected = False
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
pbone = obj.pose.bones['Bone']
|
|
|
|
pbone['type'] = 'copy'
|
|
|
|
|
|
|
|
|
|
|
|
def metarig_definition(obj, orig_bone_name):
|
|
|
|
bone = obj.data.bones[orig_bone_name]
|
|
|
|
chain = []
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
try:
|
2010-01-19 19:07:09 +00:00
|
|
|
chain += [bone.parent.parent.name, bone.parent.name, bone.name]
|
2010-01-10 19:20:48 +00:00
|
|
|
except AttributeError:
|
2010-01-31 14:33:27 +00:00
|
|
|
raise RigifyError("'%s' rig type requires a chain of two parents (bone: %s)" % (RIG_TYPE, orig_bone_name))
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
chain += [child.name for child in bone.children_recursive_basename]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
if len(chain) < 10:
|
2010-01-31 14:33:27 +00:00
|
|
|
raise RigifyError("'%s' rig type requires a chain of 8 bones (bone: %s)" % (RIG_TYPE, orig_bone_name))
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
return chain[:10]
|
|
|
|
|
|
|
|
|
|
|
|
def deform(obj, definitions, base_names, options):
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
eb = obj.data.edit_bones
|
2010-01-26 11:17:41 +00:00
|
|
|
bb = obj.data.bones
|
2010-01-10 19:20:48 +00:00
|
|
|
pb = obj.pose.bones
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
jaw = definitions[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Options
|
|
|
|
req_options = ["mesh"]
|
|
|
|
for option in req_options:
|
|
|
|
if option not in options:
|
|
|
|
raise RigifyError("'%s' rig type requires a '%s' option (bone: %s)" % (RIG_TYPE, option, base_names[definitions[0]]))
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
meshes = options["mesh"].replace(" ", "").split(",")
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
# Lip DEF
|
|
|
|
lip1 = copy_bone_simple(obj.data, definitions[2], "DEF-" + base_names[definitions[2]]).name
|
|
|
|
lip2 = copy_bone_simple(obj.data, definitions[3], "DEF-" + base_names[definitions[3]]).name
|
|
|
|
lip3 = copy_bone_simple(obj.data, definitions[4], "DEF-" + base_names[definitions[4]]).name
|
|
|
|
lip4 = copy_bone_simple(obj.data, definitions[5], "DEF-" + base_names[definitions[5]]).name
|
|
|
|
lip5 = copy_bone_simple(obj.data, definitions[6], "DEF-" + base_names[definitions[6]]).name
|
|
|
|
lip6 = copy_bone_simple(obj.data, definitions[7], "DEF-" + base_names[definitions[7]]).name
|
|
|
|
lip7 = copy_bone_simple(obj.data, definitions[8], "DEF-" + base_names[definitions[8]]).name
|
|
|
|
lip8 = copy_bone_simple(obj.data, definitions[9], "DEF-" + base_names[definitions[9]]).name
|
|
|
|
|
|
|
|
# Mouth corner spread bones (for driving corrective shape keys)
|
|
|
|
spread_l_1 = copy_bone_simple(obj.data, definitions[6], "MCH-" + base_names[definitions[6]] + ".spread_1").name
|
|
|
|
spread_l_2 = copy_bone_simple(obj.data, definitions[6], "MCH-" + base_names[definitions[6]] + ".spread_2").name
|
|
|
|
eb[spread_l_1].tail = eb[definitions[5]].head
|
|
|
|
eb[spread_l_2].tail = eb[definitions[5]].head
|
|
|
|
eb[spread_l_1].roll = 0
|
|
|
|
eb[spread_l_2].roll = 0
|
|
|
|
eb[spread_l_1].connected = False
|
|
|
|
eb[spread_l_2].connected = False
|
|
|
|
eb[spread_l_1].parent = eb[definitions[6]]
|
|
|
|
eb[spread_l_2].parent = eb[definitions[6]]
|
|
|
|
|
|
|
|
spread_r_1 = copy_bone_simple(obj.data, definitions[2], "MCH-" + base_names[definitions[2]] + ".spread_1").name
|
|
|
|
spread_r_2 = copy_bone_simple(obj.data, definitions[2], "MCH-" + base_names[definitions[2]] + ".spread_2").name
|
|
|
|
eb[spread_r_1].tail = eb[definitions[3]].head
|
|
|
|
eb[spread_r_2].tail = eb[definitions[3]].head
|
|
|
|
eb[spread_r_1].roll = 0
|
|
|
|
eb[spread_r_2].roll = 0
|
|
|
|
eb[spread_r_1].connected = False
|
|
|
|
eb[spread_r_2].connected = False
|
|
|
|
eb[spread_r_1].parent = eb[definitions[2]]
|
|
|
|
eb[spread_r_2].parent = eb[definitions[2]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Jaw open bones (for driving corrective shape keys)
|
2010-01-26 11:17:41 +00:00
|
|
|
jopen1 = copy_bone_simple(obj.data, jaw, "MCH-"+base_names[jaw]+".track1", parent=True).name
|
|
|
|
eb[jopen1].connected = False
|
|
|
|
eb[jopen1].head = eb[jaw].tail
|
|
|
|
eb[jopen1].tail = eb[jopen1].head + Vector(0, 0, eb[jaw].length/4)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
jopen2 = copy_bone_simple(obj.data, jopen1, "MCH-"+base_names[jaw]+".track2").name
|
|
|
|
eb[jopen2].parent = eb[jaw]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
# Constrain DEF bones to ORG bones
|
|
|
|
con = pb[lip1].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = definitions[2]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip2].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = definitions[3]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip3].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = definitions[4]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip4].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[5]
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip5].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[6]
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip6].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[7]
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip7].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[8]
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[lip8].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = definitions[9]
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
# Constraint mouth corner spread bones
|
|
|
|
con = pb[spread_l_1].constraints.new('DAMPED_TRACK')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
|
|
|
con.subtarget = lip4
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[spread_l_2].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = spread_l_1
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[spread_l_2].constraints.new('DAMPED_TRACK')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
|
|
|
con.subtarget = lip6
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[spread_r_1].constraints.new('DAMPED_TRACK')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[spread_r_2].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = spread_r_1
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
con = pb[spread_r_2].constraints.new('DAMPED_TRACK')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
|
|
|
con.subtarget = lip8
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Corrective shape keys for the corners of the mouth.
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Calculate the rotation difference between the bones
|
2010-02-02 17:57:12 +00:00
|
|
|
rotdiff_l = acos((eb[lip5].head - eb[lip4].head).normalize().dot((eb[lip5].head - eb[lip6].head).normalize()))
|
|
|
|
rotdiff_r = acos((eb[lip1].head - eb[lip2].head).normalize().dot((eb[lip1].head - eb[lip8].head).normalize()))
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Left side shape key
|
2010-01-19 19:07:09 +00:00
|
|
|
for mesh_name in meshes:
|
|
|
|
mesh_obj = bpy.data.objects[mesh_name]
|
2010-02-02 17:57:12 +00:00
|
|
|
shape_key_name = "COR-" + base_names[definitions[6]] + ".spread"
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add/get the shape key
|
|
|
|
shape_key = addget_shape_key(mesh_obj, name=shape_key_name)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add/get the shape key driver
|
2010-02-02 17:57:12 +00:00
|
|
|
fcurve, is_new_driver = addget_shape_key_driver(mesh_obj, name=shape_key_name)
|
2010-01-19 19:07:09 +00:00
|
|
|
driver = fcurve.driver
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Get the variable, or create it if it doesn't already exist
|
|
|
|
var_name = base_names[definitions[6]]
|
|
|
|
if var_name in driver.variables:
|
|
|
|
var = driver.variables[var_name]
|
|
|
|
else:
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.name = var_name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set up the variable
|
|
|
|
var.type = "ROTATION_DIFF"
|
|
|
|
var.targets[0].id = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
var.targets[0].bone_target = spread_l_1
|
2010-01-19 19:07:09 +00:00
|
|
|
var.targets[1].id = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
var.targets[1].bone_target = spread_l_2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set fcurve offset
|
2010-02-02 17:57:12 +00:00
|
|
|
if is_new_driver:
|
|
|
|
mod = fcurve.modifiers[0]
|
|
|
|
if rotdiff_l != pi:
|
|
|
|
mod.coefficients[0] = -rotdiff_l / (pi-rotdiff_l)
|
|
|
|
mod.coefficients[1] = 1 / (pi-rotdiff_l)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Right side shape key
|
2010-01-19 19:07:09 +00:00
|
|
|
for mesh_name in meshes:
|
|
|
|
mesh_obj = bpy.data.objects[mesh_name]
|
2010-02-02 17:57:12 +00:00
|
|
|
shape_key_name = "COR-" + base_names[definitions[2]] + ".spread"
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add/get the shape key
|
|
|
|
shape_key = addget_shape_key(mesh_obj, name=shape_key_name)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add/get the shape key driver
|
2010-02-02 17:57:12 +00:00
|
|
|
fcurve, is_new_driver = addget_shape_key_driver(mesh_obj, name=shape_key_name)
|
2010-01-19 19:07:09 +00:00
|
|
|
driver = fcurve.driver
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Get the variable, or create it if it doesn't already exist
|
|
|
|
var_name = base_names[definitions[2]]
|
|
|
|
if var_name in driver.variables:
|
|
|
|
var = driver.variables[var_name]
|
|
|
|
else:
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.name = var_name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set up the variable
|
|
|
|
var.type = "ROTATION_DIFF"
|
|
|
|
var.targets[0].id = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
var.targets[0].bone_target = spread_r_1
|
2010-01-19 19:07:09 +00:00
|
|
|
var.targets[1].id = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
var.targets[1].bone_target = spread_r_2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Set fcurve offset
|
2010-02-02 17:57:12 +00:00
|
|
|
if is_new_driver:
|
|
|
|
mod = fcurve.modifiers[0]
|
|
|
|
if rotdiff_r != pi:
|
|
|
|
mod.coefficients[0] = -rotdiff_r / (pi-rotdiff_r)
|
|
|
|
mod.coefficients[1] = 1 / (pi-rotdiff_r)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Jaw open corrective shape key
|
|
|
|
for mesh_name in meshes:
|
|
|
|
mesh_obj = bpy.data.objects[mesh_name]
|
|
|
|
shape_key_name = "COR-" + base_names[definitions[4]] + ".jaw_open"
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Add/get the shape key
|
|
|
|
shape_key = addget_shape_key(mesh_obj, name=shape_key_name)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Add/get the shape key driver
|
2010-02-02 17:57:12 +00:00
|
|
|
fcurve, is_new_driver = addget_shape_key_driver(mesh_obj, name=shape_key_name)
|
2010-01-26 11:17:41 +00:00
|
|
|
driver = fcurve.driver
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Get the variable, or create it if it doesn't already exist
|
|
|
|
var_name = base_names[definitions[4]]
|
|
|
|
if var_name in driver.variables:
|
|
|
|
var = driver.variables[var_name]
|
|
|
|
else:
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.name = var_name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Set up the variable
|
|
|
|
var.type = "LOC_DIFF"
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].bone_target = jopen1
|
|
|
|
var.targets[1].id = obj
|
|
|
|
var.targets[1].bone_target = jopen2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Set fcurve offset
|
2010-02-02 17:57:12 +00:00
|
|
|
if is_new_driver:
|
|
|
|
mod = fcurve.modifiers[0]
|
|
|
|
mod.coefficients[0] = 0.0
|
|
|
|
mod.coefficients[1] = 1.0 / bb[jaw].length
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
return (None,)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def control(obj, definitions, base_names, options):
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
eb = obj.data.edit_bones
|
|
|
|
bb = obj.data.bones
|
|
|
|
pb = obj.pose.bones
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
head_e = eb[definitions[0]]
|
|
|
|
jaw_e = eb[definitions[1]]
|
2010-01-19 19:07:09 +00:00
|
|
|
jaw = definitions[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Head lips
|
|
|
|
hlip1 = copy_bone_simple(obj.data, definitions[2], "MCH-"+base_names[definitions[2]]+".head").name
|
|
|
|
hlip2 = copy_bone_simple(obj.data, definitions[3], "MCH-"+base_names[definitions[3]]+".head").name
|
|
|
|
hlip3 = copy_bone_simple(obj.data, definitions[4], "MCH-"+base_names[definitions[4]]+".head").name
|
|
|
|
hlip4 = copy_bone_simple(obj.data, definitions[5], "MCH-"+base_names[definitions[5]]+".head").name
|
|
|
|
hlip5 = copy_bone_simple(obj.data, definitions[6], "MCH-"+base_names[definitions[6]]+".head").name
|
|
|
|
hlip6 = copy_bone_simple(obj.data, definitions[7], "MCH-"+base_names[definitions[7]]+".head").name
|
|
|
|
hlip7 = copy_bone_simple(obj.data, definitions[8], "MCH-"+base_names[definitions[8]]+".head").name
|
|
|
|
hlip8 = copy_bone_simple(obj.data, definitions[9], "MCH-"+base_names[definitions[9]]+".head").name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
eb[hlip1].parent = head_e
|
|
|
|
eb[hlip2].parent = head_e
|
|
|
|
eb[hlip3].parent = head_e
|
|
|
|
eb[hlip4].parent = head_e
|
|
|
|
eb[hlip5].parent = head_e
|
|
|
|
eb[hlip6].parent = head_e
|
|
|
|
eb[hlip7].parent = head_e
|
|
|
|
eb[hlip8].parent = head_e
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Jaw lips
|
|
|
|
jlip1 = copy_bone_simple(obj.data, definitions[2], "MCH-"+base_names[definitions[2]]+".jaw").name
|
|
|
|
jlip2 = copy_bone_simple(obj.data, definitions[3], "MCH-"+base_names[definitions[3]]+".jaw").name
|
|
|
|
jlip3 = copy_bone_simple(obj.data, definitions[4], "MCH-"+base_names[definitions[4]]+".jaw").name
|
|
|
|
jlip4 = copy_bone_simple(obj.data, definitions[5], "MCH-"+base_names[definitions[5]]+".jaw").name
|
|
|
|
jlip5 = copy_bone_simple(obj.data, definitions[6], "MCH-"+base_names[definitions[6]]+".jaw").name
|
|
|
|
jlip6 = copy_bone_simple(obj.data, definitions[7], "MCH-"+base_names[definitions[7]]+".jaw").name
|
|
|
|
jlip7 = copy_bone_simple(obj.data, definitions[8], "MCH-"+base_names[definitions[8]]+".jaw").name
|
|
|
|
jlip8 = copy_bone_simple(obj.data, definitions[9], "MCH-"+base_names[definitions[9]]+".jaw").name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
eb[jlip1].parent = jaw_e
|
|
|
|
eb[jlip2].parent = jaw_e
|
|
|
|
eb[jlip3].parent = jaw_e
|
|
|
|
eb[jlip4].parent = jaw_e
|
|
|
|
eb[jlip5].parent = jaw_e
|
|
|
|
eb[jlip6].parent = jaw_e
|
|
|
|
eb[jlip7].parent = jaw_e
|
|
|
|
eb[jlip8].parent = jaw_e
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Control lips
|
|
|
|
lip1 = copy_bone_simple(obj.data, definitions[2], base_names[definitions[2]]).name
|
|
|
|
lip2 = copy_bone_simple(obj.data, definitions[3], base_names[definitions[3]]).name
|
|
|
|
lip3 = copy_bone_simple(obj.data, definitions[4], base_names[definitions[4]]).name
|
|
|
|
lip4 = copy_bone_simple(obj.data, definitions[5], base_names[definitions[5]]).name
|
|
|
|
lip5 = copy_bone_simple(obj.data, definitions[6], base_names[definitions[6]]).name
|
|
|
|
lip6 = copy_bone_simple(obj.data, definitions[7], base_names[definitions[7]]).name
|
|
|
|
lip7 = copy_bone_simple(obj.data, definitions[8], base_names[definitions[8]]).name
|
|
|
|
lip8 = copy_bone_simple(obj.data, definitions[9], base_names[definitions[9]]).name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
eb[lip1].parent = eb[hlip1]
|
|
|
|
eb[lip2].parent = eb[hlip2]
|
|
|
|
eb[lip3].parent = eb[hlip3]
|
|
|
|
eb[lip4].parent = eb[hlip4]
|
|
|
|
eb[lip5].parent = eb[hlip5]
|
|
|
|
eb[lip6].parent = eb[hlip6]
|
|
|
|
eb[lip7].parent = eb[hlip7]
|
|
|
|
eb[lip8].parent = eb[hlip8]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Jaw open tracker
|
|
|
|
jopent = copy_bone_simple(obj.data, jaw_e.name, "MCH-"+base_names[jaw_e.name]+".track", parent=True).name
|
|
|
|
eb[jopent].connected = False
|
|
|
|
eb[jopent].tail = jaw_e.tail + Vector(0,0,jaw_e.length)
|
|
|
|
eb[jopent].head = jaw_e.tail
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-26 11:17:41 +00:00
|
|
|
# Add mouth open action if it doesn't already exist
|
2010-01-19 19:07:09 +00:00
|
|
|
action_name = "mouth_open"
|
|
|
|
if action_name in bpy.data.actions:
|
|
|
|
open_action = bpy.data.actions[action_name]
|
|
|
|
else:
|
|
|
|
open_action = add_action(name=action_name)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Add close property (useful when making the animation in the action)
|
|
|
|
prop_name = "open_action"
|
|
|
|
prop = rna_idprop_ui_prop_get(pb[lip1], prop_name, create=True)
|
|
|
|
pb[lip1][prop_name] = 1.0
|
|
|
|
prop["soft_min"] = 0.0
|
|
|
|
prop["soft_max"] = 1.0
|
|
|
|
prop["min"] = 0.0
|
|
|
|
prop["max"] = 1.0
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-04-06 07:49:10 +00:00
|
|
|
open_driver_path = pb[lip1].path_from_id() + '["open_action"]'
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Constraints
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Jaw open tracker stretches to jaw tip
|
|
|
|
con = pb[jopent].constraints.new('STRETCH_TO')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jaw
|
|
|
|
con.head_tail = 1.0
|
|
|
|
con.original_length = bb[jopent].length
|
|
|
|
con.volume = 'NO_VOLUME'
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Head lips to jaw lips
|
2010-02-02 17:57:12 +00:00
|
|
|
influence = [0.02, 0.1, 0.35, 0.25, 0.0]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip1].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip1
|
2010-01-10 19:20:48 +00:00
|
|
|
con.influence = influence[2]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip2].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip2
|
2010-01-10 19:20:48 +00:00
|
|
|
con.influence = influence[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip3].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip3
|
2010-01-10 19:20:48 +00:00
|
|
|
con.influence = influence[0]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip4].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip4
|
2010-01-10 19:20:48 +00:00
|
|
|
con.influence = influence[1]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip5].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip5
|
2010-01-10 19:20:48 +00:00
|
|
|
con.influence = influence[2]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip6].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip6
|
|
|
|
con.influence = 1.0 - influence[3]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip7].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip7
|
|
|
|
con.influence = 1.0 - influence[4]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[hlip8].constraints.new('COPY_TRANSFORMS')
|
2010-01-10 19:20:48 +00:00
|
|
|
con.target = obj
|
2010-01-19 19:07:09 +00:00
|
|
|
con.subtarget = jlip8
|
|
|
|
con.influence = 1.0 - influence[3]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-02-02 17:57:12 +00:00
|
|
|
# ORG bones to lips
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[2]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip1
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[3]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip2
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[4]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip3
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[5]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip4
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[6]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip5
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[7]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip6
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[8]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip7
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = pb[definitions[9]].constraints.new('COPY_TRANSFORMS')
|
|
|
|
con.target = obj
|
2010-02-02 17:57:12 +00:00
|
|
|
con.subtarget = lip8
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
# Action constraints for open mouth
|
|
|
|
con = pb[lip1].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip2].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip3].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip4].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip5].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip6].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip7].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-19 19:07:09 +00:00
|
|
|
con = pb[lip8].constraints.new('ACTION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = jopent
|
|
|
|
con.action = open_action
|
|
|
|
con.transform_channel = 'SCALE_Y'
|
2010-04-01 21:44:56 +00:00
|
|
|
con.frame_start = 0
|
|
|
|
con.frame_end = 60
|
2010-01-19 19:07:09 +00:00
|
|
|
con.minimum = 0.0
|
|
|
|
con.maximum = 1.0
|
|
|
|
con.target_space = 'LOCAL'
|
|
|
|
fcurve = con.driver_add("influence", 0)
|
|
|
|
driver = fcurve.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
var = driver.variables.new()
|
|
|
|
var.targets[0].id_type = 'OBJECT'
|
|
|
|
var.targets[0].id = obj
|
|
|
|
var.targets[0].data_path = open_driver_path
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Set layers
|
|
|
|
layer = list(bb[definitions[2]].layer)
|
|
|
|
bb[lip1].layer = layer
|
|
|
|
bb[lip2].layer = layer
|
|
|
|
bb[lip3].layer = layer
|
|
|
|
bb[lip4].layer = layer
|
|
|
|
bb[lip5].layer = layer
|
|
|
|
bb[lip6].layer = layer
|
|
|
|
bb[lip7].layer = layer
|
|
|
|
bb[lip8].layer = layer
|
2010-01-31 14:30:21 +00:00
|
|
|
|
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
return (None,)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(obj, bone_definition, base_names, options):
|
|
|
|
# Create control rig
|
|
|
|
control(obj, bone_definition, base_names, options)
|
|
|
|
# Create deform rig
|
|
|
|
deform(obj, bone_definition, base_names, options)
|
|
|
|
|
|
|
|
return (None,)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_lip_stretch_bone(obj, name, bone1, bone2, roll_alpha):
|
|
|
|
eb = obj.data.edit_bones
|
|
|
|
pb = obj.pose.bones
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Create the bone, pointing from bone1 to bone2
|
|
|
|
bone_e = copy_bone_simple(obj.data, bone1, name, parent=True)
|
|
|
|
bone_e.connected = False
|
|
|
|
bone_e.tail = eb[bone2].head
|
|
|
|
bone = bone_e.name
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Align the bone roll with the average direction of bone1 and bone2
|
|
|
|
vec = bone_e.y_axis.cross(((1.0-roll_alpha)*eb[bone1].y_axis) + (roll_alpha*eb[bone2].y_axis)).normalize()
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
ang = acos(vec * bone_e.x_axis)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
bone_e.roll += ang
|
|
|
|
c1 = vec * bone_e.x_axis
|
|
|
|
bone_e.roll -= (ang*2)
|
|
|
|
c2 = vec * bone_e.x_axis
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
if c1 > c2:
|
|
|
|
bone_e.roll += (ang*2)
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
bone_p = pb[bone]
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
# Constrains
|
|
|
|
con = bone_p.constraints.new('COPY_LOCATION')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = bone1
|
2010-01-31 14:30:21 +00:00
|
|
|
|
2010-01-10 19:20:48 +00:00
|
|
|
con = bone_p.constraints.new('DAMPED_TRACK')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = bone2
|
|
|
|
|
|
|
|
con = bone_p.constraints.new('STRETCH_TO')
|
|
|
|
con.target = obj
|
|
|
|
con.subtarget = bone2
|
|
|
|
con.volume = 'NO_VOLUME'
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
|
|
|
|
return bone
|