I'm doing a SceneKit project using Playgrounds in Xcode. However, when I try to load my field model into the scene, it never appears. I did some debugging and I think my function is not being able to find the file.
Here's my code:
// MARK: - Field Setup
private func setupField() {
if let modelNode = loadField() {
// Positioning and scaling
modelNode.position = SCNVector3(0, 0, -32.5)
modelNode.scale = SCNVector3(0.5, 0.5, 0.5)
scene.rootNode.addChildNode(modelNode)
}
}
private func loadField() -> SCNNode? {
// Tries to find a scene named "field.dae"
if let fieldScene = SCNScene(named: "field.dae") {
let modelNode = SCNNode()
for childNode in fieldScene.rootNode.childNodes {
modelNode.addChildNode(childNode)
}
return modelNode
}
return nil
}
}
The loadField() method stops in the if let statement and returns nil. What am I doing wrong?
I tried to write the full path of the model in the if let fieldScene = SCNScene(named: "Full/Path/field.dae", it didn't work.
Maybe something with the .dae extension?