我在 ARKit 中有一个简单的 SCNNode,我试图将它拖动到我在手机上移动手指的任何地方。这是我的代码。
@objc func pan(recognizer :UIGestureRecognizer) {
guard let currentFrame = self.sceneView.session.currentFrame else {
return
}
var translation = matrix_identity_float4x4
translation.columns.3.z = -1.5
let sceneView = recognizer.view as! ARSCNView
let touchLocation = recognizer.location(in: sceneView)
let hitTestResult = sceneView.hitTest(touchLocation, options: [:])
if !hitTestResult.isEmpty {
print("hit result")
guard let hitResult = hitTestResult.first else {
return
}
let node = hitResult.node
node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation)
}
}
问题是拖动非常缓慢且不顺畅。