5

Can you please help me determine the problem here?

It seems that I can't display the 3d file from cache directory. I'm having this error SceneKit IO: error, COLLADA files are not supported on this platform.

The zip file im saving in the cache directory contains .dae file and .png for the texturee. With Scene Kit you can:

Import COLLADA 3D objects and build scenes composed by cameras, lights, and meshes. https://developer.apple.com/library/mac/documentation/3DDrawing/Conceptual/SceneKit_PG/Introduction/Introduction.html

Thanks.

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);
    }

});
user3316454
  • 89
  • 2
  • 7
  • It's easier for you to do it in the debugger. Simply but a breakpoint on that method and check that the objects/variables are in the expected state at each step. – trojanfoe May 07 '15 at 10:40
  • @trojanfoe yes i did put a break poin and it has the files in tge right dirtectory the problem is its not displaying in my scene view – user3316454 May 07 '15 at 11:48
  • A ".dae" file is a COLLADA file, and the error message says "COLLADA files are not supported on this platform". Is that confusing? – rob mayoff May 08 '15 at 01:33
  • man I tried to run .dae file locally and it is working. – user3316454 May 08 '15 at 01:53
  • With Scene Kit you can: Import COLLADA 3D objects and build scenes composed by cameras, lights, and meshes. https://developer.apple.com/library/mac/documentation/3DDrawing/Conceptual/SceneKit_PG/Introduction/Introduction.html – user3316454 May 08 '15 at 03:07

1 Answers1

11

The SCNSceneSource Class Reference has a 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

Are you sure your .dae file is a “SceneKit compressed scene”? Apparently, iOS only supports loading compressed scenes from .dae files. Xcode should automatically convert your Collada .dae to a compressed scene (with the same extension) when it compiles your app. If you're loading the file from outside your app bundle (e.g. from a URL at runtime), it won't be a SceneKit compressed scene unless you've taken steps to convert it elsewhere.

I found the following comment on 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

I don't know if all those flags are appropriate for your use. According to this web site, there's also a command-line program named copySceneKitAssets (in the same Xcode subdirectory) that converts .scnassets directories, so maybe that's what you want to use.

Community
  • 1
  • 1
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • 2
    Im not sure about that, but the zip file contains .dae and the texture which is .png file, I already tried to display the .dae file locally and it worked, wbut when im doing this process which is im getting the zip file from the url and then unzip it and save it in cache directory it shows that COLLADA files are not supported. – user3316454 May 08 '15 at 03:48
  • I've updated my answer. If the `.dae` file isn't part of your app bundle, it won't be in the right format. – rob mayoff May 08 '15 at 03:48
  • okay thanks, that makes sense, what process you think I can do with it in order to make it a ScenKit compressed scene? – user3316454 May 08 '15 at 03:50
  • Conversion using `scntool` solved my problem and now I can show remote `dae` file. Thank you! – imike Feb 29 '20 at 22:42