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