Assimp: gltf2 importer not working when using ReadFileFromMemory

Created on 4 May 2018  路  2Comments  路  Source: assimp/assimp

The gltf2 importer does not work for me when reading from memory instead of a file. I've tried with multiple files, but it seems to throw an exception somewhere in the importer in the latter case only. Here's code to reproduce it with 4.1.0-Release, the gltf file used here is simply Blender's default scene (cube, lamp, camera) exported with https://github.com/KhronosGroup/glTF-Blender-Exporter.

#include <assimp/Importer.hpp>
#include <iostream>
#include <fstream>
#include <vector>

int main()
{
    const char* filename = "d:/default-scene.gltf";
    Assimp::Importer importer;

#if 1
    // FAILS: read into buffer first, then pass to ReadFileFromMemory

    std::ifstream input(filename, std::ios::binary);
    std::vector<char> buffer((
        std::istreambuf_iterator<char>(input)),
        (std::istreambuf_iterator<char>()));

    auto ai_scene = importer.ReadFileFromMemory(buffer.data(), buffer.size(), 0, "gltf");
    if (!ai_scene) {
        std::cout << importer.GetErrorString() << std::endl;
        // No suitable reader found for the file format of file "$$$___magic___$$$.gltf".
    }
#else
    // WORKS: read file directly

    auto ai_scene = importer.ReadFile(filename, 0);
#endif
}
Bug

Most helpful comment

Any news on that for the next release ? :/

All 2 comments

When loading the gltf from memory, it cannot find the associated .bin.

So this closely linked to #1945.

Any news on that for the next release ? :/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jayshua picture Jayshua  路  5Comments

OmegaDoom picture OmegaDoom  路  6Comments

Tcll picture Tcll  路  5Comments

krupitskas picture krupitskas  路  3Comments

dangelog picture dangelog  路  7Comments