简体   繁体   中英

Get distance to surface with ARKit

I've begun experimenting with ARKit, and I have ran into an issue. I can't find a tutorial which shows how to place an object on the nearest surface.

Let's say I am using a .scn file that contains a flat object. I know how to place that where the camera is, but how would I get the distance to the nearest surface.

例如在此图像中,它可以检测到桌子的距离。

Sorry if this sounds like a code-request, but I am not sure where to start, any guidance would be much appreciated

You can use the hitTest that might return you results that contains informations such as distance and transform: https://developer.apple.com/documentation/arkit/arhittestresult

for result in sceneView.hitTest(CGPoint(x: 0.5, y: 0.5), types: [.existingPlaneUsingExtent, .featurePoint]) {
  print(result.distance, result.worldTransform)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM