xr_face_tracker.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**************************************************************************/
  2. /* xr_face_tracker.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef XR_FACE_TRACKER_H
  31. #define XR_FACE_TRACKER_H
  32. #include "servers/xr/xr_tracker.h"
  33. /**
  34. The XRFaceTracker class provides face blend shape weights.
  35. The supported blend shapes are based on the Unified Expressions
  36. standard, and as such have a well defined mapping to ARKit, SRanipal,
  37. and Meta Movement standards.
  38. */
  39. class XRFaceTracker : public XRTracker {
  40. GDCLASS(XRFaceTracker, XRTracker);
  41. _THREAD_SAFE_CLASS_
  42. public:
  43. enum BlendShapeEntry {
  44. // Base Shapes
  45. FT_EYE_LOOK_OUT_RIGHT, // Right eye looks outwards.
  46. FT_EYE_LOOK_IN_RIGHT, // Right eye looks inwards.
  47. FT_EYE_LOOK_UP_RIGHT, // Right eye looks upwards.
  48. FT_EYE_LOOK_DOWN_RIGHT, // Right eye looks downwards.
  49. FT_EYE_LOOK_OUT_LEFT, // Left eye looks outwards.
  50. FT_EYE_LOOK_IN_LEFT, // Left eye looks inwards.
  51. FT_EYE_LOOK_UP_LEFT, // Left eye looks upwards.
  52. FT_EYE_LOOK_DOWN_LEFT, // Left eye looks downwards.
  53. FT_EYE_CLOSED_RIGHT, // Closes the right eyelid.
  54. FT_EYE_CLOSED_LEFT, // Closes the left eyelid.
  55. FT_EYE_SQUINT_RIGHT, // Squeezes the right eye socket muscles.
  56. FT_EYE_SQUINT_LEFT, // Squeezes the left eye socket muscles.
  57. FT_EYE_WIDE_RIGHT, // Right eyelid widens beyond relaxed.
  58. FT_EYE_WIDE_LEFT, // Left eyelid widens beyond relaxed.
  59. FT_EYE_DILATION_RIGHT, // Dilates the right eye pupil.
  60. FT_EYE_DILATION_LEFT, // Dilates the left eye pupil.
  61. FT_EYE_CONSTRICT_RIGHT, // Constricts the right eye pupil.
  62. FT_EYE_CONSTRICT_LEFT, // Constricts the left eye pupil.
  63. FT_BROW_PINCH_RIGHT, // Right eyebrow pinches in.
  64. FT_BROW_PINCH_LEFT, // Left eyebrow pinches in.
  65. FT_BROW_LOWERER_RIGHT, // Outer right eyebrow pulls down.
  66. FT_BROW_LOWERER_LEFT, // Outer left eyebrow pulls down.
  67. FT_BROW_INNER_UP_RIGHT, // Inner right eyebrow pulls up.
  68. FT_BROW_INNER_UP_LEFT, // Inner left eyebrow pulls up.
  69. FT_BROW_OUTER_UP_RIGHT, // Outer right eyebrow pulls up.
  70. FT_BROW_OUTER_UP_LEFT, // Outer left eyebrow pulls up.
  71. FT_NOSE_SNEER_RIGHT, // Right side face sneers.
  72. FT_NOSE_SNEER_LEFT, // Left side face sneers.
  73. FT_NASAL_DILATION_RIGHT, // Right side nose canal dilates.
  74. FT_NASAL_DILATION_LEFT, // Left side nose canal dilates.
  75. FT_NASAL_CONSTRICT_RIGHT, // Right side nose canal constricts.
  76. FT_NASAL_CONSTRICT_LEFT, // Left side nose canal constricts.
  77. FT_CHEEK_SQUINT_RIGHT, // Raises the right side cheek.
  78. FT_CHEEK_SQUINT_LEFT, // Raises the left side cheek.
  79. FT_CHEEK_PUFF_RIGHT, // Puffs the right side cheek.
  80. FT_CHEEK_PUFF_LEFT, // Puffs the left side cheek.
  81. FT_CHEEK_SUCK_RIGHT, // Sucks in the right side cheek.
  82. FT_CHEEK_SUCK_LEFT, // Sucks in the left side cheek.
  83. FT_JAW_OPEN, // Opens jawbone.
  84. FT_MOUTH_CLOSED, // Closes the mouth.
  85. FT_JAW_RIGHT, // Pushes jawbone right.
  86. FT_JAW_LEFT, // Pushes jawbone left.
  87. FT_JAW_FORWARD, // Pushes jawbone forward.
  88. FT_JAW_BACKWARD, // Pushes jawbone backward.
  89. FT_JAW_CLENCH, // Flexes jaw muscles.
  90. FT_JAW_MANDIBLE_RAISE, // Raises the jawbone.
  91. FT_LIP_SUCK_UPPER_RIGHT, // Upper right lip part tucks in the mouth.
  92. FT_LIP_SUCK_UPPER_LEFT, // Upper left lip part tucks in the mouth.
  93. FT_LIP_SUCK_LOWER_RIGHT, // Lower right lip part tucks in the mouth.
  94. FT_LIP_SUCK_LOWER_LEFT, // Lower left lip part tucks in the mouth.
  95. FT_LIP_SUCK_CORNER_RIGHT, // Right lip corner folds into the mouth.
  96. FT_LIP_SUCK_CORNER_LEFT, // Left lip corner folds into the mouth.
  97. FT_LIP_FUNNEL_UPPER_RIGHT, // Upper right lip part pushes into a funnel.
  98. FT_LIP_FUNNEL_UPPER_LEFT, // Upper left lip part pushes into a funnel.
  99. FT_LIP_FUNNEL_LOWER_RIGHT, // Lower right lip part pushes into a funnel.
  100. FT_LIP_FUNNEL_LOWER_LEFT, // Lower left lip part pushes into a funnel.
  101. FT_LIP_PUCKER_UPPER_RIGHT, // Upper right lip part pushes outwards.
  102. FT_LIP_PUCKER_UPPER_LEFT, // Upper left lip part pushes outwards.
  103. FT_LIP_PUCKER_LOWER_RIGHT, // Lower right lip part pushes outwards.
  104. FT_LIP_PUCKER_LOWER_LEFT, // Lower left lip part pushes outwards.
  105. FT_MOUTH_UPPER_UP_RIGHT, // Upper right part of the lip pulls up.
  106. FT_MOUTH_UPPER_UP_LEFT, // Upper left part of the lip pulls up.
  107. FT_MOUTH_LOWER_DOWN_RIGHT, // Lower right part of the lip pulls up.
  108. FT_MOUTH_LOWER_DOWN_LEFT, // Lower left part of the lip pulls up.
  109. FT_MOUTH_UPPER_DEEPEN_RIGHT, // Upper right lip part pushes in the cheek.
  110. FT_MOUTH_UPPER_DEEPEN_LEFT, // Upper left lip part pushes in the cheek.
  111. FT_MOUTH_UPPER_RIGHT, // Moves upper lip right.
  112. FT_MOUTH_UPPER_LEFT, // Moves upper lip left.
  113. FT_MOUTH_LOWER_RIGHT, // Moves lower lip right.
  114. FT_MOUTH_LOWER_LEFT, // Moves lower lip left.
  115. FT_MOUTH_CORNER_PULL_RIGHT, // Right lip corner pulls diagonally up and out.
  116. FT_MOUTH_CORNER_PULL_LEFT, // Left lip corner pulls diagonally up and out.
  117. FT_MOUTH_CORNER_SLANT_RIGHT, // Right corner lip slants up.
  118. FT_MOUTH_CORNER_SLANT_LEFT, // Left corner lip slants up.
  119. FT_MOUTH_FROWN_RIGHT, // Right corner lip pulls down.
  120. FT_MOUTH_FROWN_LEFT, // Left corner lip pulls down.
  121. FT_MOUTH_STRETCH_RIGHT, // Mouth corner lip pulls out and down.
  122. FT_MOUTH_STRETCH_LEFT, // Mouth corner lip pulls out and down.
  123. FT_MOUTH_DIMPLE_RIGHT, // Right lip corner is pushed backwards.
  124. FT_MOUTH_DIMPLE_LEFT, // Left lip corner is pushed backwards.
  125. FT_MOUTH_RAISER_UPPER, // Raises and slightly pushes out the upper mouth.
  126. FT_MOUTH_RAISER_LOWER, // Raises and slightly pushes out the lower mouth.
  127. FT_MOUTH_PRESS_RIGHT, // Right side lips press and flatten together vertically.
  128. FT_MOUTH_PRESS_LEFT, // Left side lips press and flatten together vertically.
  129. FT_MOUTH_TIGHTENER_RIGHT, // Right side lips squeeze together horizontally.
  130. FT_MOUTH_TIGHTENER_LEFT, // Left side lips squeeze together horizontally.
  131. FT_TONGUE_OUT, // Tongue visibly sticks out of the mouth.
  132. FT_TONGUE_UP, // Tongue points upwards.
  133. FT_TONGUE_DOWN, // Tongue points downwards.
  134. FT_TONGUE_RIGHT, // Tongue points right.
  135. FT_TONGUE_LEFT, // Tongue points left.
  136. FT_TONGUE_ROLL, // Sides of the tongue funnel, creating a roll.
  137. FT_TONGUE_BLEND_DOWN, // Tongue arches up then down inside the mouth.
  138. FT_TONGUE_CURL_UP, // Tongue arches down then up inside the mouth.
  139. FT_TONGUE_SQUISH, // Tongue squishes together and thickens.
  140. FT_TONGUE_FLAT, // Tongue flattens and thins out.
  141. FT_TONGUE_TWIST_RIGHT, // Tongue tip rotates clockwise, with the rest following gradually.
  142. FT_TONGUE_TWIST_LEFT, // Tongue tip rotates counter-clockwise, with the rest following gradually.
  143. FT_SOFT_PALATE_CLOSE, // Inner mouth throat closes.
  144. FT_THROAT_SWALLOW, // The Adam's apple visibly swallows.
  145. FT_NECK_FLEX_RIGHT, // Right side neck visibly flexes.
  146. FT_NECK_FLEX_LEFT, // Left side neck visibly flexes.
  147. // Blended Shapes
  148. FT_EYE_CLOSED, // Closes both eye lids.
  149. FT_EYE_WIDE, // Widens both eye lids.
  150. FT_EYE_SQUINT, // Squints both eye lids.
  151. FT_EYE_DILATION, // Dilates both pupils.
  152. FT_EYE_CONSTRICT, // Constricts both pupils.
  153. FT_BROW_DOWN_RIGHT, // Pulls the right eyebrow down and in.
  154. FT_BROW_DOWN_LEFT, // Pulls the left eyebrow down and in.
  155. FT_BROW_DOWN, // Pulls both eyebrows down and in.
  156. FT_BROW_UP_RIGHT, // Right brow appears worried.
  157. FT_BROW_UP_LEFT, // Left brow appears worried.
  158. FT_BROW_UP, // Both brows appear worried.
  159. FT_NOSE_SNEER, // Entire face sneers.
  160. FT_NASAL_DILATION, // Both nose canals dilate.
  161. FT_NASAL_CONSTRICT, // Both nose canals constrict.
  162. FT_CHEEK_PUFF, // Puffs both cheeks.
  163. FT_CHEEK_SUCK, // Sucks in both cheeks.
  164. FT_CHEEK_SQUINT, // Raises both cheeks.
  165. FT_LIP_SUCK_UPPER, // Tucks in the upper lips.
  166. FT_LIP_SUCK_LOWER, // Tucks in the lower lips.
  167. FT_LIP_SUCK, // Tucks in both lips.
  168. FT_LIP_FUNNEL_UPPER, // Funnels in the upper lips.
  169. FT_LIP_FUNNEL_LOWER, // Funnels in the lower lips.
  170. FT_LIP_FUNNEL, // Funnels in both lips.
  171. FT_LIP_PUCKER_UPPER, // Upper lip part pushes outwards.
  172. FT_LIP_PUCKER_LOWER, // Lower lip part pushes outwards.
  173. FT_LIP_PUCKER, // Lips push outwards.
  174. FT_MOUTH_UPPER_UP, // Raises the upper lips.
  175. FT_MOUTH_LOWER_DOWN, // Lowers the lower lips.
  176. FT_MOUTH_OPEN, // Mouth opens, revealing teeth.
  177. FT_MOUTH_RIGHT, // Moves mouth right.
  178. FT_MOUTH_LEFT, // Moves mouth left.
  179. FT_MOUTH_SMILE_RIGHT, // Right side of the mouth smiles.
  180. FT_MOUTH_SMILE_LEFT, // Left side of the mouth smiles.
  181. FT_MOUTH_SMILE, // Mouth expresses a smile.
  182. FT_MOUTH_SAD_RIGHT, // Right side of the mouth expresses sadness.
  183. FT_MOUTH_SAD_LEFT, // Left side of the mouth expresses sadness.
  184. FT_MOUTH_SAD, // Mouth expresses sadness.
  185. FT_MOUTH_STRETCH, // Mouth stretches.
  186. FT_MOUTH_DIMPLE, // Lip corners dimple.
  187. FT_MOUTH_TIGHTENER, // Mouth tightens.
  188. FT_MOUTH_PRESS, // Mouth presses together.
  189. FT_MAX // Maximum blend shape.
  190. };
  191. void set_tracker_type(XRServer::TrackerType p_type) override;
  192. float get_blend_shape(BlendShapeEntry p_blend_shape) const;
  193. void set_blend_shape(BlendShapeEntry p_blend_shape, float p_value);
  194. PackedFloat32Array get_blend_shapes() const;
  195. void set_blend_shapes(const PackedFloat32Array &p_blend_shapes);
  196. XRFaceTracker();
  197. protected:
  198. static void _bind_methods();
  199. private:
  200. float blend_shape_values[FT_MAX] = {};
  201. };
  202. VARIANT_ENUM_CAST(XRFaceTracker::BlendShapeEntry);
  203. #endif // XR_FACE_TRACKER_H