diff --git a/moves.py b/moves.py index c264134..12b350c 100644 --- a/moves.py +++ b/moves.py @@ -3,27 +3,74 @@ import bpy import math import util -from pyutil import log -def contato(action, input_hand, bones, pose, initialFrame = 18, frameJump = 10): +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, frameJump) + currentFrame = alisar(action, input_hand, pose, bones, initialFrame) elif (contact_type == "cocar"): currentFrame = cocar(action, input_hand, bones, initialFrame) + elif (contact_type == "tocar"): + currentFrame = tocar(action, input_hand, bones, initialFrame) + elif (contact_type == "riscar"): + currentFrame = riscar(action, input_hand, bones, initialFrame) return currentFrame -def cocar(action, input_hand, bones, initialFrame = 18, repetition = 2, frameJump = 6): +def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree = 2, bnMaoDegree = 45, frameJump = 10): currentFrame = initialFrame - action[0] = util.movimento_mao_action_index + 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) + currentFrame += frameJump + util.apply_rotation(bnMao, "Y", currentFrame, endFrame, (-2)*bnMaoDegree) + currentFrame += frameJump + util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) + util.setPose([action[0]], [handParam[0]], [currentFrame], bones) + currentFrame += frameJump + bnMao.bone.select = False + return currentFrame + +def tocar(action, input_hand, bones, pose, initialFrame = 18, degree = 30, frameJump = 10): + currentFrame = initialFrame + endFrame = initialFrame + 2 * frameJump + handParam = input_hand[-3:] + util.setPose(action, handParam, [initialFrame], bones) + + lado = "BnMao.R" if util.rightBonesConf == bones else "BnMao.L" + bnMao = bpy.context.object.pose.bones[lado] + bnMao.bone.select = True + currentFrame += frameJump + 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 pa_index = input_hand[-1] - # TODO mão esquerda + for i in range(0, repetition): util.setPose(action, [util.cocar_mao_aberta_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) currentFrame += frameJump + lastFrame = i == repetition - 1 util.setPose(action, [util.cocar_mao_fechada_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) currentFrame += frameJump return currentFrame @@ -57,7 +104,6 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump pose.location[orientation_index] = center[orientation_index] + width pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump - return currentFrame def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 10, width = 0.25): @@ -75,7 +121,6 @@ def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 1 pose.location[1] = center[1] + width if to_right else center[1] - width pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump - return currentFrame def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None): diff --git a/util.py b/util.py index 70b7b61..a621f35 100644 --- a/util.py +++ b/util.py @@ -5,8 +5,6 @@ import math armature = bpy.context.scene.objects.get('Armature.001') -bones = ["BnMao.R", "BnMao.L"] - # Vetor com indices de cada bone do lado direito rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66] @@ -25,13 +23,10 @@ hands_default_frames = [15, 18] # define a posição dos keyframes hands_frames_retilineo = [30, 33] -# Movimento de mão action -movimento_mao_action_index = 7 - # Movimento coçar - Índices de poses -cocar_mao_aberta_index = 0 -cocar_mao_fechada_index = 1 -cocar_orientation_index = 12 +cocar_mao_aberta_index = 56 +cocar_mao_fechada_index = 24 +cocar_orientation_index = 20 # Função responsável por selecionar as pose-libs e setar os frames def setPose(actions, parametesConf, positionFrames, bones): @@ -107,3 +102,37 @@ def get_endFrame(json_input, hands_frames_retilineo): elif(json_input["rightHand"][0] == "retilineo"): endsFrame.append(max(hands_frames_retilineo)) return(max(endsFrame)) + +def validate_rotation(bone, endFrame): + rotFrames = [[]] + scene = bpy.context.scene + frame_current = bpy.context.scene.frame_current + + for i in range(0, endFrame + 1,1): + scene.frame_set(i) + rotFrames[-1] = bone.rotation_quaternion.to_euler() + rotFrames.append( [] ) + + rotFrames.remove([]) + scene.frame_set(frame_current) + + for k in range(1, endFrame + 1, 1): + for i in range(0, 3, 1): + if (math.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > math.pi : + return False + return True + +# Axis: "X", "Y" e "Z" +def apply_rotation(bone, axis, currentFrame, endFrame, degree): + new_rotation = bone.rotation_quaternion.to_euler() + new_rotation.rotate_axis(axis, math.radians(degree)) + new_rotation = new_rotation.to_quaternion() + + bone.rotation_quaternion = new_rotation + bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) + + valid_rotation = validate_rotation(bone, endFrame) + if (not valid_rotation): + new_rotation *= (-1) + bone.rotation_quaternion = new_rotation + bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) \ No newline at end of file -- libgit2 0.21.2