summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2018-04-12 17:10:57 +0900
committersubhransu mohanty <sub.mohanty@samsung.com>2018-04-12 17:10:57 +0900
commitc88ab3de682f7480912f7bd956bb94915ddea34b (patch)
treec6dbd6ed736cc9fdc28f87a2b5d06d14ee368b34
parentf62e2ccccd0716312fcb8489c76bcd84fd47f6d4 (diff)
downloadefl-devs/subhransu/ssg.tar.gz
ssg:Added asset class and parsing of "asset" property for lottiedevs/subhransu/ssg
-rw-r--r--ssg/include/lottiemodel.h13
-rw-r--r--ssg/src/lottie/lottieparser.cpp53
2 files changed, 66 insertions, 0 deletions
diff --git a/ssg/include/lottiemodel.h b/ssg/include/lottiemodel.h
index a013844d8b..18be7e6b78 100644
--- a/ssg/include/lottiemodel.h
+++ b/ssg/include/lottiemodel.h
@@ -113,6 +113,7 @@ class LottieObject
public:
enum class Type {
Composition = 1,
+ Asset,
Layer,
ShapeGroup,
Transform,
@@ -159,6 +160,16 @@ public:
std::shared_ptr<LottieObject> mTransform;
};
+class LottieLayer;
+class LottieAsset : public LottieObject
+{
+public:
+ LottieAsset():LottieObject(LottieObject::Type::Asset){}
+ int mAssetType; //lottie aset type (precomp/char/image)
+ std::string mRefId; // ref id
+ std::vector<std::shared_ptr<LottieObject>> mLayers;
+};
+
class LottieTransform;
class LottieComposition : public LottieGroupObject
{
@@ -183,6 +194,7 @@ public:
LottieBlendMode mBlendMode;
std::unordered_map<std::string,
std::shared_ptr<SGInterpolator>> mInterpolatorCache;
+ std::vector<std::shared_ptr<LottieAsset>> mAssets;
};
class LottieLayer : public LottieGroupObject
@@ -202,6 +214,7 @@ public:
long mStartTime;
LottieBlendMode mBlendMode;
float mTimeStreatch;
+ std::string mPreCompRefId;
LottieAnimatable<float> mTimeRemap; /* "tm" */
std::shared_ptr<LottieObject> mTransform;
};
diff --git a/ssg/src/lottie/lottieparser.cpp b/ssg/src/lottie/lottieparser.cpp
index add86e0f94..ff9f27ab30 100644
--- a/ssg/src/lottie/lottieparser.cpp
+++ b/ssg/src/lottie/lottieparser.cpp
@@ -136,6 +136,8 @@ public:
LottieTrimObject::TrimType getTrimType();
std::shared_ptr<LottieComposition> parseComposition();
+ void parseAssets(LottieComposition *comp);
+ std::shared_ptr<LottieAsset> parseAsset();
void parseLayers(LottieComposition *comp);
std::shared_ptr<LottieObject> parseLayer();
void parseShapesAttr(LottieLayer *layer);
@@ -449,6 +451,8 @@ LottieParser::parseComposition()
} else if (0 == strcmp(key, "fr")) {
RAPIDJSON_ASSERT(PeekType() == kNumberType);
comp->mFrameRate = GetDouble();
+ } else if (0 == strcmp(key, "assets")) {
+ parseAssets(comp);
} else if (0 == strcmp(key, "layers")) {
parseLayers(comp);
} else {
@@ -468,6 +472,51 @@ LottieParser::parseComposition()
return sharedComposition;
}
+void LottieParser::parseAssets(LottieComposition *composition)
+{
+ RAPIDJSON_ASSERT(PeekType() == kArrayType);
+ EnterArray();
+ while (NextArrayValue()) {
+ std::shared_ptr<LottieAsset> asset = parseAsset();
+ composition->mAssets.push_back(asset);
+ }
+}
+
+/*
+ * https://github.com/airbnb/lottie-web/blob/master/docs/json/layers/shape.json
+ *
+ */
+std::shared_ptr<LottieAsset>
+LottieParser::parseAsset()
+{
+ RAPIDJSON_ASSERT(PeekType() == kObjectType);
+ std::shared_ptr<LottieAsset> sharedAsset = std::make_shared<LottieAsset>();
+ LottieAsset *asset = sharedAsset.get();
+ EnterObject();
+ while (const char* key = NextObjectKey()) {
+ if (0 == strcmp(key, "ty")) { /* Type of layer: Shape. Value 4.*/
+ RAPIDJSON_ASSERT(PeekType() == kNumberType);
+ asset->mAssetType = GetInt();
+ } else if (0 == strcmp(key, "id")) { /* reference id*/
+ RAPIDJSON_ASSERT(PeekType() == kStringType);
+ asset->mRefId = std::string(GetString());
+ }else if (0 == strcmp(key, "layers")) {
+ RAPIDJSON_ASSERT(PeekType() == kArrayType);
+ EnterArray();
+ while (NextArrayValue()) {
+ std::shared_ptr<LottieObject> layer = parseLayer();
+ asset->mLayers.push_back(layer);
+ }
+ } else {
+ #ifdef DEBUG_PARSER
+ sgWarning<<"Asset Attribute Skipped : "<<key;
+ #endif
+ Skip(key);
+ }
+ }
+ return sharedAsset;
+}
+
void LottieParser::parseLayers(LottieComposition *composition)
{
RAPIDJSON_ASSERT(PeekType() == kArrayType);
@@ -499,6 +548,10 @@ LottieParser::parseLayer()
} else if (0 == strcmp(key, "parent")) { /*Layer Parent. Uses "ind" of parent.*/
RAPIDJSON_ASSERT(PeekType() == kNumberType);
layer->mParentId = GetInt();
+ } else if (0 == strcmp(key, "refId")) { /*preComp Layer reference id*/
+ RAPIDJSON_ASSERT(PeekType() == kStringType);
+ layer->mPreCompRefId = std::string(GetString());
+ //TODO update the children with the layer list from asset
}else if (0 == strcmp(key, "sr")) { // "Layer Time Stretching"
RAPIDJSON_ASSERT(PeekType() == kNumberType);
layer->mTimeStreatch = GetDouble();