2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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
8 // http://floralicense.org/license/
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.
18 #include <dali/internal/event/actors/mesh-actor-impl.h>
21 #include <dali/public-api/object/type-registry.h>
22 #include <dali/internal/event/modeling/model-impl.h>
23 #include <dali/internal/event/modeling/animatable-mesh-impl.h>
24 #include <dali/internal/event/modeling/mesh-impl.h>
29 using Internal::MeshIter;
30 using Internal::MeshIPtr;
31 using Internal::MaterialIPtr;
42 return Dali::MeshActor::New();
45 TypeRegistration mType( typeid(Dali::MeshActor), typeid(Dali::RenderableActor), Create );
49 MeshActorPtr MeshActor::New()
51 MeshActorPtr actor(new MeshActor());
53 // Second-phase construction
56 // Create the attachment
57 actor->mMeshAttachment = MeshAttachment::New( *actor->mNode );
58 actor->Attach(*actor->mMeshAttachment);
59 actor->SetCullFace( Dali::CullBack );
64 MeshActorPtr MeshActor::New(Dali::Mesh mesh)
66 MeshActorPtr actor = MeshActor::New();
76 MeshActorPtr MeshActor::New(Dali::AnimatableMesh mesh)
78 MeshActorPtr actor = MeshActor::New();
89 MeshActorPtr MeshActor::New(ModelDataPtr modelData, Dali::Entity entity)
91 MeshActorPtr actor(new MeshActor());
92 // Second-phase construction
95 // Create the attachment
96 actor->mMeshAttachment = MeshAttachment::New( *actor->mNode );
97 actor->Attach(*actor->mMeshAttachment);
98 actor->SetName(entity.GetName());
99 actor->SetCullFace( Dali::CullBack );
101 DALI_ASSERT_ALWAYS(entity.NumberOfMeshes() == 1 && "Dali does not support multiple meshes per node in the model");
103 actor->SetMesh(modelData, entity.GetMeshByIndex(0)); // only use the first mesh
105 Matrix transform(entity.GetTransformMatrix());
109 transform.GetTransformComponents(position, rotation, scale);
110 actor->SetPosition(position);
111 actor->SetRotation(rotation);
112 actor->SetScale(scale);
117 MeshActor::MeshActor()
122 MeshActor::~MeshActor()
126 void MeshActor::SetMesh(Dali::Mesh mesh)
128 SetMesh( &GetImplementation(mesh) );
131 void MeshActor::SetMesh(Dali::AnimatableMesh mesh)
133 SetMesh( GetImplementation(mesh).GetMesh() );
135 SetInitialVolume(Vector3(1.0f, 1.0f, 1.0f));
138 void MeshActor::SetMesh( MeshIPtr meshPtr )
140 mMeshAttachment->SetMesh( meshPtr, meshPtr->GetResourceId(), meshPtr->GetBones(), meshPtr->GetMaterial() );
143 // Used by Internal::ModelActorFactory
144 void MeshActor::SetMesh(ModelDataPtr modelData, unsigned int meshIndex)
146 ResourceTicketPtr meshTicket = modelData->GetMeshTicket(meshIndex);
147 const Dali::MeshData& meshData = modelData->GetMesh(meshIndex);
148 Dali::Material material = meshData.GetMaterial();
149 DALI_ASSERT_ALWAYS( material && "No material found" );
150 MaterialIPtr matPtr = &GetImplementation(material);
152 mMeshAttachment->SetMesh(meshTicket, meshData.GetBones(), matPtr);
155 void MeshActor::SetMaterial(const Dali::Material material)
157 MaterialIPtr materialPtr = const_cast<Internal::Material*>(&GetImplementation(material));
158 mMeshAttachment->SetMaterial(materialPtr);
161 Dali::Material MeshActor::GetMaterial() const
163 Dali::Material material;
165 Internal::MaterialIPtr internalPtr = mMeshAttachment->GetMaterial( );
169 material = Dali::Material(internalPtr.Get());
175 void MeshActor::SetAffectedByLighting(bool affectedByLighting)
177 mMeshAttachment->SetAffectedByLighting( affectedByLighting );
180 bool MeshActor::IsAffectedByLighting()
182 return mMeshAttachment->IsAffectedByLighting();
185 void MeshActor::BindBonesToMesh(Internal::ActorPtr rootActor)
187 mMeshAttachment->BindBonesToMesh(rootActor);
190 } // namespace Internal