无法通过使用Exporter类导出具有assimp的模型 [英] Can't export models with assimp by using exporter class

查看:488
本文介绍了无法通过使用Exporter类导出具有assimp的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用assimp库将模型加载到我的ios应用中.但是对于某些大型模型文件,对于mobil应用程序而言,加载时间太长.

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

我的主要目标是将此场景写入文件.

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

我已将具有导出设置的assimp库编译为

.

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

No matching member function for call to 'Export'

方法在那里,但我不能使用.

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返回一个链接的内存缓冲区列表(blob),每个内存缓冲区都引用一个输出文件(在大多数情况下,当然只有一个输出文件,但是这种额外的复杂性是必需的,因为Assimp旨在支持广泛的范围文件格式).

如果您打算使用内存中的数据,ExportToBlob尤其有用.

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

但是我不知道将此 blob 写入文件. >

任何建议或帮助表示赞赏.

解决方案

您正在传递NSString *,其中函数期望使用const char *.我不熟悉Objective-C,但我想您想要Assimp::Exporter Class Reference gives me the idea of using aiExportDataBlob to create file.

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;

But i have no idea to write this blob to a file.

Any advice or help appreciated.

解决方案

You're passing NSString * where the function expects const char *. I'm not familiar with Objective-C, but I think you want [pPath UTF8String] to get pointer to a C-style character array from the NSString.

(Also, you're leaking the Exporter: C++ doesn't have garbage collection. I'm sure you don't want to create it with new but, if you do need to for some reason, remember to delete it when you're done).

这篇关于无法通过使用Exporter类导出具有assimp的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆