Commit df32bc038fc483fecba364e04a6d61937c7f335b

Authored by André Araújo
1 parent e313bcb0
Exists in master

Adiciona parâmetro -noaudio ao controller, atualiza movimento senoidal, remove funções não usadas

Makefile
... ... @@ -26,12 +26,12 @@ JSON_CIRCULAR = \
26 26 "mao_direita": { \
27 27 "circular": { \
28 28 "plano": "esquerda-cima", \
  29 + "sentido_inverso": false, \
29 30 "raio": "pequeno", \
30 31 "velocidade": "normal", \
31 32 "lado_oposto": false, \
32   - "sentido_inverso": false, \
33 33 "articulacao": 80, \
34   - "configuracao": 15, \
  34 + "configuracao": 19, \
35 35 "orientacao": 18 \
36 36 } \
37 37 } \
... ... @@ -172,11 +172,11 @@ JSON_HELICOIDAL = \
172 172 "mao_esquerda": {}, \
173 173 "mao_direita": { \
174 174 "helicoidal": { \
175   - "plano": "esquerda-cima", \
176   - "raio": "pequeno", \
  175 + "plano": "frente-esquerda", \
  176 + "sentido_inverso": false, \
  177 + "raio": "grande", \
177 178 "velocidade": "normal", \
178 179 "lado_oposto": false, \
179   - "sentido_inverso": true, \
180 180 "articulacao": 79, \
181 181 "configuracao": 0, \
182 182 "orientacao": 64 \
... ... @@ -241,12 +241,12 @@ JSON_SEMICIRCULAR = \
241 241 "mao_direita": { \
242 242 "semicircular": { \
243 243 "plano": "esquerda-cima", \
  244 + "sentido_inverso": false, \
244 245 "raio": "pequeno", \
245 246 "velocidade": "normal", \
246 247 "lado_oposto": false, \
247   - "sentido_inverso": false, \
248 248 "articulacao": 80, \
249   - "configuracao": 15, \
  249 + "configuracao": 19, \
250 250 "orientacao": 18 \
251 251 } \
252 252 } \
... ... @@ -264,12 +264,13 @@ JSON_SENOIDAL = \
264 264 "facial": {}, \
265 265 "mao_esquerda": {}, \
266 266 "mao_direita": { \
267   - "circular": { \
268   - "plano": "esquerda-cima", \
269   - "raio": "pequeno", \
  267 + "senoidal": { \
  268 + "direcao": "esquerda", \
  269 + "direcao_oposta": true, \
  270 + "plano_deslocamento": "cima-baixo", \
  271 + "distancia": "normal", \
270 272 "velocidade": "normal", \
271   - "lado_oposto": false, \
272   - "sentido_inverso": false, \
  273 + "tamanho_onda": "normal", \
273 274 "articulacao": 79, \
274 275 "configuracao": 0, \
275 276 "orientacao": 64 \
... ...
controller.py
... ... @@ -15,8 +15,8 @@ result = 0
15 15  
16 16 try:
17 17 # para gravar logs do blender, usar codigo abaixo
18   - # result = subprocess.call(['blender', '-b', blend_path, '-P', main_path, '--', sys.argv[1]], stdout = open('bpy.log', 'w'))
19   - result = subprocess.call(['blender', '-b', blend_path, '-P', main_path, '--', sys.argv[1]])
  18 + # result = subprocess.call(['blender', '-b', blend_path, '-P', main_path, '-noaudio', '--', sys.argv[1]], stdout = open('bpy.log', 'w'))
  19 + result = subprocess.call(['blender', '-b', blend_path, '-P', main_path, '-noaudio', '--', sys.argv[1]])
20 20 except:
21 21 result = pyutil.print_stack_trace()
22 22  
... ...
libras.py
... ... @@ -21,22 +21,6 @@ import moves
21 21 import pyutil
22 22 import decode
23 23  
24   -def insert_keyframe_pose_default(current_frame = 0, pose_bones = bpy.context.object.pose.bones, types_keyframe = ["location", "rotation_quaternion"]):
25   - for obj in (pose_bones):
26   - obj.bone.select = True
27   - for type_keyframe in types_keyframe:
28   - util.keyframe_insert(obj, type_keyframe, current_frame, False)
29   - obj.bone.select = False
30   - return
31   -
32   -def pose_default(current_frame = 0, frame_jump = 0, actions = bpy.data.actions):
33   - for action in actions:
34   - if (action.use_fake_user):
35   - bpy.context.object.pose_library = action
36   - bpy.ops.poselib.apply_pose(pose_index = 0)
37   - insert_keyframe_pose_default(current_frame)
38   - return current_frame + frame_jump
39   -
40 24 def main():
41 25 util.set_pose_mode()
42 26 util.delete_all_keyframes()
... ... @@ -44,18 +28,15 @@ def main():
44 28 bpy.context.scene.animation_data_create()
45 29  
46 30 try:
47   - js_input = json.loads(sys.argv[6])
  31 + js_input = json.loads(sys.argv[7])
48 32 js_movimentos = js_input["movimentos"]
49 33 frame_jump = util.dict_interpolation[js_input["interpolacao"]]
50 34  
51   - endFrame = pose_default(0, frame_jump)
  35 + endFrame = util.pose_default(0, frame_jump)
52 36 timeline_facial = 0
53 37 timeline_mao_esquerda = 0
54 38 timeline_mao_direita = 0
55 39  
56   - # setar pose padrao inicial em todos os bones ("location" e "rotation_quaternion")
57   - endFrame += pose_default(util.dict_interpolation["inicial"])
58   -
59 40 for i in range(0, len(js_movimentos)):
60 41 timeline_facial = endFrame
61 42 timeline_mao_esquerda = endFrame
... ... @@ -100,18 +81,17 @@ def main():
100 81 endFrame += frame_jump
101 82  
102 83 # setar pose padrao final em todos os bones (location e rotation)
103   - endFrame = pose_default(endFrame, frame_jump)
104   - endFrame += util.dict_interpolation["final"]
  84 + endFrame = util.pose_default(endFrame, frame_jump)
105 85  
106 86 sinal = str(js_input["sinal"])
107 87 user_id = str(js_input["userId"])
108 88 directory = os.path.join(getcwd, "users", user_id)
109 89  
110 90 # exporta .blend
111   - util.export_blend(directory, sinal + ".blend", 0, 0, endFrame)
  91 + # util.export_blend(directory, sinal + ".blend", 0, 0, endFrame)
112 92  
113 93 # exporta .json
114   - util.export_json(js_input, directory, sinal + ".json")
  94 + # util.export_json(js_input, directory, sinal + ".json")
115 95  
116 96 # exporta .mp4
117 97 util.render_sign(user_id, sinal, endFrame)
... ...
moves.py
... ... @@ -168,7 +168,8 @@ def alisar_diagonal(boneIK, to_right, repetition, initialFrame = 18, frameJump =
168 168 # Obs.: A velocidade do movimento vai ser a relacao entre tamanho do raio e o periodo
169 169 # quanto maior o periodo mais keyframes
170 170 # quanto menor o raio mais rapido
171   -# exemplos:
  171 +
  172 +# circular:
172 173 # raio: "pequeno" raio = 0.5, velocidade: "rapido" periodo = 25
173 174 # raio: "pequeno" raio = 0.5, velocidade: "normal" periodo = 35
174 175 # raio: "pequeno" raio = 0.5, velocidade: "lento" periodo = 45
... ... @@ -189,27 +190,28 @@ def circular(js_movement, current_frame, frame_jump, is_right_hand, is_semicircu
189 190 "normal": 45,
190 191 "rapido": 35
191 192 }
192   - ray = dict_ray[js_movement["raio"]]
193   - period = dict_period[js_movement["velocidade"]]
194   - opposite_side = js_movement["lado_oposto"]
195   - reverse_way = js_movement["sentido_inverso"]
  193 + dict_calc = {
  194 + "pequeno": -10,
  195 + "normal": 0,
  196 + "grande": 10
  197 + }
  198 + dict_axis = {
  199 + "frente-esquerda": [2, 0, 1],
  200 + "frente-cima": [2, 1, 0],
  201 + "esquerda-cima": [0, 1, 2]
  202 + }
196 203 actions = util.right_hand_actions if (is_right_hand) else util.left_hand_actions
197   - hand_param = read_hand_param(js_movement)
198 204 bones = util.right_bones_conf if (is_right_hand) else util.left_bones_conf
  205 + hand_param = read_hand_param(js_movement)
199 206 ik = bpy.context.object.pose.bones["ik_FK.R" if (is_right_hand) else "ik_FK.L"]
200   - if (js_movement["velocidade"] == "lento"):
201   - period += 10
202   - elif (js_movement["velocidade"] == "rapido"):
203   - period -= 10
204   - if (js_movement["plano"] == "frente-esquerda"):
205   - x, y = 2, 0
206   - elif (js_movement["plano"] == "frente-cima"):
207   - x, y = 2, 1
208   - else:
209   - x, y = 0, 1
  207 + opposite_side = js_movement["lado_oposto"]
  208 + period = dict_period[js_movement["velocidade"]] + dict_calc[js_movement["raio"]]
  209 + ray = dict_ray[js_movement["raio"]]
  210 + reverse_way = js_movement["sentido_inverso"]
  211 + x = dict_axis[js_movement["plano"]][0]
  212 + y = dict_axis[js_movement["plano"]][1]
  213 + #z = dict_axis[js_movement["plano"]][2]
210 214 k = round(period / 2) if (opposite_side) else 0
211   - x %= 3
212   - y %= 3
213 215 if (reverse_way):
214 216 tmp = x
215 217 x = y
... ... @@ -217,9 +219,7 @@ def circular(js_movement, current_frame, frame_jump, is_right_hand, is_semicircu
217 219 util.setPose(actions, hand_param, [current_frame], bones, False)
218 220 util.keyframe_insert(bones, "location", current_frame, False, False)
219 221 ik_loc = [ik.location[0], ik.location[1], ik.location[2]]
220   - limit = period + k - 1
221   - if (is_semicircular):
222   - limit = round(period / 2) + k
  222 + limit = round(period / 2) + k if (is_semicircular) else period + k
223 223 for i in range(k, limit + 1):
224 224 bpy.context.object.pose_library = bpy.data.actions[util.conf_direita_id if (is_right_hand) else util.conf_esquerda_id]
225 225 bpy.ops.poselib.apply_pose(pose_index = hand_param[0])
... ... @@ -228,43 +228,59 @@ def circular(js_movement, current_frame, frame_jump, is_right_hand, is_semicircu
228 228 util.keyframe_insert(bones, "rotation_quaternion", current_frame, False)
229 229 ik.location[x] = ik_loc[x] + (ray * math.cos(i / period * (2 * math.pi)))
230 230 ik.location[y] = ik_loc[y] + (ray * math.sin(i / period * (2 * math.pi)))
231   - util.keyframe_insert(ik, "location", current_frame)
  231 + util.keyframe_insert(ik, "location", current_frame, False)
232 232 util.keyframe_insert(ik, "rotation_quaternion", current_frame, False)
233 233 current_frame += 1
234   - return current_frame
  234 + return current_frame + frame_jump
  235 +
  236 +# 'lado_oposto' true inverte o sentido do vetor direcional
  237 +# 'sentido_inverso' true inverte o sentido do plano
235 238  
  239 +# helicoidal
  240 +# raio: "pequeno" raio = 0.2, velocidade: "rapido" periodo = 25
  241 +# raio: "pequeno" raio = 0.2, velocidade: "normal" periodo = 35
  242 +# raio: "pequeno" raio = 0.2, velocidade: "lento" periodo = 45
  243 +# raio: "normal" raio = 0.6, velocidade: "rapido" periodo = 35
  244 +# raio: "normal" raio = 0.6, velocidade: "normal" periodo = 45
  245 +# raio: "normal" raio = 0.6, velocidade: "lento" periodo = 55
  246 +# raio: "grande" raio = 0.8, velocidade: "rapido" periodo = 45
  247 +# raio: "grande" raio = 0.8, velocidade: "normal" periodo = 55
  248 +# raio: "grande" raio = 0.8, velocidade: "lento" periodo = 65
236 249 def helicoidal(js_movement, current_frame, frame_jump, is_right_hand):
237 250 dict_ray = {
238   - "pequeno": 0.5,
239   - "normal": 1.0,
240   - "grande": 1.5
  251 + "pequeno": 0.2,
  252 + "normal": 0.6,
  253 + "grande": 0.8
241 254 }
242 255 dict_period = {
243 256 "lento": 55,
244 257 "normal": 45,
245 258 "rapido": 35
246 259 }
247   - ray = dict_ray[js_movement["raio"]]
248   - period = dict_period[js_movement["velocidade"]]
249   - opposite_side = js_movement["lado_oposto"]
250   - reverse_way = js_movement["sentido_inverso"]
  260 + dict_calc = {
  261 + "pequeno": -10,
  262 + "normal": 0,
  263 + "grande": 10
  264 + }
  265 + dict_axis = {
  266 + "frente-esquerda": [2, 0, 1],
  267 + "frente-cima": [2, 1, 0],
  268 + "esquerda-cima": [0, 1, 2]
  269 + }
251 270 actions = util.right_hand_actions if (is_right_hand) else util.left_hand_actions
252   - hand_param = read_hand_param(js_movement)
253 271 bones = util.right_bones_conf if (is_right_hand) else util.left_bones_conf
  272 + hand_param = read_hand_param(js_movement)
254 273 ik = bpy.context.object.pose.bones["ik_FK.R" if (is_right_hand) else "ik_FK.L"]
255   - if (js_movement["velocidade"] == "lento"):
256   - period += 10
257   - elif (js_movement["velocidade"] == "rapido"):
258   - period -= 10
259   - if (js_movement["plano"] == "frente-esquerda"):
260   - x, y, z = 2, 0, 1
261   - elif (js_movement["plano"] == "frente-cima"):
262   - x, y, z = 2, 1, 0
263   - else:
264   - x, y, z = 0, 1, 2
265   - k = round(period / 2) if (opposite_side) else 0
266   - x %= 3
267   - y %= 3
  274 + opposite_side = js_movement["lado_oposto"]
  275 + period = dict_period[js_movement["velocidade"]] + dict_calc[js_movement["raio"]]
  276 + ray = dict_ray[js_movement["raio"]]
  277 + reverse_way = js_movement["sentido_inverso"]
  278 + # print('raio: "%s" raio = %.1f, velocidade: "%s" periodo = %d' % (js_movement["raio"], ray, js_movement["velocidade"], period))
  279 + x = dict_axis[js_movement["plano"]][0]
  280 + y = dict_axis[js_movement["plano"]][1]
  281 + z = dict_axis[js_movement["plano"]][2]
  282 + # print("x = %.1f y = %.1f z = %.1f" % (x, y, z))
  283 + k = 0
268 284 if (reverse_way):
269 285 tmp = x
270 286 x = y
... ... @@ -272,7 +288,7 @@ def helicoidal(js_movement, current_frame, frame_jump, is_right_hand):
272 288 util.setPose(actions, hand_param, [current_frame], bones, False)
273 289 util.keyframe_insert(bones, "location", current_frame, False, False)
274 290 ik_loc = [ik.location[0], ik.location[1], ik.location[2]]
275   - limit = period + k - 1
  291 + limit = period + k
276 292 for i in range(k, 2 * (limit + 1)):
277 293 bpy.context.object.pose_library = bpy.data.actions[util.conf_direita_id if (is_right_hand) else util.conf_esquerda_id]
278 294 bpy.ops.poselib.apply_pose(pose_index = hand_param[0])
... ... @@ -281,11 +297,14 @@ def helicoidal(js_movement, current_frame, frame_jump, is_right_hand):
281 297 util.keyframe_insert(bones, "rotation_quaternion", current_frame, False)
282 298 ik.location[x] = ik_loc[x] + (ray * math.cos(i / period * (2 * math.pi)))
283 299 ik.location[y] = ik_loc[y] + (ray * math.sin(i / period * (2 * math.pi)))
284   - ik.location[z] = ik_loc[z] + (i / period) - ray
285   - util.keyframe_insert(ik, "location", current_frame)
  300 + distance_inc = (i / period) - ray
  301 + if (opposite_side):
  302 + distance_inc = -distance_inc
  303 + ik.location[z] = ik_loc[z] + distance_inc
  304 + util.keyframe_insert(ik, "location", current_frame, False)
286 305 util.keyframe_insert(ik, "rotation_quaternion", current_frame, False)
287 306 current_frame += 1
288   - return current_frame
  307 + return current_frame + frame_jump
289 308  
290 309 def pontual(js_movement, current_frame, frame_jump, is_right_hand):
291 310 hand_param = read_hand_param(js_movement)
... ... @@ -315,55 +334,59 @@ def semicircular(js_movement, current_frame, frame_jump, is_right_hand):
315 334 return circular(js_movement, current_frame, frame_jump, is_right_hand, True)
316 335  
317 336 def senoidal(js_movement, current_frame, frame_jump, is_right_hand):
318   - dict_ray = {
319   - "pequeno": 0.5,
320   - "normal": 1.0,
321   - "grande": 1.5
  337 + dict_wave = {
  338 + "pequeno": 0.1,
  339 + "normal": 0.2,
  340 + "grande": 0.3
322 341 }
323   - dict_period = {
324   - "lento": 55,
325   - "normal": 45,
326   - "rapido": 35
  342 + dict_distance_inc = {
  343 + "pequeno": 0.005,
  344 + "normal": 0.010,
  345 + "grande": 0.015
327 346 }
328   - ray = dict_ray[js_movement["raio"]]
329   - period = dict_period[js_movement["velocidade"]]
330   - opposite_side = js_movement["lado_oposto"]
331   - reverse_way = js_movement["sentido_inverso"]
  347 + dict_speed = {
  348 + "rapido": 2,
  349 + "normal": 3,
  350 + "lento": 4
  351 + }
  352 + dict_axis = {
  353 + "esquerda": {
  354 + "frente-tras": [0, 2, 1],
  355 + "cima-baixo": [0, 1, 2]
  356 + },
  357 + "cima": {
  358 + "frente-tras": [1, 2, 0],
  359 + "esquerda-direita": [1, 0, 2]
  360 + },
  361 + "frente": {
  362 + "esquerda-direita": [2, 0, 1],
  363 + "cima-baixo": [2, 1, 0]
  364 + }
  365 + }
  366 + axis_dir = dict_axis[js_movement["direcao"]][js_movement["plano_deslocamento"]][0]
  367 + axis_sin = dict_axis[js_movement["direcao"]][js_movement["plano_deslocamento"]][1]
  368 + reverse_way = js_movement["direcao_oposta"]
  369 + distance_inc = dict_distance_inc[js_movement["distancia"]]
  370 + # TODO adaptar velocidade
  371 + # speed = dict_speed[js_movement["velocidade"]]
  372 + wave_len = dict_wave[js_movement["tamanho_onda"]]
332 373 actions = util.right_hand_actions if (is_right_hand) else util.left_hand_actions
333   - hand_param = read_hand_param(js_movement)
334 374 bones = util.right_bones_conf if (is_right_hand) else util.left_bones_conf
  375 + hand_param = read_hand_param(js_movement)
335 376 ik = bpy.context.object.pose.bones["ik_FK.R" if (is_right_hand) else "ik_FK.L"]
336   - if (js_movement["velocidade"] == "lento"):
337   - period += 10
338   - elif (js_movement["velocidade"] == "rapido"):
339   - period -= 10
340   - if (js_movement["plano"] == "frente-esquerda"):
341   - x, y, z = 2, 0, 1
342   - elif (js_movement["plano"] == "frente-cima"):
343   - x, y, z = 2, 1, 0
344   - else:
345   - x, y, z = 0, 1, 2
346   - k = round(period / 2) if (opposite_side) else 0
347   - x %= 3
348   - y %= 3
349   - if (reverse_way):
350   - tmp = x
351   - x = y
352   - y = tmp
353 377 util.setPose(actions, hand_param, [current_frame], bones, False)
354 378 util.keyframe_insert(bones, "location", current_frame, False, False)
355 379 ik_loc = [ik.location[0], ik.location[1], ik.location[2]]
356   - limit = period + k - 1
357   - for i in range(k, 2 * (limit + 1)):
358   - bpy.context.object.pose_library = bpy.data.actions[util.conf_direita_id if (is_right_hand) else util.conf_esquerda_id]
  380 + pose_library = bpy.data.actions[util.conf_direita_id if (is_right_hand) else util.conf_esquerda_id]
  381 + for i in range(0, 100):
  382 + bpy.context.object.pose_library = pose_library
359 383 bpy.ops.poselib.apply_pose(pose_index = hand_param[0])
360 384 bpy.context.object.pose_library = None
361 385 util.keyframe_insert(bones, "location", current_frame, False)
362 386 util.keyframe_insert(bones, "rotation_quaternion", current_frame, False)
363   - ik.location[x] = ik_loc[x] + (ray * math.cos(i / period * (2 * math.pi)))
364   - ik.location[y] = ik_loc[y] + (ray )#* math.sin(i / period * (2 * math.pi)))
365   - #ik.location[z] = ik_loc[z] + (i / period) - ray
366   - util.keyframe_insert(ik, "location", current_frame)
  387 + ik.location[axis_dir] += -distance_inc if (reverse_way) else distance_inc
  388 + ik.location[axis_sin] = ik_loc[axis_sin] + math.sin(i * wave_len)
  389 + util.keyframe_insert(ik, "location", current_frame, False)
367 390 util.keyframe_insert(ik, "rotation_quaternion", current_frame, False)
368 391 current_frame += 1
369   - return current_frame
370 392 \ No newline at end of file
  393 + return current_frame + frame_jump
... ...
util.py
... ... @@ -22,11 +22,9 @@ dict_bones = {
22 22 }
23 23  
24 24 dict_interpolation = {
25   - "inicial": 20,
26 25 "lento": 15,
27 26 "normal": 10,
28 27 "rapido": 5,
29   - "final": 20
30 28 }
31 29  
32 30 # Movimento coçar - Índices de poses
... ... @@ -60,6 +58,10 @@ left_bones_conf = dict_bones[conf_esquerda_id] + dict_bones[pa_esquerda_id] + di
60 58  
61 59 last_keyframe_dict = {}
62 60  
  61 +def pose_default(current_frame, frame_jump):
  62 + setPose(all_actions, [0, 0, 0, 0, 0, 0, 0], [current_frame], all_bones, False)
  63 + return current_frame + frame_jump
  64 +
63 65 def select_bones(bones = bpy.context.object.pose.bones):
64 66 if (isinstance(bones, int) or isinstance(bones, str)):
65 67 bpy.context.object.pose.bones[bones].bone.select = True
... ...