Welcome to mirror list, hosted at ThFree Co, Russian Federation.

copy_chain.py « basic « rigs « rigify - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3dbf79d43c645047e8d5625fc174925ecdc9a320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# SPDX-License-Identifier: GPL-2.0-or-later

import bpy

from ..chain_rigs import SimpleChainRig
from ...base_rig import stage


class Rig(SimpleChainRig):
    """ A "copy_chain" rig.  All it does is duplicate the original bone chain
        and constrain it.
        This is a control and deformation rig.
    """

    make_controls: bool
    make_deforms: bool

    def initialize(self):
        super().initialize()

        """ Gather and validate data about the rig.
        """
        self.make_controls = self.params.make_controls
        self.make_deforms = self.params.make_deforms

    ##############################
    # Control chain

    @stage.generate_bones
    def make_control_chain(self):
        if self.make_controls:
            super().make_control_chain()

    @stage.parent_bones
    def parent_control_chain(self):
        if self.make_controls:
            super().parent_control_chain()

    @stage.configure_bones
    def configure_control_chain(self):
        if self.make_controls:
            super().configure_control_chain()

    @stage.generate_widgets
    def make_control_widgets(self):
        if self.make_controls:
            super().make_control_widgets()

    ##############################
    # ORG chain

    @stage.rig_bones
    def rig_org_chain(self):
        if self.make_controls:
            super().rig_org_chain()

    ##############################
    # Deform chain

    @stage.generate_bones
    def make_deform_chain(self):
        if self.make_deforms:
            super().make_deform_chain()

    @stage.parent_bones
    def parent_deform_chain(self):
        if self.make_deforms:
            super().parent_deform_chain()

    @stage.rig_bones
    def rig_deform_chain(self):
        if self.make_deforms:
            super().rig_deform_chain()

    ##############################
    # Parameter UI

    @classmethod
    def add_parameters(cls, params):
        """ Add the parameters of this rig type to the
            RigifyParameters PropertyGroup
        """
        params.make_controls = bpy.props.BoolProperty(
            name="Controls", default=True, description="Create control bones for the copy")
        params.make_deforms = bpy.props.BoolProperty(
            name="Deform", default=True, description="Create deform bones for the copy")

    @classmethod
    def parameters_ui(cls, layout, params):
        """ Create the ui for the rig parameters.
        """
        r = layout.row()
        r.prop(params, "make_controls")
        r = layout.row()
        r.prop(params, "make_deforms")


def create_sample(obj):
    """ Create a sample metarig for this rig type.
    """
    # generated by rigify.utils.write_metarig
    bpy.ops.object.mode_set(mode='EDIT')
    arm = obj.data

    bones = {}

    bone = arm.edit_bones.new('bone.01')
    bone.head[:] = 0.0000, 0.0000, 0.0000
    bone.tail[:] = 0.0000, 0.0000, 0.3333
    bone.roll = 0.0000
    bone.use_connect = False
    bones['bone.01'] = bone.name
    bone = arm.edit_bones.new('bone.02')
    bone.head[:] = 0.0000, 0.0000, 0.3333
    bone.tail[:] = 0.0000, 0.0000, 0.6667
    bone.roll = 3.1416
    bone.use_connect = True
    bone.parent = arm.edit_bones[bones['bone.01']]
    bones['bone.02'] = bone.name
    bone = arm.edit_bones.new('bone.03')
    bone.head[:] = 0.0000, 0.0000, 0.6667
    bone.tail[:] = 0.0000, 0.0000, 1.0000
    bone.roll = 3.1416
    bone.use_connect = True
    bone.parent = arm.edit_bones[bones['bone.02']]
    bones['bone.03'] = bone.name

    bpy.ops.object.mode_set(mode='OBJECT')
    pbone = obj.pose.bones[bones['bone.01']]
    pbone.rigify_type = 'basic.copy_chain'
    pbone.lock_location = (False, False, False)
    pbone.lock_rotation = (False, False, False)
    pbone.lock_rotation_w = False
    pbone.lock_scale = (False, False, False)
    pbone.rotation_mode = 'QUATERNION'
    pbone = obj.pose.bones[bones['bone.02']]
    pbone.rigify_type = ''
    pbone.lock_location = (False, False, False)
    pbone.lock_rotation = (False, False, False)
    pbone.lock_rotation_w = False
    pbone.lock_scale = (False, False, False)
    pbone.rotation_mode = 'QUATERNION'
    pbone = obj.pose.bones[bones['bone.03']]
    pbone.rigify_type = ''
    pbone.lock_location = (False, False, False)
    pbone.lock_rotation = (False, False, False)
    pbone.lock_rotation_w = False
    pbone.lock_scale = (False, False, False)
    pbone.rotation_mode = 'QUATERNION'

    bpy.ops.object.mode_set(mode='EDIT')
    for bone in arm.edit_bones:
        bone.select = False
        bone.select_head = False
        bone.select_tail = False
    for b in bones:
        bone = arm.edit_bones[bones[b]]
        bone.select = True
        bone.select_head = True
        bone.select_tail = True
        arm.edit_bones.active = bone

    return bones