Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / public-api / actors / mesh-actor.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/public-api/actors/mesh-actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/event/actors/mesh-actor-impl.h>
24 #include <dali/internal/event/modeling/mesh-impl.h>
25 #include <dali/internal/event/modeling/animatable-mesh-impl.h>
26
27 namespace Dali
28 {
29
30 MeshActor::MeshActor()
31 {
32 }
33
34 MeshActor MeshActor::New()
35 {
36   Internal::MeshActorPtr internal = Internal::MeshActor::New();
37   return MeshActor(internal.Get());
38 }
39
40 MeshActor MeshActor::New( Mesh mesh)
41 {
42   Internal::MeshActorPtr internal = Internal::MeshActor::New(mesh);
43   return MeshActor(internal.Get());
44 }
45
46 MeshActor MeshActor::New( AnimatableMesh mesh)
47 {
48   Internal::MeshActorPtr internal = Internal::MeshActor::New(mesh);
49   return MeshActor(internal.Get());
50 }
51
52 MeshActor MeshActor::DownCast( BaseHandle handle )
53 {
54   return MeshActor( dynamic_cast<Dali::Internal::MeshActor*>(handle.GetObjectPtr()) );
55 }
56
57 MeshActor::~MeshActor()
58 {
59 }
60
61 MeshActor::MeshActor(const MeshActor& copy)
62 : RenderableActor(copy)
63 {
64 }
65
66 MeshActor& MeshActor::operator=(const MeshActor& rhs)
67 {
68   BaseHandle::operator=(rhs);
69   return *this;
70 }
71
72 void MeshActor::SetMaterial(
73   Actor               actor,
74   const std::string&  actorName,
75   Material            material)
76 {
77   Actor child = actor.FindChildByName(actorName);
78   if(child)
79   {
80     Internal::MeshActor* meshActor = dynamic_cast<Internal::MeshActor*>(&GetImplementation(child));
81     if(meshActor)
82     {
83       meshActor->SetMaterial(material);
84     }
85   }
86   else
87   {
88     DALI_LOG_ERROR("MeshActor::SetMaterial() - Can't find mesh actor\n");
89   }
90 }
91
92 void MeshActor::SetMaterial(Material material)
93 {
94   GetImplementation(*this).SetMaterial(material);
95 }
96
97 Material MeshActor::GetMaterial() const
98 {
99   return GetImplementation(*this).GetMaterial();
100 }
101
102 void MeshActor::BindBonesToMesh(Actor rootActor)
103 {
104   Internal::ActorPtr root(&GetImplementation(rootActor));
105
106   GetImplementation(*this).BindBonesToMesh(root);
107 }
108
109 MeshActor::MeshActor(Internal::MeshActor* internal)
110   : RenderableActor(internal)
111 {
112 }
113
114 } // namespace Dali