From 9e22a297e6305b47ed3bd068535ba2347accd05a Mon Sep 17 00:00:00 2001 From: Adabriand Furtado Date: Thu, 30 Jul 2015 13:21:28 -0300 Subject: [PATCH] Adicionado o tratamento de colisão com o corpo do avatar. --- avatar_cartoon_v2.74.blend | Bin 6976936 -> 0 bytes libras.py | 3 ++- moves.py | 4 ++-- util.py | 50 +++++++++++++++++++++++++++++++------------------- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/avatar_cartoon_v2.74.blend b/avatar_cartoon_v2.74.blend index 5b6ff51..1e1befe 100755 Binary files a/avatar_cartoon_v2.74.blend and b/avatar_cartoon_v2.74.blend differ diff --git a/libras.py b/libras.py index 03f693d..634a00a 100644 --- a/libras.py +++ b/libras.py @@ -35,7 +35,8 @@ act = bpy.context.scene.animation_data_create() def poseDefault(positionFrames, collisionFlag = False): handDefaultParam = [0, 0, 0] util.setPose(util.right_hand_actions, handDefaultParam, positionFrames, util.rightBonesConf, collisionFlag) - util.setPose(util.left_hand_actions, handDefaultParam, positionFrames, util.leftBonesConf, collisionFlag) + if(json_input["leftHand"] != []): + util.setPose(util.left_hand_actions, handDefaultParam, positionFrames, util.leftBonesConf, collisionFlag) #setFaceConfiguration([0], positionFrames, util.faceBonesConf) # Função responsável por setar as configurações das mãos diff --git a/moves.py b/moves.py index 9f219bb..915f126 100644 --- a/moves.py +++ b/moves.py @@ -40,7 +40,7 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree 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) + util.setPose(action[0:2], handParam[0:2], [currentFrame], bones) currentFrame += frameJump bnMao.bone.select = False return currentFrame @@ -193,6 +193,6 @@ def circular(obj, itFrame, raio, periodo, x = 0, y = 1, ladoOposto = False, inve 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) + util.keyframe_insert(obj, 'location', itFrame) itFrame += 1 return periodo - 1 diff --git a/util.py b/util.py index 88ff1e1..524f468 100644 --- a/util.py +++ b/util.py @@ -90,7 +90,7 @@ def resetBnMaoPosition(isRightHand): def checkRotation(bone, positionFrame, last_keyframe): scene = bpy.context.scene - frame_current = bpy.context.scene.frame_current + frame_current = scene.frame_current scene.frame_set(positionFrame) boneRQ = bone.rotation_quaternion.to_euler() scene.frame_set(frame_current) @@ -104,36 +104,54 @@ def checkRotation(bone, positionFrame, last_keyframe): bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrame) def checkCollision(bone, path, positionFrame, last_keyframe): + if (last_keyframe == positionFrame): + return + isRightHand = ".R" in bone.name resetIKPosition(isRightHand) - collisionFrame = check_collision(last_keyframe, positionFrame) + handCollisionFrame = check_hand_collision(last_keyframe, positionFrame) - if (last_keyframe != positionFrame and collisionFrame != -1): - handle_collision(bone, path, positionFrame, collisionFrame) + 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) + return def handle_collision(bone, path, positionFrame, collisionFrame, rollbackFrames = 0): scene = bpy.context.scene - frame_current = bpy.context.scene.frame_current + frame_current = scene.frame_current scene.frame_set(collisionFrame - rollbackFrames) bone.keyframe_insert(data_path = path, index = -1, frame = positionFrame) bpy.context.scene.frame_set(frame_current) -def check_collision(initFrame, endFrame): +def check_hand_collision(initFrame, endFrame): + return check_collision('right_hand_box', 'left_hand_box', initFrame, endFrame) + +def check_collision(objName, otherObjName, initFrame, endFrame): scene = bpy.context.scene - frame_current = bpy.context.scene.frame_current + frame_current = scene.frame_current startFrame = initFrame + int(math.fabs((endFrame - initFrame)/2)) collisionFrame = -1 for i in range(startFrame, endFrame + 1, 1): scene.frame_set(i) - right_cube = bpy.context.scene.objects.get('right_hand_box') - left_cube = bpy.context.scene.objects.get('left_hand_box') + obj = scene.objects.get(objName) + otherObj = scene.objects.get(otherObjName) - if (bmesh_check_intersect_objects(right_cube, left_cube)): + if (bmesh_check_intersect_objects(obj, otherObj)): collisionFrame = i break scene.frame_set(frame_current) return collisionFrame +def check_body_collision(isRightHand, initFrame, endFrame): + hand_box = 'right_hand_box' if isRightHand else 'left_hand_box' + body_box = 'body_box' + 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 erase_all_keyframes(): for i in bpy.data.objects: @@ -202,12 +220,12 @@ def validate_rotation(bone, endFrame, startFrame = 0): rotFrames = [[]] scene = bpy.context.scene - frame_current = bpy.context.scene.frame_current + 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.append([]) rotFrames.remove([]) scene.frame_set(frame_current) @@ -225,10 +243,4 @@ def apply_rotation(bone, axis, currentFrame, endFrame, degree): new_rotation = new_rotation.to_quaternion() bone.rotation_quaternion = new_rotation - keyframe_insert(bone, 'rotation_quaternion', currentFrame) - - valid_rotation = validate_rotation(bone, endFrame) - if (not valid_rotation): - new_rotation *= (-1) - bone.rotation_quaternion = new_rotation - keyframe_insert(bone, 'rotation_quaternion', currentFrame) \ No newline at end of file + keyframe_insert(bone, 'rotation_quaternion', currentFrame, False, True) \ No newline at end of file -- libgit2 0.21.2