下面的代碼將SCNPlane放置到所觸摸的點上,但是該平面的方向(旋轉)爲手機在應用程序啓動時的位置。理想情況下,我希望將節點定位到實體牆或攝像機的當前方向。這是如何與ARKit完成的?如何使用ARKit將SCNNode的方向更改爲相機
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {return}
let result = sceneView.hitTest(touch.location(in: sceneView), types: [ARHitTestResult.ResultType.featurePoint])
guard let hitResult = result.last else {return}
let hitTransform = SCNMatrix4.init(hitResult.worldTransform)
let hitVector = SCNVector3Make(hitTransform.m41, hitTransform.m42, hitTransform.m43)
createPlane(position: hitVector)
}
func createPlane(position: SCNVector3) {
let background = SCNNode()
background.geometry = SCNPlane.init(width: 0.12, height: 0.10) // better set its size
background.geometry?.firstMaterial?.diffuse.contents = "odinBW2.jpeg"
background.position = position
sceneView.scene.rootNode.addChildNode(background)
}
您是否找到任何解決方案? –
最後,我決定準備指導用戶,在開始arkit視圖之前按正確的方向面對手機。 –