~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/modules/rigify/tail_control.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ##### BEGIN GPL LICENSE BLOCK #####
2
 
#
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.
7
 
#
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.
12
 
#
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 
#
17
 
# ##### END GPL LICENSE BLOCK #####
18
 
 
19
 
# <pep8 compliant>
20
 
 
21
 
import bpy
22
 
from rigify import RigifyError
23
 
from rigify_utils import bone_class_instance, copy_bone_simple
24
 
from rna_prop_ui import rna_idprop_ui_prop_get
25
 
from mathutils import Vector, RotationMatrix
26
 
from math import radians, pi
27
 
 
28
 
# not used, defined for completeness
29
 
METARIG_NAMES = ("pelvis", "ribcage")
30
 
 
31
 
 
32
 
def metarig_template():
33
 
    # TODO
34
 
    pass
35
 
    # generated by rigify.write_meta_rig
36
 
    #bpy.ops.object.mode_set(mode='EDIT')
37
 
    #obj = bpy.context.active_object
38
 
    #arm = obj.data
39
 
    #bone = arm.edit_bones.new('tail.01')
40
 
    #bone.head[:] = 0.0000, -0.0306, 0.1039
41
 
    #bone.tail[:] = 0.0000, -0.0306, -0.0159
42
 
    #bone.roll = 0.0000
43
 
    #bone.connected = False
44
 
 
45
 
    #bpy.ops.object.mode_set(mode='OBJECT')
46
 
    #pbone = obj.pose.bones['tail.01']
47
 
    #pbone['type'] = 'tail_spline_ik'
48
 
 
49
 
 
50
 
def metarig_definition(obj, orig_bone_name):
51
 
    """ Collects and returns the relevent bones for the rig.
52
 
        The bone given is the first in the chain of tail bones.
53
 
        It includes bones in the chain up until it hits a bone that doesn't
54
 
        have the same name base.
55
 
 
56
 
        tail.01 -> tail.02 -> tail.03 -> ... -> tail.n
57
 
    """
58
 
    arm = obj.data
59
 
    tail_base = arm.bones[orig_bone_name]
60
 
 
61
 
    if tail_base.parent == None:
62
 
        raise RigifyError("'tail_control' rig type on bone '%s' requires a parent." % orig_bone_name)
63
 
 
64
 
    bone_definitions = [tail_base.name]
65
 
    bone_definitions.extend([child.name for child in tail_base.children_recursive_basename])
66
 
    return bone_definitions
67
 
 
68
 
 
69
 
def main(obj, bone_definitions, base_names, options):
70
 
    bpy.ops.object.mode_set(mode='EDIT')
71
 
    arm = obj.data
72
 
    bb = obj.data.bones
73
 
    eb = obj.data.edit_bones
74
 
    pb = obj.pose.bones
75
 
 
76
 
    # Create bones for hinge/free
77
 
    # hinge 1 sticks with the parent
78
 
    # hinge 2 is the parent of the tail controls
79
 
    hinge1 = copy_bone_simple(arm, bone_definitions[0], "MCH-%s.hinge1" % base_names[bone_definitions[0]], parent=True).name
80
 
    hinge2 = copy_bone_simple(arm, bone_definitions[0], "MCH-%s.hinge2" % base_names[bone_definitions[0]], parent=False).name
81
 
 
82
 
    # Create tail control bones
83
 
    bones = []
84
 
    i = 0
85
 
    for bone_def in bone_definitions:
86
 
        bone = copy_bone_simple(arm, bone_def, base_names[bone_def], parent=True).name
87
 
        if i == 1:  # Don't change parent of first tail bone
88
 
            eb[bone].connected = False
89
 
            eb[bone].parent = eb[hinge2]
90
 
            eb[bone].local_location = False
91
 
        i = 1
92
 
        bones += [bone]
93
 
 
94
 
 
95
 
    bpy.ops.object.mode_set(mode='OBJECT')
96
 
 
97
 
    # Rotation mode and axis locks
98
 
    for bone, org_bone in zip(bones, bone_definitions):
99
 
        pb[bone].rotation_mode = pb[org_bone].rotation_mode
100
 
        pb[bone].lock_location = tuple(pb[org_bone].lock_location)
101
 
        pb[bone].lock_rotations_4d = pb[org_bone].lock_rotations_4d
102
 
        pb[bone].lock_rotation = tuple(pb[org_bone].lock_rotation)
103
 
        pb[bone].lock_rotation_w = pb[org_bone].lock_rotation_w
104
 
        pb[bone].lock_scale = tuple(pb[org_bone].lock_scale)
105
 
 
106
 
    # Add custom properties
107
 
    pb[bones[0]]["hinge"] = 0.0
108
 
    prop = rna_idprop_ui_prop_get(pb[bones[0]], "hinge", create=True)
109
 
    prop["min"] = 0.0
110
 
    prop["max"] = 1.0
111
 
    prop["soft_min"] = 0.0
112
 
    prop["soft_max"] = 1.0
113
 
 
114
 
    pb[bones[0]]["free"] = 0.0
115
 
    prop = rna_idprop_ui_prop_get(pb[bones[0]], "free", create=True)
116
 
    prop["min"] = 0.0
117
 
    prop["max"] = 1.0
118
 
    prop["soft_min"] = 0.0
119
 
    prop["soft_max"] = 1.0
120
 
 
121
 
    # Add constraints
122
 
    for bone, org_bone in zip(bones, bone_definitions):
123
 
        con = pb[org_bone].constraints.new('COPY_TRANSFORMS')
124
 
        con.target = obj
125
 
        con.subtarget = bone
126
 
 
127
 
    con_f = pb[hinge2].constraints.new('COPY_LOCATION')
128
 
    con_f.target = obj
129
 
    con_f.subtarget = hinge1
130
 
 
131
 
    con_h = pb[hinge2].constraints.new('COPY_TRANSFORMS')
132
 
    con_h.target = obj
133
 
    con_h.subtarget = hinge1
134
 
 
135
 
    # Add drivers
136
 
    bone_path = pb[bones[0]].path_from_id()
137
 
 
138
 
    driver_fcurve = con_f.driver_add("influence")
139
 
    driver = driver_fcurve.driver
140
 
    driver.type = 'AVERAGE'
141
 
    var = driver.variables.new()
142
 
    var.name = "free"
143
 
    var.targets[0].id_type = 'OBJECT'
144
 
    var.targets[0].id = obj
145
 
    var.targets[0].data_path = bone_path + '["free"]'
146
 
    mod = driver_fcurve.modifiers[0]
147
 
    mod.poly_order = 1
148
 
    mod.coefficients[0] = 1.0
149
 
    mod.coefficients[1] = -1.0
150
 
 
151
 
    driver_fcurve = con_h.driver_add("influence")
152
 
    driver = driver_fcurve.driver
153
 
    driver.type = 'AVERAGE'
154
 
    var = driver.variables.new()
155
 
    var.name = "hinge"
156
 
    var.targets[0].id_type = 'OBJECT'
157
 
    var.targets[0].id = obj
158
 
    var.targets[0].data_path = bone_path + '["hinge"]'
159
 
    mod = driver_fcurve.modifiers[0]
160
 
    mod.poly_order = 1
161
 
    mod.coefficients[0] = 1.0
162
 
    mod.coefficients[1] = -1.0
163
 
 
164
 
 
165
 
    return None