# Path: PyOpenGLng/HighLevelApi/PrimitiveVertexArray.py
# class TriangleVertexArray(GlVertexArrayObject):
# 
#     """ Base class to draw primitives as triangles. """
# 
#     # Fixme: 3d
# 
#     ##############################################
# 
#     def __init__(self, items=None):
# 
#         super(TriangleVertexArray, self).__init__()
# 
#         self._number_of_items = 0
#         self._positions_buffer = GlArrayBuffer()
#         self._normals_buffer = GlArrayBuffer()
#         self._colours_buffer = GlArrayBuffer()
# 
#         if items is not None:
#             self.set(*items)
# 
#     ##############################################
# 
#     def set(self, positions, normals, colours):
# 
#         """ Set the vertex array from an iterable of triangles. """
# 
#         self._number_of_items = positions.shape[0]
# 
#         # Fixme:
#         #  - set from high level primitive: slow
#         #  - set from Numpy array: fast but check for mistake
# 
#         # vertex = np.zeros((self._number_of_objects, 3), dtype='f') # dtype=np.float
# 
#         self._positions_buffer.set(positions)
#         self._normals_buffer.set(normals)
#         self._colours_buffer.set(colours)
# 
#     ##############################################
# 
#     def bind_to_shader(self, shader_program_interface):
# 
#         """ Bind the vertex array to the shader program interface attribute.
#         """
# 
#         # Fixme: we cannot reuse the vbo
# 
#         self.bind()
#         shader_program_interface.position.bind_to_buffer(self._positions_buffer)
#         shader_program_interface.normal.bind_to_buffer(self._normals_buffer)
#         shader_program_interface.colour.bind_to_buffer(self._colours_buffer)
#         self.unbind()
# 
#     ##############################################
# 
#     def draw(self):
# 
#         """ Draw the vertex array as lines. """
# 
#         self.bind()
#         GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3*self._number_of_items)
#         self.unbind()
# 
# Path: PyOpenGLng/Tools/EnumFactory.py
# def EnumFactory(enum_name, enum_tuple):
# 
#     """ Return an :class:`EnumMetaClass` instance, where *enum_name* is the class name and
#     *enum_tuple* is an iterable of constant's names.
#     """
# 
#     obj_dict = {}
#     obj_dict['_size'] = len(enum_tuple)
#     for value, name in enumerate(enum_tuple):
#         obj_dict[name] = EnumConstant(name, value)
# 
#     return EnumMetaClass(enum_name, (), obj_dict)


import mmap
import struct
import numpy as np
from .PrimitiveVertexArray import TriangleVertexArray
from PyOpenGLng.Tools.EnumFactory import EnumFactory
            for k in range(3):
                positions[j+k] = struct.unpack('<fff', stream.read(12))
            stream.read(2)
            # struct.unpack('<H', stream.read(2))
        # stream.seek(84)

        # Center the solid
        for i in range(3):
            positions[:,i] -= .5*(positions[:,i].max() + positions[:,i].min())
        print(positions[:,0].min(), positions[:,1].min(), positions[:,2].min())
        print(positions[:,0].max(), positions[:,1].max(), positions[:,2].max())

        # normal, 3 vertex
        # dtype = np.dtype('12<f4, <u2')
        # data = np.memmap(file_handle, mode='r', dtype=dtype, shape=number_of_triangles)
        # print(data[0])

        self.positions = positions
        self.normals = normals

    ##############################################

    def to_vertex_array(self):

        # Fixme: here ?

        colour = (1, 0, 0, 1)
        self.colours = np.zeros((self.positions.shape[0], 4), dtype=np.float32)
        self.colours[...] = colour


# Path: PyOpenGLng/HighLevelApi/PrimitiveVertexArray.py
# class TriangleVertexArray(GlVertexArrayObject):
# 
#     """ Base class to draw primitives as triangles. """
# 
#     # Fixme: 3d
# 
#     ##############################################
# 
#     def __init__(self, items=None):
# 
#         super(TriangleVertexArray, self).__init__()
# 
#         self._number_of_items = 0
#         self._positions_buffer = GlArrayBuffer()
#         self._normals_buffer = GlArrayBuffer()
#         self._colours_buffer = GlArrayBuffer()
# 
#         if items is not None:
#             self.set(*items)
# 
#     ##############################################
# 
#     def set(self, positions, normals, colours):
# 
#         """ Set the vertex array from an iterable of triangles. """
# 
#         self._number_of_items = positions.shape[0]
# 
#         # Fixme:
#         #  - set from high level primitive: slow
#         #  - set from Numpy array: fast but check for mistake
# 
#         # vertex = np.zeros((self._number_of_objects, 3), dtype='f') # dtype=np.float
# 
#         self._positions_buffer.set(positions)
#         self._normals_buffer.set(normals)
#         self._colours_buffer.set(colours)
# 
#     ##############################################
# 
#     def bind_to_shader(self, shader_program_interface):
# 
#         """ Bind the vertex array to the shader program interface attribute.
#         """
# 
#         # Fixme: we cannot reuse the vbo
# 
#         self.bind()
#         shader_program_interface.position.bind_to_buffer(self._positions_buffer)
#         shader_program_interface.normal.bind_to_buffer(self._normals_buffer)
#         shader_program_interface.colour.bind_to_buffer(self._colours_buffer)
#         self.unbind()
# 
#     ##############################################
# 
#     def draw(self):
# 
#         """ Draw the vertex array as lines. """
# 
#         self.bind()
#         GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3*self._number_of_items)
#         self.unbind()
# 
# Path: PyOpenGLng/Tools/EnumFactory.py
# def EnumFactory(enum_name, enum_tuple):
# 
#     """ Return an :class:`EnumMetaClass` instance, where *enum_name* is the class name and
#     *enum_tuple* is an iterable of constant's names.
#     """
# 
#     obj_dict = {}
#     obj_dict['_size'] = len(enum_tuple)
#     for value, name in enumerate(enum_tuple):
#         obj_dict[name] = EnumConstant(name, value)
# 
#     return EnumMetaClass(enum_name, (), obj_dict)


# Path: PyOpenGLng/HighLevelApi/STL.py
import mmap
import struct
import numpy as np
from .PrimitiveVertexArray import TriangleVertexArray
from PyOpenGLng.Tools.EnumFactory import EnumFactory

            for k in range(3):
                positions[j+k] = struct.unpack('<fff', stream.read(12))
            stream.read(2)
            # struct.unpack('<H', stream.read(2))
        # stream.seek(84)

        # Center the solid
        for i in range(3):
            positions[:,i] -= .5*(positions[:,i].max() + positions[:,i].min())
        print(positions[:,0].min(), positions[:,1].min(), positions[:,2].min())
        print(positions[:,0].max(), positions[:,1].max(), positions[:,2].max())

        # normal, 3 vertex
        # dtype = np.dtype('12<f4, <u2')
        # data = np.memmap(file_handle, mode='r', dtype=dtype, shape=number_of_triangles)
        # print(data[0])

        self.positions = positions
        self.normals = normals

    ##############################################

    def to_vertex_array(self):

        # Fixme: here ?

        colour = (1, 0, 0, 1)
        self.colours = np.zeros((self.positions.shape[0], 4), dtype=np.float32)
        self.colours[...] = colour


        return TriangleVertexArray((self.positions, self.normals, self.colours))