ARInterface.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace UnityARInterface
  6. {
  7. public abstract class ARInterface
  8. {
  9. public struct Settings
  10. {
  11. public bool enablePointCloud;
  12. public bool enablePlaneDetection;
  13. public bool enableLightEstimation;
  14. }
  15. public struct CameraImage
  16. {
  17. public byte[] y;
  18. public byte[] uv;
  19. public int width;
  20. public int height;
  21. }
  22. public struct PointCloud
  23. {
  24. public List<Vector3> points;
  25. }
  26. [Flags]
  27. public enum LightEstimateCapabilities
  28. {
  29. None = 0,
  30. AmbientIntensity = 1 << 0,
  31. AmbientColorTemperature = 1 << 1,
  32. }
  33. public struct LightEstimate
  34. {
  35. public LightEstimateCapabilities capabilities;
  36. public float ambientIntensity;
  37. public float ambientColorTemperature;
  38. };
  39. public static Action<BoundedPlane> planeAdded;
  40. public static Action<BoundedPlane> planeUpdated;
  41. public static Action<BoundedPlane> planeRemoved;
  42. public virtual bool IsRunning { get; protected set; }
  43. public virtual bool IsSupported { get { return true; } }
  44. public virtual bool BackgroundRendering { get { return false; } set{ } }
  45. public abstract IEnumerator StartService(Settings settings);
  46. public abstract void StopService();
  47. public bool TryGetPose(ref Pose pose)
  48. {
  49. return TryGetUnscaledPose(ref pose);
  50. }
  51. public abstract void SetupCamera(Camera camera);
  52. // This is to perform any per-frame updates for the camera,
  53. // e.g. FOV or projection matrix. Not for setting position.
  54. public abstract void UpdateCamera(Camera camera);
  55. public abstract void Update();
  56. public abstract bool TryGetUnscaledPose(ref Pose pose);
  57. public abstract bool TryGetCameraImage(ref CameraImage cameraImage);
  58. public abstract bool TryGetPointCloud(ref PointCloud pointCloud);
  59. public abstract LightEstimate GetLightEstimate();
  60. public abstract Matrix4x4 GetDisplayTransform ();
  61. protected void OnPlaneAdded(BoundedPlane plane)
  62. {
  63. if (planeAdded != null)
  64. planeAdded(plane);
  65. }
  66. protected void OnPlaneUpdated(BoundedPlane plane)
  67. {
  68. if (planeUpdated != null)
  69. planeUpdated(plane);
  70. }
  71. protected void OnPlaneRemoved(BoundedPlane plane)
  72. {
  73. if (planeRemoved != null)
  74. planeRemoved(plane);
  75. }
  76. public virtual void ApplyAnchor(ARAnchor arAnchor)
  77. {
  78. }
  79. public virtual void DestroyAnchor(ARAnchor arAnchor)
  80. {
  81. }
  82. private static ARInterface m_Interface;
  83. public static ARInterface GetInterface()
  84. {
  85. if (m_Interface == null)
  86. {
  87. #if UNITY_EDITOR
  88. m_Interface = new AREditorInterface();
  89. #elif UNITY_IOS
  90. m_Interface = new ARKitInterface();
  91. #elif UNITY_ANDROID
  92. m_Interface = new ARCoreInterface();
  93. #endif
  94. }
  95. return m_Interface;
  96. }
  97. public static void SetInterface(ARInterface arInterface)
  98. {
  99. m_Interface = arInterface;
  100. }
  101. }
  102. }