From 2b00053810cca668f8d700c947f2284cfb6a0251 Mon Sep 17 00:00:00 2001 From: Adabriand Furtado Date: Wed, 26 Aug 2015 14:14:55 -0300 Subject: [PATCH] Correção do movimento pontual --- decode.py | 4 ++-- moves.py | 61 +++++++++++++++++++++++-------------------------------------- util.py | 22 +++++++++------------- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/decode.py b/decode.py index 395d6e9..4136a5e 100644 --- a/decode.py +++ b/decode.py @@ -35,9 +35,9 @@ def contato(js_movement, current_frame, frame_jump, is_right_hand): sub_type = next(iter(js_movement.keys())) mov_param = js_movement[sub_type] action = util.right_hand_actions if is_right_hand else util.left_hand_actions - bones = util.rightBonesConf if is_right_hand else util.leftBonesConf + bones = util.right_bones_conf if is_right_hand else util.left_bones_conf current_frame = current_frame + 2*frame_jump - return moves.contato(action, sub_type, mov_param, bones, current_frame, frame_jump) + return moves.contato(action, sub_type, mov_param, bones, is_right_hand, current_frame, frame_jump) def espiral(js_movement, current_frame, frame_jump, is_right_hand): pass diff --git a/moves.py b/moves.py index f5fa8a8..6a7a081 100644 --- a/moves.py +++ b/moves.py @@ -11,26 +11,27 @@ def read_hand_param(mov_param): orient_param = mov_param['orientacao'] if 'orientacao' in mov_param else 0 return [conf_param, artic_param, orient_param] -def contato(action, contact_type, mov_param, bones, initialFrame = 18, frameJump = 10): +def contato(action, contact_type, mov_param, bones, is_right_hand, initialFrame = 18, frameJump = 10): if (contact_type == "alisar"): - currentFrame = alisar(action, mov_param, bones, initialFrame, frameJump) + currentFrame = alisar(action, mov_param, bones, is_right_hand, initialFrame, frameJump) elif (contact_type == "cocar"): currentFrame = cocar(action, mov_param, bones, initialFrame, frameJump) elif (contact_type == "tocar"): - currentFrame = tocar(action, mov_param, bones, initialFrame, frameJump) + currentFrame = tocar(action, mov_param, bones, is_right_hand, initialFrame, frameJump) elif (contact_type == "riscar"): - currentFrame = riscar(action, mov_param, bones, initialFrame, frameJump) + currentFrame = riscar(action, mov_param, bones, is_right_hand, initialFrame, frameJump) return currentFrame -def riscar(action, mov_param, bones, initialFrame = 25, frameJump = 10, bnAntBracoDegree = 2, bnMaoDegree = 45): +def riscar(action, mov_param, bones, is_right_hand, initialFrame = 25, frameJump = 10, bnAntBracoDegree = 2, bnMaoDegree = 45): currentFrame = initialFrame handParam = read_hand_param(mov_param) - lado = "R" if util.rightBonesConf == bones else "L" + lado = "R" if is_right_hand else "L" - #bnAntBraco = bpy.context.object.pose.bones["BnAntBraco." + lado] - #util.apply_rotation(bnAntBraco, "Z", currentFrame, bnAntBracoDegree) - #currentFrame += frameJump - #util.apply_rotation(bnAntBraco, "Z", currentFrame, (-1)*(bnAntBracoDegree+1)) + bnAntBraco = bpy.context.object.pose.bones["BnAntBraco." + lado] + currentFrame += frameJump + util.apply_rotation(bnAntBraco, "Z", currentFrame, bnAntBracoDegree) + currentFrame += frameJump + util.apply_rotation(bnAntBraco, "Z", currentFrame, (-1)*(bnAntBracoDegree+1)) currentFrame = initialFrame util.setPose(action, handParam, [currentFrame], bones) @@ -45,17 +46,17 @@ def riscar(action, mov_param, bones, initialFrame = 25, frameJump = 10, bnAntBra util.setPose(action, handParam, [currentFrame], bones) return currentFrame -def tocar(action, mov_param, bones, initialFrame = 25, degree = 30, frameJump = 10): +def tocar(action, mov_param, bones, is_right_hand, initialFrame = 25, degree = 30, frameJump = 10): currentFrame = initialFrame handParam = read_hand_param(mov_param) util.setPose(action, handParam, [initialFrame], bones) - pose = util.armature.pose.bones["ik_FK.R" if util.rightBonesConf == bones else "ik_FK.L"] + pose = util.armature.pose.bones["ik_FK.R" if is_right_hand else "ik_FK.L"] - lado = "BnMao.R" if util.rightBonesConf == bones else "BnMao.L" + lado = "BnMao.R" if is_right_hand else "BnMao.L" bnMao = bpy.context.object.pose.bones[lado] currentFrame += frameJump util.apply_rotation(bnMao, "X", currentFrame, -degree) - pose = util.armature.pose.bones["ik_FK.R" if util.rightBonesConf == bones else "ik_FK.L"] + pose = util.armature.pose.bones["ik_FK.R" if is_right_hand else "ik_FK.L"] currentFrame += frameJump util.apply_rotation(bnMao, "X", currentFrame, degree) util.setPose(action[0:2], handParam[0:2], [currentFrame], bones) @@ -73,13 +74,13 @@ def cocar(action, mov_param, bones, initialFrame = 18, frameJump = 10): currentFrame += frameJump return currentFrame -def alisar(action, mov_param, bones, initialFrame = 18, frameJump = 10, width = 0.25): +def alisar(action, mov_param, bones, is_right_hand, initialFrame = 18, frameJump = 10, width = 0.25): currentFrame = initialFrame plane = mov_param['plano'] if 'plano' in mov_param else "perpendicular" repetition = mov_param['repeticoes'] if 'repeticoes' in mov_param else 2 handParam = read_hand_param(mov_param) util.setPose(action, handParam, [currentFrame], bones) - boneIK = util.armature.pose.bones["ik_FK.R" if util.rightBonesConf == bones else "ik_FK.L"] + boneIK = util.armature.pose.bones["ik_FK.R" if is_right_hand else "ik_FK.L"] if (plane == "perpendicular"): currentFrame = alisar_xy(boneIK, 1, repetition, currentFrame, frameJump, width) @@ -182,29 +183,13 @@ def circular(obj, current_frame, raio, periodo, x = 0, y = 1, usar_lado_oposto = return periodo - 1 def pontual(js_movement, current_frame, frame_jump, is_right_hand): - #import facial - print(util.right_bones_conf) hand_param = read_hand_param(js_movement) - bones = util.right_bones_conf if is_right_hand else util.leftBonesConf - #poselib = None - if (is_right_hand): - #poselib = util.pa_direita_id - hand_actions = util.right_hand_actions - else: - #poselib = util.pa_esquerda_id - hand_actions = util.left_hand_actions - #ik_bones = util.dict_bones[poselib] - #util.select_bones(ik_bones) - util.keyframe_insert(bones, 'location', current_frame, False) - #facial.keyframe_insert(current_frame, ik_bones, ['location']) + bones = util.right_bones_conf if is_right_hand else util.left_bones_conf + hand_actions = util.right_hand_actions if is_right_hand else util.left_hand_actions + + util.keyframe_insert(bones, 'location', current_frame) current_frame += frame_jump - #facial.apply_pose(js_movement['articulacao'], poselib) - pyutil.log("XXXXXXXXXXXXXXXX") - util.setPose(hand_actions, hand_param, [current_frame], bones, False) - pyutil.log("YYYYYYYYYYYYYYYY") - #facial.keyframe_insert(current_frame, ik_bones, ['location']) + util.setPose(hand_actions, hand_param, [current_frame], bones) current_frame += frame_jump - #facial.keyframe_insert(current_frame, ik_bones, ['location']) - util.keyframe_insert(bones, 'location', current_frame, False) - #util.deselect_bones(ik_bones) + util.keyframe_insert(bones, 'location', current_frame) return current_frame diff --git a/util.py b/util.py index 5e31d07..54da396 100644 --- a/util.py +++ b/util.py @@ -13,8 +13,8 @@ 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_esquerda": ['ik_FK.L', 'BnPolyV.L'], + "03_pa_direita": ['BnPolyV.R', 'ik_FK.R'], + "04_pa_esquerda": ['BnPolyV.L', 'ik_FK.L'], "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'] @@ -22,11 +22,13 @@ dict_bones = { right_bones_conf = dict_bones["01_conf_direita"] + dict_bones["03_pa_direita"] + dict_bones["05_orient_direita"] +left_bones_conf = dict_bones["02_conf_esquerda"] + dict_bones["04_pa_esquerda"] + dict_bones["06_orient_esquerda"] + # 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] # Movimento coçar - Índices de poses cocar_mao_aberta_index = 55 @@ -105,8 +107,6 @@ def setPose(actions, parametesConf, positionFrames, bones, collisionFlag = True) def internal_keyframe_insert(bone, path, positionFrame, collisionFlag = True, rotationFlag = False): # Limit hand depth - if ("ik_FK.R" == bone.name): - print("VERDADE", bone.location, positionFrame) if ("ik_FK" in bone.name and bone.location.z < 1): bone.location.z = 1 bone.bone.select = True @@ -117,7 +117,7 @@ def internal_keyframe_insert(bone, path, positionFrame, collisionFlag = True, ro last_keyframe_dict[keyframe_id] = positionFrame if (rotationFlag and path == "rotation_quaternion"): checkRotation(bone, positionFrame, last_keyframe) - if (collisionFlag): + if (collisionFlag and "ik_FK" in bone.name): checkCollision(bone, path, positionFrame, last_keyframe) def keyframe_insert(bones, path, positionFrame, collisionFlag = True, rotationFlag = False): @@ -182,7 +182,6 @@ def check_hand_collision(initFrame, endFrame): def check_collision(objName, otherObjName, initFrame, endFrame): scene = bpy.context.scene - frame_current = scene.frame_current startFrame = initFrame + int(math.fabs((endFrame - initFrame)/2)) collisionFrame = -1 @@ -191,11 +190,9 @@ def check_collision(objName, otherObjName, initFrame, endFrame): obj = scene.objects.get(objName) otherObj = scene.objects.get(otherObjName) if (bmesh_check_intersect_objects(obj, otherObj)): - pyutil.log("bla") - pyutil.log(i) collisionFrame = i break - scene.frame_set(frame_current) + scene.frame_set(endFrame) return collisionFrame def check_body_collision(isRightHand, initFrame, endFrame): @@ -240,13 +237,12 @@ def validate_rotation(bone, endFrame, startFrame = 0): 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([]) rotFrames.remove([]) - scene.frame_set(frame_current) + scene.frame_set(endFrame) 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/3: -- libgit2 0.21.2