我刚刚开始使用 Assimp 来解析一些 STL 文件。我从源代码构建它并将其作为静态库安装在我的系统中(Manjaro Linux x86_64 - Kernel 6.2.6-1)。为了了解该库的工作原理,我尝试运行以下代码:
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <iostream>
#include <memory>
#include <Eigen/Core>
#include <fcl/geometry/bvh/BVH_model.h>
std::shared_ptr<fcl::BVHModel<fcl::OBBRSSd>> loadSTL(const std::string &filename);
int main()
{
// Load the STL mesh files
std::shared_ptr<fcl::BVHModel<fcl::OBBRSSd>> Skeleton, Liver, Lungs;
Skeleton = loadSTL("Skeleton.stl");
Liver = loadSTL("Liver.stl");
Lungs = loadSTL("Lungs.stl");
return 0;
}
// Load an STL file into an FCL mesh object
std::shared_ptr<fcl::BVHModel<fcl::OBBRSSd>> loadSTL(const std::string &filename)
{
// Create an Assimp importer
Assimp::Importer importer;
// Import the STL file -- "aiProcess_Triangulate" post-processing flag automatically triangulates all non-triangular faces during the import process
const aiScene *scene = importer.ReadFile(filename, aiProcess_Triangulate);
// Check if the import was successful
if (!scene)
{
std::cerr << "Failed to import STL file: " << importer.GetErrorString() << std::endl;
return nullptr;
}
// Extract the mesh from the scene
const aiMesh *mesh = scene->mMeshes[0];
// Create a BVHModel from the mesh
auto model = std::make_shared<fcl::BVHModel<fcl::OBBRSSd>>();
model->beginModel();
for (size_t i = 0UL; i < mesh->mNumFaces; ++i)
{
const aiFace &face = mesh->mFaces[i];
if (face.mNumIndices != 3)
{
std::cerr << "Error: non-triangular face in STL file." << std::endl;
model->endModel();
return nullptr;
}
fcl::Vector3d v1(mesh->mVertices[face.mIndices[0UL]].x, mesh->mVertices[face.mIndices[0UL]].y, mesh->mVertices[face.mIndices[0UL]].z);
fcl::Vector3d v2(mesh->mVertices[face.mIndices[1UL]].x, mesh->mVertices[face.mIndices[1UL]].y, mesh->mVertices[face.mIndices[1UL]].z);
fcl::Vector3d v3(mesh->mVertices[face.mIndices[2UL]].x, mesh->mVertices[face.mIndices[2UL]].y, mesh->mVertices[face.mIndices[2UL]].z);
model->addTriangle(v1, v2, v3);
}
model->endModel();
// Clean up the Assimp data structures
importer.FreeScene();
return model;
}
但事实证明 Assimp 找不到 assimp/types.h 引用的 utf8 header (见下图)。
我注意到这个文件位于 contrib 文件夹中,但无论我在构建库时在 CMAKE 上设置什么标志,contrib 和 utf8 header 都不会被复制到 inlude 文件夹中。我在这里缺少什么?有其他人遇到过类似的问题吗?
最佳答案
我猜这个问题是由 Assimp 错误引起的。我们的安装脚本中未正确处理 utf8 的依赖关系。在研究这个主题时我错过了这一点。我将提供一个不依赖于 types 文件夹中的 utf8 header 的解决方案。
感谢您解决这个问题。
关于utf-8 - Assimp 找不到 utf8.h header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75804281/