-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptimizeAnim.js
117 lines (106 loc) · 3.75 KB
/
OptimizeAnim.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
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
function isSameValue(valueMap, lastValues, props) {
for (var i = 0; i < props.length; i++) {
if (valueMap[props[i]] !== lastValues[i]) {
return false;
}
}
return true;
}
function saveValue(valueMap, lastValues, props) {
for (var i = 0; i < props.length; i++) {
lastValues[i] = valueMap[props[i]];
}
}
function processTimeLine(timelineMap, props) {
var newTimeLine = [];
var lastValues = [];
for (var i = 0; i < props.length; i++) {
lastValues[i] = 'undefined';
}
var lastValueMap = null;
for (var i = 0; i < timelineMap.length; i++) {
var valueMap = timelineMap[i];
if (!isSameValue(valueMap, lastValues, props)) {
if (lastValueMap && isSameValue(lastValueMap, lastValues, props)) {
newTimeLine.push(lastValueMap);
lastValueMap = null;
}
newTimeLine.push(valueMap);
saveValue(valueMap, lastValues, props);
} else {
lastValueMap = valueMap;
}
}
return newTimeLine;
}
function processOneAnim(map, name) {
if (map.slots) {
for (var slotName in map.slots) {
var slotMap = map.slots[slotName];
for (var timelineName in slotMap) {
var timelineMap = slotMap[timelineName];
if (timelineName == "color") {
slotMap[timelineName] = processTimeLine(timelineMap, ['color', 'curve']);
}
else if (timelineName = "attachment") {
slotMap[timelineName] = processTimeLine(timelineMap, ['name']);
}
}
}
}
if (map.bones) {
for (var boneName in map.bones) {
var boneMap = map.bones[boneName];
for (var timelineName in boneMap) {
var timelineMap = boneMap[timelineName];
if (timelineName === "rotate") {
boneMap[timelineName] = processTimeLine(timelineMap, ['angle', 'curve']);
}
else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
boneMap[timelineName] = processTimeLine(timelineMap, ['x', 'y', 'curve']);
}
}
}
}
if (map.ik) {
for (var constraintName in map.ik) {
var constraintMap = map.ik[constraintName];
map.ik[constraintName] = processTimeLine(constraintMap, ['mix', 'bendPositive', 'curve']);
}
}
if (map.transform) {
for (var constraintName in map.transform) {
var constraintMap = map.transform[constraintName];
map.transform[constraintName] = processTimeLine(constraintMap, ['rotateMix', 'translateMix', 'scaleMix', 'shearMix', 'curve'])
}
}
if (map.paths) {
for (var constraintName in map.paths) {
var constraintMap = map.paths[constraintName];
for (var timelineName in constraintMap) {
var timelineMap = constraintMap[timelineName];
if (timelineName === "position" || timelineName === "spacing") {
constraintMap[timelineName] = processTimeLine(timelineMap, ['timelineName', 'curve'])
}
else if (timelineName === "mix") {
constraintMap[timelineName] = processTimeLine(timelineMap, ['rotateMix', 'translateMix', 'curve'])
}
}
}
}
if (map.deform) {
//skip
}
var drawOrderNode = map.drawOrder;
if (drawOrderNode == null)
drawOrderNode = map.draworder;
if (drawOrderNode != null) {
//skip
}
if (map.events) {
//skip
}
}
module.exports = {
processOneAnim : processOneAnim,
}