使用 ARKit 获取到表面的距离

Get distance to surface with ARKit

我已经开始尝试使用 ARKit,但遇到了 运行 个问题。我找不到说明如何将对象放置在最近表面上的教程。

假设我正在使用包含平面对象的 .scn 文件。我知道如何将其放置在相机所在的位置,但我如何获得到最近表面的距离。

抱歉,如果这听起来像是代码请求,但我不确定从哪里开始,任何指导将不胜感激

您可以使用 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)
}