我正在尝试垂直平面,并且尝试在基于垂直平面的正确旋转下将节点放置在墙上。
这是点击的垂直平面的 ARHitTestResult:
let hitLocation = sceneView.hitTest(touchPoint, types: .existingPlaneUsingExtent)
我尝试了以下方法:
let hitRotation = hitLocation.first?.worldTransform.columns.2
和
let anchor = hitLocation.first?.anchor
let hitRotation = anchor?.transform.columns.2
他们俩似乎都没有工作。
这就是我希望做的:
boardNode.eulerAngles = SCNVector3((hitRotation?.x)!, (hitRotation?.y)!, 0)
如果有人可以帮助我解决这个问题,我将不胜感激,因为我还没有在 ARKit 上找到很多教程。
编辑
所以这是起作用的(感谢 Josh):
let hit = sceneView.hitTest(touchPoint, types: .existingPlaneUsingExtent)
let planeAnchor = hit.first?.anchor as? ARPlaneAnchor
guard let anchoredNode = sceneView.node(for: planeAnchor!) else { return }
let anchorNodeOrientation = anchoredNode.worldOrientation
boardNode.eulerAngles.y = .pi * anchorNodeOrientation.y
注意:在这种情况下,.worldOrientation 比.rotation 更准确。
1 回答
这是您要找的东西吗?在这里,我将屏幕中心用于 CGPoint 值,但是您可以使用 touch 等:
**更新:**如果您不希望旋转与“平面”关联的节点,则可以像这样:
然后根据需要使用它?
进一步更新: