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.
Specifing
art.scnassets/ship.dae
instead ofship.dae
shoud do.I did some extensive testing, and I believe this is a bug.
The IB property all work, besides the scene one. If you remove all the code in
GameViewController.swift
you will see the background is red, as you defined it in IB.I created a bunch of new projects, in both Swift and Objective-C, iOS and OSX, Game Template and regular application, Storyboard and classic IB. They all had the same problem.
I looked into the IB file, and did not see anything unusual. The property is named
sceneName
, so I had to chececk if the problem was from Scenekit.I decided to dig a little deeper and see where the problem is. I found out SCNView has a private property,
NSString *__ibSceneName;
. Testing this proved that it is correctly set. There is also a private method called- (void)set_ibSceneName:(id)arg1;
. Subclassing it proved that it is correctly called (although it might just be a classic setter).To make sure one last time, I recorded all filesystem interactions using instruments. Here are the results from the normal template:
and here are the results from IB:
My guess is that the implementation of this function might just be missing, or not properly creating the SCNScene. I'll fill a bug report to Apple about it.
In the meantime, you can simply subclass SCNView, and add a custom string property such as
myScene
. You can then set it in IB:Then, simply import the scene from the property and set it on init in your custom subclass. Let me know if you need a code sample!
Edit July 1st: Here's the message I received from Apple: