[英]Get distance to surface with ARKit
I've begun experimenting with ARKit, and I have ran into an issue. 我已经开始尝试使用ARKit了,我遇到了一个问题。 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. 假设我使用的是包含平面对象的
.scn
文件。 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 您可以使用hitTest来返回包含距离和变换等信息的结果: 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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.