dmsurti / AssimpKit

A library (macOS, iOS) that converts the files supported by Assimp to Scene Kit scenes.
http://assimpkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
477 stars 54 forks source link

Can't manage to export fbx as scn #92

Closed leandrodemarco closed 6 years ago

leandrodemarco commented 6 years ago

This is probably some dumb mistake I'm missing, but been stuck with it for quite a few hours now so I'd appreciate any help or hint to solve it. I have a bunch of .fbx files I'd like to convert to .scn I'm doing it on Mac, with a very tiny simple app which on it's applicationDidFinishLaunching: method has the following lines

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *fbxDir = [paths[0] stringByAppendingPathComponent:@"FBX"];
    NSArray *directoryContent  = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:fbxDir error:nil];

    for (NSString *fileName in directoryContent) {
        NSString *scnFileName = [fileName stringByReplacingOccurrencesOfString:@"fbx" withString:@"scn"];
        NSString *scnFilePath = [[paths[0] stringByAppendingPathComponent:@"SCN"] stringByAppendingPathComponent:scnFileName];

//        if (![[NSFileManager defaultManager] fileExistsAtPath:scnFilePath]) {
//            [[NSFileManager defaultManager] createFileAtPath:scnFilePath contents:nil attributes:nil];
//        }

        SCNAssimpScene *scene = [SCNScene assimpSceneWithURL:[NSURL URLWithString:[fbxDir stringByAppendingPathComponent:fileName]]
                                            postProcessFlags:AssimpKit_JoinIdenticalVertices | AssimpKit_Process_Triangulate];

        if ([scene writeToURL:[NSURL URLWithString:scnFilePath] options:nil delegate:nil progressHandler:nil]) {
            NSLog(@"Serialized success for %@. Output to %@", fileName, scnFilePath);
        } else { NSLog(@"Serialized FAILED for %@", fileName); }
    }
}

In theory everything goes fine as for each one of the files I see the log message: Serialized success for <fileName>.fbx. Output to /Users/Leandro/Documents/SCN/<fileName>.scn

If I forcefully create a file at that path with the commented lines, the file remains 0 bytes in size. I've disabled sandbox of the app as it says here but no changes: https://forums.developer.apple.com/thread/88701

dmsurti commented 6 years ago

@leandrodemarco

You need to write out the modelScene and/or animationScenes inside your SCNAssimpScene object. See: https://dmsurti.github.io/AssimpKit/appledocs/html/Classes/SCNAssimpScene.html

So it should be for example:

[scene.modelScene writeToURL...]
leandrodemarco commented 6 years ago

HI @dmsurti, thanks for the quick reply and for the great work maintaining this library. I forgot to mention in my original post I had also tried writing out the modelScene with exactly same results. Would it help if I upload one of the fbx files? (it weights around 20 MB)

dmsurti commented 6 years ago

@leandrodemarco

thanks for the quick reply and for the great work maintaining this library 👍

Have you also tried loading the file with the macOS/iOS sample apps in the AssimpKit repo? That way you know that there is no problem in reading and viewing the fbx file.

Would it help if I upload one of the fbx files

Sure thing, upload the FBX file. IIUC, you are not able to write this FBX to a scn file? Otherwise, uploading a sample project to GH would also help.

leandrodemarco commented 6 years ago

Sorry for the delay @dmsurti. Here's a link to one of the fbx files: https://ufile.io/zpqe5

IIUC, you are not able to write this FBX to a scn file?

Exactly that, my Mac "app", just contains those lines I posted.

Have you also tried loading the file with the macOS/iOS sample apps in the AssimpKit repo?

I've just cloned the repo. I just opened the workspace and see there's an OSX-Example app. You mean to compile that?

dmsurti commented 6 years ago

@leandrodemarco There is no problem per se in AssimpKit with the fbx model. I loaded it fine and also wrote it out to a .scn file without any issues.

The minimal relevant sample code to save is:


[scene.modleScene writeToURL:panel.URL
                                         options:nil
                                       delegate:nil
                         progressHandler:nil];

I have attached the compressed exported scn file here. kia-hq-anim-00.scn.zip

Orthongal to the export issue, there is a problem in that some geometry is not rendered correctly. I have opened a separate issue for that here:

screenshot 2017-12-15 14 00 40

You can also download an app if you want to verify: http://www.isonapps.com, which is developed using AssimpKit. I have used this app to import your fbx and export it to .scn.

You will need to debug your file path related code; sorry I won't be able to help any further than this.