Replace std::string global variables with C-style string.
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / scene-definition.cpp
index 6e26c0f..f41422e 100644 (file)
@@ -45,7 +45,7 @@ namespace Loader
 {
 namespace
 {
 {
 namespace
 {
-const std::string JOINT_MATRIX{"jointMatrix"};
+const char* JOINT_MATRIX{"jointMatrix"};
 
 const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)> sConstraintFactory = {
   {Property::Type::BOOLEAN,
 
 const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)> sConstraintFactory = {
   {Property::Type::BOOLEAN,
@@ -164,7 +164,7 @@ void AddJointDebugVisual(Actor aJoint)
 }
 #endif //DEBUG_JOINTS
 
 }
 #endif //DEBUG_JOINTS
 
-class ActorCreatorVisitor : public NodeDefinition::IConstVisitor
+class ActorCreatorVisitor : public NodeDefinition::IVisitor
 {
 public:
   ActorCreatorVisitor(NodeDefinition::CreateParams& params)
 {
 public:
   ActorCreatorVisitor(NodeDefinition::CreateParams& params)
@@ -172,7 +172,7 @@ public:
   {
   }
 
   {
   }
 
-  void Start(const NodeDefinition& n)
+  void Start(NodeDefinition& n)
   {
     mCreationContext.mXforms.modelStack.Push(n.GetLocalSpace());
 
   {
     mCreationContext.mXforms.modelStack.Push(n.GetLocalSpace());
 
@@ -188,7 +188,7 @@ public:
     mActorStack.push_back(a);
   }
 
     mActorStack.push_back(a);
   }
 
-  void Finish(const NodeDefinition& n)
+  void Finish(NodeDefinition& n)
   {
     mActorStack.pop_back();
     mCreationContext.mXforms.modelStack.Pop();
   {
     mActorStack.pop_back();
     mCreationContext.mXforms.modelStack.Pop();
@@ -305,7 +305,7 @@ void ConfigureBoneMatrix(const Matrix& ibm, Actor joint, Shader& shader, Index&
 {
   // Register bone transform on shader.
   char propertyNameBuffer[32];
 {
   // Register bone transform on shader.
   char propertyNameBuffer[32];
-  snprintf(propertyNameBuffer, sizeof(propertyNameBuffer), "%s[%d]", Skinning::BONE_UNIFORM_NAME.c_str(), boneIdx);
+  snprintf(propertyNameBuffer, sizeof(propertyNameBuffer), "%s[%d]", Skinning::BONE_UNIFORM_NAME, boneIdx);
   DALI_ASSERT_DEBUG(shader.GetPropertyIndex(propertyNameBuffer) == Property::INVALID_INDEX);
   auto propBoneXform = shader.RegisterProperty(propertyNameBuffer, Matrix{false});
 
   DALI_ASSERT_DEBUG(shader.GetPropertyIndex(propertyNameBuffer) == Property::INVALID_INDEX);
   auto propBoneXform = shader.RegisterProperty(propertyNameBuffer, Matrix{false});
 
@@ -422,7 +422,11 @@ const NodeDefinition* SceneDefinition::GetNode(Index iNode) const
 
 NodeDefinition* SceneDefinition::GetNode(Index iNode)
 {
 
 NodeDefinition* SceneDefinition::GetNode(Index iNode)
 {
-  return mNodes[iNode].get();
+  if(iNode != Scene3D::Loader::INVALID_INDEX && iNode < mNodes.size())
+  {
+    return mNodes[iNode].get();
+  }
+  return nullptr;
 }
 
 void SceneDefinition::Visit(Index iNode, const Customization::Choices& choices, NodeDefinition::IVisitor& v)
 }
 
 void SceneDefinition::Visit(Index iNode, const Customization::Choices& choices, NodeDefinition::IVisitor& v)
@@ -453,9 +457,9 @@ void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choice
 
     void Start(const NodeDefinition& n)
     {
 
     void Start(const NodeDefinition& n)
     {
-      if(n.mRenderable)
+      for(auto& renderable : n.mRenderables)
       {
       {
-        n.mRenderable->RegisterResources(counter);
+        renderable->RegisterResources(counter);
       }
     }
 
       }
     }
 
@@ -469,7 +473,7 @@ void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choice
   Visit(iNode, choices, refCounterVisitor);
 }
 
   Visit(iNode, choices, refCounterVisitor);
 }
 
-Actor SceneDefinition::CreateNodes(Index iNode, const Customization::Choices& choices, NodeDefinition::CreateParams& params) const
+Actor SceneDefinition::CreateNodes(Index iNode, const Customization::Choices& choices, NodeDefinition::CreateParams& params)
 {
   ActorCreatorVisitor actorCreatorVisitor(params);
 
 {
   ActorCreatorVisitor actorCreatorVisitor(params);
 
@@ -526,11 +530,6 @@ void SceneDefinition::GetCustomizationOptions(const Customization::Choices& choi
 
 NodeDefinition* SceneDefinition::AddNode(std::unique_ptr<NodeDefinition>&& nodeDef)
 {
 
 NodeDefinition* SceneDefinition::AddNode(std::unique_ptr<NodeDefinition>&& nodeDef)
 {
-  if(FindNode(nodeDef->mName))
-  {
-    return nullptr;
-  }
-
   // add next index (to which we're about to push) as a child to the designated parent, if any.
   if(nodeDef->mParentIdx != INVALID_INDEX)
   {
   // add next index (to which we're about to push) as a child to the designated parent, if any.
   if(nodeDef->mParentIdx != INVALID_INDEX)
   {
@@ -962,7 +961,7 @@ void SceneDefinition::ConfigureSkeletonJoints(uint32_t iRoot, const SkeletonDefi
   }
 
   // 3, For each root, register joint matrices and constraints
   }
 
   // 3, For each root, register joint matrices and constraints
-  for(auto r : rootsJoints)
+  for(const auto& r : rootsJoints)
   {
     auto node      = GetNode(r.first);
     auto rootJoint = root.FindChildByName(node->mName);
   {
     auto node      = GetNode(r.first);
     auto rootJoint = root.FindChildByName(node->mName);
@@ -977,7 +976,7 @@ void SceneDefinition::ConfigureSkeletonJoints(uint32_t iRoot, const SkeletonDefi
     constraint.AddSource(Source(rootJoint, Actor::Property::POSITION));
     constraint.Apply();
 
     constraint.AddSource(Source(rootJoint, Actor::Property::POSITION));
     constraint.Apply();
 
-    for(auto j : r.second)
+    for(const auto j : r.second)
     {
       node       = GetNode(j);
       auto joint = rootJoint.FindChildByName(node->mName);
     {
       node       = GetNode(j);
       auto joint = rootJoint.FindChildByName(node->mName);
@@ -991,10 +990,10 @@ void SceneDefinition::EnsureUniqueSkinningShaderInstances(ResourceBundle& resour
   std::map<Index, std::map<Index, std::vector<Index*>>> skinningShaderUsers;
   for(auto& node : mNodes)
   {
   std::map<Index, std::map<Index, std::vector<Index*>>> skinningShaderUsers;
   for(auto& node : mNodes)
   {
-    if(node->mRenderable)
+    for(auto& renderable : node->mRenderables)
     {
       ResourceReflector reflector;
     {
       ResourceReflector reflector;
-      node->mRenderable->ReflectResources(reflector);
+      renderable->ReflectResources(reflector);
 
       if(reflector.iMesh)
       {
 
       if(reflector.iMesh)
       {
@@ -1045,21 +1044,21 @@ void SceneDefinition::ConfigureSkinningShaders(const ResourceBundle&
 
   SortAndDeduplicateSkinningRequests(requests);
 
 
   SortAndDeduplicateSkinningRequests(requests);
 
-  for(auto& i : requests)
+  for(auto& request : requests)
   {
   {
-    auto& skeleton = resources.mSkeletons[i.mSkeletonIdx];
+    auto& skeleton = resources.mSkeletons[request.mSkeletonIdx];
     if(skeleton.mJoints.empty())
     {
     if(skeleton.mJoints.empty())
     {
-      LOGD(("Skeleton %d has no joints.", i.mSkeletonIdx));
+      LOGD(("Skeleton %d has no joints.", request.mSkeletonIdx));
       continue;
     }
 
     Index boneIdx = 0;
       continue;
     }
 
     Index boneIdx = 0;
-    for(auto& j : skeleton.mJoints)
+    for(auto& joint : skeleton.mJoints)
     {
     {
-      auto  node  = GetNode(j.mNodeIdx);
+      auto  node  = GetNode(joint.mNodeIdx);
       Actor actor = rootActor.FindChildByName(node->mName);
       Actor actor = rootActor.FindChildByName(node->mName);
-      ConfigureBoneMatrix(j.mInverseBindMatrix, actor, i.mShader, boneIdx);
+      ConfigureBoneMatrix(joint.mInverseBindMatrix, actor, request.mShader, boneIdx);
     }
   }
 }
     }
   }
 }
@@ -1129,10 +1128,10 @@ void SceneDefinition::EnsureUniqueBlendShapeShaderInstances(ResourceBundle& reso
   std::map<Index, std::map<std::string, std::vector<Index*>>> blendShapeShaderUsers;
   for(auto& node : mNodes)
   {
   std::map<Index, std::map<std::string, std::vector<Index*>>> blendShapeShaderUsers;
   for(auto& node : mNodes)
   {
-    if(node->mRenderable)
+    for(auto& renderable : node->mRenderables)
     {
       ResourceReflector reflector;
     {
       ResourceReflector reflector;
-      node->mRenderable->ReflectResources(reflector);
+      renderable->ReflectResources(reflector);
 
       if(reflector.iMesh)
       {
 
       if(reflector.iMesh)
       {