Search Unity

Working with the ARPlane boundaries

Discussion in 'AR' started by orgelvarg, Aug 17, 2019.

  1. orgelvarg

    orgelvarg

    Joined:
    May 27, 2019
    Posts:
    15
    I am trying to use the current boundaries of an ARPlane to place gameobjects at the boundary of the given plane. My hope is that this could be used to fit a gameobject to the plane as it gets bigger.

    I have read the documentaion for the ARPlane class here. The method
    Code (CSharp):
    1. TryGetBoundary(List<Vector3> boundaryOut, Space space = null)
    has, to my knowledge. been replaced with a method called boundary which returns a NativeArray<Vector2> with the boundary points.

    How can I use those points to Instantiate gameobjects at the corresponding location on the corresponding ARPlane?

    Any suggestions are welcome. I've started to look into the ARPlaneMeshGenerator to see if I can get anything out of that.

    My goal with all of this is to eventually generate a gameobject representing water that scales to horizontal planes as they get bigger.
     
    Last edited: Aug 17, 2019
  2. joeri_07

    joeri_07

    Joined:
    Dec 18, 2015
    Posts:
    45
    Hi orgelvarg.

    I need to do exactly the same thing. I need to fill a room with a cube of water fitting the size of the room as much as possible. Currently I have a 3D cube with uniform scale positioned at 0.5, 0.5, 0.5 in an empty located at 0, 0, 0.
    I use ARFoundation PlaneManager to then set the position and scale of this empty on the callback of 'planesChanged'.

    This is my code:


    Code (CSharp):
    1.     public void PlanesChanged(ARPlanesChangedEventArgs action)
    2.     {
    3.         foreach (ARPlane plane in planeManager.trackables)
    4.         {
    5.             setMinimum(ref minX, plane.gameObject.transform.position.x);
    6.             setMaximum(ref maxX, plane.gameObject.transform.position.x);
    7.  
    8.             setMinimum(ref minY, plane.gameObject.transform.position.y);
    9.             setMaximum(ref maxY, plane.gameObject.transform.position.y);
    10.  
    11.             setMinimum(ref minZ, plane.gameObject.transform.position.z);
    12.             setMaximum(ref maxZ, plane.gameObject.transform.position.z);
    13.         }
    14.  
    15.         planeCountLabel.text = "X: [ " + minX + " - " + maxX + " ], Y: [ " + minY + " - " + maxY + " ], Z: [ " + minZ + " - " + maxZ + " ]";
    16.         waterCube.transform.position = new Vector3(minX, minY, minZ);
    17.         waterCube.transform.localScale = new Vector3(maxX - minX, waterLevel, maxZ - minZ);
    18.     }
    The problem is that I need to iterate over the boundaries of the mesh, not its position (this will be the centerPoint I guess). Also I need to then convert those coordinats to worldspace, since they will still be relative to the localSpace if the plane.

    Did you make any progress with this?
    Thank you,

    Joeri