无法从caching目录显示3D文件

你能帮我确定这里的问题吗?

看来我无法从caching目录显示3d文件。 我有这个错误SceneKit IO:错误,COLLADA文件不支持在这个平台上。

保存在caching目录中的zip文件包含纹理的.dae文件和.png文件。 使用Scene Kit,您可以:

导入COLLADA 3D对象并构build由摄像头,灯光和网格组成的场景。 https://developer.apple.com/library/mac/documentation/3DDrawing/Conceptual/SceneKit_PG/Introduction/Introduction.html

谢谢。

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ NSURL *url = [NSURL URLWithString:@"my url" NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error]; if(!error) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; NSString *zipPath = [path stringByAppendingPathComponent:@"zipfile.zip"]; [data writeToFile:zipPath options:0 error:&error]; if(!error) { ZipArchive *za = [[ZipArchive alloc] init]; if ([za UnzipOpenFile: zipPath]) { BOOL ret = [za UnzipFileTo: path overWrite: YES]; if (NO == ret){} [za UnzipCloseFile]; NSString *floorFilePath = [path stringByAppendingPathComponent:@"house1.dae"]; NSURL *floorPathURL = [NSURL fileURLWithPath:floorFilePath]; dispatch_async(dispatch_get_main_queue(), ^{ SCNView *sceneView = (SCNView *)self.view; sceneView = (SCNView *)self.view; sceneView.allowsCameraControl = YES; sceneView.autoenablesDefaultLighting = YES; sceneView.backgroundColor = [UIColor whiteColor]; sceneView.scene = [SCNScene sceneWithURL:floorPathURL options:nil error:nil]; }); } } else { NSLog(@"Error saving file %@",error); } } else { NSLog(@"Error downloading zip file: %@", error); } }); 

SCNSceneSource类参考有一个表格:

 Format Filename Extension Supported in Collada Digital Asset Exchange .dae OS X v10.8 and later Alembic .abc OS X v10.10 and later SceneKit compressed scene .dae or .abc OS X v10.10 and later iOS 8.0 and later SceneKit archive .scn OS X v10.10 and later iOS 8.0 and later 

你确定你的.dae文件是一个“SceneKit压缩场景”吗? 显然,iOS只支持从.dae文件加载压缩的场景。 当编译你的应用程序时,Xcode应该会自动将你的Collada .dae转换为压缩的场景(具有相同的扩展名)。 如果您从应用程序包外部(例如,在运行时从URL)加载文件,则不会是SceneKit压缩的场景,除非您已采取措施将其转换到其他位置。

我在这个答案中发现了以下评论:

要将dae文件转换为可以通过SCNScene读取的文件(命名为:…,您可以通过在terminal中使用以下命令行手动转换文件: /Applications/Xcode.app/Contents/Developer/usr/bin/scntool –convert InFile.dae –format c3d –output OutFile.dae –force-y-up –force-interleaved –look-for-pvrtc-image (当然,将InFile.dae和OutFile.daereplace成你自己的文件名)对不起,没有真正的格式可能在评论 – Marcus 2月2日在18:23

我不知道这些标志是否适合您的使用。 根据这个网站 ,还有一个名为copySceneKitAssets (在同一个Xcode子目录中)转换.scnassets目录的命令行程序,所以也许这就是你想要的。