diff --git a/Makefile b/Makefile index 5f82ff4..dad0ed5 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,51 @@ -BLENDER = blender -DONE = [\33[30;32mOK\33[m]\n -FAIL = [\33[30;31mERRO\33[m]\n -MODULE = Wikilibras -CLEAR = @echo -n "\033c" -CACHE = __pycache__ -SCRIPT = libras.py -AVATAR = avatar_Hozana_wikiLibras.blend -JSON = '{"userId": 2,"rightHand": ["circular", "plano", "horario", 1, 2, 0, 50, 20], "leftHand":[], "facialExp": [6], "signName":"teste_circular"}' - -default: main - -main: +BLENDER = blender +PYTHON = python3 +DONE = [\33[30;32mOK\33[m]\n +FAIL = [\33[30;31mERRO\33[m]\n +MODULE = Wikilibras +CLEAR = @echo -n "\033c" +CACHE = __pycache__ +URL = git@git.lavid.ufpb.br:wikilibras-core +MAIN = libras.py +CONTROLLER = controller.py +AVATAR = avatar_Hozana_wikiLibras.blend +JSON = '{"userId": 2,"rightHand": ["circular", "plano", "horario", 1, 2, 0, 50, 20], "leftHand":[], "facialExp": [6], "signName":"teste_circular"}' + +default: py + +bpy: $(CLEAR) - @echo Executando... - @$(BLENDER) -b $(AVATAR) -P $(SCRIPT) $(JSON) && echo "$(DONE)" || { echo "$(FAIL)"; exit 1; } + @echo Executando Blender ... + @$(BLENDER) -b $(AVATAR) -P $(MAIN) $(JSON) && echo "$(DONE)" || { echo "$(FAIL)"; exit 1; } clean: $(CLEAR) @echo -n "Limpando..." @rm -rf $(CACHE) > /dev/null 2>&1 && echo " $(DONE)" || { echo " $(FAIL)"; exit 1; } + +gclone: + $(CLEAR) + @echo "Clonando repositorio @(URL) ..." + @exit + +gconf: + $(CLEAR) + @git --help + @echo "Configurando git ..." + @exit + +py: + $(CLEAR) + @echo Executando Python ... + @$(PYTHON) $(CONTROLLER) $(JSON) && echo "$(DONE)" || { echo "$(FAIL)"; exit 1; } + +recv: + $(CLEAR) + @echo "Baixando atualizacao de @(URL)..." + @exit + +send: + $(CLEAR) + @echo "Baixando atualizacao do repositorio @(URL)..." + @exit + @git pull "$(DONE)" || { echo " $(FAIL)"; exit 1; } diff --git a/controller.py b/controller.py index e69de29..d9672db 100644 --- a/controller.py +++ b/controller.py @@ -0,0 +1,21 @@ +# -*- coding: UTF-8 -*- + +from os import getcwd +from subprocess import call +from sys import argv, path + +path.append(getcwd()) + +from pyutil import printStackTrace + +blend = "avatar_Hozana_wikiLibras.blend" +main = "libras.py" + +if (len(argv) > 1): + try: + call(["blender", "-b", blend, "-P", main, argv[1]]) + exit(0) + except: + printStackTrace(__file__) + +exit(1) diff --git a/libras.py b/libras.py index 8fd61ed..bd6d4aa 100644 --- a/libras.py +++ b/libras.py @@ -1,24 +1,22 @@ # -*- coding: UTF-8 -*- # importa modulos do Blender e Python -import bpy -import json -import os -import sys +import bpy, json +from os import getcwd +from sys import argv, path # insere o diretorio atual no path (permite o acesso aos modulos locais) -sys.path.append(os.getcwd()) +path.append(getcwd()) # importa modulos locais -import util -import moves +import util, moves +from pyutil import printStackTrace # tenta decodificar o argumento JSON recebido try: - util.file_rename("./users/4/teste_circular_0001-0083.mp4") - json_input = json.loads(sys.argv[5]) + json_input = json.loads(argv[5]) except Exception: - util.printStackTrace(__file__) + printStackTrace(__file__) exit(1) # ajusta as configuraçẽs de renderização @@ -101,7 +99,7 @@ def configureFace(): faceConfiguration(json_input["facialExp"], [endFrame/4], util.faceBonesConf) # Default Pose -print(endFrame) +print("Total frames: %.3i" % (endFrame)) poseDefault([1, endFrame + 15], util.allBones) configureHands() configureFace() diff --git a/pyutil.py b/pyutil.py new file mode 100644 index 0000000..7d6f469 --- /dev/null +++ b/pyutil.py @@ -0,0 +1,33 @@ +# -*- coding: UTF-8 -*- + +def printStackTrace(filename): + from sys import exc_info + from os.path import basename + print("\n[Exception begin]\n File: %s\n Name: %s\n Line: %s\n Type: %s\n Message: %s\n[Exception end]\n" % ( + basename(filename), # basename(exc_info()[2].tb_frame.f_code.co_filename), + exc_info()[2].tb_frame.f_code.co_name, + exc_info()[2].tb_lineno, + exc_info()[0].__name__, + exc_info()[1], + ) + ) + +def file_rename(filename, fromfile): + from shutil import move + newFilename = "" + isValidChar = True + for char in reversed(filename): + if (isValidChar == True): + newFilename += char + if (char == '_'): + isValidChar = True + elif (char == '.'): + isValidChar = False + if (len(filename) != len(newFilename)): + try: + move(filename, newFilename[::-1]) + return 1 + except Exception as e: + printStackTrace(fromfile) + return 0 + return 0 diff --git a/util.py b/util.py index 66bd6e9..7c0bfda 100644 --- a/util.py +++ b/util.py @@ -2,8 +2,6 @@ import bpy import math -import sys -import os armature = bpy.context.scene.objects.get('Armature.001') @@ -21,16 +19,6 @@ faceBonesConf =[15, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47] # Vetor com indices de todos os bones allBones = list(range(len(armature.pose.bones))) -def printStackTrace(filename): - print("\n[Exception]\n File: %s\n Name: %s\n Line: %s\n Type: %s\n Message: %s\n[Exception]\n" % ( - os.path.basename(filename), # os.path.basename(sys.exc_info()[2].tb_frame.f_code.co_filename), - sys.exc_info()[2].tb_frame.f_code.co_name, - sys.exc_info()[2].tb_lineno, - sys.exc_info()[0].__name__, - sys.exc_info()[1], - ) - ) - # Função que limpa todos os keyframes e define a quantidade de frames def erase_all_keyframes(): for i in bpy.data.objects: @@ -49,33 +37,13 @@ def outconf(): bpy.context.scene.render.ffmpeg.codec = 'H264' # bpy.context.scene.render.filepath = '/tmp/' -def file_rename(filename): - from shutil import move - newFilename = "" - isValidChar = True - for char in reversed(filename): - if (isValidChar == True): - newFilename += char - if (char == '_'): - isValidChar = True - elif (char == '.'): - isValidChar = False - if (len(filename) != len(newFilename)): - try: - move(filename, newFilename[::-1]) - return 1 - except Exception as e: - printStackTrace(__file__) - return 0 - return 0 - def render_sign(userId, signName, beginFrame, endFrame): bpy.context.scene.render.filepath = "//users//"+ str(userId)+ "//"+ signName + "_" bpy.context.scene.frame_start = beginFrame bpy.context.scene.frame_end = endFrame outFilename = (bpy.context.scene.render.filepath + "%0.4i-%0.4i.mp4" % (bpy.context.scene.frame_start, bpy.context.scene.frame_end)) bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "") - file_rename(outFilename) + file_rename(outFilename, __file__) bpy.ops.wm.quit_blender() # Função que recupera o frame final do movimento -- libgit2 0.21.2