I created a new project using the iOS game template on Xcode 6.1.1, the options were:
Language: Swift
Game Technology: SceneKit
Device: Universal
The app runs ok "as is", but now I want to specify the .dae file directly from the Interface Builder on Xcode, so I changed the method in the view controller like this:
override func viewDidLoad() {
super.viewDidLoad()
let scnView = self.view as SCNView
// customize the loaded scene
if let scene = scnView.scene {
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// the code here is never executed because scnView.scene is nil
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)
// retrieve the ship node
let ship = scene.rootNode.childNodeWithName("ship", recursively: true)!
// animate the 3d object
ship.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(0, y: 2, z: 0, duration: 1)))
}
}
...and picked out the ship.dae file on the storyboard like this
Why isn't the .dae file being loaded? like for instance when using an Image View instead of a SceneKit View, and choosing some .png file from the resources in the application bundle
This is the zip file with the project, if anyone want's to give it a try.