Commit 6bf2e3c28ace3a8a604de379978fad4973a15e7f

Authored by André Araújo
1 parent 0f2ad8a3
Exists in master

Adiciona movimento pontual

Makefile
1   -JSON = \
  1 +#JSON = $(JSON_CIRCULAR)
  2 +JSON = $(JSON_PONTUAL)
  3 +
  4 +JSON_CIRCULAR = \
2 5 '{ \
3 6 "userId": "lavid", \
4   - "sinal": "Modelo JSON", \
  7 + "sinal": "modelo_circular", \
5 8 "interpolacao": "normal", \
6 9 "movimentos": [ \
7 10 { \
... ... @@ -17,9 +20,9 @@ JSON = \
17 20 "velocidade": "normal", \
18 21 "lado_oposto": false, \
19 22 "sentido_inverso": false, \
20   - "articulacao": 124, \
21   - "configuracao": 60, \
22   - "orientacao": 142 \
  23 + "articulacao": 80, \
  24 + "configuracao": 10, \
  25 + "orientacao": 20 \
23 26 } \
24 27 }, \
25 28 "mao_direita": { \
... ... @@ -39,6 +42,31 @@ JSON = \
39 42 ] \
40 43 }'
41 44  
  45 +JSON_PONTUAL = \
  46 +'{ \
  47 + "userId": "lavid", \
  48 + "sinal": "modelo_pontual", \
  49 + "interpolacao": "normal", \
  50 + "movimentos": [ \
  51 + { \
  52 + "facial": { \
  53 + "expressao": 10, \
  54 + "transicao": "normal", \
  55 + "duracao": "normal" \
  56 + }, \
  57 + "mao_direita": { \
  58 + "pontual": { \
  59 + "articulacao": 71, \
  60 + "configuracao": 19, \
  61 + "orientacao": 11 \
  62 + } \
  63 + }, \
  64 + "mao_esquerda": { \
  65 + } \
  66 + } \
  67 + ] \
  68 +}'
  69 +
42 70 BLEND = avatar_cartoon_v2.74.blend
43 71 CONTROLLER = controller.py
44 72 MAIN = libras.py
... ...
decode.py
... ... @@ -9,9 +9,6 @@ def circular_semicircular(js_movement, current_frame, frame_jump, is_right_hand,
9 9 # decodificar valores
10 10 ray = dict_ray[js_movement['raio']]
11 11 period = dict_period[js_movement['velocidade']]
12   - #print('setar articulacao:', js_movement['articulacao'])
13   - #print('setar configuracao:', js_movement['configuracao'])
14   - #print('setar orientacao:', js_movement['orientacao'])
15 12 # diminuir a velocidade
16 13 if (js_movement['velocidade'] == 'lento'):
17 14 period += 10
... ... @@ -49,7 +46,7 @@ def redemoinho(js_movement, current_frame, frame_jump, is_right_hand):
49 46 pass
50 47  
51 48 def pontual(js_movement, current_frame, frame_jump, is_right_hand):
52   - pass
  49 + return moves.pontual(js_movement, current_frame, frame_jump, is_right_hand)
53 50  
54 51 def senoidal(js_movement, current_frame, frame_jump, is_right_hand):
55 52 pass
... ...
facial.py
... ... @@ -5,11 +5,11 @@ import util
5 5  
6 6 # duracao na posicao selecionada
7 7 dict_duration = {
8   - 'inicial': 20,
  8 + 'inicial': 10,
9 9 'lento': 15,
10 10 'normal': 10,
11 11 'rapido': 5,
12   - 'final': 20,
  12 + 'final': 10,
13 13 }
14 14  
15 15 # tempo de entrada e saida na posicao selecionada
... ... @@ -86,28 +86,25 @@ def decode_expression(timeline_facial, js_facial, initial_interpolation = dict_d
86 86 frame_transition = dict_transition[js_facial['transicao']]
87 87 # insere o primeiro keyframe
88 88 if (timeline_facial == 0):
89   - set_expression(timeline_facial, 0, initial_interpolation)
90   - set_expression(timeline_facial, index, frame_duration, frame_transition)
91   - set_expression(timeline_facial, 0, frame_duration)
  89 + timeline_facial = set_expression(timeline_facial, 0, initial_interpolation)
  90 + timeline_facial = set_expression(timeline_facial, index, frame_duration, frame_transition)
  91 + timeline_facial = set_expression(timeline_facial, 0, frame_duration)
92 92 return timeline_facial
93 93  
94 94 """
95 95 # unit test
96 96 def main():
97   - interpolation_start = 20
98   - interpolation_end = 20
99 97 timeline_facial = 0
100   - pose_max_range = round(bpy.data.actions[library_name].frame_range[1])
101 98 util.delete_all_keyframes()
102   - apply_pose(0, util.facial_expression_id)
103   - for i in range(0, pose_max_range + 1):
  99 + expressoes = list(range(0, round(bpy.data.actions[util.facial_expression_id].frame_range[1]) + 1))
  100 + expressoes = [10, 11]
  101 + for i in expressoes:
104 102 js_facial = {
105   - "expressao": i, # random.randint(0, pose_max_range),
106   - "transicao": 'normal',
107   - "duracao": 'normal'
  103 + "expressao": i,
  104 + "transicao": "normal",
  105 + "duracao": "normal"
108 106 }
109 107 timeline_facial = decode_expression(timeline_facial, js_facial, dict_duration['inicial'])
110   - print('facial expression %d current frame:' % (js_facial['expressao']), timeline_facial)
111 108 bpy.context.scene.frame_end = timeline_facial + dict_duration['final']
112 109 bpy.ops.screen.animation_play(reverse = False)
113 110  
... ...
moves.py
... ... @@ -37,9 +37,9 @@ def riscar(action, mov_param, bones, initialFrame = 25, frameJump = 10, bnAntBra
37 37 bnMao = bpy.context.object.pose.bones["BnMao." + lado]
38 38 currentFrame += frameJump
39 39 util.apply_rotation(bnMao, "Y", currentFrame, bnMaoDegree)
40   - currentFrame += int(frameJump/2)
  40 + currentFrame += int(frameJump/2)
41 41 util.apply_rotation(bnMao, "Y", currentFrame, (-1)*bnMaoDegree)
42   - currentFrame += int(frameJump/2)
  42 + currentFrame += int(frameJump/2)
43 43 util.apply_rotation(bnMao, "Y", currentFrame, (-2)*bnMaoDegree)
44 44 currentFrame += frameJump
45 45 util.setPose(action, handParam, [currentFrame], bones)
... ... @@ -138,14 +138,14 @@ def alisar_diagonal(boneIK, to_right, repetition, initialFrame = 18, frameJump =
138 138 # raio: "grande" raio = 1.5, velocidade: "normal" periodo = 55
139 139 # raio: "grande" raio = 1.5, velocidade: "lento" periodo = 65
140 140 # @param obj: (objeto) bone, mesh, e.g.
141   -# @param frame_atual: (int) posicao onde o primeiro keyframe vai ser inserido
  141 +# @param current_frame: (int) posicao onde o primeiro keyframe vai ser inserido
142 142 # @param raio: (int) raio da circunferencia
143 143 # @param periodo: (int) quantidade de keyframes necessarios para completar uma volta completa
144 144 # @param x: (int) in [0,1,2] define qual eixo vai variar no seno (0 = eixo X, 1 = eixo Y, 2 = eixo Z)
145 145 # @param y: (int) in [0,1,2] define qual eixo vai variar no cosseno (0 = eixo X, 1 = eixo Y, 2 = eixo Z)
146 146 # @param usar_lado_oposto: (bool) inverte o lado da primeira posicao (pode ser util em alguns casos para espelhar)
147 147 # @param usar_sentido_oposto (bool) inverte o sentido do movimento (horario para anti-horario)
148   -def circular(obj, frame_atual, raio, periodo, x = 0, y = 1, usar_lado_oposto = False, usar_sentido_oposto = False, meia_volta = False):
  148 +def circular(obj, current_frame, raio, periodo, x = 0, y = 1, usar_lado_oposto = False, usar_sentido_oposto = False, meia_volta = False):
149 149 # limita inferiormente
150 150 if (periodo < 16):
151 151 periodo = 16
... ... @@ -173,10 +173,38 @@ def circular(obj, frame_atual, raio, periodo, x = 0, y = 1, usar_lado_oposto = F
173 173 limite = round(limite / 2)
174 174 for i in range(k, limite + 1):
175 175 # reduz a quantidade de keyframes
176   - if (frame_atual % 2 == 0):
  176 + if (current_frame % 2 == 0):
177 177 obj.location[x] = loc[x] + (raio * math.cos(i / periodo * (2 * math.pi)))
178 178 obj.location[y] = loc[y] + (raio * math.sin(i / periodo * (2 * math.pi)))
179   - util.keyframe_insert(obj, 'location', frame_atual)
180   - frame_atual += 1
181   - util.keyframe_insert(obj, 'location', frame_atual)
182   - return periodo - 1
183 179 \ No newline at end of file
  180 + util.keyframe_insert(obj, 'location', current_frame)
  181 + current_frame += 1
  182 + util.keyframe_insert(obj, 'location', current_frame)
  183 + return periodo - 1
  184 +
  185 +def pontual(js_movement, current_frame, frame_jump, is_right_hand):
  186 + #import facial
  187 + print(util.right_bones_conf)
  188 + hand_param = read_hand_param(js_movement)
  189 + bones = util.right_bones_conf if is_right_hand else util.leftBonesConf
  190 + #poselib = None
  191 + if (is_right_hand):
  192 + #poselib = util.pa_direita_id
  193 + hand_actions = util.right_hand_actions
  194 + else:
  195 + #poselib = util.pa_esquerda_id
  196 + hand_actions = util.left_hand_actions
  197 + #ik_bones = util.dict_bones[poselib]
  198 + #util.select_bones(ik_bones)
  199 + util.keyframe_insert(bones, 'location', current_frame, False)
  200 + #facial.keyframe_insert(current_frame, ik_bones, ['location'])
  201 + current_frame += frame_jump
  202 + #facial.apply_pose(js_movement['articulacao'], poselib)
  203 + pyutil.log("XXXXXXXXXXXXXXXX")
  204 + util.setPose(hand_actions, hand_param, [current_frame], bones, False)
  205 + pyutil.log("YYYYYYYYYYYYYYYY")
  206 + #facial.keyframe_insert(current_frame, ik_bones, ['location'])
  207 + current_frame += frame_jump
  208 + #facial.keyframe_insert(current_frame, ik_bones, ['location'])
  209 + util.keyframe_insert(bones, 'location', current_frame, False)
  210 + #util.deselect_bones(ik_bones)
  211 + return current_frame
... ...
util.py
... ... @@ -14,12 +14,14 @@ dict_bones = {
14 14 "01_conf_direita": ['BnDedo.1.R', 'BnDedo.1.R.006', 'BnDedo.1.R.005', 'BnDedo.1.R.001', 'BnDedo.1.R.008', 'BnDedo.1.R.007', 'BnDedo.1.R.002', 'BnDedo.1.R.010', 'BnDedo.1.R.009', 'BnDedo.1.R.003', 'BnDedo.1.R.012', 'BnDedo.1.R.011', 'BnDedo.1.R.004', 'BnDedo.1.R.014', 'BnDedo.1.R.013'],
15 15 "02_conf_esquerda": ['BnDedo.1.L', 'BnDedo.1.L.006', 'BnDedo.1.L.005', 'BnDedo.1.L.001', 'BnDedo.1.L.008', 'BnDedo.1.L.007', 'BnDedo.1.L.002', 'BnDedo.1.L.010', 'BnDedo.1.L.009', 'BnDedo.1.L.003', 'BnDedo.1.L.012', 'BnDedo.1.L.011', 'BnDedo.1.L.004', 'BnDedo.1.L.014', 'BnDedo.1.L.013'],
16 16 "03_pa_direita": ['ik_FK.R', 'BnPolyV.R'],
17   - "04_pa_direita": ['ik_FK.R', 'BnPolyV.R'],
  17 + "04_pa_esquerda": ['ik_FK.L', 'BnPolyV.L'],
18 18 "05_orient_direita": ['BnMao.R'],
19 19 "06_orient_esquerda": ['BnMao.L'],
20 20 "07_facial": ['BnPescoco', 'BnCabeca', 'BnSobrancCentro.L', 'BnSobrancCentro.R', 'BnSobrancLateral.L', 'BnSobrancLateral.R', 'BnPalpebSuper.L', 'BnPalpebInfe.L', 'BnSobrancCentro', 'BnLabioCentroSuper', 'BnBochecha.L', 'BnBochecha.R', 'BnLabioCentroInfer', 'BnBocaCanto.L', 'BnBocaCanto.R', 'BnMandibula', 'BnLingua', 'BnLingua.003', 'BnLingua.001', 'BnLingua.002', 'BnPalpebSuper.R', 'BnPalpebInfe.R', 'BnOlhosMira', 'BnOlhoMira.L', 'BnOlhoMira.R', 'BnOlho.L', 'BnOlho.R']
21 21 }
22 22  
  23 +right_bones_conf = dict_bones["01_conf_direita"] + dict_bones["03_pa_direita"] + dict_bones["05_orient_direita"]
  24 +
23 25 # Vetor com indices de cada bone do lado direito
24 26 rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66]
25 27  
... ... @@ -87,22 +89,29 @@ def setPose(actions, parametesConf, positionFrames, bones, collisionFlag = True)
87 89 for x in range(len(positionFrames)):
88 90 for l in range(len(actions)):
89 91 action = actions[l]
  92 + select_bones(bones)
90 93 armature.pose_library = bpy.data.actions[action]
91 94 bpy.ops.poselib.apply_pose(pose_index = parametesConf[l])
  95 + deselect_bones(bones)
  96 + bpy.context.object.pose_library = None
92 97 for i in range(0, (len(bones))):
93 98 bone = armature.pose.bones[bones[i]]
94 99 validHandConf = action in [conf_direita_id, conf_esquerda_id] and "BnDedo" in bone.name
95   - validPA = action in [pa_direita_id, pa_esquerda_id] and "ik_FK" in bone.name or "BnPolyV" in bone.name
  100 + validPA = action in [pa_direita_id, pa_esquerda_id] and ("ik_FK" in bone.name or "BnPolyV" in bone.name)
96 101 validO = action in [orient_direita_id, orient_esquerda_id] and "BnMao" in bone.name
97 102 if (validHandConf or validPA or validO):
98 103 keyframe_insert(bone, 'location', positionFrames[x], collisionFlag and validPA, validO)
99 104 keyframe_insert(bone, 'rotation_quaternion', positionFrames[x], collisionFlag and validPA, validO)
100 105  
101   -def keyframe_insert(bone, path, positionFrame, collisionFlag = True, rotationFlag = False):
  106 +def internal_keyframe_insert(bone, path, positionFrame, collisionFlag = True, rotationFlag = False):
102 107 # Limit hand depth
  108 + if ("ik_FK.R" == bone.name):
  109 + print("VERDADE", bone.location, positionFrame)
103 110 if ("ik_FK" in bone.name and bone.location.z < 1):
104 111 bone.location.z = 1
  112 + bone.bone.select = True
105 113 bone.keyframe_insert(data_path = path, index = -1, frame = positionFrame)
  114 + bone.bone.select = False
106 115 keyframe_id = bone.name + "_" + path
107 116 last_keyframe = last_keyframe_dict[keyframe_id] if keyframe_id in last_keyframe_dict else 0
108 117 last_keyframe_dict[keyframe_id] = positionFrame
... ... @@ -111,6 +120,16 @@ def keyframe_insert(bone, path, positionFrame, collisionFlag = True, rotationFla
111 120 if (collisionFlag):
112 121 checkCollision(bone, path, positionFrame, last_keyframe)
113 122  
  123 +def keyframe_insert(bones, path, positionFrame, collisionFlag = True, rotationFlag = False):
  124 + if (isinstance(bones, list)):
  125 + for bone in bones:
  126 + if (isinstance(bone, int) or isinstance(bone, str)):
  127 + internal_keyframe_insert(bpy.context.object.pose.bones[bone], path, positionFrame, collisionFlag, rotationFlag)
  128 + else:
  129 + internal_keyframe_insert(bone, path, positionFrame, collisionFlag, rotationFlag)
  130 + else:
  131 + internal_keyframe_insert(bones, path, positionFrame, collisionFlag, rotationFlag)
  132 +
114 133 def resetIKPosition(isRightHand):
115 134 armature.pose_library = bpy.data.actions[pa_direita_id if isRightHand else pa_esquerda_id]
116 135 bpy.ops.poselib.apply_pose(pose_index = 0)
... ...