2
votes

Following Apple's Creating an Immersive AR Experience with Audio , I thought it would be interesting to experiment and try to place objects anywhere and not just on a vertical and horizontal plane. Is it at all possible to place an object using touch without plane detection? I understand that plane detection would increase the accuracy of hit tests and ARAnchor detection, so would there be any way where one could perform hit tests on any other location in the scene?

1

1 Answers

0
votes

If your AR scene already contains any 3D geometry in a current session you can definitely use hit-testing to place a new model there (a placement based on already contained 3D geometry), or you can use feature points for model's placement (if any).

If there's no 3D geometry at all in your AR scene, or there's a extremely sparse point cloud, what do you apply hit-testing method to? Hit-test is a projected 2D point from screen-space onto a 3D surface (remember, detected planes are hidden 3D planes), or onto any appropriate feature point.

So, in AR, plane detection is crucial when developer is using hit-testing.

func hitTest(_ point: CGPoint, 
               types: ARHitTestResult.ResultType) -> [ARHitTestResult]

Here you can see all the ARHitTestResult.ResultType available.

But pay attention to this, there's a hitTest method returning SCNHitTestResult:

func hitTest(_ point: CGPoint, 
             options: [SCNHitTestOption : Any]?) -> [SCNHitTestResult]

Usage:

let touchPosition: CGPoint = gesture.location(in: sceneView)

let hitTestResult = sceneView.hitTest(touchPosition, 
                                      types: .existingPlaneUsingExtent)

or:

let hitTestResult = sceneView.hitTest(touchPosition, 
                                      types: .featurePoint)

enter image description here

Also, hit-testing is actively used in 3D games but it's rather for VR there than for AR.