Model *ModelBuilder::buildModel(const char* Filename) {
    ObjModel *objModel;
    ObjParser objParser;
    std::cout << "Filename " << Filename << std::endl;
    objModel = objParser.loadModelFromFile(Filename);
    
    // assemble vertices and materials from collected data
    unsigned int numberOfFaces = (int)objModel->faces.size();
    unsigned int numberOfVertices = numberOfFaces * 3;
    std::vector<Vertex> vertices(numberOfVertices);
    std::vector<unsigned int> indices(numberOfVertices);
    FaceGroup currentFaceGroup;
    for(int i = 0; i < numberOfFaces; i++) {
        // @todo: check for different mats and create face groups
        
        unsigned int PosIdx0 = objModel->faces[i].pidx[0] - 1;
        unsigned int PosIdx1 = objModel->faces[i].pidx[1] - 1;
        unsigned int PosIdx2 = objModel->faces[i].pidx[2] - 1;
        
        unsigned int TexIdx0 = objModel->faces[i].tidx[0] - 1;
        unsigned int TexIdx1 = objModel->faces[i].tidx[1] - 1;
        unsigned int TexIdx2 = objModel->faces[i].tidx[2] - 1;
        
        // Positionen der Vertices setzen
        Vector a = vertices[i * 3].position = objModel->positions[PosIdx0];
        Vector b = vertices[i * 3 + 1].position = objModel->positions[PosIdx1];
        Vector c = vertices[i * 3 + 2].position = objModel->positions[PosIdx2];
        
        // Wenn aktuelles Objekt Textkoordinaten enthaelt, eben diese setzen
        vertices[i * 3].texCoordS = objModel->textureCoordinates[TexIdx0].s;
        vertices[i * 3 + 1].texCoordS = objModel->textureCoordinates[TexIdx1].s;
        vertices[i * 3 + 2].texCoordS = objModel->textureCoordinates[TexIdx2].s;
        
        vertices[i * 3].texCoordT = objModel->textureCoordinates[TexIdx0].t;
        vertices[i * 3 + 1].texCoordT = objModel->textureCoordinates[TexIdx1].t;
        vertices[i * 3 + 2].texCoordT = objModel->textureCoordinates[TexIdx2].t;
        
        // Normalen berechnen
        
        Vector normal = (b - a).cross(c - a);
        normal.normalize();
        
        vertices[i * 3].normal =
        vertices[i * 3 + 1].normal =
        vertices[i * 3 + 2].normal = normal;
        
        indices[i * 3] = i * 3;
        indices[i * 3 + 1] = i * 3 + 1;
        indices[i * 3 + 2] = i * 3 + 2;
    }
    for (unsigned int i = 0; i < numberOfVertices; i++) {
        vertices[i].normal.normalize();
    }
    
    Model *newModel = new Model();
    newModel->setMaterials(objModel->materials, objModel->materialCount);
    newModel->setVertices(vertices);
    newModel->uploadVerticesToBuffer<Vertex>((unsigned int)vertices.size(), &vertices[0]);
    newModel->uploadIndicesToBuffer<unsigned int>((unsigned int)indices.size(), &indices[0]);
    
    return newModel;
}