From e48ef0c6f4ac799071121415883b3eb24cafdcb9 Mon Sep 17 00:00:00 2001 From: André Araújo Date: Tue, 28 Jul 2015 23:51:57 -0300 Subject: [PATCH] Adiciona movimento circular otimizado e remove o antigo, adiciona argumento '--' a linha de comando do controller para evitar que o blender interprete o argumento JSON como path para um arquivo --- .fuse_hidden000003cf00000002 | 17 +++++++++++++++++ Makefile | 4 ++-- __init__.py | 8 ++++++++ avatar_cartoon_v2.74.blend | Bin 6973752 -> 0 bytes controller.py | 6 +++--- libras.py | 26 ++++++++++++++------------ moves.py | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7 files changed, 115 insertions(+), 207 deletions(-) create mode 100644 .fuse_hidden000003cf00000002 diff --git a/.fuse_hidden000003cf00000002 b/.fuse_hidden000003cf00000002 new file mode 100644 index 0000000..c551990 --- /dev/null +++ b/.fuse_hidden000003cf00000002 @@ -0,0 +1,17 @@ +[2015-07-28 22:23:30.895] ERROR: + File name: libras.py + Function name: + Line code: 23 + Type exception: ValueError + Message: Expecting value: line 1 column 1 (char 0) +[2015-07-28 22:25:38.946] INFO: All frames: 163 +[2015-07-28 22:28:30.474] INFO: Rename: '/media/truecrypt1/Lavid/wikilibras/tmp/wikilibras-core/users/4/teste circular_0001-0163.mp4' to: '/media/truecrypt1/Lavid/wikilibras/tmp/wikilibras-core/users/4/teste circular.mp4' +[2015-07-28 23:17:31.963] INFO: All frames: 163 +[2015-07-28 23:18:15.833] INFO: Rename: '/media/truecrypt1/Lavid/wikilibras/tmp/wikilibras-core/users/4/teste circular_0001-0163.mp4' to: '/media/truecrypt1/Lavid/wikilibras/tmp/wikilibras-core/users/4/teste circular.mp4' +[2015-07-28 23:35:35.942] INFO: All frames: 163 +[2015-07-28 23:35:38.782] ERROR: + File name: controller.py + Function name: + Line code: 18 + Type exception: KeyboardInterrupt + Message: diff --git a/Makefile b/Makefile index 6b8afcd..4f8f8b5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -BLEND = avatar_cartoon_v2.70.blend +BLEND = avatar_cartoon_v2.74.blend CONTROLLER = controller.py MAIN = libras.py # Circular: ['circular', x, x, Raio=1, Voltas=3 CfM=0, PAr=80, Ori=0] @@ -20,7 +20,7 @@ py: @echo "[\33[32;5mExecutando\33[m]\33[34;5m $(PYTHON) "$(CONTROLLER)" {JSON} ...\33[m"; $(PYTHON) "$(CONTROLLER)" $(JSON) && echo "$(DONE)" || echo "$(FAIL)" bpy: - @echo "[\33[32;5mExecutando\33[m]\33[34;5m $(BLENDER) -b "$(BLEND)" -P "$(MAIN)" {JSON} ...\33[m"; $(BLENDER) -b "$(BLEND)" -P "$(MAIN)" $(JSON) && echo "$(DONE)" || echo "$(FAIL)" + @echo "[\33[32;5mExecutando\33[m]\33[34;5m $(BLENDER) -b "$(BLEND)" -P "$(MAIN)" -- {JSON} ...\33[m"; $(BLENDER) -b "$(BLEND)" -P "$(MAIN)" -- $(JSON) && echo "$(DONE)" || echo "$(FAIL)" help: @echo "" diff --git a/__init__.py b/__init__.py index e69de29..eb72ed6 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1,8 @@ + +__all__ = ( + "bmesh_collision" + "controller", + "libras", + "moves", + "pyutil", + "util") diff --git a/avatar_cartoon_v2.74.blend b/avatar_cartoon_v2.74.blend index 4e6cbc8..5b6ff51 100755 Binary files a/avatar_cartoon_v2.74.blend and b/avatar_cartoon_v2.74.blend differ diff --git a/controller.py b/controller.py index e50a365..b5e5432 100644 --- a/controller.py +++ b/controller.py @@ -8,14 +8,14 @@ getcwd = dirname(abspath(__file__)) from pyutil import printStackTrace -blend_path = join(getcwd, "avatar_cartoon_v2.70.blend") +blend_path = join(getcwd, "avatar_cartoon_v2.74.blend") main_path = join(getcwd, "libras.py") result = 0 try: # Caso seja necessário gravar logs do blender utilizar a linha de código abaixo - # result = call(['blender', '-b', blend_path, '-P', main_path, argv[1]], stdout = open('bpy.log', 'w')) - result = call(['blender', '-b', blend_path, '-P', main_path, argv[1]]) + # result = call(['blender', '-b', blend_path, '-P', main_path, '--', argv[1]], stdout = open('bpy.log', 'w')) + result = call(['blender', '-b', blend_path, '-P', main_path, '--', argv[1]]) except: result = printStackTrace(__file__) diff --git a/libras.py b/libras.py index 517e5fb..03f693d 100644 --- a/libras.py +++ b/libras.py @@ -20,7 +20,7 @@ from pyutil import printStackTrace # tenta decodificar o argumento JSON recebido try: - json_input = json.loads(argv[5]) + json_input = json.loads(argv[6]) except Exception: printStackTrace(__file__) exit(1) @@ -71,14 +71,14 @@ def configureHands(): if(move in ["circular", "semicircular"]): orientation, direction, radius, laps = json_input[hands[i]][1:5] - endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) + #endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) elif(move == "retilineo"): setHandConfiguration(actions[i], json_input[hands[i]][-6:-3], util.hands_default_frames, bones_[i]) setHandConfiguration(actions[i], handParam, util.hands_frames_retilineo, bones_[i]) elif(move == "senoidal"): orientation, direction, radius, laps = json_input[hands[i]][1:5] - endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) + #endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) elif(move == "contato"): endFrame = moves.contato(actions[i], json_input[hands[i]], bones_[i], pose) @@ -89,12 +89,14 @@ def configureFace(): if(json_input["facialExp"] != []): setFaceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) -poseDefault([1]) -configureHands() -configureFace() -poseDefault([endFrame + 15]) - -# Default Pose -print("Total frames: %.3i" % (endFrame)) - -util.render_sign(json_input["userId"], json_input["signName"], 1, endFrame + 25) \ No newline at end of file +def main(): + poseDefault([1]) + configureHands() + configureFace() + poseDefault([endFrame + 15]) + # Default Pose + print("Total frames: %.3i" % (endFrame)) + util.render_sign(json_input["userId"], json_input["signName"], 1, endFrame + 25) + +if __name__ == "__main__": + main() diff --git a/moves.py b/moves.py index a09e849..9f219bb 100644 --- a/moves.py +++ b/moves.py @@ -7,7 +7,7 @@ import util def contato(action, input_hand, bones, pose, initialFrame = 18): currentFrame = initialFrame contact_type = input_hand[1] - + if (contact_type == "alisar"): currentFrame = alisar(action, input_hand, pose, bones, initialFrame) elif (contact_type == "cocar"): @@ -23,19 +23,19 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree endFrame = initialFrame + 2 * frameJump handParam = input_hand[-3:] lado = "R" if util.rightBonesConf == bones else "L" - + bnAntBraco = bpy.context.object.pose.bones["BnAntBraco." + lado] bnAntBraco.bone.select = True util.apply_rotation(bnAntBraco, "Z", currentFrame, endFrame, bnAntBracoDegree) currentFrame += frameJump util.apply_rotation(bnAntBraco, "Z", currentFrame, endFrame, (-1)*(bnAntBracoDegree+1)) bnAntBraco.bone.select = False - + currentFrame = initialFrame util.setPose(action, handParam, [currentFrame], bones) bnMao = bpy.context.object.pose.bones["BnMao." + lado] bnMao.bone.select = True - util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) + util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) currentFrame += frameJump util.apply_rotation(bnMao, "Y", currentFrame, endFrame, (-2)*bnMaoDegree) currentFrame += frameJump @@ -55,18 +55,18 @@ def tocar(action, input_hand, bones, pose, initialFrame = 18, degree = 30, frame bnMao = bpy.context.object.pose.bones[lado] bnMao.bone.select = True currentFrame += frameJump - util.apply_rotation(bnMao, "X", currentFrame, endFrame, -degree) + util.apply_rotation(bnMao, "X", currentFrame, endFrame, -degree) currentFrame += frameJump util.apply_rotation(bnMao, "X", currentFrame, endFrame, degree) util.setPose([action[0]], [handParam[0]], [currentFrame], bones) currentFrame += frameJump bnMao.bone.select = False return currentFrame - + def cocar(action, input_hand, bones, initialFrame = 18, repetition = 2, frameJump = 6): - currentFrame = initialFrame + currentFrame = initialFrame pa_index = input_hand[-1] - + for i in range(0, repetition): util.setPose(action, [util.cocar_mao_aberta_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) currentFrame += frameJump @@ -80,7 +80,7 @@ def alisar(action, input_hand, pose, bones, initialFrame = 18, frameJump = 10, w orientation, repetition = input_hand[2:4] handParam = input_hand[-3:] util.setPose(action, handParam, util.hands_default_frames, bones) - + if (orientation == "perpendicular"): currentFrame = alisar_xy(pose, 1, repetition, initialFrame, frameJump, width) elif (orientation == "paralelo"): @@ -89,16 +89,16 @@ def alisar(action, input_hand, pose, bones, initialFrame = 18, frameJump = 10, w currentFrame = alisar_diagonal(pose, True, repetition, initialFrame, frameJump, width) elif (orientation == "diagonal-esquerda"): currentFrame = alisar_diagonal(pose, False, repetition, initialFrame, frameJump, width) - + util.setPose(action, handParam, [currentFrame], bones) return currentFrame def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump = 10, width = 0.25): currentFrame = initialFrame center = pose.location.x, pose.location.y, pose.location.z - + for i in range(0, repetition): - pose.location[orientation_index] = center[orientation_index] - width + pose.location[orientation_index] = center[orientation_index] - width util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump pose.location[orientation_index] = center[orientation_index] + width @@ -109,25 +109,27 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 10, width = 0.25): currentFrame = initialFrame center = pose.location.x, pose.location.y, pose.location.z - + for i in range(0, repetition): pose.location[0] = center[0] - width if to_right else center[0] - width pose.location[1] = center[1] - width if to_right else center[1] + width - + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump - + pose.location[0] = center[0] + width if to_right else center[0] + width pose.location[1] = center[1] + width if to_right else center[1] - width util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump return currentFrame +""" +# descontinuada: circular_or_semiCircular def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None): center = pose.location.x, pose.location.y, pose.location.z if(orientation == 'perpendicular'): if(direction == 'horario'): - endFrame = locationCircular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame, turn) + endFrame = circular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame, turn) else: endFrame = locationCircular(center, radius, 0, 1, 2, pose, 0, laps, intensity, initialFrame, turn) elif(orientation == 'paralelo'): @@ -141,177 +143,56 @@ def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensi else: endFrame = locationCircular(center, radius, 0, 2, 1, pose, 0, laps, intensity, initialFrame, turn) return endFrame - -# center[3]: float vector (posição xyz centro) -# radius: float (distancia do centro) -# i_axis: int (indice do eixo i [0 | 1 | 2]) -# j_axis: int (indice do eixo j [0 | 1 | 2]) -# k_axis: int (indice do eixo k [0 | 1 | 2]) -def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPosition, laps, frameJump = 5, initialFrame = 18, turn = None): - sqrt22 = radius * (math.sqrt(2) / 2) - rad2 = (radius/2) - currentFrame = initialFrame - for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1): - if ((l % 8) == 0): - pose.location[i_axis] = center[i_axis] + radius - pose.location[j_axis] = center[j_axis] - pose.location[k_axis] = center[k_axis] - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - if ((l % 8) == 1): - pose.location[i_axis] = center[i_axis] + sqrt22 - pose.location[j_axis] = center[j_axis] + sqrt22 - pose.location[k_axis] = center[k_axis] - if(turn == 1): - pose.location[i_axis] = center[i_axis] + sqrt22 - pose.location[j_axis] = center[j_axis] + rad2 - pose.location[k_axis] = center[k_axis] - rad2 - elif(turn == -1): - pose.location[i_axis] = center[i_axis] + sqrt22 - pose.location[j_axis] = center[j_axis] + rad2 - pose.location[k_axis] = center[k_axis] + rad2 - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - if ((l % 8) == 2): - pose.location[i_axis] = center[i_axis] - pose.location[j_axis] = center[j_axis] + radius - pose.location[k_axis] = center[k_axis] - if(turn == 1): - pose.location[j_axis] = center[j_axis] + sqrt22 - pose.location[k_axis] = center[k_axis] - sqrt22 - elif(turn == -1): - pose.location[j_axis] = center[j_axis] + sqrt22 - pose.location[k_axis] = center[k_axis] + sqrt22 - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - if ((l % 8) == 3): - pose.location[i_axis] = center[i_axis] - sqrt22 - pose.location[j_axis] = center[j_axis] + sqrt22 - pose.location[k_axis] = center[k_axis] - if(turn == 1): - pose.location[i_axis] = center[i_axis] - sqrt22 - pose.location[j_axis] = center[j_axis] + rad2 - pose.location[k_axis] = center[k_axis] - rad2 - elif(turn == -1): - pose.location[i_axis] = center[i_axis] - sqrt22 - pose.location[j_axis] = center[j_axis] + rad2 - pose.location[k_axis] = center[k_axis] + rad2 - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - - if ((l % 8) == 4): - pose.location[i_axis] = center[i_axis] - radius - pose.location[j_axis] = center[j_axis] - pose.location[k_axis] = center[k_axis] - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - - if ((l % 8) == 5): - pose.location[i_axis] = center[i_axis] - sqrt22 - pose.location[j_axis] = center[j_axis] - sqrt22 - pose.location[k_axis] = center[k_axis] - if(turn == 1): - pose.location[i_axis] = center[i_axis] - sqrt22 - pose.location[j_axis] = center[j_axis] - rad2 - pose.location[k_axis] = center[k_axis] + rad2 - elif(turn == -1): - pose.location[i_axis] = center[i_axis] - sqrt22 - pose.location[j_axis] = center[j_axis] - rad2 - pose.location[k_axis] = center[k_axis] - rad2 - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - - if ((l % 8) == 6): - pose.location[i_axis] = center[i_axis] - pose.location[j_axis] = center[j_axis] - radius - pose.location[k_axis] = center[k_axis] - if(turn == 1): - pose.location[j_axis] = center[j_axis] - sqrt22 - pose.location[k_axis] = center[k_axis] + sqrt22 - elif(turn == -1): - pose.location[j_axis] = center[j_axis] - sqrt22 - pose.location[k_axis] = center[k_axis] - sqrt22 - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - - if ((l % 8) == 7): - pose.location[i_axis] = center[i_axis] + sqrt22 - pose.location[j_axis] = center[j_axis] - sqrt22 - pose.location[k_axis] = center[k_axis] - if(turn == 1): - pose.location[i_axis] = center[i_axis] + sqrt22 - pose.location[j_axis] = center[j_axis] - rad2 - pose.location[k_axis] = center[k_axis] + rad2 - elif(turn == -1): - pose.location[i_axis] = center[i_axis] + sqrt22 - pose.location[j_axis] = center[j_axis] - rad2 - pose.location[k_axis] = center[k_axis] - rad2 - util.keyframe_insert(pose, 'location', currentFrame) - currentFrame += frameJump - currentFrame -= frameJump - return currentFrame - -def locationHelicoidal(center, startRadius, incRadius, x, y, z,pose, currentLoc, laps, frameJump): - sqrt22 = radius * math.sqrt(2) / 2 - allLaps = math.floor(8 * laps) + 1 - - #for i in range(currentLoc, currentLoc + math.floor(8 * laps) + 1): - for i in range(currentLoc, currentLoc + allLaps): - print("All Laps:", allLaps) - if ((i % 8) == 0 ): - pose.location[x] = center[x] + radius - pose.location[y] = center[y] - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 1): - pose.location[x] = center[x] + sqrt22 - pose.location[y] = center[y] + sqrt22 - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 2): - pose.location[x] = center[x] - pose.location[y] = center[y] + radius - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 3): - pose.location[x] = center[x] - sqrt22 - pose.location[y] = center[y] + sqrt22 - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 4): - pose.location[x] = center[x] - radius - pose.location[y] = center[y] - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 5): - pose.location[x] = center[x] - sqrt22 - pose.location[y] = center[y] - sqrt22 - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 6): - pose.location[x] = center[x] - pose.location[y] = center[y] - radius - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - if ((i % 8) == 7): - pose.location[x] = center[x] + sqrt22 - pose.location[y] = center[y] - sqrt22 - pose.location[z] += incRadius /allLaps - util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) - bpy.context.scene.frame_end += frameJump - - bpy.context.scene.frame_end -= frameJump +""" + +# Obs.: A velocidade do movimento vai ser a relacao entre tamanho do raio e o periodo +# quanto maior o periodo mais keyframes +# quanto menor o raio mais rapido +# exemplos: +# raio: "pequeno" raio = 0.5, velocidade: "rapido" periodo = 25 +# raio: "pequeno" raio = 0.5, velocidade: "normal" periodo = 35 +# raio: "pequeno" raio = 0.5, velocidade: "lento" periodo = 45 +# raio: "normal" raio = 1.0, velocidade: "rapido" periodo = 35 +# raio: "normal" raio = 1.0, velocidade: "normal" periodo = 45 +# raio: "normal" raio = 1.0, velocidade: "lento" periodo = 55 +# raio: "grande" raio = 1.5, velocidade: "rapido" periodo = 45 +# raio: "grande" raio = 1.5, velocidade: "normal" periodo = 55 +# raio: "grande" raio = 1.5, velocidade: "lento" periodo = 65 +# @param obj: (objeto) bone, mesh, e.g. +# @param itFrame: (int) posicao onde o primeiro keyframe vai ser inserido +# @param raio: (int) raio da circunferencia +# @param periodo: (int) quantidade de keyframes necessarios para completar uma volta completa +# @param x: (int) in [0,1,2] define qual eixo vai variar no seno (0 = eixo X, 1 = eixo Y, 2 = eixo Z) +# @param y: (int) in [0,1,2] define qual eixo vai variar no cosseno (0 = eixo X, 1 = eixo Y, 2 = eixo Z) +# @param ladoOposto: (bool) inverte o lado da primeira posicao (pode ser util em alguns casos para espelhar) +# @param inverterDirecao (bool) inverte o sentido do movimento (horario para anti-horario) +def circular(obj, itFrame, raio, periodo, x = 0, y = 1, ladoOposto = False, inverterDirecao = False): + # limita inferiormente + if (periodo < 16): + periodo = 16 + # limita superiormente + elif (periodo > 360): + periodo = 360 + # muda lado inicial + if (ladoOposto): + k = round(periodo / 2) + else: + k = 0 + # evita estouro dos indices + x %= 3 + y %= 3 + # inverte direcao do movimento + if (inverterDirecao): + tmp = x + x = y + y = tmp + # copia posicao inicial para transladar + loc = [obj.location[0], obj.location[1], obj.location[2]] + for i in range(k, periodo + k): + # pequena otimizacao para reduzir a quantidade de keyframes + if (itFrame % 2 == 0): + obj.location[x] = loc[x] + (raio * math.cos(i / periodo * (2 * math.pi))) + obj.location[y] = loc[y] + (raio * math.sin(i / periodo * (2 * math.pi))) + obj.keyframe_insert(data_path='location', frame=itFrame, index=-1) + itFrame += 1 + return periodo - 1 -- libgit2 0.21.2