Commit b698cccd1d1b90fd994577bab6f78eae55968e5c

Authored by Adabriand Furtado
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 19 printStackTrace(__file__)
20 20 exit(1)
21 21  
22   -# ajusta as configuraçs de renderização
  22 +# ajusta as configurações de renderização
23 23 util.outconf()
24 24  
25 25 # define a posição dos keyframes
26   -hands_default_frames = [15,18]
  26 +hands_default_frames = [15, 18]
27 27 # define a posição dos keyframes
28   -hands_frames_retilineo = [30,33]
  28 +hands_frames_retilineo = [30, 33]
29 29  
30 30 # Carrega o objeto presente no avatar
31 31 armature = bpy.context.scene.objects.get('Armature.001')
... ... @@ -41,7 +41,7 @@ def setPose(actions, parametesConf, positionFrames, bones):
41 41 for l in range(len(actions)):
42 42 armature.pose_library = bpy.data.actions[actions[l]]
43 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 45 for i in range(0, (len(bones))):
46 46 armature.pose.bones[bones[i]].keyframe_insert(data_path = 'location', index = -1, frame = positionFrames[x])
47 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 50 def poseDefault(positionFrames, bones):
51 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 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 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 64 #------------------ Configurações------------------------------
64 65  
... ... @@ -75,33 +76,42 @@ def configureHands():
75 76 if(json_input[hands[i]] != []):
76 77 move = json_input[hands[i]][0]
77 78 pose = armature.pose.bones[iks[i]]
  79 + handParam = json_input[hands[i]][-3:]
  80 +
78 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 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 86 if(move == "circular" or move == "semicircular"):
83 87 orientation, direction, radius, laps = json_input[hands[i]][1:5]
84 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 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 93 elif(json_input[hands[i]][0] == "senoidal"):
90 94 orientation, direction, radius, laps = json_input[hands[i]][1:5]
91 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 102 # Função que inicia a configuração da face
95 103 def configureFace():
96 104 global endFrame
97 105 if(json_input["facialExp"] != []):
98 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 109 configureHands()
105 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 118 \ No newline at end of file
... ...
moves.py
... ... @@ -2,6 +2,26 @@
2 2  
3 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 25 def circular_or_semiCircular(pose, orientation, direction, radius, laps, intensity = 5, initialFrame = 18, turn = None):
6 26 center = pose.location.x, pose.location.y, pose.location.z
7 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 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 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 19 # Vetor com indices de todos os bones
20 20 allBones = list(range(len(armature.pose.bones)))
... ... @@ -38,19 +38,20 @@ def outconf():
38 38 # bpy.context.scene.render.filepath = '/tmp/'
39 39  
40 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 42 bpy.context.scene.frame_start = beginFrame
43 43 bpy.context.scene.frame_end = endFrame
44 44 outFilename = (bpy.context.scene.render.filepath + "%0.4i-%0.4i.mp4" % (bpy.context.scene.frame_start, bpy.context.scene.frame_end))
45 45 bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "")
46   - file_rename(outFilename, __file__)
  46 + #file_rename(outFilename, __file__)
47 47 bpy.ops.wm.quit_blender()
48 48  
49 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 51 endsFrame = [18]
52 52 if(json_input["rightHand"] != []):
53 53 if(json_input["rightHand"][0] == "circular"):
  54 + # Sugestao: json_input["rightHand"][4] eh o número de voltas/repeticoes? colocar numa variavel
54 55 endsFrame.append(int(json_input["rightHand"][4]*8*5+18))
55 56 elif(json_input["rightHand"][0] == "semicircular"):
56 57 endsFrame.append(int(json_input["rightHand"][4]*5*5+18))
... ...