159fd582767dbbc2f40f2846d535b75bfc395568
[platform/core/uifw/dali-core.git] / capi / dali / public-api / geometry / animatable-mesh.h
1 #ifndef __DALI_ANIMATABLE_MESH__H__
2 #define __DALI_ANIMATABLE_MESH__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  * @addtogroup CAPI_DALI_GEOMETRY_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/object/constrainable.h>
29 #include <dali/public-api/geometry/animatable-vertex.h>
30 #include <dali/public-api/modeling/material.h>
31
32 namespace Dali DALI_IMPORT_API
33 {
34 class AnimatableVertex;
35
36 namespace Internal DALI_INTERNAL
37 {
38 class AnimatableMesh;
39 }
40
41 /**
42  * @brief An animatable mesh can have any of its vertices animated using Dali's animation and
43  * constraint systems.
44  *
45  * It is recommended that the vertices of the mesh remain in the bounds -0.5 - 0.5, which
46  * will match the actor size boundaries. The origin of the mesh matches the actor's position.
47  */
48 class AnimatableMesh : public Constrainable
49 {
50 public:
51   /**
52    * @brief Vector of face indices.
53    */
54   typedef std::vector<unsigned short> Faces;
55   typedef Faces::iterator             FacesIter;      ///< Iterator for Dali::AnimatableMesh::Faces
56   typedef Faces::const_iterator       FacesConstIter; ///< Const Iterator for Dali::AnimatableMesh::Faces
57
58   /**
59    * @brief Create an uninitialized handle, this can be initialized with New().
60    *
61    * Calling member functions on an uninitialized handle will result
62    * in an assertion
63    */
64   AnimatableMesh();
65
66   /**
67    * @brief Create a new animatable mesh with a given number of vertices and triangles.
68    *
69    * This will assert if any index is out of range.
70    * Using this constructor enables the vertex color property.
71    * AnimatableMesh does not take ownership of the faceIndices.
72    * @param[in] numVertices The number of vertices in the mesh
73    * @param[in] faceIndices A set of vertex indices, 3 per face.
74    * @return an initialized handle to the animatable mesh
75    * @note The maximum number of supported vertices is 3333333.
76    */
77   static AnimatableMesh New( unsigned int numVertices,
78                              const Faces& faceIndices );
79
80   /**
81    * @brief Create a new animatable mesh with a given number of vertices and triangles.
82    *
83    * This will assert if any index is out of range.
84    * Using this constructor disables the vertex color property.
85    * AnimatableMesh does not take ownership of the faceIndices.
86    * @param[in] numVertices The number of vertices in the mesh
87    * @param[in] faceIndices A set of vertex indices, 3 per face.
88    * @param[in] material Material used to render mesh
89    * @return an initialized handle to the animatable mesh
90    * @note The maximum number of supported vertices is 3333333.
91    */
92   static AnimatableMesh New( unsigned int numVertices,
93                              const Faces& faceIndices,
94                              Dali::Material material );
95
96   /**
97    * @brief Downcast an Object handle to AnimatableMesh.
98    *
99    * If the handle points to an AnimatableMesh objec, the downcast
100    * produces a valid handle. If not, the handle is left
101    * uninitialized.
102    *
103    * @param[in] handle to an Object
104    * @return handle to an AnimatableMesh or an uninitialized handle
105    */
106   static AnimatableMesh DownCast( BaseHandle handle );
107
108   /**
109    * @brief Destructor
110    */
111   virtual ~AnimatableMesh();
112
113   /**
114    * @brief Get the number of vertices with which this mesh was created.
115    *
116    * @return number of vertices in this mesh
117    */
118   unsigned int GetNumberOfVertices() const;
119
120   /**
121    * @copydoc Dali::BaseHandle::operator=
122    */
123   using BaseHandle::operator=;
124
125   /**
126    * @brief Array subscript operator overload.
127    *
128    * @pre The vertex index is in range
129    * @param[in] index subscript
130    * @return    the vertex at the given index
131    */
132   AnimatableVertex operator[]( unsigned int index ) const;
133
134   /**
135    * @brief Get a property index for a given vertex.
136    *
137    * @pre The vertex index and property is in range
138    * @param[in] vertex The vertex
139    * @param[in] property The vertex attribute
140    * @return A property index for use in constraints or animations
141    */
142   Property::Index GetPropertyIndex( unsigned int vertex, Property::Index property) const;
143
144   /**
145    * @brief Get the property for a given vertex.
146    *
147    * @pre The vertex index and property is in range
148    * @param[in] vertex The vertex
149    * @param[in] property The vertex attribute
150    * @return A property index for use in constraints or animations
151    */
152   Property GetVertexProperty( unsigned int vertex, Property::Index property );
153
154 public: // Not for use by application developer
155
156   /**
157    * @brief This constructor is used by Dali New() methods
158    *
159    * @param [in] mesh A pointer to a newly allocated Dali resource
160    */
161   explicit DALI_INTERNAL AnimatableMesh(Internal::AnimatableMesh* mesh);
162 };
163
164 }// Dali
165
166 /**
167  * @}
168  */
169 #endif