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