- Published on
ARkit Part 1
- Authors
- Name
- Jacob Aronoff
Today I'm beggining my series on ARKit, and I'm going to be working on a basic ARKit app, that's going to involve some basic physics, and 3d modeling (two things I'm really terrible at.)
To start, I had to download iOS 11 on my devices and then I had to install the Xcode 9 beta which includes an easy starter for ARKit apps.
After starting up the simulator I realized that running the simulator would not work because it doesn't have access to the camera. My next step is to get the demo working on my iPhone and then mess around with the code and adjust and play around with things.
//
// ViewController.swift
// arkit-demo
//
// Created by Jacob Aronoff on 6/27/17.
// Copyright © 2017 Jacob Aronoff. All rights reserved.
//
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
// Create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// Set the scene to the view
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingSessionConfiguration()
// 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()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
// MARK: - ARSCNViewDelegate
/*
// Override to create and configure nodes for anchors added to the view's session.
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
return node
}
*/
func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}
func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}
func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}
That's basically the only special part in the code; is the scene configuration and loading when the SCNScene is being created. I'll be editing and hacking around a bit more very soon!