- Home /
Question by
zyonneo · Jun 06, 2019 at 12:51 PM ·
unity 5iosaugmented reality
How to remove point clouds in Arkit?
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?
using UnityEngine;
using UnityEngine.XR.iOS;
public class PointCloudParticleExample : MonoBehaviour
{
public ParticleSystem pointCloudParticlePrefab;
public int maxPointsToShow;
public float particleSize = 1.0f;
Vector3[] m_PointCloudData;
bool frameUpdated = false;
ParticleSystem currentPS;
ParticleSystem.Particle [] particles;
//added
int loadcheck=0;
//For creating instance of class
public static PointCloudParticleExample pointinstance;
// Use this for initialization
void Start ()
{
UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
WorldMapManager.offevent += particlesoff;//Added event
currentPS = Instantiate (pointCloudParticlePrefab);
m_PointCloudData = null;
frameUpdated = false;
pointinstance = this;
}
public void ARFrameUpdated(UnityARCamera camera)
{
if (camera.pointCloud != null)
{
m_PointCloudData = camera.pointCloud.Points;
}
frameUpdated = true;
}
// Update is called once per frame
void Update ()
{
if (frameUpdated)
{
if (m_PointCloudData != null && m_PointCloudData.Length > 0 && maxPointsToShow > 0 && loadcheck == 0)
{
int numParticles = Mathf.Min (m_PointCloudData.Length, maxPointsToShow);
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numParticles];
int index = 0;
foreach (Vector3 currentPoint in m_PointCloudData)
{
particles [index].position = currentPoint;
particles [index].startColor = new Color (1.0f, 1.0f, 1.0f);
particles [index].startSize = particleSize;
index++;
Debug.Log("Points set to 0 called");
if (index >= numParticles) break;
}
currentPS.SetParticles (particles, numParticles);
}
else
{
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1];
particles [0].startSize = 0.0f;
currentPS.SetParticles (particles, 1);
Debug.Log("Points set to 1 called");
}
//if(loadcheck==1)
//{
// Debug.Log("Points set to 0 called");
// ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1];
// particles[0].startSize = 0.0f;
// currentPS.SetParticles(particles, 1);
// Debug.Log("Points set to 0 called");
//}
frameUpdated = false;
}
}
public void particlesoff(UnityARCamera arcamera)
{
//var points = arcamera.pointCloud.Points;
//if (points == null)
//{
// Debug.Log("No points");
// return;
//}
//else
//{
// //foreach (var poi in points)
// //{
// // poi.Scale(new Vector3(0, 0, 0));
// // Debug.Log("Points set to 0 " + poi.x+" : "+ poi.y + " : "+poi.z);
// // //currentPS.SetParticles (points, 0);
// //}
// int numParticles = Mathf.Min(m_PointCloudData.Length, maxPointsToShow);
// Debug.Log("numParticles length " + numParticles);
// int index = 0;
// Debug.Log("m_PointCloudData length " + m_PointCloudData.Length);
// foreach(Vector3 currentPoint in m_PointCloudData)
// {
// Debug.Log("currentPoint Positions " + currentPoint.x +" : "+currentPoint.y + " : "+currentPoint.z);
// particles[index].position = currentPoint;
// //particles[index].startColor = new Color(1.0f, 1.0f, 1.0f);
// particles[index].startSize = 0f;
// index++;
// if (index >= numParticles) break;
// }
// currentPS.SetParticles(particles, numParticles);
//}
}
public void particlesoffcheck()
{
loadcheck = 1;
}
}
Comment