[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / scene-definition.cpp
index 370e926..7d28053 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.
@@ -48,50 +48,39 @@ const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)>& GetCons
 {
   static const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)> sConstraintFactory = {
     {Property::Type::BOOLEAN,
-     [](Actor& a, Property::Index i)
-     {
-       return Constraint::New<bool>(a, i, [](bool& current, const PropertyInputContainer& inputs)
-                                    { current = inputs[0]->GetBoolean(); });
+     [](Actor& a, Property::Index i) {
+       return Constraint::New<bool>(a, i, [](bool& current, const PropertyInputContainer& inputs) { current = inputs[0]->GetBoolean(); });
      }},
     {Property::Type::INTEGER,
-     [](Actor& a, Property::Index i)
-     {
-       return Constraint::New<int>(a, i, [](int& current, const PropertyInputContainer& inputs)
-                                   { current = inputs[0]->GetInteger(); });
+     [](Actor& a, Property::Index i) {
+       return Constraint::New<int>(a, i, [](int& current, const PropertyInputContainer& inputs) { current = inputs[0]->GetInteger(); });
      }},
     {Property::Type::FLOAT,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<float>(a, i, EqualToConstraint());
      }},
     {Property::Type::VECTOR2,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<Vector2>(a, i, EqualToConstraint());
      }},
     {Property::Type::VECTOR3,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<Vector3>(a, i, EqualToConstraint());
      }},
     {Property::Type::VECTOR4,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<Vector4>(a, i, EqualToConstraint());
      }},
     {Property::Type::MATRIX,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<Matrix>(a, i, EqualToConstraint());
      }},
     {Property::Type::MATRIX3,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<Matrix3>(a, i, EqualToConstraint());
      }},
     {Property::Type::ROTATION,
-     [](Actor& a, Property::Index i)
-     {
+     [](Actor& a, Property::Index i) {
        return Constraint::New<Quaternion>(a, i, EqualToConstraint());
      }},
   };
@@ -132,7 +121,7 @@ void EnsureJointDebugShaderCreated()
 {
   if(0 == sNumScenes)
   {
-    sJointDebugShader = Shader::New(SHADER_SCENE3D_JOINT_DEBUG_VERT, SHADER_SCENE3D_JOINT_DEBUG_FRAG);
+    sJointDebugShader = Shader::New(SHADER_SCENE3D_JOINT_DEBUG_VERT, SHADER_SCENE3D_JOINT_DEBUG_FRAG, Shader::Hint::NONE, "SCENE3D_JOINT_DEBUG");
   }
   ++sNumScenes;
 }
@@ -245,8 +234,7 @@ void SortAndDeduplicateRequests(std::vector<RequestType>& requests)
     ++iter;
   } while(true);
 
-  requests.erase(std::remove_if(requests.begin(), requests.end(), [](const RequestType& sscr)
-                                { return !sscr.mShader; }),
+  requests.erase(std::remove_if(requests.begin(), requests.end(), [](const RequestType& sscr) { return !sscr.mShader; }),
                  requests.end());
 }
 
@@ -383,7 +371,7 @@ void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choice
 
     void Register(ResourceType::Value type, Index id)
     {
-      if((!(*refCounts)[type].Empty()) && (id >= 0) && ((*refCounts)[type].Size() > id))
+      if((!(*refCounts)[type].Empty()) && ((*refCounts)[type].Size() > id))
       {
         ++(*refCounts)[type][id];
       }
@@ -494,8 +482,7 @@ bool SceneDefinition::ReparentNode(const std::string& name, const std::string& n
   auto& node  = *nodePtr;
   auto  iNode = std::distance(mNodes.data(), nodePtr);
 
-  DEBUG_ONLY(auto dumpNode = [](NodeDefinition const& n)
-             {
+  DEBUG_ONLY(auto dumpNode = [](NodeDefinition const& n) {
     std::ostringstream stream;
     stream << n.mName << " (" << n.mParentIdx << "):";
     for(auto i : n.mChildren)
@@ -548,16 +535,15 @@ bool SceneDefinition::RemoveNode(const std::string& name)
   auto&                                                 thisNodes = mNodes;
   unsigned int                                          numReset  = 0;
   std::function<void(std::unique_ptr<NodeDefinition>&)> resetFn =
-    [&thisNodes, &resetFn, &numReset](std::unique_ptr<NodeDefinition>& nd)
-  {
-    LOGD(("resetting %d", &nd - thisNodes.data()));
-    for(auto i : nd->mChildren)
-    {
-      resetFn(thisNodes[i]);
-    }
-    nd.reset();
-    ++numReset;
-  };
+    [&thisNodes, &resetFn, &numReset](std::unique_ptr<NodeDefinition>& nd) {
+      LOGD(("resetting %d", &nd - thisNodes.data()));
+      for(auto i : nd->mChildren)
+      {
+        resetFn(thisNodes[i]);
+      }
+      nd.reset();
+      ++numReset;
+    };
 
   resetFn(*node);
 
@@ -580,8 +566,7 @@ bool SceneDefinition::RemoveNode(const std::string& name)
   {
     INDEX_FOR_REMOVAL = INVALID_INDEX
   };
-  auto offsetter = [&offsets](Index& i)
-  {
+  auto offsetter = [&offsets](Index& i) {
     auto iFind = std::lower_bound(offsets.begin(), offsets.end(), i);
     if(iFind != offsets.end() && *iFind == i)
     {
@@ -621,8 +606,7 @@ bool SceneDefinition::RemoveNode(const std::string& name)
 void SceneDefinition::GetNodeModelStack(Index index, MatrixStack& model) const
 {
   auto&                    thisNodes  = mNodes;
-  std::function<void(int)> buildStack = [&model, &thisNodes, &buildStack](int i)
-  {
+  std::function<void(int)> buildStack = [&model, &thisNodes, &buildStack](int i) {
     auto node = thisNodes[i].get();
     if(node->mParentIdx != INVALID_INDEX)
     {
@@ -637,8 +621,7 @@ NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index* outInd
 {
   auto iBegin = mNodes.begin();
   auto iEnd   = mNodes.end();
-  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd)
-                            { return nd->mName == name; });
+  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; });
 
   auto result = iFind != iEnd ? iFind->get() : nullptr;
   if(result && outIndex)
@@ -652,8 +635,7 @@ const NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index*
 {
   auto iBegin = mNodes.begin();
   auto iEnd   = mNodes.end();
-  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd)
-                            { return nd->mName == name; });
+  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; });
 
   auto result = iFind != iEnd ? iFind->get() : nullptr;
   if(result && outIndex)
@@ -667,8 +649,7 @@ Index SceneDefinition::FindNodeIndex(const NodeDefinition& node) const
 {
   auto iBegin = mNodes.begin();
   auto iEnd   = mNodes.end();
-  auto iFind  = std::find_if(iBegin, iEnd, [&node](const std::unique_ptr<NodeDefinition>& n)
-                            { return n.get() == &node; });
+  auto iFind  = std::find_if(iBegin, iEnd, [&node](const std::unique_ptr<NodeDefinition>& n) { return n.get() == &node; });
   return iFind != iEnd ? std::distance(iBegin, iFind) : INVALID_INDEX;
 }
 
@@ -959,8 +940,7 @@ bool SceneDefinition::FindNode(const std::string& name, std::unique_ptr<NodeDefi
   // We're searching from the end assuming a higher probability of operations targeting
   // recently added nodes. (conf.: root, which is immovable, cannot be removed, and was
   // the first to be added, is index 0.)
-  auto iFind = std::find_if(mNodes.rbegin(), mNodes.rend(), [&name](const std::unique_ptr<NodeDefinition>& nd)
-                            { return nd->mName == name; })
+  auto iFind = std::find_if(mNodes.rbegin(), mNodes.rend(), [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; })
                  .base();
 
   const bool success = iFind != mNodes.begin();