how to convert .dae to .scn files in SceneKit
Asked Answered
E

3

41

This is a screenshot from Apple's Fox sample code. As you can see, they use .scn file format for graphics object. They explicitly state in the wwdc2015 video that this was done by an artist. So far I only worked with .dae and was until recently convinced that this is the only supported format. My question is, how do I export objects stored in .dae file to .scn file?

enter image description here

EDIT: this is what I get if go to Editor-> Convert to SceneKit scene file format (.scn)

enter image description here

Evening answered 25/7, 2015 at 15:14 Comment(1)
I don't know a lot about 3D modeling (what program do you use to create a .dae file?). I do know that you don't need to make a .scn model, as SpriteKit textures can be .png files.Avernus
E
38

Exporting the .dae is unnecessary; you can place the object directly into a .scn file:

enter image description here

Create the new .scn file in the .scnassets folder, then drag the .dae file into the scene.

Elidaelidad answered 25/7, 2015 at 16:22 Comment(4)
that's great. Thx I'L'I. Btw, how do you create .scnassets folder? Assets Catalog template from Resource panel doesn't allow creation of .scnassets folders-Evening
If you choose New > Project > Game, the .scnassets folder gets created automatically.Renshaw
Or if you choose Asset Catalog from the template and in the file name prompt enter art.scnassts instead of xcassets Xcode will prompt you asking if you would like to use scnassets as the extension just select yes.Quasi
I found that the materials will only get converted when in PNG format - as DAE objects also allow JPEG images it is important to convert them to PNG otherwise they will not show in the converted SCN file!Dutyfree
A
28

open your DAE file in the SceneKit scene editor, then go to the Editor menu and click "Convert to scn file format".

Your artist won't be able to export a scn file from their favourite tool. You'll have to use Xcode to convert a DAE to SCN.

Abernethy answered 25/7, 2015 at 17:29 Comment(4)
I used your way but I get some strange message. I updated the question with picture. After I click convert there is no .scn folder in my bundle. Where does it put it?Evening
make sure to hit Cmd-S in Xcode beta. Depending on your choice (convert or duplicate) it should replace or be added next to the DAE file.Abernethy
Strange behaviour. After cmd-s it turned red. I had to manually change file extension to get it working.Evening
is your document part of an open workspace or project? We are aware of some issues in Xcode 7 beta 4.Abernethy
D
0

You can programmatically convert .dae to .scn using the following code. The instance method called write(to:options:delegate:progressHandler:) works in iOS 10.0+ and macOS 10.9+.

import SceneKit

class GameViewController: NSViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let sceneView = self.view as! SCNView
        sceneView.allowsCameraControl = true
        let dae = SCNScene(named: "art.scnassets/model.dae")!
        
        
        let path = FileManager.default.urls(for: .documentDirectory,
                                             in: .userDomainMask)[0]
                                          .appendingPathComponent("Model.scn")
        
        dae.write(to: path, options: nil, delegate: nil, progressHandler: nil)
        print(path)
        
        let scene = try! SCNScene(url: path)
        sceneView.scene = scene
    }
}
Deerdre answered 5/5, 2022 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.