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.

256 lines
8.5 KiB

4 years ago
  1. using System;
  2. namespace UnityEngine.XR.ARSubsystems
  3. {
  4. /// <summary>
  5. /// Capabilities of a face subsystem implementation.
  6. /// </summary>
  7. [Flags]
  8. public enum FaceSubsystemCapabilities
  9. {
  10. /// <summary>
  11. /// The subsystem has no capabilities
  12. /// </summary>
  13. None = 0,
  14. /// <summary>
  15. /// The subsystem can produce a <c>Pose</c> for a face.
  16. /// </summary>
  17. Pose = 1 << 0,
  18. /// <summary>
  19. /// The subsystem can generate vertices and triangle indices for a mesh representing a face.
  20. /// </summary>
  21. MeshVerticesAndIndices = 1 << 1,
  22. /// <summary>
  23. /// The subsystem can supply texture coordinates for a face mesh.
  24. /// </summary>
  25. MeshUVs = 1 << 2,
  26. /// <summary>
  27. /// The subsystem can supply normals for a face mesh.
  28. /// </summary>
  29. MeshNormals = 1 << 3,
  30. /// <summary>
  31. /// The subsystem can supply eye tracking data for a face.
  32. /// </summary>
  33. EyeTracking = 1 << 4
  34. }
  35. /// <summary>
  36. /// This struct is an initializer for the creation of a <see cref="XRFaceSubsystemDescriptor"/>.
  37. /// </summary>
  38. /// <remarks>
  39. /// Face Tracking data provider should create during <c>InitializeOnLoad<c> a descriptor using
  40. /// the params here to specify which of the XRFaceSubsystem features it supports.
  41. /// </remarks>
  42. public struct FaceSubsystemParams : IEquatable<FaceSubsystemParams>
  43. {
  44. /// <summary>
  45. /// The string identifier for a specific implementation.
  46. /// </summary>
  47. public string id { get; set; }
  48. /// <summary>
  49. /// The concrete <c>Type</c> which will be instantiated if <c>Create</c> is called on this subsystem descriptor.
  50. /// </summary>
  51. public Type subsystemImplementationType { get; set; }
  52. /// <summary>
  53. /// Whether the subsystem supports getting a pose for the face.
  54. /// </summary>
  55. public bool supportsFacePose
  56. {
  57. get { return (m_Capabilities & FaceSubsystemCapabilities.Pose) != 0; }
  58. set
  59. {
  60. if (value)
  61. {
  62. m_Capabilities |= FaceSubsystemCapabilities.Pose;
  63. }
  64. else
  65. {
  66. m_Capabilities &= ~FaceSubsystemCapabilities.Pose;
  67. }
  68. }
  69. }
  70. /// <summary>
  71. /// Whether the subsystem supports getting vertices and triangle indices describing a face mesh.
  72. /// </summary>
  73. public bool supportsFaceMeshVerticesAndIndices
  74. {
  75. get { return (m_Capabilities & FaceSubsystemCapabilities.MeshVerticesAndIndices) != 0; }
  76. set
  77. {
  78. if (value)
  79. {
  80. m_Capabilities |= FaceSubsystemCapabilities.MeshVerticesAndIndices;
  81. }
  82. else
  83. {
  84. m_Capabilities &= ~FaceSubsystemCapabilities.MeshVerticesAndIndices;
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// Whether the subsystem supports texture coordinates for the face mesh.
  90. /// </summary>
  91. public bool supportsFaceMeshUVs
  92. {
  93. get { return (m_Capabilities & FaceSubsystemCapabilities.MeshUVs) != 0; }
  94. set
  95. {
  96. if (value)
  97. {
  98. m_Capabilities |= FaceSubsystemCapabilities.MeshUVs;
  99. }
  100. else
  101. {
  102. m_Capabilities &= ~FaceSubsystemCapabilities.MeshUVs;
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// Whether the subsystem supports normals for the face mesh.
  108. /// </summary>
  109. public bool supportsFaceMeshNormals
  110. {
  111. get { return (m_Capabilities & FaceSubsystemCapabilities.MeshNormals) != 0; }
  112. set
  113. {
  114. if (value)
  115. {
  116. m_Capabilities |= FaceSubsystemCapabilities.MeshNormals;
  117. }
  118. else
  119. {
  120. m_Capabilities &= ~FaceSubsystemCapabilities.MeshNormals;
  121. }
  122. }
  123. }
  124. /// <summary>
  125. /// Whether the subsystem supports eye tracking for each detected face.
  126. /// </summary>
  127. public bool supportsEyeTracking
  128. {
  129. get { return (m_Capabilities & FaceSubsystemCapabilities.EyeTracking) != 0; }
  130. set
  131. {
  132. if (value)
  133. {
  134. m_Capabilities |= FaceSubsystemCapabilities.EyeTracking;
  135. }
  136. else
  137. {
  138. m_Capabilities &= FaceSubsystemCapabilities.EyeTracking;
  139. }
  140. }
  141. }
  142. FaceSubsystemCapabilities m_Capabilities;
  143. //IEquatable boilerplate
  144. public bool Equals(FaceSubsystemParams other)
  145. {
  146. return
  147. (m_Capabilities == other.m_Capabilities) &&
  148. (id == other.id) &&
  149. (subsystemImplementationType == other.subsystemImplementationType);
  150. }
  151. public override bool Equals(object obj)
  152. {
  153. if (!(obj is FaceSubsystemParams))
  154. {
  155. return false;
  156. }
  157. return Equals((FaceSubsystemParams)obj);
  158. }
  159. public override int GetHashCode()
  160. {
  161. unchecked
  162. {
  163. var hashCode = (id == null) ? 0 : id.GetHashCode();
  164. hashCode = (hashCode * 486187739) + subsystemImplementationType.GetHashCode();
  165. hashCode = (hashCode * 486187739) + ((int)m_Capabilities).GetHashCode();
  166. return hashCode;
  167. }
  168. }
  169. public static bool operator==(FaceSubsystemParams lhs, FaceSubsystemParams rhs)
  170. {
  171. return lhs.Equals(rhs);
  172. }
  173. public static bool operator!=(FaceSubsystemParams lhs, FaceSubsystemParams rhs)
  174. {
  175. return !lhs.Equals(rhs);
  176. }
  177. }
  178. /// <summary>
  179. /// The descriptor of the <see cref="XRFaceSubsystem"/> that shows which face tracking features are available on that XRSubsystem.
  180. /// </summary>
  181. /// <remarks>
  182. /// You use the <c>Create<c> factory method along with <see cref="FaceSubsystemParams"/> struct to construct and
  183. /// register one of these from each face tracking data provider.
  184. /// </remarks>
  185. public class XRFaceSubsystemDescriptor : SubsystemDescriptor<XRFaceSubsystem>
  186. {
  187. XRFaceSubsystemDescriptor(FaceSubsystemParams descriptorParams)
  188. {
  189. id = descriptorParams.id;
  190. subsystemImplementationType = descriptorParams.subsystemImplementationType;
  191. supportsFacePose = descriptorParams.supportsFacePose;
  192. supportsFaceMeshVerticesAndIndices = descriptorParams.supportsFaceMeshVerticesAndIndices;
  193. supportsFaceMeshUVs = descriptorParams.supportsFaceMeshUVs;
  194. supportsFaceMeshNormals = descriptorParams.supportsFaceMeshNormals;
  195. supportsEyeTracking = descriptorParams.supportsEyeTracking;
  196. }
  197. /// <summary>
  198. /// Whether the subsystem can produce a <c>Pose</c> for each detected face.
  199. /// </summary>
  200. public bool supportsFacePose { get; }
  201. /// <summary>
  202. /// Whether the subsystem supports face meshes, and can produce vertices and triangle indices representing a face mesh.
  203. /// </summary>
  204. public bool supportsFaceMeshVerticesAndIndices { get; }
  205. /// <summary>
  206. /// Whether the subsystem supports texture coordinates for each face mesh.
  207. /// </summary>
  208. public bool supportsFaceMeshUVs { get; }
  209. /// <summary>
  210. /// Whether the subsystem supports normals for each face mesh.
  211. /// </summary>
  212. public bool supportsFaceMeshNormals { get; }
  213. /// <summary>
  214. /// Whether the subsystem supports eye tracking for each detected face.
  215. /// </summary>
  216. public bool supportsEyeTracking { get; }
  217. /// <summary>
  218. /// Creates a subsystem descriptor. Used to register an implementation of the <see cref="XRFaceSubsystem"/>.
  219. /// </summary>
  220. /// <param name="descriptorParams">Parameters describing the <see cref="XRFaceSubsystem"/>.</param>
  221. public static void Create(FaceSubsystemParams descriptorParams)
  222. {
  223. var descriptor = new XRFaceSubsystemDescriptor(descriptorParams);
  224. SubsystemRegistration.CreateDescriptor(descriptor);
  225. }
  226. }
  227. }