在相同的.obj模型文件上,Assimp查看器比Assimp c++导入器快得多

Assimp viewer is much faster then Assimp C++ importer on the same .obj model file

本文关键字:Assimp c++ 快得多 导入 obj 模型 文件      更新时间:2023-10-16

assimp库提供了一种从文件加载3D .obj模型的好方法。然而,我发现它附带的assimp_viewer.exe(我使用版本3.1.1)在导入我的。obj文件(42Mb,已经简化)时要快得多,然后我的c++代码加载相同的模型。查看器在几秒钟内加载文件,而我的c++程序(MSVS 2013/Win64/Release)需要154秒才能完成。我在查看器和c++中都尝试了导入器后处理标志,但我无法弥合两者之间的差距。

对原因有什么想法吗?下面是我的c++代码:

#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;
}

找到了我自己的答案:我在Visual Studio中运行它,但在发布模式(F5)下启动调试器。当我在没有调试(CTRL+F5)的情况下启动它时,现在需要1秒才能像assimp查看器一样加载模型。如果您使用文件资源管理器或命令行从外部visual studio运行可执行文件,则同样适用。有调试和没有调试仍然有很大的区别。