[Tizen] Change to use ModelLoader instead of Gltf2Loader and DliLoader 25/289425/1 accepted/tizen/7.0/unified/20230327.042633 accepted/tizen/7.0/unified/20230403.235604 accepted/tizen/7.0/unified/20230404.033736 accepted/tizen/7.0/unified/20230407.155839 accepted/tizen/7.0/unified/20230418.141946
authorseungho baek <sbsh.baek@samsung.com>
Thu, 23 Feb 2023 01:51:40 +0000 (10:51 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 7 Mar 2023 11:44:00 +0000 (20:44 +0900)
Change-Id: Ib9a64eef388799d4534d86f95b20735bc03a7fdd

examples/scene3d/scene3d-example.cpp
examples/scene3d/scene3d-example.h
examples/scene3d/scene3d-extension.h

index da9ea20..6759c6c 100644 (file)
@@ -19,8 +19,7 @@
 #include <dirent.h>\r
 #include <cstring>\r
 #include <string_view>\r
-#include "dali-scene3d/public-api/loader/dli-loader.h"\r
-#include "dali-scene3d/public-api/loader/gltf2-loader.h"\r
+#include "dali-scene3d/public-api/loader/model-loader.h"\r
 #include "dali-scene3d/public-api/loader/light-parameters.h"\r
 #include "dali-scene3d/public-api/loader/load-result.h"\r
 #include "dali-scene3d/public-api/loader/shader-definition-factory.h"\r
@@ -141,7 +140,7 @@ void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition
   }\r
 }\r
 \r
-Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<AnimationDefinition>* animations, Animation& animation)\r
+Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Dali::Animation>& generatedAnimations, Animation& animation)\r
 {\r
   ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) {\r
     return Application::GetResourcePath() + RESOURCE_TYPE_DIRS[type];\r
@@ -149,48 +148,27 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
 \r
   auto path = pathProvider(ResourceType::Mesh) + sceneName;\r
 \r
-  ResourceBundle                        resources;\r
-  SceneDefinition                       scene;\r
-  SceneMetadata                         metaData;\r
-  std::vector<AnimationGroupDefinition> animGroups;\r
-  std::vector<CameraParameters>         cameraParameters;\r
-  std::vector<LightParameters>          lights;\r
+  ResourceBundle                                          resources;\r
+  SceneDefinition                                         scene;\r
+  SceneMetadata                                           metaData;\r
+  std::vector<Dali::Scene3D::Loader::AnimationDefinition> animations;\r
+  std::vector<AnimationGroupDefinition>                   animGroups;\r
+  std::vector<CameraParameters>                           cameraParameters;\r
+  std::vector<LightParameters>                            lights;\r
 \r
-  animations->clear();\r
+  animations.clear();\r
 \r
   LoadResult output{\r
     resources,\r
     scene,\r
     metaData,\r
-    *animations,\r
+    animations,\r
     animGroups,\r
     cameraParameters,\r
     lights};\r
 \r
-  if(sceneName.rfind(DLI_EXTENSION) == sceneName.size() - DLI_EXTENSION.size())\r
-  {\r
-    DliLoader              loader;\r
-    DliLoader::InputParams input{\r
-      pathProvider(ResourceType::Mesh),\r
-      nullptr,\r
-      {},\r
-      {},\r
-      nullptr,\r
-      {}};\r
-    DliLoader::LoadParams loadParams{input, output};\r
-    if(!loader.LoadScene(path, loadParams))\r
-    {\r
-      ExceptionFlinger(ASSERT_LOCATION) << "Failed to load scene from '" << path << "': " << loader.GetParseError();\r
-    }\r
-  }\r
-  else\r
-  {\r
-    ShaderDefinitionFactory sdf;\r
-    sdf.SetResources(resources);\r
-    LoadGltfScene(path, sdf, output);\r
-\r
-    resources.mEnvironmentMaps.push_back({});\r
-  }\r
+  Dali::Scene3D::Loader::ModelLoader modelLoader(path, pathProvider(ResourceType::Mesh) + "/", output);\r
+  modelLoader.LoadModel(pathProvider);\r
 \r
   if(cameraParameters.empty())\r
   {\r
@@ -210,20 +188,14 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
     {},\r
     {},\r
     {}};\r
-  Customization::Choices choices;\r
 \r
   Actor root = Actor::New();\r
   SetActorCentered(root);\r
 \r
+  auto& resourceChoices = modelLoader.GetResourceChoices();\r
   for(auto iRoot : scene.GetRoots())\r
   {\r
-    auto resourceRefs = resources.CreateRefCounter();\r
-    scene.CountResourceRefs(iRoot, choices, resourceRefs);\r
-    resources.CountEnvironmentReferences(resourceRefs);\r
-\r
-    resources.LoadResources(resourceRefs, pathProvider);\r
-\r
-    if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))\r
+    if(auto actor = scene.CreateNodes(iRoot, resourceChoices, nodeParams))\r
     {\r
       scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);\r
       scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));\r
@@ -235,8 +207,10 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
     }\r
   }\r
 \r
-  if(!animations->empty())\r
+  generatedAnimations.clear();\r
+  if(!animations.empty())\r
   {\r
+    generatedAnimations.reserve(animations.size());\r
     auto getActor = [&](const Scene3D::Loader::AnimatedProperty& property)\r
     {\r
       Dali::Actor actor;\r
@@ -255,8 +229,11 @@ Actor LoadScene(std::string sceneName, CameraActor camera, std::vector<Animation
       return actor;\r
     };\r
 \r
-    animation = (*animations)[0].ReAnimate(getActor);\r
-    animation.Play();\r
+    for(auto& animationDefinition : animations)\r
+    {\r
+      generatedAnimations.push_back(animationDefinition.ReAnimate(getActor));\r
+    }\r
+    generatedAnimations[0].Play();\r
   }\r
 \r
   return root;\r
@@ -466,7 +443,6 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap)
 \r
   auto id = mItemView.GetItemId(actor);\r
 \r
-  Scene3D::Loader::InitializeGltfLoader();\r
   try\r
   {\r
     auto window      = mApp.GetWindow();\r
@@ -474,7 +450,7 @@ void Scene3DExample::OnTap(Dali::Actor actor, const Dali::TapGesture& tap)
     auto renderTasks = window.GetRenderTaskList();\r
     renderTasks.RemoveTask(mSceneRender);\r
 \r
-    auto scene = LoadScene(mSceneNames[id], mSceneCamera, &mSceneAnimations, mCurrentAnimation);\r
+    auto scene = LoadScene(mSceneNames[id], mSceneCamera, mSceneAnimations, mCurrentAnimation);\r
 \r
     auto sceneRender = renderTasks.CreateTask();\r
     sceneRender.SetCameraActor(mSceneCamera);\r
index eda40d5..3f56eba 100644 (file)
@@ -65,8 +65,8 @@ private: // data
 public:\r
   Dali::Actor mScene;\r
 \r
-  std::vector<Dali::Scene3D::Loader::AnimationDefinition> mSceneAnimations;\r
-  Dali::Animation                                     mCurrentAnimation;\r
+  std::vector<Dali::Animation> mSceneAnimations;\r
+  Dali::Animation              mCurrentAnimation;\r
 \r
   std::unique_ptr<Scene3DExtension> mScene3DExtension;\r
 \r
index 7317d32..fd56d7f 100644 (file)
@@ -93,16 +93,14 @@ private:
         return false;\r
       }\r
 \r
-      auto root     = mSceneLoader->mScene;\r
-      auto getActor = [&root](const Dali::Scene3D::Loader::AnimatedProperty& property) {\r
-        return root.FindChildByName(property.mNodeName);\r
-      };\r
-\r
       if(mSceneLoader->mSceneAnimations.size() > animationIndex)\r
       {\r
         mCurrentAnimationIndex          = animationIndex;\r
-        mSceneLoader->mCurrentAnimation = mSceneLoader->mSceneAnimations[animationIndex].ReAnimate(getActor);\r
-        mSceneLoader->mCurrentAnimation.FinishedSignal().Connect(this, &Scene3DExtension::OnAnimationFinished);\r
+        mSceneLoader->mCurrentAnimation = mSceneLoader->mSceneAnimations[animationIndex];\r
+        if(mSceneLoader->mCurrentAnimation.FinishedSignal().GetConnectionCount() == 0)\r
+        {\r
+          mSceneLoader->mCurrentAnimation.FinishedSignal().Connect(this, &Scene3DExtension::OnAnimationFinished);\r
+        }\r
         mSceneLoader->mCurrentAnimation.Play();\r
       }\r
     }\r