2009-11-30 12:31:11 +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,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
# <pep8 compliant>
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
import bpy
|
2009-12-10 18:28:22 +00:00
|
|
|
from rigify import RigifyError
|
2009-11-30 12:31:11 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
# not used, defined for completeness
|
|
|
|
METARIG_NAMES = tuple()
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-10 11:56:31 +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('bonesker')
|
|
|
|
bone.head[:] = 0.0000, 0.0000, 0.0000
|
|
|
|
bone.tail[:] = -0.0000, 0.7382, 0.1895
|
|
|
|
bone.roll = -0.0000
|
|
|
|
bone.connected = False
|
|
|
|
bone = arm.edit_bones.new('delta')
|
|
|
|
bone.head[:] = -0.0497, 0.8414, 0.3530
|
|
|
|
bone.tail[:] = -0.2511, 1.1588, 0.9653
|
|
|
|
bone.roll = 2.6044
|
|
|
|
bone.connected = False
|
|
|
|
bone.parent = arm.edit_bones['bonesker']
|
|
|
|
bone = arm.edit_bones.new('boney')
|
|
|
|
bone.head[:] = 0.7940, 2.5592, 0.4134
|
|
|
|
bone.tail[:] = 0.7940, 3.3975, 0.4890
|
|
|
|
bone.roll = 3.1416
|
|
|
|
bone.connected = False
|
|
|
|
bone.parent = arm.edit_bones['delta']
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
pbone = obj.pose.bones['delta']
|
|
|
|
pbone['type'] = 'delta'
|
|
|
|
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
def metarig_definition(obj, orig_bone_name):
|
2009-11-30 12:31:11 +00:00
|
|
|
'''
|
2009-12-05 19:26:28 +00:00
|
|
|
The bone given is the head, its parent is the body,
|
|
|
|
# its only child the first of a chain with matching basenames.
|
|
|
|
eg.
|
|
|
|
body -> head -> neck_01 -> neck_02 -> neck_03.... etc
|
2009-11-30 12:31:11 +00:00
|
|
|
'''
|
|
|
|
arm = obj.data
|
2009-12-05 19:26:28 +00:00
|
|
|
delta = arm.bones[orig_bone_name]
|
|
|
|
children = delta.children
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
if len(children) != 1:
|
2009-12-10 18:28:22 +00:00
|
|
|
raise RigifyError("only 1 child supported for delta on bone '%s'" % delta.name)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-10 22:23:09 +00:00
|
|
|
if delta.connected:
|
|
|
|
raise RigifyError("bone cannot be connected to its parent '%s'" % delta.name)
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
bone_definition = [delta.name, children[0].name]
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
return bone_definition
|
|
|
|
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-11 16:30:27 +00:00
|
|
|
def main(obj, bone_definition, base_names, options):
|
2009-12-05 19:26:28 +00:00
|
|
|
'''
|
|
|
|
Use this bone to define a delta thats applied to its child in pose mode.
|
|
|
|
'''
|
2009-11-30 12:31:11 +00:00
|
|
|
mode_orig = obj.mode
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
delta_name, child_name = bone_definition
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
delta_pbone = obj.pose.bones[delta_name]
|
|
|
|
|
2009-12-10 12:58:03 +00:00
|
|
|
arm = obj.data
|
|
|
|
child_pbone = obj.pose.bones[child_name]
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
delta_phead = delta_pbone.head.copy()
|
|
|
|
delta_ptail = delta_pbone.tail.copy()
|
|
|
|
delta_pmatrix = delta_pbone.matrix.copy()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
child_phead = child_pbone.head.copy()
|
|
|
|
child_ptail = child_pbone.tail.copy()
|
|
|
|
child_pmatrix = child_pbone.matrix.copy()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
children = delta_pbone.children
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
delta_ebone = arm.edit_bones[delta_name]
|
|
|
|
child_ebone = arm.edit_bones[child_name]
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
delta_head = delta_ebone.head.copy()
|
2009-12-05 22:03:07 +00:00
|
|
|
delta_tail = delta_ebone.tail.copy()
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
child_head = child_ebone.head.copy()
|
|
|
|
child_tail = child_ebone.tail.copy()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-07 17:21:30 +00:00
|
|
|
#arm.edit_bones.remove(delta_ebone)
|
|
|
|
#del delta_ebone # cant use this
|
|
|
|
del child_pbone
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
2009-12-08 07:11:43 +00:00
|
|
|
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
# Move the child bone to the deltas location
|
|
|
|
obj.animation_data_create()
|
2009-12-07 17:21:30 +00:00
|
|
|
delta_pbone = obj.pose.bones[delta_name]
|
|
|
|
# child_pbone = obj.pose.bones[child_name]
|
2009-12-08 07:11:43 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
# ------------------- drivers
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-07 17:21:30 +00:00
|
|
|
delta_pbone.rotation_mode = 'XYZ'
|
2009-12-05 22:03:07 +00:00
|
|
|
|
Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
- Mathutils.MidpointVecs --> vector.lerp(other, fac)
- Mathutils.AngleBetweenVecs --> vector.angle(other)
- Mathutils.ProjectVecs --> vector.project(other)
- Mathutils.DifferenceQuats --> quat.difference(other)
- Mathutils.Slerp --> quat.slerp(other, fac)
- Mathutils.Rand: removed, use pythons random module
- Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
- Matrix.scalePart --> Matrix.scale_part
- Matrix.translationPart --> Matrix.translation_part
- Matrix.rotationPart --> Matrix.rotation_part
- toMatrix --> to_matrix
- toEuler --> to_euler
- toQuat --> to_quat
- Vector.toTrackQuat --> Vector.to_track_quat
2010-01-25 09:44:04 +00:00
|
|
|
rot = delta_pmatrix.invert().rotation_part() * child_pmatrix.rotation_part()
|
|
|
|
rot = rot.invert().to_euler()
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-07 17:21:30 +00:00
|
|
|
fcurve_drivers = delta_pbone.driver_add("rotation_euler", -1)
|
2009-11-30 12:31:11 +00:00
|
|
|
for i, fcurve_driver in enumerate(fcurve_drivers):
|
|
|
|
driver = fcurve_driver.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
#mod = fcurve_driver.modifiers.new('GENERATOR')
|
|
|
|
mod = fcurve_driver.modifiers[0]
|
|
|
|
mod.poly_order = 1
|
|
|
|
mod.coefficients[0] = rot[i]
|
|
|
|
mod.coefficients[1] = 0.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
# tricky, find the transform to drive the bone to this location.
|
Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
- Mathutils.MidpointVecs --> vector.lerp(other, fac)
- Mathutils.AngleBetweenVecs --> vector.angle(other)
- Mathutils.ProjectVecs --> vector.project(other)
- Mathutils.DifferenceQuats --> quat.difference(other)
- Mathutils.Slerp --> quat.slerp(other, fac)
- Mathutils.Rand: removed, use pythons random module
- Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
- Matrix.scalePart --> Matrix.scale_part
- Matrix.translationPart --> Matrix.translation_part
- Matrix.rotationPart --> Matrix.rotation_part
- toMatrix --> to_matrix
- toEuler --> to_euler
- toQuat --> to_quat
- Vector.toTrackQuat --> Vector.to_track_quat
2010-01-25 09:44:04 +00:00
|
|
|
delta_head_offset = child_pmatrix.rotation_part() * (delta_phead - child_phead)
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-12-07 17:21:30 +00:00
|
|
|
fcurve_drivers = delta_pbone.driver_add("location", -1)
|
2009-11-30 12:31:11 +00:00
|
|
|
for i, fcurve_driver in enumerate(fcurve_drivers):
|
|
|
|
driver = fcurve_driver.driver
|
|
|
|
driver.type = 'AVERAGE'
|
|
|
|
#mod = fcurve_driver.modifiers.new('GENERATOR')
|
|
|
|
mod = fcurve_driver.modifiers[0]
|
|
|
|
mod.poly_order = 1
|
|
|
|
mod.coefficients[0] = delta_head_offset[i]
|
|
|
|
mod.coefficients[1] = 0.0
|
2009-12-05 22:03:07 +00:00
|
|
|
|
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2009-12-05 22:03:07 +00:00
|
|
|
|
2009-11-30 12:31:11 +00:00
|
|
|
bpy.ops.object.mode_set(mode=mode_orig)
|
|
|
|
|
2009-12-05 19:26:28 +00:00
|
|
|
# no blendeing
|
|
|
|
return None
|