Search code examples
swiftkotlinaugmented-realityarkitarcore

Does ARCore have a semantic equivalent of ARKit's "guard let planeAnchor"?


I'd like to know if there's similar semantic construction in ARCore/Kotlin like the following guard let statement in ARKit/Swift?

let anchor: ARAnchor?

guard let planeAnchor = anchor as? ARPlaneAnchor else { 
    print("condition not met")
    return 
}

Solution

  • I think I've found a required semantics for ARCore's planeAnchor with Elvis operator and safe cast operator:

    public class CenterPosePlaneAnchor { ... }
    
    val anchor: Anchor?
    val info = "condition not met"
    
    val planeAnchor = anchor as? CenterPosePlaneAnchor ?: return println(info)