Commit 9e22a297e6305b47ed3bd068535ba2347accd05a

Authored by Adabriand Furtado
1 parent e48ef0c6
Exists in master

Adicionado o tratamento de colisão com o corpo do avatar.

avatar_cartoon_v2.74.blend
No preview for this file type
libras.py
... ... @@ -35,7 +35,8 @@ act = bpy.context.scene.animation_data_create()
35 35 def poseDefault(positionFrames, collisionFlag = False):
36 36 handDefaultParam = [0, 0, 0]
37 37 util.setPose(util.right_hand_actions, handDefaultParam, positionFrames, util.rightBonesConf, collisionFlag)
38   - util.setPose(util.left_hand_actions, handDefaultParam, positionFrames, util.leftBonesConf, collisionFlag)
  38 + if(json_input["leftHand"] != []):
  39 + util.setPose(util.left_hand_actions, handDefaultParam, positionFrames, util.leftBonesConf, collisionFlag)
39 40 #setFaceConfiguration([0], positionFrames, util.faceBonesConf)
40 41  
41 42 # Função responsável por setar as configurações das mãos
... ...
moves.py
... ... @@ -40,7 +40,7 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree
40 40 util.apply_rotation(bnMao, "Y", currentFrame, endFrame, (-2)*bnMaoDegree)
41 41 currentFrame += frameJump
42 42 util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree)
43   - util.setPose([action[0]], [handParam[0]], [currentFrame], bones)
  43 + util.setPose(action[0:2], handParam[0:2], [currentFrame], bones)
44 44 currentFrame += frameJump
45 45 bnMao.bone.select = False
46 46 return currentFrame
... ... @@ -193,6 +193,6 @@ def circular(obj, itFrame, raio, periodo, x = 0, y = 1, ladoOposto = False, inve
193 193 if (itFrame % 2 == 0):
194 194 obj.location[x] = loc[x] + (raio * math.cos(i / periodo * (2 * math.pi)))
195 195 obj.location[y] = loc[y] + (raio * math.sin(i / periodo * (2 * math.pi)))
196   - obj.keyframe_insert(data_path='location', frame=itFrame, index=-1)
  196 + util.keyframe_insert(obj, 'location', itFrame)
197 197 itFrame += 1
198 198 return periodo - 1
... ...
util.py
... ... @@ -90,7 +90,7 @@ def resetBnMaoPosition(isRightHand):
90 90  
91 91 def checkRotation(bone, positionFrame, last_keyframe):
92 92 scene = bpy.context.scene
93   - frame_current = bpy.context.scene.frame_current
  93 + frame_current = scene.frame_current
94 94 scene.frame_set(positionFrame)
95 95 boneRQ = bone.rotation_quaternion.to_euler()
96 96 scene.frame_set(frame_current)
... ... @@ -104,36 +104,54 @@ def checkRotation(bone, positionFrame, last_keyframe):
104 104 bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrame)
105 105  
106 106 def checkCollision(bone, path, positionFrame, last_keyframe):
  107 + if (last_keyframe == positionFrame):
  108 + return
  109 +
107 110 isRightHand = ".R" in bone.name
108 111 resetIKPosition(isRightHand)
109   - collisionFrame = check_collision(last_keyframe, positionFrame)
  112 + handCollisionFrame = check_hand_collision(last_keyframe, positionFrame)
110 113  
111   - if (last_keyframe != positionFrame and collisionFrame != -1):
112   - handle_collision(bone, path, positionFrame, collisionFrame)
  114 + if (handCollisionFrame != -1):
  115 + handle_collision(bone, path, positionFrame, handCollisionFrame)
  116 + return
  117 +
  118 + bodyCollisionFrame = check_body_collision(isRightHand, last_keyframe, positionFrame)
  119 + if (bodyCollisionFrame != -1):
  120 + handle_collision(bone, path, positionFrame, bodyCollisionFrame)
  121 + return
113 122  
114 123 def handle_collision(bone, path, positionFrame, collisionFrame, rollbackFrames = 0):
115 124 scene = bpy.context.scene
116   - frame_current = bpy.context.scene.frame_current
  125 + frame_current = scene.frame_current
117 126 scene.frame_set(collisionFrame - rollbackFrames)
118 127 bone.keyframe_insert(data_path = path, index = -1, frame = positionFrame)
119 128 bpy.context.scene.frame_set(frame_current)
120 129  
121   -def check_collision(initFrame, endFrame):
  130 +def check_hand_collision(initFrame, endFrame):
  131 + return check_collision('right_hand_box', 'left_hand_box', initFrame, endFrame)
  132 +
  133 +def check_collision(objName, otherObjName, initFrame, endFrame):
122 134 scene = bpy.context.scene
123   - frame_current = bpy.context.scene.frame_current
  135 + frame_current = scene.frame_current
124 136 startFrame = initFrame + int(math.fabs((endFrame - initFrame)/2))
125 137 collisionFrame = -1
126 138 for i in range(startFrame, endFrame + 1, 1):
127 139 scene.frame_set(i)
128   - right_cube = bpy.context.scene.objects.get('right_hand_box')
129   - left_cube = bpy.context.scene.objects.get('left_hand_box')
  140 + obj = scene.objects.get(objName)
  141 + otherObj = scene.objects.get(otherObjName)
130 142  
131   - if (bmesh_check_intersect_objects(right_cube, left_cube)):
  143 + if (bmesh_check_intersect_objects(obj, otherObj)):
132 144 collisionFrame = i
133 145 break
134 146 scene.frame_set(frame_current)
135 147 return collisionFrame
136 148  
  149 +def check_body_collision(isRightHand, initFrame, endFrame):
  150 + hand_box = 'right_hand_box' if isRightHand else 'left_hand_box'
  151 + body_box = 'body_box'
  152 + result = check_collision(hand_box, body_box, initFrame, endFrame)
  153 + return result
  154 +
137 155 # Função que limpa todos os keyframes e define a quantidade de frames
138 156 def erase_all_keyframes():
139 157 for i in bpy.data.objects:
... ... @@ -202,12 +220,12 @@ def validate_rotation(bone, endFrame, startFrame = 0):
202 220  
203 221 rotFrames = [[]]
204 222 scene = bpy.context.scene
205   - frame_current = bpy.context.scene.frame_current
  223 + frame_current = scene.frame_current
206 224  
207 225 for i in range(startFrame+1, endFrame+1, 1):
208 226 scene.frame_set(i)
209 227 rotFrames[-1] = bone.rotation_quaternion.to_euler()
210   - rotFrames.append( [] )
  228 + rotFrames.append([])
211 229  
212 230 rotFrames.remove([])
213 231 scene.frame_set(frame_current)
... ... @@ -225,10 +243,4 @@ def apply_rotation(bone, axis, currentFrame, endFrame, degree):
225 243 new_rotation = new_rotation.to_quaternion()
226 244  
227 245 bone.rotation_quaternion = new_rotation
228   - keyframe_insert(bone, 'rotation_quaternion', currentFrame)
229   -
230   - valid_rotation = validate_rotation(bone, endFrame)
231   - if (not valid_rotation):
232   - new_rotation *= (-1)
233   - bone.rotation_quaternion = new_rotation
234   - keyframe_insert(bone, 'rotation_quaternion', currentFrame)
235 246 \ No newline at end of file
  247 + keyframe_insert(bone, 'rotation_quaternion', currentFrame, False, True)
236 248 \ No newline at end of file
... ...