Search Unity

How to remove point clouds in Arkit?

Discussion in 'AR' started by zyonneo, Jun 6, 2019.

  1. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    After gettting the plane detected we remove the debugplane prefab that is the blue coloured rectangles. Similarly how to remove the point clouds that is coming once the plane is detected or after I place a 3d model on touch the plane(using UnityHitTest).

    My objective is to hide planes and point clouds after arworldmap is loaded.Any idea?
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.XR.iOS;
    3.  
    4. public class PointCloudParticleExample : MonoBehaviour
    5. {
    6.     public ParticleSystem pointCloudParticlePrefab;
    7.     public int maxPointsToShow;
    8.     public float particleSize = 1.0f;
    9.     Vector3[] m_PointCloudData;
    10.     bool frameUpdated = false;
    11.     ParticleSystem currentPS;
    12.     ParticleSystem.Particle [] particles;
    13.     //added
    14.     int loadcheck=0;
    15.  
    16.  
    17.     //For creating instance of class
    18.     public static PointCloudParticleExample pointinstance;
    19.  
    20.     // Use this for initialization
    21.     void Start ()
    22.     {
    23.         UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
    24.         WorldMapManager.offevent += particlesoff;//Added event
    25.         currentPS = Instantiate (pointCloudParticlePrefab);
    26.         m_PointCloudData = null;
    27.         frameUpdated = false;
    28.         pointinstance = this;
    29.     }
    30.    
    31.     public void ARFrameUpdated(UnityARCamera camera)
    32.     {
    33.         if (camera.pointCloud != null)
    34.         {
    35.            m_PointCloudData = camera.pointCloud.Points;
    36.         }
    37.         frameUpdated = true;
    38.     }
    39.  
    40.     // Update is called once per frame
    41.     void Update ()
    42.     {
    43.      
    44.         if (frameUpdated)
    45.         {
    46.             if (m_PointCloudData != null && m_PointCloudData.Length > 0 && maxPointsToShow > 0 && loadcheck == 0)
    47.             {
    48.                 int numParticles = Mathf.Min (m_PointCloudData.Length, maxPointsToShow);
    49.                 ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numParticles];
    50.                 int index = 0;
    51.                 foreach (Vector3 currentPoint in m_PointCloudData)
    52.                 {    
    53.                     particles [index].position = currentPoint;
    54.                     particles [index].startColor = new Color (1.0f, 1.0f, 1.0f);
    55.                     particles [index].startSize = particleSize;
    56.                     index++;
    57.                     Debug.Log("Points set to 0 called");
    58.                     if (index >= numParticles) break;
    59.                 }
    60.                 currentPS.SetParticles (particles, numParticles);
    61.  
    62.  
    63.             }
    64.             else
    65.             {
    66.                 ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1];
    67.                 particles [0].startSize = 0.0f;
    68.                 currentPS.SetParticles (particles, 1);
    69.                 Debug.Log("Points set to 1 called");
    70.             }
    71.  
    72.             //if(loadcheck==1)
    73.             //{
    74.             //    Debug.Log("Points set to 0 called");
    75.             //    ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1];
    76.             //    particles[0].startSize = 0.0f;
    77.             //    currentPS.SetParticles(particles, 1);
    78.             //    Debug.Log("Points set to 0 called");
    79.  
    80.             //}
    81.  
    82.             frameUpdated = false;
    83.         }
    84.     }
    85.  
    86.     public void particlesoff(UnityARCamera arcamera)
    87.     {
    88.         //var points = arcamera.pointCloud.Points;
    89.         //if (points == null)
    90.         //{
    91.         //    Debug.Log("No points");
    92.         //    return;
    93.         //}
    94.  
    95.         //else
    96.         //{
    97.         //    //foreach (var poi in points)
    98.         //    //{
    99.         //    //    poi.Scale(new Vector3(0, 0, 0));
    100.  
    101.         //    //    Debug.Log("Points set to 0 " + poi.x+" : "+ poi.y + " : "+poi.z);
    102.         //    //    //currentPS.SetParticles (points, 0);
    103.  
    104.         //    //}
    105.          
    106.         //    int numParticles = Mathf.Min(m_PointCloudData.Length, maxPointsToShow);
    107.         //    Debug.Log("numParticles length " + numParticles);
    108.         //    int index = 0;
    109.         //    Debug.Log("m_PointCloudData length " + m_PointCloudData.Length);
    110.         //    foreach(Vector3 currentPoint in m_PointCloudData)
    111.         //        {
    112.         //        Debug.Log("currentPoint Positions " + currentPoint.x +" : "+currentPoint.y + " : "+currentPoint.z);
    113.         //        particles[index].position = currentPoint;
    114.         //        //particles[index].startColor = new Color(1.0f, 1.0f, 1.0f);
    115.         //        particles[index].startSize = 0f;
    116.         //        index++;
    117.         //        if (index >= numParticles) break;
    118.         //       }
    119.         //    currentPS.SetParticles(particles, numParticles);
    120.  
    121.         //}
    122.  
    123.  
    124.     }
    125.  
    126.  
    127.  
    128.     public void particlesoffcheck()
    129.     {
    130.  
    131.         loadcheck = 1;
    132.     }
    133.  
    134. }
    135.  
    136.