NRTrackablePlane.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using System.Collections.Generic;
  13. using UnityEngine;
  14. /// <summary> A plane in the real world detected by NRInternel. </summary>
  15. public class NRTrackablePlane : NRTrackable
  16. {
  17. internal NRPlaneSubsystem PlaneSubsystem
  18. {
  19. get
  20. {
  21. return NRSessionManager.Instance.TrackableFactory.PlaneSubsystem;
  22. }
  23. }
  24. /// <summary> Constructor. </summary>
  25. /// <param name="nativeHandle"> Handle of the native.</param>
  26. /// <param name="nativeInterface"> The native interface.</param>
  27. internal NRTrackablePlane(UInt64 nativeHandle) : base(nativeHandle)
  28. {
  29. }
  30. /// <summary> Type of the trackable plane. </summary>
  31. TrackablePlaneType trackablePlaneType;
  32. /// <summary> Get the plane type. </summary>
  33. /// <returns> Plane type. </returns>
  34. public TrackablePlaneType GetPlaneType()
  35. {
  36. if (NRFrame.SessionStatus != SessionState.Running)
  37. {
  38. return trackablePlaneType;
  39. }
  40. trackablePlaneType = PlaneSubsystem.GetPlaneType(TrackableNativeHandle);
  41. return trackablePlaneType;
  42. }
  43. /// <summary> The center pose. </summary>
  44. Pose centerPose;
  45. /// <summary>
  46. /// Gets the position and orientation of the plane's center in Unity world space. </summary>
  47. /// <returns> The center pose. </returns>
  48. public override Pose GetCenterPose()
  49. {
  50. if (NRFrame.SessionStatus != SessionState.Running)
  51. {
  52. return centerPose;
  53. }
  54. centerPose = PlaneSubsystem.GetCenterPose(TrackableNativeHandle);
  55. return ConversionUtility.ApiWorldToUnityWorld(centerPose);
  56. }
  57. /// <summary>
  58. /// Gets the extent of plane in the X dimension, centered on the plane position. </summary>
  59. /// <value> The extent x coordinate. </value>
  60. public float ExtentX
  61. {
  62. get
  63. {
  64. if (NRFrame.SessionStatus != SessionState.Running)
  65. {
  66. return 0;
  67. }
  68. return PlaneSubsystem.GetExtentX(TrackableNativeHandle);
  69. }
  70. }
  71. /// <summary>
  72. /// Gets the extent of plane in the Z dimension, centered on the plane position. </summary>
  73. /// <value> The extent z coordinate. </value>
  74. public float ExtentZ
  75. {
  76. get
  77. {
  78. if (NRFrame.SessionStatus != SessionState.Running)
  79. {
  80. return 0;
  81. }
  82. return PlaneSubsystem.GetExtentZ(TrackableNativeHandle);
  83. }
  84. }
  85. /// <summary>
  86. /// Gets a list of points(in clockwise order) in plane coordinate representing a boundary polygon
  87. /// for the plane. </summary>
  88. /// <param name="polygonList"> polygonList A list used to be filled with polygon points.</param>
  89. public void GetBoundaryPolygon(List<Vector3> polygonList)
  90. {
  91. if (NRFrame.SessionStatus != SessionState.Running)
  92. {
  93. return;
  94. }
  95. var planetype = GetPlaneType();
  96. if (planetype == TrackablePlaneType.INVALID)
  97. {
  98. NRDebugger.Error("Invalid plane type.");
  99. return;
  100. }
  101. PlaneSubsystem.GetBoundaryPolygon(TrackableNativeHandle, polygonList);
  102. }
  103. }
  104. }