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
moves.py
... ... @@ -33,7 +33,7 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree
33 33  
34 34 currentFrame = initialFrame
35 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 37 bnMao.bone.select = True
38 38 util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree)
39 39 currentFrame += frameJump
... ... @@ -99,10 +99,10 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump
99 99  
100 100 for i in range(0, repetition):
101 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 103 currentFrame += frameJump
104 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 106 currentFrame += frameJump
107 107 return currentFrame
108 108  
... ... @@ -114,12 +114,12 @@ def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 1
114 114 pose.location[0] = center[0] - width if to_right else center[0] - width
115 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 118 currentFrame += frameJump
119 119  
120 120 pose.location[0] = center[0] + width if to_right else center[0] + width
121 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 123 currentFrame += frameJump
124 124 return currentFrame
125 125  
... ... @@ -127,19 +127,19 @@ def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensi
127 127 center = pose.location.x, pose.location.y, pose.location.z
128 128 if(orientation == 'perpendicular'):
129 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 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 133 elif(orientation == 'paralelo'):
134 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 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 138 elif(orientation == 'plano'):
139 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 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 143 return endFrame
144 144  
145 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 152 rad2 = (radius/2)
153 153 currentFrame = initialFrame
154 154 for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1):
155   - if ((l % 8) == 0 ):
  155 + if ((l % 8) == 0):
156 156 pose.location[i_axis] = center[i_axis] + radius
157 157 pose.location[j_axis] = center[j_axis]
158 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 160 currentFrame += frameJump
161 161 if ((l % 8) == 1):
162 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 170 pose.location[i_axis] = center[i_axis] + sqrt22
171 171 pose.location[j_axis] = center[j_axis] + rad2
172 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 174 currentFrame += frameJump
175 175 if ((l % 8) == 2):
176 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 182 elif(turn == -1):
183 183 pose.location[j_axis] = center[j_axis] + sqrt22
184 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 186 currentFrame += frameJump
187 187 if ((l % 8) == 3):
188 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 196 pose.location[i_axis] = center[i_axis] - sqrt22
197 197 pose.location[j_axis] = center[j_axis] + rad2
198 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 200 currentFrame += frameJump
201 201  
202 202 if ((l % 8) == 4):
203 203 pose.location[i_axis] = center[i_axis] - radius
204 204 pose.location[j_axis] = center[j_axis]
205 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 207 currentFrame += frameJump
208 208  
209 209 if ((l % 8) == 5):
... ... @@ -218,7 +218,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
218 218 pose.location[i_axis] = center[i_axis] - sqrt22
219 219 pose.location[j_axis] = center[j_axis] - rad2
220 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 222 currentFrame += frameJump
223 223  
224 224 if ((l % 8) == 6):
... ... @@ -231,7 +231,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
231 231 elif(turn == -1):
232 232 pose.location[j_axis] = center[j_axis] - sqrt22
233 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 235 currentFrame += frameJump
236 236  
237 237 if ((l % 8) == 7):
... ... @@ -246,7 +246,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi
246 246 pose.location[i_axis] = center[i_axis] + sqrt22
247 247 pose.location[j_axis] = center[j_axis] - rad2
248 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 250 currentFrame += frameJump
251 251 currentFrame -= frameJump
252 252 return currentFrame
... ... @@ -262,70 +262,56 @@ def locationHelicoidal(center, startRadius, incRadius, x, y, z,pose, currentLoc,
262 262 pose.location[x] = center[x] + radius
263 263 pose.location[y] = center[y]
264 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 266 bpy.context.scene.frame_end += frameJump
267 267  
268 268 if ((i % 8) == 1):
269 269 pose.location[x] = center[x] + sqrt22
270 270 pose.location[y] = center[y] + sqrt22
271 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 273 bpy.context.scene.frame_end += frameJump
274 274  
275 275 if ((i % 8) == 2):
276 276 pose.location[x] = center[x]
277 277 pose.location[y] = center[y] + radius
278 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 280 bpy.context.scene.frame_end += frameJump
281 281  
282 282 if ((i % 8) == 3):
283 283 pose.location[x] = center[x] - sqrt22
284 284 pose.location[y] = center[y] + sqrt22
285 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 287 bpy.context.scene.frame_end += frameJump
288 288  
289 289 if ((i % 8) == 4):
290 290 pose.location[x] = center[x] - radius
291 291 pose.location[y] = center[y]
292 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 294 bpy.context.scene.frame_end += frameJump
295 295  
296 296 if ((i % 8) == 5):
297 297 pose.location[x] = center[x] - sqrt22
298 298 pose.location[y] = center[y] - sqrt22
299 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 301 bpy.context.scene.frame_end += frameJump
302 302  
303 303 if ((i % 8) == 6):
304 304 pose.location[x] = center[x]
305 305 pose.location[y] = center[y] - radius
306 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 308 bpy.context.scene.frame_end += frameJump
309 309  
310 310 if ((i % 8) == 7):
311 311 pose.location[x] = center[x] + sqrt22
312 312 pose.location[y] = center[y] - sqrt22
313 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 315 bpy.context.scene.frame_end += frameJump
316 316  
317 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
... ...
util.py
... ... @@ -38,8 +38,12 @@ def setPose(actions, parametesConf, positionFrames, bones):
38 38 for x in range(len(positionFrames)):
39 39 bpy.ops.poselib.apply_pose(pose_index = parametesConf[l])
40 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 48 # Função que limpa todos os keyframes e define a quantidade de frames
45 49 def erase_all_keyframes():
... ... @@ -129,10 +133,10 @@ def apply_rotation(bone, axis, currentFrame, endFrame, degree):
129 133 new_rotation = new_rotation.to_quaternion()
130 134  
131 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 138 valid_rotation = validate_rotation(bone, endFrame)
135 139 if (not valid_rotation):
136 140 new_rotation *= (-1)
137 141 bone.rotation_quaternion = new_rotation
138   - bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame)
139 142 \ No newline at end of file
  143 + keyframe_insert(bone, 'rotation_quaternion', currentFrame)
140 144 \ No newline at end of file
... ...