Discover Klaas's code

001import UIKit002import SceneKit003import ARKit004 005@available(iOS 11.3, *)006protocol ARViewDelegate: class {007 func didLoadView()008 func didPlaceModel()009 func didTapOnScene()010 func didTapBack()011 func didTapClose()012 func didFocusOnSurface()013 func didFocusOutSurface()014}015 016protocol ARViewProtocol: class {017 var viewData: ARViewData? { get set }018 func embedActions(_ controller: UIViewController)019 func embedInstructions(controller: UIViewController)020}021 022@available(iOS 11.3, *)023class ARViewController: UIViewController {024 025 @IBOutlet private weak var sceneView: ARSCNView!026 @IBOutlet private weak var footerContainer: UIView!027 @IBOutlet private weak var headerContainer: UIView!028 @IBOutlet private var gestures: [UIGestureRecognizer]!029 030 weak var delegate: ARViewDelegate?031 032 var viewData: ARViewData? {033   didSet {034     guard let viewData = viewData else { return }035 036     if viewData.alignment != oldValue?.alignment {037       updateAlignment(viewData.alignment)038     }039 040     if viewData.vibrate != oldValue?.vibrate, viewData.vibrate {041 .peek)042     }043 044     if viewData.shouldRemoveModel {045       model.runAction(SCNAction.fadeOut(duration: 0.3)) {046         self.model.removeFromParentNode()047       }048     }049 050     model.scale(by: viewData.modelSize)051   }052 }053 054 // MARK: Private Properties055 056 private lazy var model: Model = {057   return Model(name: "tv")058 }()059 060 private var currentAngleY: Float = 0.0061 private var currentPosition: CGPoint?062 private var featurePointModel = FeaturePointNode()063 private var featurePoints: [FeaturePointNode] = []064 private let configuration = CoolblueAR.configurationType.init()065 private var tappedNode: SCNNode?
Augmented reality
This is actual code from the Packaging Machine. Feel free to scroll through it.

With this piece of code, we can let customers know that they're positioning their camera incorrectly, causing their television to go out of view. We do this by making the image vibrate and providing an audio hint.

What if we can no longer show the model?

Sometimes, customers turn the camera so far that we can no longer show the model. In that case, we remove the 3D object from the display on the screen.