I can't find a good explanation of what a SCNCamera is and it's purpose. This is Apple's definition:
A set of camera attributes that can be attached to a node to provide a point of view for displaying the scene.
This definition isn't clear because I set up the scene and added a SCNNode without attaching a SCNCamera to it. The point of view from the device's camera shows the SCNNode at the location I positioned it at with no problem and the scene is displayed fine.
What is the difference between the device's camera and a SCNCamera?
What is the benefit of attaching a SCNCamera to a SCNNode vs not using one?
If I have multiple SCNNodes (all detached no hierarchy amongst each other) does each node need it's own SCNCamera?
If I have multiple SCNNodes in a hierarchy (parent node with child nodes) does each node need it's own SCNCamera or does just the parent node?
lazy var sceneView: ARSCNView = {
let sceneView = ARSCNView()
sceneView.translatesAutoresizingMaskIntoConstraints = false
sceneView.delegate = self
return sceneView
}()
let configuration = ARWorldTrackingConfiguration()
override func viewDidLoad() {
super.viewDidLoad()
// pin sceneView to the view
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "earth")
let plane = SCNPlane(width: 0.33, height: 0.33)
plane.materials = [material]
plane.firstMaterial?.isDoubleSided = true
let myNode = SCNNode(geometry: plane)
myNode.name = "earth"
myNode.position = SCNVector3(0.0, 0.6, -0.9)
sceneView.scene.rootNode.addChildNode(myNode)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
sceneView.session.run(configuration, options: [])
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillAppear(animated)
sceneView.session.pause()
sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
}
In SceneKit, the
SCNCamerarepresents the point of view from which the user sees a scene. Ray Wenderlich provides a good explanation:You do not need to have a
SCNCamerafor each node. You should only need to have one camera for each angle that you want to show, or even just one. You can move one camera throughout the scene using its parent'spositionproperty.It looks like you're working with ARKit, which behaves a little differently. When using an
ARSCNView, as opposed to a non-ARSCNView, you get the following behvior:You do not need to worry as much about the scene's camera in this case, as it is automatically being controlled by the system so that it matches the device's movement for AR.
For more detail, see Apple's documentation on
SCNCamera: SCNCamera - SceneKit