Change dali-scene-loader to dali-scene3d
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / dli-loader.h
1 #ifndef DALI_SCENE3D_LOADER_DLI_LOADER_H
2 #define DALI_SCENE3D_LOADER_DLI_LOADER_H
3 /*
4  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include "dali-scene3d/public-api/api.h"
22 #include "dali-scene3d/public-api/loader/animation-definition.h"
23 #include "dali-scene3d/public-api/loader/customization.h"
24 #include "dali-scene3d/public-api/loader/index.h"
25 #include "dali-scene3d/public-api/loader/string-callback.h"
26
27 // EXTERNAL INCLUDES
28 #include "dali/public-api/common/vector-wrapper.h"
29
30 namespace Dali
31 {
32 namespace Scene3D
33 {
34 namespace Loader
35 {
36 typedef std::pair<std::string, std::string> Metadata;
37
38 // Forward declarations
39 struct LoadResult;
40 struct CameraParameters;
41 struct LightParameters;
42 struct TextParameters;
43
44 class ResourceBundle;
45 struct NodeDefinition;
46 class SceneDefinition;
47
48 class DALI_SCENE3D_API DliLoader
49 {
50 public:
51   using ConvertFontCode  = void (*)(const std::string& code, std::string& fontFamily, std::string& slant, std::string& weight, float& size);
52   using ConvertColorCode = Vector4 (*)(const std::string& code);
53
54   using CategoryProcessor       = std::function<void(Property::Array&& categoryData, StringCallback onError)>;
55   using CategoryProcessorVector = std::vector<std::pair<std::string /*name*/, CategoryProcessor>>;
56
57   using NodeProcessor = std::function<void(const NodeDefinition& nodeDef,
58                                            Property::Map&&       nodeData,
59                                            StringCallback        onError)>;
60
61   using AnimationProcessor = std::function<void(const AnimationDefinition& animDef,
62                                                 Property::Map&&            animData,
63                                                 StringCallback             onError)>;
64
65   struct InputParams
66   {
67     /**
68      * @brief The absolute path of animation binaries referenced in the .dli.
69      */
70     std::string mAnimationsPath;
71
72     /**
73      * @brief Provides a facility to determine a color from a code instead of RGB(A) values.
74      */
75     ConvertColorCode mConvertColorCode;
76
77     /**
78      * @brief A collection of handlers, mapped to the names of the top level (i.e. below
79      *  root) element, whom they will attempt to process. This will take place before
80      *  the parsing of scene Nodes and Animations, but after skeletons, environment, mesh,
81      *  shader and material resources.
82      */
83     CategoryProcessorVector mPreNodeCategoryProcessors;
84
85     /**
86      * @brief A collection of handlers, mapped to the names of the top level (i.e. below
87      *  root) element, whom they will attempt to process. This will take place after
88      *  the parsing of the scene Nodes and Animations.
89      */
90     CategoryProcessorVector mPostNodeCategoryProcessors;
91
92     /**
93      * @brief Provides an extension point to nodes. If provided, this function will be
94      *  called with each JSON element and definition, of a scene node.
95      * @note Constraints rely on ID resolution (from .dli to scene definition), which
96      *  takes place after the parsing of the nodes; therefore AT THIS POINT the node
97      *  IDs seen in constraints will still be the .dli IDs - NOT to be relied on for
98      *  indexing into mScene.
99      */
100     NodeProcessor mNodePropertyProcessor;
101
102     /**
103      * @brief Provides an extension point to animations. If provided, this function will be
104      *  called with each JSON element and fully processed definition, of an animation.
105      */
106     AnimationProcessor mAnimationPropertyProcessor;
107   };
108
109   struct LoadParams
110   {
111     InputParams const& input;
112     LoadResult&        output;
113   };
114
115   DliLoader();
116   ~DliLoader();
117
118   /**
119    * @brief Sets the callback that messages from non-fatal errors get posted to.
120    *  Uses DefaultErrorCallback by default.
121    */
122   void SetErrorCallback(StringCallback onError);
123
124   /**
125    * @brief Attempts to load and parse a .dli document into a DOM tree.
126    * @return Whether the operation was successful.
127    */
128   bool LoadScene(const std::string& uri, LoadParams& params);
129
130   /**
131    * @return The error string describing how the parse has failed, if any.
132    */
133   std::string GetParseError() const;
134
135 private:
136   struct Impl;
137   const std::unique_ptr<Impl> mImpl;
138 };
139
140 } // namespace Loader
141 } // namespace Scene3D
142 } // namespace Dali
143
144 #endif // DALI_SCENE3D_LOADER_DLI_LOADER_H