Skip to content

Instantly share code, notes, and snippets.

@giln
Created March 4, 2019 14:44
Show Gist options
  • Save giln/e8f841d2b737f3b3d364a9210e1fa892 to your computer and use it in GitHub Desktop.
Save giln/e8f841d2b737f3b3d364a9210e1fa892 to your computer and use it in GitHub Desktop.
PlaneNode
import ARKit
import SceneKit
public class PlaneNode: SCNNode {
// MARK: - Public functions
public func update(from planeAnchor: ARPlaneAnchor) {
// We need to create a new geometry each time because it does not seem to update correctly for physics
guard let device = MTLCreateSystemDefaultDevice(),
let geom = ARSCNPlaneGeometry(device: device) else {
fatalError()
}
geom.firstMaterial?.diffuse.contents = UIColor.blue.withAlphaComponent(0.3)
geom.update(from: planeAnchor.geometry)
// We modify our plane geometry each time ARKit updates the shape of an existing plane
geometry = geom
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment