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_utils import bone_class_instance, copy_bone_simple
24
METARIG_NAMES = ("cpy",)
27
def metarig_template():
28
# generated by rigify.write_meta_rig
29
bpy.ops.object.mode_set(mode='EDIT')
30
obj = bpy.context.active_object
32
bone = arm.edit_bones.new('Bone')
33
bone.head[:] = 0.0000, 0.0000, 0.0000
34
bone.tail[:] = 0.0000, 0.0000, 1.0000
36
bone.connected = False
38
bpy.ops.object.mode_set(mode='OBJECT')
39
pbone = obj.pose.bones['Bone']
40
pbone['type'] = 'copy'
43
def metarig_definition(obj, orig_bone_name):
44
return (orig_bone_name,)
47
def deform(obj, definitions, base_names, options):
48
bpy.ops.object.mode_set(mode='EDIT')
51
bone = copy_bone_simple(obj.data, definitions[0], "DEF-%s" % base_names[definitions[0]], parent=True)
53
# Store name before leaving edit mode
57
bpy.ops.object.mode_set(mode='OBJECT')
60
bone = obj.pose.bones[bone_name]
62
# Constrain to the original bone
63
con = bone.constraints.new('COPY_TRANSFORMS')
66
con.subtarget = definitions[0]
71
def control(obj, definitions, base_names, options):
72
bpy.ops.object.mode_set(mode='EDIT')
75
mt = bone_class_instance(obj, METARIG_NAMES)
76
mt.cpy = definitions[0]
78
cp = bone_class_instance(obj, ["cpy"])
79
cp.cpy_e = copy_bone_simple(arm, mt.cpy, base_names[mt.cpy], parent=True)
80
cp.cpy = cp.cpy_e.name
82
bpy.ops.object.mode_set(mode='OBJECT')
87
con = mt.cpy_p.constraints.new('COPY_TRANSFORMS')
89
con.subtarget = cp.cpy
92
# Rotation mode and axis locks
93
cp.cpy_p.rotation_mode = mt.cpy_p.rotation_mode
94
cp.cpy_p.lock_location = tuple(mt.cpy_p.lock_location)
95
cp.cpy_p.lock_rotations_4d = mt.cpy_p.lock_rotations_4d
96
cp.cpy_p.lock_rotation = tuple(mt.cpy_p.lock_rotation)
97
cp.cpy_p.lock_rotation_w = mt.cpy_p.lock_rotation_w
98
cp.cpy_p.lock_scale = tuple(mt.cpy_p.lock_scale)
101
cp.cpy_b.layer = list(mt.cpy_b.layer)
106
def main(obj, bone_definition, base_names, options):
107
# Create control bone
108
cpy = control(obj, bone_definition, base_names, options)[0]
110
deform(obj, bone_definition, base_names, options)