2

I've just started playing around with Assimp to parse some stl files. I built it from source and installed it as a static library in my system (Manjaro Linux x86_64 - Kernel 6.2.6-1). To get a feel of how the library works, I am trying to run the following piece of code:

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

But it turns out Assimp can't find the a utf8 header referenced by assimp/types.h (see image below).

I noticed that this file is in a contrib folder, but no matter what flags I set on CMAKE while building the library, the contrib and utf8 headers won't get copied into the inlude folder. What am I missing here? Has anyone else encountered a similar issue?

2 Answers2

2

I guess the issue is caused by an Assimp bug. The dependency for utf8 is not handled correctly in our install script. I missed that point when working on this topic. I will offer a solution which in not depending on the utf8 header in the types folder.

Thanks for figuring this out.

KimKulling
  • 2,654
  • 1
  • 15
  • 26
  • Thank you for your reply! I have tried both. With Hunter, I set the flag ASSIMP_HUNTER_ENABLED to ON and that did not do it. The problem still persists. Obviously I could just add the contrib directory manually on the cmake file in my project, but that is not the ideal solution in my case. Is there any other flags I should set? I believe I there must be something rather trivial I am missing here. – Filipe Pedrosa Mar 27 '23 at 02:17
  • You are right, I have changed my answer. Thanks for your help! – KimKulling Mar 27 '23 at 08:33
0

I had a similar problem. g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0:

/home/michael/Documents/OpenGL/LearnOpenGL-master/includes/assimp/types.h:79:13: fatal error: ../contrib/utf8cpp/source/utf8.h: No such file or directory
   79 | #   include "../contrib/utf8cpp/source/utf8.h"

I downloaded assimp and compiled from source then I also copied over the /home/michael/Documents/OpenGL/LearnOpenGL-master/lib/assimp-master/include/assimp/* to /home/michael/Documents/OpenGL/LearnOpenGL-master/includes/assimp/*.

In types.h:

#ifdef ASSIMP_USE_HUNTER
#   include <utf8.h>
#elif __cplusplus < 199711L //previous else added as utf8.h deprecated in my //version of c++ ??
#   include "../contrib/utf8cpp/source/utf8.h"
#endif

I got it to work this is a quick fix I might experience other problems. I am learning OpenGL with learnopengl.com. I created the build directory in the main trunk and ran CMake then I ran make and after a while all the examples built. I went into the bin and quickly ran several examples and in /home/michael/Documents/OpenGL/LearnOpenGL-master/bin/4.advanced_opengl/. All the examples ran.

user16217248
  • 3,119
  • 19
  • 19
  • 37
Michael
  • 11
  • 1