-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPointCloudParticleExample.cs
61 lines (57 loc) · 2 KB
/
PointCloudParticleExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
// Use this for initialization
void Start ()
{
UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
currentPS = Instantiate (pointCloudParticlePrefab);
m_PointCloudData = null;
frameUpdated = false;
}
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)
{
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++;
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);
}
frameUpdated = false;
}
}
}