SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1 KiB

4 years ago
  1. using System;
  2. using Unity.Collections;
  3. using Unity.Collections.LowLevel.Unsafe;
  4. using UnityEngine.XR.ARSubsystems;
  5. namespace UnityEngine.XR.ARFoundation
  6. {
  7. /// <summary>
  8. /// Represents a detected point cloud, aka feature points.
  9. /// </summary>
  10. [DefaultExecutionOrder(ARUpdateOrder.k_PointCloud)]
  11. [DisallowMultipleComponent]
  12. [HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@3.0/api/UnityEngine.XR.ARFoundation.ARPointCloud.html")]
  13. public class ARPointCloud : ARTrackable<XRPointCloud, ARPointCloud>
  14. {
  15. /// <summary>
  16. /// Invoked whenever the point cloud is updated.
  17. /// </summary>
  18. public event Action<ARPointCloudUpdatedEventArgs> updated;
  19. /// <summary>
  20. /// An array of positions for each point in the point cloud.
  21. /// This array is parallel to <see cref="identifiers"/> and
  22. /// <see cref="confidenceValues"/>. Positions are provided in
  23. /// point cloud space, that is, relative to this <see cref="ARPointCloud"/>'s
  24. /// local position and rotation.
  25. /// </summary>
  26. public NativeSlice<Vector3>? positions
  27. {
  28. get
  29. {
  30. if (m_Data.positions.IsCreated)
  31. {
  32. return m_Data.positions;
  33. }
  34. return null;
  35. }
  36. }
  37. /// <summary>
  38. /// An array of identifiers for each point in the point cloud.
  39. /// This array is parallel to <see cref="positions"/> and
  40. /// <see cref="confidenceValues"/>.
  41. /// </summary>
  42. public NativeSlice<ulong>? identifiers
  43. {
  44. get
  45. {
  46. if (m_Data.identifiers.IsCreated)
  47. {
  48. return m_Data.identifiers;
  49. }
  50. return null;
  51. }
  52. }
  53. /// <summary>
  54. /// An array of confidence values for each point in the point cloud
  55. /// ranging from 0..1.
  56. /// This array is parallel to <see cref="positions"/> and
  57. /// <see cref="identifiers"/>. Check for existence with
  58. /// <c>confidenceValues.IsCreated</c>.
  59. /// </summary>
  60. public NativeArray<float>? confidenceValues
  61. {
  62. get
  63. {
  64. if (m_Data.confidenceValues.IsCreated)
  65. {
  66. return m_Data.confidenceValues;
  67. }
  68. return null;
  69. }
  70. }
  71. void Update()
  72. {
  73. if (m_PointsUpdated && updated != null)
  74. {
  75. m_PointsUpdated = false;
  76. updated(new ARPointCloudUpdatedEventArgs());
  77. }
  78. }
  79. void OnDestroy()
  80. {
  81. m_Data.Dispose();
  82. }
  83. internal void UpdateData(XRDepthSubsystem subsystem)
  84. {
  85. m_Data.Dispose();
  86. m_Data = subsystem.GetPointCloudData(trackableId, Allocator.Persistent);
  87. m_PointsUpdated = m_Data.positions.IsCreated;
  88. }
  89. XRPointCloudData m_Data;
  90. bool m_PointsUpdated = false;
  91. }
  92. }