使用assimp库想要导入原3D模型 并导出新的格式的3D模型
发现官方文档的解释看不懂 他大概不是面向初学者的文档
#pragma once
#include // C++ importer interface
#include // Output data structure
#include // Post processing flags
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define printV2(x) cout <<"("<", " <")"
#define printV3(x) cout <<"("<", " <", "<")"
#define printColor(x) cout <<"("<", " <", "<")"
#define len(x) sizeof(x)/sizeof(x[0])
#define type(x) typeid(x).name()
#include // C++ importer interface
#include // Output data structure
#include // Post processing flags
#include
// 这部分主要是导入3D模型文件
bool DoTheImportThing(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 (nullptr != scene) {
print(importer.GetErrorString());
print("导入模型失败");
return false;
}
// Now we can access the file's contents.
print("成功获取scene 导入模型成功");
// We're done. Everything will be cleaned up by the importer destructor
return true;
}
// 这部分主要是构造IO逻辑
// My own implementation of IOStream
class MyIOStream : public Assimp::IOStream {
friend class MyIOSystem;
protected:
// Constructor protected for private usage by MyIOSystem
MyIOStream();
public:
~MyIOStream();
size_t Read(void* pvBuffer, size_t pSize, size_t pCount) { ... }
size_t Write(const void* pvBuffer, size_t pSize, size_t pCount) { ... }
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) { ... }
size_t Tell() const { ... }
size_t FileSize() const { ... }
void Flush() { ... }
};
// Fisher Price - My First Filesystem
class MyIOSystem : public Assimp::IOSystem {
MyIOSystem() { ... }
~MyIOSystem() { ... }
// Check whether a specific file exists
bool Exists(const std::string& pFile) const {
..
}
// Get the path delimiter character we'd like to see
char GetOsSeparator() const {
return '/';
}
// ... and finally a method to open a custom stream
IOStream* Open(const std::string& pFile, const std::string& pMode) {
return new MyIOStream(...);
}
void Close(IOStream* pFile) { delete pFile; }
};
// 现在您的 IO 系统已实现,通过调用将其实例提供给 Importer 对象
Assimp::Importer::SetIOHandler().
// 这部分主要是导出3D模型
bool exporterTest() override {
::Assimp::Importer importer;
::Assimp::Exporter exporter;
const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure);
exporter.Export(scene, "obj", ASSIMP_TEST_MODELS_DIR "/OBJ/spider_out.obj");
return true;
}
>
官方文档给出的代码可能包含了很多伪代码 入门不久的我根本不能理解 出现很多语法问题和未知问题
我只能一个一个语法去解决 但是有些不是语法问题 有些是第三方库的一些设置 根本没法短时间去解决
我只想这 能利用assimp库转换max格式的3D模型 转换为 fbx格式的3D模型
回答不易,求求您采纳点赞哦
要使用 ASSIMP 库将 MAX 格式的 3D 模型转换为 FBX 格式,您可以按照以下步骤操作:
在您的系统上安装 ASSIMP 库。您可以从官方网站 ( https://www.assimp.org/ ) 下载该库,并按照您的特定操作系统的说明进行安装。
使用您选择的编程语言(例如 C++、Python)编写程序,使用 ASSIMP 库加载 MAX 格式的 3D 模型。
使用aiExportScene()ASSIMP库提供的函数将加载的模型导出为FBX格式。
提供输出文件的路径和导出格式作为函数的参数aiExportScene()。
运行程序将 3D 模型从 MAX 格式转换为 FBX 格式。
下面是 C++ 中的一些示例代码:
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/Exporter.hpp>
int main() {
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile("path/to/input.max", aiProcess_Triangulate | aiProcess_FlipUVs);
Assimp::Exporter exporter;
exporter.Export(scene, "fbx", "path/to/output.fbx");
return 0;
}
请注意,这只是一个示例代码,可能需要根据您的具体用例进行额外的错误检查和处理。