lwjgl

How to get to the textures from materials?


I'm following this guide to read a 3D model from a file. In this code snippet taken from said guide, the textures are read:

vector<Texture> loadMaterialTextures(aiMaterial *mat, aiTextureType type, string typeName)
{
    vector<Texture> textures;
    for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
    {
        aiString str;
        mat->GetTexture(type, i, &str);

This is C++ code; however, I'm programming in Clojure using the LWJGL library.

The problem I'm facing is that the AIMaterial class does not have a GetTextureCount and neither a GetTexture method.

Therefore my question, how to get to the texture from the material using LWJGL?


Solution

  • The functions GetTextureCount and GetTexture are only defined for C++. LWJGL however only provides access to C functions. The Assimp class provides a static method that can be used to retrieve the filename of the texture:

              (Assimp/aiGetMaterialString material
                                          Assimp/_AI_MATKEY_TEXTURE_BASE
                                          Assimp/aiTextureType_DIFFUSE
                                          0
                                          path)
    

    path is an output parameter of type AIString and receives the filename of the texture.