问题遇到的现象和发生背景
使用assimp库想要导入原3D模型 并导出新的格式的3D模型
遇到的现象和发生背景,请写出第一个错误信息
发现官方文档的解释看不懂 他大概不是面向初学者的文档
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
#pragma once
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
#include <iostream>
#include <string.h>
using namespace std;
#define print(x) cout << x << endl
#define printV2(x) cout <<"("<<x[0]<<", "<<x[1]<<")"
#define printV3(x) cout <<"("<<x[0]<<", "<<x[1]<<", "<<x[2]<<")"
#define printColor(x) cout <<"("<<x.r<<", "<<x.g<<", "<<x.b<<")"
#define len(x) sizeof(x)/sizeof(x[0])
#define type(x) typeid(x).name()
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
#include <assimp/IOStream.hpp>
// 这部分主要是导入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;
}
>
运行结果及详细报错内容
官方文档给出的代码可能包含了很多伪代码 入门不久的我根本不能理解 出现很多语法问题和未知问题
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
我只能一个一个语法去解决 但是有些不是语法问题 有些是第三方库的一些设置 根本没法短时间去解决
我想要达到的结果
我只想这 能利用assimp库转换max格式的3D模型 转换为 fbx格式的3D模型