Merge "Combine Internal::ProxyObject & Internal::Object" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / modeling / model-logger.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/modeling/model-logger.h>
20
21 // INTERNAL INCLUDES
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>
27
28 #include <dali/integration-api/debug.h>
29
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>
34
35 // EXTERNAL INCLUDES
36 #include <iostream>
37 #include <sstream>
38 #include <iomanip>
39
40 using std::cout;
41 using std::endl;
42 using std::string;
43
44 namespace Dali
45 {
46 using Internal::MaterialIPtr;
47 using Internal::MeshIPtr;
48 using Dali::MeshData;
49
50 namespace Internal
51 {
52
53 void ModelLogger::WriteMeshes()
54 {
55   cout << "Meshes: " << endl;
56
57   for(unsigned int meshIdx = 0; meshIdx < mModel.NumberOfMeshes(); ++meshIdx)
58   {
59     const Dali::MeshData& meshData = mModel.GetMesh(meshIdx);
60
61     cout << endl;
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;
68
69     if (meshData.GetBoneCount())
70     {
71       const BoneContainer& bones = meshData.GetBones();
72       for(size_t boneIdx = 0; boneIdx < bones.size(); ++boneIdx)
73       {
74         cout << "   Bones[" << boneIdx << "] " << bones.at(boneIdx).GetName() << endl;
75       }
76     }
77
78
79     if(mWriteVertices)
80     {
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)
84       {
85         const MeshData::Vertex& vertex = vertices[vertexIdx];
86         cout << "Vertex[" << vertexIdx << "] Pos<"<<vertex.x<<","<<vertex.y<<","<<vertex.z<<">";
87         if(meshData.HasTextureCoords())
88         {
89           cout << " TexC<"<<vertex.u<<","<<vertex.v<<">";
90         }
91         if(meshData.HasNormals())
92         {
93           cout << " Normal<"<<vertex.nX<<","<<vertex.nY<<","<<vertex.nZ<<">";
94         }
95         cout << endl;
96         if(meshData.HasBones())
97         {
98           cout << "    BoneIndices[] = ";
99           for(size_t i=0; i<MeshData::Vertex::MAX_BONE_INFLUENCE; i++)
100           {
101             cout << (int)vertex.boneIndices[i] << ", ";
102           }
103           cout << endl << "    BoneWeights[] = ";
104           for (size_t i=0; i< MeshData::Vertex::MAX_BONE_INFLUENCE; i++)
105           {
106             cout << vertex.boneWeights[i] << ", ";
107           }
108           cout << endl;
109         }
110       }
111       cout << endl;
112
113       const Dali::MeshData::FaceIndices& faces = meshData.GetFaces();
114       for(unsigned int faceIdx = 0; faceIdx < meshData.GetFaceCount(); ++faceIdx)
115       {
116         const FaceIndex* face = &(faces)[faceIdx * 3];
117         cout << "(" << face[0] <<"," << face[1] << "," << face[2] << ") ";
118         cout << endl;
119       }
120
121       cout << endl;
122     }
123
124   }
125   cout << endl;
126 }
127
128 void ModelLogger::WriteMaterials()
129 {
130   cout << "Materials:" << endl;
131
132   for(unsigned int matIdx = 0; matIdx < mModel.NumberOfMaterials(); ++matIdx)
133   {
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;
142
143     // TODO: Add
144   }
145   cout << endl;
146 }
147
148 void ModelLogger::WriteLights()
149 {
150   cout << "Lights:" << endl;
151   for(unsigned int lightIdx = 0; lightIdx < mModel.NumberOfLights(); ++lightIdx)
152   {
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
161          << ")" << endl;
162   }
163   cout << endl;
164 }
165
166 void ModelLogger::WriteEntity(Dali::Entity entity, int level)
167 {
168   if (entity)
169   {
170     string indent = string(level*2, ' ');
171     cout << indent << "Entity " << "Type:<";
172     switch(entity.GetType())
173     {
174       case Dali::Entity::OBJECT: cout<<"OBJECT"; break;
175       case Dali::Entity::CAMERA: cout<<"CAMERA"; break;
176       case Dali::Entity::LIGHT:  cout<<"LIGHT";  break;
177     }
178     cout << "> Name: " << entity.GetName() << endl;
179     cout << indent << "  Meshes(" << entity.NumberOfMeshes() << ") = [";
180     for (int i=0; i<entity.NumberOfMeshes(); i++)
181     {
182       cout << entity.GetMeshByIndex(i) << ", ";
183     }
184     cout << "]" << endl;
185
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;
190
191     if(entity.HasChildren())
192     {
193       ++level;
194       const EntityContainer& children = entity.GetChildren();
195       for(EntityConstIter iter = children.begin(); iter != children.end(); ++iter)
196       {
197         WriteEntity(*iter, level);
198       }
199     }
200   }
201   cout << endl;
202 }
203
204 void ModelLogger::WriteAnimations()
205 {
206   cout << "Animations (:" << mModel.NumberOfAnimationMaps() << ")" << endl;
207   for(unsigned int idx = 0; idx < mModel.NumberOfAnimationMaps(); ++idx)
208   {
209     const ModelAnimationMap* animation( mModel.GetAnimationMap(idx) );
210     cout << "Animation ["<< idx << "] " << endl;
211     if( animation != NULL )
212     {
213       cout << "  Duration:  " << animation->duration << endl;
214       cout << "  Repeats:   " << animation->repeats << endl;
215
216       size_t animatorIdx=0;
217
218       for(EntityAnimatorMapIter iter = animation->animators.begin(); iter != animation->animators.end(); ++iter)
219       {
220         const EntityAnimatorMap& animator(*iter);
221         std::string entityName = animator.GetEntityName();
222
223         cout << "  Animator ["<<animatorIdx<<"] " << entityName << "  "
224              << "Duration: " << animator.GetDuration() << endl;
225
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);
232
233         if(positionKeyFrames->GetNumberOfKeyFrames() > 0)
234         {
235           cout << "    Channel: Position" << endl;
236
237           for(size_t kfIndex = 0; kfIndex < positionKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
238           {
239             float progress;
240             Vector3 position;
241
242             positionKeyFrames->GetKeyFrame(kfIndex, progress, position);
243             cout << "  [" << kfIndex << "] " << progress << position << endl;
244           }
245         }
246
247         if(scaleKeyFrames->GetNumberOfKeyFrames() > 0)
248         {
249           cout << "    Channel: Scale" << endl;
250           for(size_t kfIndex = 0; kfIndex < scaleKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
251           {
252             float progress;
253             Vector3 scale;
254             scaleKeyFrames->GetKeyFrame(kfIndex, progress, scale);
255             cout << "  [" << kfIndex << "] " << progress << scale << endl;
256           }
257         }
258
259         if(rotationKeyFrames->GetNumberOfKeyFrames() > 0)
260         {
261           cout << "    Channel: Rotation" << endl;
262           for(size_t kfIndex = 0; kfIndex < rotationKeyFrames->GetNumberOfKeyFrames(); kfIndex++)
263           {
264             float progress;
265             Quaternion rotation;
266             rotationKeyFrames->GetKeyFrame(kfIndex, progress, rotation);
267             cout << "  [" << kfIndex << "] " << progress << rotation << endl;
268           }
269         }
270       }
271     }
272     else
273     {
274       cout << "Not found";
275     }
276   }
277   cout << endl;
278 }
279
280
281 void ModelLogger::Write()
282 {
283   cout << "Model name : " << mModel.GetName() << endl;
284   WriteMeshes();
285   WriteMaterials();
286   WriteLights();
287   cout << "Entities:" << endl;
288   WriteEntity(mModel.GetRootEntity(), 0);
289   WriteAnimations();
290 }
291
292
293 } // Internal
294 } // Dali