-
Notifications
You must be signed in to change notification settings - Fork 16
/
func_picker.py
248 lines (178 loc) · 6.85 KB
/
func_picker.py
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import bpy
#from. insert_keyframe import insert_keyframe
from. snapping_utils import *
from .utils import get_IK_bones
try :
from rigutils.driver_utils import split_path
from rigutils.insert_keyframe import insert_keyframe
from rigutils.snap_ik_fk import snap_ik_fk
from rigutils.utils import find_mirror
except :
print('You need to install the rigutils module in your blender modules path')
def hide_layers(args) :
""" """
ob = bpy.context.object
layers=[]
for bone in [b for b in ob.pose.bones if b.bone.select] :
for i,l in enumerate(bone.bone.layers) :
if l and i not in layers :
layers.append(i)
for i in layers :
ob.data.layers[i] = not ob.data.layers[i]
def boolean(args) :
""" data_path, keyable """
ob = bpy.context.object
data_path = args['data_path']
keyable = args['keyable']
#bone,prop = split_path(data_path)
try :
value = ob.path_resolve(data_path)
#setattr(ob.pose.bones.get(bone),'["%s"]'%prop,not value)
try :
exec("ob.%s = %s"%(data_path,not value))
except :
exec("ob%s= %s"%(data_path,not value))
if keyable and bpy.context.scene.tool_settings.use_keyframe_insert_auto :
if not ob.animation_data:
ob.animation_data_create()
ob.keyframe_insert(data_path = data_path ,group = bone)
except ValueError :
print("Property don't exist")
def select_layer(args) :
ob = bpy.context.object
layers =[]
for bone in [b for b in ob.pose.bones if b.bone.select] :
bone_layers = [i for i,l in enumerate(bone.bone.layers) if l]
for l in bone_layers :
if l not in layers :
layers.append(l)
for bone in ob.pose.bones :
bone_layers = [i for i,l in enumerate(bone.bone.layers) if l]
if len(set(bone_layers).intersection(layers)) :
bone.bone.select = True
def hide_bones(args) :
ob = bpy.context.object
selected_bone = [b for b in ob.pose.bones if b.bone.select]
hide = [b.bone.hide for b in selected_bone if not b.bone.hide]
visibility = True if len(hide) else False
for bone in selected_bone :
bone.bone.hide = visibility
def select_all(args) :
ob = bpy.context.object
shapes = ob.data.UI['shapes']
bones = [s['bone'] for s in shapes if s['shape_type']=='BONE']
for bone_name in bones :
bone = ob.pose.bones.get(bone_name)
if bone :
bone.bone.select = True
def select_bones(args) :
"""bones (name list)"""
ob = bpy.context.object
pBones = ob.pose.bones
bones_name =args['bones']
event = args['event']
if not event.shift :
for bone in bpy.context.object.pose.bones:
bone.bone.select = False
bones = [pBones.get(b) for b in bones_name]
select = False
for bone in bones :
if bone.bone.select == False :
select =True
break
for bone in bones :
bone.bone.select = select
ob.data.bones.active = bones[-1].bone
def keyframe_bones(args) :
print(args)
event=args['event']
bones=[]
for bone in bpy.context.object.pose.bones :
if not bone.name.startswith(('DEF','ORG','MCH')) and not bone.get('_unkeyable_') ==1 :
if event.shift :
bones.append(bone)
elif not event.shift and bone.bone.select :
bones.append(bone)
for bone in bones :
insert_keyframe(bone)
def reset_bones(args) :
event=args['event']
avoid_value =args['avoid_value']
ob = bpy.context.object
bones=[]
for bone in bpy.context.object.pose.bones :
if not bone.name.startswith(('DEF','ORG','MCH')) and not bone.get('_unkeyable_') ==1 :
if event.shift :
bones.append(bone)
elif not event.shift and bone.bone.select :
bones.append(bone)
for bone in bones :
if bone.rotation_mode =='QUATERNION':
bone.rotation_quaternion = 1,0,0,0
if bone.rotation_mode == 'AXIS_ANGLE':
bone.rotation_axis_angle = 0,0,1,0
else :
bone.rotation_euler = 0,0,0
bone.location = 0,0,0
bone.scale = 1,1,1
for key,value in bone.items() :
if key not in avoid_value and type(value) in (int,float):
if ob.data.get("DefaultValues") and ob.data.DefaultValues['bones'].get(bone.name) :
if key in ob.data.DefaultValues['bones'][bone.name] :
bone[key] = ob.data.DefaultValues['bones'][bone.name][key]
else :
if type(value)== int :
bone[key]=0
else :
bone[key]=0.0
else :
if type(value)== int :
bone[key]=0
else :
bone[key]=0.0
if bpy.context.scene.tool_settings.use_keyframe_insert_auto :
insert_keyframe(bone)
def flip_bones(args) :
event=args['event']
ob = bpy.context.object
arm = bpy.context.object.pose.bones
selected_bones = [bone for bone in ob.pose.bones if bone.bone.select==True ]
mirrorActive = None
for bone in selected_bones :
boneName = bone.name
mirrorBoneName= find_mirror(boneName)
mirrorBone = ob.pose.bones.get(mirrorBoneName) if mirrorBoneName else None
if bpy.context.active_pose_bone == bone :
mirrorActive = mirrorBone
#print(mirrorBone)
if not event.shift and mirrorBone:
bone.bone.select = False
if mirrorBone :
mirrorBone.bone.select = True
if mirrorActive :
ob.data.bones.active = mirrorActive.bone
def snap_ikfk(args):
""" way, chain_index """
way =args['way']
chain_index = args['chain_index']
#auto_switch = self.auto_switch
ob = bpy.context.object
armature = ob.data
SnappingChain = armature.get('SnappingChain')
poseBone = ob.pose.bones
dataBone = ob.data.bones
IKFK_chain = SnappingChain['IKFK_bones'][chain_index]
switch_prop = IKFK_chain['switch_prop']
FK_root = poseBone.get(IKFK_chain['FK_root'])
FK_mid = [poseBone.get(b['name']) for b in IKFK_chain['FK_mid']]
FK_tip = poseBone.get(IKFK_chain['FK_tip'])
IK_last = poseBone.get(IKFK_chain['IK_last'])
IK_tip = poseBone.get(IKFK_chain['IK_tip'])
IK_pole = poseBone.get(IKFK_chain['IK_pole'])
invert = IKFK_chain['invert_switch']
ik_fk_layer = (IKFK_chain['FK_layer'],IKFK_chain['IK_layer'])
for lock in ('lock_ik_x','lock_ik_y','lock_ik_z') :
if getattr(IK_last,lock) :
full_snapping = False
break
snap_ik_fk(ob,way,switch_prop,FK_root,FK_tip,IK_last,IK_tip,IK_pole,FK_mid,full_snapping,invert,ik_fk_layer,auto_switch=True)