Created
March 4, 2019 14:47
-
-
Save giln/4ed34e211970fa9f5fefe48c4418f35a to your computer and use it in GitHub Desktop.
UpdatePlane
This file contains hidden or 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
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