我正在试验垂直平面,我正在尝试将一个节点放在墙上,并根据垂直平面进行正确的旋转.
这是被挖掘的垂直平面的ARHitTestResult:
let hitLocation = sceneView.hitTest(touchPoint, types: .existingPlaneUsingExtent)
Run Code Online (Sandbox Code Playgroud)
我尝试过以下方法:
let hitRotation = hitLocation.first?.worldTransform.columns.2
Run Code Online (Sandbox Code Playgroud)
和
let anchor = hitLocation.first?.anchor
let hitRotation = anchor?.transform.columns.2
Run Code Online (Sandbox Code Playgroud)
他们中的任何一个似乎都没有工作.
这就是我希望做的事情:
boardNode.eulerAngles = SCNVector3((hitRotation?.x)!, (hitRotation?.y)!, 0)
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我,我会非常感激,因为我还没有找到很多关于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
Run Code Online (Sandbox Code Playgroud)
注意:在这种情况下,.worldOrientation比.rotation更准确,只是想提一下.