Commit a0026fb0cb6e921fcc6d1a8323979d4e7cf15ce5

Authored by Adabriand Furtado
1 parent 91c658b7
Exists in master

Refactoring para centralizar a chamada do keyframe_insert

Showing 2 changed files with 36 additions and 46 deletions   Show diff stats
@@ -33,7 +33,7 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree @@ -33,7 +33,7 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree
33 33
34 currentFrame = initialFrame 34 currentFrame = initialFrame
35 util.setPose(action, handParam, [currentFrame], bones) 35 util.setPose(action, handParam, [currentFrame], bones)
36 - bnMao = bpy.context.object.pose.bones["BnMao." + lado] 36 + bnMao = bpy.context.object.pose.bones["BnMao." + lado]
37 bnMao.bone.select = True 37 bnMao.bone.select = True
38 util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) 38 util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree)
39 currentFrame += frameJump 39 currentFrame += frameJump
@@ -99,10 +99,10 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump @@ -99,10 +99,10 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump
99 99
100 for i in range(0, repetition): 100 for i in range(0, repetition):
101 pose.location[orientation_index] = center[orientation_index] - width 101 pose.location[orientation_index] = center[orientation_index] - width
102 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 102 + util.keyframe_insert(pose, 'location', currentFrame)
103 currentFrame += frameJump 103 currentFrame += frameJump
104 pose.location[orientation_index] = center[orientation_index] + width 104 pose.location[orientation_index] = center[orientation_index] + width
105 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 105 + util.keyframe_insert(pose, 'location', currentFrame)
106 currentFrame += frameJump 106 currentFrame += frameJump
107 return currentFrame 107 return currentFrame
108 108
@@ -114,12 +114,12 @@ def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 1 @@ -114,12 +114,12 @@ def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 1
114 pose.location[0] = center[0] - width if to_right else center[0] - width 114 pose.location[0] = center[0] - width if to_right else center[0] - width
115 pose.location[1] = center[1] - width if to_right else center[1] + width 115 pose.location[1] = center[1] - width if to_right else center[1] + width
116 116
117 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 117 + util.keyframe_insert(pose, 'location', currentFrame)
118 currentFrame += frameJump 118 currentFrame += frameJump
119 119
120 pose.location[0] = center[0] + width if to_right else center[0] + width 120 pose.location[0] = center[0] + width if to_right else center[0] + width
121 pose.location[1] = center[1] + width if to_right else center[1] - width 121 pose.location[1] = center[1] + width if to_right else center[1] - width
122 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 122 + util.keyframe_insert(pose, 'location', currentFrame)
123 currentFrame += frameJump 123 currentFrame += frameJump
124 return currentFrame 124 return currentFrame
125 125
@@ -127,19 +127,19 @@ def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensi @@ -127,19 +127,19 @@ def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensi
127 center = pose.location.x, pose.location.y, pose.location.z 127 center = pose.location.x, pose.location.y, pose.location.z
128 if(orientation == 'perpendicular'): 128 if(orientation == 'perpendicular'):
129 if(direction == 'horario'): 129 if(direction == 'horario'):
130 - endFrame = locationCircular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame,turn) 130 + endFrame = locationCircular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame, turn)
131 else: 131 else:
132 - endFrame = locationCircular(center, radius, 0, 1, 2, pose, 0, laps, intensity, initialFrame,turn) 132 + endFrame = locationCircular(center, radius, 0, 1, 2, pose, 0, laps, intensity, initialFrame, turn)
133 elif(orientation == 'paralelo'): 133 elif(orientation == 'paralelo'):
134 if(direction == 'horario'): 134 if(direction == 'horario'):
135 - endFrame = locationCircular(center, radius, 1, 2, 0, pose, 0, laps, intensity, initialFrame,turn) 135 + endFrame = locationCircular(center, radius, 1, 2, 0, pose, 0, laps, intensity, initialFrame, turn)
136 else: 136 else:
137 - endFrame = locationCircular(center, radius, 2, 1, 0, pose, 0, laps, intensity, initialFrame,turn) 137 + endFrame = locationCircular(center, radius, 2, 1, 0, pose, 0, laps, intensity, initialFrame, turn)
138 elif(orientation == 'plano'): 138 elif(orientation == 'plano'):
139 if(direction == 'horario'): 139 if(direction == 'horario'):
140 - endFrame = locationCircular(center, radius, 2, 0, 1, pose, 0, laps, intensity, initialFrame,turn) 140 + endFrame = locationCircular(center, radius, 2, 0, 1, pose, 0, laps, intensity, initialFrame, turn)
141 else: 141 else:
142 - endFrame = locationCircular(center, radius, 0, 2, 1, pose, 0, laps, intensity, initialFrame,turn) 142 + endFrame = locationCircular(center, radius, 0, 2, 1, pose, 0, laps, intensity, initialFrame, turn)
143 return endFrame 143 return endFrame
144 144
145 # center[3]: float vector (posição xyz centro) 145 # center[3]: float vector (posição xyz centro)
@@ -152,11 +152,11 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -152,11 +152,11 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
152 rad2 = (radius/2) 152 rad2 = (radius/2)
153 currentFrame = initialFrame 153 currentFrame = initialFrame
154 for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1): 154 for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1):
155 - if ((l % 8) == 0 ): 155 + if ((l % 8) == 0):
156 pose.location[i_axis] = center[i_axis] + radius 156 pose.location[i_axis] = center[i_axis] + radius
157 pose.location[j_axis] = center[j_axis] 157 pose.location[j_axis] = center[j_axis]
158 pose.location[k_axis] = center[k_axis] 158 pose.location[k_axis] = center[k_axis]
159 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 159 + util.keyframe_insert(pose, 'location', currentFrame)
160 currentFrame += frameJump 160 currentFrame += frameJump
161 if ((l % 8) == 1): 161 if ((l % 8) == 1):
162 pose.location[i_axis] = center[i_axis] + sqrt22 162 pose.location[i_axis] = center[i_axis] + sqrt22
@@ -170,7 +170,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -170,7 +170,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
170 pose.location[i_axis] = center[i_axis] + sqrt22 170 pose.location[i_axis] = center[i_axis] + sqrt22
171 pose.location[j_axis] = center[j_axis] + rad2 171 pose.location[j_axis] = center[j_axis] + rad2
172 pose.location[k_axis] = center[k_axis] + rad2 172 pose.location[k_axis] = center[k_axis] + rad2
173 - pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') 173 + util.keyframe_insert(pose, 'location', initialPosition)
174 currentFrame += frameJump 174 currentFrame += frameJump
175 if ((l % 8) == 2): 175 if ((l % 8) == 2):
176 pose.location[i_axis] = center[i_axis] 176 pose.location[i_axis] = center[i_axis]
@@ -182,7 +182,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -182,7 +182,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
182 elif(turn == -1): 182 elif(turn == -1):
183 pose.location[j_axis] = center[j_axis] + sqrt22 183 pose.location[j_axis] = center[j_axis] + sqrt22
184 pose.location[k_axis] = center[k_axis] + sqrt22 184 pose.location[k_axis] = center[k_axis] + sqrt22
185 - pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') 185 + util.keyframe_insert(pose, 'location', initialPosition)
186 currentFrame += frameJump 186 currentFrame += frameJump
187 if ((l % 8) == 3): 187 if ((l % 8) == 3):
188 pose.location[i_axis] = center[i_axis] - sqrt22 188 pose.location[i_axis] = center[i_axis] - sqrt22
@@ -196,14 +196,14 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -196,14 +196,14 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
196 pose.location[i_axis] = center[i_axis] - sqrt22 196 pose.location[i_axis] = center[i_axis] - sqrt22
197 pose.location[j_axis] = center[j_axis] + rad2 197 pose.location[j_axis] = center[j_axis] + rad2
198 pose.location[k_axis] = center[k_axis] + rad2 198 pose.location[k_axis] = center[k_axis] + rad2
199 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 199 + util.keyframe_insert(pose, 'location', initialPosition)
200 currentFrame += frameJump 200 currentFrame += frameJump
201 201
202 if ((l % 8) == 4): 202 if ((l % 8) == 4):
203 pose.location[i_axis] = center[i_axis] - radius 203 pose.location[i_axis] = center[i_axis] - radius
204 pose.location[j_axis] = center[j_axis] 204 pose.location[j_axis] = center[j_axis]
205 pose.location[k_axis] = center[k_axis] 205 pose.location[k_axis] = center[k_axis]
206 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 206 + util.keyframe_insert(pose, 'location', currentFrame)
207 currentFrame += frameJump 207 currentFrame += frameJump
208 208
209 if ((l % 8) == 5): 209 if ((l % 8) == 5):
@@ -218,7 +218,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -218,7 +218,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
218 pose.location[i_axis] = center[i_axis] - sqrt22 218 pose.location[i_axis] = center[i_axis] - sqrt22
219 pose.location[j_axis] = center[j_axis] - rad2 219 pose.location[j_axis] = center[j_axis] - rad2
220 pose.location[k_axis] = center[k_axis] - rad2 220 pose.location[k_axis] = center[k_axis] - rad2
221 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 221 + util.keyframe_insert(pose, 'location', currentFrame)
222 currentFrame += frameJump 222 currentFrame += frameJump
223 223
224 if ((l % 8) == 6): 224 if ((l % 8) == 6):
@@ -231,7 +231,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -231,7 +231,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
231 elif(turn == -1): 231 elif(turn == -1):
232 pose.location[j_axis] = center[j_axis] - sqrt22 232 pose.location[j_axis] = center[j_axis] - sqrt22
233 pose.location[k_axis] = center[k_axis] - sqrt22 233 pose.location[k_axis] = center[k_axis] - sqrt22
234 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 234 + util.keyframe_insert(pose, 'location', currentFrame)
235 currentFrame += frameJump 235 currentFrame += frameJump
236 236
237 if ((l % 8) == 7): 237 if ((l % 8) == 7):
@@ -246,7 +246,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi @@ -246,7 +246,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
246 pose.location[i_axis] = center[i_axis] + sqrt22 246 pose.location[i_axis] = center[i_axis] + sqrt22
247 pose.location[j_axis] = center[j_axis] - rad2 247 pose.location[j_axis] = center[j_axis] - rad2
248 pose.location[k_axis] = center[k_axis] - rad2 248 pose.location[k_axis] = center[k_axis] - rad2
249 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') 249 + util.keyframe_insert(pose, 'location', currentFrame)
250 currentFrame += frameJump 250 currentFrame += frameJump
251 currentFrame -= frameJump 251 currentFrame -= frameJump
252 return currentFrame 252 return currentFrame
@@ -262,70 +262,56 @@ def locationHelicoidal(center, startRadius, incRadius, x, y, z,pose, currentLoc, @@ -262,70 +262,56 @@ def locationHelicoidal(center, startRadius, incRadius, x, y, z,pose, currentLoc,
262 pose.location[x] = center[x] + radius 262 pose.location[x] = center[x] + radius
263 pose.location[y] = center[y] 263 pose.location[y] = center[y]
264 pose.location[z] += incRadius /allLaps 264 pose.location[z] += incRadius /allLaps
265 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 265 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
266 bpy.context.scene.frame_end += frameJump 266 bpy.context.scene.frame_end += frameJump
267 267
268 if ((i % 8) == 1): 268 if ((i % 8) == 1):
269 pose.location[x] = center[x] + sqrt22 269 pose.location[x] = center[x] + sqrt22
270 pose.location[y] = center[y] + sqrt22 270 pose.location[y] = center[y] + sqrt22
271 pose.location[z] += incRadius /allLaps 271 pose.location[z] += incRadius /allLaps
272 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 272 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
273 bpy.context.scene.frame_end += frameJump 273 bpy.context.scene.frame_end += frameJump
274 274
275 if ((i % 8) == 2): 275 if ((i % 8) == 2):
276 pose.location[x] = center[x] 276 pose.location[x] = center[x]
277 pose.location[y] = center[y] + radius 277 pose.location[y] = center[y] + radius
278 pose.location[z] += incRadius /allLaps 278 pose.location[z] += incRadius /allLaps
279 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 279 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
280 bpy.context.scene.frame_end += frameJump 280 bpy.context.scene.frame_end += frameJump
281 281
282 if ((i % 8) == 3): 282 if ((i % 8) == 3):
283 pose.location[x] = center[x] - sqrt22 283 pose.location[x] = center[x] - sqrt22
284 pose.location[y] = center[y] + sqrt22 284 pose.location[y] = center[y] + sqrt22
285 pose.location[z] += incRadius /allLaps 285 pose.location[z] += incRadius /allLaps
286 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 286 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
287 bpy.context.scene.frame_end += frameJump 287 bpy.context.scene.frame_end += frameJump
288 288
289 if ((i % 8) == 4): 289 if ((i % 8) == 4):
290 pose.location[x] = center[x] - radius 290 pose.location[x] = center[x] - radius
291 pose.location[y] = center[y] 291 pose.location[y] = center[y]
292 pose.location[z] += incRadius /allLaps 292 pose.location[z] += incRadius /allLaps
293 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 293 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
294 bpy.context.scene.frame_end += frameJump 294 bpy.context.scene.frame_end += frameJump
295 295
296 if ((i % 8) == 5): 296 if ((i % 8) == 5):
297 pose.location[x] = center[x] - sqrt22 297 pose.location[x] = center[x] - sqrt22
298 pose.location[y] = center[y] - sqrt22 298 pose.location[y] = center[y] - sqrt22
299 pose.location[z] += incRadius /allLaps 299 pose.location[z] += incRadius /allLaps
300 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 300 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
301 bpy.context.scene.frame_end += frameJump 301 bpy.context.scene.frame_end += frameJump
302 302
303 if ((i % 8) == 6): 303 if ((i % 8) == 6):
304 pose.location[x] = center[x] 304 pose.location[x] = center[x]
305 pose.location[y] = center[y] - radius 305 pose.location[y] = center[y] - radius
306 pose.location[z] += incRadius /allLaps 306 pose.location[z] += incRadius /allLaps
307 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 307 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
308 bpy.context.scene.frame_end += frameJump 308 bpy.context.scene.frame_end += frameJump
309 309
310 if ((i % 8) == 7): 310 if ((i % 8) == 7):
311 pose.location[x] = center[x] + sqrt22 311 pose.location[x] = center[x] + sqrt22
312 pose.location[y] = center[y] - sqrt22 312 pose.location[y] = center[y] - sqrt22
313 pose.location[z] += incRadius /allLaps 313 pose.location[z] += incRadius /allLaps
314 - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') 314 + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end)
315 bpy.context.scene.frame_end += frameJump 315 bpy.context.scene.frame_end += frameJump
316 316
317 bpy.context.scene.frame_end -= frameJump 317 bpy.context.scene.frame_end -= frameJump
318 -  
319 -def locationSenoidal(obj):  
320 - seno = 0  
321 - waveHeight = 5.0  
322 - wave = 5  
323 - pi180 = math.pi / 180  
324 - print(pi180)  
325 - for wave in range(0, 3):  
326 - for i in range(-180, 180):  
327 - obj.location[1] = math.sin(i * (pi180)) * waveHeight  
328 - obj.location[2] += 0.005  
329 - if (i % 10 == 0):  
330 - obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location')  
331 - bpy.context.scene.frame_end += 1  
@@ -38,8 +38,12 @@ def setPose(actions, parametesConf, positionFrames, bones): @@ -38,8 +38,12 @@ def setPose(actions, parametesConf, positionFrames, bones):
38 for x in range(len(positionFrames)): 38 for x in range(len(positionFrames)):
39 bpy.ops.poselib.apply_pose(pose_index = parametesConf[l]) 39 bpy.ops.poselib.apply_pose(pose_index = parametesConf[l])
40 for i in range(0, (len(bones))): 40 for i in range(0, (len(bones))):
41 - armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x])  
42 - armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) 41 + keyframe_insert(armature.pose.bones[bones[i]], 'location', positionFrames[x])
  42 + keyframe_insert(armature.pose.bones[bones[i]], 'rotation_quaternion', positionFrames[x])
  43 +
  44 +def keyframe_insert(bone, path, positionFrame):
  45 + bone.keyframe_insert(data_path = path, index = -1, frame = positionFrame)
  46 + # collision
43 47
44 # Função que limpa todos os keyframes e define a quantidade de frames 48 # Função que limpa todos os keyframes e define a quantidade de frames
45 def erase_all_keyframes(): 49 def erase_all_keyframes():
@@ -129,10 +133,10 @@ def apply_rotation(bone, axis, currentFrame, endFrame, degree): @@ -129,10 +133,10 @@ def apply_rotation(bone, axis, currentFrame, endFrame, degree):
129 new_rotation = new_rotation.to_quaternion() 133 new_rotation = new_rotation.to_quaternion()
130 134
131 bone.rotation_quaternion = new_rotation 135 bone.rotation_quaternion = new_rotation
132 - bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) 136 + keyframe_insert(bone, 'rotation_quaternion', currentFrame)
133 137
134 valid_rotation = validate_rotation(bone, endFrame) 138 valid_rotation = validate_rotation(bone, endFrame)
135 if (not valid_rotation): 139 if (not valid_rotation):
136 new_rotation *= (-1) 140 new_rotation *= (-1)
137 bone.rotation_quaternion = new_rotation 141 bone.rotation_quaternion = new_rotation
138 - bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame)  
139 \ No newline at end of file 142 \ No newline at end of file
  143 + keyframe_insert(bone, 'rotation_quaternion', currentFrame)
140 \ No newline at end of file 144 \ No newline at end of file