Commit b698cccd1d1b90fd994577bab6f78eae55968e5c
1 parent
af39d387
Exists in
master
Adiciona movimento de contato do tipo Alisar
Showing
3 changed files
with
55 additions
and
24 deletions
Show diff stats
libras.py
@@ -19,13 +19,13 @@ except Exception: | @@ -19,13 +19,13 @@ except Exception: | ||
19 | printStackTrace(__file__) | 19 | printStackTrace(__file__) |
20 | exit(1) | 20 | exit(1) |
21 | 21 | ||
22 | -# ajusta as configuraçẽs de renderização | 22 | +# ajusta as configurações de renderização |
23 | util.outconf() | 23 | util.outconf() |
24 | 24 | ||
25 | # define a posição dos keyframes | 25 | # define a posição dos keyframes |
26 | -hands_default_frames = [15,18] | 26 | +hands_default_frames = [15, 18] |
27 | # define a posição dos keyframes | 27 | # define a posição dos keyframes |
28 | -hands_frames_retilineo = [30,33] | 28 | +hands_frames_retilineo = [30, 33] |
29 | 29 | ||
30 | # Carrega o objeto presente no avatar | 30 | # Carrega o objeto presente no avatar |
31 | armature = bpy.context.scene.objects.get('Armature.001') | 31 | armature = bpy.context.scene.objects.get('Armature.001') |
@@ -41,7 +41,7 @@ def setPose(actions, parametesConf, positionFrames, bones): | @@ -41,7 +41,7 @@ def setPose(actions, parametesConf, positionFrames, bones): | ||
41 | for l in range(len(actions)): | 41 | for l in range(len(actions)): |
42 | armature.pose_library = bpy.data.actions[actions[l]] | 42 | armature.pose_library = bpy.data.actions[actions[l]] |
43 | for x in range(len(positionFrames)): | 43 | for x in range(len(positionFrames)): |
44 | - bpy.ops.poselib.apply_pose(pose_index= parametesConf[l]) | 44 | + bpy.ops.poselib.apply_pose(pose_index = parametesConf[l]) |
45 | for i in range(0, (len(bones))): | 45 | for i in range(0, (len(bones))): |
46 | armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x]) | 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]) | 47 | armature.pose.bones[bones[i]].keyframe_insert(data_path = 'rotation_quaternion', index = -1, frame = positionFrames[x]) |
@@ -50,15 +50,16 @@ def setPose(actions, parametesConf, positionFrames, bones): | @@ -50,15 +50,16 @@ def setPose(actions, parametesConf, positionFrames, bones): | ||
50 | def poseDefault(positionFrames, bones): | 50 | def poseDefault(positionFrames, bones): |
51 | setPose([0], [0], positionFrames, bones) | 51 | setPose([0], [0], positionFrames, bones) |
52 | 52 | ||
53 | -# Função responsável por setar as configuraçẽs das mãos | ||
54 | -def generationConfigurations(actions, handParam, positionFrames, bones): | 53 | +# Função responsável por setar as configurações das mãos |
54 | +def setHandConfiguration(actions, handParam, positionFrames, bones): | ||
55 | setPose(actions, handParam, positionFrames, bones) | 55 | setPose(actions, handParam, positionFrames, bones) |
56 | 56 | ||
57 | -def faceConfiguration(handParam, positionFrames, bones): | ||
58 | - # Função responsável por setar a configuração da face | 57 | +# Função responsável por setar a configuração da face |
58 | +def setFaceConfiguration(handParam, positionFrames, bones): | ||
59 | setPose([7], handParam, positionFrames, bones) | 59 | setPose([7], handParam, positionFrames, bones) |
60 | 60 | ||
61 | -initialFrame, endFrame = 15, util.get_endFrame(json_input,hands_frames_retilineo) | 61 | +# Sugestao: Alguma forma de uniformizar o calculo do endFrame (atualizado aqui e no movimento circular) |
62 | +initialFrame, endFrame = 15, util.get_endFrame(json_input, hands_frames_retilineo) | ||
62 | 63 | ||
63 | #------------------ Configurações------------------------------ | 64 | #------------------ Configurações------------------------------ |
64 | 65 | ||
@@ -75,33 +76,42 @@ def configureHands(): | @@ -75,33 +76,42 @@ def configureHands(): | ||
75 | if(json_input[hands[i]] != []): | 76 | if(json_input[hands[i]] != []): |
76 | move = json_input[hands[i]][0] | 77 | move = json_input[hands[i]][0] |
77 | pose = armature.pose.bones[iks[i]] | 78 | pose = armature.pose.bones[iks[i]] |
79 | + handParam = json_input[hands[i]][-3:] | ||
80 | + | ||
78 | if(move == "pontual"): | 81 | if(move == "pontual"): |
79 | - generationConfigurations(actions[i], json_input[hands[i]][-3:], [15, endFrame], bones_[i]) | 82 | + setHandConfiguration(actions[i], handParam, hands_default_frames, bones_[i]) |
80 | else: | 83 | else: |
81 | - generationConfigurations(actions[i], json_input[hands[i]][-3:], hands_default_frames, bones_[i]) | 84 | + setHandConfiguration(actions[i], handParam, hands_default_frames, bones_[i]) |
85 | + | ||
82 | if(move == "circular" or move == "semicircular"): | 86 | if(move == "circular" or move == "semicircular"): |
83 | orientation, direction, radius, laps = json_input[hands[i]][1:5] | 87 | orientation, direction, radius, laps = json_input[hands[i]][1:5] |
84 | endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) | 88 | endFrame = moves.circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) |
85 | - generationConfigurations(actions[i], json_input[hands[i]][-3:], [endFrame], bones_[i]) | 89 | + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) |
86 | elif(move == "retilineo"): | 90 | elif(move == "retilineo"): |
87 | - generationConfigurations(actions[i], json_input[hands[i]][-6:-3], hands_default_frames, bones_[i]) | ||
88 | - generationConfigurations(actions[i], json_input[hands[i]][-3:],hands_frames_retilineo, bones_[i]) | 91 | + setHandConfiguration(actions[i], json_input[hands[i]][-6:-3], hands_default_frames, bones_[i]) |
92 | + setHandConfiguration(actions[i], handParam, hands_frames_retilineo, bones_[i]) | ||
89 | elif(json_input[hands[i]][0] == "senoidal"): | 93 | elif(json_input[hands[i]][0] == "senoidal"): |
90 | orientation, direction, radius, laps = json_input[hands[i]][1:5] | 94 | orientation, direction, radius, laps = json_input[hands[i]][1:5] |
91 | endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) | 95 | endFrame = circular_or_semiCircular(pose, orientation, direction, radius, laps, 5) |
92 | - generationConfigurations(actions[i], json_input[hands[i]][-3:], [endFrame], bones_[i]) | 96 | + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) |
97 | + elif(json_input[hands[i]][0] == "contato"): | ||
98 | + contact_type, orientation, repetition = json_input[hands[i]][1:4] | ||
99 | + endFrame = moves.contato(pose, contact_type, orientation, repetition) | ||
100 | + setHandConfiguration(actions[i], handParam, [endFrame], bones_[i]) | ||
93 | 101 | ||
94 | # Função que inicia a configuração da face | 102 | # Função que inicia a configuração da face |
95 | def configureFace(): | 103 | def configureFace(): |
96 | global endFrame | 104 | global endFrame |
97 | if(json_input["facialExp"] != []): | 105 | if(json_input["facialExp"] != []): |
98 | # Set face | 106 | # Set face |
99 | - faceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) | 107 | + setFaceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) |
100 | 108 | ||
101 | -# Default Pose | ||
102 | -print("Total frames: %.3i" % (endFrame)) | ||
103 | -poseDefault([1, endFrame + 15], util.allBones) | ||
104 | configureHands() | 109 | configureHands() |
105 | configureFace() | 110 | configureFace() |
106 | 111 | ||
107 | -util.render_sign(json_input["userId"], json_input["signName"], 1, endFrame + 25) | 112 | +poseDefault([1, endFrame + 15], util.allBones) |
113 | + | ||
114 | +# Default Pose | ||
115 | +print("Total frames: %.3i" % (endFrame)) | ||
116 | + | ||
117 | +util.render_sign(json_input["userId"], json_input["signName"], 1, endFrame + 25) | ||
108 | \ No newline at end of file | 118 | \ No newline at end of file |
moves.py
@@ -2,6 +2,26 @@ | @@ -2,6 +2,26 @@ | ||
2 | 2 | ||
3 | import math | 3 | import math |
4 | 4 | ||
5 | +def contato(pose, contact_type, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.5): | ||
6 | + currentFrame = initialFrame | ||
7 | + if (contact_type == "alisar"): | ||
8 | + currentFrame = alisar(pose, contact_type, orientation, repetition) | ||
9 | + return currentFrame | ||
10 | + | ||
11 | +def alisar(pose, contact_type, orientation, repetition, frameJump = 10, initialFrame = 18, width = 0.5): | ||
12 | + center = pose.location.x, pose.location.y, pose.location.z | ||
13 | + currentFrame = initialFrame | ||
14 | + | ||
15 | + for i in range(0, repetition): | ||
16 | + pose.location.y = center[1] - width | ||
17 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | ||
18 | + currentFrame += frameJump | ||
19 | + pose.location.y = center[1] + width | ||
20 | + pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') | ||
21 | + currentFrame += frameJump | ||
22 | + currentFrame -= frameJump | ||
23 | + return currentFrame | ||
24 | + | ||
5 | def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None): | 25 | def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None): |
6 | center = pose.location.x, pose.location.y, pose.location.z | 26 | center = pose.location.x, pose.location.y, pose.location.z |
7 | if(orientation == 'perpendicular'): | 27 | if(orientation == 'perpendicular'): |
util.py
@@ -14,7 +14,7 @@ rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, | @@ -14,7 +14,7 @@ rightBonesConf = [1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, | ||
14 | leftBonesConf = [0, 43, 44, 45, 46, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82] | 14 | leftBonesConf = [0, 43, 44, 45, 46, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82] |
15 | 15 | ||
16 | # Vetor com indices de cada bone da face | 16 | # Vetor com indices de cada bone da face |
17 | -faceBonesConf =[15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] | 17 | +faceBonesConf = [15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] |
18 | 18 | ||
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))) |
@@ -38,19 +38,20 @@ def outconf(): | @@ -38,19 +38,20 @@ def outconf(): | ||
38 | # bpy.context.scene.render.filepath = '/tmp/' | 38 | # bpy.context.scene.render.filepath = '/tmp/' |
39 | 39 | ||
40 | def render_sign(userId, signName, beginFrame, endFrame): | 40 | def render_sign(userId, signName, beginFrame, endFrame): |
41 | - bpy.context.scene.render.filepath = "//users//"+ str(userId)+ "//"+ signName + "_" | 41 | + bpy.context.scene.render.filepath = "//users//" + str(userId)+ "//" + signName + "_" |
42 | bpy.context.scene.frame_start = beginFrame | 42 | bpy.context.scene.frame_start = beginFrame |
43 | bpy.context.scene.frame_end = endFrame | 43 | bpy.context.scene.frame_end = endFrame |
44 | outFilename = (bpy.context.scene.render.filepath + "%0.4i-%0.4i.mp4" % (bpy.context.scene.frame_start, bpy.context.scene.frame_end)) | 44 | outFilename = (bpy.context.scene.render.filepath + "%0.4i-%0.4i.mp4" % (bpy.context.scene.frame_start, bpy.context.scene.frame_end)) |
45 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | 45 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") |
46 | - file_rename(outFilename, __file__) | 46 | + #file_rename(outFilename, __file__) |
47 | bpy.ops.wm.quit_blender() | 47 | bpy.ops.wm.quit_blender() |
48 | 48 | ||
49 | # Função que recupera o frame final do movimento | 49 | # Função que recupera o frame final do movimento |
50 | -def get_endFrame(json_input,hands_frames_retilineo): | 50 | +def get_endFrame(json_input, hands_frames_retilineo): |
51 | endsFrame = [18] | 51 | endsFrame = [18] |
52 | if(json_input["rightHand"] != []): | 52 | if(json_input["rightHand"] != []): |
53 | if(json_input["rightHand"][0] == "circular"): | 53 | if(json_input["rightHand"][0] == "circular"): |
54 | + # Sugestao: json_input["rightHand"][4] eh o número de voltas/repeticoes? colocar numa variavel | ||
54 | endsFrame.append(int(json_input["rightHand"][4]*8*5+18)) | 55 | endsFrame.append(int(json_input["rightHand"][4]*8*5+18)) |
55 | elif(json_input["rightHand"][0] == "semicircular"): | 56 | elif(json_input["rightHand"][0] == "semicircular"): |
56 | endsFrame.append(int(json_input["rightHand"][4]*5*5+18)) | 57 | endsFrame.append(int(json_input["rightHand"][4]*5*5+18)) |