Commit 91c658b763e131997bd49e86041798e070e25d53
1 parent
1348fa47
Exists in
master
Adicionado o movimento Riscar
Showing
2 changed files
with
90 additions
and
16 deletions
Show diff stats
moves.py
... | ... | @@ -3,27 +3,74 @@ |
3 | 3 | import bpy |
4 | 4 | import math |
5 | 5 | import util |
6 | -from pyutil import log | |
7 | 6 | |
8 | -def contato(action, input_hand, bones, pose, initialFrame = 18, frameJump = 10): | |
7 | +def contato(action, input_hand, bones, pose, initialFrame = 18): | |
9 | 8 | currentFrame = initialFrame |
10 | 9 | contact_type = input_hand[1] |
11 | 10 | |
12 | 11 | if (contact_type == "alisar"): |
13 | - currentFrame = alisar(action, input_hand, pose, bones, initialFrame, frameJump) | |
12 | + currentFrame = alisar(action, input_hand, pose, bones, initialFrame) | |
14 | 13 | elif (contact_type == "cocar"): |
15 | 14 | currentFrame = cocar(action, input_hand, bones, initialFrame) |
15 | + elif (contact_type == "tocar"): | |
16 | + currentFrame = tocar(action, input_hand, bones, initialFrame) | |
17 | + elif (contact_type == "riscar"): | |
18 | + currentFrame = riscar(action, input_hand, bones, initialFrame) | |
16 | 19 | return currentFrame |
17 | 20 | |
18 | -def cocar(action, input_hand, bones, initialFrame = 18, repetition = 2, frameJump = 6): | |
21 | +def riscar(action, input_hand, bones, pose, initialFrame = 18, bnAntBracoDegree = 2, bnMaoDegree = 45, frameJump = 10): | |
19 | 22 | currentFrame = initialFrame |
20 | - action[0] = util.movimento_mao_action_index | |
23 | + endFrame = initialFrame + 2 * frameJump | |
24 | + handParam = input_hand[-3:] | |
25 | + lado = "R" if util.rightBonesConf == bones else "L" | |
21 | 26 | |
27 | + bnAntBraco = bpy.context.object.pose.bones["BnAntBraco." + lado] | |
28 | + bnAntBraco.bone.select = True | |
29 | + util.apply_rotation(bnAntBraco, "Z", currentFrame, endFrame, bnAntBracoDegree) | |
30 | + currentFrame += frameJump | |
31 | + util.apply_rotation(bnAntBraco, "Z", currentFrame, endFrame, (-1)*(bnAntBracoDegree+1)) | |
32 | + bnAntBraco.bone.select = False | |
33 | + | |
34 | + currentFrame = initialFrame | |
35 | + util.setPose(action, handParam, [currentFrame], bones) | |
36 | + bnMao = bpy.context.object.pose.bones["BnMao." + lado] | |
37 | + bnMao.bone.select = True | |
38 | + util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) | |
39 | + currentFrame += frameJump | |
40 | + util.apply_rotation(bnMao, "Y", currentFrame, endFrame, (-2)*bnMaoDegree) | |
41 | + currentFrame += frameJump | |
42 | + util.apply_rotation(bnMao, "Y", currentFrame, endFrame, bnMaoDegree) | |
43 | + util.setPose([action[0]], [handParam[0]], [currentFrame], bones) | |
44 | + currentFrame += frameJump | |
45 | + bnMao.bone.select = False | |
46 | + return currentFrame | |
47 | + | |
48 | +def tocar(action, input_hand, bones, pose, initialFrame = 18, degree = 30, frameJump = 10): | |
49 | + currentFrame = initialFrame | |
50 | + endFrame = initialFrame + 2 * frameJump | |
51 | + handParam = input_hand[-3:] | |
52 | + util.setPose(action, handParam, [initialFrame], bones) | |
53 | + | |
54 | + lado = "BnMao.R" if util.rightBonesConf == bones else "BnMao.L" | |
55 | + bnMao = bpy.context.object.pose.bones[lado] | |
56 | + bnMao.bone.select = True | |
57 | + currentFrame += frameJump | |
58 | + util.apply_rotation(bnMao, "X", currentFrame, endFrame, -degree) | |
59 | + currentFrame += frameJump | |
60 | + util.apply_rotation(bnMao, "X", currentFrame, endFrame, degree) | |
61 | + util.setPose([action[0]], [handParam[0]], [currentFrame], bones) | |
62 | + currentFrame += frameJump | |
63 | + bnMao.bone.select = False | |
64 | + return currentFrame | |
65 | + | |
66 | +def cocar(action, input_hand, bones, initialFrame = 18, repetition = 2, frameJump = 6): | |
67 | + currentFrame = initialFrame | |
22 | 68 | pa_index = input_hand[-1] |
23 | - # TODO mão esquerda | |
69 | + | |
24 | 70 | for i in range(0, repetition): |
25 | 71 | util.setPose(action, [util.cocar_mao_aberta_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) |
26 | 72 | currentFrame += frameJump |
73 | + lastFrame = i == repetition - 1 | |
27 | 74 | util.setPose(action, [util.cocar_mao_fechada_index, pa_index, util.cocar_orientation_index], [currentFrame], bones) |
28 | 75 | currentFrame += frameJump |
29 | 76 | return currentFrame |
... | ... | @@ -57,7 +104,6 @@ def alisar_xy(pose, orientation_index, repetition, initialFrame = 18, frameJump |
57 | 104 | pose.location[orientation_index] = center[orientation_index] + width |
58 | 105 | pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') |
59 | 106 | currentFrame += frameJump |
60 | - | |
61 | 107 | return currentFrame |
62 | 108 | |
63 | 109 | def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 10, width = 0.25): |
... | ... | @@ -75,7 +121,6 @@ def alisar_diagonal(pose, to_right, repetition, initialFrame = 18, frameJump = 1 |
75 | 121 | pose.location[1] = center[1] + width if to_right else center[1] - width |
76 | 122 | pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') |
77 | 123 | currentFrame += frameJump |
78 | - | |
79 | 124 | return currentFrame |
80 | 125 | |
81 | 126 | def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None): | ... | ... |
util.py
... | ... | @@ -5,8 +5,6 @@ import math |
5 | 5 | |
6 | 6 | armature = bpy.context.scene.objects.get('Armature.001') |
7 | 7 | |
8 | -bones = ["BnMao.R", "BnMao.L"] | |
9 | - | |
10 | 8 | # Vetor com indices de cada bone do lado direito |
11 | 9 | rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66] |
12 | 10 | |
... | ... | @@ -25,13 +23,10 @@ hands_default_frames = [15, 18] |
25 | 23 | # define a posição dos keyframes |
26 | 24 | hands_frames_retilineo = [30, 33] |
27 | 25 | |
28 | -# Movimento de mão action | |
29 | -movimento_mao_action_index = 7 | |
30 | - | |
31 | 26 | # Movimento coçar - Índices de poses |
32 | -cocar_mao_aberta_index = 0 | |
33 | -cocar_mao_fechada_index = 1 | |
34 | -cocar_orientation_index = 12 | |
27 | +cocar_mao_aberta_index = 56 | |
28 | +cocar_mao_fechada_index = 24 | |
29 | +cocar_orientation_index = 20 | |
35 | 30 | |
36 | 31 | # Função responsável por selecionar as pose-libs e setar os frames |
37 | 32 | def setPose(actions, parametesConf, positionFrames, bones): |
... | ... | @@ -107,3 +102,37 @@ def get_endFrame(json_input, hands_frames_retilineo): |
107 | 102 | elif(json_input["rightHand"][0] == "retilineo"): |
108 | 103 | endsFrame.append(max(hands_frames_retilineo)) |
109 | 104 | return(max(endsFrame)) |
105 | + | |
106 | +def validate_rotation(bone, endFrame): | |
107 | + rotFrames = [[]] | |
108 | + scene = bpy.context.scene | |
109 | + frame_current = bpy.context.scene.frame_current | |
110 | + | |
111 | + for i in range(0, endFrame + 1,1): | |
112 | + scene.frame_set(i) | |
113 | + rotFrames[-1] = bone.rotation_quaternion.to_euler() | |
114 | + rotFrames.append( [] ) | |
115 | + | |
116 | + rotFrames.remove([]) | |
117 | + scene.frame_set(frame_current) | |
118 | + | |
119 | + for k in range(1, endFrame + 1, 1): | |
120 | + for i in range(0, 3, 1): | |
121 | + if (math.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > math.pi : | |
122 | + return False | |
123 | + return True | |
124 | + | |
125 | +# Axis: "X", "Y" e "Z" | |
126 | +def apply_rotation(bone, axis, currentFrame, endFrame, degree): | |
127 | + new_rotation = bone.rotation_quaternion.to_euler() | |
128 | + new_rotation.rotate_axis(axis, math.radians(degree)) | |
129 | + new_rotation = new_rotation.to_quaternion() | |
130 | + | |
131 | + bone.rotation_quaternion = new_rotation | |
132 | + bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) | |
133 | + | |
134 | + valid_rotation = validate_rotation(bone, endFrame) | |
135 | + if (not valid_rotation): | |
136 | + new_rotation *= (-1) | |
137 | + bone.rotation_quaternion = new_rotation | |
138 | + bone.keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = currentFrame) | |
110 | 139 | \ No newline at end of file | ... | ... |