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, Access Scene Graph and Convert 3D Models to 3MF, DAE, 3DS, PLY, DXF, XML, OBJ and more.

What is Assimp?

C++ is used to implement the robust open source Asset-Importer-Lib (Assimp). It enables programmers to load and process geometric scenes from several 3D data formats within their own C++ programs. Platform-independent, the library offers simple game engine integration and programming language binding.

There are numerous 3D file formats in use worldwide, and the Assimp library supports a number of significant ones. 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 3D file formats are supported by this well-organized library.

For importing items from multiple sources at once and storing them in an engine-specific manner for convenient and fast access, the library is quite helpful. Additionally, the most recent version now supports exporting 3D files to various compatible file formats. Improved vertex cache locality, triangulating arbitrary polygons, searching for degenerate polygons, splitting large meshes to get around GPU restrictions, mesh optimization, ensuring maximum data integrity by validating the output structure & nodes for fewer draw calls, and other features are all supported by the library.

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