[Tizen] Use AnimatedProperty instead of name for getActor. 43/285543/1
authorseungho baek <sbsh.baek@samsung.com>
Wed, 14 Dec 2022 09:11:00 +0000 (18:11 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Wed, 14 Dec 2022 09:13:02 +0000 (18:13 +0900)
 - This allows AnimationDefinition can find target Actor by using node id

Change-Id: Ie827fb71c574b56f71cdc9ffeeb6ae11046e96e3
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
dali-scene3d/internal/controls/model/model-impl.cpp
dali-scene3d/public-api/loader/animated-property.cpp
dali-scene3d/public-api/loader/animated-property.h
dali-scene3d/public-api/loader/gltf2-loader.cpp
dali-scene3d/public-api/loader/node-definition.cpp
dali-scene3d/public-api/loader/node-definition.h
dali-scene3d/public-api/loader/scene-definition.cpp
dali-scene3d/public-api/loader/scene-definition.h

index eccd618..be8ce74 100644 (file)
@@ -521,8 +521,8 @@ void Model::LoadModel()
 
   if(!animations.empty())
   {
-    auto getActor = [&](const std::string& name) {
-      return mModelRoot.FindChildByName(name);
+    auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property) {
+      return mModelRoot.FindChildById(scene.GetNode(property.mNodeIndex)->mNodeId);
     };
 
     mAnimations.clear();
index 5f15815..83ae2df 100644 (file)
@@ -24,7 +24,7 @@ namespace Loader
 {
 void AnimatedProperty::Animate(Animation& anim, GetActor getActor)
 {
-  if(Actor actor = getActor(mNodeName))
+  if(Actor actor = getActor(*this))
   {
     Property prop = GetProperty(actor);
     if(mKeyFrames)
index 6433d5c..522a542 100644 (file)
@@ -19,6 +19,7 @@
 
 // INTERNAL INCLUDES
 #include "dali-scene3d/public-api/api.h"
+#include "dali-scene3d/public-api/loader/index.h"
 
 // EXTERNAL INCLUDES
 #include <functional>
@@ -44,10 +45,10 @@ struct DALI_SCENE3D_API AnimatedProperty
 {
 public: // METHODS
   /**
-   * @brief Function to obtain an Actor based on its name. Its processing will
+   * @brief Function to obtain an Actor based on its property. Its processing will
    *  ignore empty handles returned by it.
    */
-  using GetActor = std::function<Actor(const std::string&)>;
+  using GetActor = std::function<Actor(const AnimatedProperty&)>;
 
   /**
    * @return The Property object (of the given @a actor) whose value is being animated.
@@ -82,6 +83,7 @@ public: // DATA
     bool            mIsRelative;
   };
 
+  Index       mNodeIndex = INVALID_INDEX;
   std::string mNodeName;
   std::string mPropertyName;
 
@@ -96,4 +98,4 @@ public: // DATA
 } // namespace Scene3D
 } // namespace Dali
 
-#endif //DALI_SCENE3D_LOADER_ANIMATED_PROPERTY_H
+#endif // DALI_SCENE3D_LOADER_ANIMATED_PROPERTY_H
index d6944e1..07860e3 100644 (file)
@@ -958,7 +958,7 @@ float LoadKeyFrames(const std::string& path, const gt::Animation::Channel& chann
   return duration;
 }
 
-float LoadBlendShapeKeyFrames(const std::string& path, const gt::Animation::Channel& channel, const std::string& nodeName, uint32_t& propertyIndex, std::vector<Dali::Scene3D::Loader::AnimatedProperty>& properties)
+float LoadBlendShapeKeyFrames(const std::string& path, const gt::Animation::Channel& channel, Index nodeIndex, uint32_t& propertyIndex, std::vector<Dali::Scene3D::Loader::AnimatedProperty>& properties)
 {
   const gltf2::Accessor& input  = *channel.mSampler->mInput;
   const gltf2::Accessor& output = *channel.mSampler->mOutput;
@@ -976,7 +976,7 @@ float LoadBlendShapeKeyFrames(const std::string& path, const gt::Animation::Chan
   {
     AnimatedProperty& animatedProperty = properties[propertyIndex++];
 
-    animatedProperty.mNodeName = nodeName;
+    animatedProperty.mNodeIndex = nodeIndex;
     snprintf(pWeightName, remainingSize, "%d]", weightIndex);
     animatedProperty.mPropertyName = std::string(weightNameBuffer);
 
@@ -1008,26 +1008,23 @@ void ConvertAnimations(const gt::Document& doc, ConversionContext& cctx)
     }
 
     uint32_t numberOfProperties = 0u;
-
     for(const auto& channel : animation.mChannels)
     {
-      numberOfProperties += channel.mSampler->mOutput->mCount;
+      if(channel.mTarget.mPath == gt::Animation::Channel::Target::WEIGHTS)
+      {
+        numberOfProperties += channel.mSampler->mOutput->mCount / channel.mSampler->mInput->mCount;
+      }
+      else
+      {
+        numberOfProperties++;
+      }
     }
     animationDef.mProperties.resize(numberOfProperties);
 
     Index propertyIndex = 0u;
     for(const auto& channel : animation.mChannels)
     {
-      std::string nodeName;
-      if(!channel.mTarget.mNode->mName.empty())
-      {
-        nodeName = channel.mTarget.mNode->mName;
-      }
-      else
-      {
-        Index index = cctx.mNodeIndices.GetRuntimeId(channel.mTarget.mNode.GetIndex());
-        nodeName    = cctx.mOutput.mScene.GetNode(index)->mName;
-      }
+      Index nodeIndex    = cctx.mNodeIndices.GetRuntimeId(channel.mTarget.mNode.GetIndex());
 
       float duration = 0.f;
 
@@ -1037,7 +1034,7 @@ void ConvertAnimations(const gt::Document& doc, ConversionContext& cctx)
         {
           AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex];
 
-          animatedProperty.mNodeName     = nodeName;
+          animatedProperty.mNodeIndex    = nodeIndex;
           animatedProperty.mPropertyName = POSITION_PROPERTY;
 
           animatedProperty.mKeyFrames = KeyFrames::New();
@@ -1050,7 +1047,7 @@ void ConvertAnimations(const gt::Document& doc, ConversionContext& cctx)
         {
           AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex];
 
-          animatedProperty.mNodeName     = nodeName;
+          animatedProperty.mNodeIndex    = nodeIndex;
           animatedProperty.mPropertyName = ORIENTATION_PROPERTY;
 
           animatedProperty.mKeyFrames = KeyFrames::New();
@@ -1063,7 +1060,7 @@ void ConvertAnimations(const gt::Document& doc, ConversionContext& cctx)
         {
           AnimatedProperty& animatedProperty = animationDef.mProperties[propertyIndex];
 
-          animatedProperty.mNodeName     = nodeName;
+          animatedProperty.mNodeIndex    = nodeIndex;
           animatedProperty.mPropertyName = SCALE_PROPERTY;
 
           animatedProperty.mKeyFrames = KeyFrames::New();
@@ -1074,7 +1071,7 @@ void ConvertAnimations(const gt::Document& doc, ConversionContext& cctx)
         }
         case gt::Animation::Channel::Target::WEIGHTS:
         {
-          duration = LoadBlendShapeKeyFrames(cctx.mPath, channel, nodeName, propertyIndex, animationDef.mProperties);
+          duration = LoadBlendShapeKeyFrames(cctx.mPath, channel, nodeIndex, propertyIndex, animationDef.mProperties);
 
           break;
         }
index 022ccd2..add512e 100644 (file)
@@ -63,9 +63,11 @@ void NodeDefinition::Renderable::OnCreate(const NodeDefinition& node, CreatePara
 
 const std::string NodeDefinition::ORIGINAL_MATRIX_PROPERTY_NAME = "originalMatrix";
 
-Actor NodeDefinition::CreateActor(CreateParams& params) const
+Actor NodeDefinition::CreateActor(CreateParams& params)
 {
   Actor actor = Actor::New();
+  mNodeId     = actor.GetProperty<int32_t>(Dali::Actor::Property::ID);
+
   SetActorCentered(actor);
 
   actor.SetProperty(Actor::Property::NAME, mName);
index 8cba317..658359d 100644 (file)
@@ -218,7 +218,7 @@ public: // METHODS
    * @brief Creates a DALi Actor from this definition only.
    * @note Not recursive.
    */
-  Actor CreateActor(CreateParams& params) const;
+  Actor CreateActor(CreateParams& params);
 
   /**
    * @brief Gets local space matrix of this node
@@ -253,6 +253,7 @@ public: // DATA
   static const std::string ORIGINAL_MATRIX_PROPERTY_NAME;
 
   std::string mName;
+  uint32_t    mNodeId = INVALID_INDEX;
 
   Vector3    mPosition    = Vector3::ZERO;
   Quaternion mOrientation = Quaternion::IDENTITY;
index e5102f5..a45dbd4 100644 (file)
@@ -164,7 +164,7 @@ void AddJointDebugVisual(Actor aJoint)
 }
 #endif //DEBUG_JOINTS
 
-class ActorCreatorVisitor : public NodeDefinition::IConstVisitor
+class ActorCreatorVisitor : public NodeDefinition::IVisitor
 {
 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());
 
@@ -188,7 +188,7 @@ public:
     mActorStack.push_back(a);
   }
 
-  void Finish(const NodeDefinition& n)
+  void Finish(NodeDefinition& n)
   {
     mActorStack.pop_back();
     mCreationContext.mXforms.modelStack.Pop();
@@ -469,7 +469,7 @@ void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choice
   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);
 
index 0f40f5b..ecb5cff 100644 (file)
@@ -113,7 +113,7 @@ public: // METHODS
    *  from node definitions.
    * @return Handle to the root actor.
    */
-  Actor CreateNodes(Index iNode, const Customization::Choices& choices, NodeDefinition::CreateParams& params) const;
+  Actor CreateNodes(Index iNode, const Customization::Choices& choices, NodeDefinition::CreateParams& params);
 
   /*
    * @brief Creates / update a registry of mappings from customization tags to