swift - 在 ARKIt 中使用 SCNFloor

标签 swift scenekit arkit

在几乎所有的ARKit教程中,我们似乎总是使用ARPlane做floor。

let planeGeometry = SCNPlane(width:CGFloat(planeAnchor.extent.x), height:CGFloat(planeAnchor.extent.z))
let planeNode = SCNNode(geometry:planeGeometry)
planeNode.position = SCNVector3(x:planeAnchor.center.x, y:0, z:planeAnchor.center.y)
planeNode.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1.0, 0, 0)

如果您想要一个无限平面(用于转换阴影)怎么办?我尝试了 SCNFloor,结果很奇怪——地板悬在半空中:

let planeGeometry = SCNFloor()
let planeNode = SCNNode(geometry:planeGeometry)
planeNode.position = SCNVector3(planeAnchor.center.x, 0, planeAnchor.center.z)

我已经进行了谷歌搜索,我得到的唯一结果是这个(这也不起作用):https://github.com/arirawr/ARKit-FloorIsLava/blob/master/FloorIsLava/ViewController.swift

SCNFloor() 是否适用于 ARKit?如果没有,我可以做些什么来制造一架大飞机?

最佳答案

如果将地板节点添加到根节点中,则应更改Y 位置:

planeNode.position = SCNVector3(planeAnchor.center.x, -1.0, planeAnchor.center.z)

在这种情况下,我使用负一米^

您可以使用表面检测来找到您的地板表面 anchor ,然后将您的地板添加到该 anchor 的相关节点中。 anchor 的世界坐标已经正确(负 Y),因此您可以使用 SCNVector3Zero 作为地板的位置。

关于swift - 在 ARKIt 中使用 SCNFloor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45930019/

相关文章:

swift - ARKit 的图像识别是否可以对同一张图像进行两次或更多次检测?

ios - 如何使用 ARKit 检测平面

ios - UITextView 中的 UITextField?

swift - 创建一类颜色

ios - 创建更平滑的边缘或以其他方式修复 SCNView 中框上的锯齿状边缘?

swift - SceneKit didApplyAnimationsAtTime 计算时间

tableView.reloadData 上的 Swift fatal error 索引超出范围问题

swift - 在 Swift 中计算与 Int 的时间差

ios - 使用 Swift 将 UIImage 作为 Material 添加到 ARKit 中的 SCNGeometry

swift - Arkit - 3d 模型真实尺寸快速