-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the SwiftUISceneKitDemo wiki!
This small project is my attempt at giving whomever downloads it a leg-up on moving toward the heavenly light that is using SwiftUI and its SceneKit SceneView implementation. Because, once you start using SwiftUI to build SceneKit apps, it's darn hard to even consider going back to UIKit.
This sample app is a close reflection of Apple's Xcode SceneKit-based Game template. To keep things familiar, included is the same ship.scn scene that Apple includes in its Xcode SceneKit-based Game template. It is a one page app, at least that's what I call it, in that ContentView.swift contains all of the code for the SceneView.
I hope you like it. And when you have suggestions about how I can fix the mistakes I'm sure I made, please email me.
When Apple announced at WWDC20 during the State of the Union presentation that SCNSceneView had been implemented in SwiftUI as SceneView, I literally shouted out with joy. No more UIViewRepresentable band-aid needed to get SceneKit to work in SwiftUI. Progress is sweet!
Unfortunately, when I jumped-in to use this new implementation of SceneKit in SwiftUI, it turned-out that using SceneView wasn't very straight-forward, at least not for mois. How do you combine gesture recognizers so you can both pinch-to-zoom and drag to change the orientation of a model in the scene? How do you change pointOfView, a.k.a. cameras? There are view modifiers so where are the scene modifiers? Show and hide status? Or just toggle a light source? Ok, maybe working with SwiftUI's SceneView is easy and I'm just dumb, which I hold as a distinct possibility.
Normally, I'd register for any SceneKit lab. Note: If you ever go to WWDC, if forced to choose between a lab and a presentation, go with the lab. Apple's engineers have always answered my questions and lifted the fog in my head. Anyway, there were no virtual labs for SceneKit at WWDC20. Apple's own SceneView documentation is a textbook case for sparsity; there is a basic description of the arguments initializing a SceneView takes and that's about it. Unfortunately, there is no discussion of how to use SceneView with SCNSceneRendererDelegate to do more than have a simple SceneKit SwiftUI app. Nor did Apple update the SceneKit-based Game template within Xcode 12, which is still based on UIKit.
Apple's own developer forums weren't much help; looking at the posts on Apple's developer forums by those seeking some insight into using SceneView – several of the more boneheaded posts belong to yours truly – shows that the dearth of supporting documentation made working with the new SceneView a bit of a challenge even for those who had worked on-and-off with SceneKit. Those just coming in to look at working with SceneKit in SwiftUI made a pretty quick exit, I'm sure. Stackoverflow and the rest of the web are no help.
While the experience of learning how to use SwiftUI's SceneView implementation hasn't been levitating, all of these documentation and resource short-comings are understandable when taken in the context that SceneView was brought into SwiftUI during the opening days and months of the SARS-CoV-2 (Covid-19) pandemic. At the end of the day, it's not Apple's job to hold my hand as I learn SceneKit – although I sure do like it when Apple does.
Frankly, I'm still amazed that Apple engineers didn't bail on the effort to implement SceneKit in SwiftUI as they were dealing with the pandemic. And I am very thankful to those at Apple who got this done. They deserve applause, lots of applause.
You can reach me at portablefrontier@me.com.