change python scripts so modules which register with blender have a register() functi...
[blender.git] / release / scripts / op / add_armature_human.py
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-80 compliant>
20 import bpy
21 import Mathutils
22 from math import cos, sin, pi
23
24 # could this be stored elsewhere?
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('pelvis')
33     bone.head[:] = -0.0000, -0.0145, 1.1263
34     bone.tail[:] = -0.0000, -0.0145, 0.9563
35     bone.roll = 3.1416
36     bone.connected = False
37     bone = arm.edit_bones.new('torso')
38     bone.head[:] = -0.0000, -0.0145, 1.1263
39     bone.tail[:] = -0.0000, -0.0145, 1.2863
40     bone.roll = 3.1416
41     bone.connected = False
42     bone.parent = arm.edit_bones['pelvis']
43     bone = arm.edit_bones.new('spine.01')
44     bone.head[:] = 0.0000, 0.0394, 0.9688
45     bone.tail[:] = -0.0000, -0.0145, 1.1263
46     bone.roll = 0.0000
47     bone.connected = False
48     bone.parent = arm.edit_bones['torso']
49     bone = arm.edit_bones.new('spine.02')
50     bone.head[:] = -0.0000, -0.0145, 1.1263
51     bone.tail[:] = -0.0000, -0.0213, 1.2884
52     bone.roll = -0.0000
53     bone.connected = True
54     bone.parent = arm.edit_bones['spine.01']
55     bone = arm.edit_bones.new('thigh.L')
56     bone.head[:] = 0.0933, -0.0421, 1.0434
57     bone.tail[:] = 0.0933, -0.0516, 0.5848
58     bone.roll = 0.0000
59     bone.connected = False
60     bone.parent = arm.edit_bones['spine.01']
61     bone = arm.edit_bones.new('thigh.R')
62     bone.head[:] = -0.0933, -0.0421, 1.0434
63     bone.tail[:] = -0.0933, -0.0516, 0.5848
64     bone.roll = -0.0000
65     bone.connected = False
66     bone.parent = arm.edit_bones['spine.01']
67     bone = arm.edit_bones.new('spine.03')
68     bone.head[:] = -0.0000, -0.0213, 1.2884
69     bone.tail[:] = -0.0000, 0.0160, 1.3705
70     bone.roll = -0.0000
71     bone.connected = True
72     bone.parent = arm.edit_bones['spine.02']
73     bone = arm.edit_bones.new('shin.L')
74     bone.head[:] = 0.0933, -0.0516, 0.5848
75     bone.tail[:] = 0.0915, 0.0100, 0.1374
76     bone.roll = 0.0034
77     bone.connected = True
78     bone.parent = arm.edit_bones['thigh.L']
79     bone = arm.edit_bones.new('shin.R')
80     bone.head[:] = -0.0933, -0.0516, 0.5848
81     bone.tail[:] = -0.0915, 0.0100, 0.1374
82     bone.roll = -0.0034
83     bone.connected = True
84     bone.parent = arm.edit_bones['thigh.R']
85     bone = arm.edit_bones.new('spine.04')
86     bone.head[:] = -0.0000, 0.0160, 1.3705
87     bone.tail[:] = -0.0000, 0.0590, 1.4497
88     bone.roll = -0.0000
89     bone.connected = True
90     bone.parent = arm.edit_bones['spine.03']
91     bone = arm.edit_bones.new('foot.L')
92     bone.head[:] = 0.0915, 0.0100, 0.1374
93     bone.tail[:] = 0.1033, -0.0968, 0.0510
94     bone.roll = 2.8964
95     bone.connected = True
96     bone.parent = arm.edit_bones['shin.L']
97     bone = arm.edit_bones.new('foot.R')
98     bone.head[:] = -0.0915, 0.0100, 0.1374
99     bone.tail[:] = -0.1033, -0.0968, 0.0510
100     bone.roll = -2.8793
101     bone.connected = True
102     bone.parent = arm.edit_bones['shin.R']
103     bone = arm.edit_bones.new('neck_base')
104     bone.head[:] = -0.0000, 0.0590, 1.4497
105     bone.tail[:] = -0.0000, 0.0401, 1.5389
106     bone.roll = -0.0000
107     bone.connected = True
108     bone.parent = arm.edit_bones['spine.04']
109     bone = arm.edit_bones.new('toe.L')
110     bone.head[:] = 0.1033, -0.0968, 0.0510
111     bone.tail[:] = 0.1136, -0.1848, 0.0510
112     bone.roll = 0.0001
113     bone.connected = True
114     bone.parent = arm.edit_bones['foot.L']
115     bone = arm.edit_bones.new('heel.L')
116     bone.head[:] = 0.0809, 0.0969, -0.0000
117     bone.tail[:] = 0.1020, -0.0846, -0.0000
118     bone.roll = -0.0001
119     bone.connected = False
120     bone.parent = arm.edit_bones['foot.L']
121     bone = arm.edit_bones.new('toe.R')
122     bone.head[:] = -0.1033, -0.0968, 0.0510
123     bone.tail[:] = -0.1136, -0.1848, 0.0510
124     bone.roll = -0.0002
125     bone.connected = True
126     bone.parent = arm.edit_bones['foot.R']
127     bone = arm.edit_bones.new('heel.R')
128     bone.head[:] = -0.0809, 0.0969, -0.0000
129     bone.tail[:] = -0.1020, -0.0846, -0.0000
130     bone.roll = -0.0000
131     bone.connected = False
132     bone.parent = arm.edit_bones['foot.R']
133     bone = arm.edit_bones.new('head')
134     bone.head[:] = -0.0000, 0.0401, 1.5389
135     bone.tail[:] = -0.0000, 0.0401, 1.5979
136     bone.roll = 3.1416
137     bone.connected = True
138     bone.parent = arm.edit_bones['neck_base']
139     bone = arm.edit_bones.new('DLT-shoulder.L')
140     bone.head[:] = 0.0141, -0.0346, 1.4991
141     bone.tail[:] = 0.1226, 0.0054, 1.4991
142     bone.roll = 0.0005
143     bone.connected = False
144     bone.parent = arm.edit_bones['neck_base']
145     bone = arm.edit_bones.new('DLT-shoulder.R')
146     bone.head[:] = -0.0141, -0.0346, 1.4991
147     bone.tail[:] = -0.1226, 0.0054, 1.4991
148     bone.roll = -0.0005
149     bone.connected = False
150     bone.parent = arm.edit_bones['neck_base']
151     bone = arm.edit_bones.new('neck.01')
152     bone.head[:] = -0.0000, 0.0401, 1.5389
153     bone.tail[:] = -0.0000, 0.0176, 1.5916
154     bone.roll = 0.0000
155     bone.connected = False
156     bone.parent = arm.edit_bones['head']
157     bone = arm.edit_bones.new('shoulder.L')
158     bone.head[:] = 0.0141, -0.0346, 1.4991
159     bone.tail[:] = 0.1226, 0.0216, 1.5270
160     bone.roll = -0.1225
161     bone.connected = False
162     bone.parent = arm.edit_bones['DLT-shoulder.L']
163     bone = arm.edit_bones.new('shoulder.R')
164     bone.head[:] = -0.0141, -0.0346, 1.4991
165     bone.tail[:] = -0.1226, 0.0216, 1.5270
166     bone.roll = 0.0849
167     bone.connected = False
168     bone.parent = arm.edit_bones['DLT-shoulder.R']
169     bone = arm.edit_bones.new('neck.02')
170     bone.head[:] = -0.0000, 0.0176, 1.5916
171     bone.tail[:] = -0.0000, 0.0001, 1.6499
172     bone.roll = 0.0000
173     bone.connected = True
174     bone.parent = arm.edit_bones['neck.01']
175     bone = arm.edit_bones.new('DLT-upper_arm.L')
176     bone.head[:] = 0.1482, 0.0483, 1.4943
177     bone.tail[:] = 0.2586, 0.1057, 1.5124
178     bone.roll = 1.4969
179     bone.connected = False
180     bone.parent = arm.edit_bones['shoulder.L']
181     bone = arm.edit_bones.new('DLT-upper_arm.R')
182     bone.head[:] = -0.1482, 0.0483, 1.4943
183     bone.tail[:] = -0.2586, 0.1057, 1.5124
184     bone.roll = -1.4482
185     bone.connected = False
186     bone.parent = arm.edit_bones['shoulder.R']
187     bone = arm.edit_bones.new('neck.03')
188     bone.head[:] = -0.0000, 0.0001, 1.6499
189     bone.tail[:] = -0.0000, 0.0001, 1.8522
190     bone.roll = 0.0000
191     bone.connected = True
192     bone.parent = arm.edit_bones['neck.02']
193     bone = arm.edit_bones.new('upper_arm.L')
194     bone.head[:] = 0.1482, 0.0483, 1.4943
195     bone.tail[:] = 0.3929, 0.0522, 1.4801
196     bone.roll = 1.6281
197     bone.connected = False
198     bone.parent = arm.edit_bones['DLT-upper_arm.L']
199     bone = arm.edit_bones.new('upper_arm.R')
200     bone.head[:] = -0.1482, 0.0483, 1.4943
201     bone.tail[:] = -0.3929, 0.0522, 1.4801
202     bone.roll = -1.6281
203     bone.connected = False
204     bone.parent = arm.edit_bones['DLT-upper_arm.R']
205     bone = arm.edit_bones.new('forearm.L')
206     bone.head[:] = 0.3929, 0.0522, 1.4801
207     bone.tail[:] = 0.6198, 0.0364, 1.4906
208     bone.roll = 1.5240
209     bone.connected = True
210     bone.parent = arm.edit_bones['upper_arm.L']
211     bone = arm.edit_bones.new('forearm.R')
212     bone.head[:] = -0.3929, 0.0522, 1.4801
213     bone.tail[:] = -0.6198, 0.0364, 1.4906
214     bone.roll = -1.5219
215     bone.connected = True
216     bone.parent = arm.edit_bones['upper_arm.R']
217     bone = arm.edit_bones.new('hand.L')
218     bone.head[:] = 0.6198, 0.0364, 1.4906
219     bone.tail[:] = 0.6592, 0.0364, 1.4853
220     bone.roll = -3.0065
221     bone.connected = True
222     bone.parent = arm.edit_bones['forearm.L']
223     bone = arm.edit_bones.new('hand.R')
224     bone.head[:] = -0.6198, 0.0364, 1.4906
225     bone.tail[:] = -0.6592, 0.0364, 1.4853
226     bone.roll = 3.0065
227     bone.connected = True
228     bone.parent = arm.edit_bones['forearm.R']
229     bone = arm.edit_bones.new('palm.04.L')
230     bone.head[:] = 0.6514, 0.0658, 1.4906
231     bone.tail[:] = 0.7287, 0.0810, 1.4747
232     bone.roll = -3.0715
233     bone.connected = False
234     bone.parent = arm.edit_bones['hand.L']
235     bone = arm.edit_bones.new('palm.03.L')
236     bone.head[:] = 0.6533, 0.0481, 1.4943
237     bone.tail[:] = 0.7386, 0.0553, 1.4781
238     bone.roll = -3.0290
239     bone.connected = False
240     bone.parent = arm.edit_bones['hand.L']
241     bone = arm.edit_bones.new('palm.02.L')
242     bone.head[:] = 0.6539, 0.0305, 1.4967
243     bone.tail[:] = 0.7420, 0.0250, 1.4835
244     bone.roll = -3.0669
245     bone.connected = False
246     bone.parent = arm.edit_bones['hand.L']
247     bone = arm.edit_bones.new('palm.01.L')
248     bone.head[:] = 0.6514, 0.0116, 1.4961
249     bone.tail[:] = 0.7361, -0.0074, 1.4823
250     bone.roll = -2.9422
251     bone.connected = False
252     bone.parent = arm.edit_bones['hand.L']
253     bone = arm.edit_bones.new('thumb.01.L')
254     bone.head[:] = 0.6380, -0.0005, 1.4848
255     bone.tail[:] = 0.6757, -0.0408, 1.4538
256     bone.roll = -0.7041
257     bone.connected = False
258     bone.parent = arm.edit_bones['hand.L']
259     bone = arm.edit_bones.new('palm.04.R')
260     bone.head[:] = -0.6514, 0.0658, 1.4906
261     bone.tail[:] = -0.7287, 0.0810, 1.4747
262     bone.roll = 3.0715
263     bone.connected = False
264     bone.parent = arm.edit_bones['hand.R']
265     bone = arm.edit_bones.new('palm.03.R')
266     bone.head[:] = -0.6533, 0.0481, 1.4943
267     bone.tail[:] = -0.7386, 0.0553, 1.4781
268     bone.roll = 3.0290
269     bone.connected = False
270     bone.parent = arm.edit_bones['hand.R']
271     bone = arm.edit_bones.new('palm.02.R')
272     bone.head[:] = -0.6539, 0.0305, 1.4967
273     bone.tail[:] = -0.7420, 0.0250, 1.4835
274     bone.roll = 3.0669
275     bone.connected = False
276     bone.parent = arm.edit_bones['hand.R']
277     bone = arm.edit_bones.new('thumb.01.R')
278     bone.head[:] = -0.6380, -0.0005, 1.4848
279     bone.tail[:] = -0.6757, -0.0408, 1.4538
280     bone.roll = 0.7041
281     bone.connected = False
282     bone.parent = arm.edit_bones['hand.R']
283     bone = arm.edit_bones.new('palm.01.R')
284     bone.head[:] = -0.6514, 0.0116, 1.4961
285     bone.tail[:] = -0.7361, -0.0074, 1.4823
286     bone.roll = 2.9332
287     bone.connected = False
288     bone.parent = arm.edit_bones['hand.R']
289     bone = arm.edit_bones.new('finger_pinky.01.L')
290     bone.head[:] = 0.7287, 0.0810, 1.4747
291     bone.tail[:] = 0.7698, 0.0947, 1.4635
292     bone.roll = -3.0949
293     bone.connected = True
294     bone.parent = arm.edit_bones['palm.04.L']
295     bone = arm.edit_bones.new('finger_ring.01.L')
296     bone.head[:] = 0.7386, 0.0553, 1.4781
297     bone.tail[:] = 0.7890, 0.0615, 1.4667
298     bone.roll = -3.0081
299     bone.connected = True
300     bone.parent = arm.edit_bones['palm.03.L']
301     bone = arm.edit_bones.new('finger_middle.01.L')
302     bone.head[:] = 0.7420, 0.0250, 1.4835
303     bone.tail[:] = 0.7975, 0.0221, 1.4712
304     bone.roll = -2.9982
305     bone.connected = True
306     bone.parent = arm.edit_bones['palm.02.L']
307     bone = arm.edit_bones.new('finger_index.01.L')
308     bone.head[:] = 0.7361, -0.0074, 1.4823
309     bone.tail[:] = 0.7843, -0.0204, 1.4718
310     bone.roll = -3.0021
311     bone.connected = True
312     bone.parent = arm.edit_bones['palm.01.L']
313     bone = arm.edit_bones.new('thumb.02.L')
314     bone.head[:] = 0.6757, -0.0408, 1.4538
315     bone.tail[:] = 0.6958, -0.0568, 1.4376
316     bone.roll = -0.6963
317     bone.connected = True
318     bone.parent = arm.edit_bones['thumb.01.L']
319     bone = arm.edit_bones.new('finger_pinky.01.R')
320     bone.head[:] = -0.7287, 0.0810, 1.4747
321     bone.tail[:] = -0.7698, 0.0947, 1.4635
322     bone.roll = 3.0949
323     bone.connected = True
324     bone.parent = arm.edit_bones['palm.04.R']
325     bone = arm.edit_bones.new('finger_ring.01.R')
326     bone.head[:] = -0.7386, 0.0553, 1.4781
327     bone.tail[:] = -0.7890, 0.0615, 1.4667
328     bone.roll = 2.9892
329     bone.connected = True
330     bone.parent = arm.edit_bones['palm.03.R']
331     bone = arm.edit_bones.new('finger_middle.01.R')
332     bone.head[:] = -0.7420, 0.0250, 1.4835
333     bone.tail[:] = -0.7975, 0.0221, 1.4712
334     bone.roll = 2.9816
335     bone.connected = True
336     bone.parent = arm.edit_bones['palm.02.R']
337     bone = arm.edit_bones.new('thumb.02.R')
338     bone.head[:] = -0.6757, -0.0408, 1.4538
339     bone.tail[:] = -0.6958, -0.0568, 1.4376
340     bone.roll = 0.6963
341     bone.connected = True
342     bone.parent = arm.edit_bones['thumb.01.R']
343     bone = arm.edit_bones.new('finger_index.01.R')
344     bone.head[:] = -0.7361, -0.0074, 1.4823
345     bone.tail[:] = -0.7843, -0.0204, 1.4718
346     bone.roll = 2.9498
347     bone.connected = True
348     bone.parent = arm.edit_bones['palm.01.R']
349     bone = arm.edit_bones.new('finger_pinky.02.L')
350     bone.head[:] = 0.7698, 0.0947, 1.4635
351     bone.tail[:] = 0.7910, 0.1018, 1.4577
352     bone.roll = -3.0949
353     bone.connected = True
354     bone.parent = arm.edit_bones['finger_pinky.01.L']
355     bone = arm.edit_bones.new('finger_ring.02.L')
356     bone.head[:] = 0.7890, 0.0615, 1.4667
357     bone.tail[:] = 0.8177, 0.0650, 1.4600
358     bone.roll = -3.0006
359     bone.connected = True
360     bone.parent = arm.edit_bones['finger_ring.01.L']
361     bone = arm.edit_bones.new('finger_middle.02.L')
362     bone.head[:] = 0.7975, 0.0221, 1.4712
363     bone.tail[:] = 0.8289, 0.0206, 1.4643
364     bone.roll = -2.9995
365     bone.connected = True
366     bone.parent = arm.edit_bones['finger_middle.01.L']
367     bone = arm.edit_bones.new('finger_index.02.L')
368     bone.head[:] = 0.7843, -0.0204, 1.4718
369     bone.tail[:] = 0.8117, -0.0275, 1.4660
370     bone.roll = -3.0064
371     bone.connected = True
372     bone.parent = arm.edit_bones['finger_index.01.L']
373     bone = arm.edit_bones.new('thumb.03.L')
374     bone.head[:] = 0.6958, -0.0568, 1.4376
375     bone.tail[:] = 0.7196, -0.0671, 1.4210
376     bone.roll = -0.8072
377     bone.connected = True
378     bone.parent = arm.edit_bones['thumb.02.L']
379     bone = arm.edit_bones.new('finger_pinky.02.R')
380     bone.head[:] = -0.7698, 0.0947, 1.4635
381     bone.tail[:] = -0.7910, 0.1018, 1.4577
382     bone.roll = 3.0949
383     bone.connected = True
384     bone.parent = arm.edit_bones['finger_pinky.01.R']
385     bone = arm.edit_bones.new('finger_ring.02.R')
386     bone.head[:] = -0.7890, 0.0615, 1.4667
387     bone.tail[:] = -0.8177, 0.0650, 1.4600
388     bone.roll = 3.0341
389     bone.connected = True
390     bone.parent = arm.edit_bones['finger_ring.01.R']
391     bone = arm.edit_bones.new('finger_middle.02.R')
392     bone.head[:] = -0.7975, 0.0221, 1.4712
393     bone.tail[:] = -0.8289, 0.0206, 1.4643
394     bone.roll = 3.0291
395     bone.connected = True
396     bone.parent = arm.edit_bones['finger_middle.01.R']
397     bone = arm.edit_bones.new('thumb.03.R')
398     bone.head[:] = -0.6958, -0.0568, 1.4376
399     bone.tail[:] = -0.7196, -0.0671, 1.4210
400     bone.roll = 0.8072
401     bone.connected = True
402     bone.parent = arm.edit_bones['thumb.02.R']
403     bone = arm.edit_bones.new('finger_index.02.R')
404     bone.head[:] = -0.7843, -0.0204, 1.4718
405     bone.tail[:] = -0.8117, -0.0275, 1.4660
406     bone.roll = 3.0705
407     bone.connected = True
408     bone.parent = arm.edit_bones['finger_index.01.R']
409     bone = arm.edit_bones.new('finger_pinky.03.L')
410     bone.head[:] = 0.7910, 0.1018, 1.4577
411     bone.tail[:] = 0.8109, 0.1085, 1.4523
412     bone.roll = -3.0949
413     bone.connected = True
414     bone.parent = arm.edit_bones['finger_pinky.02.L']
415     bone = arm.edit_bones.new('finger_ring.03.L')
416     bone.head[:] = 0.8177, 0.0650, 1.4600
417     bone.tail[:] = 0.8396, 0.0677, 1.4544
418     bone.roll = -2.9819
419     bone.connected = True
420     bone.parent = arm.edit_bones['finger_ring.02.L']
421     bone = arm.edit_bones.new('finger_middle.03.L')
422     bone.head[:] = 0.8289, 0.0206, 1.4643
423     bone.tail[:] = 0.8534, 0.0193, 1.4589
424     bone.roll = -3.0004
425     bone.connected = True
426     bone.parent = arm.edit_bones['finger_middle.02.L']
427     bone = arm.edit_bones.new('finger_index.03.L')
428     bone.head[:] = 0.8117, -0.0275, 1.4660
429     bone.tail[:] = 0.8331, -0.0333, 1.4615
430     bone.roll = -3.0103
431     bone.connected = True
432     bone.parent = arm.edit_bones['finger_index.02.L']
433     bone = arm.edit_bones.new('finger_pinky.03.R')
434     bone.head[:] = -0.7910, 0.1018, 1.4577
435     bone.tail[:] = -0.8109, 0.1085, 1.4523
436     bone.roll = 3.0949
437     bone.connected = True
438     bone.parent = arm.edit_bones['finger_pinky.02.R']
439     bone = arm.edit_bones.new('finger_ring.03.R')
440     bone.head[:] = -0.8177, 0.0650, 1.4600
441     bone.tail[:] = -0.8396, 0.0677, 1.4544
442     bone.roll = 2.9819
443     bone.connected = True
444     bone.parent = arm.edit_bones['finger_ring.02.R']
445     bone = arm.edit_bones.new('finger_middle.03.R')
446     bone.head[:] = -0.8289, 0.0206, 1.4643
447     bone.tail[:] = -0.8534, 0.0193, 1.4589
448     bone.roll = 3.0004
449     bone.connected = True
450     bone.parent = arm.edit_bones['finger_middle.02.R']
451     bone = arm.edit_bones.new('finger_index.03.R')
452     bone.head[:] = -0.8117, -0.0275, 1.4660
453     bone.tail[:] = -0.8331, -0.0333, 1.4615
454     bone.roll = 2.9917
455     bone.connected = True
456     bone.parent = arm.edit_bones['finger_index.02.R']
457
458     bpy.ops.object.mode_set(mode='OBJECT')
459     pbone = obj.pose.bones['torso']
460     pbone['type'] = 'spine_pivot_flex'
461     pbone = obj.pose.bones['torso']
462     pbone['spine_pivot_flex.later_main'] = 1
463     pbone = obj.pose.bones['torso']
464     pbone['spine_pivot_flex.layer_extra'] = 2
465     pbone = obj.pose.bones['thigh.L']
466     pbone['type'] = 'leg_biped'
467     pbone = obj.pose.bones['thigh.L']
468     pbone['leg_biped_generic.layer_ik'] = 12
469     pbone = obj.pose.bones['thigh.L']
470     pbone['leg_biped_generic.layer_fk'] = 11
471     pbone = obj.pose.bones['thigh.R']
472     pbone['type'] = 'leg_biped'
473     pbone = obj.pose.bones['thigh.R']
474     pbone['leg_biped_generic.layer_ik'] = 14
475     pbone = obj.pose.bones['thigh.R']
476     pbone['leg_biped_generic.layer_fk'] = 13
477     pbone = obj.pose.bones['head']
478     pbone['type'] = 'neck_flex'
479     pbone = obj.pose.bones['head']
480     pbone['neck_flex.layer_extra'] = 4
481     pbone = obj.pose.bones['head']
482     pbone['neck_flex.layer_main'] = 3
483     pbone = obj.pose.bones['DLT-shoulder.L']
484     pbone['type'] = 'delta'
485     pbone = obj.pose.bones['DLT-shoulder.R']
486     pbone['type'] = 'delta'
487     pbone = obj.pose.bones['shoulder.L']
488     pbone['type'] = 'copy'
489     pbone = obj.pose.bones['shoulder.L']
490     pbone['copy.layer'] = 1
491     pbone = obj.pose.bones['shoulder.R']
492     pbone['type'] = 'copy'
493     pbone = obj.pose.bones['shoulder.R']
494     pbone['copy.layer'] = 1
495     pbone = obj.pose.bones['DLT-upper_arm.L']
496     pbone['type'] = 'delta'
497     pbone = obj.pose.bones['DLT-upper_arm.R']
498     pbone['type'] = 'delta'
499     pbone = obj.pose.bones['upper_arm.L']
500     pbone['type'] = 'arm_biped'
501     pbone = obj.pose.bones['upper_arm.L']
502     pbone['arm_biped_generic.elbow_parent'] = 'spine.04'
503     pbone = obj.pose.bones['upper_arm.L']
504     pbone['arm_biped_generic.layer_fk'] = 7
505     pbone = obj.pose.bones['upper_arm.L']
506     pbone['arm_biped_generic.layer_ik'] = 8
507     pbone = obj.pose.bones['upper_arm.R']
508     pbone['type'] = 'arm_biped'
509     pbone = obj.pose.bones['upper_arm.R']
510     pbone['arm_biped_generic.layer_fk'] = 9
511     pbone = obj.pose.bones['upper_arm.R']
512     pbone['arm_biped_generic.layer_ik'] = 10
513     pbone = obj.pose.bones['upper_arm.R']
514     pbone['arm_biped_generic.elbow_parent'] = 'spine.04'
515     pbone = obj.pose.bones['palm.01.L']
516     pbone['type'] = 'palm_curl'
517     pbone = obj.pose.bones['palm.01.L']
518     pbone['palm_curl.layer'] = 5
519     pbone = obj.pose.bones['thumb.01.L']
520     pbone['type'] = 'finger_curl'
521     pbone = obj.pose.bones['thumb.01.L']
522     pbone['finger_curl.layer_main'] = 5
523     pbone = obj.pose.bones['thumb.01.L']
524     pbone['finger_curl.layer_extra'] = 6
525     pbone = obj.pose.bones['thumb.01.R']
526     pbone['type'] = 'finger_curl'
527     pbone = obj.pose.bones['thumb.01.R']
528     pbone['finger_curl.layer_main'] = 5
529     pbone = obj.pose.bones['thumb.01.R']
530     pbone['finger_curl.layer_extra'] = 6
531     pbone = obj.pose.bones['palm.01.R']
532     pbone['type'] = 'palm_curl'
533     pbone = obj.pose.bones['palm.01.R']
534     pbone['palm_curl.layer'] = 5
535     pbone = obj.pose.bones['finger_pinky.01.L']
536     pbone['type'] = 'finger_curl'
537     pbone = obj.pose.bones['finger_pinky.01.L']
538     pbone['finger_curl.layer_main'] = 5
539     pbone = obj.pose.bones['finger_pinky.01.L']
540     pbone['finger_curl.layer_extra'] = 6
541     pbone = obj.pose.bones['finger_ring.01.L']
542     pbone['type'] = 'finger_curl'
543     pbone = obj.pose.bones['finger_ring.01.L']
544     pbone['finger_curl.layer_main'] = 5
545     pbone = obj.pose.bones['finger_ring.01.L']
546     pbone['finger_curl.layer_extra'] = 6
547     pbone = obj.pose.bones['finger_middle.01.L']
548     pbone['type'] = 'finger_curl'
549     pbone = obj.pose.bones['finger_middle.01.L']
550     pbone['finger_curl.layer_main'] = 5
551     pbone = obj.pose.bones['finger_middle.01.L']
552     pbone['finger_curl.layer_extra'] = 6
553     pbone = obj.pose.bones['finger_index.01.L']
554     pbone['type'] = 'finger_curl'
555     pbone = obj.pose.bones['finger_index.01.L']
556     pbone['finger_curl.layer_main'] = 5
557     pbone = obj.pose.bones['finger_index.01.L']
558     pbone['finger_curl.layer_extra'] = 6
559     pbone = obj.pose.bones['finger_pinky.01.R']
560     pbone['type'] = 'finger_curl'
561     pbone = obj.pose.bones['finger_pinky.01.R']
562     pbone['finger_curl.layer_main'] = 5
563     pbone = obj.pose.bones['finger_pinky.01.R']
564     pbone['finger_curl.layer_extra'] = 6
565     pbone = obj.pose.bones['finger_ring.01.R']
566     pbone['type'] = 'finger_curl'
567     pbone = obj.pose.bones['finger_ring.01.R']
568     pbone['finger_curl.layer_main'] = 5
569     pbone = obj.pose.bones['finger_ring.01.R']
570     pbone['finger_curl.layer_extra'] = 6
571     pbone = obj.pose.bones['finger_middle.01.R']
572     pbone['type'] = 'finger_curl'
573     pbone = obj.pose.bones['finger_middle.01.R']
574     pbone['finger_curl.layer_main'] = 5
575     pbone = obj.pose.bones['finger_middle.01.R']
576     pbone['finger_curl.layer_extra'] = 6
577     pbone = obj.pose.bones['finger_index.01.R']
578     pbone['type'] = 'finger_curl'
579     pbone = obj.pose.bones['finger_index.01.R']
580     pbone['finger_curl.layer_main'] = 5
581     pbone = obj.pose.bones['finger_index.01.R']
582     pbone['finger_curl.layer_extra'] = 6
583
584
585 class AddHuman(bpy.types.Operator):
586     '''Add an advanced human metarig base'''
587     bl_idname = "object.armature_human_advanced_add"
588     bl_label = "Add Humanoid (advanced metarig)"
589     bl_register = True
590     bl_undo = True
591
592     def execute(self, context):
593         bpy.ops.object.armature_add()
594         obj = context.active_object
595         mode_orig = obj.mode
596         bpy.ops.object.mode_set(mode='EDIT') # grr, remove bone
597         bones = context.active_object.data.edit_bones
598         bones.remove(bones[0])
599         metarig_template()
600         bpy.ops.object.mode_set(mode=mode_orig)
601         return {'FINISHED'}
602
603
604 # Add to a menu
605 menu_func = (lambda self, context: self.layout.operator(AddHuman.bl_idname,
606                     icon='OUTLINER_OB_ARMATURE', text="Human (Meta-Rig)"))
607
608
609 def register():
610     bpy.types.register(AddHuman)
611     bpy.types.INFO_MT_armature_add.append(menu_func)
612
613 def unregister():
614     bpy.types.unregister(AddHuman)
615     bpy.types.INFO_MT_armature_add.remove(menu_func)
616