Search Unity

ARFoundation remove mesh visualizer and cancel touch tracking

Discussion in 'Handheld AR' started by Edur-Games, Oct 6, 2018.

  1. Edur-Games

    Edur-Games

    Joined:
    Nov 21, 2017
    Posts:
    46
    Hi!
    How can I remove the viewer once I have placed the content on the surface? and cancel the touches to be able to use your own canvas with buttons in the GUI.

    Regards!
     
    GreeneMachine likes this.
  2. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    59
    Hi.

    Today, almost a year after your message, I'm having the same problem. Did you find the solution for the current version of ARFoundation?

    Thanks.
     
  3. Edur-Games

    Edur-Games

    Joined:
    Nov 21, 2017
    Posts:
    46
    Hi tonymnoz!

    Hello. I think I found the Solution in Unity 2018.2


    In the script PlaceOnPlane.cs
    ...

    void OnPositionContent(){
    if (Input.touchCount > 0)
    {
    Touch touch = Input.GetTouch(0);

    if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
    {
    Pose hitPose = s_Hits[0].pose;

    if (spawnedObject == null)
    {
    spawnedObject = Instantiate(m_PlacedPrefab);
    DisablePlanes();
    }
    else
    {
    spawnedObject.transform.position = hitPose.position;
    }
    }
    }
    }

    void DisablePlanes(){
    planeManager.GetAllPlanes(allPlanes);
    planeManager.enabled = false;
    foreach (ARPlane plane in allPlanes)
    {
    plane.gameObject.SetActive(false);
    }
    }




    When you place your content disable the ARPlaneManager and clean the generated planes visualized

    planeManager is the ARPlaneManager component you have to turn off
    planeManager = GetComponent<ARPlaneManager>();

    Then get the generated plane meshes and clean them as shown in DisablePlanes()

    I hope it helps!
    Regards

    Edu
     
    karsnen and tonOnWu like this.
  4. Edur-Games

    Edur-Games

    Joined:
    Nov 21, 2017
    Posts:
    46
    I forgot to mention that I've only tried it on iOS. I guess Android will also be valid.
    And I'm sure that this can be implemented in some other way more effective

    Regards
     
    tonOnWu likes this.
  5. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    59
    Thank you. That was it. I misunderstood GetAllPlanes code. I thought that, like it was a void, I couldn't use it without changing that code. And I didn't want to do that for the future updating implications it carries.

    In fact, everything was centered on the DisablePlanes method. Unity should include that code in the library. I only made a small update to yours. I'm sharing it for whoever needs it:

    Code (CSharp):
    1.     void DisablePlanes()
    2.     {
    3.         planeManager = GetComponent<ARPlaneManager>();
    4.         List<ARPlane> allPlanes = new List<ARPlane>();
    5.  
    6.         planeManager.GetAllPlanes(allPlanes);
    7.         planeManager.enabled = false;
    8.         foreach (ARPlane plane in allPlanes)
    9.         {
    10.             plane.gameObject.SetActive(false);
    11.         }
    12.     }
    13.  
     
  6. Edur-Games

    Edur-Games

    Joined:
    Nov 21, 2017
    Posts:
    46
    Thanks a lot. Perfect.
    yes, the GetAllPlanes need to create a new list of ARPlanes to be given to the GetAllPlanes and be able to obtain them in such a way that you turn them off.

    Thank you!
     
    tonOnWu likes this.
  7. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126