コード例 #1
0
vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial* mat,
                                                  aiTextureType type,
                                                  TextureTypes texType) {
    TextureLoader textureLoader;

    vector<Texture> textures;
    for(GLuint i = 0; i < mat->GetTextureCount(type); i++) {
        aiString str;
        mat->GetTexture(type, i, &str);
        GLboolean skip = false;
        for(GLuint j = 0; j < textureCache.size(); j++) {
            if(textureCache[j].path == string(str.C_Str()))
            {
                textures.push_back(textureCache[j]);
                skip = true;
                break;
            }
        }
        if(!skip) {
            std::string filepath = directory + '/' + string(str.C_Str());
            Texture texture = textureLoader.loadTexture(filepath,
                                                        texType);
            texture.path = string(str.C_Str());
            textures.push_back(texture);
            this->textureCache.push_back(texture);
        }
    }
    return textures;
}
コード例 #2
0
vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial* mat,
                                                  aiTextureType type,
                                                  TextureTypes texType) {
    TextureLoader textureLoader;

    vector<Texture> textures;
    for(GLuint i = 0; i < mat->GetTextureCount(type); i++) {
        aiString str;
        mat->GetTexture(type, i, &str);
        string filename = string(str.C_Str());
/*
        // <Eagle HASK> :(
        string filenameTMP = string(str.C_Str());
        string filename = "";
        for(int i = 4; i < filenameTMP.size(); i++){
            if(filenameTMP[i] == '\\')
                filename += "/";
            else
                filename += filenameTMP[i];
        }
        // </Eagle HASK> :(
*/
        GLboolean skip = false;
        for(GLuint j = 0; j < textureCache.size(); j++) {
            if(textureCache[j].path == filename)
            {
                textures.push_back(textureCache[j]);
                skip = true;
                break;
            }
        }
        if(!skip) {
            std::string filepath = directory + '/' + filename;
            Texture texture = textureLoader.loadTexture(filepath,
                                                        texType);

            texture.path = string(str.C_Str());
            textures.push_back(texture);
            this->textureCache.push_back(texture);
        }
    }
    return textures;
}
コード例 #3
0
void Heightmap::loadHeightmap(string filename, float strength) {
    TextureLoader tl;
    Texture t = tl.loadTexture(filename, 1);
    
    if(t.getWidth() < columns || t.getHeight() < rows) {
        cout << "The provided file " << filename << " (" << t.getWidth() << "x" << t.getHeight() << ") is too small and cannot be used for this heightmap (" << columns << "x" << rows << ")" << endl;
        return;
    }
    
    int dx = t.getWidth()/columns;
    int dy = t.getHeight()/rows;
    
    for(int row = 0; row <= rows; row++) {
        for(int column = 0; column <= columns; column++) {
            setHeightAt(column, row, (t.getData()[row * t.getWidth() * dy + column * dx] / 255.0f) * strength);
            //assert(0.0f <= getHeightAt(column, row) && getHeightAt(column, row) <= strength);
        }
    }
    
    calculateNormals();
}
コード例 #4
0
Model DuckLoader::loadDuckModel() {
    vector<Vertex> vertices;
    vector<GLuint> indices;

    string filepath = "res/models/duck/duck.txt";
    ifstream fileStream(filepath);
    if(!fileStream){
        throw new invalid_argument("No such duck file");
    }
    string line;
    getline(fileStream, line);

    int vertexCount = stoi(line);
    for(int i = 0; i < vertexCount; i++){
        getline(fileStream, line);
        vector<string> vertexStr = splitString(line, " ");
        if(vertexStr.size() != 8){
            throw new invalid_argument("No such duck file");

        }
        vec3 pos = vec3(atof(vertexStr[0].c_str()),
                        atof(vertexStr[1].c_str()),
                        atof(vertexStr[2].c_str()));
        vec3 norm = vec3(atof(vertexStr[3].c_str()),
                         atof(vertexStr[4].c_str()),
                         atof(vertexStr[5].c_str()));
        vec2 tex = vec2(atof(vertexStr[6].c_str()),
                         atof(vertexStr[7].c_str()));

        Vertex vertex;
        vertex.Position = pos;
        vertex.Normal = norm;
        vertex.TexCoords = tex;
        vertices.push_back(vertex);
    }

    getline(fileStream, line);
    int indexCount = stoi(line);
    for(int i = 0; i < indexCount; i++){
        getline(fileStream, line);
        vector<string> indexStr = splitString(line, " ");

        GLuint i1 = stoi(indexStr[0]);
        GLuint i2 = stoi(indexStr[1]);
        GLuint i3 = stoi(indexStr[2]);
        indices.push_back(i1);
        indices.push_back(i2);
        indices.push_back(i3);
    }

    TextureLoader textureLoader;
    string texturePath = "res/models/duck/ducktex.jpg";
    Texture texture = textureLoader.loadTexture(texturePath,
                                                TextureTypes::DIFFUSE);
    Texture textureSpec = textureLoader.loadTexture(texturePath,
                                                    TextureTypes::SPECULAR);

    vector<Texture> textures = {texture, textureSpec};
    Material material;
    material.shininess = 32.0f;
    Mesh mesh(vertices, indices, textures);
    mesh.setMaterial(material);

    vector<Mesh> meshes = {mesh};
    Model model (meshes);

    return model;
}