-
Notifications
You must be signed in to change notification settings - Fork 0
/
foodhuman.py
81 lines (74 loc) · 2.37 KB
/
foodhuman.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
import bpy
# Create armature object
armature = bpy.data.objects.new("Armature", bpy.data.armatures.new("Armature"))
bpy.context.collection.objects.link(armature)
bpy.context.view_layer.objects.active = armature
armature.select_set(True)
# Enter edit mode
bpy.ops.object.mode_set(mode='EDIT')
# Create bones
bones = [
("root", (0, 0, 0), (0, 0, 0)),
("pelvis", (0, 0, 1), (0, 0, 0)),
("spine", (0, 0, 2), (0, 0, 0)),
("chest", (0, 0, 3), (0, 0, 0)),
("neck", (0, 0, 4), (0, 0, 0)),
("head", (0, 0, 5), (0, 0, 0)),
("shoulder.L", (-1, 0, 4), (0, 0, 0)),
("upper_arm.L", (-2, 0, 4), (0, 0, 0)),
("forearm.L", (-3, 0, 4), (0, 0, 0)),
("hand.L", (-4, 0, 4), (0, 0, 0)),
("shoulder.R", (1, 0, 4), (0, 0, 0)),
("upper_arm.R", (2, 0, 4), (0, 0, 0)),
("forearm.R", (3, 0, 4), (0, 0, 0)),
("hand.R", (4, 0, 4), (0, 0, 0)),
("hip.L", (-1, 0, 1), (0, 0, 0)),
("thigh.L", (-1, 0, 0), (0, 0, 0)),
("shin.L", (-1, 0, -1), (0, 0, 0)),
("foot.L", (-1, 0, -2), (0, 0, 0)),
("toe.L", (-1, 0, -3), (0, 0, 0)),
("hip.R", (1, 0, 1), (0, 0, 0)),
("thigh.R", (1, 0, 0), (0, 0, 0)),
("shin.R", (1, 0, -1), (0, 0, 0)),
("foot.R", (1, 0, -2), (0, 0, 0)),
("toe.R", (1, 0, -3), (0, 0, 0))
]
for bone in bones:
bone_name, bone_head, bone_tail = bone
bpy.ops.armature.bone_primitive_add(name=bone_name)
new_bone = armature.data.edit_bones[bone_name]
new_bone.head = bone_head
new_bone.tail = bone_tail
# Connect bones
bone_connections = [
("root", "pelvis"),
("pelvis", "spine"),
("spine", "chest"),
("chest", "neck"),
("neck", "head"),
("chest", "shoulder.L"),
("shoulder.L", "upper_arm.L"),
("upper_arm.L", "forearm.L"),
("forearm.L", "hand.L"),
("chest", "shoulder.R"),
("shoulder.R", "upper_arm.R"),
("upper_arm.R", "forearm.R"),
("forearm.R", "hand.R"),
("pelvis", "hip.L"),
("hip.L", "thigh.L"),
("thigh.L", "shin.L"),
("shin.L", "foot.L"),
("foot.L", "toe.L"),
("pelvis", "hip.R"),
("hip.R", "thigh.R"),
("thigh.R", "shin.R"),
("shin.R", "foot.R"),
("foot.R", "toe.R")
]
for connection in bone_connections:
parent_bone, child_bone = connection
parent = armature.data.edit_bones[parent_bone]
child = armature.data.edit_bones[child_bone]
child.parent = parent
# Exit edit mode
bpy.ops.object.mode_set(mode='OBJECT')