androidandroid-ndkassimp.objgles

Use LoadModelFromMemoy in ASSIMP to load obj model with no texture loaded


I'm currently working on an Android project where I need to load .obj file with ASSIMP on Android Platform. My way of implementing that is to use the AssetManager to load the .obj file into memory first, and then using the importer.ReadFileFromMemory() function to create the aiScene object. I've managed to import all vertex data, but I found that the texture is missing. I actually read from the ASSIMP GitHub page where it mentioned that ReadFileFromMemory() won't read contents cross file, therefore I think it is not reading the .mtl file where texture is applied. I would like to use the importer.ReadFile() function, but I have no idea on how to work with it on Android platform. Any one has suggestions?

Attached is my implementation of the loadModelFromMemory, similar as the loadModel from LearnOpenGL.


void Model::loadModelFromMemory(const void* pbuffer, size_t pLength)
{
    Log::Message("Enter loadModelFromMemory", LOG_INIT);

    // read file via ASSIMP
    Assimp::Importer importer;

    const aiScene* scene = importer.ReadFileFromMemory(pbuffer, pLength, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_CalcTangentSpace);

    // check for errors
    if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
    {
        Log::Message(strcat("ERROR::ASSIMP::", importer.GetErrorString()), LOG_ERROR);
        return;
    }
    // process ASSIMP's root node recursively
    processNode(scene->mRootNode, scene);
}

I have tried on using ReadFile but it is not working on the Android context. I also tried to use the MemoryIOWrapper provided by the ASSIMP, but have no clue on where to start.


Solution

  • There are different ways how to implement this.

    1. Load the mtl- and the obj-file via memory buffers
    2. Use the android-filesystem implementations to load assets from the asset-folder on your mobile phone. You can find our headers for that at Android File system implementations