macrozone
macrozone

Reputation: 869

ARKit only detect floor to place objects

In ARKit i can use hitTest:tapPoint types:ARHitTestResultTypeExistingPlaneUsingExtent

This works if you want to place objects on e.g. tables as types:ARHitTestResultTypeExistingPlaneUsingExtent will only detect hits within the extent of the detected plane.

It is less usefull if you want to place objects on the floor, because you need to have to walk around until ARKit has placed (or extended) a lot of planes across your floor.

ARHitTestResultTypeExistingPlane solves that issue, because you just need to have detected a small patch of your floor and can place objects everywhere. The problem is however as soon as ARKit has detected another plane that doesn't correspond to the floor (e.g. a table), every object will be placed on that higher surface.

Is it possible to control which planes are used for the hittest?

Upvotes: 2

Views: 2145

Answers (1)

rickster
rickster

Reputation: 126177

The hit testing methods return multiple results, sorted by distance from the camera. If you're hit testing against existing planes with infinite extent, you should see at least two results in the situation you describe: first the table/desk/etc, then the floor.

If you specifically want the floor, there are a couple of ways to find it:

  • If you already know which ARPlaneAnchor is the floor from earlier in your session, search the array of hit test results for one whose anchor matches.

  • Assume the floor is always the plane farthest from the camera (the last in the array). Probably a safe assumption in most cases, but watch out for balconies, genkan, etc.

Upvotes: 2

Related Questions