I have positive hit test results with following tapped function but when I set camera's "zFar" (to enable farther nodes to be displayed), hit test (performed on the node that previously worked and is in direct view to camera) stops working.. can that be a memory issue caused by huge number of nodes? Other behaviour of the scene is just normal.
sceneView.defaultCameraController.pointOfView?.camera?.zFar = 5000
@IBAction func tapped(_ sender: UITapGestureRecognizer) {
let currentTouchLocation: CGPoint = sender.location(in: sceneView)
guard let hitTestResultNode = self.sceneView.hitTest(currentTouchLocation, options: nil).first?.node else { return }
print("hitTestResultNode",hitTestResultNode.name,hitTestResultNode)
hitPlace.text = hitTestResultNode.name
}
This error is logged (Haven't found any topic in Google): [SceneKit] Error: error in C3DProjectionInfosUnproject // and hitTestResultNode = []
EDIT: Partial solution found:
sceneView.defaultCameraController.pointOfView?.camera?.zFar = 5000
replaced by:
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3Make(0, 0, 0)
sceneView.scene.rootNode.addChildNode(cameraNode)
sceneView.pointOfView?.camera?.zFar = 5000
Now I am able to perform hit test while having zFar set to 5000 but when I go farther like setting 50000 the error is back again and result is empty array again.
EDIT: Finally working as requested after adding this line of code.
sceneView.pointOfView?.camera?.zNear = 1