Using the new SceneKit SceneView in SwiftUI how do I turn on the SceneKit debug parameters? The current options parameter only takes a limited number of Options?
https://developer.apple.com/documentation/scenekit/sceneview/options
https://developer.apple.com/documentation/scenekit/sceneview/options
Code Block swift struct ContentView : View { @State var theScene = SCNScene(named: "ship.scn")! @State private var pointOfView = "distantCamera" public var body: some View { ZStack { SceneView( scene: theScene, pointOfView: theScene.rootNode.childNode(withName: pointOfView, recursively: true), options: [ .allowsCameraControl, SCNDebugOptions.showBoundingBoxes ] - [ERROR] ) Button(action: { // Can I turn on debug for SceneView here? // show SCNView statistics such as fps and timing information scnView.showsStatistics = true - [ERROR] scnView.debugOptions = [.renderAsWireframe, .showBoundingBoxes] - [ERROR] }) { Text("Debug").padding(.top, 300) } } } }
I'm not sure this is the right way to handle this situation, but you can set showsStatistics or debugOptions inside SCNSceneRendererDelegate.
A sample code. (Taken and modified from the template project of iOS/Game/SceneKit. You may need to modify some parts.)
(To make this code run on simulators, I needed to disable Metal API Validation with Edit Scheme...>Run>Diagnostics.)
A sample code. (Taken and modified from the template project of iOS/Game/SceneKit. You may need to modify some parts.)
Code Block import SwiftUI import SceneKit struct ContentView: View { @StateObject var coordinator = SceneCoordinator() var body: some View { ZStack { SceneView( scene: coordinator.theScene, options: [.allowsCameraControl], delegate: coordinator ) Button(action: { coordinator.showsStatistics = true coordinator.debugOptions = [.renderAsWireframe, .showBoundingBoxes] }) { Text("Debug").padding(.top, 300) } } } } class SceneCoordinator: NSObject, SCNSceneRendererDelegate, ObservableObject { var showsStatistics: Bool = false var debugOptions: SCNDebugOptions = [] lazy var theScene: SCNScene = { // create a new scene let scene = SCNScene(named: "art.scnassets/ship.scn")! //... return scene }() func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { renderer.showsStatistics = self.showsStatistics renderer.debugOptions = self.debugOptions } }
(To make this code run on simulators, I needed to disable Metal API Validation with Edit Scheme...>Run>Diagnostics.)