ADAM _YONEDA
ADAM _YONEDA

Reputation: 63

Swift-SceneKit-Can not load '.scn' file from 'art.scnassets'

I'm trying to create a new SCNScene from 'diceCollada.scn' file. But this file won't be loaded. enter image description here

This file is in "ARDicee/art.assets" folder.

Not only "diceCollada.scn", but also it cannot load the default "ship.scn". I don't know why it doesn't load files.


Here is my code.


import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {
    
    @IBOutlet var sceneView: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the view's delegate
        sceneView.delegate = self
        
        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true
         
        // Create a new scene. ---------- The error is here ---------------
        guard let diceScene = SCNScene(named: "art.scnassets/diceCollada.scn") else {
            fatalError()
        }
        // Setting node
        if let diceNode = diceScene.rootNode.childNode(withName: "Dice", recursively: true) {
            diceNode.position = SCNVector3(x: 0, y: 0, z: -0.1)
            sceneView.scene.rootNode.addChildNode(diceNode)
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if ARWorldTrackingConfiguration.isSupported {
            
            // Create a session configuration
            let configuration = ARWorldTrackingConfiguration()

            // Run the view's session
            sceneView.session.run(configuration)
        }
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        // Pause the view's session
        sceneView.session.pause()
    }
}


Xcode - Version 14.1

macOS Ventura - Version 13.0.1

GitHub - This project


I also tried to create SCNScene another way.

override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the view's delegate
        sceneView.delegate = self
        
        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true

        // --- Another way to create SCNScene ---
        let filePath = URL(fileURLWithPath: "/Applications/xcode/Development/ARDicee/ARDicee/art.scnassets/diceCollada.scn")
        do {
            let diceScene = try SCNScene(url: filePath)
            if let diceNode = diceScene.rootNode.childNode(withName: "Dice", recursively: true) {
                diceNode.position = SCNVector3(x: 0, y: 0, z: -0.1)
                sceneView.scene.rootNode.addChildNode(diceNode)
            }
        } catch {
            print(error)
        }
    }

But it gave this error.

Error Domain=NSCocoaErrorDomain Code=260 "The file “diceCollada.scn” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Applications/xcode/Development/ARDicee/ARDicee/art.scnassets/diceCollada.scn, NSUnderlyingError=0x282924570 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}


I'm trying to create a new SCNScene from 'diceCollada.scn' file.

Upvotes: 4

Views: 1234

Answers (3)

Apneist
Apneist

Reputation: 406

Literally lost a day trying to fix this doing all the above - and anything else I found online - reinstalled XCode, command line tools etc etc nothing worked - BUT the below just worked for me, so posting in case it prevents someone from losing hours like myself:

  1. Copy the contents of the art.scnassets folder to a safe location on hard drive (e.g. a new folder on desktop) - but NOT include the "art.scnassets" folder, just everything below it.

  2. Created a new "art.scnassets" folder (Xcode Menu File>New File>Scenekit Catalog> "art.scnassets").

  3. Drag and drop (copy) the contents from the safe hard drive location in there, and it worked.

So for some reason the folder itself had been corrupted - for an unknown reason, it worked for 2 years on that app - and renaming it or manipulating its contents did nothing, and recreating a new one solved it.

Upvotes: 3

Andy Jazz
Andy Jazz

Reputation: 58043

Resetting the path to command-line tools

There are some issues in your command line tools. As a result, the content in the art.scnassets folder isn't readable. In order to fix this, you need to install the latest version of Command_Line_Tools for Xcode 14.1 and then execute the following commands in Terminal:

sudo xcode-select --reset

sudo xcode-select -switch /Library/Developer/CommandLineTools

enter image description here

Reinstalling command-line tools

Or you can remove the old version of command line tools and install the new one using Terminal:

sudo rm -rf /Library/Developer/CommandLineTools

sudo xcode-select --install

Then restart your Mac.

I had the same problem and these steps helped me.

Renaming

If the above steps still do not help, rename the art.scnassets folder to artisan.scnassets.

Upvotes: 3

ZAY
ZAY

Reputation: 4990

If the app cannot load the spaceship from the apple template, the project might be broken somehow. Try to create a brandnew, default SceneKit/ARKit project, compile it directly and check if the spaceship loads correctly. If yes, copy and paste the code from your current project into the new one. If the spaceship does not even load from a fresh template, your xCode installation could be broken. You can also clean your project build folder or delete derived data, there are articles here on how to do such things. In addition you could share your project here on StackOverflow, so that we can have a look at it.

Upvotes: 3

Related Questions