c++ - 无法使用导出器类使用 assimp 导出模型

标签 c++ objective-c macos blob assimp

我正在使用 assimp 库将模型加载到我的 ios 应用程序中。但对于一些大型模型文件,加载时间对于移动应用来说太长了。

考虑转换过程时间。我决定在运行前通过工具转换我的模型。

我的主要目标是将这个场景写入文件。

我有非常基本的 C++ 经验。 首先,我尝试了 assimp::expoerter 类。

我在打开导出设置的情况下遵守了 assimp 库。

但是当我尝试使用导出方法时,我收到此错误消息。

No matching member function for call to 'Export'

error capture

方法有,但我不会用。

scene = (aiScene*) aiImportFile([[openPanel filename] cStringUsingEncoding:[NSString defaultCStringEncoding]], aiPostProccesFlags | aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_PreTransformVertices | 0 );
                
if (scene) {
    
    NSString *pPath = [openPanel filename];
    pPath =[NSString stringWithFormat:@"%@%@", pPath, @"_new"];
    NSLog(@"New file Path : %@", pPath);
    
    Assimp::Exporter *exporter = new Assimp::Exporter();
    exportFormatDesc = exporter->GetExportFormatDescription(0);
    
    exporter->Export(scene, exportFormatDesc->id, pPath);
    
    const aiExportDataBlob *blob = exporter->ExportToBlob(scene, exportFormatDesc->id);
    size_t blobSize = blob->size;
    aiString blobName = blob->name;
    
}

然后通过阅读Assimp::Exporter Class Reference让我想到使用 aiExportDataBlob创建文件。

ExportToBlob which returns a linked list of memory buffers (blob), each referring to one output file (in most cases there will be only one output file of course, but this extra complexity is needed since Assimp aims at supporting a wide range of file formats).

ExportToBlob is especially useful if you intend to work with the data in-memory.

const aiExportDataBlob *blob = exporter->ExportToBlob(scene, exportFormatDesc->id);
size_t blobSize = blob->size;
aiString blobName = blob->name;

但我不知道要写这个blob到一个文件。

感谢任何建议或帮助。

最佳答案

您在函数需要 const char * 的地方传递 NSString *。我不熟悉 Objective-C,但我想你想要 [pPath UTF8String]NSString 获取指向 C 风格字符数组的指针。

(此外,您正在泄漏 Exporter:C++ 没有垃圾回收功能。我确定您不想使用 new 创建它,但是,如果出于某种原因确实需要,请记住在完成后删除它)。

关于c++ - 无法使用导出器类使用 assimp 导出模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17895776/

相关文章:

macos - 使用 Bash 解析 ifconfig 以仅获取我的 IP 地址

c++ - 你如何连接两个字符串?

c++ - 静态库与动态库

objective-c - NSDateFormatter 具有自定义格式的相对日期格式

ios - 如何在 objective-c 中打假电话

macos - Apple 的颜色选择器可以从任何地方打开吗?

objective-c - 动态列出类的IBOutlets

c++ - std::transform 需要特别注意集合

C++错误使用类模板需要模板参数列表

iphone - cocos2d : Show entire layer then zoom in on character