Last active
March 15, 2022 16:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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