Removed model loading and lighting
[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
37 namespace
38 {
39
40 BaseHandle Create()
41 {
42   return Dali::MeshActor::New();
43 }
44
45 TypeRegistration mType( typeid(Dali::MeshActor), typeid(Dali::RenderableActor), Create );
46
47 }
48
49 MeshActorPtr MeshActor::New()
50 {
51   MeshActorPtr actor(new MeshActor());
52
53   // Second-phase construction
54   actor->Initialize();
55
56   // Create the attachment
57   actor->mMeshAttachment = MeshAttachment::New( *actor->mStage, *actor->mNode );
58   actor->Attach(*actor->mMeshAttachment);
59   actor->SetCullFace( Dali::CullBack );
60
61   return actor;
62 }
63
64 MeshActorPtr MeshActor::New(Dali::Mesh mesh)
65 {
66   MeshActorPtr actor = MeshActor::New();
67
68   if(actor)
69   {
70     actor->SetMesh(mesh);
71   }
72
73   return actor;
74 }
75
76 MeshActorPtr MeshActor::New(Dali::AnimatableMesh mesh)
77 {
78   MeshActorPtr actor = MeshActor::New();
79
80   if(actor)
81   {
82     actor->SetMesh(mesh);
83   }
84
85   return actor;
86 }
87
88 MeshActor::MeshActor()
89 : RenderableActor()
90 {
91 }
92
93 MeshActor::~MeshActor()
94 {
95 }
96
97 void MeshActor::SetMesh(Dali::Mesh mesh)
98 {
99   SetMesh( &GetImplementation(mesh) );
100 }
101
102 void MeshActor::SetMesh(Dali::AnimatableMesh mesh)
103 {
104   mAnimatableMeshHandle = mesh;
105   SetMesh( GetImplementation(mesh).GetMesh() );
106
107   SetInitialVolume(Vector3(1.0f, 1.0f, 1.0f));
108 }
109
110 void MeshActor::SetMesh( MeshIPtr meshPtr )
111 {
112   mMeshAttachment->SetMesh( meshPtr, meshPtr->GetResourceId(), meshPtr->GetBones(),  meshPtr->GetMaterial() );
113 }
114
115 void MeshActor::SetMaterial(const Dali::Material material)
116 {
117   MaterialIPtr materialPtr = const_cast<Internal::Material*>(&GetImplementation(material));
118   mMeshAttachment->SetMaterial(materialPtr);
119 }
120
121 Dali::Material MeshActor::GetMaterial() const
122 {
123   Dali::Material material;
124
125   Internal::MaterialIPtr internalPtr = mMeshAttachment->GetMaterial( );
126
127   if(internalPtr)
128   {
129     material = Dali::Material(internalPtr.Get());
130   }
131
132   return material;
133 }
134
135 void MeshActor::BindBonesToMesh(Internal::ActorPtr rootActor)
136 {
137   mMeshAttachment->BindBonesToMesh(rootActor);
138 }
139
140 } // namespace Internal
141
142 } // namespace Dali