forked from SuperIRis/AEParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AEParser.js
executable file
·85 lines (80 loc) · 2.1 KB
/
AEParser.js
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
/*
AEParser
Convert After Effects tracking points to JSON
by @SuperIRis
updated by @mrgnou
V 0.2
17.12.13
*/
var AEParser = function(){
var aeData = {},
aeKeys = {"Units Per Second":"framesPerSecond", "Source Width":"width", "Source Height":"height", "Position":"position", "Scale":"scale", "Rotation":"rotation", "Frame":"frame", "X":"x", "Y":"y"},
parseBlock = function(block)
{
var blockItems;
var finalObject = {};
// 0 is title, 1 is subtitle (Frame, X, Y, Z)
switch (block[0])
{
case "Transform Position":
blockItems = ["frame", "x", "y", "z"];
finalObject.name = aeKeys["Position"];
break;
case "Transform Scale":
blockItems = ["frame", "xScale", "yScale", "zScale"];
finalObject.name = aeKeys["Scale"];
break;
case "Transform Rotation":
blockItems = ["frame", "degrees"];
finalObject.name = aeKeys["Rotation"];
break;
default:
return null;
}
var itemData;
var itemDataAe = [];
for (var j = 2, bl = block.length; j < bl; j++)
{
itemData = block[j].replace(/\t|\n/g, " ").replace(" ", "").split(" ");
if(itemData[itemData.length - 1] == "") itemData.pop();
for (var ji = 0; ji < itemData.length; ji += 4)
{
itemDataAe[itemDataAe.length] = {};
for (var jii = 0; jii < blockItems.length; jii++)
{
itemDataAe[itemDataAe.length-1][blockItems[jii]] = itemData[ji+jii];
}
}
}
finalObject.items = itemDataAe;
return finalObject;
};
return {
parse:function(parseText)
{
if(parseText.length)
{
var parseDatas = parseText.split("\n\n");
var generalData = parseDatas[1].split(" ");
for (var i = 1, gl = generalData.length; i < gl; i += 2)
{
if(aeKeys[generalData[i]])
{
aeData[aeKeys[generalData[i]]] = generalData[i + 1].replace(/\n/g, "");
}
}
aeData.data = [];
var parserResult;
for(var j = 2, pl = parseDatas.length; j < pl; j++)
{
parserResult = parseBlock(parseDatas[j].split("\n"));
if(parserResult)
{
aeData.data.push(parserResult);
}
}
return aeData;
}
}
};
}();