Align data members, pointers first, classes then, next built in types and flags last...
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / mesh-actor-impl.h
1 #ifndef __DALI_INTERNAL_MESH_ACTOR_H__
2 #define __DALI_INTERNAL_MESH_ACTOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <cstddef>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/actors/mesh-actor.h>
26 #include <dali/public-api/geometry/mesh.h>
27 #include <dali/public-api/modeling/entity.h>
28 #include <dali/internal/event/actors/actor-impl.h>
29 #include <dali/internal/event/actors/actor-declarations.h>
30 #include <dali/internal/event/modeling/material-impl.h>
31 #include <dali/internal/event/modeling/model-data-impl.h>
32 #include <dali/internal/event/actor-attachments/mesh-attachment-impl.h>
33 #include <dali/internal/event/actors/renderable-actor-impl.h>
34
35 namespace Dali
36 {
37 class Mesh;
38 class Entity;
39
40
41 namespace Internal
42 {
43
44 class MeshActor : public RenderableActor
45 {
46 public:
47
48   /**
49    * Create an un-intialised mesh actor
50    * @return A smart-pointer to a newly allocated mesh actor
51    */
52   static MeshActorPtr New();
53
54   /**
55    * Create an intialised mesh actor from the given mesh
56    * @param[in] mesh An object containing mesh data
57    * @return A smart-pointer to a newly allocated mesh actor
58    */
59   static MeshActorPtr New(Dali::Mesh mesh);
60
61     /**
62    * Create an intialised mesh actor from the given mesh
63    * @param[in] mesh An object containing mesh data
64    * @return A smart-pointer to a newly allocated mesh actor
65    */
66   static MeshActorPtr New(Dali::AnimatableMesh mesh);
67
68   /**
69    * Create an intialised mesh actor from a model entity
70    * @param[in] modelData Scene graph object
71    * @param[in] entity in a model
72    * @return A smart-pointer to a newly allocated mesh actor
73    */
74   static MeshActorPtr New(ModelDataPtr modelData, Dali::Entity entity);
75
76 public:
77
78   /**
79    * Add a mesh to this actor.
80    * @param[in] mesh A mesh structure
81    */
82   void SetMesh(Dali::Mesh mesh);
83
84   /**
85    * Add an animated mesh to this actor
86    * @param[in] mesh An animatable mesh
87    */
88   void SetMesh(Dali::AnimatableMesh mesh);
89
90   /**
91    * Add a mesh resource to this actor
92    * @param[in] mesh A mesh resource
93    */
94   void SetMesh(MeshIPtr meshPtr);
95
96   /**
97    * Set the given mesh to this actor
98    * @param[in] modelData The model data
99    * @param[in] meshIndex The mesh index from the model
100    */
101   void SetMesh(ModelDataPtr modelData, unsigned int meshIndex);
102
103   /**
104    * @copydoc Dali::MeshActor::SetMaterial(Material material)
105    */
106   void SetMaterial(const Dali::Material material);
107
108   /**
109    * Get a material for a given mesh.
110    * @return The material
111    */
112   Dali::Material GetMaterial() const;
113
114   /**
115    * Set whether this mesh actor should be affected by lights in the
116    * scene.  If it set to false, then the mesh will be unaffected by
117    * lighting, and will be evenly lit without any shading.
118    * This property is not inherited.
119    * @param[in] affectedByLighting Whether the actor should be lit by the scene lighting.
120    */
121   void SetAffectedByLighting(bool affectedByLighting);
122
123   /**
124    * Get whether the actor is lit by scene or evenly lit
125    * @return true if lit by scene, false if evenly lit
126    */
127   bool IsAffectedByLighting();
128
129   /**
130    * Search the actor tree for all named bones in the mesh array and connect them.
131    * @param[in] rootActor - the root actor of the actor tree.
132    */
133   void BindBonesToMesh(Internal::ActorPtr rootActor);
134
135 private: // From RenderableActor
136
137   /**
138    * @copydoc RenderableActor::GetRenderableAttachment
139    */
140   virtual RenderableAttachment& GetRenderableAttachment() const
141   {
142     DALI_ASSERT_DEBUG( mMeshAttachment );
143     return *mMeshAttachment;
144   }
145
146 protected:
147   /**
148    * Protected constructor; see also MeshActor::New()
149    */
150   MeshActor();
151
152   /**
153    * A reference counted object may only be deleted by calling Unreference()
154    */
155   virtual ~MeshActor();
156
157 private:
158   Internal::MeshAttachmentPtr mMeshAttachment;
159 };
160
161 } // namespace Internal
162
163 // Helpers for public-api forwarding methods
164
165 inline Internal::MeshActor& GetImplementation(Dali::MeshActor& meshActor)
166 {
167   DALI_ASSERT_ALWAYS( meshActor && "MeshActor handle is empty" );
168
169   BaseObject& handle = meshActor.GetBaseObject();
170
171   return static_cast<Internal::MeshActor&>(handle);
172 }
173
174 inline const Internal::MeshActor& GetImplementation(const Dali::MeshActor& meshActor)
175 {
176   DALI_ASSERT_ALWAYS( meshActor && "MeshActor handle is empty" );
177
178   const BaseObject& handle = meshActor.GetBaseObject();
179
180   return static_cast<const Internal::MeshActor&>(handle);
181 }
182
183 } // namespace Internal
184
185 #endif // __DALI_INTERNAL_MESH_ACTOR_H__