util.py
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import bpy
import math as m
import subprocess as sub
bones = ["BnMao.R", "BnMao.L"]
def sizeRadius(value):
value = value.lower()
if (value == 'grande'):
return 1
elif (value == 'medio'):
return 0.6
else:
return 0.3
# 1600 x 1200 -> 00:01:25.158198
# 640 x 480 -> 00:00:41.590239
def outconf():
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 100
bpy.context.scene.render.image_settings.file_format = 'H264'
bpy.context.scene.render.ffmpeg.format = 'MPEG4'
bpy.context.scene.render.ffmpeg.codec = 'H264'
# bpy.context.scene.render.filepath = '/tmp/'
def flip(frame, lado):
print ("flipou Frame: " + str(frame) + " BONE: " + str(bones[lado]))
for i in range(0, 4, 1):
bpy.Object.Get("Armature.001").getAction().getChannelIpo(bones[lado]).getCurves()[i][frame]*=-1
def fixRots(lado):
keyFrames = bpy.Object.Get("Armature.001").getAction().getFrameNumbers()
print (keyFrames)
rotFrames = [[]]
status = [True] * (len(keyFrames) + 1)
for i in range(0,len(keyFrames),1):
bpy.Set('curframe',keyFrames[i])
rotFrames[-1] = bpy.Object.Get("Armature.001").getPose().bones[bones[lado]].quat.toEuler()
rotFrames.append( [] )
rotFrames.remove([])
for k in range(1, len(keyFrames), 1):
for i in range(0, 3, 1):
if (m.fabs(rotFrames[k][i] - rotFrames[k-1][i])) > 180 :
status[k] = False
print (status[0:len(status)-1])
for k in range(1, len(keyFrames), 1):
if status[k] == False:
flip(keyFrames[k], lado)
if status[k+1] == True:
status[k+1] = False
else:
status[k+1] = True
print (status[0:len(status)-1])
'''
def get_calculo_mov(radius,orientation,sense):
'''
def render_sign(userId,signName,beginFrame,endFrame):
bpy.context.scene.render.filepath = "//"+ str(userId)+ "//"+ signName + "_"
bpy.context.scene.frame_start = beginFrame
bpy.context.scene.frame_end = endFrame
bpy.ops.render.render(animation = True, write_still = False, layer = "", scene = "")
bpy.ops.wm.quit_blender()
"""
def lib_parse (filename):
res = []
cfg = None
with open(filename) as f:
for ln in f:
ln = ln.split()
if len(ln) == 0:
continue
elif len(ln) in (1,2,3,4):
cfg = Struct(name = ln[0],
bones = [])
res.append (cfg)
else:
name = ln[0]
loc = [float(x) for x in ln[2:5]]
rot = [float(x) for x in ln[6:]]
cfg.bones.append (Struct(name = name, loc = loc, rot = rot))
return res
def read_lines_file(fileName):
with open(fileName,"r") as f:
return [x.strip() for x in f]
# Struct-like dictionary. obj['x'] == obj.x
class Struct:
def __init__ (self, **kws):
self.__dict__ = kws
def __getitem__(self, i):
return self.__dict__[i]
def __repr__ (self):
return repr(self.__dict__)
def parseVideo(id,nameSign,endFrame):
print ("Convertendo AVI em FLV usando ffmpeg")
num = endFrame + 30
if(num > 100):
s = "0" + str(num);
else:
s = "00" + str(num);
print (nameSign+"_0001_"+s+".avi");
sub.call(["ffmpeg", "-i", "/usr/share/WikiLIBRAS/server/ScriptsPython/"+nameSign+"_0001_"+s+".avi", "-bpy", "2028k", "-s", "640x480", "-r", "30", "-acodec", "copy", nameSign+".flv"])
print (id + "**********************************************")
sub.call(["mv", "/usr/share/WikiLIBRAS/server/ScriptsPython/"+nameSign+".flv", "/home/gtaaas/gtaaas_web/public/uploads/files/"+id+ "/"])
"""