Pietro Messineo
Pietro Messineo

Reputation: 837

Is it possible to hide Feature Points in ARKit?

I want to introduce in my app a toggle that will let the user to enable or disable the Feature Point.

The function that I'm talking about is:

self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]

Is it possible to disable it or it's in just one way?

Thank you!

Upvotes: 1

Views: 1999

Answers (2)

Andy Jazz
Andy Jazz

Reputation: 58063

The answer is YES,

you can enable / disable Feature Points even if other debugOptions are ON. You can accomplish this by using insert(_:) and remove(_:) instance methods.

Here's a code (Xcode 10.2.1, Swift 5.0.1, ARKit 2.0):

let configuration = ARWorldTrackingConfiguration()
@IBOutlet weak var `switch`: UISwitch!
var debugOptions = SCNDebugOptions()


override func viewDidLoad() {
    super.viewDidLoad()
    sceneView.delegate = self
    let scene = SCNScene(named: "art.scnassets/model.scn")!
    
    debugOptions = [.showWorldOrigin]
    sceneView.debugOptions = debugOptions
    sceneView.scene = scene
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    sceneView.session.run(configuration)
}

@IBAction func featurePointsOnOff(_ sender: Any) {

    if `switch`.isOn == true {
        debugOptions.insert(.showFeaturePoints)
        sceneView.debugOptions = debugOptions
        print("'showFeaturePoints' option is \(debugOptions.contains(.showFeaturePoints))")

    } else if `switch`.isOn == false {
        debugOptions.remove(.showFeaturePoints)
        sceneView.debugOptions = debugOptions
        print("'showFeaturePoints' option is \(debugOptions.contains(.showFeaturePoints))")
    }
}

Hope this helps.

Upvotes: 0

rickster
rickster

Reputation: 126117

If feature points was the only debug option you turned on, you can easily turn it off (along with all other debug options) by setting debug options to the empty set:

self.sceneView.debugOptions = []

If you've set other debug options and want to remove only the feature points one, you'll need to take the current debugOptions value and apply some SetAlgebra methods to remove the option you don't want. (Then set debugOptions to your modified set.)

Upvotes: 4

Related Questions