ARKit: how to reset world orientation after a break

I am trying to get the ARWorldTracking session to reorient north after the session is interrupted. I went through the documentation several times, but I find this confusing.

Current behavior:

When I lock the device and sessionWasInterrupted application, starting sessionWasInterrupted , SCNNodes all shift ~ 90 degrees or so counterclockwise on the compass.

When you call the run method (_: options :) with a configuration other than the current session configuration, the session always resets tracking

I interpreted this as saying that when I create a new set of configurations that is different from viewWillAppear , the session will be "reset". I don’t understand what is actually happening, but orientation after interruption is disabled. (as well as removeExistingAnchors does nothing)

 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let configuration = ARWorldTrackingSessionConfiguration() configuration.planeDetection = .horizontal configuration.worldAlignment = .gravityAndHeading sceneView.session.run(configuration) } func sessionWasInterrupted(_ session: ARSession) { let configuration = ARWorldTrackingSessionConfiguration() configuration.planeDetection = .horizontal configuration.worldAlignment = .gravityAndHeading self.sceneView.session.run(configuration, options: [ARSession.RunOptions.removeExistingAnchors, ARSession.RunOptions.resetTracking]) } 

Desired behavior:

When the application detects a session interruption, I would like it to focus on the real north again.

+5
source share
1 answer

This problem also killed me - you helped me with half the solution - adding Reset flags to track / delete existing anchors is the magic key for me - I think the second half is a guide from This post where you need to pause the session and delete all nodes off the stage, and then rearrange them. The combination of both of these things led the compass to reset back to True North after terminating the session for me.

 func resetARSession() { // Called by sessionInterruptionDidEnd sceneView.session.pause() sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in node.removeFromParentNode() } setupARSession() setupSceneView() } func setupARSession() { let configuration = ARWorldTrackingConfiguration() configuration.worldAlignment = .gravityAndHeading sceneView.session.run(configuration, options: [ARSession.RunOptions.resetTracking, ARSession.RunOptions.removeExistingAnchors]) } 
0
source

Source: https://habr.com/ru/post/1271064/


All Articles