0
votes

We are using ARKit for detecting horizontal and vertical planes. When user tap somewhere on the screen it get the world coordinates using the hittest function and place 3D object at that specific location. Now what i want is to detect the type of the plane weather the nearest detected plane is vertical or horizontal?

ARKit session configurations are:

    let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = [.vertical, .horizontal]
    sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])

This is how we are placing 3D objects:

    let sceneView = tapGesture.view as! ARSCNView
    let location = tapGesture.location(in: sceneView)

    let result = sceneView.hitTest(location, types: .existingPlane).first

    guard let hitResult = result else {
        debugPrint("Unable to get hit result")
        return
    }

    let position = SCNVector3(hitResult.worldTransform.columns.3.x,
                              hitResult.worldTransform.columns.3.y,
                              hitResult.worldTransform.columns.3.z)
    addNode(position: position)

We are using the Xcode: 9.3 beta

1

1 Answers

1
votes

To detect the alignment of the plane you can do something like this:

    let sceneView = gestureRecognizer.view as! ARSCNView
    let location = gestureRecognizer.location(in: sceneView)


    let likelyHitResult = sceneView.hitTest(location, types: .existingPlane).filter { (result) -> Bool in
        return (result.anchor as? ARPlaneAnchor)?.alignment == ARPlaneAnchor.Alignment.vertical
    }.first