我正在try 从‘diceCollada.scn’文件创建一个新的SCNScene
.
But this file won't be loaded.
该文件位于"ARDicee/art.sets"文件夹中.
不仅是"diceCollada.scn",而且不能加载默认的"ship.scn". 我不知道它为什么不加载文件.
这是我的代码.
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-版本14.1
MacOS Ventura-版本13.0.1
GitHub-This project
我还试着用另一种方式创造SCNScene
.
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)
}
}
但它给出了这个错误.
Error Domain=NSCocoaErrorDomain Code=260"无法打开文件"diceCollada.scn",因为没有这样的文件."UserInfo={NSFilePath=/Applications/xcode/Development/ARDicee/ARDicee/art.scnassets/diceCollada.scn,NSUnderlyingError=0x282924570{错误域=NSPOSIX错误域代码=2"没有这样的文件或目录"}}
我正在try 从‘diceCollada.scn’文件创建一个新的SCNScene
.