[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / common / model-load-task.h
1 #ifndef DALI_SCENE3D_MODEL_LOAD_TASK_H
2 #define DALI_SCENE3D_MODEL_LOAD_TASK_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/adaptor-framework/async-task-manager.h>
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/images/pixel-data.h>
25 #include <memory>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene3d/internal/common/model-cache-manager.h>
29 #include <dali-scene3d/public-api/loader/load-result.h>
30 #include <dali-scene3d/public-api/loader/model-loader.h>
31 #include <dali-scene3d/public-api/loader/scene-definition.h>
32 #include <dali/devel-api/threading/conditional-wait.h>
33
34 namespace Dali
35 {
36 namespace Scene3D
37 {
38 namespace Internal
39 {
40 class ModelLoadTask;
41 typedef IntrusivePtr<ModelLoadTask> ModelLoadTaskPtr;
42
43 class ModelLoadTask : public AsyncTask
44 {
45 public:
46   /**
47    * Constructor
48    * @param[in] modelUrl Model file path.(e.g., glTF, and DLI).
49    * @param[in] resourceDirectoryUrl Resource file path that includes binary, image etc.
50    * @param[in] callback The callback that is called when the operation is completed.
51    */
52   ModelLoadTask(const std::string& modelUrl, const std::string& resourceDirectoryUrl, CallbackBase* callback);
53
54   /**
55    * Destructor.
56    */
57   ~ModelLoadTask();
58
59   /**
60    * Whether the task has succeeded.
61    * @return True if the task has succeeded.
62    */
63   bool HasSucceeded() const;
64
65   /**
66    * @brief Retrieves loaded scene
67    * @return SceneDefinition that is loaded from file
68    */
69   Dali::Scene3D::Loader::SceneDefinition& GetScene() const;
70
71   /**
72    * @brief Retrieves resource bunder that includes resource information
73    * @return ResourceBundle for model resources
74    */
75   Dali::Scene3D::Loader::ResourceBundle& GetResources() const;
76
77   /**
78    * @brief Retrieves loaded AnimationDefinition
79    * @return AnimationDefinition that is loaded from file
80    */
81   std::vector<Dali::Scene3D::Loader::AnimationDefinition>& GetAnimations() const;
82
83   /**
84    * @brief Retrieves loaded CameraParameters
85    * @return CameraParameters list that is loaded from file
86    */
87   std::vector<Dali::Scene3D::Loader::CameraParameters>& GetCameras() const;
88
89   /**
90    * @brief Retrieves ResourceChoices
91    * @return Choices for loaded Resources
92    */
93   Dali::Scene3D::Loader::Customization::Choices& GetResourceChoices();
94
95 public: // Implementation of AsyncTask
96   /**
97    * @copydoc Dali::AsyncTask::Process()
98    */
99   void Process();
100
101   /**
102    * @copydoc Dali::AsyncTask::IsReady()
103    */
104   bool IsReady();
105
106   /**
107    * @copydoc Dali::AsyncTask::GetTaskName()
108    */
109   std::string_view GetTaskName() const override
110   {
111     return "ModelLoadTask";
112   }
113
114 private:
115   // Undefined
116   ModelLoadTask(const ModelLoadTask& task) = delete;
117
118   // Undefined
119   ModelLoadTask& operator=(const ModelLoadTask& task) = delete;
120
121   std::string                                         mModelUrl;
122   std::string                                         mResourceDirectoryUrl;
123   std::shared_ptr<Dali::Scene3D::Loader::ModelLoader> mModelLoader;
124   ModelCacheManager                                   mModelCacheManager;
125   Dali::Scene3D::Loader::LoadResult                   mLoadResult;
126   bool                                                mHasSucceeded;
127 };
128
129 } // namespace Internal
130
131 } // namespace Scene3D
132
133 } // namespace Dali
134
135 #endif // DALI_SCENE3D_MODEL_LOAD_TASK_H