Model to load the library Assimp

Hello everyone, the next will introduce the model to load the library Assimp.

1, Assimp Introduction

Assimp called the Open Asset Import Library, dozens of analytical models can support different file format (the same format can also export part of the model), Assimp itself is a C ++ library that can work across platforms.

Assimp may be dozens of model files are converted to a unified data structure, all no matter what we import the model file format, you can use the same way to access model data we need.

When importing a model file, i.e. Assimp loading an entire model file that contains all the models and scene data when a scene objects, Assimp will all scene node, model node model file are generating a data structure having a correspondence relationship , and the model data with various elements of the association of these scenarios. The following figure shows a simplified model of the generated file data structure Assimp:

a, of all the models, the scene data contained in the object scene, all such materials and Mesh. Similarly, reference to the root node of the scene are also included in this scene object.

b, the root node of the scene may also contain many sub-nodes and a pointer to index set point cloud model stored mMeshes [] a. mMeshes on the root [] in the preservation of the actual Mesh object, mMesshes on each child node [] are just pointing to the root node mMeshes [] of a reference.

C, a Mesh object itself contains all relevant data required to render such vertex position, normal vector, texture coordinates, surface of the sheet material and objects.

d, contains a plurality of patches Mesh. A Face (patch) represents rendering a basic shape of the unit, i.e. primitives (base primitive bit line, triangular patches, a rectangular patch). A patch record a primitive vertex indices, by this index, can find the corresponding position of the vertex data mMeshes [] in. Vertex and index data stored separately, we may facilitate use cache (VBO, NBO, TBO, IBO) at high speed rendering object.

e, a Mesh also contains a Material's material properties (material) used to specify the target object. Such as color, texture map (diffuse map, specular map, etc.).

So the first thing we need to do is load a model file for the scene object, and then get Mesh objects corresponding to each node (child node we need to recursively search each node to get all of the nodes), and process each Mesh vertex data corresponding to an object, and the index of its material properties. Finally we get Mesh collection contains only the data we need.

 

2, build Assimp

Assimp source address: https: //github.com/assimp/assimp

a: Several environment variable as follows:

export ANDROID_NDK_PATH=/Users/liao/Library/Android/sdk/ndk-bundle // 设置DNK路径
export ANDROID_SDK_PATH=/Users/liao/Library/Android/sdk // 设置SDK路径
export CMAKE_TOOLCHAIN=/Users/liao/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake // 设置交叉编译用到的toolchain,这个用NDK默认提供的就行
export ANDROID_NDK_TOOLCHAIN=/Users/liao/Library/Android/sdk/android-toolchain // 这个也必须设置,其中android-toolchain就是上面生成的啦
export PATH=$PATH:/Users/liao/Library/Android/sdk/android-toolchain/bin // 必须设置

b: After setting up environment variables, we can cmake generate makefile up.

First, execute the following command:

cd xxx/assimp // 下载assimp,然后解压,进入assimp根目录
mkdir buildAndroid // 创建文件夹
cd buildAndroid // 进入这个文件夹

Then execute the following command

cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=/assimp -DANDROID_ABI=armeabi-v7a -DANDROID_NATIVE_API_LEVEL=android-14 -DANDROID_FORCE_ARM_BUILD=TRUE -DANDROID_STL=c++_shared -DASSIMP_BUILD_OBJ_IMPORTER=TRUE -DASSIMP_BUILD_FBX_IMPORTER=TRUE -DANDROID_NDK=$ANDROID_NDK_PATH -DCMAKE_BUILD_TYPE=Release -DANDROID_FORCE_ARM_BUILD=TRUE -DCMAKE_CXX_FLAGS=-Wno-c++11-narrowing -DANDROID_TOOLCHAIN=clang -DASSIMP_BUILD_TESTS=OFF -DASSIMP_NO_EXPORT=TRUE -DASSIMP_BUILD_ASSIMP_TOOLS=FALSE -DASSIMP_BUILD_SAMPLES=FALSE -DASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT=FALSE ..

Parameter Description

-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN 指向上面生成的toolchain
-DCMAKE_INSTALL_PREFIX=/assimp 最终生成的.so文件的名称
-DANDROID_ABI=armeabi-v7a 应用程序二进制接口类型,详见[ABI Management](https://developer.android.com/ndk/guides/abis)
-DANDROID_NATIVE_API_LEVEL=android-14 api版本,设成这个就行
-DANDROID_FORCE_ARM_BUILD=TRUE 强制编译arm架构
-DANDROID_STL=c++_shared c++类型
-DASSIMP_BUILD_OBJ_IMPORTER=TRUE 支持OBJ格式的3D模型文件导入
-DASSIMP_BUILD_FBX_IMPORTER=TRUE 支持FBX格式的3D模型文件导入
-DASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT=FALSE assimp默认支持很多种3D模型格式,这里只指定常用的一两种格式即可,减小.so包的大小
-DASSIMP_BUILD_TESTS=OFF 这个要关掉,不然make时会有一些奇怪的错误
-DASSIMP_NO_EXPORT=TRUE 只需要解析3D模型,不需要生成3D模型

c: the step of generating the above makefile file, the following make batch.

make -j8 // 在buildAndroid目录下执行make操作。其中-j8是指多线程个数,根据自己电脑配置,选择不同线程数,线程数越多编译的越快。

The above make if not wrong, then go directly to assimp / buildAndroid / code to find the next directory libassimp.so file.

 

 

 

 

Published 41 original articles · won praise 52 · views 20000 +

Guess you like

Origin blog.csdn.net/u010281924/article/details/105344598