ASSIMP 导出导入的场景而不进行任何更改会引发异常

ASSIMP exporting an imported scene without any changes throws exception

本文关键字:任何更 异常 导入 ASSIMP      更新时间:2023-10-16

我正在做一个项目,我使用 ASSIMP 库导入头像的 3D 网格,更新它并使用相同的 ASSIMP 库再次导出更新的场景。为了实现这一点,作为第一步,我编写了一个代码来导入场景,并且在不进行任何更改的情况下,我将引用传递给导出函数。但是,导出函数给我抛出了一个错误。主要功能如下(您可以验证我没有对导入的场景进行任何更改):

int main(int argc, char** argv)
{
    string filename = "../Content/PinocchioMesh/Model1.obj";
    Assimp::Importer Importer;
    //Importer.
    cout << "tReading file using ASSIMP" << endl;
    const aiScene* aiscene = Importer.ReadFile(filename.c_str(), aiProcess_JoinIdenticalVertices | 
        aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_SortByPType | aiProcess_Triangulate);
    string str = Importer.GetErrorString();
    if (!aiscene) {
        printf("Error parsing '%s': '%s'n", filename.c_str(), Importer.GetErrorString());
        return false;
    }

    Assimp::Exporter exporter;
    const aiExportFormatDesc* format = exporter.GetExportFormatDescription(0);
    int lIndex = filename.find_last_of('/');
    //const string path = Filename.substr(0,lIndex+1);
    string path = "../Content/PinocchioMesh/";
    cout << "tExport path: " << path << endl;
    aiReturn ret = exporter.Export(aiscene, format->id, path, aiscene->mFlags);
    cout << exporter.GetErrorString() << endl;
    return 0;
}

错误出在 Export() 函数中,上面写着:

First-chance exception at 0x1052591B (Assimp32.dll) in ImportRigExport.exe: 0xC0000005: Access violation reading location 0x00000000.

如果有人使用 assimp 导出场景,请帮助我。

似乎 path 不包含文件名,只包含目录部分,因此 export() 不太可能创建输出文件。尽管如此,我同意,Assimp 应该管理此错误情况。

相关文章: