Просмотрите следующий код, я думаю, он поможет вам выяснить, как работает измерение:
class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate {
@IBOutlet weak var resultLabel: UILabel!
@IBOutlet weak var aimLabel: UILabel!
@IBOutlet weak var notReadyLabel: UILabel!
@IBOutlet var sceneView: ARSCNView!
let session = ARSession()
let vectorZero = SCNVector3()
let sessionConfig = ARWorldTrackingSessionConfiguration()
var measuring = false
var startValue = SCNVector3()
var endValue = SCNVector3()
override func viewDidLoad() {
super.viewDidLoad()
setupScene()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.isIdleTimerDisabled = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
session.pause()
}
func setupScene() {
sceneView.delegate = self
sceneView.session = session
session.run(sessionConfig, options: [.resetTracking,
.removeExistingAnchors])
resetValues()
}
func resetValues() {
measuring = false
startValue = SCNVector3()
endValue = SCNVector3()
updateResultLabel(0.0)
}
func updateResultLabel(_ value: Float) {
let cm = value * 100.0
let inch = cm * 0.3937007874
resultLabel.text = String(format: "%.2f cm / %.2f\"", cm, inch)
}
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
DispatchQueue.main.async {
self.detectObjects()
}
}
func detectObjects() {
if let worldPos = sceneView.realWorldVector(screenPos: view.center) {
aimLabel.isHidden = false
notReadyLabel.isHidden = true
if measuring {
if startValue == vectorZero {
startValue = worldPos
}
endValue = worldPos
updateResultLabel(startValue.distance(from: endValue))
}
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
resetValues()
measuring = true
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
measuring = false
}
}
Как видите, структуры .planeDetection
нет.