我是 Swift 新手,我正在使用 RealityKit 为应用程序界面编写一个 AR 应用程序,并在其中一个视图控制器中使用 Wrapped SwiftUI 结构,因此我可以创建自定义 AR 界面。(我不知道这是否是正确的方法,但正如我告诉你的那样,我一直在自学并设法做到了直到现在)。
无论如何,目标是根据用户给出的纬度和经度放置 AR 对象(仍然没有完成那部分,但我正在使用手动值进行测试),实现这一目标的好方法是使用ARGeoTrackingConfiguration()
(来自我读过的)但是因为我的设备(iPhone 7)没有 A12 Bionic 芯片,我不能使用它,所以我试图用它来实现它ARWorldTrackingConfiguration()
,但到目前为止,我被困在这个问题上尝试使用 self.raycast(...).first?.worldTransform.translation 在屏幕上获取触摸位置时,由于“内部”保护级别,“翻译”无法访问
extension ARView {
@objc func handleTap(_ sender: UITapGestureRecognizer? = nil) {
guard let touchInView = sender?.location(in: self) else {
print("Failed on touch")
return
}
let results = self.raycast(from: touchInView,
allowing: .estimatedPlane,
alignment: .horizontal)
print(results)
if let firstResult = results.first {
let anchor = ARGeoAnchor(name: "pinus_pinaster.usdz",
coordinate: firstResult.worldTransform.translation)
self.session.add(anchor: anchor)
} else {
print("Object placement failed - coudn't find surface")
}
}
}
关于如何解决这个问题的任何解释(一个例子会很好)?
此外,对于 ARKit 开发的任何一般建议,是否可以在没有 ARGeoTrackingConfiguration() 的情况下实现具有这些功能的应用程序?