SceneKit Basics – View Scene & Nodes

SceneKit Basics – View Scene & Nodes

SceneKit is a Framework to display objects in 3D Space. There are 2(3) parts to a basic Scenekit scene: You can create a visual scene with just a View & a scene, but everything will move together with no interaction. That’s were Nodes come in handy.

1.SceneView: A subclass of UIView : 

let sceneView = self.view as! SCNView
ⓘ A Safer and more accepted method would be
if let view = SCNView {…}
ⓘ Adding Camera Control and Default Lighting.
if let view = sceneView{
    view.allowsCameraConrol = true
    view.autoenableDefaultLighting = true
}

The variable can have any name and this is the basic force optional method. In the project main.storyboard the is one Element named Game View Controller. This has a custom class of GameViewController a subclass of UIViewController.()

Also note this it is the initial View Controller.()
Inside Game View Controller there is a view of type SCNView. The last bit of code is sceneView.scene = scene. A variable to be created next.

2.SCNScene: You can load scene’s from files or make theme from scratch without any parameters.

scene = SCNScene(named: “art.scnassets/hero.dae”)

OR

scene = SCNScene()

SCNScene is comprised of SCNNodes: primitive objects like a box, scene objects, cameras, and lights. The SCNScene is comprised of a node called the rootnode that all nodes are added to, scene.rootNode.addChild(lightNode). At this point you can have a scene displayed on the screen, but that is one object or chunk of objects. Thats why you add Nodes to have some separation of objects.

3.Nodes: SCNScene is a collection of nodes that follow a parent child heirarchy. Each Node has a parent the SCNScene being the main parent were nodes are added. Nodes are defined by SCNNode(). Add nodes to Scene, self.rootNode.addChild(…)

Everything is built on top of this basic structure.

Code – GitHub