I'm new to this and currently building an AR-related application, on the old version I stated this
let results = self.hitTest(screenPosition, types: [.featurePoint])
and now I have a problem where the hitTest is deprecated in iOS 14.0
hitTest(_:types:)' was deprecated in iOS 14.0: Use [ARSCNView raycastQueryFromPoint:allowingTarget:alignment]
please advise me on how to fix it, thank you :)
The behavior of a hit test depends on which types you specify and the order you specify them in. For details, see ARHitTestResult and the various ARHitTestResult.ResultType options.
If you use ARKit with a SceneKit or SpriteKit view, the ARSCNView hitTest(_:types:) or ARSKView hitTest(_:types:) method lets you specify a search point in view coordinates. The behavior of a hit test depends on which types you specify and the order you specify them in.
If you use ARKit with a SceneKit or SpriteKit view, the ARSCNView hitTest (_:types:) or ARSKView hitTest (_:types:) method lets you specify a search point in view coordinates. The behavior of a hit test depends on which types you specify and the order you specify them in.
Hit testing searches for real-world objects or surfaces detected through the AR session's processing of the camera image. A 2D point in the image coordinates can refer to any point along a 3D line that starts at the device camera and extends in a direction determined by the device orientation and camera projection.
You can assign a node with a name and then use hitTest(point:, options:[SCNHitTestOption : Any]?)
in touchesBegan
.
Below is the code I used:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let touchLocation = touch.location(in: sceneView)
let results = sceneView.hitTest(touchLocation, options: [SCNHitTestOption.searchMode : 1])
for result in results.filter({$0.node.name != nil}) {
if result.node.name == "planeNode" {
print("touched the planeNode")
}
}
}
}
Yes, use raycastQuery(from:allowing:alignment:)
as suggested by Xcode in this way:
...
let location = gesture.location(in: sceneView)
guard let query = sceneView.raycastQuery(from: location, allowing: .existingPlaneInfinite, alignment: .any) else {
return
}
let results = sceneView.session.raycast(query)
guard let hitTestResult = results.first else {
print("No surface found")
return
}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With