51880248e8c92b0cdb33e709901625cea5eded9b
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / mesh-actor-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/actors/mesh-actor-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/internal/event/modeling/animatable-mesh-impl.h>
24 #include <dali/internal/event/modeling/mesh-impl.h>
25
26 namespace Dali
27 {
28
29 using Internal::MeshIter;
30 using Internal::MeshIPtr;
31 using Internal::MaterialIPtr;
32
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 BaseHandle Create()
40 {
41   return Dali::MeshActor::New();
42 }
43
44 TypeRegistration mType( typeid(Dali::MeshActor), typeid(Dali::RenderableActor), Create );
45
46 }
47
48 MeshActorPtr MeshActor::New()
49 {
50   MeshActorPtr actor(new MeshActor());
51
52   // Second-phase construction
53   actor->Initialize();
54
55   // Create the attachment
56   actor->mMeshAttachment = MeshAttachment::New( *actor->mStage, *actor->mNode );
57   actor->Attach(*actor->mMeshAttachment);
58   actor->SetCullFace( Dali::CullBack );
59
60   return actor;
61 }
62
63 MeshActorPtr MeshActor::New(Dali::Mesh mesh)
64 {
65   MeshActorPtr actor = MeshActor::New();
66
67   if(actor)
68   {
69     actor->SetMesh(mesh);
70   }
71
72   return actor;
73 }
74
75 MeshActorPtr MeshActor::New(Dali::AnimatableMesh mesh)
76 {
77   MeshActorPtr actor = MeshActor::New();
78
79   if(actor)
80   {
81     actor->SetMesh(mesh);
82   }
83
84   return actor;
85 }
86
87 MeshActor::MeshActor()
88 : RenderableActor()
89 {
90 }
91
92 MeshActor::~MeshActor()
93 {
94 }
95
96 void MeshActor::SetMesh(Dali::Mesh mesh)
97 {
98   SetMesh( &GetImplementation(mesh) );
99 }
100
101 void MeshActor::SetMesh(Dali::AnimatableMesh mesh)
102 {
103   mAnimatableMeshHandle = mesh;
104   SetMesh( GetImplementation(mesh).GetMesh() );
105
106   SetInitialVolume(Vector3(1.0f, 1.0f, 1.0f));
107 }
108
109 void MeshActor::SetMesh( MeshIPtr meshPtr )
110 {
111   mMeshAttachment->SetMesh( meshPtr, meshPtr->GetResourceId(), meshPtr->GetBones(),  meshPtr->GetMaterial() );
112 }
113
114 void MeshActor::SetMaterial(const Dali::Material material)
115 {
116   MaterialIPtr materialPtr = const_cast<Internal::Material*>(&GetImplementation(material));
117   mMeshAttachment->SetMaterial(materialPtr);
118 }
119
120 Dali::Material MeshActor::GetMaterial() const
121 {
122   Dali::Material material;
123
124   Internal::MaterialIPtr internalPtr = mMeshAttachment->GetMaterial( );
125
126   if(internalPtr)
127   {
128     material = Dali::Material(internalPtr.Get());
129   }
130
131   return material;
132 }
133
134 void MeshActor::BindBonesToMesh(Internal::ActorPtr rootActor)
135 {
136   mMeshAttachment->BindBonesToMesh(rootActor);
137 }
138
139 } // namespace Internal
140
141 } // namespace Dali