4

The assimp library provides a nice way to load 3D .obj models from file. However I found out that the assimp_viewer.exe that comes with it (I use version 3.1.1) is much faster in importing my .obj file (42Mb, already simplified) then my C++ code that loads the same model. The viewer loads the file in a couple of seconds whereas my C++ program (MSVS 2013/Win64/Release) takes 154 seconds to do that. I experimented with the importer post processing flags both in the viewer and C++ but I cannot bridge the gap between the two.

Any thoughts on the cause? Here is my C++ code:

#include <ctime>
#include <iostream>
#include <fstream>
#include <vector>

#include "assimp/Importer.hpp"
#include "assimp/scene.h"
#include "assimp/postprocess.h"
#include "assimp/progresshandler.hpp"

using namespace std;

int main(int argc, char* argv[])
{
    Assimp::Importer importer;
    unsigned int post_processing_flags = aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices |
            aiProcess_OptimizeMeshes | aiProcess_OptimizeGraph | aiProcess_ImproveCacheLocality;

    cout << "starting load: ";

    auto begin = clock();
    auto scene = importer.ReadFile( "MODEL.obj", post_processing_flags);
    auto end = clock();

    cout << "done!\n";

    double seconds = (end - begin) / CLOCKS_PER_SEC;

    cout << "loading took " << seconds << " seconds" << endl;

    return 0;
}
RevJohn
  • 1,054
  • 9
  • 15
  • Do you compile your program in release mode? It looks like the library is header-based, so the compilation configuration of your program will have effect on it. – michalsrb Sep 05 '16 at 08:30
  • Also check your compiler optimisation level, this reduces the load time and parsing time to a great extend. Try with -O3 or better optimisation. – codetiger Sep 05 '16 at 12:22

1 Answers1

0

Found my own answer: I run it in Visual Studio but start it -with- the debugger in Release mode (F5). When I start it without debugging (CTRL+F5) it takes now 1 second to load the model as the assimp viewer does. The same applies if you run the executable from outside visual studio using the file explorer or command line. Still a huge difference between with and without debugging.

RevJohn
  • 1,054
  • 9
  • 15