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/modeling/model-logger.h>
27 #include <dali/public-api/modeling/bone.h>
28 #include <dali/public-api/modeling/entity.h>
29 #include <dali/public-api/modeling/material.h>
30 #include <dali/public-api/modeling/model-animation-map.h>
31 #include <dali/public-api/modeling/entity-animator-map.h>
33 #include <dali/integration-api/debug.h>
35 #include <dali/internal/event/modeling/light-impl.h>
36 #include <dali/internal/event/modeling/mesh-impl.h>
37 #include <dali/internal/event/animation/key-frames-impl.h>
38 #include <dali/internal/event/modeling/model-impl.h>
44 using Internal::MaterialIPtr;
45 using Internal::MeshIPtr;
51 void ModelLogger::WriteMeshes()
53 cout << "Meshes: " << endl;
55 for(unsigned int meshIdx = 0; meshIdx < mModel.NumberOfMeshes(); ++meshIdx)
57 const Dali::MeshData& meshData = mModel.GetMesh(meshIdx);
60 cout << "Mesh[" << meshIdx << "] NumVertices: " << meshData.GetVertexCount()
61 << " NumFaces: " << meshData.GetFaceCount()
62 << " HasTexCoords: " << (meshData.HasTextureCoords()?"T":"F")
63 << " HasNormals: " << (meshData.HasNormals()?"T":"F")
64 << " Material: " << meshData.GetMaterial().GetName() << endl
65 << " Bounding box: " << meshData.GetBoundingBoxMin() << " - " << meshData.GetBoundingBoxMax() << endl;
67 if (meshData.GetBoneCount())
69 const BoneContainer& bones = meshData.GetBones();
70 for(size_t boneIdx = 0; boneIdx < bones.size(); ++boneIdx)
72 cout << " Bones[" << boneIdx << "] " << bones.at(boneIdx).GetName() << endl;
79 // create temporary pointer to the vertices
80 const Dali::MeshData::VertexContainer& vertices = meshData.GetVertices();
81 for(unsigned int vertexIdx = 0; vertexIdx < vertices.size(); ++vertexIdx)
83 const MeshData::Vertex& vertex = vertices[vertexIdx];
84 cout << "Vertex[" << vertexIdx << "] Pos<"<<vertex.x<<","<<vertex.y<<","<<vertex.z<<">";
85 if(meshData.HasTextureCoords())
87 cout << " TexC<"<<vertex.u<<","<<vertex.v<<">";
89 if(meshData.HasNormals())
91 cout << " Normal<"<<vertex.nX<<","<<vertex.nY<<","<<vertex.nZ<<">";
94 if(meshData.HasBones())
96 cout << " BoneIndices[] = ";
97 for(size_t i=0; i<MeshData::Vertex::MAX_BONE_INFLUENCE; i++)
99 cout << (int)vertex.boneIndices[i] << ", ";
101 cout << endl << " BoneWeights[] = ";
102 for (size_t i=0; i< MeshData::Vertex::MAX_BONE_INFLUENCE; i++)
104 cout << vertex.boneWeights[i] << ", ";
111 const Dali::MeshData::FaceIndices& faces = meshData.GetFaces();
112 for(unsigned int faceIdx = 0; faceIdx < meshData.GetFaceCount(); ++faceIdx)
114 const FaceIndex* face = &(faces)[faceIdx * 3];
115 cout << "(" << face[0] <<"," << face[1] << "," << face[2] << ") ";
126 void ModelLogger::WriteMaterials()
128 cout << "Materials:" << endl;
130 for(unsigned int matIdx = 0; matIdx < mModel.NumberOfMaterials(); ++matIdx)
132 Dali::Material mat = mModel.GetMaterial(matIdx);
133 cout << "Material[" << matIdx << "] " << mat.GetName();
134 cout << " Opacity: " << mat.GetOpacity();
135 cout << " Shininess: " << mat.GetShininess();
136 cout << " Ambient: " << Debug::ColorToString(mat.GetAmbientColor());
137 cout << " Diffuse: " << Debug::ColorToString(mat.GetDiffuseColor());
138 cout << " Specular: " << Debug::ColorToString(mat.GetSpecularColor());
139 cout << " Emissive: " << Debug::ColorToString(mat.GetEmissiveColor()) << endl;
146 void ModelLogger::WriteLights()
148 cout << "Lights:" << endl;
149 for(unsigned int lightIdx = 0; lightIdx < mModel.NumberOfLights(); ++lightIdx)
151 Dali::Light light = mModel.GetLight(lightIdx);
152 cout << "Light[" << lightIdx << "] " << light.GetName()
153 << " type(" << light.GetType()
154 << ") falloff(" << light.GetFallOff().x << ", " << light.GetFallOff().y
155 << ") spotangle(" << light.GetSpotAngle().x << ", " << light.GetSpotAngle().y
156 << ") ambient(" << light.GetAmbientColor().r << ", " << light.GetAmbientColor().g << ", " << light.GetAmbientColor().b
157 << ") diffuse(" << light.GetDiffuseColor().r << ", " << light.GetDiffuseColor().g << ", " << light.GetDiffuseColor().b
158 << ") specular(" << light.GetSpecularColor().r << ", " << light.GetSpecularColor().g << ", " << light.GetSpecularColor().b
164 void ModelLogger::WriteEntity(Dali::Entity entity, int level)
168 string indent = string(level*2, ' ');
169 cout << indent << "Entity " << "Type:<";
170 switch(entity.GetType())
172 case Dali::Entity::OBJECT: cout<<"OBJECT"; break;
173 case Dali::Entity::CAMERA: cout<<"CAMERA"; break;
174 case Dali::Entity::LIGHT: cout<<"LIGHT"; break;
176 cout << "> Name: " << entity.GetName() << endl;
177 cout << indent << " Meshes(" << entity.NumberOfMeshes() << ") = [";
178 for (int i=0; i<entity.NumberOfMeshes(); i++)
180 cout << entity.GetMeshByIndex(i) << ", ";
184 cout << indent << " LowerBounds: " << Debug::Vector3ToString(entity.GetLowerBounds()) << endl;
185 cout << indent << " UpperBounds: " << Debug::Vector3ToString(entity.GetUpperBounds()) << endl;
186 cout << indent << " TransformMatrix: " << endl;
187 cout << Debug::MatrixToString(entity.GetTransformMatrix(), 3, level*2+4) << endl;
189 if(entity.HasChildren())
192 const EntityContainer& children = entity.GetChildren();
193 for(EntityConstIter iter = children.begin(); iter != children.end(); ++iter)
195 WriteEntity(*iter, level);
202 void ModelLogger::WriteAnimations()
204 cout << "Animations (:" << mModel.NumberOfAnimationMaps() << ")" << endl;
205 for(unsigned int idx = 0; idx < mModel.NumberOfAnimationMaps(); ++idx)
207 const ModelAnimationMap* animation( mModel.GetAnimationMap(idx) );
208 cout << "Animation ["<< idx << "] " << endl;
209 if( animation != NULL )
211 cout << " Duration: " << animation->duration << endl;
212 cout << " Repeats: " << animation->repeats << endl;
214 size_t animatorIdx=0;
216 for(EntityAnimatorMapIter iter = animation->animators.begin(); iter != animation->animators.end(); ++iter)
218 const EntityAnimatorMap& animator(*iter);
219 std::string entityName = animator.GetEntityName();
221 cout << " Animator ["<<animatorIdx<<"] " << entityName << " "
222 << "Duration: " << animator.GetDuration() << endl;
224 const KeyFrameVector3* positionKeyFrames;
225 GetSpecialization(GetImplementation(animator.GetPositionKeyFrames()), positionKeyFrames);
226 const KeyFrameVector3* scaleKeyFrames;
227 GetSpecialization(GetImplementation(animator.GetScaleKeyFrames()), scaleKeyFrames);
228 const KeyFrameQuaternion* rotationKeyFrames;
229 GetSpecialization(GetImplementation(animator.GetRotationKeyFrames()), rotationKeyFrames);
231 if(positionKeyFrames->GetNumberOfKeyFrames() > 0)
233 cout << " Channel: Position" << endl;
235 for(size_t kfIndex = 0; kfIndex < positionKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
240 positionKeyFrames->GetKeyFrame(kfIndex, progress, position);
241 cout << " [" << kfIndex << "] " << progress << position << endl;
245 if(scaleKeyFrames->GetNumberOfKeyFrames() > 0)
247 cout << " Channel: Scale" << endl;
248 for(size_t kfIndex = 0; kfIndex < scaleKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
252 scaleKeyFrames->GetKeyFrame(kfIndex, progress, scale);
253 cout << " [" << kfIndex << "] " << progress << scale << endl;
257 if(rotationKeyFrames->GetNumberOfKeyFrames() > 0)
259 cout << " Channel: Rotation" << endl;
260 for(size_t kfIndex = 0; kfIndex < rotationKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
264 rotationKeyFrames->GetKeyFrame(kfIndex, progress, rotation);
265 cout << " [" << kfIndex << "] " << progress << rotation << endl;
279 void ModelLogger::Write()
281 cout << "Model name : " << mModel.GetName() << endl;
285 cout << "Entities:" << endl;
286 WriteEntity(mModel.GetRootEntity(), 0);