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->mStage, *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 = MeshActor::New();
94 actor->SetName(entity.GetName());
96 DALI_ASSERT_ALWAYS(entity.NumberOfMeshes() == 1 && "Dali does not support multiple meshes per node in the model");
98 actor->SetMesh(modelData, entity.GetMeshByIndex(0)); // only use the first mesh
100 Matrix transform(entity.GetTransformMatrix());
104 transform.GetTransformComponents(position, rotation, scale);
105 actor->SetPosition(position);
106 actor->SetRotation(rotation);
107 actor->SetScale(scale);
112 MeshActor::MeshActor()
117 MeshActor::~MeshActor()
121 void MeshActor::SetMesh(Dali::Mesh mesh)
123 SetMesh( &GetImplementation(mesh) );
126 void MeshActor::SetMesh(Dali::AnimatableMesh mesh)
128 mAnimatableMeshHandle = mesh;
129 SetMesh( GetImplementation(mesh).GetMesh() );
131 SetInitialVolume(Vector3(1.0f, 1.0f, 1.0f));
134 void MeshActor::SetMesh( MeshIPtr meshPtr )
136 mMeshAttachment->SetMesh( meshPtr, meshPtr->GetResourceId(), meshPtr->GetBones(), meshPtr->GetMaterial() );
139 // Used by Internal::ModelActorFactory
140 void MeshActor::SetMesh(ModelDataPtr modelData, unsigned int meshIndex)
142 ResourceTicketPtr meshTicket = modelData->GetMeshTicket(meshIndex);
143 const Dali::MeshData& meshData = modelData->GetMesh(meshIndex);
144 Dali::Material material = meshData.GetMaterial();
145 DALI_ASSERT_ALWAYS( material && "No material found" );
146 MaterialIPtr matPtr = &GetImplementation(material);
148 mMeshAttachment->SetMesh(meshTicket, meshData.GetBones(), matPtr);
151 void MeshActor::SetMaterial(const Dali::Material material)
153 MaterialIPtr materialPtr = const_cast<Internal::Material*>(&GetImplementation(material));
154 mMeshAttachment->SetMaterial(materialPtr);
157 Dali::Material MeshActor::GetMaterial() const
159 Dali::Material material;
161 Internal::MaterialIPtr internalPtr = mMeshAttachment->GetMaterial( );
165 material = Dali::Material(internalPtr.Get());
171 void MeshActor::SetAffectedByLighting(bool affectedByLighting)
173 mMeshAttachment->SetAffectedByLighting( affectedByLighting );
176 bool MeshActor::IsAffectedByLighting()
178 return mMeshAttachment->IsAffectedByLighting();
181 void MeshActor::BindBonesToMesh(Internal::ActorPtr rootActor)
183 mMeshAttachment->BindBonesToMesh(rootActor);
186 } // namespace Internal