Home > Software design >  Swift-SceneKit-Can not load '.scn' file from 'art.scnassets'
Swift-SceneKit-Can not load '.scn' file from 'art.scnassets'

Time:12-03

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 - 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.

CodePudding user response:

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.

  • Related