Search Unity

Difference between plane TrackableTypes?

Discussion in 'AR' started by BuoDev, Feb 4, 2019.

  1. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    What is the difference between the different .Plane-TrackableTypes? The definitions seem pretty vague to me.

    For instance,
    PlaneEstimated
    ? Like, if it isn't actually a plane, what is it, and how does it work? Since there is already
    PlaneWithinInfinity
    , which to me, sounds almost the same.

    Also, the difference between
    PlaneWithinPolygon
    and
    PlaneWithinBounds
    ?

    Lastly, is there a logic behind using just
    TrackableType.Planes
    ? Should this be used alone, or is it just to get all the possible plane trackable types in the ARRaycastHit?
     
  2. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    "Estimated" means the plane has an imprecise boundary. On ARKit, for example, it corresponds to ARHitTestResultTypeEstimatedHorizontalPlane.

    "Within Infinity" means to raycast against the infinite plane.

    "Within Polygon" means the ray must hit somewhere inside the boundary points of the plane.

    "Within Bounds" means the ray must hit somewhere inside the 2d bounding box of the plane (the rectangle that encloses the boundary points).

    TrackableType.Planes
    means any of the above.
     
  3. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    Thanks! So if we were to order them in size, it would go:
    PlaneWithinPolygon
    <
    PlaneEstimated
    <
    PlaneWithinBounds
    <
    PlaneWithinInfinity


    Does TrackableType.Planes prioritise which plane type should be used and always fall back to the most reliable one in this order? e.g If there is two planes of different height positions, when hitting the lower plane, will it filter out the top plane's PlaneWithinInfinity? ect...
     
  4. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    It's more like
    PlaneWithinPolygon
    <
    PlaneWithinBounds
    <
    PlaneEstimated
    <
    PlaneWithinInfinity
    .

    The trackable type parameter is a filter, not a priority. For example, if you specify
    PlaneWithinPolygon
    and
    PlaneWithinInfinity
    , and the hit point is within the plane's polygon, then you would have one hit whose
    hitType
    is
    PlaneWithinPolygon | PlaneWithinInfinity
    . If multiple planes intersect the ray, then you would get multiple hits, with the appropriate flags set on each hit's hitType. The results are sorted by distance from the raycast origin.
     
    Christin2015, dnnkeeper and BuoDev like this.
  5. DeloitteCam

    DeloitteCam

    Joined:
    Jan 23, 2018
    Posts:
    22
    Some documentation to the above effect would be nice, I also hit this part of AR raycasting and the vagueness was a head scratcher.

    It would also be great if the underlying enum value could be ordered so that they ran from most the least specific so we can more easily sort by hit type:
    Code (CSharp):
    1. hits.OrderBy(x => x.hitType).ThenBy(x => x.distance).First();
    to grab the most specific hit in the list.
     
  6. IXD-ADE

    IXD-ADE

    Joined:
    Oct 22, 2020
    Posts:
    4
    Hi All, Sorry to jump on an old thread, but I am really struggling to remove an AR placed object using physics raycast in AR FOUNDATION 4.1 and oddly can't see find much on it which is obviously me. My logic is to check if a physics raycast hits an object with tag (so must have been placed) then remove it. If it hits a plane using the ARraycast then spawn the object in place. I feel its something to do with the main camera? I have used ar session camera and tagged it as main. I can delete using a UI interface but want to click and hold on the placed object? Below are two separate attempts but none of the physics raycasts seem to hit anything?

    Code (CSharp):
    1.  
    2. if (Input.touchCount > 0)
    3.         {
    4.             Touch touch = Input.GetTouch(0);
    5.  
    6.             if (touch.phase == TouchPhase.Began)
    7.             {
    8.                 var touchPosition = touch.position;
    9.  
    10.                 bool isOverUI = touchPosition.IsPointOverUIObject();
    11.  
    12.                 if (isOverUI)
    13.                 {
    14.                     Debug.Log(" blocked raycast");
    15. return;
    16.                 }
    17.                 Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
    18.                  RaycastHit hit;
    19.                 if (Physics.Raycast(ray, out hit) && (hit.transform.tag == "knight"))
    20.                 {
    21.                     Debug.Log(" raycast");
    22.                     if (Input.GetTouch(0).deltaTime > 0.2f)
    23.                     {
    24.                         Destroy(hit.transform.gameObject);
    25.                     }
    26.                 }
    27.                 else if (!isOverUI && arRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.Planes))
    28.                 {
    29.                     Debug.Log(" arraycast");
    30.                     var hitPose = hits[0].pose;
    31.                     Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
    32.                 }
    33.  
    34.             }
    35.         }
    36.  

    I have also tried the following which places but then will not remove.

    Code (CSharp):
    1.  
    2.  void Update()
    3.     {
    4.         if (Input.touchCount > 0)
    5.         {
    6.             var touch = Input.GetTouch(0);
    7.             if (touch.phase == TouchPhase.Ended)
    8.             {
    9.                 if (Input.touchCount == 1)
    10.                 {
    11.                     //Rraycast Planes
    12.                     if (arRaycastManager.Raycast(touch.position, arRaycastHits))
    13.                     {
    14.                         var pose = arRaycastHits[0].pose;
    15.                         CreateKnight(pose.position);
    16.                         return;
    17.                     }
    18.  
    19.                     Ray ray = Camera.main.ScreenPointToRay(touch.position);
    20.                     if (Physics.Raycast(ray, out RaycastHit hit))
    21.                     {
    22.                         if (hit.collider.tag == "knight")
    23.                         {
    24.                             DeleteKnight(hit.collider.gameObject);
    25.                         }
    26.                     }
    27.                 }
    28.             }
    29.         }
    30.     }
    31.  
    32. /code]
    33.  
    34. Thanks for any pointers.
     
    kaksaveksaka likes this.
  7. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
  8. IXD-ADE

    IXD-ADE

    Joined:
    Oct 22, 2020
    Posts:
    4
    Hi Treyk-47, thanks for the reply. I resolved in the end. There was an issue with my AR FOUNDATION set up.
    Cheers
     
    TreyK-47 likes this.
  9. kakudev

    kakudev

    Joined:
    Feb 15, 2021
    Posts:
    2
    Hi,
    So for example, if I want to spawn a 3D object onto another one (Place one 3D model onto another). What plane type should I use? I have attached a picture of what I am talking about. Could someone please help me out?
     

    Attached Files: