【发布时间】:2021-12-26 14:31:50
【问题描述】:
我正在尝试使用 ARKit 和 RealityKit 将 3D 模型放置在已识别的图像之上 - 全部以编程方式进行。在启动 ARView 之前,我正在下载要在检测到参考图像时显示的模型。
这是我目前的设置:
override func viewDidLoad() {
super.viewDidLoad()
arView.session.delegate = self
// Check if the device supports the AR experience
if (!ARConfiguration.isSupported) {
TLogger.shared.error_objc("Device does not support Augmented Reality")
return
}
guard let qrCodeReferenceImage = UIImage(named: "QRCode") else { return }
let detectionImages: Set<ARReferenceImage> = convertToReferenceImages([qrCodeReferenceImage])
let configuration = ARWorldTrackingConfiguration()
configuration.detectionImages = detectionImages
arView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
}
我使用 ARSessionDelegate 在添加新图像锚点时收到通知,这意味着检测到参考图像:
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
print("Hello")
for anchor in anchors {
guard let imageAnchor = anchor as? ARImageAnchor else { return }
let referenceImage = imageAnchor.referenceImage
addEntity(self.localModelPath!)
}
}
但是,委托方法永远不会被调用,而其他委托函数(如 func session(ARSession, didUpdate: ARFrame) )正在被调用,所以我假设会话只是没有检测到图像。图像分辨率很好,打印的图像很大,所以它肯定会被 ARSession 识别。在将其添加到配置之前,我还检查了该图像是否已找到。
任何人都可以在这里引导我走向正确的方向吗?
【问题讨论】:
-
您是否尝试将图像添加到项目中以查看是否有效?如果图像不适合识别,AR 资源文件夹会警告您。
标签: ios swift arkit realitykit