Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Utsira/9129370cb2add4e93076b1b197c9f4fb to your computer and use it in GitHub Desktop.
Save Utsira/9129370cb2add4e93076b1b197c9f4fb to your computer and use it in GitHub Desktop.
Examples for augmented office blog post
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard let plane = anchor as? ARPlaneAnchor,
let geometry = node.geometry as? ARSCNPlaneGeometry
else { return }
geometry.update(from: plane.geometry)
node.boundingBox = planeBoundary(extent: plane.extent)
}
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
guard let plane = anchor as? ARPlaneAnchor,
let device = renderer.device,
let geometry = ARSCNPlaneGeometry(device: device)
else { return nil }
geometry.update(from: plane.geometry)
let maskMaterial = SCNMaterial()
maskMaterial.colorBufferWriteMask = []
geometry.materials = [maskMaterial]
return SCNNode(geometry: geometry)
}
private func planeBoundary(extent: float3) -> (min: SCNVector3, max: SCNVector3) {
let radius = extent * 0.5
return (min: SCNVector3(-radius), max: SCNVector3(radius))
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
startTracking()
}
private func startTracking() {
sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.vertical, .horizontal]
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