1
# ##### BEGIN GPL LICENSE BLOCK #####
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# ##### END GPL LICENSE BLOCK #####
22
from rigify import RigifyError
23
from rigify_utils import copy_bone_simple
25
METARIG_NAMES = tuple()
26
RIG_TYPE = "stretch_twist"
29
#def metarig_template():
30
# # generated by rigify.write_meta_rig
31
# bpy.ops.object.mode_set(mode='EDIT')
32
# obj = bpy.context.active_object
34
# bone = arm.edit_bones.new('Bone')
35
# bone.head[:] = 0.0000, 0.0000, 0.0000
36
# bone.tail[:] = 0.0000, 0.0000, 1.0000
38
# bone.connected = False
40
# bpy.ops.object.mode_set(mode='OBJECT')
41
# pbone = obj.pose.bones['Bone']
42
# pbone['type'] = 'copy'
44
bool_map = {0:False, 1:True,
46
"false":False, "true":True,
47
"False":False, "True":True,
48
"no":False, "yes":True,
49
"No":False, "Yes":True}
51
def metarig_definition(obj, orig_bone_name):
52
return (orig_bone_name,)
57
def main(obj, bone_definition, base_names, options):
58
""" A dual-bone stretchy bone setup. Each half follows the twist of the
60
Deformation only (no controls).
62
# Verify required parameter
63
if "to" not in options:
64
raise RigifyError("'%s' rig type requires a 'to' parameter (bone: %s)" % (RIG_TYPE, base_names[0]))
65
if type(options["to"]) is not str:
66
raise RigifyError("'%s' rig type 'to' parameter must be a string (bone: %s)" % (RIG_TYPE, base_names[0]))
67
if ("ORG-" + options["to"]) not in obj.data.bones:
68
raise RigifyError("'%s' rig type 'to' parameter must name a bone in the metarig (bone: %s)" % (RIG_TYPE, base_names[0]))
70
preserve_volume = None
71
# Check optional parameter
72
if "preserve_volume" in options:
74
preserve_volume = bool_map[options["preserve_volume"]]
76
preserve_volume = False
78
eb = obj.data.edit_bones
82
bpy.ops.object.mode_set(mode='EDIT')
85
mbone1 = bone_definition[0]
86
mbone2 = "ORG-" + options["to"]
88
bone_e = copy_bone_simple(obj.data, mbone1, "MCH-%s" % base_names[bone_definition[0]])
89
bone_e.connected = False
91
bone_e.head = (eb[mbone1].head + eb[mbone2].head) / 2
92
bone_e.tail = (bone_e.head[0], bone_e.head[1], bone_e.head[2]+0.1)
93
mid_bone = bone_e.name
95
bone_e = copy_bone_simple(obj.data, mbone1, "DEF-%s.01" % base_names[bone_definition[0]])
96
bone_e.connected = False
97
bone_e.parent = eb[mbone1]
98
bone_e.tail = eb[mid_bone].head
101
bone_e = copy_bone_simple(obj.data, mbone2, "DEF-%s.02" % base_names[bone_definition[0]])
102
bone_e.connected = False
103
bone_e.parent = eb[mbone2]
104
bone_e.tail = eb[mid_bone].head
109
bpy.ops.object.mode_set(mode='OBJECT')
114
con = pb[mid_bone].constraints.new('COPY_LOCATION')
116
con.subtarget = mbone1
118
con = pb[mid_bone].constraints.new('COPY_LOCATION')
120
con.subtarget = mbone2
124
con = pb[bone1].constraints.new('DAMPED_TRACK')
126
con.subtarget = mid_bone
128
con = pb[bone1].constraints.new('STRETCH_TO')
130
con.subtarget = mid_bone
131
con.original_length = bb[bone1].length
133
con.volume = 'VOLUME_XZX'
135
con.volume = 'NO_VOLUME'
138
con = pb[bone2].constraints.new('DAMPED_TRACK')
140
con.subtarget = mid_bone
142
con = pb[bone2].constraints.new('STRETCH_TO')
144
con.subtarget = mid_bone
145
con.original_length = bb[bone2].length
147
con.volume = 'VOLUME_XZX'
149
con.volume = 'NO_VOLUME'