1. Products
  2.   3D
  3.   C++
  4.   Assimp
 
  

Open Source C++ Library to Process 3D Data Formats

C++ API that provides supports for loading as well as processing geometric scenes from various 3D Data Formats. You can integrate it with game engines and binding to other programming languages.

The Asset-Importer-Lib (Assimp) is a powerful open source library that is implemented in C++. It gives software developers the capability to load as well as process geometric scenes from various 3d-data-formats inside their own C++ applications. The library is platform-independent and provides easy integration with game engines and binding to other programming languages.

There are several 3D file formats around the world, and Assimp library has included support for several important ones of them. The library is very well organized and provided support for 40+ 3D-file-formats such as Collada, 3D Studio Max 3DS and ASE, Biovision BVH, Stanford Polygon Library, AutoCAD DXF, Neutral File Format, Autodesk DXF, Object File Format, Milkshape 3D, LightWave Scene, and many more.

The library is very useful for importing elements from various sources once and storing them in an engine-specific format for easy and quick access. The latest version has also included support for exporting 3D files to other supported file formats. The library supports features like enhanced vertex cache locality, triangulating arbitrary polygons, searching degenerate polygons, splitting large meshes to overcome GPU limitations, optimizing meshes, ensuring maximum data integrity by validating the output structure & nodes for fewer draw calls, and so on.

Previous Next

Getting Started with Assimp

The easiest way to install Assimp library is via cmake. First, you need to install cmake. Please use the following command for a smooth installation. To build the library just open a command-prompt, navigate into the repo-folder and run cmake.

Install Assimp via cmake

cmake CMakeLists.txt

Load & Process 3D Models via C++ Library

The Open Asset Import Library (Assimp) has included support for accessing and loading 3D models from some common 3D model formats inside C++ applications. You need to provide the path to the 3D model file and it will start loading the model. You can easily create the instance and stores all information about the model inside it. The library will load and read the model in such order that materials must be loaded before meshes and meshes must be before nodes.

How to Load a 3D Model File via C++ Code?

#include 
#include 
#include 
#include 

int main() {
    Assimp::Importer importer;
    const aiScene* scene = importer.ReadFile("model.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
    if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
        std::cerr << "Error loading model: " << importer.GetErrorString() << std::endl;
        return -1;
    }
    std::cout << "Model loaded successfully!" << std::endl;
    return 0;
}

Convert CAD Models via C++

The open source Library Assimp gives software developers the capability to load and convert CAD models to other supported 3D models using C++ applications. You need to provide the address of the CAD file and once load you can easily convert it to other supported formats such as DAE, STL, OBJ, PLY, STEP, 3MF, FBX and many more. The following example shows how to convert a CAD model to another format using C++ code via Assimp library.

How to Load and Convert a 3D Model File to Desired Format via C++ API?

#include 
#include 
#include 
#include 

int main() {
    // Initialize Assimp importer
    Assimp::Importer importer;

    // Specify CAD model file path
    const char* cadModelPath = "input_model.step"; // Change to the path of your CAD model file

    // Import CAD model
    const aiScene* scene = importer.ReadFile(cadModelPath, aiProcess_Triangulate | aiProcess_FlipUVs);

    // Check if the import was successful
    if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
        std::cerr << "Error loading model: " << importer.GetErrorString() << std::endl;
        return -1;
    }

    // Specify output format
    const char* outputFormat = "obj"; // Change to the desired output format

    // Specify output file path
    const char* outputFile = "output_model.obj"; // Change to the desired output file path

    // Export CAD model to the specified format
    if (importer.Export(scene, outputFormat, outputFile) != AI_SUCCESS) {
        std::cerr << "Error exporting model to " << outputFormat << std::endl;
        return -1;
    }

    // Print success message
    std::cout << "CAD model converted successfully to " << outputFormat << std::endl;

    return 0;
}

Import and Apply Animation to Models

The Open Asset Import Library (Assimp) gives software programmers the ability to apply animations to the models using C++ code. The best approach will be to first animate the nodes in the scene graph after that you can calculate the bone matrices from the current state of the scene graph.

Scene Graph Representation inside C++ Apps

The open source Assimp library provides a comprehensive scene graph representation of imported models inside C++ applications. The library allows software developers to access and manipulate various elements such as meshes, materials, textures, and transformations. The following example demonstrates how software developers can access and handle various elements of a graph inside C++ applications.

How to Access Scene Graph and Work with It via C++ API?

const aiScene* scene = importer.ReadFile("model.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
if (scene && scene->mRootNode) {
    aiNode* rootNode = scene->mRootNode;
    // Traverse the scene graph and access nodes, meshes, etc.
} else {
    // Handle error
}
 English