2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/actors/mesh-actor-impl.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/internal/event/modeling/model-impl.h>
24 #include <dali/internal/event/modeling/animatable-mesh-impl.h>
25 #include <dali/internal/event/modeling/mesh-impl.h>
30 using Internal::MeshIter;
31 using Internal::MeshIPtr;
32 using Internal::MaterialIPtr;
43 return Dali::MeshActor::New();
46 TypeRegistration mType( typeid(Dali::MeshActor), typeid(Dali::RenderableActor), Create );
50 MeshActorPtr MeshActor::New()
52 MeshActorPtr actor(new MeshActor());
54 // Second-phase construction
57 // Create the attachment
58 actor->mMeshAttachment = MeshAttachment::New( *actor->mNode );
59 actor->Attach(*actor->mMeshAttachment);
60 actor->SetCullFace( Dali::CullBack );
65 MeshActorPtr MeshActor::New(Dali::Mesh mesh)
67 MeshActorPtr actor = MeshActor::New();
77 MeshActorPtr MeshActor::New(Dali::AnimatableMesh mesh)
79 MeshActorPtr actor = MeshActor::New();
90 MeshActorPtr MeshActor::New(ModelDataPtr modelData, Dali::Entity entity)
92 MeshActorPtr actor(new MeshActor());
93 // Second-phase construction
96 // Create the attachment
97 actor->mMeshAttachment = MeshAttachment::New( *actor->mNode );
98 actor->Attach(*actor->mMeshAttachment);
99 actor->SetName(entity.GetName());
100 actor->SetCullFace( Dali::CullBack );
102 DALI_ASSERT_ALWAYS(entity.NumberOfMeshes() == 1 && "Dali does not support multiple meshes per node in the model");
104 actor->SetMesh(modelData, entity.GetMeshByIndex(0)); // only use the first mesh
106 Matrix transform(entity.GetTransformMatrix());
110 transform.GetTransformComponents(position, rotation, scale);
111 actor->SetPosition(position);
112 actor->SetRotation(rotation);
113 actor->SetScale(scale);
118 MeshActor::MeshActor()
123 MeshActor::~MeshActor()
127 void MeshActor::SetMesh(Dali::Mesh mesh)
129 SetMesh( &GetImplementation(mesh) );
132 void MeshActor::SetMesh(Dali::AnimatableMesh mesh)
134 mAnimatableMeshHandle = mesh;
135 SetMesh( GetImplementation(mesh).GetMesh() );
137 SetInitialVolume(Vector3(1.0f, 1.0f, 1.0f));
140 void MeshActor::SetMesh( MeshIPtr meshPtr )
142 mMeshAttachment->SetMesh( meshPtr, meshPtr->GetResourceId(), meshPtr->GetBones(), meshPtr->GetMaterial() );
145 // Used by Internal::ModelActorFactory
146 void MeshActor::SetMesh(ModelDataPtr modelData, unsigned int meshIndex)
148 ResourceTicketPtr meshTicket = modelData->GetMeshTicket(meshIndex);
149 const Dali::MeshData& meshData = modelData->GetMesh(meshIndex);
150 Dali::Material material = meshData.GetMaterial();
151 DALI_ASSERT_ALWAYS( material && "No material found" );
152 MaterialIPtr matPtr = &GetImplementation(material);
154 mMeshAttachment->SetMesh(meshTicket, meshData.GetBones(), matPtr);
157 void MeshActor::SetMaterial(const Dali::Material material)
159 MaterialIPtr materialPtr = const_cast<Internal::Material*>(&GetImplementation(material));
160 mMeshAttachment->SetMaterial(materialPtr);
163 Dali::Material MeshActor::GetMaterial() const
165 Dali::Material material;
167 Internal::MaterialIPtr internalPtr = mMeshAttachment->GetMaterial( );
171 material = Dali::Material(internalPtr.Get());
177 void MeshActor::SetAffectedByLighting(bool affectedByLighting)
179 mMeshAttachment->SetAffectedByLighting( affectedByLighting );
182 bool MeshActor::IsAffectedByLighting()
184 return mMeshAttachment->IsAffectedByLighting();
187 void MeshActor::BindBonesToMesh(Internal::ActorPtr rootActor)
189 mMeshAttachment->BindBonesToMesh(rootActor);
192 } // namespace Internal