Hi, I’m on lesson 3A.2 / App Development with Swift and I can’t get the code appear on the Scene Graph. The scene “campus” and its’ childviews which I have set up visually “Main Building” and “Sidewalks” appear on the Scene Graph. But the rest which are loadGrass() and loadTree() methods don’t appear on the Scene Graph.
Any help or information will be greatly appreciated.
Kind Regards,
Onur.
import UIKit
import SceneKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view’s delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
sceneView.debugOptions = [ARSCNDebugOptions.showWorldOrigin]
loadCampus()
}
func loadCampus() {
let scene = SCNScene(named: “art.scnassets/campus.scn”)!
sceneView.scene = scene
let node = SCNNode()
node.position = SCNVector3(0.0, 0.2, 0.0)
sceneView.scene.rootNode.addChildNode(node)
loadGrass()
loadTree()
}
func loadGrass() {
let node = SCNNode()
let geometry = SCNPlane(width: 4.5, height: 2.0)
geometry.firstMaterial?.diffuse.contents = UIColor.green
geometry.firstMaterial?.isDoubleSided = true
node.eulerAngles.x = -Float.pi / 2
node.geometry = geometry
let position = SCNVector3(0.0, -0.501, 0.0)
node.position = position
sceneView.scene.rootNode.addChildNode(node)
}
func loadTree() {
let trunkNode = SCNNode()
let trunkGeometry = SCNCylinder(radius: 0.05, height: 0.5)
trunkGeometry.firstMaterial?.diffuse.contents = UIColor.brown
trunkNode.geometry = trunkGeometry
let trunkPosition = SCNVector3(2.0, -0.25, 0.75)
trunkNode.position = trunkPosition
sceneView.scene.rootNode.addChildNode(trunkNode)
let crownNode = SCNNode()
let crownGeometry = SCNSphere(radius: 0.2)
crownGeometry.firstMaterial?.diffuse.contents = UIColor.green
crownNode.geometry = crownGeometry
let crownPosition = SCNVector3(0.0, 0.25, 0.0)
crownNode.position = crownPosition
trunkNode.addChildNode(crownNode)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
// Run the view’s session
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view’s session
sceneView.session.pause()
}
Powered by WPeMatico