Assimp 编译(Visual Studio 2019)
Assimp 编译一、前言二、源码下载三、编译环境四、编译五、配置环境六、测试 DEMO一、前言Assimp 是一个非常流行的模型导入库,它是 Open Asset Import Library(开放的资源导入库)的缩写。Assimp 能够导入多种不同的模型文件格式(并也能够导出部分的格式),它能将不同格式的模型数据加载至 Assimp 的通用数据结构中。当 Assimp 加载完模型之后,我们就能
一、前言
Assimp 是一个非常流行的模型导入库,它是 Open Asset Import Library(开放的资源导入库)的缩写。Assimp 能够导入多种不同的模型文件格式(并也能够导出部分的格式),它能将不同格式的模型数据加载至 Assimp 的通用数据结构中。当 Assimp 加载完模型之后,我们就能够从 Assimp 的数据结构中提取我们所需的所有数据了。由于 Assimp 的数据结构保持不变,不论导入的是什么种类的文件格式,它都能够将我们从这些不同的文件格式中抽象出来,用同一种方式访问我们需要的数据。
二、源码下载
Assimp 5.0.1: https://github.com/assimp/assimp/releases/tag/v5.0.1
三、编译环境
操作系统:Win10 x64 专业版
编译环境:Visual Studion Enterprise 2019、CMake 3.18.0
四、编译
-
打开 cmake-gui.exe
-
配置环境变量选择源码路径与输出目录

-
点击 Configure 配置想要输出 x64 版本 (x86 版本自己选择 win32)

-
点击 Configure 完成后,再点击 Generate

出现以下警告忽略即可,不影响编译
- 点击OpenProject 选择 Release 编译即可


编译完成后,可在code/Release 目录找到生成的 dll 与 lib

注:x86版本自己安照上面的教程编译,只需在步骤3 修改下导出版本,如果报找不到 DirectX,自行安装 Dx 即可,Dx 下载链接:https://www.microsoft.com/en-us/download/details.aspx?id=6812,或在导出配置时去掉 ASSIMP_BUILD_ASSIMP_VIEW
五、配置环境
- 配置 Include 文件
-
将导出工程中的 config.h 拷到源码 include/assimp 目录中,或直接拷贝到VS include 目录,否则在引用 assimp 库会报以下错误



-
将源码 include 目录拷贝到 VS2019 安装目录下的 \Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\include

-
配置 .lib 文件
将编译好的 assimp-vc142-mt.lib 拷贝到 \Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\lib目录,注意区分x86 和 x64
-
配置 .dll 文件
拷贝 assimp-vc142-mt.dll 到系统目录,这里需要注意下 32 位 系统和 64 位 系统的区别。64 位 系统下 System32 目录是存放 64位 dll 的,SysWOW64 是用来存放 32位 dll 的,目录功能参考 https://zh.wikipedia.org/wiki/WoW64 。
(1)64 位 系统:将 64位的 dll 拷贝到 C:\Windows\System32,32位 dll 拷贝到 C:\Windows\SysWOW64
(2)32 位 系统:只需拷贝 32位 dll 到 C:\Windows\System32 即可
六、测试 DEMO
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
#include <iostream>
#pragma comment (lib, "assimp-vc142-mt.lib")
void LoadFinish(const aiScene* scene)
{
std::cout << "LoadFinish ! NumVertices : " << (*(scene->mMeshes))->mNumVertices << std::endl;
}
bool LoadModel(const std::string& pFile)
{
// Create an instance of the Importer class
Assimp::Importer importer;
// And have it read the given file with some example postprocessing
// Usually - if speed is not the most important aspect for you - you'll
// probably to request more postprocessing than we do in this example.
const aiScene* scene = importer.ReadFile(pFile,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
// If the import failed, report it
if (!scene)
{
std::cout << importer.GetErrorString() << std::endl;
return false;
}
// Now we can access the file's contents.
LoadFinish(scene);
// We're done. Everything will be cleaned up by the importer destructor
return true;
}
int main()
{
LoadModel("bun_zipper.ply");
return 0;
}
斯坦福兔子(bun_zipper.ply文件)下载地址 :http://graphics.stanford.edu/pub/3Dscanrep/bunny.tar.gz

参考链接:
[1] https://assimp-docs.readthedocs.io/en/latest/usage/use_the_lib.html
[2] https://learnopengl.com/Model-Loading/Assimp
欢迎关注个人公众号,实时推送最新博文!
更多推荐



所有评论(0)