ARPointCloud.cs
3 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// Represents a detected point cloud, aka feature points.
/// </summary>
[DefaultExecutionOrder(ARUpdateOrder.k_PointCloud)]
[DisallowMultipleComponent]
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARPointCloud) + ".html")]
public class ARPointCloud : ARTrackable<XRPointCloud, ARPointCloud>
{
/// <summary>
/// Invoked whenever the point cloud is updated.
/// </summary>
public event Action<ARPointCloudUpdatedEventArgs> updated;
/// <summary>
/// An array of positions for each point in the point cloud.
/// This array is parallel to <see cref="identifiers"/> and
/// <see cref="confidenceValues"/>. Positions are provided in
/// point cloud space, that is, relative to this <see cref="ARPointCloud"/>'s
/// local position and rotation.
/// </summary>
public NativeSlice<Vector3>? positions
{
get
{
if (m_Data.positions.IsCreated)
{
return m_Data.positions;
}
return null;
}
}
/// <summary>
/// An array of identifiers for each point in the point cloud.
/// This array is parallel to <see cref="positions"/> and
/// <see cref="confidenceValues"/>.
/// </summary>
public NativeSlice<ulong>? identifiers
{
get
{
if (m_Data.identifiers.IsCreated)
{
return m_Data.identifiers;
}
return null;
}
}
/// <summary>
/// An array of confidence values for each point in the point cloud
/// ranging from 0..1.
/// This array is parallel to <see cref="positions"/> and
/// <see cref="identifiers"/>. Check for existence with
/// <c>confidenceValues.IsCreated</c>.
/// </summary>
public NativeArray<float>? confidenceValues
{
get
{
if (m_Data.confidenceValues.IsCreated)
{
return m_Data.confidenceValues;
}
return null;
}
}
void Update()
{
if (m_PointsUpdated && updated != null)
{
m_PointsUpdated = false;
updated(new ARPointCloudUpdatedEventArgs());
}
}
void OnDestroy()
{
m_Data.Dispose();
}
internal void UpdateData(XRDepthSubsystem subsystem)
{
m_Data.Dispose();
m_Data = subsystem.GetPointCloudData(trackableId, Allocator.Persistent);
m_PointsUpdated = m_Data.positions.IsCreated;
}
XRPointCloudData m_Data;
bool m_PointsUpdated = false;
}
}