我ARSessionDelegate
在ARView
初始化ARBodyTrackingConfiguration
.
session
带有didAdd: [ARAnchor]
和的方法didUpdate: [ARAnchor]
被正确调用。但didRemove: [ARAnchor]
永远不会被调用。
根据官方文档,锚点“可能”会自动从会话中删除,具体取决于会话配置。我没有找到这个设置。
有谁知道为什么永远不会调用该session
方法didRemove [ARAnchor]
以及我需要更改哪个设置才能使其正常工作?
import ARKit
import RealityKit
import UIKit
class AugmentedVideoView: ARView, ARSessionDelegate {
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
print("didAdd") // called correctly
}
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
print("didUpdate") // called correctly
}
func session(_ session: ARSession, didRemove anchors: [ARAnchor]) {
print("didRemove") // is never called :-(
}
required init(frame: CGRect) {
#if targetEnvironment(simulator)
super.init(frame: frame)
handleError("Camera not available in simulator.")
return
#else
super.init(frame: frame,
cameraMode: ARView.CameraMode.ar,
automaticallyConfigureSession: false)
self.session.delegate = self
guard ARBodyTrackingConfiguration.isSupported else {
handleError("Your device does not support body tracking.")
return
}
let configuration = ARBodyTrackingConfiguration()
configuration.automaticSkeletonScaleEstimationEnabled = false
self.session.run(configuration)
#endif
}
@available(*, unavailable)
dynamic required init?(coder decoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}