~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/modules/rigify/copy.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_utils import bone_class_instance, copy_bone_simple
23
 
 
24
 
METARIG_NAMES = ("cpy",)
25
 
 
26
 
 
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
31
 
    arm = obj.data
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
35
 
    bone.roll = 0.0000
36
 
    bone.connected = False
37
 
 
38
 
    bpy.ops.object.mode_set(mode='OBJECT')
39
 
    pbone = obj.pose.bones['Bone']
40
 
    pbone['type'] = 'copy'
41
 
 
42
 
 
43
 
def metarig_definition(obj, orig_bone_name):
44
 
    return (orig_bone_name,)
45
 
 
46
 
 
47
 
def deform(obj, definitions, base_names, options):
48
 
    bpy.ops.object.mode_set(mode='EDIT')
49
 
 
50
 
    # Create deform bone.
51
 
    bone = copy_bone_simple(obj.data, definitions[0], "DEF-%s" % base_names[definitions[0]], parent=True)
52
 
 
53
 
    # Store name before leaving edit mode
54
 
    bone_name = bone.name
55
 
 
56
 
    # Leave edit mode
57
 
    bpy.ops.object.mode_set(mode='OBJECT')
58
 
 
59
 
    # Get the pose bone
60
 
    bone = obj.pose.bones[bone_name]
61
 
 
62
 
    # Constrain to the original bone
63
 
    con = bone.constraints.new('COPY_TRANSFORMS')
64
 
    con.name = "copy_loc"
65
 
    con.target = obj
66
 
    con.subtarget = definitions[0]
67
 
 
68
 
    return (bone_name,)
69
 
 
70
 
 
71
 
def control(obj, definitions, base_names, options):
72
 
    bpy.ops.object.mode_set(mode='EDIT')
73
 
 
74
 
    arm = obj.data
75
 
    mt = bone_class_instance(obj, METARIG_NAMES)
76
 
    mt.cpy = definitions[0]
77
 
    mt.update()
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
81
 
 
82
 
    bpy.ops.object.mode_set(mode='OBJECT')
83
 
 
84
 
    cp.update()
85
 
    mt.update()
86
 
 
87
 
    con = mt.cpy_p.constraints.new('COPY_TRANSFORMS')
88
 
    con.target = obj
89
 
    con.subtarget = cp.cpy
90
 
 
91
 
 
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)
99
 
 
100
 
    # Layers
101
 
    cp.cpy_b.layer = list(mt.cpy_b.layer)
102
 
 
103
 
    return (mt.cpy,)
104
 
 
105
 
 
106
 
def main(obj, bone_definition, base_names, options):
107
 
    # Create control bone
108
 
    cpy = control(obj, bone_definition, base_names, options)[0]
109
 
    # Create deform bone
110
 
    deform(obj, bone_definition, base_names, options)
111
 
 
112
 
    return (cpy,)