zoukankan      html  css  js  c++  java
  • 开源代码·Assimp导入stl模型顶点数量问题

      使用Assimp示例代码导入stl文件:

     1 #include <assimp/Importer.hpp>      // C++ importer interface
     2 #include <assimp/scene.h>           // Output data structure
     3 #include <assimp/postprocess.h>     // Post processing flags
     4 bool DoTheImportThing(const std::string& pFile)
     5 {
     6     // Create an instance of the Importer class
     7     Assimp::Importer importer;
     8     // And have it read the given file with some example postprocessing
     9     // Usually - if speed is not the most important aspect for you - you'll 
    10     // propably to request more postprocessing than we do in this example.
    11     const aiScene* scene = importer.ReadFile(pFile,
    12         aiProcess_CalcTangentSpace |
    13         aiProcess_Triangulate |
    14         aiProcess_JoinIdenticalVertices |
    15         aiProcess_SortByPType);
    16 
    17     // If the import failed, report it
    18     if (!scene)
    19     {
    20         //DoTheErrorLogging(importer.GetErrorString());
    21         std::printf("failed to import %s!
    ", pFile.c_str());
    22         return false;
    23     }
    24     // Now we can access the file's contents. 
    25     //DoTheSceneProcessing(scene);
    26     if (scene->HasMeshes())
    27     {
    28         std::printf("has %d meshes!
    ", scene->mNumMeshes);
    29         for (int i = 0; i < scene->mNumMeshes; ++i)
    30         {
    31             std::printf("%d: %u vertices!
    ", i, scene->mMeshes[i]->mNumVertices);
    32             if (scene->mMeshes[i]->HasFaces())
    33                 std::printf("%d: %u faces!
    ", i, scene->mMeshes[i]->mNumFaces);
    34         }
    35     }
    36     // We're done. Everything will be cleaned up by the importer destructor
    37     return true;
    38 }
    39 
    40 
    41 int main()
    42 {
    43     std::string File = ".\bottle.stl";
    44     DoTheImportThing(File);
    45 
    46     system("pause");
    47     return 0;
    48 }

      输出:

    has 1 meshes!
    0: 553770 vertices!
    0: 190624 faces!

      MeshLab导入同一stl模型的结果:

    0:  95314 vertices!
    0: 190624 faces!

      问题在于顶点合并:

      assimp-5.0.1codePostProcessingJoinVerticesProcess.cpp

     1     // A little helper to find locally close vertices faster.
     2     // Try to reuse the lookup table from the last step.
     3     const static float epsilon = 1e-5f;
     4     // Squared because we check against squared length of the vector difference
     5     static const float squareEpsilon = epsilon * epsilon;
     6 
     7     // Square compare is useful for animeshes vertices compare
     8     if ((lhs.position - rhs.position).SquareLength() > squareEpsilon) {
     9         return false;
    10     }
  • 相关阅读:
    TomCat安装配置教程
    Java桌面程序打包成exe可执行文件
    【android studio】 gradle配置成本地离线zip包
    使用Android Studio过程中,停留在“Building ‘工程名’ Gradle project info”的解决方法
    Android studio启动后卡在refreshing gradle project(包解决)
    Genymotion的安装与使用(附百度云盘下载地址,全套都有,无需注册Genymotion即可使用)
    CodeForcesGym 100735G LCS Revised
    CodeForcesGym 100735D Triangle Formation
    CodeForcesGym 100735B Retrospective Sequence
    HDU 2829 Lawrence
  • 原文地址:https://www.cnblogs.com/Ezekiel/p/12681732.html
Copyright © 2011-2022 走看看