【发布时间】:2021-08-24 03:09:16
【问题描述】:
我是 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() 的情况下实现具有这些功能的应用程序?
【问题讨论】:
-
Xcode 也给了我这条信息... 1. 此处声明的“翻译”(RealityKit.simd_float4x4(内部))
标签: swift augmented-reality arkit realitykit aranchor