-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPointCloudIds.cs
53 lines (46 loc) · 1.71 KB
/
PointCloudIds.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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.iOS;
public class PointCloudIds : MonoBehaviour {
bool frameUpdated;
ulong[] m_PointCloudIdentifiers;
HashSet<ulong> m_IdentifiersSeenSoFar;
int m_ExistingIdsSeen;
private GUIStyle GStyle;
void Start() {
UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
frameUpdated = false;
m_IdentifiersSeenSoFar = new HashSet<ulong>();
GStyle = new GUIStyle();
GStyle.fontSize = 30;
}
void OnGUI() {
int seenThisFrame = (m_PointCloudIdentifiers != null) ? m_PointCloudIdentifiers.Length : 0;
string formattedMessage = String.Format("{0} new/ {1} frame/ {2} seen", seenThisFrame - m_ExistingIdsSeen, seenThisFrame, m_IdentifiersSeenSoFar.Count);
GUI.Label(new Rect(100, 100, 200, 40), formattedMessage, GStyle);
}
public void ARFrameUpdated(UnityARCamera camera) {
if (camera.pointCloud != null) {
m_PointCloudIdentifiers = camera.pointCloud.Identifiers;
}
frameUpdated = true;
}
// Update is called once per frame
void Update() {
if (frameUpdated) {
m_ExistingIdsSeen = 0;
if (m_PointCloudIdentifiers != null && m_PointCloudIdentifiers.Length > 0) {
foreach (var currentPointId in m_PointCloudIdentifiers) {
if (m_IdentifiersSeenSoFar.Contains(currentPointId)) {
m_ExistingIdsSeen++;
}
else {
m_IdentifiersSeenSoFar.Add(currentPointId);
}
}
}
frameUpdated = false;
}
}
}