Commit d7f6d50c506d68256ae1203d54145a738576ba13
1 parent
e628fafb
Exists in
master
versao atual
Showing
6 changed files
with
346 additions
and
148 deletions
Show diff stats
.gitignore
avatar_Hozana_wikiLibras.blend
No preview for this file type
libras.py
1 | 1 | # -*- coding: UTF-8 -*- |
2 | + | |
3 | +# importa modulos do Python | |
2 | 4 | import sys |
3 | -sys.path.append('/home/gtaaas/wikilibras/wikilibras-core') | |
5 | +import os | |
6 | + | |
7 | +# insere o diretorio atual no path | |
8 | +# permite que o código seja executado de qualquer diretório, possibilitando acesso aos modulos locais | |
9 | +sys.path.append(os.getcwd()) | |
10 | + | |
11 | +# importa modulos nativos do Blender e Python | |
12 | +import bpy | |
4 | 13 | import json |
5 | -import lbsObjects | |
14 | + | |
15 | +# importa modulos locais | |
16 | +import objects | |
6 | 17 | import util |
18 | +import moves | |
19 | + | |
20 | +# verifica a quantidade de argumentos recebidos | |
21 | +if (len(sys.argv) != 6): | |
22 | + print ("WikiLibras: Invalid number of arguments") | |
23 | + exit(1) | |
24 | + | |
25 | +# tenta decodificar o argumento JSON recebido | |
26 | +try: | |
27 | + json_input = json.loads(sys.argv[5]) | |
28 | +except (ValueError, KeyError, TypeError): | |
29 | + print ("WikiLibras: JSON format error") | |
30 | + exit(1) | |
31 | + | |
32 | +# ajusta as configuraçẽs de renderização | |
33 | +util.outconf() | |
34 | + | |
35 | +# define a posição dos keyframes | |
36 | +hands_default_frames = [15, 18] | |
37 | + | |
38 | +# Carrega o objeto presente no avatar | |
39 | +armature = bpy.context.scene.objects.get('Armature.001') | |
40 | + | |
41 | +# Cria uma Action | |
42 | +act = bpy.context.scene.animation_data_create() | |
43 | + | |
44 | +# Função responsável por selecionar as pose-libs e setar os frames | |
45 | +def setPose(actions, parametesConf, positionFrames, bones): | |
46 | + bpy.ops.object.mode_set(mode = 'OBJECT') | |
47 | + bpy.ops.object.select_all(action="DESELECT") | |
48 | + bpy.ops.object.mode_set(mode = 'POSE') | |
49 | + for l in range(len(actions)): | |
50 | + armature.pose_library = bpy.data.actions[actions[l]] | |
51 | + for x in range(len(positionFrames)): | |
52 | + bpy.ops.poselib.apply_pose(pose_index= parametesConf[l]) | |
53 | + for i in range(0, (len(bones))): | |
54 | + armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x]) | |
55 | + armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) | |
7 | 56 | |
57 | +# Função responsável por setar pose padrão | |
58 | +def poseDefault(positionFrames, bones): | |
59 | + setPose([2], [0], positionFrames, bones) | |
8 | 60 | |
9 | -def circular_or_semiCircular(hand,pose,orientation,direction,radius,laps,intensity = 5,initialFrame = 15): | |
10 | - center = pose.location.x,pose.location.y,pose.location.z | |
61 | +# Função responsável por setar as configuraçẽs das mãos | |
62 | +def generationConfigurations(actions, handParam, positionFrames, bones): | |
63 | + setPose(actions, handParam, positionFrames, bones) | |
64 | + | |
65 | +def faceConfiguration(handParam, positionFrames, bones): | |
66 | + # Função responsável por setar a configuração da face | |
67 | + setPose([7], handParam, positionFrames, bones) | |
68 | + | |
69 | +# Função que recupera o frame final do movimento | |
70 | +def get_endFrame(): | |
71 | + endsFrame = [18] | |
72 | + if(json_input["rightHand"] != []): | |
73 | + if(json_input["rightHand"][0] == "circular" or json_input["rightHand"][0] == "semicircular"): | |
74 | + endsFrame.append(int(json_input["rightHand"][4]*8*5+15)) | |
75 | + if(json_input["leftHand"] != []): | |
76 | + if(json_input["leftHand"][0] == "circular" or json_input["leftHand"][0] == "semicircular"): | |
77 | + endsFrame.append(int(json_input["leftHand"][4]*8*5+15)) | |
78 | + return(max(endsFrame)) | |
79 | + | |
80 | +initialFrame, endFrame = 15, get_endFrame() | |
81 | + | |
82 | +def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 15): | |
83 | + center = pose.location.x, pose.location.y, pose.location.z | |
11 | 84 | if(orientation == 'perpendicular'): |
12 | 85 | if(direction == 'horario'): |
13 | - endFrame = hand.rotationCircular(center,radius,1,0,2,pose,0,laps,intensity,initialFrame) | |
86 | + endFrame = moves.locationCircular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame) | |
14 | 87 | else: |
15 | - endFrame = hand.rotationCircular(center,radius,0,1,2,pose,0,laps,intensity,initialFrame) | |
88 | + endFrame = moves.locationCircular(center, radius, 0, 1, 2, pose, 0, laps, intensity, initialFrame) | |
16 | 89 | elif(orientation == 'paralelo'): |
17 | 90 | if(direction == 'horario'): |
18 | - endFrame = hand.rotationCircular(center,radius,1,2,0,pose,0,laps,intensity,initialFrame) | |
91 | + endFrame = moves.locationCircular(center, radius, 1, 2, 0, pose, 0, laps, intensity, initialFrame) | |
19 | 92 | else: |
20 | - endFrame = hand.rotationCircular(center,radius,2,1,0,pose,0,laps,intensity,initialFrame) | |
93 | + endFrame = moves.locationCircular(center, radius, 2, 1, 0, pose, 0, laps, intensity, initialFrame) | |
21 | 94 | return endFrame |
22 | 95 | |
23 | -def get_endFrame(json_input): | |
24 | - endsFrame = [] | |
25 | - if(json_input["rightHand"][0] == "circular" or json_input["rightHand"][0] == "semicircular"): | |
26 | - endsFrame.append(int(json_input["rightHand"][4]*8*5+15)) | |
27 | - if(json_input["leftHand"][0] == "circular" or json_input["leftHand"][0] == "semicircular"): | |
28 | - endsFrame.append(int(json_input["leftHand"][4]*8*5+15)) | |
29 | - return(max(endsFrame)) | |
30 | 96 | |
31 | -#Configurações gerais | |
32 | -json_input = json.loads(sys.argv[5]) # Load jason | |
33 | -util.outconf() | |
34 | -handPosFrame = {'loc':[15],'rot':[15]} | |
35 | -armature = lbsObjects.Armadura('Armature.001') | |
36 | -initialFrame,endFrame = 18,get_endFrame(json_input) | |
37 | - | |
38 | -#Initial Pose | |
39 | -lbsObjects.Pose({'loc':[0], 'rot':[0]}, armature) #Set the default pose | |
40 | - | |
41 | -#ConfHandRight | |
42 | -if(json_input["rightHand"] != []): | |
43 | - movRight = json_input["rightHand"][0] | |
44 | - pose = armature.pose.bones['ik_FK.R'] | |
45 | - if(movRight == "pontual"): | |
46 | - handRight = lbsObjects.MaoDireita(json_input["rightHand"][-3:],{'loc':[15,endFrame],'rot':[15,endFrame]}, armature) | |
47 | - else: | |
48 | - handRight = lbsObjects.MaoDireita(json_input["rightHand"][-3:],handPosFrame, armature) | |
49 | - if(movRight == "circular" or movRight == "semicircular"): | |
50 | - orientation,direction,radius,laps = json_input["rightHand"][1:5] | |
51 | - endFrame = circular_or_semiCircular(handRight,pose,orientation,direction,radius,laps,5) | |
52 | - handRight.genConf({'loc':[endFrame],'rot':[endFrame]}) | |
53 | - handRight.genOri({'loc':[endFrame],'rot':[endFrame]}) | |
54 | - elif(json_input["rightHand"][0] == "retilineo"): | |
55 | - pass | |
56 | - | |
57 | -#ConfLeftRight | |
58 | -if(json_input["leftHand"] != []): | |
59 | - movLeft = json_input["leftHand"][0] | |
60 | - pose = armature.pose.bones['ik_FK.L'] | |
61 | - if(movLeft == "pontual"): | |
62 | - handLeft = lbsObjects.MaoEsquerda(json_input["leftHand"][-3:], {'loc':[15,endFrame],'rot':[15,endFrame]}, armature) | |
63 | - else: | |
64 | - handLeft = lbsObjects.MaoEsquerda(json_input["leftHand"][-3:], handPosFrame, armature) | |
65 | - if(movLeft == "circular" or movLeft == "semicircular"): | |
66 | - orientation,direction,radius,laps = json_input["leftHand"][1:5] | |
67 | - endFrame = circular_or_semiCircular(handRight,pose,orientation,direction,radius,laps,5) | |
68 | - handLeft.genConf({'loc':[endFrame],'rot':[endFrame]}) | |
69 | - handLeft.genOri({'loc':[endFrame],'rot':[endFrame]}) | |
70 | - elif(json_input["leftHand"][0] == "retilineo"): | |
71 | - pass | |
72 | - | |
73 | -if(json_input["facialExp"] != []): | |
74 | - #confFace | |
75 | - lbsObjects.Face(json_input["facialExp"], armature, int(endFrame/1.5)) # Set face | |
76 | - | |
77 | -#confPoseEnd | |
78 | -lbsObjects.Pose({'loc':[1,endFrame+20],'rot':[1,endFrame+20]},armature) # Set the final pose | |
79 | - | |
80 | -util.render_sign(json_input["userId"],json_input["signName"],1,endFrame + 20) | |
97 | +#------------------ Configurações------------------------------ | |
98 | + | |
99 | +#Função que inicia a configuração de ambas as mãos | |
100 | +def configureHands(): | |
101 | + # Array com valores dos campos que serão passados pelo JSON | |
102 | + hands = ["rightHand", "leftHand"] | |
103 | + iks = ['ik_FK.R', 'ik_FK.L'] | |
104 | + bones_ = [util.rightBonesConf, util.leftBonesConf] | |
105 | + #Array com as actions FAKES que seram selecionadas no Blender para cada lado do corpo | |
106 | + actions = [[0, 3, 5], [1, 4, 6]] | |
107 | + global endFrame | |
108 | + for i in range(len(hands)): | |
109 | + if(json_input[hands[i]] != []): | |
110 | + move = json_input[hands[i]][0] | |
111 | + pose = armature.pose.bones[iks[i]] | |
112 | + if(move == "pontual"): | |
113 | + generationConfigurations(actions[i], json_input[hands[i]][-3:], [15, endFrame], bones_[i]) | |
114 | + else: | |
115 | + generationConfigurations(actions[i], json_input[hands[i]][-3:], hands_default_frames, bones_[i]) | |
116 | + if(move == "circular" or move == "semicircular"): | |
117 | + orientation, direction, radius, laps = json_input[hands[i]][1:5] | |
118 | + endFrame = circular_or_semiCircular(handRight, pose, orientation, direction, radius, laps, 5) | |
119 | + elif(json_input[hands[i]][0] == "retilineo"): | |
120 | + pass | |
121 | + | |
122 | +# Função que inicia a configuração da face | |
123 | +def configureFace(): | |
124 | + global endFrame | |
125 | + if(json_input["facialExp"] != []): | |
126 | + # Set face | |
127 | + faceConfiguration(json_input["facialExp"], [endFrame/2], util.faceBonesConf) | |
128 | + | |
129 | +#configureHands() | |
130 | +#configureFace() | |
131 | + | |
132 | +# Default Pose | |
133 | +poseDefault([0, endFrame+15], util.allBones) | |
134 | + | |
135 | +util.render_sign(json_input["userId"], json_input["signName"], 1, endFrame + 25) | ... | ... |
... | ... | @@ -0,0 +1,191 @@ |
1 | +# -*- coding: UTF-8 -*- | |
2 | + | |
3 | +def locationCircular(self, center, radius, i_axis, j_axis, k_axis, pose, initialPosition, laps, frameJump = 5, initialFrame = 15, turn = None): | |
4 | + sqrt22 = radius * math.sqrt(2) / 2 | |
5 | + rad2 = (radius/2) | |
6 | + currentFrame = initialFrame | |
7 | + for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1): | |
8 | + if ((l % 8) == 0 ): | |
9 | + pose.location[i_axis] = center[i_axis] + radius | |
10 | + pose.location[j_axis] = center[j_axis] | |
11 | + pose.location[k_axis] = center[k_axis] | |
12 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | |
13 | + currentFrame += frameJump | |
14 | + if ((l % 8) == 1): | |
15 | + pose.location[i_axis] = center[i_axis] + sqrt22 | |
16 | + pose.location[j_axis] = center[j_axis] + sqrt22 | |
17 | + pose.location[k_axis] = center[k_axis] | |
18 | + if(turn == 1): | |
19 | + pose.location[i_axis] = center[i_axis] + sqrt22 | |
20 | + pose.location[j_axis] = center[j_axis] + rad2 | |
21 | + pose.location[k_axis] = center[k_axis] - rad2 | |
22 | + elif(turn == -1): | |
23 | + pose.location[i_axis] = center[i_axis] + sqrt22 | |
24 | + pose.location[j_axis] = center[j_axis] + rad2 | |
25 | + pose.location[k_axis] = center[k_axis] + rad2 | |
26 | + pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') | |
27 | + currentFrame += frameJump | |
28 | + if ((l % 8) == 2): | |
29 | + pose.location[i_axis] = center[i_axis] | |
30 | + pose.location[j_axis] = center[j_axis] + radius | |
31 | + pose.location[k_axis] = center[k_axis] | |
32 | + if(turn == 1): | |
33 | + pose.location[j_axis] = center[j_axis] + sqrt22 | |
34 | + pose.location[k_axis] = center[k_axis] - sqrt22 | |
35 | + elif(turn == -1): | |
36 | + pose.location[j_axis] = center[j_axis] + sqrt22 | |
37 | + pose.location[k_axis] = center[k_axis] + sqrt22 | |
38 | + pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') | |
39 | + currentFrame += frameJump | |
40 | + if ((l % 8) == 3): | |
41 | + pose.location[i_axis] = center[i_axis] - sqrt22 | |
42 | + pose.location[j_axis] = center[j_axis] + sqrt22 | |
43 | + pose.location[k_axis] = center[k_axis] | |
44 | + if(turn == 1): | |
45 | + pose.location[i_axis] = center[i_axis] - sqrt22 | |
46 | + pose.location[j_axis] = center[j_axis] + rad2 | |
47 | + pose.location[k_axis] = center[k_axis] - rad2 | |
48 | + elif(turn == -1): | |
49 | + pose.location[i_axis] = center[i_axis] - sqrt22 | |
50 | + pose.location[j_axis] = center[j_axis] + rad2 | |
51 | + pose.location[k_axis] = center[k_axis] + rad2 | |
52 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | |
53 | + currentFrame += frameJump | |
54 | + | |
55 | + if ((l % 8) == 4): | |
56 | + pose.location[i_axis] = center[i_axis] - radius | |
57 | + pose.location[j_axis] = center[j_axis] | |
58 | + pose.location[k_axis] = center[k_axis] | |
59 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | |
60 | + currentFrame += frameJump | |
61 | + | |
62 | + if ((l % 8) == 5): | |
63 | + pose.location[i_axis] = center[i_axis] - sqrt22 | |
64 | + pose.location[j_axis] = center[j_axis] - sqrt22 | |
65 | + pose.location[k_axis] = center[k_axis] | |
66 | + if(turn == 1): | |
67 | + pose.location[i_axis] = center[i_axis] - sqrt22 | |
68 | + pose.location[j_axis] = center[j_axis] - rad2 | |
69 | + pose.location[k_axis] = center[k_axis] + rad2 | |
70 | + elif(turn == -1): | |
71 | + pose.location[i_axis] = center[i_axis] - sqrt22 | |
72 | + pose.location[j_axis] = center[j_axis] - ray2 | |
73 | + pose.location[k_axis] = center[k_axis] - ray2 | |
74 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | |
75 | + currentFrame += frameJump | |
76 | + | |
77 | + if ((l % 8) == 6): | |
78 | + pose.location[i_axis] = center[i_axis] | |
79 | + pose.location[j_axis] = center[j_axis] - radius | |
80 | + pose.location[k_axis] = center[k_axis] | |
81 | + if(turn == 1): | |
82 | + pose.location[j_axis] = center[j_axis] - sqrt22 | |
83 | + pose.location[k_axis] = center[k_axis] + sqrt22 | |
84 | + elif(turn == -1): | |
85 | + pose.location[j_axis] = center[j_axis] - sqrt22 | |
86 | + pose.location[k_axis] = center[k_axis] - sqrt22 | |
87 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | |
88 | + currentFrame += frameJump | |
89 | + | |
90 | + if ((l % 8) == 7): | |
91 | + pose.location[i_axis] = center[i_axis] + sqrt22 | |
92 | + pose.location[j_axis] = center[j_axis] - sqrt22 | |
93 | + pose.location[k_axis] = center[k_axis] | |
94 | + if(turn == 1): | |
95 | + pose.location[i_axis] = center[i_axis] + sqrt22 | |
96 | + pose.location[j_axis] = center[j_axis] - ray2 | |
97 | + pose.location[k_axis] = center[k_axis] + ray2 | |
98 | + elif(turn == -1): | |
99 | + pose.location[i_axis] = center[i_axis] + sqrt22 | |
100 | + pose.location[j_axis] = center[j_axis] - ray2 | |
101 | + pose.location[k_axis] = center[k_axis] - ray2 | |
102 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | |
103 | + currentFrame += frameJump | |
104 | + currentFrame -= frameJump | |
105 | + return currentFrame | |
106 | + | |
107 | + | |
108 | +# testing . . . | |
109 | +def locationHelicoidal(center, startRadius, incRadius, x, y, z, currentLoc, laps, frameJump): | |
110 | + sqrt22 = radius * math.sqrt(2) / 2 | |
111 | + allLaps = math.floor(8 * laps) + 1 | |
112 | + | |
113 | + #for i in range(currentLoc, currentLoc + math.floor(8 * laps) + 1): | |
114 | + for i in range(currentLoc, currentLoc + allLaps): | |
115 | + print("All Laps:", allLaps) | |
116 | + if ((i % 8) == 0 ): | |
117 | + obj.location[x] = center[x] + radius | |
118 | + obj.location[y] = center[y] | |
119 | + obj.location[z] += incRadius /allLaps | |
120 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
121 | + bpy.context.scene.frame_end += frameJump | |
122 | + | |
123 | + if ((i % 8) == 1): | |
124 | + obj.location[x] = center[x] + sqrt22 | |
125 | + obj.location[y] = center[y] + sqrt22 | |
126 | + obj.location[z] += incRadius /allLaps | |
127 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
128 | + bpy.context.scene.frame_end += frameJump | |
129 | + | |
130 | + if ((i % 8) == 2): | |
131 | + obj.location[x] = center[x] | |
132 | + obj.location[y] = center[y] + radius | |
133 | + obj.location[z] += incRadius /allLaps | |
134 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
135 | + bpy.context.scene.frame_end += frameJump | |
136 | + | |
137 | + if ((i % 8) == 3): | |
138 | + obj.location[x] = center[x] - sqrt22 | |
139 | + obj.location[y] = center[y] + sqrt22 | |
140 | + obj.location[z] += incRadius /allLaps | |
141 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
142 | + bpy.context.scene.frame_end += frameJump | |
143 | + | |
144 | + if ((i % 8) == 4): | |
145 | + obj.location[x] = center[x] - radius | |
146 | + obj.location[y] = center[y] | |
147 | + obj.location[z] += incRadius /allLaps | |
148 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
149 | + bpy.context.scene.frame_end += frameJump | |
150 | + | |
151 | + if ((i % 8) == 5): | |
152 | + obj.location[x] = center[x] - sqrt22 | |
153 | + obj.location[y] = center[y] - sqrt22 | |
154 | + obj.location[z] += incRadius /allLaps | |
155 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
156 | + bpy.context.scene.frame_end += frameJump | |
157 | + | |
158 | + if ((i % 8) == 6): | |
159 | + obj.location[x] = center[x] | |
160 | + obj.location[y] = center[y] - radius | |
161 | + obj.location[z] += incRadius /allLaps | |
162 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
163 | + bpy.context.scene.frame_end += frameJump | |
164 | + | |
165 | + if ((i % 8) == 7): | |
166 | + obj.location[x] = center[x] + sqrt22 | |
167 | + obj.location[y] = center[y] - sqrt22 | |
168 | + obj.location[z] += incRadius /allLaps | |
169 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
170 | + bpy.context.scene.frame_end += frameJump | |
171 | + | |
172 | + bpy.context.scene.frame_end -= frameJump | |
173 | + | |
174 | +# testing . . . | |
175 | +def locationSenoidal(obj): | |
176 | + obj.location = [0, 0, 0] | |
177 | + bpy.context.scene.frame_start = 1 | |
178 | + bpy.context.scene.frame_end = 1 | |
179 | + seno = 0 | |
180 | + waveHeight = 5.0 | |
181 | + wave = 5 | |
182 | + pi180 = math.pi / 180 | |
183 | + print(pi180) | |
184 | + for wave in range(0, 3): | |
185 | + for i in range(-180, 180): | |
186 | + obj.location[1] = math.sin(i * (pi180)) * waveHeight | |
187 | + obj.location[2] += 0.005 | |
188 | + if (i % 10 == 0): | |
189 | + obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') | |
190 | + bpy.context.scene.frame_end += 1 | |
191 | + | |
0 | 192 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,5 @@ |
1 | +'{"userId": 4,"rightHand": ["circular","perpendicular","horario",0.6,1,"conf_20","Ori_4","Pa_6"],"leftHand":["pontual","conf_10","Ori_3","Pa_3"],"facialExp": "Exp_6","signName":"teste_novo"}' | |
2 | + | |
3 | +'{"userId": 4,"rightHand": ["pontual","conf_20","Ori_4","Pa_6"],"leftHand":["circular","perpendicular","horario",0.6,1,"conf_20","Ori_4","Pa_6"],"facialExp": "Exp_6","signName":"pontual_direita"}' | |
4 | + | |
5 | +'{"userId": 4,"rightHand": ["semicircular","perpendicular","horario",0.6,0.5,"conf_20","Ori_4","Pa_6"],"leftHand":["pontual","conf_10","Ori_3","Pa_3"],"facialExp": "Exp_6","signName":"SemiCircular"}' | ... | ... |
util.py
1 | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | |
3 | 3 | import bpy |
4 | -import math as m | |
5 | -import subprocess as sub | |
6 | -import sys | |
7 | -sys.path.append("./") | |
4 | +import math | |
8 | 5 | |
9 | 6 | bones = ["BnMao.R", "BnMao.L"] |
10 | -def sizeRadius(value): | |
11 | - value = value.lower() | |
12 | - if (value == 'grande'): | |
13 | - return 1 | |
14 | - elif (value == 'medio'): | |
15 | - return 0.6 | |
16 | - else: | |
17 | - return 0.3 | |
18 | - | |
7 | +armature = bpy.context.scene.objects.get('Armature.001') | |
8 | +rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66] | |
9 | +leftBonesConf = [0, 43, 44, 45, 46, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82] | |
10 | +faceBonesConf =[15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] | |
11 | +allBones = list(range(len(armature.pose.bones))) | |
12 | + | |
13 | +def erase_all_keyframes(): | |
14 | + for i in bpy.data.objects: | |
15 | + i.animation_data_clear() | |
16 | + bpy.context.scene.frame_start = 1 | |
17 | + bpy.context.scene.frame_current = bpy.context.scene.frame_start | |
18 | + bpy.context.scene.frame_end = bpy.context.scene.frame_start | |
19 | + | |
19 | 20 | def outconf(): |
20 | 21 | bpy.context.scene.render.resolution_x = 640 |
21 | 22 | bpy.context.scene.render.resolution_y = 480 |
... | ... | @@ -24,8 +25,15 @@ def outconf(): |
24 | 25 | bpy.context.scene.render.ffmpeg.format = 'MPEG4' |
25 | 26 | bpy.context.scene.render.ffmpeg.codec = 'H264' |
26 | 27 | # bpy.context.scene.render.filepath = '/tmp/' |
27 | - | |
28 | - | |
28 | + | |
29 | +def render_sign(userId, signName, beginFrame, endFrame): | |
30 | + bpy.context.scene.render.filepath = "//users//"+ str(userId)+ "//"+ signName + "_" | |
31 | + bpy.context.scene.frame_start = beginFrame | |
32 | + bpy.context.scene.frame_end = endFrame | |
33 | + bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | |
34 | + bpy.ops.wm.quit_blender() | |
35 | + | |
36 | +""" | |
29 | 37 | def flip(frame, lado): |
30 | 38 | print ("flipou Frame: " + str(frame) + " BONE: " + str(bones[lado])) |
31 | 39 | for i in range(0, 4, 1): |
... | ... | @@ -33,12 +41,11 @@ def flip(frame, lado): |
33 | 41 | |
34 | 42 | def fixRots(lado): |
35 | 43 | keyFrames = bpy.Object.Get("Armature.001").getAction().getFrameNumbers() |
36 | - print (keyFrames) | |
37 | 44 | rotFrames = [[]] |
38 | 45 | status = [True] * (len(keyFrames) + 1) |
39 | 46 | |
40 | - for i in range(0,len(keyFrames),1): | |
41 | - bpy.Set('curframe',keyFrames[i]) | |
47 | + for i in range(0, len(keyFrames), 1): | |
48 | + bpy.Set('curframe', keyFrames[i]) | |
42 | 49 | rotFrames[-1] = bpy.Object.Get("Armature.001").getPose().bones[bones[lado]].quat.toEuler() |
43 | 50 | rotFrames.append( [] ) |
44 | 51 | |
... | ... | @@ -46,7 +53,7 @@ def fixRots(lado): |
46 | 53 | |
47 | 54 | for k in range(1, len(keyFrames), 1): |
48 | 55 | for i in range(0, 3, 1): |
49 | - if (m.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > 180 : | |
56 | + if (math.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > 180 : | |
50 | 57 | status[k] = False |
51 | 58 | |
52 | 59 | print (status[0:len(status)-1]) |
... | ... | @@ -60,67 +67,4 @@ def fixRots(lado): |
60 | 67 | status[k+1] = True |
61 | 68 | |
62 | 69 | print (status[0:len(status)-1]) |
63 | - | |
64 | -''' | |
65 | -def get_calculo_mov(radius,orientation,sense): | |
66 | -''' | |
67 | - | |
68 | -def render_sign(userId,signName,beginFrame,endFrame): | |
69 | - bpy.context.scene.render.filepath = "//Users//"+ str(userId)+ "//"+ signName + "_" | |
70 | - bpy.context.scene.frame_start = beginFrame | |
71 | - bpy.context.scene.frame_end = endFrame | |
72 | - bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | |
73 | - | |
74 | - bpy.ops.wm.quit_blender() | |
75 | - | |
76 | -""" | |
77 | -def lib_parse (filename): | |
78 | - res = [] | |
79 | - cfg = None | |
80 | - with open(filename) as f: | |
81 | - for ln in f: | |
82 | - ln = ln.split() | |
83 | - | |
84 | - if len(ln) == 0: | |
85 | - continue | |
86 | - elif len(ln) in (1,2,3,4): | |
87 | - cfg = Struct(name = ln[0], | |
88 | - bones = []) | |
89 | - res.append (cfg) | |
90 | - else: | |
91 | - name = ln[0] | |
92 | - loc = [float(x) for x in ln[2:5]] | |
93 | - rot = [float(x) for x in ln[6:]] | |
94 | - cfg.bones.append (Struct(name = name, loc = loc, rot = rot)) | |
95 | - return res | |
96 | - | |
97 | -def read_lines_file(fileName): | |
98 | - with open(fileName,"r") as f: | |
99 | - return [x.strip() for x in f] | |
100 | - | |
101 | -# Struct-like dictionary. obj['x'] == obj.x | |
102 | -class Struct: | |
103 | - def __init__ (self, **kws): | |
104 | - self.__dict__ = kws | |
105 | - | |
106 | - def __getitem__(self, i): | |
107 | - return self.__dict__[i] | |
108 | - | |
109 | - def __repr__ (self): | |
110 | - return repr(self.__dict__) | |
111 | - | |
112 | -def parseVideo(id,nameSign,endFrame): | |
113 | - print ("Convertendo AVI em FLV usando ffmpeg") | |
114 | - num = endFrame + 30 | |
115 | - if(num > 100): | |
116 | - s = "0" + str(num); | |
117 | - else: | |
118 | - s = "00" + str(num); | |
119 | - print (nameSign+"_0001_"+s+".avi"); | |
120 | - | |
121 | - sub.call(["ffmpeg", "-i", "/usr/share/WikiLIBRAS/server/ScriptsPython/"+nameSign+"_0001_"+s+".avi", "-bpy", "2028k", "-s", "640x480", "-r", "30", "-acodec", "copy", nameSign+".flv"]) | |
122 | - | |
123 | - print (id + "**********************************************") | |
124 | - sub.call(["mv", "/usr/share/WikiLIBRAS/server/ScriptsPython/"+nameSign+".flv", "/home/gtaaas/gtaaas_web/public/uploads/files/"+id+ "/"]) | |
125 | -""" | |
126 | - | |
70 | +""" | |
127 | 71 | \ No newline at end of file | ... | ... |