无法显示缓存目录中的 3d 文件

Can't display 3d file from cache directory

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

我似乎无法显示缓存目录中的 3d 文件。我遇到此错误 SceneKit IO: 错误,此平台不支持 COLLADA 文件。

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

导入 COLLADA 3D 对象并构建由相机、灯光和网格组成的场景。 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 Class Reference有一个table:

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 压缩场景。

我在 this answer 上找到了以下评论:

To convert the dae file to a file that can be read by SCNScene(named:... you can convert the file manually by using the following commandline in 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 (Of course, replace InFile.dae and OutFile.dae by your own filenames) Sorry, no real formatting possible in comments. – Marcus Feb 2 at 18:23

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