Commit bc03b22e4fa9ed5b9f5df6cf234b2a96bbda4267
1 parent
bbc5cf21
Exists in
master
Atualiza controller
Showing
5 changed files
with
109 additions
and
59 deletions
Show diff stats
Makefile
1 | -BLENDER = blender | ||
2 | -DONE = [\33[30;32mOK\33[m]\n | ||
3 | -FAIL = [\33[30;31mERRO\33[m]\n | ||
4 | -MODULE = Wikilibras | ||
5 | -CLEAR = @echo -n "\033c" | ||
6 | -CACHE = __pycache__ | ||
7 | -SCRIPT = libras.py | ||
8 | -AVATAR = avatar_Hozana_wikiLibras.blend | ||
9 | -JSON = '{"userId": 2,"rightHand": ["circular", "plano", "horario", 1, 2, 0, 50, 20], "leftHand":[], "facialExp": [6], "signName":"teste_circular"}' | ||
10 | - | ||
11 | -default: main | ||
12 | - | ||
13 | -main: | 1 | +BLENDER = blender |
2 | +PYTHON = python3 | ||
3 | +DONE = [\33[30;32mOK\33[m]\n | ||
4 | +FAIL = [\33[30;31mERRO\33[m]\n | ||
5 | +MODULE = Wikilibras | ||
6 | +CLEAR = @echo -n "\033c" | ||
7 | +CACHE = __pycache__ | ||
8 | +URL = git@git.lavid.ufpb.br:wikilibras-core | ||
9 | +MAIN = libras.py | ||
10 | +CONTROLLER = controller.py | ||
11 | +AVATAR = avatar_Hozana_wikiLibras.blend | ||
12 | +JSON = '{"userId": 2,"rightHand": ["circular", "plano", "horario", 1, 2, 0, 50, 20], "leftHand":[], "facialExp": [6], "signName":"teste_circular"}' | ||
13 | + | ||
14 | +default: py | ||
15 | + | ||
16 | +bpy: | ||
14 | $(CLEAR) | 17 | $(CLEAR) |
15 | - @echo Executando... | ||
16 | - @$(BLENDER) -b $(AVATAR) -P $(SCRIPT) $(JSON) && echo "$(DONE)" || { echo "$(FAIL)"; exit 1; } | 18 | + @echo Executando Blender ... |
19 | + @$(BLENDER) -b $(AVATAR) -P $(MAIN) $(JSON) && echo "$(DONE)" || { echo "$(FAIL)"; exit 1; } | ||
17 | 20 | ||
18 | clean: | 21 | clean: |
19 | $(CLEAR) | 22 | $(CLEAR) |
20 | @echo -n "Limpando..." | 23 | @echo -n "Limpando..." |
21 | @rm -rf $(CACHE) > /dev/null 2>&1 && echo " $(DONE)" || { echo " $(FAIL)"; exit 1; } | 24 | @rm -rf $(CACHE) > /dev/null 2>&1 && echo " $(DONE)" || { echo " $(FAIL)"; exit 1; } |
25 | + | ||
26 | +gclone: | ||
27 | + $(CLEAR) | ||
28 | + @echo "Clonando repositorio @(URL) ..." | ||
29 | + @exit | ||
30 | + | ||
31 | +gconf: | ||
32 | + $(CLEAR) | ||
33 | + @git --help | ||
34 | + @echo "Configurando git ..." | ||
35 | + @exit | ||
36 | + | ||
37 | +py: | ||
38 | + $(CLEAR) | ||
39 | + @echo Executando Python ... | ||
40 | + @$(PYTHON) $(CONTROLLER) $(JSON) && echo "$(DONE)" || { echo "$(FAIL)"; exit 1; } | ||
41 | + | ||
42 | +recv: | ||
43 | + $(CLEAR) | ||
44 | + @echo "Baixando atualizacao de @(URL)..." | ||
45 | + @exit | ||
46 | + | ||
47 | +send: | ||
48 | + $(CLEAR) | ||
49 | + @echo "Baixando atualizacao do repositorio @(URL)..." | ||
50 | + @exit | ||
51 | + @git pull "$(DONE)" || { echo " $(FAIL)"; exit 1; } |
controller.py
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +# -*- coding: UTF-8 -*- | ||
2 | + | ||
3 | +from os import getcwd | ||
4 | +from subprocess import call | ||
5 | +from sys import argv, path | ||
6 | + | ||
7 | +path.append(getcwd()) | ||
8 | + | ||
9 | +from pyutil import printStackTrace | ||
10 | + | ||
11 | +blend = "avatar_Hozana_wikiLibras.blend" | ||
12 | +main = "libras.py" | ||
13 | + | ||
14 | +if (len(argv) > 1): | ||
15 | + try: | ||
16 | + call(["blender", "-b", blend, "-P", main, argv[1]]) | ||
17 | + exit(0) | ||
18 | + except: | ||
19 | + printStackTrace(__file__) | ||
20 | + | ||
21 | +exit(1) |
libras.py
1 | # -*- coding: UTF-8 -*- | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | ||
3 | # importa modulos do Blender e Python | 3 | # importa modulos do Blender e Python |
4 | -import bpy | ||
5 | -import json | ||
6 | -import os | ||
7 | -import sys | 4 | +import bpy, json |
5 | +from os import getcwd | ||
6 | +from sys import argv, path | ||
8 | 7 | ||
9 | # insere o diretorio atual no path (permite o acesso aos modulos locais) | 8 | # insere o diretorio atual no path (permite o acesso aos modulos locais) |
10 | -sys.path.append(os.getcwd()) | 9 | +path.append(getcwd()) |
11 | 10 | ||
12 | # importa modulos locais | 11 | # importa modulos locais |
13 | -import util | ||
14 | -import moves | 12 | +import util, moves |
13 | +from pyutil import printStackTrace | ||
15 | 14 | ||
16 | # tenta decodificar o argumento JSON recebido | 15 | # tenta decodificar o argumento JSON recebido |
17 | try: | 16 | try: |
18 | - util.file_rename("./users/4/teste_circular_0001-0083.mp4") | ||
19 | - json_input = json.loads(sys.argv[5]) | 17 | + json_input = json.loads(argv[5]) |
20 | except Exception: | 18 | except Exception: |
21 | - util.printStackTrace(__file__) | 19 | + printStackTrace(__file__) |
22 | exit(1) | 20 | exit(1) |
23 | 21 | ||
24 | # ajusta as configuraçẽs de renderização | 22 | # ajusta as configuraçẽs de renderização |
@@ -101,7 +99,7 @@ def configureFace(): | @@ -101,7 +99,7 @@ def configureFace(): | ||
101 | faceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) | 99 | faceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) |
102 | 100 | ||
103 | # Default Pose | 101 | # Default Pose |
104 | -print(endFrame) | 102 | +print("Total frames: %.3i" % (endFrame)) |
105 | poseDefault([1, endFrame + 15], util.allBones) | 103 | poseDefault([1, endFrame + 15], util.allBones) |
106 | configureHands() | 104 | configureHands() |
107 | configureFace() | 105 | configureFace() |
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +# -*- coding: UTF-8 -*- | ||
2 | + | ||
3 | +def printStackTrace(filename): | ||
4 | + from sys import exc_info | ||
5 | + from os.path import basename | ||
6 | + print("\n[Exception begin]\n File: %s\n Name: %s\n Line: %s\n Type: %s\n Message: %s\n[Exception end]\n" % ( | ||
7 | + basename(filename), # basename(exc_info()[2].tb_frame.f_code.co_filename), | ||
8 | + exc_info()[2].tb_frame.f_code.co_name, | ||
9 | + exc_info()[2].tb_lineno, | ||
10 | + exc_info()[0].__name__, | ||
11 | + exc_info()[1], | ||
12 | + ) | ||
13 | + ) | ||
14 | + | ||
15 | +def file_rename(filename, fromfile): | ||
16 | + from shutil import move | ||
17 | + newFilename = "" | ||
18 | + isValidChar = True | ||
19 | + for char in reversed(filename): | ||
20 | + if (isValidChar == True): | ||
21 | + newFilename += char | ||
22 | + if (char == '_'): | ||
23 | + isValidChar = True | ||
24 | + elif (char == '.'): | ||
25 | + isValidChar = False | ||
26 | + if (len(filename) != len(newFilename)): | ||
27 | + try: | ||
28 | + move(filename, newFilename[::-1]) | ||
29 | + return 1 | ||
30 | + except Exception as e: | ||
31 | + printStackTrace(fromfile) | ||
32 | + return 0 | ||
33 | + return 0 |
util.py
@@ -2,8 +2,6 @@ | @@ -2,8 +2,6 @@ | ||
2 | 2 | ||
3 | import bpy | 3 | import bpy |
4 | import math | 4 | import math |
5 | -import sys | ||
6 | -import os | ||
7 | 5 | ||
8 | armature = bpy.context.scene.objects.get('Armature.001') | 6 | armature = bpy.context.scene.objects.get('Armature.001') |
9 | 7 | ||
@@ -21,16 +19,6 @@ faceBonesConf =[15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] | @@ -21,16 +19,6 @@ faceBonesConf =[15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] | ||
21 | # Vetor com indices de todos os bones | 19 | # Vetor com indices de todos os bones |
22 | allBones = list(range(len(armature.pose.bones))) | 20 | allBones = list(range(len(armature.pose.bones))) |
23 | 21 | ||
24 | -def printStackTrace(filename): | ||
25 | - print("\n[Exception]\n File: %s\n Name: %s\n Line: %s\n Type: %s\n Message: %s\n[Exception]\n" % ( | ||
26 | - os.path.basename(filename), # os.path.basename(sys.exc_info()[2].tb_frame.f_code.co_filename), | ||
27 | - sys.exc_info()[2].tb_frame.f_code.co_name, | ||
28 | - sys.exc_info()[2].tb_lineno, | ||
29 | - sys.exc_info()[0].__name__, | ||
30 | - sys.exc_info()[1], | ||
31 | - ) | ||
32 | - ) | ||
33 | - | ||
34 | # Função que limpa todos os keyframes e define a quantidade de frames | 22 | # Função que limpa todos os keyframes e define a quantidade de frames |
35 | def erase_all_keyframes(): | 23 | def erase_all_keyframes(): |
36 | for i in bpy.data.objects: | 24 | for i in bpy.data.objects: |
@@ -49,33 +37,13 @@ def outconf(): | @@ -49,33 +37,13 @@ def outconf(): | ||
49 | bpy.context.scene.render.ffmpeg.codec = 'H264' | 37 | bpy.context.scene.render.ffmpeg.codec = 'H264' |
50 | # bpy.context.scene.render.filepath = '/tmp/' | 38 | # bpy.context.scene.render.filepath = '/tmp/' |
51 | 39 | ||
52 | -def file_rename(filename): | ||
53 | - from shutil import move | ||
54 | - newFilename = "" | ||
55 | - isValidChar = True | ||
56 | - for char in reversed(filename): | ||
57 | - if (isValidChar == True): | ||
58 | - newFilename += char | ||
59 | - if (char == '_'): | ||
60 | - isValidChar = True | ||
61 | - elif (char == '.'): | ||
62 | - isValidChar = False | ||
63 | - if (len(filename) != len(newFilename)): | ||
64 | - try: | ||
65 | - move(filename, newFilename[::-1]) | ||
66 | - return 1 | ||
67 | - except Exception as e: | ||
68 | - printStackTrace(__file__) | ||
69 | - return 0 | ||
70 | - return 0 | ||
71 | - | ||
72 | def render_sign(userId, signName, beginFrame, endFrame): | 40 | def render_sign(userId, signName, beginFrame, endFrame): |
73 | bpy.context.scene.render.filepath = "//users//"+ str(userId)+ "//"+ signName + "_" | 41 | bpy.context.scene.render.filepath = "//users//"+ str(userId)+ "//"+ signName + "_" |
74 | bpy.context.scene.frame_start = beginFrame | 42 | bpy.context.scene.frame_start = beginFrame |
75 | bpy.context.scene.frame_end = endFrame | 43 | bpy.context.scene.frame_end = endFrame |
76 | 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)) |
77 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") | 45 | bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") |
78 | - file_rename(outFilename) | 46 | + file_rename(outFilename, __file__) |
79 | bpy.ops.wm.quit_blender() | 47 | bpy.ops.wm.quit_blender() |
80 | 48 | ||
81 | # Função que recupera o frame final do movimento | 49 | # Função que recupera o frame final do movimento |