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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# SPDX-License-Identifier: GPL-2.0-or-later
# <pep8 compliant>
import bpy
import math
from itertools import count
from ...utils.naming import make_derived_name
from ...utils.bones import flip_bone, copy_bone_position
from ...utils.layers import ControlLayersOption
from ...utils.misc import map_list
from ...base_rig import stage
from ..chain_rigs import TweakChainRig
from ..widgets import create_jaw_widget
class Rig(TweakChainRig):
"""Basic tongue from the original PitchiPoy face rig."""
min_chain_length = 3
def initialize(self):
super().initialize()
self.bbone_segments = self.params.bbones
####################################################
# BONES
#
# ctrl:
# master:
# Master control.
# mch:
# follow[]:
# Partial follow master bones.
#
####################################################
####################################################
# Control chain
@stage.generate_bones
def make_control_chain(self):
org = self.bones.org[0]
name = self.copy_bone(org, make_derived_name(org, 'ctrl'), parent=True)
flip_bone(self.obj, name)
self.bones.ctrl.master = name
@stage.parent_bones
def parent_control_chain(self):
pass
@stage.configure_bones
def configure_control_chain(self):
master = self.bones.ctrl.master
self.copy_bone_properties(self.bones.org[0], master)
ControlLayersOption.SKIN_PRIMARY.assign(self.params, self.obj, [master])
@stage.generate_widgets
def make_control_widgets(self):
create_jaw_widget(self.obj, self.bones.ctrl.master)
####################################################
# Mechanism chain
@stage.generate_bones
def make_follow_chain(self):
self.bones.mch.follow = map_list(self.make_mch_follow_bone, count(1), self.bones.org[1:])
def make_mch_follow_bone(self, i, org):
name = self.copy_bone(org, make_derived_name(org, 'mch'))
copy_bone_position(self.obj, self.base_bone, name)
flip_bone(self.obj, name)
return name
@stage.parent_bones
def parent_follow_chain(self):
for mch in self.bones.mch.follow:
self.set_bone_parent(mch, self.rig_parent_bone)
@stage.rig_bones
def rig_follow_chain(self):
master = self.bones.ctrl.master
num_orgs = len(self.bones.org)
for i, mch in enumerate(self.bones.mch.follow):
self.make_constraint(mch, 'COPY_TRANSFORMS', master, influence=1-(1+i)/num_orgs)
####################################################
# Tweak chain
@stage.parent_bones
def parent_tweak_chain(self):
ctrl = self.bones.ctrl
parents = [ctrl.master, *self.bones.mch.follow, self.rig_parent_bone]
for tweak, main in zip(ctrl.tweak, parents):
self.set_bone_parent(tweak, main)
####################################################
# SETTINGS
@classmethod
def add_parameters(self, params):
params.bbones = bpy.props.IntProperty(
name='B-Bone Segments',
default=10,
min=1,
description='Number of B-Bone segments'
)
ControlLayersOption.SKIN_PRIMARY.add_parameters(params)
@classmethod
def parameters_ui(self, layout, params):
layout.prop(params, 'bbones')
ControlLayersOption.SKIN_PRIMARY.parameters_ui(layout, params)
def create_sample(obj):
# generated by rigify.utils.write_metarig
bpy.ops.object.mode_set(mode='EDIT')
arm = obj.data
bones = {}
bone = arm.edit_bones.new('tongue')
bone.head = 0.0000, 0.0000, 0.0000
bone.tail = 0.0000, 0.0161, 0.0074
bone.roll = 0.0000
bone.use_connect = False
bones['tongue'] = bone.name
bone = arm.edit_bones.new('tongue.001')
bone.head = 0.0000, 0.0161, 0.0074
bone.tail = 0.0000, 0.0375, 0.0091
bone.roll = 0.0000
bone.use_connect = True
bone.parent = arm.edit_bones[bones['tongue']]
bones['tongue.001'] = bone.name
bone = arm.edit_bones.new('tongue.002')
bone.head = 0.0000, 0.0375, 0.0091
bone.tail = 0.0000, 0.0605, -0.0029
bone.roll = 0.0000
bone.use_connect = True
bone.parent = arm.edit_bones[bones['tongue.001']]
bones['tongue.002'] = bone.name
bpy.ops.object.mode_set(mode='OBJECT')
pbone = obj.pose.bones[bones['tongue']]
pbone.rigify_type = 'face.basic_tongue'
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['tongue.001']]
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['tongue.002']]
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
bone.bbone_x = bone.bbone_z = bone.length * 0.05
arm.edit_bones.active = bone
return bones
|