moves.py 12.5 KB
# -*- coding: UTF-8 -*-

import math

def contato(pose, contact_type, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.25):
    currentFrame = initialFrame
    if (contact_type == "alisar"):
        currentFrame = alisar(pose, orientation, repetition, frameJump, initialFrame, width)
    return currentFrame

def alisar(pose, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.25):
    currentFrame = initialFrame
    if (orientation == "perpendicular"):
        currentFrame = alisarXY(pose, 1, repetition, frameJump, initialFrame, width)
    elif (orientation == "paralelo"):
        currentFrame = alisarXY(pose, 0, repetition, frameJump, initialFrame, width)
    elif (orientation == "diagonal-direita"):
        currentFrame = alisar_diagonal(pose, True, repetition, frameJump, initialFrame, width)
    elif (orientation == "diagonal-esquerda"):
        currentFrame = alisar_diagonal(pose, False, repetition, frameJump, initialFrame, width)
        
    return currentFrame

def alisarXY(pose, orientation_index, repetition, frameJump = 10, initialFrame = 18, width = 0.25):
    currentFrame = initialFrame
    center =  pose.location.x, pose.location.y, pose.location.z
        
    for i in range(0, repetition):
        pose.location[orientation_index] = center[orientation_index] - width      
        pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location')
        currentFrame += frameJump
        pose.location[orientation_index] = center[orientation_index] + width
        pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location')
        currentFrame += frameJump
    #currentFrame -= frameJump
    
    return currentFrame

def alisar_diagonal(pose, to_right, repetition, frameJump = 10, initialFrame = 18, width = 0.25):
    currentFrame = initialFrame
    center =  pose.location.x, pose.location.y, pose.location.z
        
    for i in range(0, repetition):
        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')
        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')
        currentFrame += frameJump
    #currentFrame -= frameJump
    
    return currentFrame

def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None):
    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)
        else:
            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)
        else:
            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)
        else:
            endFrame = locationCircular(center, radius, 0, 2, 1, pose, 0, laps, intensity, initialFrame,turn)
    return endFrame

# center[3]: float vector (posição xyz centro)
# radius: float (distancia do centro)
# i_axis: int (indice do eixo i [0 | 1 | 2])
# j_axis: int (indice do eixo j [0 | 1 | 2])
# k_axis: int (indice do eixo k [0 | 1 | 2])
def locationCircular(center, radius, i_axis, j_axis, k_axis, pose, initialPosition, laps, frameJump = 5, initialFrame = 18, turn = None):
    sqrt22 = radius * (math.sqrt(2) / 2)
    rad2 = (radius/2)
    currentFrame = initialFrame
    for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1):
        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')
            currentFrame += frameJump
        if ((l % 8) == 1):
            pose.location[i_axis] = center[i_axis] + sqrt22
            pose.location[j_axis] = center[j_axis] + sqrt22
            pose.location[k_axis] = center[k_axis]
            if(turn == 1):
                pose.location[i_axis] = center[i_axis] + sqrt22
                pose.location[j_axis] = center[j_axis] + rad2
                pose.location[k_axis] = center[k_axis] - rad2
            elif(turn == -1):
                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')
            currentFrame += frameJump
        if ((l % 8) == 2):
            pose.location[i_axis] = center[i_axis]
            pose.location[j_axis] = center[j_axis] + radius
            pose.location[k_axis] = center[k_axis]
            if(turn == 1):
                pose.location[j_axis] = center[j_axis] + sqrt22
                pose.location[k_axis] = center[k_axis] - sqrt22
            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')
            currentFrame += frameJump
        if ((l % 8) == 3):
            pose.location[i_axis] = center[i_axis] - sqrt22
            pose.location[j_axis] = center[j_axis] + sqrt22
            pose.location[k_axis] = center[k_axis]
            if(turn == 1):
                pose.location[i_axis] = center[i_axis] - sqrt22
                pose.location[j_axis] = center[j_axis] + rad2
                pose.location[k_axis] = center[k_axis] - rad2
            elif(turn == -1):
                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')
            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')
            currentFrame += frameJump

        if ((l % 8) == 5):
            pose.location[i_axis] = center[i_axis] - sqrt22
            pose.location[j_axis] = center[j_axis] - sqrt22
            pose.location[k_axis] = center[k_axis]
            if(turn == 1):
                pose.location[i_axis] = center[i_axis] - sqrt22
                pose.location[j_axis] = center[j_axis] - rad2
                pose.location[k_axis] = center[k_axis] + rad2
            elif(turn == -1):
                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')
            currentFrame += frameJump

        if ((l % 8) == 6):
            pose.location[i_axis] = center[i_axis]
            pose.location[j_axis] = center[j_axis] - radius
            pose.location[k_axis] = center[k_axis]
            if(turn == 1):
                pose.location[j_axis] = center[j_axis] - sqrt22
                pose.location[k_axis] = center[k_axis] + sqrt22
            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')
            currentFrame += frameJump

        if ((l % 8) == 7):
            pose.location[i_axis] = center[i_axis] + sqrt22
            pose.location[j_axis] = center[j_axis] - sqrt22
            pose.location[k_axis] = center[k_axis]
            if(turn == 1):
                pose.location[i_axis] = center[i_axis] + sqrt22
                pose.location[j_axis] = center[j_axis] - rad2
                pose.location[k_axis] = center[k_axis] + rad2
            elif(turn == -1):
                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')
            currentFrame += frameJump
    currentFrame -= frameJump
    return currentFrame

def locationHelicoidal(center, startRadius, incRadius, x, y, z,pose, currentLoc, laps, frameJump):
    sqrt22 = radius * math.sqrt(2) / 2
    allLaps = math.floor(8 * laps) + 1

    #for i in range(currentLoc, currentLoc + math.floor(8 * laps) + 1):
    for i in range(currentLoc, currentLoc + allLaps):
        print("All Laps:", allLaps)
        if ((i % 8) == 0 ):
            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')
            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')
            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')
            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')
            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')
            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')
            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')
            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')
            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