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>
22 #include <dali/public-api/modeling/bone.h>
23 #include <dali/public-api/modeling/entity.h>
24 #include <dali/public-api/modeling/material.h>
25 #include <dali/public-api/modeling/model-animation-map.h>
26 #include <dali/public-api/modeling/entity-animator-map.h>
28 #include <dali/integration-api/debug.h>
30 #include <dali/internal/event/modeling/light-impl.h>
31 #include <dali/internal/event/modeling/mesh-impl.h>
32 #include <dali/internal/event/animation/key-frames-impl.h>
33 #include <dali/internal/event/modeling/model-impl.h>
46 using Internal::MaterialIPtr;
47 using Internal::MeshIPtr;
53 void ModelLogger::WriteMeshes()
55 cout << "Meshes: " << endl;
57 for(unsigned int meshIdx = 0; meshIdx < mModel.NumberOfMeshes(); ++meshIdx)
59 const Dali::MeshData& meshData = mModel.GetMesh(meshIdx);
62 cout << "Mesh[" << meshIdx << "] NumVertices: " << meshData.GetVertexCount()
63 << " NumFaces: " << meshData.GetFaceCount()
64 << " HasTexCoords: " << (meshData.HasTextureCoords()?"T":"F")
65 << " HasNormals: " << (meshData.HasNormals()?"T":"F")
66 << " Material: " << meshData.GetMaterial().GetName() << endl
67 << " Bounding box: " << meshData.GetBoundingBoxMin() << " - " << meshData.GetBoundingBoxMax() << endl;
69 if (meshData.GetBoneCount())
71 const BoneContainer& bones = meshData.GetBones();
72 for(size_t boneIdx = 0; boneIdx < bones.size(); ++boneIdx)
74 cout << " Bones[" << boneIdx << "] " << bones.at(boneIdx).GetName() << endl;
81 // create temporary pointer to the vertices
82 const Dali::MeshData::VertexContainer& vertices = meshData.GetVertices();
83 for(unsigned int vertexIdx = 0; vertexIdx < vertices.size(); ++vertexIdx)
85 const MeshData::Vertex& vertex = vertices[vertexIdx];
86 cout << "Vertex[" << vertexIdx << "] Pos<"<<vertex.x<<","<<vertex.y<<","<<vertex.z<<">";
87 if(meshData.HasTextureCoords())
89 cout << " TexC<"<<vertex.u<<","<<vertex.v<<">";
91 if(meshData.HasNormals())
93 cout << " Normal<"<<vertex.nX<<","<<vertex.nY<<","<<vertex.nZ<<">";
96 if(meshData.HasBones())
98 cout << " BoneIndices[] = ";
99 for(size_t i=0; i<MeshData::Vertex::MAX_BONE_INFLUENCE; i++)
101 cout << (int)vertex.boneIndices[i] << ", ";
103 cout << endl << " BoneWeights[] = ";
104 for (size_t i=0; i< MeshData::Vertex::MAX_BONE_INFLUENCE; i++)
106 cout << vertex.boneWeights[i] << ", ";
113 const Dali::MeshData::FaceIndices& faces = meshData.GetFaces();
114 for(unsigned int faceIdx = 0; faceIdx < meshData.GetFaceCount(); ++faceIdx)
116 const FaceIndex* face = &(faces)[faceIdx * 3];
117 cout << "(" << face[0] <<"," << face[1] << "," << face[2] << ") ";
128 void ModelLogger::WriteMaterials()
130 cout << "Materials:" << endl;
132 for(unsigned int matIdx = 0; matIdx < mModel.NumberOfMaterials(); ++matIdx)
134 Dali::Material mat = mModel.GetMaterial(matIdx);
135 cout << "Material[" << matIdx << "] " << mat.GetName();
136 cout << " Opacity: " << mat.GetOpacity();
137 cout << " Shininess: " << mat.GetShininess();
138 cout << " Ambient: " << Debug::ColorToString(mat.GetAmbientColor());
139 cout << " Diffuse: " << Debug::ColorToString(mat.GetDiffuseColor());
140 cout << " Specular: " << Debug::ColorToString(mat.GetSpecularColor());
141 cout << " Emissive: " << Debug::ColorToString(mat.GetEmissiveColor()) << endl;
148 void ModelLogger::WriteLights()
150 cout << "Lights:" << endl;
151 for(unsigned int lightIdx = 0; lightIdx < mModel.NumberOfLights(); ++lightIdx)
153 Dali::Light light = mModel.GetLight(lightIdx);
154 cout << "Light[" << lightIdx << "] " << light.GetName()
155 << " type(" << light.GetType()
156 << ") falloff(" << light.GetFallOff().x << ", " << light.GetFallOff().y
157 << ") spotangle(" << light.GetSpotAngle().x << ", " << light.GetSpotAngle().y
158 << ") ambient(" << light.GetAmbientColor().r << ", " << light.GetAmbientColor().g << ", " << light.GetAmbientColor().b
159 << ") diffuse(" << light.GetDiffuseColor().r << ", " << light.GetDiffuseColor().g << ", " << light.GetDiffuseColor().b
160 << ") specular(" << light.GetSpecularColor().r << ", " << light.GetSpecularColor().g << ", " << light.GetSpecularColor().b
166 void ModelLogger::WriteEntity(Dali::Entity entity, int level)
170 string indent = string(level*2, ' ');
171 cout << indent << "Entity " << "Type:<";
172 switch(entity.GetType())
174 case Dali::Entity::OBJECT: cout<<"OBJECT"; break;
175 case Dali::Entity::CAMERA: cout<<"CAMERA"; break;
176 case Dali::Entity::LIGHT: cout<<"LIGHT"; break;
178 cout << "> Name: " << entity.GetName() << endl;
179 cout << indent << " Meshes(" << entity.NumberOfMeshes() << ") = [";
180 for (int i=0; i<entity.NumberOfMeshes(); i++)
182 cout << entity.GetMeshByIndex(i) << ", ";
186 cout << indent << " LowerBounds: " << Debug::Vector3ToString(entity.GetLowerBounds()) << endl;
187 cout << indent << " UpperBounds: " << Debug::Vector3ToString(entity.GetUpperBounds()) << endl;
188 cout << indent << " TransformMatrix: " << endl;
189 cout << Debug::MatrixToString(entity.GetTransformMatrix(), 3, level*2+4) << endl;
191 if(entity.HasChildren())
194 const EntityContainer& children = entity.GetChildren();
195 for(EntityConstIter iter = children.begin(); iter != children.end(); ++iter)
197 WriteEntity(*iter, level);
204 void ModelLogger::WriteAnimations()
206 cout << "Animations (:" << mModel.NumberOfAnimationMaps() << ")" << endl;
207 for(unsigned int idx = 0; idx < mModel.NumberOfAnimationMaps(); ++idx)
209 const ModelAnimationMap* animation( mModel.GetAnimationMap(idx) );
210 cout << "Animation ["<< idx << "] " << endl;
211 if( animation != NULL )
213 cout << " Duration: " << animation->duration << endl;
214 cout << " Repeats: " << animation->repeats << endl;
216 size_t animatorIdx=0;
218 for(EntityAnimatorMapIter iter = animation->animators.begin(); iter != animation->animators.end(); ++iter)
220 const EntityAnimatorMap& animator(*iter);
221 std::string entityName = animator.GetEntityName();
223 cout << " Animator ["<<animatorIdx<<"] " << entityName << " "
224 << "Duration: " << animator.GetDuration() << endl;
226 const KeyFrameVector3* positionKeyFrames;
227 GetSpecialization(GetImplementation(animator.GetPositionKeyFrames()), positionKeyFrames);
228 const KeyFrameVector3* scaleKeyFrames;
229 GetSpecialization(GetImplementation(animator.GetScaleKeyFrames()), scaleKeyFrames);
230 const KeyFrameQuaternion* rotationKeyFrames;
231 GetSpecialization(GetImplementation(animator.GetRotationKeyFrames()), rotationKeyFrames);
233 if(positionKeyFrames->GetNumberOfKeyFrames() > 0)
235 cout << " Channel: Position" << endl;
237 for(size_t kfIndex = 0; kfIndex < positionKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
242 positionKeyFrames->GetKeyFrame(kfIndex, progress, position);
243 cout << " [" << kfIndex << "] " << progress << position << endl;
247 if(scaleKeyFrames->GetNumberOfKeyFrames() > 0)
249 cout << " Channel: Scale" << endl;
250 for(size_t kfIndex = 0; kfIndex < scaleKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
254 scaleKeyFrames->GetKeyFrame(kfIndex, progress, scale);
255 cout << " [" << kfIndex << "] " << progress << scale << endl;
259 if(rotationKeyFrames->GetNumberOfKeyFrames() > 0)
261 cout << " Channel: Rotation" << endl;
262 for(size_t kfIndex = 0; kfIndex < rotationKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
266 rotationKeyFrames->GetKeyFrame(kfIndex, progress, rotation);
267 cout << " [" << kfIndex << "] " << progress << rotation << endl;
281 void ModelLogger::Write()
283 cout << "Model name : " << mModel.GetName() << endl;
287 cout << "Entities:" << endl;
288 WriteEntity(mModel.GetRootEntity(), 0);