Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARF 2.1.0] ARRaycastManager doesn't find planes within infinity #135

Closed
nilsk123 opened this issue May 24, 2019 · 5 comments
Closed

[ARF 2.1.0] ARRaycastManager doesn't find planes within infinity #135

nilsk123 opened this issue May 24, 2019 · 5 comments

Comments

@nilsk123
Copy link

Hi,

We just migrated to these packages:

AR Foundation 2.1.0 preview 2
ARCore XR 2.1.0 preview 4
ARKit XR 2.1.0 preview 3

Unity 2019.1.3F1

Thank you for your continued efforts and support developing ARFoundation, it truely makes ar development much easier and more maintainable.

We use the ray version of the arsession/arraycastmanager to find infinite planes using the following code

Ray r = new Ray(transform.position, transform.TransformDirection(Vector3.down)); if (m_RaycastManager.Raycast(r, s_Hits, TrackableType.PlaneWithinInfinity)) { if(s_Hits.Count > 0) { hitPose = s_Hits.Last().pose; infiniteAnchor = m_ReferencePointManager.AddReferencePoint(hitPose); } }

This never returns a hit in the new arfoundation versions, eventhough arplanemanager indicates one or more planes have been found. This exact code works just fine when trying to find PlaneWithinPolygon, and has always worked fine for infinity too in previous versions.

@tdmowrer
Copy link
Contributor

This behavior did change in 2.1, and it's pretty subtle.

ARCore doesn't really support a PlaneWithinInfinity type of query. In ARFoundation 1.0, we incorrectly assigned any hit with a plane a PlaneWithinInfinity trackable type. ARCore's hit test support is closer to ARFoundation's PlaneEstimated. So it's not really raycasting against the infinite plane, but it will still be pretty generous. If you change your raycast query to include PlaneEstimated, you should get the same behavior that you had in 1.0.

You can also query for which types of TrackableTypes are supported with ARRaycastManager.descriptor.supportedTrackableTypes.

@nilsk123
Copy link
Author

This behavior did change in 2.1, and it's pretty subtle.

ARCore doesn't really support a PlaneWithinInfinity type of query. In ARFoundation 1.0, we incorrectly assigned any hit with a plane a PlaneWithinInfinity trackable type. ARCore's hit test support is closer to ARFoundation's PlaneEstimated. So it's not really raycasting against the infinite plane, but it will still be pretty generous. If you change your raycast query to include PlaneEstimated, you should get the same behavior that you had in 1.0.

You can also query for which types of TrackableTypes are supported with ARRaycastManager.descriptor.supportedTrackableTypes.

Hi, thanks for the explanation as always. I have been experimenting with the different trackable types, but none are anywhere near as forgiving as the infinite behaviour in 1.0. Is there any way to get that exact behaviour? In 1.0, when querying the plane within infinity, it would literaly alway find a plane.

@oktomus
Copy link

oktomus commented Jul 3, 2019

Hi, I'm trying to achieve the same behavior as @nilsk123.

In 1.0, when querying the plane within infinity, it would literaly alway find a plane.

There isn't any way to do this ? Even with a custom Plane and a custom Raycast from the camera ?

@Dryra
Copy link

Dryra commented Aug 23, 2019

Hi, I'm trying to achieve the same behavior as @nilsk123.

In 1.0, when querying the plane within infinity, it would literaly alway find a plane.

There isn't any way to do this ? Even with a custom Plane and a custom Raycast from the camera ?

Yes there is, on iOS, you would only have to check againt the raycasts from the Trackable type TrackableType.PlaneWithinInfinity, as it works as expected.

For Android, what you can do is, first check for either a camera raycast or Raycast Manager raycast:

if (m_RaycastManager.Raycast(ray, s_Hits, TrackableType.PlaneWithinPolygon) || m_RaycastManager.Raycast(ray, s_Hits, TrackableType.PlaneEstimated) || Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("PlaneHelper")))

and inside that condition get the first pose position from the ARplane that you get and spawn a 50 meter plane and then check the raycast to that plane and the ARplane at the same time.

if (!planePlaced)
                    {
                        var hitPose = s_Hits[0].pose;
                        planeObject.transform.position = new Vector3(hitPose.position.x, hitPose.position.y - 0.10f, hitPose.position.z);
                        planeObject.SetActive(true);
                        planePlaced = true;
                    }
                    if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("PlaneHelper")))
                    {
                        poseToHit = hit.point;
                    }

                    if (m_RaycastManager.Raycast(ray, s_Hits, TrackableType.PlaneEstimated) || m_RaycastManager.Raycast(ray, s_Hits, TrackableType.PlaneWithinPolygon))
                    {
                        if (s_Hits[0] != null)
                        {
                            poseToHit = s_Hits[0].pose.position;
                        }
                    }

this is just a general idea on how you can achieve this, it is possible.

@KyryloKuzyk
Copy link

KyryloKuzyk commented Oct 28, 2021

Please see this response:
#893 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants