Skip to content

Instantly share code, notes, and snippets.

@maxxfrazer
Last active March 15, 2022 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxxfrazer/d39e0067f599612f13028baa851c9456 to your computer and use it in GitHub Desktop.
Save maxxfrazer/d39e0067f599612f13028baa851c9456 to your computer and use it in GitHub Desktop.
Simple example of setting up vertical and horizontal detected planes to occlude objects in SceneKit
import ARKit
extension ViewController {
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let planeAnchor = anchor as? ARPlaneAnchor, let geom = ARSCNPlaneGeometry(device: MTLCreateSystemDefaultDevice()!) else {
return
}
geom.update(from: planeAnchor.geometry)
geom.firstMaterial?.colorBufferWriteMask = .alpha
node.geometry = geom
}
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
if let planeAnchor = anchor as? ARPlaneAnchor, let geom = node.geometry as? ARSCNPlaneGeometry {
geom.update(from: planeAnchor.geometry)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment