From e8750e1078fe72ed8486c2cc4b13c967dc750baf Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Sat, 30 Dec 2017 18:47:41 -0500 Subject: [skotty] Fix path close handling ... and add a transform animation sample TBR= Change-Id: I27a67d7861dffb9ca22a5e7155ee0eba3b4575f6 Reviewed-on: https://skia-review.googlesource.com/90023 Reviewed-by: Florin Malita Commit-Queue: Florin Malita --- experimental/skotty/SkottyAnimator.cpp | 3 + experimental/skotty/SkottyProperties.cpp | 10 ++- resources/skotty/skotty_sample_2.json | 123 +++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 resources/skotty/skotty_sample_2.json diff --git a/experimental/skotty/SkottyAnimator.cpp b/experimental/skotty/SkottyAnimator.cpp index e08cf35995..f08e7088da 100644 --- a/experimental/skotty/SkottyAnimator.cpp +++ b/experimental/skotty/SkottyAnimator.cpp @@ -54,6 +54,9 @@ void KeyframeInterval::lerp(float t, ShapeValue* v) const { lerp_point(fV0.fVertices[i].fVertex , fV1.fVertices[i].fVertex , t) })); } + + // hmm, any meaningful interpolation to consider here? + v->fClose = fV0.fClose; } } // namespace skotty diff --git a/experimental/skotty/SkottyProperties.cpp b/experimental/skotty/SkottyProperties.cpp index f65a106735..1a3a14593c 100644 --- a/experimental/skotty/SkottyProperties.cpp +++ b/experimental/skotty/SkottyProperties.cpp @@ -39,6 +39,11 @@ bool ParsePoints(const Json::Value& v, PointArray* pts) { } // namespace bool ScalarValue::Parse(const Json::Value& v, ScalarValue* scalar) { + // Some files appear to wrap keyframes in arrays for no reason. + if (v.isArray() && v.size() == 1) { + return Parse(v[0], scalar); + } + if (v.isNull() || !v.isConvertibleTo(Json::realValue)) return false; @@ -68,8 +73,8 @@ bool ShapeValue::Parse(const Json::Value& v, ShapeValue* shape) { outPts, verts; - // Some files appear to wrap these in arrays for no reason. - if (v.isArray()) { + // Some files appear to wrap keyframes in arrays for no reason. + if (v.isArray() && v.size() == 1) { return Parse(v[0], shape); } @@ -135,6 +140,7 @@ SkPath ShapeValue::as() const { if (fClose) { addCubic(fVertices.back(), fVertices.front(), &path); + path.close(); } return path; diff --git a/resources/skotty/skotty_sample_2.json b/resources/skotty/skotty_sample_2.json new file mode 100644 index 0000000000..c211ce7f01 --- /dev/null +++ b/resources/skotty/skotty_sample_2.json @@ -0,0 +1,123 @@ +{ + "v":"4.6.9", + "fr":60, + "ip":0, + "op":200, + "w":800, + "h":600, + "nm":"Loader 1 JSON", + "ddd":0, + + + "layers":[ + { + "ddd":0, + "ind":1, + "ty":4, + "nm":"Custom Path 1", + "ao": 0, + "ip": 0, + "op": 300, + "st": 0, + "sr": 1, + "bm": 0, + "ks": { + "o": { "a":0, "k":100 }, + "r": { "a":1, "k": [ + { "s": [ 0 ], "e": [ 360], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 0 }, + { "t": 200 } + ] }, + "p": { "a":0, "k":[ 300, 300, 0 ] }, + "a": { "a":0, "k":[ 100, 100, 0 ] }, + "s": { "a":1, "k":[ + { "s": [ 100, 100 ], "e": [ 200, 200 ], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 0 }, + { "s": [ 200, 200 ], "e": [ 100, 100 ], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 100 }, + { "t": 200 } + ] } + }, + + "shapes":[ + { + "ty":"gr", + "it":[ + { + "ty" : "sh", + "nm" : "Path 1", + "ks" : { + "a" : 1, + "k" : [ + { + "s": [ { + "i": [ [ 0, 50 ], [ -50, 0 ], [ 0, -50 ], [ 50, 0 ] ], + "o": [ [ 0, -50 ], [ 50, 0 ], [ 0, 50 ], [ -50, 0 ] ], + "v": [ [ 0, 100 ], [ 100, 0 ], [ 200, 100 ], [ 100, 200 ] ], + "c": true + } ], + "e": [ { + "i": [ [ 50, 50 ], [ -50, 0 ], [ -50, -50 ], [ 50, 50 ] ], + "o": [ [ 50, -50 ], [ 50, 0 ], [ -50, 50 ], [ -50, 50 ] ], + "v": [ [ 0, 100 ], [ 100, 0 ], [ 200, 100 ], [ 100, 200 ] ], + "c": true + } ], + "i": { "x":0.5, "y":0.5 }, + "o": { "x":0.5, "y":0.5 }, + "t": 0 + }, + { + "s": [ { + "i": [ [ 50, 50 ], [ -50, 0 ], [ -50, -50 ], [ 50, 50 ] ], + "o": [ [ 50, -50 ], [ 50, 0 ], [ -50, 50 ], [ -50, 50 ] ], + "v": [ [ 0, 100 ], [ 100, 0 ], [ 200, 100 ], [ 100, 200 ] ], + "c": true + } ], + "e": [ { + "i": [ [ 0, 50 ], [ -50, 0 ], [ 0, -50 ], [ 50, 0 ] ], + "o": [ [ 0, -50 ], [ 50, 0 ], [ 0, 50 ], [ -50, 0 ] ], + "v": [ [ 0, 100 ], [ 100, 0 ], [ 200, 100 ], [ 100, 200 ] ], + "c": true + } ], + "i": { "x":0.5, "y":0.5 }, + "o": { "x":0.5, "y":0.5 }, + "t": 100 + }, + { + "t": 200 + } + ] + } + }, + + { + "ty": "st", + "nm": "Stroke 1", + "lc": 1, + "lj": 1, + "ml": 4, + "w" : { "a": 1, "k": [ + { "s": [ 30 ], "e": [ 50 ], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 0 }, + { "s": [ 50 ], "e": [ 30 ], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 100 }, + { "t": 200 } + ] }, + "o" : { "a": 0, "k": 100 }, + "c" : { "a": 1, "k": [ + { "s": [ 0, 1, 0 ], "e": [ 1, 0, 0 ], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 0 }, + { "s": [ 1, 0, 0 ], "e": [ 0, 1, 0 ], "i": { "x":0.5, "y":0.5 }, "o": { "x":0.5, "y":0.5 }, "t": 100 }, + { "t": 200 } + ] } + }, + + { + "ty":"tr", + "p" : { "a":0, "k":[ 0, 0 ] }, + "a" : { "a":0, "k":[ 0, 0 ] }, + "s" : { "a":0, "k":[ 100, 100 ] }, + "r" : { "a":0, "k": 0 }, + "o" : { "a":0, "k":100 }, + "nm": "Transform" + } + ] + } + ] + } + ] +} -- cgit v1.2.3