Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

AR Foundation all planes register as Horizontal

Discussion in 'Handheld AR' started by hawken, Nov 15, 2018.

  1. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    480
    using

    Code (CSharp):
    1. ARPlane thisPlane = arpm.TryGetPlane(eventArgs.Plane.Id);
    2.  
    3.         if (thisPlane.boundedPlane.Alignment == PlaneAlignment.Vertical)
    4.         {
    5.             print("vertical");
    6.         }
    this never registers as vertical, even if they are vertical planes
     
  2. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    546
    What do you get if you just print out the Alignment?

    eventArgs.Plane is a BoundedPlane, so you should just use that directly rather than asking the ARPlaneManager for its copy. The ARPlaneManager component subscribes to the ARSubsystemManager's plane events, which it then uses to update the ARPlane components in the scene. One possible explanation for what you're seeing is
    1. PlaneAddedEvent fires
    2. Your logic runs, which grabs asks the ARPlaneManager for its copy of the BoundedPlane
    3. The ARPlaneManager receives the PlaneAddedEvent and updates each ARPlane's BoundedPlane.

    So you may be getting at the plane before the ARPlaneManager has updated the ARPlane.

    Another option would be to instead subscribe to the ARPlaneManager's plane events, which additionally gives you the ARPlane.
     
  3. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    480
    The horizontal ones print out as horizontal, the vertical ones come out as nonaxis
     
  4. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    546
    Ah, that sounds more like it. We added this enum before ARCore and ARKit actually supported vertical planes, so we're making the determination by computing the angle of the normal with the horizontal. I've found ARKit can vary by 6 or 7 degrees from perfectly vertical, so that calculation seems to be too restrictive.

    NonAxis (as in not axis aligned) just means it isn't perfectly vertical or horizontal. Since neither ARCore or ARKit support that, you could just assume NonAxis is the same as vertical for now.

    You could also perform the calculation yourself, and allow for greater variance in vertical planes. The calculation we're doing is equivalent to

    Code (CSharp):
    1. if (Mathf.Abs(plane.normal.y) <= epsilon) // assume vertical
    Where epsilon is a small number. The y component of the normal is the cosine of the angle it makes with the up vector, so to find a reasonable value, take the inverse cosine. If
    epsilon == 0.0
    , that would be 90 degrees (so a perfectly vertical plane), while an epsilon of 0.1 would be plus or minus 6 degrees (since arccos(0.1) = 84.2 degrees).
     
  5. Mal_Duffin

    Mal_Duffin

    Joined:
    Jan 22, 2015
    Posts:
    44
    Just out of curiosity, does this mean that the IgnoreVerticalPlanes sample scene never worked?

    It uses the code...

    Code (CSharp):
    1. if (plane.boundedPlane.Alignment == PlaneAlignment.Vertical)
    This issue seems to have been reported a while back ( https://forum.unity.com/threads/bou...ing-ar-foundation-on-ios.558589/#post-3701575 ), but didn't get a reply.

    It would be great if the built-in tolerance for PlaneAlignment.Vertical was the same as it currently is for PlaneAlignment.Horizontal ( and was configurable - better still, allow for both tolerances to have separate values ).

    At the very least, the sample scene should be updated to work using the normal.y check.
     
    hawken and newguy123 like this.
  6. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    546
    It worked when I tested it, but it is possible for some vertical planes to slip through. I've added a way to request only horizontal or vertical plane detection for the next release of ARFoundation, which will eliminate the need for this sample.
     
    assassinKK likes this.
  7. assassinKK

    assassinKK

    Joined:
    Dec 14, 2016
    Posts:
    2
    Also, we should be able to request only ground horizontal planes. As of now, you cannot disable ceiling detection.
     
  8. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    121
    I tried https://github.com/Unity-Technologi...aster/Assets/Scripts/DisableVerticalPlanes.cs
    Despite vertical planes may be disabled it appears the raycast and placement of objects is successful. Anyone else seeing this behaviour?

    I had to add these lines inside the raycast condition to make it work at cost of performance:
    Code (CSharp):
    1. if(m_ArRaycastManagerScript.Raycast(ray, s_Hits, TrackableType.PlaneWithinPolygon))
    2.             {
    3.                 TrackableId planeHit_ID = s_Hits[0].trackableId;
    4.                 ARPlane m_ARPlaneHit = m_PlaneManagerScript.GetPlane(planeHit_ID);
    5.            
    6.                 if (m_ARPlaneHit.alignment.ToString().Equals("NotAxisAligned") || m_ARPlaneHit.alignment.ToString().Equals("Vertical") || m_ARPlaneHit.alignment.ToString().Equals("None"))
    7.                 {
    8.                     Debug.Log("Exiting raycast, plane is " + m_ARPlaneHit.alignment +" in string " + m_ARPlaneHit.alignment.ToString() + " is on/off:"+m_ARPlaneHit.gameObject.activeSelf);
    9.                     return;
    10.                 }