Assimp 编译(Visual Studio 2019)

一、前言

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

四、编译

  1. 打开 cmake-gui.exe

  2. 配置环境变量选择源码路径与输出目录
    在这里插入图片描述

  3. 点击 Configure 配置想要输出 x64 版本 (x86 版本自己选择 win32)
    在这里插入图片描述

  4. 点击 Configure 完成后,再点击 Generate
    在这里插入图片描述

出现以下警告忽略即可,不影响编译
在这里插入图片描述

  1. 点击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

五、配置环境

  1. 配置 Include 文件
  • 将导出工程中的 config.h 拷到源码 include/assimp 目录中,或直接拷贝到VS include 目录,否则在引用 assimp 库会报以下错误
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 将源码 include 目录拷贝到 VS2019 安装目录下的 \Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\include
    在这里插入图片描述

  1. 配置 .lib 文件
    将编译好的 assimp-vc142-mt.lib 拷贝到 \Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\lib目录,注意区分x86 和 x64
    在这里插入图片描述

  2. 配置 .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

欢迎关注个人公众号,实时推送最新博文!
在这里插入图片描述

  • 16
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值