[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / loader / dli-loader-impl.cpp
index 2285940..6cdb1c4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -667,6 +667,11 @@ void DliLoaderImpl::Impl::ParseShaders(const TreeNode* shaders, Dali::Scene3D::L
     auto&            node = (*i0).second;
     ShaderDefinition shaderDef;
     ReadStringVector(node.GetChild("defines"), shaderDef.mDefines);
+    auto sssIter = std::find_if(shaderDef.mDefines.begin(), shaderDef.mDefines.end(), [](std::string& item) { return (item == "SSS"); });
+    if(sssIter != shaderDef.mDefines.end())
+    {
+      shaderDef.mDefines.erase(sssIter);
+    }
 
     // Read shader hints. Possible values are:
     //                         Don't define for No hints.
@@ -837,10 +842,13 @@ void DliLoaderImpl::Impl::ParseMeshes(const TreeNode* meshes, Dali::Scene3D::Loa
         mOnError(FormatString("mesh %d: Failed to read %s.", resources.mMeshes.size(), "normals"));
       }
 
-      if(MaskMatch(attributes, MeshDefinition::TEX_COORDS) &&
-         !ReadAttribAccessor(node.GetChild("textures"), meshDef.mTexCoords))
+      if(MaskMatch(attributes, MeshDefinition::TEX_COORDS))
       {
-        mOnError(FormatString("mesh %d: Failed to read %s.", resources.mMeshes.size(), "textures"));
+        meshDef.mTexCoords.emplace_back(MeshDefinition::Accessor{});
+        if(!ReadAttribAccessor(node.GetChild("textures"), meshDef.mTexCoords[0]))
+        {
+          mOnError(FormatString("mesh %d: Failed to read %s.", resources.mMeshes.size(), "textures"));
+        }
       }
 
       if(MaskMatch(attributes, MeshDefinition::TANGENTS) &&
@@ -858,11 +866,16 @@ void DliLoaderImpl::Impl::ParseMeshes(const TreeNode* meshes, Dali::Scene3D::Loa
           mOnError(FormatString("mesh %d: Expected joints0 / weights0 attribute(s) missing.",
                                 resources.mMeshes.size()));
         }
-        else if(!ReadAttribAccessor(node.GetChild("joints0"), meshDef.mJoints0) ||
-                !ReadAttribAccessor(node.GetChild("weights0"), meshDef.mWeights0))
+        else
         {
-          mOnError(FormatString("mesh %d: Failed to read skinning information.",
-                                resources.mMeshes.size()));
+          meshDef.mJoints.emplace_back(MeshDefinition::Accessor{});
+          meshDef.mWeights.emplace_back(MeshDefinition::Accessor{});
+          if(!ReadAttribAccessor(node.GetChild("joints0"), meshDef.mJoints[0]) ||
+             !ReadAttribAccessor(node.GetChild("weights0"), meshDef.mWeights[0]))
+          {
+            mOnError(FormatString("mesh %d: Failed to read skinning information.",
+                                  resources.mMeshes.size()));
+          }
         }
       }
 
@@ -1027,14 +1040,17 @@ void DliLoaderImpl::Impl::ParseMaterials(const TreeNode* materials, DliInputPara
       materialDef.mFlags |= semantic;
     }
 
-    if(ReadString(node.GetChild("subsurfaceMap"), texturePath))
-    {
-      ToUnixFileSeparators(texturePath);
-
-      const auto semantic = MaterialDefinition::SUBSURFACE;
-      materialDef.mTextureStages.push_back({semantic, TextureDefinition{std::move(texturePath)}});
-      materialDef.mFlags |= semantic;
-    }
+    /// @TODO : Some dli shader don't implement this subsurfaceMp usage.
+    ///         To make visual test pass, Skip subsurfaceMap texture using
+    ///         until dli shaders are support it.
+    //    if(ReadString(node.GetChild("subsurfaceMap"), texturePath))
+    //    {
+    //      ToUnixFileSeparators(texturePath);
+    //
+    //      const auto semantic = MaterialDefinition::SUBSURFACE;
+    //      materialDef.mTextureStages.push_back({semantic, TextureDefinition{std::move(texturePath)}});
+    //      materialDef.mFlags |= semantic;
+    //    }
 
     if(ReadString(node.GetChild("occlusionMap"), texturePath))
     {
@@ -1438,52 +1454,59 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara
       iAnim != iAnimEnd;
       ++iAnim)
   {
-    const TreeNode&     tnAnim = (*iAnim).second;
+    const TreeNode&     tnAnim                 = (*iAnim).second;
+    uint32_t            animationPropertyIndex = 0;
     AnimationDefinition animDef;
-    ReadString(tnAnim.GetChild(NAME), animDef.mName);
+    std::string         animationName;
+    ReadString(tnAnim.GetChild(NAME), animationName);
+    animDef.SetName(animationName);
 
-    auto       iFind     = std::lower_bound(definitions.begin(), definitions.end(), animDef, [](const AnimationDefinition& ad0, const AnimationDefinition& ad1) { return ad0.mName < ad1.mName; });
-    const bool overwrite = iFind != definitions.end() && iFind->mName == animDef.mName;
+    auto       iFind     = std::lower_bound(definitions.begin(), definitions.end(), animDef, [](const AnimationDefinition& ad0, const AnimationDefinition& ad1) { return ad0.GetName() < ad1.GetName(); });
+    const bool overwrite = iFind != definitions.end() && iFind->GetName() == animDef.GetName();
     if(overwrite)
     {
-      mOnError(FormatString("Pre-existing animation with name '%s' is being overwritten.", animDef.mName.c_str()));
+      mOnError(FormatString("Pre-existing animation with name '%s' is being overwritten.", animDef.GetName().c_str()));
     }
 
     // Duration -- We need something that animated properties' delay / duration can
     // be expressed as a multiple of; 0 won't work. This is small enough (i.e. shorter
     // than our frame delay) to not be restrictive WRT replaying. If anything needs
     // to occur more frequently, then Animations are likely not your solution anyway.
-    animDef.mDuration = AnimationDefinition::MIN_DURATION_SECONDS;
-    if(!ReadFloat(tnAnim.GetChild("duration"), animDef.mDuration))
+    float animationDuration = 0.0f;
+    if(!ReadFloat(tnAnim.GetChild("duration"), animationDuration))
     {
-      mOnError(FormatString("Animation '%s' fails to define '%s', defaulting to %f.",
-                            animDef.mName.c_str(),
-                            "duration",
-                            animDef.mDuration));
+      mOnError(FormatString("Animation '%s' fails to define '%s'.",
+                            animDef.GetName().c_str(),
+                            "duration"));
     }
+    if(animationDuration < AnimationDefinition::MIN_DURATION_SECONDS)
+    {
+      animationDuration = AnimationDefinition::MIN_DURATION_SECONDS;
+    }
+    animDef.SetDuration(animationDuration);
 
     // Get loop count - # of playbacks. Default is once. 0 means repeat indefinitely.
-    animDef.mLoopCount = 1;
-    if(ReadInt(tnAnim.GetChild("loopCount"), animDef.mLoopCount) &&
-       animDef.mLoopCount < 0)
+    int32_t animationLoopCount = 1;
+    if(ReadInt(tnAnim.GetChild("loopCount"), animationLoopCount) && animationLoopCount < 0)
     {
-      animDef.mLoopCount = 0;
+      animationLoopCount = 0;
     }
+    animDef.SetLoopCount(animationLoopCount);
 
     std::string endAction;
     if(ReadString(tnAnim.GetChild("endAction"), endAction))
     {
       if("BAKE" == endAction)
       {
-        animDef.mEndAction = Animation::BAKE;
+        animDef.SetEndAction(Animation::BAKE);
       }
       else if("DISCARD" == endAction)
       {
-        animDef.mEndAction = Animation::DISCARD;
+        animDef.SetEndAction(Animation::DISCARD);
       }
       else if("BAKE_FINAL" == endAction)
       {
-        animDef.mEndAction = Animation::BAKE_FINAL;
+        animDef.SetEndAction(Animation::BAKE_FINAL);
       }
     }
 
@@ -1491,21 +1514,21 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara
     {
       if("BAKE" == endAction)
       {
-        animDef.mDisconnectAction = Animation::BAKE;
+        animDef.SetDisconnectAction(Animation::BAKE);
       }
       else if("DISCARD" == endAction)
       {
-        animDef.mDisconnectAction = Animation::DISCARD;
+        animDef.SetDisconnectAction(Animation::DISCARD);
       }
       else if("BAKE_FINAL" == endAction)
       {
-        animDef.mDisconnectAction = Animation::BAKE_FINAL;
+        animDef.SetDisconnectAction(Animation::BAKE_FINAL);
       }
     }
 
     if(const TreeNode* tnProperties = tnAnim.GetChild("properties"))
     {
-      animDef.mProperties.reserve(tnProperties->Size());
+      animDef.ReserveSize(tnProperties->Size());
       for(TreeNode::ConstIterator iProperty = tnProperties->CBegin(), iPropertyEnd = tnProperties->CEnd();
           iProperty != iPropertyEnd;
           ++iProperty)
@@ -1515,24 +1538,24 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara
         AnimatedProperty animProp;
         if(!ReadString(tnProperty.GetChild("node"), animProp.mNodeName))
         {
-          mOnError(FormatString("Animation '%s': Failed to read the 'node' tag.", animDef.mName.c_str()));
+          mOnError(FormatString("Animation '%s': Failed to read the 'node' tag.", animDef.GetName().c_str()));
           continue;
         }
 
         if(!ReadString(tnProperty.GetChild("property"), animProp.mPropertyName))
         {
-          mOnError(FormatString("Animation '%s': Failed to read the 'property' tag", animDef.mName.c_str()));
+          mOnError(FormatString("Animation '%s': Failed to read the 'property' tag", animDef.GetName().c_str()));
           continue;
         }
 
         // these are the defaults
         animProp.mTimePeriod.delaySeconds    = 0.f;
-        animProp.mTimePeriod.durationSeconds = animDef.mDuration;
+        animProp.mTimePeriod.durationSeconds = animDef.GetDuration();
         if(!ReadTimePeriod(tnProperty.GetChild("timePeriod"), animProp.mTimePeriod))
         {
           mOnError(FormatString("Animation '%s': timePeriod missing in Property #%d: defaulting to %f.",
-                                animDef.mName.c_str(),
-                                animDef.mProperties.size(),
+                                animDef.GetName().c_str(),
+                                animDef.GetPropertyCount(),
                                 animProp.mTimePeriod.durationSeconds));
         }
 
@@ -1562,7 +1585,7 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara
           ReadInt(tnKeyFramesBin->GetChild("byteOffset"), byteOffset);
           DALI_ASSERT_ALWAYS(byteOffset >= 0);
 
-          binAniFile.seekg(byteOffset, std::ios::beg);
+          binAniFile.seekg(static_cast<std::streamoff>(byteOffset), std::ios::beg);
 
           int numKeys = 0;
           ReadInt(tnKeyFramesBin->GetChild("numKeys"), numKeys);
@@ -1668,10 +1691,17 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara
           }
         }
 
-        animDef.mProperties.push_back(std::move(animProp));
+        animDef.SetProperty(animationPropertyIndex++, std::move(animProp));
       }
     }
 
+    if(auto proc = params.input->mAnimationPropertyProcessor) // optional processing
+    {
+      Property::Map map;
+      ParseProperties(tnAnim, map);
+      proc(animDef, std::move(map), mOnError);
+    }
+
     if(overwrite)
     {
       *iFind = std::move(animDef);
@@ -1680,13 +1710,6 @@ void DliLoaderImpl::Impl::ParseAnimations(const TreeNode* tnAnimations, LoadPara
     {
       iFind = definitions.insert(iFind, std::move(animDef));
     }
-
-    if(auto proc = params.input->mAnimationPropertyProcessor) // optional processing
-    {
-      Property::Map map;
-      ParseProperties(tnAnim, map);
-      proc(animDef, std::move(map), mOnError);
-    }
   }
 }