Mostafa
Mostafa

Reputation: 1612

Getting plane size from RayCasting

According to this article by apple Ray-Casting and Hit-Testing. I should use ray casting provided by RealityKit to detect the surfaces instead of hit testing provided by ARKit as apple says

but the hit-testing functions remain present for compatibility

. However,I can't find a way to know the extent of the surface detected by the raycast query.

So according to this code:

    func startRayCasting() {

    guard let raycastQuery = arView.makeRaycastQuery(from: arView.center,
                                                 allowing: .estimatedPlane,
                                                alignment: .vertical) else {
        return
    }

    guard let result = arView.session.raycast(raycastQuery).first else {
        return
    }


    let transformation = Transform(matrix: result.worldTransform)
    let plane = Plane(color: .green, transformation: transformation)
    plane.transform = transformation
    let raycastAnchor = AnchorEntity(raycastResult: result)
    raycastAnchor.addChild(plane)
    arView.scene.addAnchor(raycastAnchor)
}

I would expect that the plane I am creating would get the size and position of the plane detected. However this does not happen.

So my question is, Is ray casting suitable for detecting the surfaces size and location. Or its just for checking the 2d point location on a surface.

Upvotes: 2

Views: 768

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58563

An Apple Documentation says here:

Raycast instance method performs a convex ray cast against all the geometry in the scene for a ray of a given origin, direction, and length.

and here:

Raycast instance method performs a convex ray cast against all the geometry in the scene for a ray between two end points.

In both cases raycast methods are used for detecting intersections. And in both cases these methods return an array of collision cast hit results.

That's all raycast was made for.

Upvotes: 1

Related Questions