~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/modules/rigify/stretch_twist.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 copy_bone_simple
24
 
 
25
 
METARIG_NAMES = tuple()
26
 
RIG_TYPE = "stretch_twist"
27
 
 
28
 
# TODO
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
33
 
#    arm = obj.data
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
37
 
#    bone.roll = 0.0000
38
 
#    bone.connected = False
39
 
#
40
 
#    bpy.ops.object.mode_set(mode='OBJECT')
41
 
#    pbone = obj.pose.bones['Bone']
42
 
#    pbone['type'] = 'copy'
43
 
 
44
 
bool_map = {0:False, 1:True,
45
 
            0.0:False, 1.0:True,
46
 
            "false":False, "true":True,
47
 
            "False":False, "True":True,
48
 
            "no":False, "yes":True,
49
 
            "No":False, "Yes":True}
50
 
 
51
 
def metarig_definition(obj, orig_bone_name):
52
 
    return (orig_bone_name,)
53
 
 
54
 
 
55
 
 
56
 
 
57
 
def main(obj, bone_definition, base_names, options):
58
 
    """ A dual-bone stretchy bone setup.  Each half follows the twist of the
59
 
        bone on its side.
60
 
        Deformation only (no controls).
61
 
    """
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]))
69
 
 
70
 
    preserve_volume = None
71
 
    # Check optional parameter
72
 
    if "preserve_volume" in options:
73
 
        try:
74
 
            preserve_volume = bool_map[options["preserve_volume"]]
75
 
        except KeyError:
76
 
            preserve_volume = False
77
 
 
78
 
    eb = obj.data.edit_bones
79
 
    bb = obj.data.bones
80
 
    pb = obj.pose.bones
81
 
 
82
 
    bpy.ops.object.mode_set(mode='EDIT')
83
 
    arm = obj.data
84
 
 
85
 
    mbone1 = bone_definition[0]
86
 
    mbone2 = "ORG-" + options["to"]
87
 
 
88
 
    bone_e = copy_bone_simple(obj.data, mbone1, "MCH-%s" % base_names[bone_definition[0]])
89
 
    bone_e.connected = False
90
 
    bone_e.parent = None
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
94
 
 
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
99
 
    bone1 = bone_e.name
100
 
 
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
105
 
    bone2 = bone_e.name
106
 
 
107
 
 
108
 
 
109
 
    bpy.ops.object.mode_set(mode='OBJECT')
110
 
 
111
 
    # Constraints
112
 
 
113
 
    # Mid bone
114
 
    con = pb[mid_bone].constraints.new('COPY_LOCATION')
115
 
    con.target = obj
116
 
    con.subtarget = mbone1
117
 
 
118
 
    con = pb[mid_bone].constraints.new('COPY_LOCATION')
119
 
    con.target = obj
120
 
    con.subtarget = mbone2
121
 
    con.influence = 0.5
122
 
 
123
 
    # Bone 1
124
 
    con = pb[bone1].constraints.new('DAMPED_TRACK')
125
 
    con.target = obj
126
 
    con.subtarget = mid_bone
127
 
 
128
 
    con = pb[bone1].constraints.new('STRETCH_TO')
129
 
    con.target = obj
130
 
    con.subtarget = mid_bone
131
 
    con.original_length = bb[bone1].length
132
 
    if preserve_volume:
133
 
        con.volume = 'VOLUME_XZX'
134
 
    else:
135
 
        con.volume = 'NO_VOLUME'
136
 
 
137
 
    # Bone 2
138
 
    con = pb[bone2].constraints.new('DAMPED_TRACK')
139
 
    con.target = obj
140
 
    con.subtarget = mid_bone
141
 
 
142
 
    con = pb[bone2].constraints.new('STRETCH_TO')
143
 
    con.target = obj
144
 
    con.subtarget = mid_bone
145
 
    con.original_length = bb[bone2].length
146
 
    if preserve_volume:
147
 
        con.volume = 'VOLUME_XZX'
148
 
    else:
149
 
        con.volume = 'NO_VOLUME'
150
 
 
151
 
    return tuple()
152