diff --git a/Makefile b/Makefile index 72ced8b..774afc7 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ JSON_ALL = \ { \ "facial": { \ "expressao": 0..21, \ - "velocidade": "lento|normal|rapido" \ + "transicao": "lento|normal|rapido", \ + "duracao": "lento|normal|rapido" \ }, \ "mao_esquerda": { \ "circular": { \ @@ -102,28 +103,39 @@ JSON = \ '{ \ "userId": "lavid", \ "sinal": "Modelo JSON 2", \ - "ex_interpolacao": "lento|normal|rapido", \ "interpolacao": "normal", \ "movimentos": [ \ { \ "facial": { \ - "expressao": 21, \ - "velocidade": "lento|normal|rapido" \ + "expressao": 20, \ + "transicao": "normal", \ + "duracao": "normal" \ }, \ "mao_esquerda": { \ "circular": { \ "plano": "esquerda-cima", \ "raio": "pequeno", \ - "velocidade": "lento", \ + "velocidade": "normal", \ "lado_oposto": false, \ "sentido_inverso": false, \ "articulacao": 124, \ - "configuracao": 129, \ + "configuracao": 60, \ "orientacao": 142 \ } \ }, \ "mao_direita": { \ } \ + }, \ + { \ + "facial": { \ + "expressao": 21, \ + "transicao": "normal", \ + "duracao": "normal" \ + }, \ + "mao_esquerda": { \ + }, \ + "mao_direita": { \ + } \ } \ ] \ }' diff --git a/controller.py b/controller.py index 3b837a0..0a2c935 100644 --- a/controller.py +++ b/controller.py @@ -18,6 +18,6 @@ try: # result = subprocess.call(['blender', '-b', blend_path, '-P', main_path, '--', sys.argv[1]], stdout = open('bpy.log', 'w')) result = subprocess.call(['blender', '-b', blend_path, '-P', main_path, '--', sys.argv[1]]) except: - result = pyutil.printStackTrace(__file__) + result = pyutil.print_stack_trace(__file__) exit(result) diff --git a/facial.py b/facial.py new file mode 100644 index 0000000..1f32a4b --- /dev/null +++ b/facial.py @@ -0,0 +1,123 @@ +# -*- coding: UTF-8 -*- + +import bpy +import util + +library_name = '07_facial' + +# duracao na posicao selecionada +dict_duration = { + 'lento': 15, + 'normal': 10, + 'rapido': 5 +} + +# tempo de entrada e saida na posicao selecionada +dict_transition = { + 'lento': 15, + 'normal': 10, + 'rapido': 5 +} + +# marcador global da linha do tempo exclusivo para expressao facial +timeline_facial = 0 + +# insere keyframes aos bones selecionados anteriormente e passados como parametro +def keyframe_insert(current_frame = 0, pose_bones = bpy.context.object.pose.bones, keyframe_types = ['location', 'rotation_quaternion']): + # verifica se existe apenas um bone + if (isinstance(pose_bones, int) or isinstance(pose_bones, str)): + # verifica se existe apenas um tipo de insercao de keyframe + if (isinstance(keyframe_types, str)): + bpy.context.object.pose.bones[pose_bones].keyframe_insert(index = -1, frame = current_frame, group = bpy.context.object.pose.bones[pose_bones].name, data_path = keyframe_types) + # verifica se existe mais de um tipo de insercao de keyframe + elif (isinstance(keyframe_types, list)): + for keyframe_type in keyframe_types: + bpy.context.object.pose.bones[bones].keyframe_insert(index = -1, frame = current_frame, group = bpy.context.object.pose.bones[pose_bones].name, data_path = keyframe_type) + # verifica se existe mais de um bone + elif (isinstance(pose_bones, list)): + for bone in pose_bones: + # verifica se existe apenas um tipo de insercao de keyframe + if (isinstance(keyframe_types, str)): + bpy.context.object.pose.bones[bone].keyframe_insert(index = -1, frame = current_frame, group = bpy.context.object.pose.bones[bone].name, data_path = keyframe_types) + # verifica se existe mais de um tipo de insercao de keyframe + elif (isinstance(keyframe_types, list)): + for keyframe_type in keyframe_types: + bpy.context.object.pose.bones[bone].keyframe_insert(index = -1, frame = current_frame, group = bpy.context.object.pose.bones[bone].name, data_path = keyframe_type) + return + +# aplica biblioteca(s) de pose(s) e seu respectivo indice +def apply_pose(index = 0, pose_library = list(bpy.data.actions)): + # verifica se deve aplicar apenas uma biblioteca + if (isinstance(pose_library, int) or isinstance(pose_library, str)): + # verifica biblioteca fake_user + if (bpy.data.actions[pose_library].use_fake_user): + bpy.context.object.pose_library = bpy.data.actions[pose_library] + bpy.ops.poselib.apply_pose(pose_index = index) + # verifica se deve aplicar mais de uma biblioteca + elif (isinstance(pose_library, list)): + for library in pose_library: + # verifica biblioteca fake_user + if (library.use_fake_user): + bpy.context.object.pose_library = library + bpy.ops.poselib.apply_pose(pose_index = index) + bpy.context.object.pose_library = None + return + +# consolida o movimento (faz insercao dos keyframes) e incrementa a timeline +def set_expression(index, frame_duration = dict_duration['normal'], frame_transition = 0): + global timeline_facial + global library_name + bones_facial = util.dict_bones[library_name] + util.select_bones(bones_facial) + # TODO separar bones 'location' e 'rotation_quaternion' + keyframe_insert(timeline_facial, bones_facial, ['location', 'rotation_quaternion']) + apply_pose(index, library_name) + timeline_facial += frame_transition + keyframe_insert(timeline_facial, bones_facial, ['location', 'rotation_quaternion']) + timeline_facial += frame_duration + keyframe_insert(timeline_facial, bones_facial, ['location', 'rotation_quaternion']) + timeline_facial += frame_transition + util.deselect_bones(bones_facial) + return timeline_facial + +# decodifica objeto JSON +def decode_expression(js_facial, initial_interpolation = dict_duration['normal']): + global dict_duration + global dict_transition + index = js_facial['expressao'] + frame_duration = dict_duration[js_facial['duracao']] + frame_transition = dict_duration[js_facial['transicao']] + # insere o primeiro keyframe + if (timeline_facial == 0): + set_expression(0, initial_interpolation) + set_expression(index, frame_duration, frame_transition) + set_expression(0, frame_duration) + return timeline_facial + +""" +# unit test +def main(): + import random + interpolation_start = 20 + interpolation_end = 20 + pose_max_range = round(bpy.data.actions[library_name].frame_range[1]) + + util.delete_all_keyframes() + apply_pose(0, library_name) + + js_facial = {"expressao": random.randint(0, pose_max_range), "transicao": 'normal', "duracao": 'normal'} + print('facial expression %d current frame:' % (js_facial['expressao']), decode_expression(js_facial)) + + js_facial = {"expressao": random.randint(0, pose_max_range), "transicao": 'normal', "duracao": 'normal'} + print('facial expression %d current frame:' % (js_facial['expressao']), decode_expression(js_facial)) + + #for i in range(0, pose_max_range + 1): + # js_facial = {"expressao": i, "transicao": 'normal', "duracao": 'normal'} + # print('facial expression %d current frame:' % (js_facial['expressao']), decode_expression(js_facial)) + + bpy.context.scene.frame_end = timeline_facial + interpolation_end + bpy.ops.screen.animation_play(reverse = False) + +if __name__ == "__main__": + main() +""" \ No newline at end of file diff --git a/libras.py b/libras.py index 18807cc..6c1f9f0 100644 --- a/libras.py +++ b/libras.py @@ -18,9 +18,16 @@ sys.path.insert(0, getcwd) import util import moves import pyutil +import facial # intervalos de interpolacao dos keyframes -interpolation = {'inicial': 20, 'lento': 5, 'normal': 10, 'rapido': 15, 'final': 20} +dict_interpolation = { + 'inicial': 20, + 'lento': 5, + 'normal': 10, + 'rapido': 15, + 'final': 20 +} def insert_keyframe_pose_default(current_frame = 0, frame_jump = 0, pose_bones = bpy.context.object.pose.bones, types_keyframe = ['location', 'rotation_quaternion']): for obj in (pose_bones): @@ -41,17 +48,20 @@ def pose_default(current_frame = 0, frame_jump = 0, actions = bpy.data.actions): def decode_circular_semicircular(js_movement, current_frame, frame_jump, is_right_hand, is_semicircular): # const - obj_raio = {'pequeno': 0.5, 'normal': 1.0, 'grande': 1.5} - obj_periodo = {'lento': 55, 'normal': 45, 'rapido': 35} + dict_ray = {'pequeno': 0.5, 'normal': 1.0, 'grande': 1.5} + dict_period = {'lento': 55, 'normal': 45, 'rapido': 35} # decodificar valores - raio = obj_raio[js_movement['raio']] - periodo = obj_periodo[js_movement['velocidade']] + ray = dict_ray[js_movement['raio']] + period = dict_period[js_movement['velocidade']] + print('setar articulacao:', js_movement['articulacao']) + print('setar configuracao:', js_movement['configuracao']) + print('setar orientacao:', js_movement['orientacao']) # diminuir a velocidade if (js_movement['velocidade'] == 'lento'): - periodo += 10 + period += 10 # aumentar a velocidade elif (js_movement['velocidade'] == 'rapido'): - periodo -= 10 + period -= 10 # definir eixos do movimento if (js_movement['plano'] == 'frente-esquerda'): x, y = 2, 0 @@ -61,11 +71,11 @@ def decode_circular_semicircular(js_movement, current_frame, frame_jump, is_righ x, y = 0, 1 # mao usada (direita/esquerda) if (is_right_hand): - ik = bpy.context.object.pose.bones[1] + ik = bpy.context.object.pose.bones['ik_FK.R'] else: - ik = bpy.context.object.pose.bones[0] + ik = bpy.context.object.pose.bones['ik_FK.L'] current_frame = insert_keyframe_pose_default(current_frame, frame_jump, [ik], ['location']) - current_frame = moves.circular(ik, current_frame + frame_jump, raio, periodo, x, y, js_movement['lado_oposto'], js_movement['sentido_inverso'], is_semicircular) + current_frame = moves.circular(ik, current_frame + frame_jump, ray, period, x, y, js_movement['lado_oposto'], js_movement['sentido_inverso'], is_semicircular) return current_frame def decode_hand_mov(current_frame, frame_jump, js_mao, is_right_hand): @@ -79,13 +89,14 @@ def decode_hand_mov(current_frame, frame_jump, js_mao, is_right_hand): current_frame = decode_circular_semicircular(js_mao[movement_name], current_frame, frame_jump, is_right_hand, True) return current_frame + frame_jump +""" # Funcao responsavel por setar pose padrao def poseDefault(json_input, positionFrames, collisionFlag = False): handDefaultParam = [0, 0, 0] util.setPose(util.right_hand_actions, handDefaultParam, positionFrames, util.rightBonesConf, collisionFlag) if(json_input["leftHand"] != []): util.setPose(util.left_hand_actions, handDefaultParam, positionFrames, util.leftBonesConf, collisionFlag) - #setFaceConfiguration([0], positionFrames, util.faceBonesConf) + setFaceConfiguration([0], positionFrames, util.faceBonesConf) # Funcao responsavel por setar as configuracoes das maos def setHandConfiguration(actions, handParam, positionFrames, bones): @@ -123,61 +134,66 @@ def configureHands(endFrame): setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) elif(move == "contato"): endFrame = moves.contato(actions[i], json_input[hands[i]], bones_[i], pose) - -# Funcao que inicia a configuracao da face -def setFacialExpr(a, b): - pass - #if(json_input["facialExp"] != []): - # setFaceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) +""" def main(): + util.delete_all_keyframes() util.configure_output() bpy.context.scene.animation_data_create() try: js_input = json.loads(sys.argv[6]) js_movimentos = js_input['movimentos'] - frame_jump = interpolation[js_input['interpolacao']] + frame_jump = dict_interpolation[js_input['interpolacao']] endFrame = pose_default(0) - facial_frame = 0 mao_esquerda_frame = 0 mao_direita_frame = 0 - # setar pose padrao inicial em todos os bones ('location' e 'rotation_quaternion') - endFrame += pose_default(interpolation['inicial']) + # pose padrao inicial em todos os bones ('location' e 'rotation_quaternion') + endFrame += pose_default(dict_interpolation['inicial']) for i in range(0, len(js_movimentos)): - - js_facial = js_movimentos[i]['facial'] - - if (js_facial != {}): - setFacialExpr(js_facial['expressao'], js_facial['velocidade']) + # tenta decodificar objetos JSON + try: + js_facial = js_movimentos[i]['facial'] + except: + js_facial = {} + try: + js_mao_esquerda = js_movimentos[i]['mao_esquerda'] + except: + js_mao_esquerda = {} + try: + js_mao_direita = js_movimentos[i]['mao_direita'] + except: + js_mao_direita = {} + + # faz tratamento dos objetos + if (js_facial == {}): + pyutil.log(" js_movimentos[%d] >> Exp facial" % (i)) + facial.set_expression(0, facial.timeline_facial + frame_jump) else: - pyutil.log(" Expressao Facial %d" % (i)) + facial.decode_expression(js_facial) - js_mao_esquerda = js_movimentos[i]['mao_esquerda'] - if (js_mao_esquerda != {}): - mao_esquerda_frame += decode_hand_mov(mao_esquerda_frame, frame_jump, js_mao_esquerda, False) + if (js_mao_esquerda == {}): + pyutil.log(" js_movimentos[%d] >> Mao esquerda" % (i)) + # TODO posicionar mao esquerda na lateral do corpo else: - pyutil.log(" mov %d Mao esquerda" % (i)) + mao_esquerda_frame += decode_hand_mov(mao_esquerda_frame, frame_jump, js_mao_esquerda, False) - js_mao_direita = js_movimentos[i]['mao_direita'] - if (js_mao_direita != {}): - mao_direita_frame += decode_hand_mov(mao_direita_frame, frame_jump, js_mao_direita, True) + if (js_mao_direita == {}): + pyutil.log(" js_movimentos[%d] >> Mao direita" % (i)) + # TODO posicionar mao direita na lateral do corpo else: - pyutil.log(" mov %d Mao direita" % (i)) + mao_direita_frame += decode_hand_mov(mao_direita_frame, frame_jump, js_mao_direita, True) - endFrame = max(facial_frame, mao_esquerda_frame, mao_direita_frame) + endFrame = max(facial.timeline_facial, mao_esquerda_frame, mao_direita_frame) endFrame += frame_jump # setar pose padrao final em todos os bones (location e rotation) - #endFrame += pose_default(endFrame + interpolation['final']) - endFrame = insert_keyframe_pose_default(endFrame, frame_jump) - endFrame += interpolation['final'] - - # Sugestao: Alguma forma de uniformizar o calculo do endFrame (atualizado aqui e no movimento circular) - #initialFrame = 15 + #endFrame += pose_default(endFrame + dict_interpolation['final']) + #endFrame = insert_keyframe_pose_default(endFrame, frame_jump) + #endFrame += dict_interpolation['final'] #endFrame = util.get_endFrame(js_input, util.hands_frames_retilineo) #poseDefault([1]) #configureHands(endFrame) @@ -187,7 +203,7 @@ def main(): util.render_sign(js_input["userId"], js_input["sinal"], endFrame) except: - pyutil.printStackTrace(__file__) + pyutil.print_stack_trace(__file__) raise if __name__ == "__main__": diff --git a/pyutil.py b/pyutil.py index 9046b5a..732de01 100644 --- a/pyutil.py +++ b/pyutil.py @@ -64,7 +64,7 @@ def test_log(): # @def Função para exibir exceção # @param string deve ser passado: "__file__" para identificar em qual arquivo ocorreu a exceção # @return int Retorna 1 -def printStackTrace(fromFile): +def print_stack_trace(fromFile): from sys import exc_info from os.path import basename error = "\n File name: %s\n Function name: %s\n Line code: %s\n Type exception: %s\n Message: %s" % ( diff --git a/util.py b/util.py index 93e18e2..fed92f6 100644 --- a/util.py +++ b/util.py @@ -9,23 +9,33 @@ from bmesh_collision import bmesh_check_intersect_objects armature = bpy.context.scene.objects.get('Armature.001') +dict_bones = { + "01_conf_direita": ['BnDedo.1.R', 'BnDedo.1.R.006', 'BnDedo.1.R.005', 'BnDedo.1.R.001', 'BnDedo.1.R.008', 'BnDedo.1.R.007', 'BnDedo.1.R.002', 'BnDedo.1.R.010', 'BnDedo.1.R.009', 'BnDedo.1.R.003', 'BnDedo.1.R.012', 'BnDedo.1.R.011', 'BnDedo.1.R.004', 'BnDedo.1.R.014', 'BnDedo.1.R.013'], + "02_conf_esquerda": ['BnDedo.1.L', 'BnDedo.1.L.006', 'BnDedo.1.L.005', 'BnDedo.1.L.001', 'BnDedo.1.L.008', 'BnDedo.1.L.007', 'BnDedo.1.L.002', 'BnDedo.1.L.010', 'BnDedo.1.L.009', 'BnDedo.1.L.003', 'BnDedo.1.L.012', 'BnDedo.1.L.011', 'BnDedo.1.L.004', 'BnDedo.1.L.014', 'BnDedo.1.L.013'], + "03_pa_direita": ['ik_FK.R', 'BnPolyV.R'], + "04_pa_direita": ['ik_FK.R', 'BnPolyV.R'], + "05_orient_direita": ['BnMao.R'], + "06_orient_esquerda": ['BnMao.L'], + "07_facial": ['BnPescoco', 'BnCabeca', 'BnSobrancCentro.L', 'BnSobrancCentro.R', 'BnSobrancLateral.L', 'BnSobrancLateral.R', 'BnPalpebSuper.L', 'BnPalpebInfe.L', 'BnSobrancCentro', 'BnLabioCentroSuper', 'BnBochecha.L', 'BnBochecha.R', 'BnLabioCentroInfer', 'BnBocaCanto.L', 'BnBocaCanto.R', 'BnMandibula', 'BnLingua', 'BnLingua.003', 'BnLingua.001', 'BnLingua.002', 'BnPalpebSuper.R', 'BnPalpebInfe.R', 'BnOlhosMira', 'BnOlhoMira.L', 'BnOlhoMira.R', 'BnOlho.L', 'BnOlho.R'] +} + # 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] +# rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66] # Vetor com indices de cada bone do lado esquerdo -leftBonesConf = [0, 43, 44, 45, 46, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82] +# 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))) +# allBones = list(range(len(armature.pose.bones))) # define a posição dos keyframes -hands_default_frames = [15] +# hands_default_frames = [15] # define a posição dos keyframes -hands_frames_retilineo = [30, 33] +# hands_frames_retilineo = [30, 33] # Movimento coçar - Índices de poses cocar_mao_aberta_index = 56 @@ -33,7 +43,7 @@ cocar_mao_fechada_index = 24 cocar_orientation_index = 20 # Action expressão facial -facial_expression_id ='07_facial' +facial_expression_id = '07_facial' facial_expression_action = [facial_expression_id] # Actions mão direita @@ -50,26 +60,39 @@ left_hand_actions = [conf_esquerda_id, pa_esquerda_id, orient_esquerda_id] last_keyframe_dict = {} -def select_bones(bones = None): - if (isinstance(bones, int)): +def select_bones(bones = bpy.context.object.pose.bones): + if (isinstance(bones, int) or isinstance(bones, str)): bpy.context.object.pose.bones[bones].bone.select = True - else: + elif (isinstance(bones, list)): for bone in bones: bpy.context.object.pose.bones[bone].bone.select = True + elif (isinstance(bones, type(bpy.context.object.pose.bones))): + for pose_bone in bones: + pose_bone.bone.select = True + return -def deselect_bones(bones = None): - if (isinstance(bones, int)): +def deselect_bones(bones = bpy.context.object.pose.bones): + if (isinstance(bones, int) or isinstance(bones, str)): bpy.context.object.pose.bones[bones].bone.select = False - else: + elif (isinstance(bones, list)): for bone in bones: bpy.context.object.pose.bones[bone].bone.select = False + elif (isinstance(bones, type(bpy.context.object.pose.bones))): + for pose_bone in bones: + pose_bone.bone.select = False + return + +def delete_all_keyframes(): + bpy.context.active_object.animation_data_clear() + for obj in bpy.data.objects: + obj.animation_data_clear() + return # Função responsável por selecionar as pose-libs e setar os frames def setPose(actions, parametesConf, positionFrames, bones, collisionFlag = True): bpy.ops.object.mode_set(mode = 'OBJECT') bpy.ops.object.select_all(action="DESELECT") bpy.ops.object.mode_set(mode = 'POSE') - for x in range(len(positionFrames)): for l in range(len(actions)): action = actions[l] @@ -80,7 +103,6 @@ def setPose(actions, parametesConf, positionFrames, bones, collisionFlag = True) validHandConf = action in [conf_direita_id, conf_esquerda_id] and "BnDedo" in bone.name validPA = action in [pa_direita_id, pa_esquerda_id] and "ik_FK" in bone.name or "BnPolyV" in bone.name validO = action in [orient_direita_id, orient_esquerda_id] and "BnMao" in bone.name - if (validHandConf or validPA or validO): keyframe_insert(bone, 'location', positionFrames[x], collisionFlag and validPA, validO) keyframe_insert(bone, 'rotation_quaternion', positionFrames[x], collisionFlag and validPA, validO) @@ -90,10 +112,8 @@ def keyframe_insert(bone, path, positionFrame, collisionFlag = True, rotationFla keyframe_id = bone.name + "_" + path last_keyframe = last_keyframe_dict[keyframe_id] if keyframe_id in last_keyframe_dict else 0 last_keyframe_dict[keyframe_id] = positionFrame - if (rotationFlag and path == "rotation_quaternion"): checkRotation(bone, positionFrame, last_keyframe) - if (collisionFlag): checkCollision(bone, path, positionFrame, last_keyframe) @@ -114,7 +134,6 @@ def checkRotation(bone, positionFrame, last_keyframe): isRightHand = ".R" in bone.name resetBnMaoPosition(isRightHand) valid_rotation = validate_rotation(bone, positionFrame, last_keyframe) - if (not valid_rotation): new_rotation = boneRQ.to_quaternion() * (-1) bone.rotation_quaternion = new_rotation @@ -123,15 +142,12 @@ def checkRotation(bone, positionFrame, last_keyframe): def checkCollision(bone, path, positionFrame, last_keyframe): if (last_keyframe == positionFrame): return - isRightHand = ".R" in bone.name resetIKPosition(isRightHand) handCollisionFrame = check_hand_collision(last_keyframe, positionFrame) - if (handCollisionFrame != -1): handle_collision(bone, path, positionFrame, handCollisionFrame) return - bodyCollisionFrame = check_body_collision(isRightHand, last_keyframe, positionFrame) if (bodyCollisionFrame != -1): handle_collision(bone, path, positionFrame, bodyCollisionFrame) @@ -153,13 +169,12 @@ def check_collision(objName, otherObjName, initFrame, endFrame): startFrame = initFrame + int(math.fabs((endFrame - initFrame)/2)) collisionFrame = -1 for i in range(startFrame, endFrame + 1, 1): - scene.frame_set(i) - obj = scene.objects.get(objName) - otherObj = scene.objects.get(otherObjName) - - if (bmesh_check_intersect_objects(obj, otherObj)): - collisionFrame = i - break + scene.frame_set(i) + obj = scene.objects.get(objName) + otherObj = scene.objects.get(otherObjName) + if (bmesh_check_intersect_objects(obj, otherObj)): + collisionFrame = i + break scene.frame_set(frame_current) return collisionFrame @@ -169,15 +184,8 @@ def check_body_collision(isRightHand, initFrame, endFrame): result = check_collision(hand_box, body_box, initFrame, endFrame) return result -# Função que limpa todos os keyframes e define a quantidade de frames -def limpar_keyframes(): - bpy.context.active_object.animation_data_clear() - for i in bpy.data.objects: - i.animation_data_clear() - # Função que define as configurações de saida def configure_output(): - limpar_keyframes() bpy.context.scene.frame_start = 0 bpy.context.scene.frame_current = bpy.context.scene.frame_start bpy.context.scene.frame_end = bpy.context.scene.frame_start @@ -195,6 +203,7 @@ def configure_output(): bpy.context.scene.render.use_shadows = False bpy.context.scene.render.tile_x = 320 bpy.context.scene.render.tile_y = 240 + return def render_sign(user_id, nome_sinal = "sinal", frame_final = bpy.context.scene.frame_end): getcwd = os.path.dirname(os.path.abspath(__file__)) @@ -204,8 +213,9 @@ def render_sign(user_id, nome_sinal = "sinal", frame_final = bpy.context.scene.f bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") pyutil.file_rename("%s%0.4i-%0.4i.mp4" % (bpy.context.scene.render.filepath, bpy.context.scene.frame_start, bpy.context.scene.frame_end)) bpy.ops.wm.quit_blender() + return -# descontinuada: get_endFrame +""" def get_endFrame(json_input, hands_frames_retilineo): endsFrame = [18] if(json_input["rightHand"] != []): @@ -224,27 +234,24 @@ 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, startFrame = 0): if (endFrame - startFrame == 1): return True - rotFrames = [[]] scene = bpy.context.scene frame_current = scene.frame_current - for i in range(startFrame+1, endFrame+1, 1): - scene.frame_set(i) - rotFrames[-1] = bone.rotation_quaternion.to_euler() - rotFrames.append([]) - + 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, len(rotFrames), 1): - for i in range(0, 3, 1): - if (math.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > math.pi/2: - return False + for i in range(0, 3, 1): + if (math.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > math.pi/2: + return False return True # Axis: "X", "Y" e "Z" @@ -252,6 +259,5 @@ 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 - keyframe_insert(bone, 'rotation_quaternion', currentFrame, False, True) \ No newline at end of file + keyframe_insert(bone, 'rotation_quaternion', currentFrame, False, True) -- libgit2 0.21.2