-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoCreateController.py
205 lines (165 loc) · 5.13 KB
/
AutoCreateController.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
# -*-coding: utf-8 -*-
from maya import cmds
# import json
# import types
'''不能有重名的字符串'''
face_rig_dict = {
"face_rig": [
{ "face_constraint": "face_constraint1" },
{
"face_ctrl": [
{
"ctrl_grp": [
{
"jaw_ctrl_locator": [
{
"lowerlip": [
{
"lowerlip2": "lowerlip_2_sufaceJoint"
}
]
}
]
},
{
"lowerEyelid_left_ctrl_locator": [
{
"lowerEyelid_left": [
"lowerEyelid_left_1_bn_ctrl",
"lowerEyelid_left_2_bn_ctrl",
"lowerEyelid_left_3_bn_ctrl",
"lowerEyelid_left_4_bn_ctrl",
"lowerEyelid_left_5_bn_ctrl"
]
}
]
},
{
"upperEyelid_left_ctrl_locator": [
{
"upperEyelid_left": [
"upperEyelid_left_1_bn_ctrl",
"upperEyelid_left_2_bn_ctrl",
"upperEyelid_left_3_bn_ctrl",
"upperEyelid_left_4_bn_ctrl",
"upperEyelid_left_5_bn_ctrl",
]
}
]
}
]
},
{
"brows_left": [
"brows_left_1_locator",
"brows_left_2_locator",
"brows_left_3_locator"
]
},
{
"brows_right": [
"brows_right_1_locator",
"brows_right_2_locator",
"brows_right_3_locator"
]
},
{
"mouth_conner": [
{
"upperlip": "upperlip_2_surfaceJoint"
},
{
"mouthCorner_left": [
{
"mouthCorner_left": [
{
"mouthCorner_left_jaw": [
{
"mouthCorner_left_ctrl": [
{ "mouthCorner_left_locator_grp": "mouthCorner_left_locator" },
"upperlip_1_sufaceJoint",
"lowerlip_1_sufaceJoint"
]
}
]
}
]
}
]
},
{
"mouthCorner_right": [
{
"mouthCorner_right": [
{
"mouthCorner_right_jaw": [
{
"mouthCorner_right_ctrl": [
{ "mouthCorner_right_locator_grp": "mouthCorner_right_locator" },
"upperlip_3_sufaceJoint",
"lowerlip_3_sufaceJoint"
]
}
]
}
]
}
]
}
]
}
]
}
]
}
global depth
depth = 1
'''
递归路径,将路径按照[(path, depth)]的方式进行保存。
其中path为每一遍叶子的绝对路径
depth为叶子的深度。
'''
final_list = []
def go_though_dict(json_data , path=""):
global depth
if isinstance(json_data, dict):
#depth += 1
for key in json_data:
path = path + key + "-->"
go_though_dict(json_data[key], path)
elif isinstance(json_data, list):
#print len(json_data)
for i in range(len(json_data)):
#print json_data[i]
if isinstance(json_data[i], dict):
for sub_key in json_data[i]:
depth += 1
go_though_dict(json_data[i], path)
depth -= 1
else:
final_list.append((path + json_data[i],depth))
else:
final_list.append((path +json_data, depth))
go_though_dict(face_rig_dict)
order_list = sorted(final_list, key=lambda x:x[1])
def create_tree(tree_leaf_edges):
for element in order_list:
element_list = element[0].split("-->")
for i in range(len(element_list)):
if cmds.objExists(element_list[i]):
print (("{} has been created already!").format(element_list[i]))
else:
if i!=0:
cmds.select(clear=True)
if "_loc" in element_list[i]:
cmds.spaceLocator(name=element_list[i])
elif "_bn_" in element_list[i] or "Joint" in element_list[i]:
cmds.joint(name=element_list[i])
else:
cmds.group(empty=True, name=element_list[i])
cmds.parent(element_list[i], element_list[i-1])
else:
cmds.group(empty=True, name=element_list[i])
print ("-------------------------------------------------------------------------")
#cmds.group(name=element_list[i])
create_tree(tree_leaf_edges=order_list)