Blender Game Engine: poly and vertex listing

Hi,

I need to list all polygons and all vertex of a mesh in Blender Game Engine to construct a tree structure and calculate the bounding box.

I use the following function: sometimes I receive wrong result, specially with hi-poly mesh, like a max poly count limit.
At the end I get wrong bounding box coordinates.

Is that function correct?

Thank you,
Rickyx


def getBgeObjectData(obj):
    """ This functions retrieve an array of [polyIndex][vertexes] of an object """
    """ https://www.blender.org/api/blender_python_api_2_68_release/bge.types.KX_MeshProxy.html """

    tris = []
    for mesh in obj.meshes:

        countme = 0
        for polyIndex in range(mesh.numPolygons):
            countme += 1

            polygon = mesh.getPolygon(polyIndex)
            matIndex = polygon.getMaterialIndex()

            vertsPosition = []

            count = 0
            for polyVertIndex in range(polygon.getNumVertex()):
                count += 1

                meshVertIndex = polygon.getVertexIndex(polyVertIndex)

                #print(matIndex, meshVertIndex)
                vertex = mesh.getVertex(matIndex, meshVertIndex)

                #print( "Count:", countme, " Poly:", count, " MatIndex:", matIndex, " MeshVertIndex:", meshVertIndex, " ", vertex.XYZ)

                vertexPosition = vertex.XYZ
                vertsPosition.append(vertexPosition)

            #print(vertsPosition)
            tris.append(vertsPosition)
    print( "CountPoly:", countme )
    return tris