SceneKit. Which way is up?
Asked Answered
B

1

7

It seems that most 3D authoring applications use Z as the 'Up' axis. While SceneKit uses Y as the 'Up' axis. SceneKit allows you to load scenes as Collada .DAE files. When loading a Scene via either:

SCNScene(named: String?, inDirectory: String?, options: [NSObject : AnyObject]?)

or

SCNSceneSource(URL url: NSURL!, options: [NSObject : AnyObject]!)

You can specify options including SCNSceneSourceConvertToYUpKey and SCNSceneSourceConvertUnitsToMetersKey.

Setting these accordingly, I expected the various nodes to be transformed and scaled when I added them to my own scene constructed from Nodes in the loaded scene. But these options appear to have no effect.

let myScene = SCNScene(named: "Scene.dae", inDirectory: nil, options: [SCNSceneSourceConvertToYUpKey:true, SCNSceneSourceConvertUnitsToMetersKey:25.4])

Have I misunderstood the meaning of these option parameters?

Boykin answered 14/7, 2014 at 14:46 Comment(4)
The only Z-up app I've used is Blender. The standard is Y-up, right-handed. what else are you using that uses Z-up?Primrosa
Both Sketchup and 3DS Max use Z-Up too, and also seem to default to inches as the base unit.Boykin
I think I might have found the problem. SceneKit: warning, SCNSceneSourceConvertUnitsToMetersKey and SCNSceneSourceConvertToYUpKey have no effect on compressed assets. Use Xcode's compression options insteadBoykin
But setting the file to uncompressed gives the following error : SceneKit IO: error, COLLADA files are not supported on this platform. So it seems these options are not supported for DAE files?Boykin
I
10

SceneKit does not directly load DAE (or ABC) files on iOS -- it loads scenes from a private Apple format, which Xcode automatically converts to when you include scene files in your project. Part of this conversion is the option to transform the up axis.

I don't believe that option is exposed when you simply include the DAE file as a bundle resource. (That might be a good bug to file.) However, it's a good idea to use the new SceneKit Asset Catalog feature instead, anyway -- put your DAE files and whatever external resources (textures) into a folder with a .scnassets extension, and Xcode will process them together to optimize for the target device when you build. Then, when you select that folder in the Xcode navigator, you'll get an editor for scene building options:

SceneKit Asset Catalog options

All the boxes there are good to check. :) (Since the first one doesn't come with an explanation: interleaving means organizing the vertex data for a geometry so you get better GPU-memory locality for fewer cache misses during vertex processing, which is important for performance on embedded devices.)

Hm, I don't see anything about units in there, though. Might be another good bug to file.

There's another option, too -- all SceneKit objects implement the NSSecureCoding protocol, so you can load and preprocess your scene on OS X, then use NSKeyedArchiver to write it out. Include the resulting file in your iOS project as a bundle resource, and Xcode won't preprocess it (it's already as compressed and optimized as it can get) -- and if you name it with an .scn extension, you can use all the SCNScene and SCNSceneSource methods for loading it just like you would a (preprocessed) DAE file.

Isochroous answered 14/7, 2014 at 18:31 Comment(7)
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.Nadean
That command line is useful if you need to do this conversion manually — thanks! But if you're putting your files into an SCNAssets folder in Xcode, it automatically does this conversion for you at build time.Isochroous
Just adding a note that you can run scntool without having to type the entire path to your Xcode install by using: xcrun scntool <arguments here>Tolly
Adding a note to the note: You can also do this directly in Xcode. Select the .dae in your .scnassets catalog and click Editor/Convert to scene file format (.scn).Contorted
Where is that option in the new Xcode 8.1? It disappeared in my opinion, or is it hidden somewhere?Susy
Also when I export a collada file from Maya with z-axis-up the SceneKit editor does not show it with z-axis-up. The finder preview shows it correctly...Susy
Indeed all of those options are gone, including the Y-up axis option, in current Xcode 8.2.1.Volatilize

© 2022 - 2024 — McMap. All rights reserved.