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