Optimization to reduce Handle size by 50%
[platform/core/uifw/dali-core.git] / dali / public-api / modeling / model-data.h
1 #ifndef __DALI_MODEL_DATA_H__
2 #define __DALI_MODEL_DATA_H__
3
4 /*
5  * Copyright (c) 2014 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
21
22 // EXTERNAL INCLUDES
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/modeling/model-animation-map.h>
27 #include <dali/public-api/object/base-handle.h>
28
29 namespace Dali DALI_IMPORT_API
30 {
31
32 class Entity;
33 class MeshData;
34 class Material;
35 class Light;
36
37 namespace Internal DALI_INTERNAL
38 {
39 class ModelData;
40 }
41
42 /**
43  * @brief Encapsulates a Dali 3D model/scene.
44  *
45  * This is usually generated by an external model loader (and is also
46  * used internally with the default model loader).
47  */
48 class ModelData : public BaseHandle
49 {
50 public:
51
52   /**
53    * @brief Constructs an uninitialized handle.
54    */
55   ModelData();
56
57   /**
58    * @brief Create an initialized ModelData.
59    *
60    * @param[in] name The name of the model.
61    * @return A handle to a newly allocated Dali resource.
62    */
63   static ModelData New(const std::string& name);
64
65   /**
66    * @brief Downcast an Object handle to ModelData handle.
67    *
68    * If handle points to a ModelData object the downcast produces
69    * valid handle. If not the returned handle is left uninitialized.
70    *
71    * @param[in] handle to An object
72    * @return handle to a ModelData object or an uninitialized handle
73    */
74   static ModelData DownCast( BaseHandle handle );
75
76   /**
77    * @brief Destructor
78    *
79    * This is non-virtual since derived Handle types must not contain data or virtual methods.
80    */
81   ~ModelData();
82
83   /**
84    * @copydoc Dali::BaseHandle::operator=
85    */
86   using BaseHandle::operator=;
87
88   /**
89    * @brief Returns the name of the model.
90    *
91    * @return The model name
92    */
93   const std::string& GetName() const;
94
95   /**
96    * @brief Set the root Entity of the model.
97    *
98    * @param root A handle to the root entity
99    */
100   void SetRootEntity(Entity root);
101
102   /**
103    * @brief Get the root Entity of the model.
104    *
105    * @return The root entity
106    */
107   Entity GetRootEntity() const;
108
109   /**
110    * @brief Add a mesh to the model.
111    *
112    * @param mesh The mesh data to add.
113    */
114   void AddMesh(MeshData& mesh);
115
116   /**
117    * @brief Get a mesh by index.
118    *
119    * @param[in] index The zero based index to a mesh
120    * @return          The mesh.
121    */
122   const MeshData& GetMesh(unsigned int index) const;
123
124   /**
125    * @brief Get a mesh by index.
126    *
127    * @param[in] index The zero based index to a mesh
128    * @return          The mesh.
129    */
130   MeshData& GetMesh(unsigned int index);
131
132   /**
133    * @brief Get Mesh count.
134    *
135    * @returns number of meshes
136    */
137   unsigned int NumberOfMeshes() const;
138
139   /**
140    * @brief Add material to the model.
141    *
142    * @param[in] material - the material to add to the model
143    */
144   void AddMaterial(Material material);
145
146   /**
147    * @brief Get a material by index.
148    *
149    * @param[in] index The index to a material
150    * @return          A handle to a material, or NULL.
151    */
152   Material GetMaterial(unsigned int index) const;
153
154   /**
155    * @brief Get material count.
156    *
157    * @return The Number of materials
158    */
159   unsigned int NumberOfMaterials() const;
160
161   /**
162    * @brief Get animation map container.
163    *
164    * @return reference to the animation map container.
165    */
166    ModelAnimationMapContainer& GetAnimationMapContainer();
167
168   /**
169    * @brief Get an animation map from the model data.
170    *
171    * @deprecated Use ModelActorFactory to generate animations
172    * @param[in] index The index of the animation map.
173    * @return a pointer to model animation map.
174    */
175   const ModelAnimationMap* GetAnimationMap (unsigned int index) const;
176
177   /**
178    * @brief Get the animation for the given name.
179    *
180    * @deprecated Use ModelActorFactory to generate animations
181    * @param[in] name The name of an animation map to search for.
182    * @return a pointer to model animation map.
183    */
184   const ModelAnimationMap* GetAnimationMap (const std::string& name) const;
185
186   /**
187    * @brief Find the index for the given animation name.
188    *
189    * @param[in] name The name of the animation map to search for.
190    * @param[out] index The index of the found map
191    * @return true if the name was found, false otherwise.
192    */
193   bool FindAnimation (const std::string& name, unsigned int& index) const;
194
195   /**
196    * @return the number of animations defined for this model
197    */
198   unsigned int NumberOfAnimationMaps() const;
199
200   /**
201    * @brief Add a light to the model.
202    *
203    * @param light - the light to add to the model
204    */
205   void AddLight(Light light);
206
207   /**
208    * @brief Get a light by index.
209    *
210    * @param[in] index The zero based index to a light
211    * @return          A pointer to a light, or NULL.
212    */
213   Light GetLight(unsigned int index) const;
214
215   /**
216    * @brief Get the number of lights contained in the model.
217    *
218    * @return The number of lights contained in the model.
219    */
220   unsigned int NumberOfLights() const;
221
222   /**
223    * @brief Read the model data from an open streambuf.
224    *
225    * @param[in] buf A streambuf opened for reading
226    * @return true if data was read successfully.
227    */
228   bool Read(std::streambuf& buf);
229
230   /**
231    * @brief Write the model data to an open streambuf.
232    *
233    * @param[in] buf A streambuf opened for writing
234    * @return true if data was written successfully.
235    */
236   bool Write(std::streambuf& buf) const;
237
238 public: // Not intended for application developers
239   /**
240    * @brief This constructor is used by Dali New() methods.
241    *
242    * @param[in] modelData A pointer to a newly allocated modelData
243    */
244   explicit DALI_INTERNAL ModelData(Internal::ModelData* modelData);
245
246 }; // Class ModelData
247
248 } // namespace Dali
249
250 #endif // __DALI_MODEL_DATA_H__