是否可以在 ARKit 中隐藏特征点?

Is it possible to hide Feature Points in ARKit?

我想在我的应用中引入一个开关,让用户启用或禁用功能点。

我说的函数是:

self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]

是否可以禁用它或仅以一种方式禁用它?

谢谢!

如果特征点是您打开的唯一调试选项,您可以通过将调试选项设置为空集来轻松关闭它(连同所有其他调试选项):

self.sceneView.debugOptions = []

如果您设置了其他调试选项并且想要删除 特征点之一,您需要采用当前 debugOptions 值并应用一些SetAlgebra 方法来删​​除您不想要的选项。 (然后将 debugOptions 设置为您修改后的集合。)

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.

这是一个代码(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))")
    }
}

希望对您有所帮助。