是否可以在ARKit中隐藏功能点?

时间:2017-09-02 15:05:10

标签: ios swift augmented-reality arkit

我想在我的应用程序中介绍一个切换按钮,让用户启用或禁用功能点。

我所谈论的功能是:

self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]

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

谢谢!

2 个答案:

答案 0 :(得分:3)

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

self.sceneView.debugOptions = []

如果您已设置其他调试选项并且只想删除 功能点,则您需要获取当前debugOptions值并应用一些{ {3}}删除您不想要的选项的方法。 (然后将debugOptions设置为修改后的集合。)

答案 1 :(得分:0)

  

答案是是

     

即使其他Feature PointsdebugOptions,也可以启用 / 禁用 ON。您可以使用insert(_:)remove(_:)实例方法来完成此操作。

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

希望这会有所帮助。

相关问题