0

Goal: save scn file to disk.

What I did: Trying to use this API: https://developer.apple.com/documentation/scenekit/scnscene/1523577-write

Problem: Get this error: AttributeGraph: cycle detected through attribute 248096 === The operation couldn’t be completed. (MDLErrorDomain error 0.)

Any help is much appreciated!

  let scnScene = SCNScene(named: "Art.scnassets/Ship")!

//get documents URL
func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}
  //save scn to disk
    func saveSCNFileToDisk() {
        let url = getDocumentsDirectory()
        scnScene.write(to: url, options: nil, delegate: nil) { float, error, pointer in
            if let error = error {
                print(error.localizedDescription)
                return
            }
            self.scene = url.absoluteString
            
        }
    }
Mane Manero
  • 3,086
  • 5
  • 25
  • 47

1 Answers1

0

Your code should specify the file scheme as described in the docs

//save scn to disk
func saveSCNFileToDisk() {
    let url = getDocumentsDirectory().appendingPathComponent("someFleName.scn)
    scnScene.write(to: url, options: nil, delegate: nil) { float, error, pointer in
        if let error = error {
            print(error.localizedDescription)
            return
        }
        self.scene = url.absoluteString
        
    }
}
CloudBalancing
  • 1,461
  • 2
  • 11
  • 22