diff --git a/moves.py b/moves.py index 12b350c..fc9e1e6 100644 --- a/moves.py +++ b/moves.py @@ -33,7 +33,7 @@ def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree currentFrame = initialFrame util.setPose(action, handParam, [currentFrame], bones) - bnMao = bpy.context.object.pose.bones["BnMao." + lado] + bnMao = bpy.context.object.pose.bones["BnMao." + lado] bnMao.bone.select = True util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) currentFrame += frameJump @@ -99,10 +99,10 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump for i in range(0, repetition): pose.location[orientation_index] = center[orientation_index] - width - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump pose.location[orientation_index] = center[orientation_index] + width - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump return currentFrame @@ -114,12 +114,12 @@ def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 1 pose.location[0] = center[0] - width if to_right else center[0] - width pose.location[1] = center[1] - width if to_right else center[1] + width - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump pose.location[0] = center[0] + width if to_right else center[0] + width pose.location[1] = center[1] + width if to_right else center[1] - width - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump return currentFrame @@ -127,19 +127,19 @@ def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensi center = pose.location.x, pose.location.y, pose.location.z if(orientation == 'perpendicular'): if(direction == 'horario'): - endFrame = locationCircular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame,turn) + endFrame = locationCircular(center, radius, 1, 0, 2, pose, 0, laps, intensity, initialFrame, turn) else: - endFrame = locationCircular(center, radius, 0, 1, 2, pose, 0, laps, intensity, initialFrame,turn) + endFrame = locationCircular(center, radius, 0, 1, 2, pose, 0, laps, intensity, initialFrame, turn) elif(orientation == 'paralelo'): if(direction == 'horario'): - endFrame = locationCircular(center, radius, 1, 2, 0, pose, 0, laps, intensity, initialFrame,turn) + endFrame = locationCircular(center, radius, 1, 2, 0, pose, 0, laps, intensity, initialFrame, turn) else: - endFrame = locationCircular(center, radius, 2, 1, 0, pose, 0, laps, intensity, initialFrame,turn) + endFrame = locationCircular(center, radius, 2, 1, 0, pose, 0, laps, intensity, initialFrame, turn) elif(orientation == 'plano'): if(direction == 'horario'): - endFrame = locationCircular(center, radius, 2, 0, 1, pose, 0, laps, intensity, initialFrame,turn) + endFrame = locationCircular(center, radius, 2, 0, 1, pose, 0, laps, intensity, initialFrame, turn) else: - endFrame = locationCircular(center, radius, 0, 2, 1, pose, 0, laps, intensity, initialFrame,turn) + endFrame = locationCircular(center, radius, 0, 2, 1, pose, 0, laps, intensity, initialFrame, turn) return endFrame # center[3]: float vector (posição xyz centro) @@ -152,11 +152,11 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi rad2 = (radius/2) currentFrame = initialFrame for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1): - if ((l % 8) == 0 ): + if ((l % 8) == 0): pose.location[i_axis] = center[i_axis] + radius pose.location[j_axis] = center[j_axis] pose.location[k_axis] = center[k_axis] - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump if ((l % 8) == 1): pose.location[i_axis] = center[i_axis] + sqrt22 @@ -170,7 +170,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi pose.location[i_axis] = center[i_axis] + sqrt22 pose.location[j_axis] = center[j_axis] + rad2 pose.location[k_axis] = center[k_axis] + rad2 - pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', initialPosition) currentFrame += frameJump if ((l % 8) == 2): pose.location[i_axis] = center[i_axis] @@ -182,7 +182,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi elif(turn == -1): pose.location[j_axis] = center[j_axis] + sqrt22 pose.location[k_axis] = center[k_axis] + sqrt22 - pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', initialPosition) currentFrame += frameJump if ((l % 8) == 3): pose.location[i_axis] = center[i_axis] - sqrt22 @@ -196,14 +196,14 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi pose.location[i_axis] = center[i_axis] - sqrt22 pose.location[j_axis] = center[j_axis] + rad2 pose.location[k_axis] = center[k_axis] + rad2 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', initialPosition) currentFrame += frameJump if ((l % 8) == 4): pose.location[i_axis] = center[i_axis] - radius pose.location[j_axis] = center[j_axis] pose.location[k_axis] = center[k_axis] - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump if ((l % 8) == 5): @@ -218,7 +218,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi pose.location[i_axis] = center[i_axis] - sqrt22 pose.location[j_axis] = center[j_axis] - rad2 pose.location[k_axis] = center[k_axis] - rad2 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump if ((l % 8) == 6): @@ -231,7 +231,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi elif(turn == -1): pose.location[j_axis] = center[j_axis] - sqrt22 pose.location[k_axis] = center[k_axis] - sqrt22 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump if ((l % 8) == 7): @@ -246,7 +246,7 @@ def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPositi pose.location[i_axis] = center[i_axis] + sqrt22 pose.location[j_axis] = center[j_axis] - rad2 pose.location[k_axis] = center[k_axis] - rad2 - pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', currentFrame) currentFrame += frameJump currentFrame -= frameJump return currentFrame @@ -262,70 +262,56 @@ def locationHelicoidal(center, startRadius, incRadius, x, y, z,pose, currentLoc, pose.location[x] = center[x] + radius pose.location[y] = center[y] pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 1): pose.location[x] = center[x] + sqrt22 pose.location[y] = center[y] + sqrt22 pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 2): pose.location[x] = center[x] pose.location[y] = center[y] + radius pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 3): pose.location[x] = center[x] - sqrt22 pose.location[y] = center[y] + sqrt22 pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 4): pose.location[x] = center[x] - radius pose.location[y] = center[y] pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 5): pose.location[x] = center[x] - sqrt22 pose.location[y] = center[y] - sqrt22 pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 6): pose.location[x] = center[x] pose.location[y] = center[y] - radius pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump if ((i % 8) == 7): pose.location[x] = center[x] + sqrt22 pose.location[y] = center[y] - sqrt22 pose.location[z] += incRadius /allLaps - pose.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') + util.keyframe_insert(pose, 'location', bpy.context.scene.frame_end) bpy.context.scene.frame_end += frameJump bpy.context.scene.frame_end -= frameJump - -def locationSenoidal(obj): - seno = 0 - waveHeight = 5.0 - wave = 5 - pi180 = math.pi / 180 - print(pi180) - for wave in range(0, 3): - for i in range(-180, 180): - obj.location[1] = math.sin(i * (pi180)) * waveHeight - obj.location[2] += 0.005 - if (i % 10 == 0): - obj.keyframe_insert(frame = bpy.context.scene.frame_end, index = -1, data_path = 'location') - bpy.context.scene.frame_end += 1 diff --git a/util.py b/util.py index a621f35..93313b9 100644 --- a/util.py +++ b/util.py @@ -38,8 +38,12 @@ def setPose(actions, parametesConf, positionFrames, bones): for x in range(len(positionFrames)): bpy.ops.poselib.apply_pose(pose_index = parametesConf[l]) for i in range(0, (len(bones))): - armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x]) - armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) + keyframe_insert(armature.pose.bones[bones[i]], 'location', positionFrames[x]) + keyframe_insert(armature.pose.bones[bones[i]], 'rotation_quaternion', positionFrames[x]) + +def keyframe_insert(bone, path, positionFrame): + bone.keyframe_insert(data_path = path, index = -1, frame = positionFrame) + # collision # Função que limpa todos os keyframes e define a quantidade de frames def erase_all_keyframes(): @@ -129,10 +133,10 @@ def apply_rotation(bone, axis, currentFrame, endFrame, degree): new_rotation = new_rotation.to_quaternion() bone.rotation_quaternion = new_rotation - bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) + keyframe_insert(bone, 'rotation_quaternion', currentFrame) valid_rotation = validate_rotation(bone, endFrame) if (not valid_rotation): new_rotation *= (-1) bone.rotation_quaternion = new_rotation - bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) \ No newline at end of file + keyframe_insert(bone, 'rotation_quaternion', currentFrame) \ No newline at end of file -- libgit2 0.21.2