1 #ifndef __DALI_INTERNAL_MESH_ATTACHMENT_H__
2 #define __DALI_INTERNAL_MESH_ATTACHMENT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 #include <dali/public-api/geometry/mesh.h>
22 #include <dali/public-api/modeling/material.h>
23 #include <dali/internal/common/owner-container.h>
24 #include <dali/internal/event/actors/actor-declarations.h>
25 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
26 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
27 #include <dali/internal/event/modeling/mesh-impl.h>
28 #include <dali/internal/event/modeling/material-impl.h>
29 #include <dali/internal/event/resources/resource-ticket.h>
30 #include <dali/internal/event/common/proxy-object.h>
44 typedef std::vector<std::string> BoneNames;
45 typedef BoneNames::const_iterator BoneNamesIter;
48 * An attachment for rendering a 3D mesh with a material.
50 class MeshAttachment : public RenderableAttachment
54 struct MeshAndCustomMaterial
56 Internal::MeshIPtr mMesh;
57 Internal::MaterialIPtr mMaterial;
58 Internal::MaterialIPtr mCustomMaterial;
63 * Create an initialised MeshAttachment.
64 * @param[in] parentNode The node to attach a scene-object to.
65 * This will not be displayed until a mesh is added with SetMesh().
66 * @return A handle to a newly allocated Dali resource.
68 static MeshAttachmentPtr New( const SceneGraph::Node& parentNode );
71 * Set the mesh to be rendererd by this attachment
72 * @param[in] meshPtr A mesh impl (may be null)
73 * @param[in] meshId The resource id of the mesh
74 * @param[in] bones Container of bones for this mesh
75 * @param[in] material The material
77 void SetMesh( const MeshIPtr meshPtr,
79 const BoneContainer& bones,
80 const MaterialIPtr material );
83 * Add a mesh to the collection of meshes being rendered by this attachment
84 * @param [in] meshResource A mesh resource
85 * @param[in] bones Container of bones for this mesh
86 * @param [in] material Material
88 void SetMesh( const ResourceTicketPtr meshResource,
89 const BoneContainer& bones,
90 const MaterialIPtr material );
93 * Set the material of the mesh
94 * @param[in] materialPtr - a custom material to apply to this mesh
96 void SetMaterial( Internal::MaterialIPtr materialPtr );
99 * Get the material of the mesh
100 * @return The internal material pointer
102 Internal::MaterialIPtr GetMaterial( ) const;
105 * Disconnect any connected material from the mesh
107 void DisconnectMaterial( );
110 * Set whether this mesh actor should be affected by lights in the
111 * scene. If it set to false, then the mesh will be unaffected by
112 * lighting, and will be evenly lit without any shading.
113 * This property is not inherited.
114 * @param[in] affectedByLighting Whether the actor should be lit by the scene lighting.
116 void SetAffectedByLighting( bool affectedByLighting );
119 * @return true if the actor is lit by the scene, or false if evenly lit.
121 bool IsAffectedByLighting();
124 * Search the actor tree for all named bones in the mesh and connect them.
125 * @param[in] rootActor - the root actor of the actor tree.
127 void BindBonesToMesh( Internal::ActorPtr rootActor );
130 * Connects a boneActor to the mesh (allows the mesh renderer to do
131 * skeletal animation by calculating the actor transforms)
132 * @param[in] boneActor - the actor containing the bone's current position
133 * @param[in] boneIdx - the index of the bone in this mesh
134 * @param[in] boneCount - the bone count
136 void ConnectBoneActor( Internal::ActorPtr boneActor, size_t boneIdx, size_t boneCount );
138 const MeshAndCustomMaterial& GetMesh() const
146 * A reference counted object may only be deleted by calling Unreference()
148 virtual ~MeshAttachment();
153 * First stage construction of a MeshAttachment.
154 * @param[in] stage Used to send messages to scene-graph.
156 MeshAttachment( Stage& stage );
159 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
161 virtual void OnStageConnection2();
164 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
166 virtual void OnStageDisconnection2();
169 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
171 virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
175 * Set the node for given bone index in the scene graph object
176 * @param[in] node The node to set
177 * @param[in] boneIdx The bone index
179 void SetBoneNode( SceneGraph::Node* node, size_t boneIdx );
182 * Helper class for connecting Nodes to the scene-graph MeshAttachment
184 class Connector : public ProxyObject::Observer
188 * Create the helper class
190 Connector( Internal::ActorPtr boneActor, size_t boneIdx, MeshAttachment& meshAttachment);
193 * Copy constructor required for vector storage
195 Connector(const Connector&);
198 * Assignment constructor required for vector storage
200 Connector& operator=(const Connector& rhs);
208 * Update the scene-graph mesh attachment with this node
212 public: // From ProxyObject::Observer
215 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
217 virtual void SceneObjectAdded( ProxyObject& proxy );
220 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
222 virtual void SceneObjectRemoved( ProxyObject& proxy );
225 * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed
227 virtual void ProxyDestroyed( ProxyObject& proxy );
230 MeshAttachment& mMeshAttachment; ///< Parent
231 Actor* mActor; ///< Raw-pointer to the actor; not owned.
232 size_t mBoneIdx; ///< Index of the bone with which this connecter is associated
234 typedef OwnerContainer< Connector* > ConnectorList;
238 const SceneGraph::MeshAttachment* mSceneObject; ///< Not owned
240 MeshAndCustomMaterial mMesh;
241 bool mAffectedByLighting;
242 ConnectorList mConnectors;
245 } // namespace Internal
249 #endif // __DALI_INTERNAL_MESH_ATTACHMENT_H__