Mesh refactoring and modified loading from binary and saving to binary
authork.zverev <k.zverev@samsung.com>
Fri, 1 Nov 2013 15:33:19 +0000 (17:33 +0200)
committerk.zverev <k.zverev@samsung.com>
Fri, 1 Nov 2013 15:33:19 +0000 (17:33 +0200)
Change-Id: If4fdb645d6b21d62b52b9e9c3b4255b58171bc61
Signed-off-by: k.zverev <k.zverev@samsung.com>
inc/FUiAnimMesh.h
src/ui/animations/FUiAnimMesh.cpp
src/ui/animations/FUiAnimModelImporter.cpp
src/ui/animations/FUiAnim_MeshImpl.cpp
src/ui/animations/FUiAnim_ModelImporterImpl.cpp
src/ui/inc/FUiAnim_MeshImpl.h
src/ui/inc/FUiAnim_ModelImporterImpl.h

index cc38d11..d1950ca 100644 (file)
@@ -257,7 +257,7 @@ public:
     result ReserveTextureCoordinates();
     result ReserveNormals();
     result ReserveColors();
-    result SaveMesh(const Tizen::Base::String& fileName);
+    result SaveMeshToBin(const Tizen::Base::String& fileName);
 
        bool IsIndexEnabled() const;
        bool IsTextureCoordinateEnabled() const;
index 5eabbfd..486e5f2 100644 (file)
@@ -257,10 +257,10 @@ Mesh::GetIndexCount() const
 }
 
 result
-Mesh::SaveMesh(const Tizen::Base::String& fileName)
+Mesh::SaveMeshToBin(const Tizen::Base::String& fileName)
 {
        CHECK_CONSTRUCTED;
-       return __pMeshImpl->SaveMesh(fileName);
+       return __pMeshImpl->SaveMeshToBin(fileName);
 }
 
 void
index 83e7cc1..9668f00 100644 (file)
@@ -59,8 +59,7 @@ ModelImporter::LoadMeshN(MODEL_FORMAT modelFormat, const Tizen::Base::String& fi
                        pMesh = modelImporter.LoadMeshCollada(strModelName, materialId);
                }break;
                case BIN:{
-                       AppLog("ModelImporter::LoadMesh::BIN");
-                       pMesh = _ModelImporterImpl::LoadMeshBinN(strFileName, strModelName);
+                       pMesh = _ModelImporterImpl::LoadMeshFromBinaryN(strFileName, strModelName);
                }break;
        }
        return pMesh;
index 7028609..572b293 100644 (file)
@@ -110,24 +110,19 @@ _MeshImpl::AllocVertices(int count)
 {
        MESH_LOCK();
 
-    if(__pVertices)
-        return E_ALREADY_SET;
+       SysTryReturnResult(NID_UI_ANIM, __pVertices == null, E_ALREADY_SET, " Vertices have already been allocated");
+    SysTryReturnResult(NID_UI_ANIM, count > 0, E_INVALID_ARG, " Invalid argument in order to set countOfAllocatedVertex");
 
-    if(count <= 0)
-        return E_INVALID_ARG;
-
-
-    __countOfAllocatedVertex = count;
 
     __pVertices = new (std::nothrow) float[count * APPROPRIATE_COUNT_VERTICES];
+    SysTryReturnResult(NID_UI_ANIM, __pVertices != null, E_OUT_OF_MEMORY, "%s Memory allocation failed while allocating Vertices.");
+    __countOfAllocatedVertex = count;
 
-    if(!__pVertices)
-        return E_OUT_OF_MEMORY;
-
-    for(int i = 0 ; i < __countOfAllocatedVertex * APPROPRIATE_COUNT_VERTICES; i++)
+    for (int i = 0; i < __countOfAllocatedVertex * APPROPRIATE_COUNT_VERTICES; i++)
     {
         __pVertices[i] = 0.0f;
     }
+
     return E_SUCCESS;
 }
 
@@ -137,91 +132,95 @@ _MeshImpl::AllocTextureCoordinates()
 {
        MESH_LOCK();
 
-    if(__pTexCoordinates)
-        return E_ALREADY_SET;
+       SysTryReturnResult(NID_UI_ANIM, __pTexCoordinates == null, E_ALREADY_SET, " TextureCoordinates have already been allocated");
+       SysTryReturnResult(NID_UI_ANIM, __countOfAllocatedVertex > 0, E_INVALID_STATE, " Invalid argument in order to set size of TextCoordinates");
 
-    if(__countOfAllocatedVertex <= 0)
-        return E_INVALID_STATE;
+       int count = __countOfAllocatedVertex * APPROPRIATE_COUNT_TEXTCOORDINATES;
+       __pTexCoordinates = new (std::nothrow) float[count];
+       SysTryCatch(NID_UI_ANIM, __pTexCoordinates != null, , E_OUT_OF_MEMORY, "%s Memory allocation failed while allocating TextCoordinates.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-    int count = __countOfAllocatedVertex * APPROPRIATE_COUNT_TEXTCOORDINATES;
-    __pTexCoordinates = new (std::nothrow) float[count];
-    if(!__pTexCoordinates)
-        return E_OUT_OF_MEMORY;
+       for (int i = 0; i < count; i++)
+       {
+               __pTexCoordinates[i] = 0.0f;
+       }
+       return E_SUCCESS;
 
-    for(int i = 0 ; i < count ; i++)
-    {
-        __pTexCoordinates[i] = 0;
-    }
-    return E_SUCCESS;
+       CATCH:
+               __pTexCoordinates = null;
+               return E_OUT_OF_MEMORY;
 }
 
 result
 _MeshImpl::AllocNormals()
 {
        MESH_LOCK();
-    if(__pNormals)
-        return E_ALREADY_SET;
 
-    if(__countOfAllocatedVertex <= 0)
-        return E_INVALID_STATE;
+       SysTryReturnResult(NID_UI_ANIM, __pNormals == null, E_ALREADY_SET, " Normals have already been allocated");
+       SysTryReturnResult(NID_UI_ANIM, __countOfAllocatedVertex > 0, E_INVALID_STATE, " Invalid argument in order to set size of Normals");
 
-    int count = __countOfAllocatedVertex * APPROPRIATE_COUNT_NORMALS;
-    __pNormals = new (std::nothrow) float[count];
-    if(!__pNormals)
-        return E_OUT_OF_MEMORY;
+       int count = __countOfAllocatedVertex * APPROPRIATE_COUNT_NORMALS;
+       __pNormals = new (std::nothrow) float[count];
+       SysTryCatch(NID_UI_ANIM, __pNormals != null, , E_OUT_OF_MEMORY, "%s Memory allocation failed while allocating Normals.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-    for(int i = 0 ; i < count ; i++)
-    {
-        __pNormals[i] = 0;
-    }
-    return E_SUCCESS;
+       for (int i = 0; i < count; i++)
+       {
+               __pNormals[i] = 0.0f;
+       }
+       return E_SUCCESS;
+
+       CATCH:
+               __pNormals = null;
+               return E_OUT_OF_MEMORY;
 }
 
 result
 _MeshImpl::AllocColors()
 {
        MESH_LOCK();
-    if(__pColors)
-        return E_ALREADY_SET;
 
-    if(__countOfAllocatedVertex <= 0)
-        return E_INVALID_STATE;
+       SysTryReturnResult(NID_UI_ANIM, __pColors == null, E_ALREADY_SET, " Colors have already been allocated");
+       SysTryReturnResult(NID_UI_ANIM, __countOfAllocatedVertex > 0, E_INVALID_STATE, " Invalid argument in order to set size of Colors");
 
-    int count = __countOfAllocatedVertex * APPROPRIATE_COUNT_COLORS;
-    __pColors = new (std::nothrow) float[count];
-    if(!__pColors)
-        return E_OUT_OF_MEMORY;
+       int count = __countOfAllocatedVertex * APPROPRIATE_COUNT_COLORS;
+       __pColors = new (std::nothrow) float[count];
 
-    for(int i = 0 ; i < count ; i++)
-    {
-        __pColors[i] = 0;
-    }
-    return E_SUCCESS;
+       SysTryCatch(NID_UI_ANIM, __pColors != null, , E_OUT_OF_MEMORY, "%s Memory allocation failed while allocating Colors.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       for(int i = 0; i < count; i++)
+       {
+               __pColors[i] = 0.0f;
+       }
+       return E_SUCCESS;
+
+       CATCH:
+               __pColors = null;
+               return E_OUT_OF_MEMORY;
 }
 
 result
 _MeshImpl::AllocIndices(int count)
 {
        MESH_LOCK();
-    if(__pIndices)
-        return E_ALREADY_SET;
 
-    if(count <= 0)
-        return E_INVALID_ARG;
+       SysTryReturnResult(NID_UI_ANIM, __pIndices == null, E_ALREADY_SET, " Indices have already been allocated");
+       SysTryReturnResult(NID_UI_ANIM, count > 0, E_INVALID_ARG, " Invalid argument in order to set countOfAllocatedIndex");
 
+       __countOfAllocatedIndex = count;
 
-    __countOfAllocatedIndex = count;
+    __pIndices = new (std::nothrow) IndexType[count];
 
-    __pIndices = new (std::nothrow) unsigned short int[count];
-    if(!__pIndices)
-        return E_OUT_OF_MEMORY;
+       SysTryCatch(NID_UI_ANIM, __pIndices != null, , E_OUT_OF_MEMORY, "%s Memory allocation failed while allocating Indices.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-    for(int i = 0 ; i < __countOfAllocatedVertex ; i++)
-    {
-        __pIndices[i] = 0;
-    }
+       for(int i = 0; i < __countOfAllocatedIndex; i++)
+       {
+               __pIndices[i] = 0;
+       }
 
-    return E_SUCCESS;
+       return E_SUCCESS;
+
+       CATCH:
+               __pIndices = null;
+               return E_OUT_OF_MEMORY;
 }
 
 
@@ -230,123 +229,99 @@ _MeshImpl::SetVertex(int arrayIndex, const FloatPoint3& vertex)
 {
        MESH_LOCK();
 
-    if(__pVertices)
-    {
-        if ( arrayIndex > __countOfAllocatedVertex )
-        {
-            return E_OUT_OF_RANGE;
-        }
-
-        int i = arrayIndex * 3;
-
-        if ( __hasBoundingVolume && (__pMeshController == null) )
-        {
-                       __pVertices[i]   = vertex.x - __boundingVolume.GetCenter().x;   //x
-                       __pVertices[i+1] = vertex.y - __boundingVolume.GetCenter().y;   //y
-                       __pVertices[i+2] = vertex.z - __boundingVolume.GetCenter().z;   //z
-        }
-        else
-        {
-            __pVertices[i]   = vertex.x;   //x
-            __pVertices[i+1] = vertex.y;   //y
-            __pVertices[i+2] = vertex.z;   //z
-        }
-
-        __boundingVolume.Merge(vertex);
-
-
-               if(__countOfVertex <= arrayIndex )
-        {
-                       __countOfVertex = arrayIndex + 1;
-        }
-        return E_SUCCESS;
-    }
+       SysTryReturnResult(NID_UI_ANIM, __pVertices != null, E_INVALID_STATE, " Vertices haven't been allocated yet");
+       bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+       SysTryReturnResult(NID_UI_ANIM, arrayIndexState, E_OUT_OF_RANGE, " arrayIndex is big in order to SetVertex (%d, %d)", arrayIndex, __countOfAllocatedVertex);
 
-    return E_INVALID_STATE;
+       int i = arrayIndex * APPROPRIATE_COUNT_VERTICES;
+
+       __pVertices[i]   = vertex.x;// - __boundingVolume.GetCenter().x;   //x
+       __pVertices[i + 1] = vertex.y;// - __boundingVolume.GetCenter().y;   //y
+       __pVertices[i + 2] = vertex.z;// - __boundingVolume.GetCenter().z;   //z
+
+       if (__hasBoundingVolume)
+       {
+               __boundingVolume.Merge(vertex);
+       }
+
+       if (__countOfVertex <= arrayIndex)
+       {
+               __countOfVertex = arrayIndex + 1;
+       }
+       return E_SUCCESS;
 }
 
 
 result
 _MeshImpl::SetTextureCoord(int arrayIndex, const FloatPoint& textureCoord)
 {
+       result r;
        MESH_LOCK();
 
-    if(!__pTexCoordinates)
+    if(__pTexCoordinates == null)
     {
-       AllocTextureCoordinates();
+       r = AllocTextureCoordinates();
+       SysTryReturnResult(NID_UI_ANIM, r != E_OUT_OF_MEMORY, r, " Memory allocation failed due to out of memory");
     }
-    if(__pTexCoordinates)
-    {
-        if ( arrayIndex > __countOfAllocatedVertex )
-        {
-            return E_OUT_OF_RANGE;
-        }
 
-        int i = arrayIndex * 2;
+    SysTryReturnResult(NID_UI_ANIM, __pTexCoordinates, E_INVALID_STATE, " TexCoordinates haven't been allocated");
 
-        __pTexCoordinates[i] = textureCoord.x;       //x
-        __pTexCoordinates[i+1] = textureCoord.y;   //y
+    bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+    SysTryReturnResult(NID_UI_ANIM, arrayIndexState, E_OUT_OF_RANGE, " arrayIndex is big in order to set TextureCoord(%d, %d)", arrayIndex, __countOfAllocatedVertex);
 
-        return E_SUCCESS;
-    }
+       int i = arrayIndex * APPROPRIATE_COUNT_TEXTCOORDINATES;
+
+       __pTexCoordinates[i] = textureCoord.x;       //x
+       __pTexCoordinates[i + 1] = textureCoord.y;   //y
 
-    return E_INVALID_STATE;
+       return E_SUCCESS;
 }
 
 result
 _MeshImpl::SetNormal(int arrayIndex, const FloatPoint3& normal)
 {
+       result r;
        MESH_LOCK();
 
-    if(!__pNormals)
+    if(__pNormals == null)
     {
-       AllocNormals();
+       r = AllocNormals();
+       SysTryReturnResult(NID_UI_ANIM, r != E_OUT_OF_MEMORY, r, " Memory allocation failed due to out of memory");
     }
 
-    if(__pNormals)
-    {
-        if ( arrayIndex > __countOfAllocatedVertex )
-        {
-            return E_OUT_OF_RANGE;
-        }
-
-        int i = arrayIndex * 3;
+    bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+    SysTryReturnResult(NID_UI_ANIM, arrayIndexState, E_OUT_OF_RANGE, " arrayIndex is big in order to set Normal(%d, %d)", arrayIndex, __countOfAllocatedVertex);
 
-        __pNormals[i] = normal.x;       //x
-        __pNormals[i+1] = normal.y;   //y
-        __pNormals[i+2] = normal.z;   //z
+       int i = arrayIndex * APPROPRIATE_COUNT_NORMALS;
 
-        return E_SUCCESS;
-    }
+       __pNormals[i] = normal.x;       //x
+       __pNormals[i + 1] = normal.y;   //y
+       __pNormals[i + 2] = normal.z;   //z
 
-    return E_INVALID_STATE;
+    return E_SUCCESS;
 }
 
 result
 _MeshImpl::SetColor(int arrayIndex, const Color& color)
 {
+       result r;
        MESH_LOCK();
 
-    if(!__pColors)
+    if(__pColors == null)
     {
-       AllocColors();
-    }
-    if(__pColors)
-    {
-        if ( arrayIndex > __countOfAllocatedVertex )
-        {
-            return E_OUT_OF_RANGE;
-        }
-
-        int i = arrayIndex*4;
-        __pColors[i]   = (float)color.GetRed()/255.0f;
-        __pColors[i+1] = (float)color.GetGreen()/255.0f;
-        __pColors[i+2] = (float)color.GetBlue()/255.0f;
-        __pColors[i+3] = (float)color.GetAlpha()/255.0f;
-        return E_SUCCESS;
+       r = AllocColors();
+       SysTryReturnResult(NID_UI_ANIM, r != E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, " Memory allocation failed due to out of memory");
     }
 
-    return E_INVALID_STATE;
+    bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+    SysTryReturnResult(NID_UI_ANIM, arrayIndexState, E_OUT_OF_RANGE, " arrayIndex is big in order to set Color(%d, %d)", arrayIndex, __countOfAllocatedVertex);
+
+       int i = arrayIndex * APPROPRIATE_COUNT_COLORS;
+       __pColors[i]   = (float)color.GetRed() / 255.0f;
+       __pColors[i + 1] = (float)color.GetGreen() / 255.0f;
+       __pColors[i + 2] = (float)color.GetBlue() / 255.0f;
+       __pColors[i + 3] = (float)color.GetAlpha() / 255.0f;
+       return E_SUCCESS;
 }
 
 result
@@ -354,61 +329,68 @@ _MeshImpl::SetIndex(int arrayIndex, int vertexIndex)
 {
        MESH_LOCK();
 
-    if(__pIndices)
-    {
-        if ( arrayIndex > __countOfAllocatedIndex )
-        {
-            return E_OUT_OF_RANGE;
-        }
-
-        __pIndices[arrayIndex] = vertexIndex;
-
-               if(__countOfIndex <= arrayIndex )
-        {
-                       __countOfIndex = arrayIndex + 1;
-        }
-        return E_SUCCESS;
-    }
-    return E_INVALID_STATE;
+       SysTryReturnResult(NID_UI_ANIM, __pIndices != null, E_INVALID_STATE, " Indices haven't been allocated yet");
+
+       bool arrayIndexState = ((arrayIndex < __countOfAllocatedIndex) && (arrayIndex >= 0));
+       SysTryReturnResult(NID_UI_ANIM, arrayIndexState, E_OUT_OF_RANGE, " arrayIndex is big in order to set Indices(%d, %d)", arrayIndex, __countOfAllocatedIndex);
+
+       __pIndices[arrayIndex] = vertexIndex;
+
+       if(__countOfIndex <= arrayIndex)
+       {
+               __countOfIndex = arrayIndex + 1;
+       }
+
+       return E_SUCCESS;
 }
 
 FloatPoint3
 _MeshImpl::GetVertex(int arrayIndex) const
 {
-    FloatPoint3 point(0,0,0);
+    FloatPoint3 point(0.0f, 0.0f, 0.0f);
+
+    bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+
+    SysTryReturn(NID_UI_ANIM, arrayIndexState, point, E_INVALID_ARG, "%s Index is out of range(%d, %d)", GetErrorMessage(E_INVALID_ARG), arrayIndex, __countOfAllocatedVertex);
+    SysTryReturn(NID_UI_ANIM, __pVertices != null, point, E_INVALID_STATE, "%s Vertices haven't been allocated(%i, %i)",GetErrorMessage(E_INVALID_STATE), arrayIndex, __countOfAllocatedVertex );
+
+       point.x = __pVertices[arrayIndex * APPROPRIATE_COUNT_VERTICES];
+       point.y = __pVertices[arrayIndex * APPROPRIATE_COUNT_VERTICES + 1];
+       point.z = __pVertices[arrayIndex * APPROPRIATE_COUNT_VERTICES + 2];
 
-    if(__pVertices)
-    {
-        point.x = __pVertices[arrayIndex*3];
-        point.y = __pVertices[arrayIndex*3+1];
-        point.z = __pVertices[arrayIndex*3+2];
-    }
     return point;
 }
 
 FloatPoint
 _MeshImpl::GetTextureCoord(int arrayIndex) const
 {
-    FloatPoint point(0,0);
-    if(__pTexCoordinates)
-    {
-        point.x = __pTexCoordinates[arrayIndex*3];
-        point.y = __pTexCoordinates[arrayIndex*3+1];
-    }
+    FloatPoint point(0.0f, 0.0f);
+
+    bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+
+    SysTryReturn(NID_UI_ANIM, arrayIndexState, point, E_INVALID_ARG, "%s Index is out of range(%d, %d)", GetErrorMessage(E_INVALID_ARG), arrayIndex, __countOfAllocatedVertex);
+    SysTryReturn(NID_UI_ANIM, __pTexCoordinates != null, point, E_INVALID_STATE, "%s TexCoordinates haven't been allocated", GetErrorMessage(E_INVALID_STATE));
+
+       point.x = __pTexCoordinates[arrayIndex * APPROPRIATE_COUNT_TEXTCOORDINATES];
+       point.y = __pTexCoordinates[arrayIndex * APPROPRIATE_COUNT_TEXTCOORDINATES+1];
+
     return point;
 }
 
 FloatPoint3
 _MeshImpl::GetNormal(int arrayIndex) const
 {
-    FloatPoint3 point(0,0,0);
+    FloatPoint3 point(0.0f, 0.0f, 0.0f);
+
+       bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+
+    SysTryReturn(NID_UI_ANIM, arrayIndexState, point, E_INVALID_ARG, "%s Index is out of range(%d, %d)", GetErrorMessage(E_INVALID_ARG), arrayIndex, __countOfAllocatedVertex);
+    SysTryReturn(NID_UI_ANIM, __pNormals != null, point, E_INVALID_STATE, "%s Normals haven't been allocated", GetErrorMessage(E_INVALID_STATE));
+
+       point.x = __pNormals[arrayIndex * APPROPRIATE_COUNT_NORMALS];
+       point.y = __pNormals[arrayIndex * APPROPRIATE_COUNT_NORMALS + 1];
+       point.z = __pNormals[arrayIndex * APPROPRIATE_COUNT_NORMALS + 2];
 
-    if(__pNormals)
-    {
-        point.x = __pNormals[arrayIndex*3];
-        point.y = __pNormals[arrayIndex*3+1];
-        point.z = __pNormals[arrayIndex*3+2];
-    }
     return point;
 }
 
@@ -417,31 +399,34 @@ _MeshImpl::GetColor(int arrayIndex) const
 {
     Color color;
 
-    if(__pColors)
-    {
-        color.SetRed    (__pColors[arrayIndex*4]    *255.0f);
-        color.SetGreen  (__pColors[arrayIndex*4 + 1]*255.0f);
-        color.SetBlue   (__pColors[arrayIndex*4 + 2]*255.0f);
-        color.SetAlpha  (__pColors[arrayIndex*4 + 3]*255.0f);
-    }
+    bool arrayIndexState = ((arrayIndex < __countOfAllocatedVertex) && (arrayIndex >= 0));
+
+    SysTryReturn(NID_UI_ANIM, arrayIndexState, color, E_INVALID_ARG, "%s Index out of range(%d, %d)", GetErrorMessage(E_INVALID_ARG), arrayIndex, __countOfAllocatedVertex);
+    SysTryReturn(NID_UI_ANIM, __pColors != null, color, E_INVALID_STATE, "%s Colors haven't been allocated", GetErrorMessage(E_INVALID_STATE));
+
+       color.SetRed    (__pColors[arrayIndex * APPROPRIATE_COUNT_COLORS]     * 255.0f);
+       color.SetGreen  (__pColors[arrayIndex * APPROPRIATE_COUNT_COLORS + 1] * 255.0f);
+       color.SetBlue   (__pColors[arrayIndex * APPROPRIATE_COUNT_COLORS + 2] * 255.0f);
+       color.SetAlpha  (__pColors[arrayIndex * APPROPRIATE_COUNT_COLORS + 3] * 255.0f);
     return color;
 }
 
 int
 _MeshImpl::GetIndex(int arrayIndex) const
 {
-    if(__pIndices)
-    {
-        return __pIndices[arrayIndex];
-    }
-    return 0;
+       bool arrayIndexState = ((arrayIndex < __countOfAllocatedIndex) && (arrayIndex >= 0));
+
+       SysTryReturn(NID_UI_ANIM, arrayIndexState, 0, E_INVALID_ARG, "%s Index out of range(%d, %d)", GetErrorMessage(E_INVALID_ARG), arrayIndex, __countOfAllocatedIndex);
+       SysTryReturn(NID_UI_ANIM, __pIndices != null, 0, E_INVALID_STATE, "%s Indices haven't been allocated", GetErrorMessage(E_INVALID_STATE));
+
+    return __pIndices[arrayIndex];
 }
 
 result
 _MeshImpl::SetGeometryType(Mesh::GeometryType type)
 {
-
     __geoType = type;
+
     return E_SUCCESS;
 }
 
@@ -455,24 +440,30 @@ result
 _MeshImpl::AdjustBoundingVolume(bool rebuild)
 {
        MESH_LOCK();
+       result r;
 
-       if(__pVertices)
+       SysTryReturnResult(NID_UI_ANIM, __pVertices != null, E_INVALID_STATE, " Vertices haven't been allocated");
+
+       __boundingVolume.Reset();
+
+       FloatPoint3 v;
+       for (int i = 0; i < __countOfVertex; i++)
        {
-               __boundingVolume.Reset();
-
-               FloatPoint3 v;
-               for(int i = 0; i < __countOfVertex; i++)
-               {
-                       v.x = __pVertices[i * 3];
-                       v.y = __pVertices[i * 3 + 1];
-                       v.z = __pVertices[i * 3 + 2];
-                       __boundingVolume.Merge(v);
-               }
-
-               __hasBoundingVolume = true;
+               v.x = __pVertices[i * APPROPRIATE_COUNT_VERTICES];
+               v.y = __pVertices[i * APPROPRIATE_COUNT_VERTICES + 1];
+               v.z = __pVertices[i * APPROPRIATE_COUNT_VERTICES + 2];
+               r = __boundingVolume.Merge(v);
+               SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "%s Adds volume of specified BoundingVolume to this BoundingVolume is failed.", GetErrorMessage(r));
        }
 
+       __hasBoundingVolume = true;
+
     return E_SUCCESS;
+
+    CATCH:
+       __boundingVolume.Reset();
+       __hasBoundingVolume = false;
+       return r;
 }
 
 BoundingVolume&
@@ -508,7 +499,7 @@ _MeshImpl::GetBoundingVolume()
 //}
 
 Mesh*
-_MeshImpl::LoadFromBinaryN(const std::string& fileName, const std::string& modelName)
+_MeshImpl::LoadMeshFromBinaryN(const std::string& fileName, const std::string& modelName)
  {
        result r;
        int quantityReadFromFile;
@@ -524,7 +515,6 @@ _MeshImpl::LoadFromBinaryN(const std::string& fileName, const std::string& model
        SysTryCatch(NID_UI_ANIM, pMesh != null, , E_OUT_OF_MEMORY, "%s Memory allocation failed while creating Mesh.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        pMeshImpl = pMesh->__pMeshImpl;
-       AppLog("Loading Mesh");
 
        Header localCapacity;
 
@@ -584,7 +574,7 @@ _MeshImpl::LoadFromBinaryN(const std::string& fileName, const std::string& model
        {
                r = pMeshImpl->AllocIndices(pMeshImpl->__countOfAllocatedIndex);
                SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "%s. Propagating", GetErrorMessage(r));
-               intsData = pMeshImpl->__countOfAllocatedVertex;
+               intsData = pMeshImpl->__countOfAllocatedIndex;
                quantityReadFromFile += fread(&pMeshImpl->__pIndices[0], sizeof(uint16_t), intsData, pFile);
        }
 
@@ -611,16 +601,14 @@ _MeshImpl::LoadFromBinaryN(const std::string& fileName, const std::string& model
 }
 
 result
-_MeshImpl::SaveMesh(const Tizen::Base::String& fileName)
+_MeshImpl::SaveMeshToBin(const Tizen::Base::String& fileName)
 {
-       AppLog("SaveMesh debug");
        int quantityWriteToFile;
        result r;
        int32_t intsData;
 
        FILE* pFile;
        SetLastResult(E_SUCCESS);
-       //SysAssert(__pMeshImpl != null);
 
        std::wstring wStr(fileName.GetPointer());
        std::string str(wStr.begin(), wStr.end());
@@ -628,7 +616,6 @@ _MeshImpl::SaveMesh(const Tizen::Base::String& fileName)
        pFile = fopen(str.c_str(), "w");
        r = E_OPERATION_FAILED;
        SysTryReturn(NID_UI_ANIM, pFile != null, r, r, "%s Error occurred while saving Mesh to file: %s", GetErrorMessage(r), str.c_str());
-       AppLog("SaveMesh debug");
 
        Header capacity;
        capacity.SetMeshArrays(*this);
@@ -645,18 +632,14 @@ _MeshImpl::SaveMesh(const Tizen::Base::String& fileName)
        intsData = static_cast<int>(__hasBoundingVolume);
        quantityWriteToFile += fwrite(&intsData, sizeof(int32_t), 1, pFile);
 
-       AppLog("SaveMesh debug");
-
        intsData = static_cast<int>(__geoType);
        quantityWriteToFile += fwrite(&intsData, sizeof(int32_t), 1, pFile);
 
-       AppLog("SaveMesh debug");
        r = E_INVALID_DATA;
        SysTryCatch(NID_UI_ANIM, capacity.isVerticesEnabled, , r, "%s. Propagating", GetErrorMessage(r));
        intsData = (__countOfAllocatedVertex * APPROPRIATE_COUNT_VERTICES);
        quantityWriteToFile += fwrite(&__pVertices[0], sizeof(float), intsData, pFile);
 
-       AppLog("SaveMesh debug");
        if (capacity.isColorEnabled)
        {
                intsData = (__countOfAllocatedVertex * APPROPRIATE_COUNT_COLORS);
@@ -669,20 +652,18 @@ _MeshImpl::SaveMesh(const Tizen::Base::String& fileName)
                quantityWriteToFile += fwrite(&__pNormals[0], sizeof(float), intsData, pFile);
        }
 
-       AppLog("SaveMesh debug");
        if (capacity.isTextureCoordinateEnabled)
        {
                intsData = (__countOfAllocatedVertex * APPROPRIATE_COUNT_TEXTCOORDINATES);
                quantityWriteToFile += fwrite(&__pTexCoordinates[0], sizeof(float), intsData, pFile);
        }
 
-       AppLog("SaveMesh debug");
        intsData = __countOfIndex;
        quantityWriteToFile += fwrite(&intsData, sizeof(int32_t), 1, pFile);
 
        if (capacity.isIndexEnabled)
        {
-               intsData = (__countOfAllocatedVertex);
+               intsData = (__countOfAllocatedIndex);
                quantityWriteToFile += fwrite(&__pIndices[0], sizeof(uint16_t), intsData, pFile);
        }
 
@@ -691,15 +672,13 @@ _MeshImpl::SaveMesh(const Tizen::Base::String& fileName)
 
        intsData = __name.size();
        quantityWriteToFile += fwrite(&intsData, sizeof(int32_t), 1, pFile);
-       quantityWriteToFile += fwrite(__name.c_str(), sizeof(int32_t), 1, pFile);
+       quantityWriteToFile += fwrite(__name.c_str(), 1, intsData, pFile);
 
        fclose(pFile);
-       AppLog("SaveMesh debug");
        return E_SUCCESS;
 
        CATCH:
                fclose(pFile);
-               AppLog("SaveMesh debug");
                return r;
 }
 
index 135df76..64523c0 100644 (file)
@@ -534,11 +534,9 @@ _ModelImporterImpl::LoadMeshCollada(const std::string& modelName, std::string& m
 }
 
 Mesh*
-_ModelImporterImpl::LoadMeshBinN(const std::string& fileName, const std::string& modelName)
+_ModelImporterImpl::LoadMeshFromBinaryN(const std::string& fileName, const std::string& modelName)
 {
-       AppLog("LoadBin...");
-       Mesh* pMesh = _MeshImpl::LoadFromBinaryN(fileName, modelName);
-       AppLog("Return mesh!!!!");
+       Mesh* pMesh = _MeshImpl::LoadMeshFromBinaryN(fileName, modelName);
        return pMesh;
 }
 
index 7fc374d..df8efa0 100644 (file)
@@ -36,9 +36,11 @@ public:
        explicit _MeshImpl(const Mesh& mesh);
 
 public:
+       typedef unsigned short int IndexType;
+
        static _MeshImpl* GetInstance(Mesh& mesh);
        static const _MeshImpl* GetInstance(const Mesh& mesh);
-       static Mesh* LoadFromBinaryN(const std::string& fileName, const std::string& modelName);
+       static Mesh* LoadMeshFromBinaryN(const std::string& fileName, const std::string& modelName);
 
        result SetVertex(int arrayIndex, const Tizen::Graphics::FloatPoint3& point);
        result SetTextureCoord(int arrayIndex, const Tizen::Graphics::FloatPoint& textureCoord);
@@ -121,7 +123,7 @@ public:
                return __name;
        }
 
-       result SaveMesh(const Tizen::Base::String& fileName);
+       result SaveMeshToBin(const Tizen::Base::String& fileName);
 
        MeshController* CreateMeshController(VisualElement* pRootJoint, const Tizen::Graphics::FloatMatrix4& bindShapeMatrix);
 
index 4c1b602..e2065db 100644 (file)
@@ -53,7 +53,7 @@ public:
        virtual ~_ModelImporterImpl(void);
 
        Mesh* LoadMeshCollada(const std::string& modelName, std::string& materialId, ColladaIndices* colladaIndices = null);
-       static Mesh* LoadMeshBinN(const std::string& fileName, const std::string& modelName);
+       static Mesh* LoadMeshFromBinaryN(const std::string& fileName, const std::string& modelName);
 
        Material* LoadMaterial(const std::string& materialId, std::string& texureId, _ImportCollada::LibraryEffects::Effect::ShaderType& shaderType);
        std::string LoadTextureName(const std::string& imageId);