I an new to SceneKit. Trying to figure out, how I can reset the pointOfView camera to it original zoom/position so it would cover all nodes in the scene?
I an new to SceneKit. Trying to figure out, how I can reset the pointOfView camera to it original zoom/position so it would cover all nodes in the scene?
@IBOutlet weak var sceneKitView: SCNView! //Your SCNView
var myCamera:SCNNode! //An object to hold your scene's camera
In viewDidLoad, load it with hyour camera's name:
myCamera:SCNNode = scene.rootNode.childNode(withName: "sceneCamera", recursively: true)!
// sceneCamera is my camera node's name in .scn file
sceneKitView.allowsCameraControl = true //Allow camera control
When you want to reset it:
sceneKitView.allowsCameraControl = false
sceneKitView.pointOfView = myCamera
Keep coding......... :)
Just setup a default camera position and orientation to desired values. Use the following code:
func resetCameraToDefaultPosition() {
sceneView.pointOfView?.position = SCNVector3(x: 5, y: 0, z: 5)
sceneView.pointOfView?.orientation = SCNVector4(x: 0, y: 1, z: 0, w: .pi/4)
}
Also, as @mnuages proposed, you can use defaultCameraController instance property to frame all the nodes with 3D geometry in your scene:
func resetCameraToDefaultPosition() {
sceneView.defaultCameraController.frameNodes([coneNode, sphereNode, cubeNode])
}
But the better way is to create a new camera. Here's what Apple documentation says:
Use a node with an SCNCamera instance assigned to its camera property to view a scene. The node provides the position and direction of a virtual camera, and the camera object provides rendering parameters such as field of view and focus.
let cameraNode = SCNNode()
cameraNode.position = SCNVector3(x: CGFloat, y: CGFloat, z: CGFloat)
cameraNode.rotation = SCNVector4(x: CGFloat, y: CGFloat, z: CGFloat, w: CGFloat)
let camera = SCNCamera()
camera.focalLength = 24
cameraNode.camera = camera
Hope this helps.
you can use the frameNodes(_:) method on SCNCameraController to place a camera so that a set of nodes becomes visible.