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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/geometry/mesh.h>
23 #include <dali/public-api/modeling/material.h>
24 #include <dali/internal/common/owner-container.h>
25 #include <dali/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
27 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
28 #include <dali/internal/event/modeling/mesh-impl.h>
29 #include <dali/internal/event/modeling/material-impl.h>
30 #include <dali/internal/event/resources/resource-ticket.h>
31 #include <dali/internal/event/common/proxy-object.h>
45 typedef std::vector<std::string> BoneNames;
46 typedef BoneNames::const_iterator BoneNamesIter;
49 * An attachment for rendering a 3D mesh with a material.
51 class MeshAttachment : public RenderableAttachment
55 struct MeshAndCustomMaterial
57 Internal::MeshIPtr mMesh;
58 Internal::MaterialIPtr mMaterial;
59 Internal::MaterialIPtr mCustomMaterial;
64 * Create an initialised MeshAttachment.
65 * @param[in] parentNode The node to attach a scene-object to.
66 * This will not be displayed until a mesh is added with SetMesh().
67 * @return A handle to a newly allocated Dali resource.
69 static MeshAttachmentPtr New( const SceneGraph::Node& parentNode );
72 * Set the mesh to be rendererd by this attachment
73 * @param[in] meshPtr A mesh impl (may be null)
74 * @param[in] meshId The resource id of the mesh
75 * @param[in] bones Container of bones for this mesh
76 * @param[in] material The material
78 void SetMesh( const MeshIPtr meshPtr,
80 const BoneContainer& bones,
81 const MaterialIPtr material );
84 * Add a mesh to the collection of meshes being rendered by this attachment
85 * @param [in] meshResource A mesh resource
86 * @param[in] bones Container of bones for this mesh
87 * @param [in] material Material
89 void SetMesh( const ResourceTicketPtr meshResource,
90 const BoneContainer& bones,
91 const MaterialIPtr material );
94 * Set the material of the mesh
95 * @param[in] materialPtr - a custom material to apply to this mesh
97 void SetMaterial( Internal::MaterialIPtr materialPtr );
100 * Get the material of the mesh
101 * @return The internal material pointer
103 Internal::MaterialIPtr GetMaterial( ) const;
106 * Disconnect any connected material from the mesh
108 void DisconnectMaterial( );
111 * Set whether this mesh actor should be affected by lights in the
112 * scene. If it set to false, then the mesh will be unaffected by
113 * lighting, and will be evenly lit without any shading.
114 * This property is not inherited.
115 * @param[in] affectedByLighting Whether the actor should be lit by the scene lighting.
117 void SetAffectedByLighting( bool affectedByLighting );
120 * @return true if the actor is lit by the scene, or false if evenly lit.
122 bool IsAffectedByLighting();
125 * Search the actor tree for all named bones in the mesh and connect them.
126 * @param[in] rootActor - the root actor of the actor tree.
128 void BindBonesToMesh( Internal::ActorPtr rootActor );
131 * Connects a boneActor to the mesh (allows the mesh renderer to do
132 * skeletal animation by calculating the actor transforms)
133 * @param[in] boneActor - the actor containing the bone's current position
134 * @param[in] boneIdx - the index of the bone in this mesh
135 * @param[in] boneCount - the bone count
137 void ConnectBoneActor( Internal::ActorPtr boneActor, size_t boneIdx, size_t boneCount );
139 const MeshAndCustomMaterial& GetMesh() const
147 * A reference counted object may only be deleted by calling Unreference()
149 virtual ~MeshAttachment();
154 * First stage construction of a MeshAttachment.
155 * @param[in] stage Used to send messages to scene-graph.
157 MeshAttachment( Stage& stage );
160 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
162 virtual void OnStageConnection2();
165 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
167 virtual void OnStageDisconnection2();
170 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
172 virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
176 * Set the node for given bone index in the scene graph object
177 * @param[in] node The node to set
178 * @param[in] boneIdx The bone index
180 void SetBoneNode( SceneGraph::Node* node, size_t boneIdx );
183 * Helper class for connecting Nodes to the scene-graph MeshAttachment
185 class Connector : public ProxyObject::Observer
189 * Create the helper class
191 Connector( Internal::ActorPtr boneActor, size_t boneIdx, MeshAttachment& meshAttachment);
194 * Copy constructor required for vector storage
196 Connector(const Connector&);
199 * Assignment constructor required for vector storage
201 Connector& operator=(const Connector& rhs);
209 * Update the scene-graph mesh attachment with this node
213 public: // From ProxyObject::Observer
216 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
218 virtual void SceneObjectAdded( ProxyObject& proxy );
221 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded
223 virtual void SceneObjectRemoved( ProxyObject& proxy );
226 * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed
228 virtual void ProxyDestroyed( ProxyObject& proxy );
231 MeshAttachment& mMeshAttachment; ///< Parent
232 Actor* mActor; ///< Raw-pointer to the actor; not owned.
233 size_t mBoneIdx; ///< Index of the bone with which this connecter is associated
235 typedef OwnerContainer< Connector* > ConnectorList;
239 const SceneGraph::MeshAttachment* mSceneObject; ///< Not owned
241 MeshAndCustomMaterial mMesh;
242 bool mAffectedByLighting;
243 ConnectorList mConnectors;
246 } // namespace Internal
250 #endif // __DALI_INTERNAL_MESH_ATTACHMENT_H__