From b698cccd1d1b90fd994577bab6f78eae55968e5c Mon Sep 17 00:00:00 2001 From: Adabriand Furtado Date: Sat, 21 Mar 2015 19:00:08 -0300 Subject: [PATCH] Adiciona movimento de contato do tipo Alisar --- libras.py | 50 ++++++++++++++++++++++++++++++-------------------- moves.py | 20 ++++++++++++++++++++ util.py | 9 +++++---- 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/libras.py b/libras.py index bd6d4aa..cdec5a2 100644 --- a/libras.py +++ b/libras.py @@ -19,13 +19,13 @@ except Exception: printStackTrace(__file__) exit(1) -# ajusta as configuraçẽs de renderização +# ajusta as configurações de renderização util.outconf() # define a posição dos keyframes -hands_default_frames = [15,18] +hands_default_frames = [15, 18] # define a posição dos keyframes -hands_frames_retilineo = [30,33] +hands_frames_retilineo = [30, 33] # Carrega o objeto presente no avatar armature = bpy.context.scene.objects.get('Armature.001') @@ -41,7 +41,7 @@ def setPose(actions, parametesConf, positionFrames, bones): for l in range(len(actions)): armature.pose_library = bpy.data.actions[actions[l]] for x in range(len(positionFrames)): - bpy.ops.poselib.apply_pose(pose_index= parametesConf[l]) + bpy.ops.poselib.apply_pose(pose_index = parametesConf[l]) for i in range(0, (len(bones))): armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x]) armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) @@ -50,15 +50,16 @@ def setPose(actions, parametesConf, positionFrames, bones): def poseDefault(positionFrames, bones): setPose([0], [0], positionFrames, bones) -# Função responsável por setar as configuraçẽs das mãos -def generationConfigurations(actions, handParam, positionFrames, bones): +# Função responsável por setar as configurações das mãos +def setHandConfiguration(actions, handParam, positionFrames, bones): setPose(actions, handParam, positionFrames, bones) -def faceConfiguration(handParam, positionFrames, bones): - # Função responsável por setar a configuração da face +# Função responsável por setar a configuração da face +def setFaceConfiguration(handParam, positionFrames, bones): setPose([7], handParam, positionFrames, bones) -initialFrame, endFrame = 15, util.get_endFrame(json_input,hands_frames_retilineo) +# Sugestao: Alguma forma de uniformizar o calculo do endFrame (atualizado aqui e no movimento circular) +initialFrame, endFrame = 15, util.get_endFrame(json_input, hands_frames_retilineo) #------------------ Configurações------------------------------ @@ -75,33 +76,42 @@ def configureHands(): if(json_input[hands[i]] != []): move = json_input[hands[i]][0] pose = armature.pose.bones[iks[i]] + handParam = json_input[hands[i]][-3:] + if(move == "pontual"): - generationConfigurations(actions[i], json_input[hands[i]][-3:], [15, endFrame], bones_[i]) + setHandConfiguration(actions[i], handParam, hands_default_frames, bones_[i]) else: - generationConfigurations(actions[i], json_input[hands[i]][-3:], hands_default_frames, bones_[i]) + setHandConfiguration(actions[i], handParam, hands_default_frames, bones_[i]) + if(move == "circular" or move == "semicircular"): orientation, direction, radius, laps = json_input[hands[i]][1:5] endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) - generationConfigurations(actions[i], json_input[hands[i]][-3:], [endFrame], bones_[i]) + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) elif(move == "retilineo"): - generationConfigurations(actions[i], json_input[hands[i]][-6:-3], hands_default_frames, bones_[i]) - generationConfigurations(actions[i], json_input[hands[i]][-3:],hands_frames_retilineo, bones_[i]) + setHandConfiguration(actions[i], json_input[hands[i]][-6:-3], hands_default_frames, bones_[i]) + setHandConfiguration(actions[i], handParam, hands_frames_retilineo, bones_[i]) elif(json_input[hands[i]][0] == "senoidal"): orientation, direction, radius, laps = json_input[hands[i]][1:5] endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) - generationConfigurations(actions[i], json_input[hands[i]][-3:], [endFrame], bones_[i]) + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) + elif(json_input[hands[i]][0] == "contato"): + contact_type, orientation, repetition = json_input[hands[i]][1:4] + endFrame = moves.contato(pose, contact_type, orientation, repetition) + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) # Função que inicia a configuração da face def configureFace(): global endFrame if(json_input["facialExp"] != []): # Set face - faceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) + setFaceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) -# Default Pose -print("Total frames: %.3i" % (endFrame)) -poseDefault([1, endFrame + 15], util.allBones) configureHands() configureFace() -util.render_sign(json_input["userId"], json_input["signName"], 1, endFrame + 25) +poseDefault([1, endFrame + 15], util.allBones) + +# 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 diff --git a/moves.py b/moves.py index f8d97dc..6081b56 100644 --- a/moves.py +++ b/moves.py @@ -2,6 +2,26 @@ import math +def contato(pose, contact_type, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.5): + currentFrame = initialFrame + if (contact_type == "alisar"): + currentFrame = alisar(pose, contact_type, orientation, repetition) + return currentFrame + +def alisar(pose, contact_type, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.5): + center = pose.location.x, pose.location.y, pose.location.z + currentFrame = initialFrame + + for i in range(0, repetition): + pose.location.y = center[1] - width + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + currentFrame += frameJump + pose.location.y = center[1] + width + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + currentFrame += frameJump + currentFrame -= frameJump + return currentFrame + 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'): diff --git a/util.py b/util.py index 7c0bfda..b30dd84 100644 --- a/util.py +++ b/util.py @@ -14,7 +14,7 @@ rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, leftBonesConf = [0, 43, 44, 45, 46, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82] # Vetor com indices de cada bone da face -faceBonesConf =[15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] +faceBonesConf = [15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] # Vetor com indices de todos os bones allBones = list(range(len(armature.pose.bones))) @@ -38,19 +38,20 @@ def outconf(): # bpy.context.scene.render.filepath = '/tmp/' def render_sign(userId, signName, beginFrame, endFrame): - bpy.context.scene.render.filepath = "//users//"+ str(userId)+ "//"+ signName + "_" + bpy.context.scene.render.filepath = "//users//" + str(userId)+ "//" + signName + "_" bpy.context.scene.frame_start = beginFrame bpy.context.scene.frame_end = endFrame outFilename = (bpy.context.scene.render.filepath + "%0.4i-%0.4i.mp4" % (bpy.context.scene.frame_start, bpy.context.scene.frame_end)) bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") - file_rename(outFilename, __file__) + #file_rename(outFilename, __file__) bpy.ops.wm.quit_blender() # Função que recupera o frame final do movimento -def get_endFrame(json_input,hands_frames_retilineo): +def get_endFrame(json_input, hands_frames_retilineo): endsFrame = [18] if(json_input["rightHand"] != []): if(json_input["rightHand"][0] == "circular"): + # Sugestao: json_input["rightHand"][4] eh o número de voltas/repeticoes? colocar numa variavel endsFrame.append(int(json_input["rightHand"][4]*8*5+18)) elif(json_input["rightHand"][0] == "semicircular"): endsFrame.append(int(json_input["rightHand"][4]*5*5+18)) -- libgit2 0.21.2