1 #ifndef __DALI_ENTITY_H__
2 #define __DALI_ENTITY_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.
23 #include <dali/public-api/geometry/mesh.h>
34 namespace Internal DALI_INTERNAL
39 typedef std::vector<Entity> EntityContainer; ///< Container of Entity handles
40 typedef EntityContainer::iterator EntityIter; ///< iterator for Entity container
41 typedef EntityContainer::const_iterator EntityConstIter; ///< const_iterator for Entity container
42 typedef std::vector<unsigned int> EntityMeshIndices; ///< Container to hold indexes of meshes this entity uses in the associated Dali::Model.
45 * @brief A 3D model comprises a tree of named entities. Each entity has a
46 * transform, regardless of type.
48 * It can contain zero or more meshes. The entity names are used for
49 * cross referencing, e.g. from animations or from bone structures.
51 class DALI_IMPORT_API Entity : public BaseHandle
56 * @brief The entity type
60 OBJECT, ///< A generic entity
61 CAMERA, ///< The entity represents a camera
62 LIGHT, ///< The entity represents a light
66 * @brief Create an uninitialized Entity; this can be initialized with Entity::New().
68 * Calling member functions with an uninitialized Dali::Object is not allowed.
73 * @brief Create an initialized handle.
75 * @param[in] name The name of the entity
76 * @return a handle to a newly allocated Dali resource
78 static Entity New(const std::string name);
81 * @brief Downcast an Object handle to Entity handle.
83 * If handle points to a Entity object the downcast produces valid
84 * handle. If not the returned handle is left uninitialized.
86 * @param[in] handle to An object
87 * @return handle to a Entity object or an uninitialized handle
89 static Entity DownCast( BaseHandle handle );
94 * This is non-virtual since derived Handle types must not contain data or virtual methods.
99 * @brief This copy constructor is required for (smart) pointer semantics.
101 * @param [in] handle A reference to the copied handle
103 Entity(const Entity& handle);
106 * @brief This assignment operator is required for (smart) pointer semantics.
108 * @param [in] rhs A reference to the copied handle
109 * @return A reference to this
111 Entity& operator=(const Entity& rhs);
114 * @brief Find an entity by name.
116 * The search includes this entity and it's children.
117 * @param[in] name The search name.
118 * @return A handle to the searched entity, or an uninitialized handle if not found.
120 Entity Find(const std::string& name) const;
123 * @brief Set the name of the entity.
125 * @param[in] name The name for the entity.
127 void SetName(const char* name);
130 * @copydoc SetName(const char*)
132 void SetName(const std::string& name);
135 * @brief Get the name of the entity.
137 * @return The name of the entity.
139 const std::string& GetName() const;
142 * @brief Set the entity type.
144 * @param[in] type The entity's type, a member of the EntityType enumeration.
146 void SetType(const EntityType type);
149 * @brief Get the entity's type.
151 * @return The entity's type, a member of the EntityType enumeration.
153 EntityType GetType() const;
156 * @brief Set the transform matrix.
158 * @param[in] matrix The transform matrix
160 void SetTransformMatrix(Matrix& matrix);
163 * @brief Returns a reference to the transform matrix.
165 * @return The transform matrix
167 const Matrix& GetTransformMatrix() const;
170 * @brief Checks if the entity has children.
172 * @return true if the entity has children, otherwise false.
174 bool HasChildren() const;
177 * @brief Get the number of children.
179 * @return The number of children.
181 int NumberOfChildren() const;
184 * @brief Get the list of children.
186 * @return A reference to the list of children.
188 const EntityContainer& GetChildren() const;
191 * @brief Add an entity to the end of the child list.
193 * Sets the child's parent.
194 * @param[in] child A handle to a child Entity.
196 void Add(Entity child);
199 * @brief Get the entity's parent.
201 * @return A pointer to the entity's parent.
203 Entity GetParent() const;
206 * @brief Change the size of storage allocated to the mesh index list.
208 * This may be greater than the number of indices stored as returned
211 * @param[in] capacity The new size of the storage allocated to the mesh
214 void SetMeshCapacity(unsigned int capacity);
217 * @brief Add a mesh to the entity.
219 * @param[in] meshIdx The mesh index into the model data's list of meshes
221 void AddMeshIndex(unsigned int meshIdx);
224 * @brief Checks if the entity references any meshes.
226 * @return true if the entity refers to 1 or more meshes, otherwise false.
228 bool HasMeshes() const;
231 * @brief Get the number of meshes referenced by this entity.
233 * @return The number of meshes referenced by this entity.
235 int NumberOfMeshes() const;
238 * @brief Returns a mesh in the model's mesh array.
240 * @param[in] meshIndex The index of the mesh within the entity.
241 * @return The index of the mesh in the model's mesh array.
243 unsigned int GetMeshByIndex(unsigned int meshIndex) const;
246 * @brief Get the entity's list of mesh indices.
248 * @return The entity's list of mesh indices.
250 const EntityMeshIndices& GetMeshes() const;
253 * @brief Expand the bounding volume to include the child's bounding volume.
255 * @param[in] child A handle to the child.
257 void AddToBounds(Entity child);
260 * @brief Expand the entity bounding box to include the new boundaries.
262 * @param[in] lowerBounds to extend the entity bounds
263 * @param[in] upperBounds to extend the entity bounds
265 void AddToBounds( const Vector3& lowerBounds, const Vector3& upperBounds );
268 * @brief Get the lower bounds of the bounding volume which contains all vertices in all meshes
269 * referenced by this entity.
271 * @return A vector describing the lower bounds.
273 const Vector3& GetLowerBounds() const;
276 * @brief Set the lower bounds of the bounding volume which contains all vertices in all meshes
277 * referenced by this entity.
279 * @param[in] lowerBounds of the entity.
281 void SetLowerBounds( const Vector3& lowerBounds );
284 * @brief Get the upper bounds of the bounding volume which contains all vertices in all meshes
285 * referenced by this entity.
287 * @return A vector describing the upper bounds.
289 const Vector3& GetUpperBounds() const;
292 * @brief Set the upper bounds of the bounding volume which contains all vertices in all meshes
293 * referenced by this entity.
295 * @param[in] upperBounds of the entity.
297 void SetUpperBounds( const Vector3& upperBounds );
299 public: // Not intended for application developers
302 * @brief This constructor is used by Dali New() methods.
303 * @param [in] entity A pointer to a newly allocated Dali resource
305 explicit DALI_INTERNAL Entity(Internal::Entity* entity);
311 #endif // __DALI_ENTITY_H__