1 #ifndef __DALI_INTERNAL_MODEL_DATA_H__
2 #define __DALI_INTERNAL_MODEL_DATA_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/common/light.h>
24 #include <dali/public-api/modeling/material.h>
25 #include <dali/public-api/modeling/entity.h>
26 #include <dali/public-api/modeling/model-data.h>
27 #include <dali/public-api/modeling/model-animation-map.h>
28 #include <dali/public-api/object/base-object.h>
29 #include <dali/internal/event/resources/resource-ticket.h>
30 #include <dali/internal/common/owner-container.h>
44 typedef IntrusivePtr<ModelData> ModelDataPtr;
47 * Encapsulates a Dali 3D model/scene.
49 class ModelData : public BaseObject
59 * @param[in] name The name of the model.
62 static ModelDataPtr New(const std::string& name);
66 * @param[in] name The model name
68 void SetName(const std::string& name);
71 * Returns the name of the model
72 * @return the model name
74 const std::string& GetName() const;
77 * Set the root Entity of the model.
78 * @param root - the root entity
80 void SetRootEntity(Dali::Entity root);
83 * Get the root Entity of the model.
84 * @return the root entity
86 Dali::Entity GetRootEntity() const;
89 * Add a mesh to the model
90 * @param mesh - the mesh to add.
92 void AddMesh(const Dali::MeshData& mesh);
95 * Add a mesh ticket to the model. ModelFactory should ensure that the index
96 * of this ticket is the same as the MeshData it represents.
97 * @param[in] ticket The ticket of the mesh resource.
99 void AddMeshTicket(ResourceTicketPtr ticket);
102 * Get a mesh by index.
103 * @param[in] index The zero based index to a mesh
104 * @return The MeshData object.
106 const Dali::MeshData& GetMesh(unsigned int index) const;
109 * Get a mesh by index.
110 * @param[in] index The zero based index to a mesh
111 * @return The MeshData object.
113 Dali::MeshData& GetMesh(unsigned int index);
116 * Get a mesh ticket by index
117 * @param[in] index The index of a mesh
118 * @return The resource ticket for that mesh
120 const ResourceTicketPtr GetMeshTicket(unsigned int index) const;
124 * @returns number of meshes
126 unsigned int NumberOfMeshes() const;
129 * Add material to the model
130 * @param[in] material - the material to add to the model
132 void AddMaterial(Dali::Material material);
135 * Get a material by index.
136 * @param[in] index The zero based index to a material
137 * @return A pointer to a material, or NULL.
139 Dali::Material GetMaterial(unsigned int index) const;
143 * @return number of materials
145 unsigned int NumberOfMaterials() const;
148 * Get animation map container.
149 * @return reference to the animation map container.
151 ModelAnimationMapContainer& GetAnimationMapContainer();
154 * Get the animation for the given index. Returns a null pointer
155 * if the index is out of range.
156 * @param[in] index The index of the animation
157 * @return A pointer to the animation data
159 const ModelAnimationMap* GetAnimationMap (unsigned int index) const;
162 * Get the animation for the given name. Returns a null pointer
163 * if the name is not found.
164 * @param[in] name Name of animation for which to search
165 * @return A pointer to the animation data
167 const ModelAnimationMap* GetAnimationMap (const std::string& name) const;
170 * Get the duration for a given animation. Returns zero if not found.
171 * @param[in] animationIndex - the index of the animation
172 * @return the duration in seconds, or zero if not found
174 float GetAnimationDuration(size_t animationIndex) const;
177 * Get the index for the given name. Returns false if not found.
178 * @param[in] name The name of the animation to find
179 * @param[out] index The index of the named animation if found
180 * @return true if the animation was foud, false if not found.
182 bool FindAnimation (const std::string& name, unsigned int& index) const;
185 * Get the number of animation maps
186 * @return the number of animation maps
188 unsigned int NumberOfAnimationMaps() const;
191 * Add a light to the model
192 * @param light - the light to add to the model
194 void AddLight(Dali::Light light);
197 * Get a light by index.
198 * @param[in] index The zero based index to a light
199 * @return A pointer to a light, or NULL.
201 Dali::Light GetLight(unsigned int index) const;
204 * Get the number of lights contained in the model.
205 * @return The number of lights contained in the model.
207 unsigned int NumberOfLights() const;
210 * Unpacking is where new resources are created, for the meshes provided in the model data.
211 * This should be called after the model data has loaded.
212 * @param[in] resourceClient Used to create new resource tickets.
214 void Unpack( ResourceClient& resourceClient );
217 * @copydoc Dali::ModelData::Read()
219 bool Read(std::streambuf& buf);
222 * @copydoc Dali::ModelData::Write()
224 bool Write(std::streambuf& buf) const;
229 * A reference counted object may only be deleted by calling Unreference()
231 virtual ~ModelData();
235 std::string mName; ///< 3D model name
236 std::vector<Dali::Material> mMaterials; ///< Container of Materials
237 OwnerContainer< MeshData* > mMeshes; ///< Container of Meshes
238 std::vector<Dali::Light> mLights; ///< Collection of Lights
239 ModelAnimationMapContainer mAnimationMaps; ///< List of Animation maps
240 Dali::Entity mRoot; ///< Root of the entity hierarchy tree
242 bool mUnpacked; ///< True if resources have been created, for the meshes provided in the model data.
243 std::vector<ResourceTicketPtr> mMeshTickets; ///< List of Mesh tickets to scene graph objects
244 }; // class ModelData
246 } // namespace Internal
248 // Helpers for public-api forwarding methods
250 inline Internal::ModelData& GetImplementation(Dali::ModelData& modelData)
252 DALI_ASSERT_ALWAYS( modelData && "ModelData handle is empty" );
254 BaseObject& handle = modelData.GetBaseObject();
256 return static_cast<Internal::ModelData&>(handle);
259 inline const Internal::ModelData& GetImplementation(const Dali::ModelData& modelData)
261 DALI_ASSERT_ALWAYS( modelData && "ModelData handle is empty" );
263 const BaseObject& handle = modelData.GetBaseObject();
265 return static_cast<const Internal::ModelData&>(handle);
272 #endif // __DALI_INTERNAL_MODEL_DATA_H__