using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
///
/// Represents a detected point cloud. These are also known as feature points.
///
[DefaultExecutionOrder(ARUpdateOrder.k_PointCloud)]
[DisallowMultipleComponent]
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARPointCloud) + ".html")]
public class ARPointCloud : ARTrackable
{
///
/// Invoked whenever the point cloud is updated.
///
public event Action updated;
///
/// An array of positions for each point in the point cloud.
/// This array is parallel to and
/// . Positions are provided in
/// point cloud space, that is, relative to this 's
/// local position and rotation.
///
public NativeSlice? positions
{
get
{
if (m_Data.positions.IsCreated)
{
return m_Data.positions;
}
return null;
}
}
///
/// An array of identifiers for each point in the point cloud.
/// This array is parallel to and
/// .
///
public NativeSlice? identifiers
{
get
{
if (m_Data.identifiers.IsCreated)
{
return m_Data.identifiers;
}
return null;
}
}
///
/// An array of confidence values for each point in the point cloud
/// ranging from 0..1.
/// This array is parallel to and
/// . Check for existence with
/// confidenceValues.IsCreated.
///
public NativeArray? 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;
}
}