-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
178 lines (165 loc) · 5.36 KB
/
build.gradle
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
apply plugin: 'download-task'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.undercouch:gradle-download-task:1.0'
}
}
ext {
dataDir = file("$buildDir/data")
}
task downloadData {
description 'Downloads msak0 speaker from MOCHA-TIMIT database.'
group 'data'
ext.dataFile = new File(buildDir, 'msak0.tar.gz')
outputs.files dataFile
doLast {
download {
src 'http://data.cstr.ed.ac.uk/mocha/msak0_v1.1.tar.gz'
dest dataFile
overwrite false
}
}
}
task unpackData {
description 'Unpacks one utterance from msak0 dataset for our demo.'
dependsOn downloadData
group 'data'
outputs.files fileTree(dataDir).include('*.ema')
doFirst {
dataDir.mkdirs()
}
doLast {
exec {
executable sevenzip
args 'x', downloadData.dataFile, '*.ema', '-y'
workingDir dataDir
}
}
}
task convertData {
description 'Convert EMA files to ASCII format, using EST.'
dependsOn unpackData
group 'data'
inputs.files fileTree(dataDir).include('*.ema')
outputs.files fileTree(dataDir).include('*.txt')
doLast {
inputs.files.each { infile ->
logger.warn "converting $infile.name"
exec {
executable ch_track
args infile.name, '-otype', 'est', '-o', infile.name.replace('.ema', '.txt')
workingDir dataDir
}
}
}
}
task generateMocapData {
description 'Generate BVH files from the ASCII EMA files.'
//dependsOn convertData
group 'data'
inputs.files convertData
outputs.files fileTree(dataDir).include('*.bvh')
doLast {
inputs.files.each { inputFile ->
def processheader = true
def header = [:]
def frames = ""
def roots = []
def channels = []
def data = []
inputFile.eachLine { line ->
def strlist = line.split()
//header end
if (line == "EST_Header_End") {
processheader = false
} else if (processheader) {
//parse header
header[strlist[0]] = strlist[1]
if (line.startsWith("Channel")) {
def channel = line.split(' ')
channels.add channel[1]
} else if (line.startsWith("NumFrames")) {
def numframes = line.split(' ')
frames = numframes[1]
}
}
//parse data
else {
data.add strlist[2..-1].collect { (it as float) / 1000 }
}
}
header.each { key, value ->
if (key.startsWith("Channel")) {
def rootlist = value.split('_')
if (!roots.contains(rootlist[0]) && rootlist.size() == 2) {
roots.add rootlist[0]
}
}
}
//map of channels and data
def spreadsheet = [:]
channels.eachWithIndex { chan, i ->
def datasort = []
data.each { dt ->
datasort.add dt[i]
spreadsheet[chan] = datasort
}
}
//write to file
def bvhfile = file(inputFile.path.replace('.txt', '.bvh'))
bvhfile.withWriter('ASCII') {
//format header
it.writeLine "HIERARCHY"
roots.each { root ->
it.writeLine "ROOT " + root
it.writeLine "{"
it.writeLine "\t OFFSET 0 0 0"
it.writeLine "\t CHANNELS 3 XPosition YPosition ZPosition"
it.writeLine "\t End Site"
it.writeLine "\t {"
it.writeLine "\t OFFSET 0 -1 0"
it.writeLine "\t }"
it.writeLine "}"
}
it.writeLine "MOTION"
it.writeLine "Frames: " + frames
it.writeLine "Frame Time: 0.002"
//format data
def frameit = frames.toInteger()
for (f in 1..frameit) {
roots.each { root ->
def x_chan = root + "_x"
def y_chan = root + "_y"
def x_value = spreadsheet[x_chan][f - 1]
def y_value = spreadsheet[y_chan][f - 1]
def z_value = "0"
it.write([x_value, y_value, z_value, '\t'].join('\t'))
}
it.write "\n"
}
}
logger.warn "Converting $inputFile.name to $bvhfile.name"
}
}
}
task buildModel {
description 'Uses Blender to build a model using external 3D assets.'
group 'model'
outputs.files 'animated_model.blend'
}
task buildDemo {
description 'Uses Blender to compile the model with the data into a demo app.'
dependsOn buildModel
group 'demo'
def scriptFile = file('src/python/test.py')
doLast {
exec {
executable blender
args '--python', scriptFile
workingDir buildDir
}
}
}