Commit 1880bcdf9d16e473e4adf502d2311b8cdf6bfd77
1 parent
a9d95fa4
Exists in
master
Adicionado o movimento Coçar (mão direita)
Showing
3 changed files
with
85 additions
and
61 deletions
Show diff stats
libras.py
@@ -28,45 +28,23 @@ except Exception: | @@ -28,45 +28,23 @@ except Exception: | ||
28 | # ajusta as configurações de renderização | 28 | # ajusta as configurações de renderização |
29 | util.outconf() | 29 | util.outconf() |
30 | 30 | ||
31 | -# define a posição dos keyframes | ||
32 | -hands_default_frames = [15, 18] | ||
33 | - | ||
34 | -# define a posição dos keyframes | ||
35 | -hands_frames_retilineo = [30, 33] | ||
36 | - | ||
37 | -# Carrega o objeto presente no avatar | ||
38 | -armature = bpy.context.scene.objects.get('Armature.001') | ||
39 | - | ||
40 | # Cria uma Action | 31 | # Cria uma Action |
41 | act = bpy.context.scene.animation_data_create() | 32 | act = bpy.context.scene.animation_data_create() |
42 | 33 | ||
43 | -# Função responsável por selecionar as pose-libs e setar os frames | ||
44 | -def setPose(actions, parametesConf, positionFrames, bones): | ||
45 | - bpy.ops.object.mode_set(mode = 'OBJECT') | ||
46 | - bpy.ops.object.select_all(action="DESELECT") | ||
47 | - bpy.ops.object.mode_set(mode = 'POSE') | ||
48 | - for l in range(len(actions)): | ||
49 | - armature.pose_library = bpy.data.actions[actions[l]] | ||
50 | - for x in range(len(positionFrames)): | ||
51 | - bpy.ops.poselib.apply_pose(pose_index = parametesConf[l]) | ||
52 | - for i in range(0, (len(bones))): | ||
53 | - armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x]) | ||
54 | - armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) | ||
55 | - | ||
56 | # Função responsável por setar pose padrão | 34 | # Função responsável por setar pose padrão |
57 | def poseDefault(positionFrames, bones): | 35 | def poseDefault(positionFrames, bones): |
58 | - setPose([0], [0], positionFrames, bones) | 36 | + util.setPose([0], [0], positionFrames, bones) |
59 | 37 | ||
60 | # Função responsável por setar as configurações das mãos | 38 | # Função responsável por setar as configurações das mãos |
61 | def setHandConfiguration(actions, handParam, positionFrames, bones): | 39 | def setHandConfiguration(actions, handParam, positionFrames, bones): |
62 | - setPose(actions, handParam, positionFrames, bones) | 40 | + util.setPose(actions, handParam, positionFrames, bones) |
63 | 41 | ||
64 | # Função responsável por setar a configuração da face | 42 | # Função responsável por setar a configuração da face |
65 | def setFaceConfiguration(handParam, positionFrames, bones): | 43 | def setFaceConfiguration(handParam, positionFrames, bones): |
66 | - setPose([7], handParam, positionFrames, bones) | 44 | + util.setPose([7], handParam, positionFrames, bones) |
67 | 45 | ||
68 | # Sugestao: Alguma forma de uniformizar o calculo do endFrame (atualizado aqui e no movimento circular) | 46 | # Sugestao: Alguma forma de uniformizar o calculo do endFrame (atualizado aqui e no movimento circular) |
69 | -initialFrame, endFrame = 15, util.get_endFrame(json_input, hands_frames_retilineo) | 47 | +initialFrame, endFrame = 15, util.get_endFrame(json_input, util.hands_frames_retilineo) |
70 | 48 | ||
71 | #------------------ Configurações------------------------------ | 49 | #------------------ Configurações------------------------------ |
72 | 50 | ||
@@ -74,37 +52,33 @@ initialFrame, endFrame = 15, util.get_endFrame(json_input, hands_frames_retiline | @@ -74,37 +52,33 @@ initialFrame, endFrame = 15, util.get_endFrame(json_input, hands_frames_retiline | ||
74 | def configureHands(): | 52 | def configureHands(): |
75 | # Array com valores dos campos que serão passados pelo JSON | 53 | # Array com valores dos campos que serão passados pelo JSON |
76 | hands = ["rightHand", "leftHand"] | 54 | hands = ["rightHand", "leftHand"] |
77 | - iks = ['ik_FK.R', 'ik_FK.L'] | 55 | + iks = ["ik_FK.R", "ik_FK.L"] |
78 | bones_ = [util.rightBonesConf, util.leftBonesConf] | 56 | bones_ = [util.rightBonesConf, util.leftBonesConf] |
79 | #Array com as actions FAKES que seram selecionadas no Blender para cada lado do corpo | 57 | #Array com as actions FAKES que seram selecionadas no Blender para cada lado do corpo |
80 | - actions = [[1, 3, 5], [2, 4, 6]] | 58 | + actions = [[0, 2, 4], [1, 3, 5]] |
81 | global endFrame | 59 | global endFrame |
82 | for i in range(len(hands)): | 60 | for i in range(len(hands)): |
83 | if(json_input[hands[i]] != []): | 61 | if(json_input[hands[i]] != []): |
84 | move = json_input[hands[i]][0] | 62 | move = json_input[hands[i]][0] |
85 | - pose = armature.pose.bones[iks[i]] | 63 | + pose = util.armature.pose.bones[iks[i]] |
86 | handParam = json_input[hands[i]][-3:] | 64 | handParam = json_input[hands[i]][-3:] |
87 | 65 | ||
88 | - if(move == "pontual"): | ||
89 | - setHandConfiguration(actions[i], handParam, hands_default_frames, bones_[i]) | ||
90 | - else: | ||
91 | - setHandConfiguration(actions[i], handParam, hands_default_frames, bones_[i]) | ||
92 | - | ||
93 | - if(move == "circular" or move == "semicircular"): | ||
94 | - orientation, direction, radius, laps = json_input[hands[i]][1:5] | ||
95 | - endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) | ||
96 | - setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) | ||
97 | - elif(move == "retilineo"): | ||
98 | - setHandConfiguration(actions[i], json_input[hands[i]][-6:-3], hands_default_frames, bones_[i]) | ||
99 | - setHandConfiguration(actions[i], handParam, hands_frames_retilineo, bones_[i]) | ||
100 | - elif(move == "senoidal"): | ||
101 | - orientation, direction, radius, laps = json_input[hands[i]][1:5] | ||
102 | - endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) | ||
103 | - setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) | ||
104 | - elif(move == "contato"): | ||
105 | - contact_type, orientation, repetition = json_input[hands[i]][1:4] | ||
106 | - endFrame = moves.contato(pose, contact_type, orientation, repetition) | ||
107 | - setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) | 66 | + if(move in ["pontual, circular, semicircular, retilineo, senoidal"]): |
67 | + setHandConfiguration(actions[i], handParam, util.hands_default_frames, bones_[i]) | ||
68 | + | ||
69 | + if(move in ["circular", "semicircular"]): | ||
70 | + orientation, direction, radius, laps = json_input[hands[i]][1:5] | ||
71 | + endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) | ||
72 | + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) | ||
73 | + elif(move == "retilineo"): | ||
74 | + setHandConfiguration(actions[i], json_input[hands[i]][-6:-3], util.hands_default_frames, bones_[i]) | ||
75 | + setHandConfiguration(actions[i], handParam, util.hands_frames_retilineo, bones_[i]) | ||
76 | + elif(move == "senoidal"): | ||
77 | + orientation, direction, radius, laps = json_input[hands[i]][1:5] | ||
78 | + endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) | ||
79 | + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) | ||
80 | + elif(move == "contato"): | ||
81 | + endFrame = moves.contato(actions[i], json_input[hands[i]], bones_[i], pose) | ||
108 | 82 | ||
109 | # Função que inicia a configuração da face | 83 | # Função que inicia a configuração da face |
110 | def configureFace(): | 84 | def configureFace(): |
moves.py
1 | # -*- coding: UTF-8 -*- | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | ||
3 | +import bpy | ||
3 | import math | 4 | import math |
5 | +import util | ||
6 | +from pyutil import log | ||
4 | 7 | ||
5 | -def contato(pose, contact_type, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.25): | 8 | +def contato(action, input_hand, bones, pose, initialFrame = 18, frameJump = 10): |
6 | currentFrame = initialFrame | 9 | currentFrame = initialFrame |
10 | + contact_type = input_hand[1] | ||
11 | + | ||
7 | if (contact_type == "alisar"): | 12 | if (contact_type == "alisar"): |
8 | - currentFrame = alisar(pose, orientation, repetition, frameJump, initialFrame, width) | 13 | + currentFrame = alisar(action, input_hand, pose, bones, initialFrame, frameJump) |
14 | + elif (contact_type == "cocar"): | ||
15 | + currentFrame = cocar(action, input_hand, bones, initialFrame) | ||
9 | return currentFrame | 16 | return currentFrame |
10 | 17 | ||
11 | -def alisar(pose, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.25): | 18 | +def cocar(action, input_hand, bones, initialFrame = 18, repetition = 2, frameJump = 6): |
12 | currentFrame = initialFrame | 19 | currentFrame = initialFrame |
20 | + action[0] = util.movimento_mao_action_index | ||
21 | + | ||
22 | + pa_index = input_hand[-1] | ||
23 | + # TODO mão esquerda | ||
24 | + for i in range(0, repetition): | ||
25 | + util.setPose(action, [util.cocar_mao_aberta_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) | ||
26 | + currentFrame += frameJump | ||
27 | + util.setPose(action, [util.cocar_mao_fechada_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) | ||
28 | + currentFrame += frameJump | ||
29 | + return currentFrame | ||
30 | + | ||
31 | +def alisar(action, input_hand, pose, bones, initialFrame = 18, frameJump = 10, width = 0.25): | ||
32 | + currentFrame = initialFrame | ||
33 | + orientation, repetition = input_hand[2:4] | ||
34 | + handParam = input_hand[-3:] | ||
35 | + util.setPose(action, handParam, util.hands_default_frames, bones) | ||
36 | + | ||
13 | if (orientation == "perpendicular"): | 37 | if (orientation == "perpendicular"): |
14 | - currentFrame = alisarXY(pose, 1, repetition, frameJump, initialFrame, width) | 38 | + currentFrame = alisar_xy(pose, 1, repetition, initialFrame, frameJump, width) |
15 | elif (orientation == "paralelo"): | 39 | elif (orientation == "paralelo"): |
16 | - currentFrame = alisarXY(pose, 0, repetition, frameJump, initialFrame, width) | 40 | + currentFrame = alisar_xy(pose, 0, repetition, initialFrame, frameJump, width) |
17 | elif (orientation == "diagonal-direita"): | 41 | elif (orientation == "diagonal-direita"): |
18 | - currentFrame = alisar_diagonal(pose, True, repetition, frameJump, initialFrame, width) | 42 | + currentFrame = alisar_diagonal(pose, True, repetition, initialFrame, frameJump, width) |
19 | elif (orientation == "diagonal-esquerda"): | 43 | elif (orientation == "diagonal-esquerda"): |
20 | - currentFrame = alisar_diagonal(pose, False, repetition, frameJump, initialFrame, width) | ||
21 | - | 44 | + currentFrame = alisar_diagonal(pose, False, repetition, initialFrame, frameJump, width) |
45 | + | ||
46 | + util.setPose(action, handParam, [currentFrame], bones) | ||
22 | return currentFrame | 47 | return currentFrame |
23 | 48 | ||
24 | -def alisarXY(pose, orientation_index, repetition, frameJump = 10, initialFrame = 18, width = 0.25): | 49 | +def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump = 10, width = 0.25): |
25 | currentFrame = initialFrame | 50 | currentFrame = initialFrame |
26 | center = pose.location.x, pose.location.y, pose.location.z | 51 | center = pose.location.x, pose.location.y, pose.location.z |
27 | 52 | ||
@@ -32,11 +57,10 @@ def alisarXY(pose, orientation_index, repetition, frameJump = 10, initialFrame = | @@ -32,11 +57,10 @@ def alisarXY(pose, orientation_index, repetition, frameJump = 10, initialFrame = | ||
32 | pose.location[orientation_index] = center[orientation_index] + width | 57 | pose.location[orientation_index] = center[orientation_index] + width |
33 | pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | 58 | pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') |
34 | currentFrame += frameJump | 59 | currentFrame += frameJump |
35 | - #currentFrame -= frameJump | ||
36 | 60 | ||
37 | return currentFrame | 61 | return currentFrame |
38 | 62 | ||
39 | -def alisar_diagonal(pose, to_right, repetition, frameJump = 10, initialFrame = 18, width = 0.25): | 63 | +def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 10, width = 0.25): |
40 | currentFrame = initialFrame | 64 | currentFrame = initialFrame |
41 | center = pose.location.x, pose.location.y, pose.location.z | 65 | center = pose.location.x, pose.location.y, pose.location.z |
42 | 66 | ||
@@ -51,7 +75,6 @@ def alisar_diagonal(pose, to_right, repetition, frameJump = 10, initialFrame = 1 | @@ -51,7 +75,6 @@ def alisar_diagonal(pose, to_right, repetition, frameJump = 10, initialFrame = 1 | ||
51 | pose.location[1] = center[1] + width if to_right else center[1] - width | 75 | pose.location[1] = center[1] + width if to_right else center[1] - width |
52 | pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | 76 | pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') |
53 | currentFrame += frameJump | 77 | currentFrame += frameJump |
54 | - #currentFrame -= frameJump | ||
55 | 78 | ||
56 | return currentFrame | 79 | return currentFrame |
57 | 80 |
util.py
@@ -19,6 +19,33 @@ faceBonesConf = [15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] | @@ -19,6 +19,33 @@ faceBonesConf = [15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] | ||
19 | # Vetor com indices de todos os bones | 19 | # Vetor com indices de todos os bones |
20 | allBones = list(range(len(armature.pose.bones))) | 20 | allBones = list(range(len(armature.pose.bones))) |
21 | 21 | ||
22 | +# define a posição dos keyframes | ||
23 | +hands_default_frames = [15, 18] | ||
24 | + | ||
25 | +# define a posição dos keyframes | ||
26 | +hands_frames_retilineo = [30, 33] | ||
27 | + | ||
28 | +# Movimento de mão action | ||
29 | +movimento_mao_action_index = 7 | ||
30 | + | ||
31 | +# Movimento coçar - Índices de poses | ||
32 | +cocar_mao_aberta_index = 0 | ||
33 | +cocar_mao_fechada_index = 1 | ||
34 | +cocar_orientation_index = 12 | ||
35 | + | ||
36 | +# Função responsável por selecionar as pose-libs e setar os frames | ||
37 | +def setPose(actions, parametesConf, positionFrames, bones): | ||
38 | + bpy.ops.object.mode_set(mode = 'OBJECT') | ||
39 | + bpy.ops.object.select_all(action="DESELECT") | ||
40 | + bpy.ops.object.mode_set(mode = 'POSE') | ||
41 | + for l in range(len(actions)): | ||
42 | + armature.pose_library = bpy.data.actions[actions[l]] | ||
43 | + for x in range(len(positionFrames)): | ||
44 | + bpy.ops.poselib.apply_pose(pose_index = parametesConf[l]) | ||
45 | + for i in range(0, (len(bones))): | ||
46 | + armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x]) | ||
47 | + armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) | ||
48 | + | ||
22 | # Função que limpa todos os keyframes e define a quantidade de frames | 49 | # Função que limpa todos os keyframes e define a quantidade de frames |
23 | def erase_all_keyframes(): | 50 | def erase_all_keyframes(): |
24 | for i in bpy.data.objects: | 51 | for i in bpy.data.objects: |