From c88ab3de682f7480912f7bd956bb94915ddea34b Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Thu, 12 Apr 2018 17:10:57 +0900 Subject: ssg:Added asset class and parsing of "asset" property for lottie --- ssg/include/lottiemodel.h | 13 ++++++++++ ssg/src/lottie/lottieparser.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) 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 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> mLayers; +}; + class LottieTransform; class LottieComposition : public LottieGroupObject { @@ -183,6 +194,7 @@ public: LottieBlendMode mBlendMode; std::unordered_map> mInterpolatorCache; + std::vector> mAssets; }; class LottieLayer : public LottieGroupObject @@ -202,6 +214,7 @@ public: long mStartTime; LottieBlendMode mBlendMode; float mTimeStreatch; + std::string mPreCompRefId; LottieAnimatable mTimeRemap; /* "tm" */ std::shared_ptr 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 parseComposition(); + void parseAssets(LottieComposition *comp); + std::shared_ptr parseAsset(); void parseLayers(LottieComposition *comp); std::shared_ptr 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 asset = parseAsset(); + composition->mAssets.push_back(asset); + } +} + +/* + * https://github.com/airbnb/lottie-web/blob/master/docs/json/layers/shape.json + * + */ +std::shared_ptr +LottieParser::parseAsset() +{ + RAPIDJSON_ASSERT(PeekType() == kObjectType); + std::shared_ptr sharedAsset = std::make_shared(); + 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 layer = parseLayer(); + asset->mLayers.push_back(layer); + } + } else { + #ifdef DEBUG_PARSER + sgWarning<<"Asset Attribute Skipped : "<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(); -- cgit v1.2.1