目录
1 编译assimp5.0.1
编译过程与我的博客win10操作系统上编译assimp库_liji_digital的博客-CSDN博客描述类似。但是由于assimp5.0.1的版本较高,vs2013编译源码会报错。错误原因是BaseImporter::importerUnits采用了初始化列表赋值,不受2013支持。假如你坚持使用vs2013,可以用std::map::insert()函数代替初始化列表。
BaseImporter::BaseImporter() AI_NO_EXCEPT
: m_progress() {
importerUnits.insert(std::pair<ImporterUnits, double>(ImporterUnits::M, 1));
importerUnits.insert(std::pair<ImporterUnits, double>(ImporterUnits::CM, 0.01));
importerUnits.insert(std::pair<ImporterUnits, double>(ImporterUnits::MM, 0.001));
importerUnits.insert(std::pair<ImporterUnits, double>(ImporterUnits::INCHES, 0.0254));
importerUnits.insert(std::pair<ImporterUnits, double>(ImporterUnits::FEET, 0.3048));
}
编译结束后,build/code/Debug目录下出现文件assimp-vc120-mtd.dll(lib)
2 工程
2.1 pro文件:
#-------------------------------------------------
#
# Project created by QtCreator 2022-04-22T13:36:43
#
#-------------------------------------------------
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = widget
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp \
mesh.cpp \
model.cpp \
camera.cpp
HEADERS += widget.h \
mesh.h \
model.h \
camera.h
DISTFILES += \
model.frag \
model.vert
INCLUDEPATH += "C:/code/assimp-5.0.1/include"
LIBS += -L"C:/code/assimp-5.0.1/build/code/Debug" -lassimp-vc120-mtd
工程中其他文件来自Learn OpenGL with Qt——加载3D模型_Italink的博客-CSDN博客_qt加载多个模型,略有改动。我的资源CSDNhttps://mp.csdn.net/mp_download/manage/download/UpDetailed也提供下载。
注意2点:
2.2 config.h
assimp3.1.1中有config.h,而assmp5.0.1中没有config.h,取而代之的是config.h.in。在5.0.1的defs.h中,引用了并不存在的config.h,导致编译失败。解决办法是把#include <assimp/config.h>改为
#include <assimp/config.h.in>
2.3 config.h.in中注释掉如下代码:
#cmakedefine ASSIMP_DOUBLE_PRECISION 1
3 运行效果