ARImageAnchor相对于SCNNode的方向



我当前的代码库提供了与世界相关的ARImageAnchor的方向(pitch,yaw,roll)。我想要实现的是获得与启动会话后某个时间添加的节点相关的ARImageAnchor方向数据。

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode,
for anchor: ARAnchor) {
guard let _ = anchor as? ARImageAnchor else { return }

DispatchQueue.main.async {
let cylinderNode = SCNNode()
cylinderNode.geometry = SCNCylinder(radius: 0.05, height: 0.4)
node.addChildNode(cylinderNode)

let ea: SCNVector3 = node.eulerAngles

print(self.convert(ea.x), self.convert(ea.y), self.convert(ea.z))
}
}

任何帮助将非常感激!

你可以传递锚的simd_float4x4变换的orientation part到你的模型(注意这个数据存储在当前会话的每个ARFrame中)恢复位置:

import ARKit
import SceneKit
class ViewController : UIViewController, ARSCNViewDelegate {

@IBOutlet var sceneView: ARSCNView!
var model = SCNNode()

override func viewDidLoad() {
super.viewDidLoad()
sceneView.delegate = self
sceneView.scene = SCNScene(named: "ARScene")!
model = sceneView.scene.rootNode.childNode(withName: "model", 
recursively: true)!
}

@IBAction func passTransformButton(_ sender: UIButton) {
if let trans = sceneView.session.currentFrame?.anchors[0].transform {
model.simdTransform = trans          // Full Transform
model.simdTransform.columns.3.x = 0  // restore position X
model.simdTransform.columns.3.y = 0  // restore position Y
model.simdTransform.columns.3.z = 0  // restore position Z
}
}
}

相关内容

  • 没有找到相关文章

最新更新