我正在尝试在osx(Lion 10.7.5)上测试库assimp。但是Demo.app找不到位于Demo.app/Contents/Resources文件夹中的模型文件。奇怪的是,我的旧演示仍然可以正常运行。这是主要代码:
bool ImportModel(const string& pFile)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(pFile, ...);
if(!scene)
{
cout<<importer.GetErrorString()<<endl;
return false;
}
return true;
}
int main(void)
{
while(ImportModel("skin.xml"));
return 0;
}
它不断返回:无法打开文件“ skin.xml”。这是Demo.app的结构:
Contents
Frameworks
info.plist
MacOS
Demo
libassimp.dylib
Resources
Demo.icns
skin.xml -> the model file.
知道哪里可能是错的吗?谢谢你们。
在assimp的文档中,Assimp::Importer::ReadFile
将路径作为第一个参数。似乎没有(至少在文档中没有)针对默认Resources
文件夹路径的任何特定支持。
很有可能您将不得不提供文件的完整路径,以便从那些库中正确读取文件,这意味着获取主捆绑包的资源路径,附加模型文件名,并将最终路径转换为ac。字符串(将成为std :: string)。或者,您可以获取主包的资源路径,将其转换为ac字符串,并将其附加skin.xml
到该字符串。
如果您使用的是Objective-C ++,这非常简单:
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource: @"skin" ofType: @"xml"];
// now get the c string from the path
const char *cPath =[path cStringUsingEncoding: NSUTF8StringEncoding];
如果您希望继续使用C ++,则由于手动内存管理和更广泛的错误检查而有些棘手(在上述情况下,您可以只使用错误检查cPath
,因为Objective-C代码将nil
毫无问题地发出消息)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句