Skip to content

Instantly share code, notes, and snippets.

@avnerbarr
Created June 22, 2019 09:14
Show Gist options
  • Save avnerbarr/9a7f0901f9d690820fca557708bfb94b to your computer and use it in GitHub Desktop.
Save avnerbarr/9a7f0901f9d690820fca557708bfb94b to your computer and use it in GitHub Desktop.
ARKit learning

Scene

Drag ARKitSCNView to story builder or make in code

@IBOutlet weak var sceneView: ARSCNView!
  let configuration = ARWorldTrackingConfiguration()

Add a configuration object to the view controller

let configuration = ARWorldTrackingConfiguration()

in view did load we configure the scene

self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints,.showWorldOrigin] // so it shows the axis origin and shows yellow feature points discovery
self.sceneView.session.run(configuration)

Coordinate

-+- |Green + Y axis up/down positive is up / negative down| |Red + X axis left/right positive is right / negative left| |Blus + Z axis away/towards positive is away / negative is closer| -+-

Creating nodes

let node = SCNNode() // a node object (has not shape / size / color yet)
node.geometry = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0) // sizes are in meters
node.geometry?.firstMaterial?.diffuse.contents = UIColor.blue // give it a color
// up / down is Y
// left / right is X
// towards / away is Z (negative is behind the origin (away))
node.position = SCNVector3(0, 0, 0) // origin in respect to the parent node 
self.sceneView.scene.rootNode.addChildNode(node)

removing nodes

node.removeFromParentNode()

resetting the coordinate system

self.sceneView.session.pause()
let n = self.sceneView.scene.rootNode
n.enumerateChildNodes { (node, _) in
  node.removeFromParentNode()
}
self.sceneView.session.run(configuration, options: [.resetTracking,.removeExistingAnchors])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment