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

anchor.py « skin « rigs « rigify - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0392761f74a70c7bbb466d7394863b083696972c (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
# ====================== BEGIN GPL LICENSE BLOCK ======================
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ======================= END GPL LICENSE BLOCK ========================

# <pep8 compliant>

import bpy

from ...utils.naming import make_derived_name
from ...utils.widgets import layout_widget_dropdown, create_registered_widget
from ...utils.mechanism import move_all_constraints

from ...base_rig import stage

from .skin_nodes import ControlBoneNode, ControlNodeIcon, ControlNodeEnd
from .skin_rigs import BaseSkinChainRigWithRotationOption

from ..basic.raw_copy import RelinkConstraintsMixin


class Rig(BaseSkinChainRigWithRotationOption, RelinkConstraintsMixin):
    """Custom skin control node."""

    chain_priority = 20

    def find_org_bones(self, bone):
        return bone.name

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

        self.make_deform = self.params.make_extra_deform

    ####################################################
    # CONTROL NODES

    @stage.initialize
    def init_control_nodes(self):
        org = self.bones.org
        name = make_derived_name(org, 'ctrl')

        self.control_node = node = ControlBoneNode(
            self, org, name, icon=ControlNodeIcon.CUSTOM, chain_end=ControlNodeEnd.START)

        node.hide_control = self.params.skin_anchor_hide

    def make_control_node_widget(self, node):
        create_registered_widget(self.obj, node.control_bone,
                                 self.params.pivot_master_widget_type or 'cube')

    def extend_control_node_rig(self, node):
        if node.rig == self:
            org = self.bones.org

            self.copy_bone_properties(org, node.control_bone)

            self.relink_bone_constraints(org)

            move_all_constraints(self.obj, org, node.control_bone)

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

    @stage.parent_bones
    def parent_org_chain(self):
        self.set_bone_parent(self.bones.org, self.control_node.control_bone)

    ##############################
    # Deform bone

    @stage.generate_bones
    def make_deform_bone(self):
        if self.make_deform:
            self.bones.deform = self.copy_bone(
                self.bones.org, make_derived_name(self.bones.org, 'def'))

    @stage.parent_bones
    def parent_deform_chain(self):
        if self.make_deform:
            self.set_bone_parent(self.bones.deform, self.bones.org)

    ####################################################
    # SETTINGS

    @classmethod
    def add_parameters(self, params):
        params.make_extra_deform = bpy.props.BoolProperty(
            name="Extra Deform",
            default=False,
            description="Create an optional deform bone"
        )

        params.skin_anchor_hide = bpy.props.BoolProperty(
            name='Suppress Control',
            default=False,
            description='Make the control bone a mechanism bone invisible to the user and only affected by constraints'
        )

        params.pivot_master_widget_type = bpy.props.StringProperty(
            name="Widget Type",
            default='cube',
            description="Choose the type of the widget to create"
        )

        self.add_relink_constraints_params(params)

        super().add_parameters(params)

    @classmethod
    def parameters_ui(self, layout, params):
        col = layout.column()
        col.prop(params, "make_extra_deform", text='Generate Deform Bone')
        col.prop(params, "skin_anchor_hide")

        row = layout.row()
        row.active = not params.skin_anchor_hide
        layout_widget_dropdown(row, params, "pivot_master_widget_type")

        layout.prop(params, "relink_constraints")

        layout.label(text="All constraints are moved to the control bone.", icon='INFO')

        super().parameters_ui(layout, params)


def create_sample(obj):
    from rigify.rigs.basic.super_copy import create_sample as inner
    obj.pose.bones[inner(obj)["Bone"]].rigify_type = 'skin.anchor'