如何使用 Assimp 加载 Blender 文件?

如何使用 Assimp 加载 Blender 文件?

问题描述:

我尝试使用以下代码在 C++ 上使用 Assimp 库加载 Blender 文件,但它失败了,因为它根本没有任何网格.我使用的 Blender 文件是使用 Blender 本身保存的默认立方体.

I tried to load Blender file using Assimp library on C++ using the following code, but it fails since it doesn't have any meshes at all. The blender file I am using is the default cube saved using Blender itself.

Assimp::Importer importer;
const aiScene * scene = importer.ReadFile( path, aiProcessPreset_TargetRealtime_Fast );

if( !scene ) {
    fprintf( stderr, importer.GetErrorString() );
    return false;
}

const aiMesh * mesh = scene->mMeshes[0]; // Fails here since mMeshes is NULL

我在这里做错了什么,我是否需要包含特殊标志才能加载搅拌机对象?还是我需要以某种方式导出 Blender 对象?

What am I doing wrong here, do I need to include special flag in order to load blender object ? Or do I need to export the Blender object in certain way ?

Blender 文件很难被非 Blender 的任何东西阅读和解释.这样做的原因是,Blender 文件实际上是 Blender 进程的结构化内存转储.除非您打算将整个 Blender 实例嵌入到您的程序中,否则您几乎无法解析它.

Blender files are difficult to read and interpret by anything that's not Blender. The reason for this is, that Blender files are in fact structured memory dumps of the Blender process. Unless you plan to embed a whole Blender instance into your program you'll hardly be able to parse it.

相反,您应该使用 Blender 将模型导出为易于处理的文件格式.Blender 附带了大量 3D 文件格式的集合.

Instead you should export your model using Blender into someting easy to process, a well documented file format. Blender ships with a collection for a large number of 3D file formats.