首页 > 解决方案 > 网格未在 Assimp 中加载

问题描述

要加载网格,我正在使用 Assimp 的 Importer::ReadFile()。

在 Assimp 的文档中,它指出 aiMesh::mVertices 和 aiMesh::mFaces 总是被定义的。当我在 stl 文件中加载时,定义了顶点,但没有定义面。我的场景只包含 1 个网格,并且应该包含该网格面的指针始终是 1B1B1B1B1B1B1B1B。

我在网上发现的唯一类似问题是https://sourceforge.net/p/assimp/discussion/817654/thread/a7c953a7/。他有同样的问题,只是指针是空指针。他通过使用更新版本的 Assimp 解决了他的问题,即 assimp 3.0.1264。我正在使用 Assimp 5.0.4162681867,所以我认为可以,但我还没有尝试过他的具体版本。

我的代码和输出如下

Assimp::DefaultLogger::create("", Assimp::Logger::VERBOSE, aiDefaultLogStream_STDOUT);


    // Create an instance of the Importer class
    Assimp::Importer importer;

    const aiScene* temp_scene = importer.ReadFile( file,
      aiProcess_CalcTangentSpace       |
      aiProcess_GenNormals             |
      aiProcess_Triangulate            |
      aiProcess_JoinIdenticalVertices  |
      aiProcess_SortByPType            |
      aiProcess_ValidateDataStructure
      );

    //kill here the logger, just to see what has happened with the importer
    Assimp::DefaultLogger::kill();

    //check if scene
      if (temp_scene == NULL)
      {
            std::cout << __LINE__ << ": Error importing scene. Check if file exists ! " << std::endl;
            return -1;
      }
      else
      {
          int meshIdx = temp_scene->mRootNode->mChildren[0]->mMeshes[0];
          std::cout << __LINE__ << ": idx " << meshIdx << std::endl;
          std::cout << __LINE__ << ": mNumFaces: " << temp_scene->mMeshes[meshIdx]->mNumFaces << std::endl;
          std::cout << __LINE__ << ": HasFaces(): " << temp_scene->mMeshes[meshIdx]->HasFaces() << std::endl;
          std::cout << __LINE__ << ": ptr mFace[0]: " << &(temp_scene->mMeshes[meshIdx]->mFaces[0]) << std::endl;
      }

    exit(0);
Info,  T21520: Load C:/Users/Woute/Documents/2021-2022/computationalFabrication/files/balanced_die.stl
Debug, T21520: Assimp 5.0.4162681867 amd64 msvc debug shared singlethreadedsingle : 
Info,  T21520: Found a matching importer for this file format: Stereolithography (STL) Importer.
Info,  T21520: Import root directory is 'C:/Users/Woute/Documents/2021-2022/computationalFabrication/files\'
Info,  T21520: STL: Taking code path for Materialise files
Debug, T21520: UpdateImporterScale scale set: 1
Debug, T21520: ValidateDataStructureProcess begin
Debug, T21520: ValidateDataStructureProcess end
Info,  T21520: Entering post processing pipeline
Debug, T21520: TriangulateProcess begin
Debug, T21520: TriangulateProcess finished. There was nothing to be done.
Debug, T21520: SortByPTypeProcess begin
Info,  T21520: Points: 0, Lines: 0, Triangles: 1, Polygons: 0 (Meshes, X = removed)
Debug, T21520: SortByPTypeProcess finished
Debug, T21520: GenFaceNormalsProcess begin
Debug, T21520: GenFaceNormalsProcess finished. Normals are already there
Debug, T21520: Generate spatially-sorted vertex cache
Debug, T21520: CalcTangentsProcess begin
Error, T21520: Failed to compute tangents; need UV data in channel0
Debug, T21520: CalcTangentsProcess finished
Debug, T21520: JoinVerticesProcess begin
Info,  T21520: JoinVerticesProcess finished | Verts in: 6486 out: 4029 | ~37.8816
Info,  T21520: Leaving post processing pipeline
47/ idx0
48: mNumFaces: 2162
49: HasFaces(): 1
50: ptr mFace[0]: 1B1B1B1B1B1B1B1B

标签: c++assimp

解决方案


检查您的日志后,我猜您的模型中只有一个三角形,但有 6486 个顶点。

您使用的是点云模型吗?如果没有:您可以在Github的项目空间中为该模型创建一个新的问题报告


推荐阅读