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