I'm building an ARKit
+ SceneKit
app which requires displaying models on to the real world. Every time a user selects a button, the model changes.
I tried loading a new model apon button press into a node and then adding it to the scene's root node, but this causes the camera to freeze for a few seconds until it is added to the scene.
I then read that it might be better to load all the nodes on start (viewDidLoad
or something), call the scene's prepare
method, and then add the nodes to the scene, but this causes the app to freeze a few times for a few seconds until the process is done. This is what I'm currently doing, and it isn't working well! Any ideas?
Keep in mind the model files are quite heavy (~15MB each)
func addNodesToScene() {
for menuItem in self.menuItems {
let tempScene = SCNScene(named: menuItem.modelPath)!
let node = tempScene.rootNode
node.scale = SCNVector3Make(0.1, 0.1, 0.1)
node.isHidden = true
self.foodNodes[menuItem] = node
print("\(menuItem.title) node loaded")
}
print("done loading nodes - adding to scene")
self.sceneView.prepare(Array(self.foodNodes.values), completionHandler: { (success) in
for nNode in self.foodNodes.values {
self.sceneView.scene.rootNode.addChildNode(nNode)
}
})
}