Skip to content

Instantly share code, notes, and snippets.

@giln
Created March 4, 2019 14:47
Show Gist options
  • Save giln/4ed34e211970fa9f5fefe48c4418f35a to your computer and use it in GitHub Desktop.
Save giln/4ed34e211970fa9f5fefe48c4418f35a to your computer and use it in GitHub Desktop.
UpdatePlane
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
// We have to specify we want to use the bounding box or it does not work
let shape = SCNPhysicsShape(geometry: geom, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.boundingBox])
physicsBody = SCNPhysicsBody(type: .static, shape: shape)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment