0.2.0-dev Download ZIP
214 lines ·11.1 KB Raw
| 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 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include "servers/xr/xr_tracker.h" |
| 34 | |
| 35 | /** |
| 36 | The XRFaceTracker class provides face blend shape weights. |
| 37 | |
| 38 | The supported blend shapes are based on the Unified Expressions |
| 39 | standard, and as such have a well defined mapping to ARKit, SRanipal, |
| 40 | and Meta Movement standards. |
| 41 | */ |
| 42 | |
| 43 | class XRFaceTracker : public XRTracker { |
| 44 | GDCLASS(XRFaceTracker, XRTracker); |
| 45 | _THREAD_SAFE_CLASS_ |
| 46 | |
| 47 | public: |
| 48 | enum BlendShapeEntry { |
| 49 | // Base Shapes |
| 50 | FT_EYE_LOOK_OUT_RIGHT, // Right eye looks outwards. |
| 51 | FT_EYE_LOOK_IN_RIGHT, // Right eye looks inwards. |
| 52 | FT_EYE_LOOK_UP_RIGHT, // Right eye looks upwards. |
| 53 | FT_EYE_LOOK_DOWN_RIGHT, // Right eye looks downwards. |
| 54 | FT_EYE_LOOK_OUT_LEFT, // Left eye looks outwards. |
| 55 | FT_EYE_LOOK_IN_LEFT, // Left eye looks inwards. |
| 56 | FT_EYE_LOOK_UP_LEFT, // Left eye looks upwards. |
| 57 | FT_EYE_LOOK_DOWN_LEFT, // Left eye looks downwards. |
| 58 | FT_EYE_CLOSED_RIGHT, // Closes the right eyelid. |
| 59 | FT_EYE_CLOSED_LEFT, // Closes the left eyelid. |
| 60 | FT_EYE_SQUINT_RIGHT, // Squeezes the right eye socket muscles. |
| 61 | FT_EYE_SQUINT_LEFT, // Squeezes the left eye socket muscles. |
| 62 | FT_EYE_WIDE_RIGHT, // Right eyelid widens beyond relaxed. |
| 63 | FT_EYE_WIDE_LEFT, // Left eyelid widens beyond relaxed. |
| 64 | FT_EYE_DILATION_RIGHT, // Dilates the right eye pupil. |
| 65 | FT_EYE_DILATION_LEFT, // Dilates the left eye pupil. |
| 66 | FT_EYE_CONSTRICT_RIGHT, // Constricts the right eye pupil. |
| 67 | FT_EYE_CONSTRICT_LEFT, // Constricts the left eye pupil. |
| 68 | FT_BROW_PINCH_RIGHT, // Right eyebrow pinches in. |
| 69 | FT_BROW_PINCH_LEFT, // Left eyebrow pinches in. |
| 70 | FT_BROW_LOWERER_RIGHT, // Outer right eyebrow pulls down. |
| 71 | FT_BROW_LOWERER_LEFT, // Outer left eyebrow pulls down. |
| 72 | FT_BROW_INNER_UP_RIGHT, // Inner right eyebrow pulls up. |
| 73 | FT_BROW_INNER_UP_LEFT, // Inner left eyebrow pulls up. |
| 74 | FT_BROW_OUTER_UP_RIGHT, // Outer right eyebrow pulls up. |
| 75 | FT_BROW_OUTER_UP_LEFT, // Outer left eyebrow pulls up. |
| 76 | FT_NOSE_SNEER_RIGHT, // Right side face sneers. |
| 77 | FT_NOSE_SNEER_LEFT, // Left side face sneers. |
| 78 | FT_NASAL_DILATION_RIGHT, // Right side nose canal dilates. |
| 79 | FT_NASAL_DILATION_LEFT, // Left side nose canal dilates. |
| 80 | FT_NASAL_CONSTRICT_RIGHT, // Right side nose canal constricts. |
| 81 | FT_NASAL_CONSTRICT_LEFT, // Left side nose canal constricts. |
| 82 | FT_CHEEK_SQUINT_RIGHT, // Raises the right side cheek. |
| 83 | FT_CHEEK_SQUINT_LEFT, // Raises the left side cheek. |
| 84 | FT_CHEEK_PUFF_RIGHT, // Puffs the right side cheek. |
| 85 | FT_CHEEK_PUFF_LEFT, // Puffs the left side cheek. |
| 86 | FT_CHEEK_SUCK_RIGHT, // Sucks in the right side cheek. |
| 87 | FT_CHEEK_SUCK_LEFT, // Sucks in the left side cheek. |
| 88 | FT_JAW_OPEN, // Opens jawbone. |
| 89 | FT_MOUTH_CLOSED, // Closes the mouth. |
| 90 | FT_JAW_RIGHT, // Pushes jawbone right. |
| 91 | FT_JAW_LEFT, // Pushes jawbone left. |
| 92 | FT_JAW_FORWARD, // Pushes jawbone forward. |
| 93 | FT_JAW_BACKWARD, // Pushes jawbone backward. |
| 94 | FT_JAW_CLENCH, // Flexes jaw muscles. |
| 95 | FT_JAW_MANDIBLE_RAISE, // Raises the jawbone. |
| 96 | FT_LIP_SUCK_UPPER_RIGHT, // Upper right lip part tucks in the mouth. |
| 97 | FT_LIP_SUCK_UPPER_LEFT, // Upper left lip part tucks in the mouth. |
| 98 | FT_LIP_SUCK_LOWER_RIGHT, // Lower right lip part tucks in the mouth. |
| 99 | FT_LIP_SUCK_LOWER_LEFT, // Lower left lip part tucks in the mouth. |
| 100 | FT_LIP_SUCK_CORNER_RIGHT, // Right lip corner folds into the mouth. |
| 101 | FT_LIP_SUCK_CORNER_LEFT, // Left lip corner folds into the mouth. |
| 102 | FT_LIP_FUNNEL_UPPER_RIGHT, // Upper right lip part pushes into a funnel. |
| 103 | FT_LIP_FUNNEL_UPPER_LEFT, // Upper left lip part pushes into a funnel. |
| 104 | FT_LIP_FUNNEL_LOWER_RIGHT, // Lower right lip part pushes into a funnel. |
| 105 | FT_LIP_FUNNEL_LOWER_LEFT, // Lower left lip part pushes into a funnel. |
| 106 | FT_LIP_PUCKER_UPPER_RIGHT, // Upper right lip part pushes outwards. |
| 107 | FT_LIP_PUCKER_UPPER_LEFT, // Upper left lip part pushes outwards. |
| 108 | FT_LIP_PUCKER_LOWER_RIGHT, // Lower right lip part pushes outwards. |
| 109 | FT_LIP_PUCKER_LOWER_LEFT, // Lower left lip part pushes outwards. |
| 110 | FT_MOUTH_UPPER_UP_RIGHT, // Upper right part of the lip pulls up. |
| 111 | FT_MOUTH_UPPER_UP_LEFT, // Upper left part of the lip pulls up. |
| 112 | FT_MOUTH_LOWER_DOWN_RIGHT, // Lower right part of the lip pulls up. |
| 113 | FT_MOUTH_LOWER_DOWN_LEFT, // Lower left part of the lip pulls up. |
| 114 | FT_MOUTH_UPPER_DEEPEN_RIGHT, // Upper right lip part pushes in the cheek. |
| 115 | FT_MOUTH_UPPER_DEEPEN_LEFT, // Upper left lip part pushes in the cheek. |
| 116 | FT_MOUTH_UPPER_RIGHT, // Moves upper lip right. |
| 117 | FT_MOUTH_UPPER_LEFT, // Moves upper lip left. |
| 118 | FT_MOUTH_LOWER_RIGHT, // Moves lower lip right. |
| 119 | FT_MOUTH_LOWER_LEFT, // Moves lower lip left. |
| 120 | FT_MOUTH_CORNER_PULL_RIGHT, // Right lip corner pulls diagonally up and out. |
| 121 | FT_MOUTH_CORNER_PULL_LEFT, // Left lip corner pulls diagonally up and out. |
| 122 | FT_MOUTH_CORNER_SLANT_RIGHT, // Right corner lip slants up. |
| 123 | FT_MOUTH_CORNER_SLANT_LEFT, // Left corner lip slants up. |
| 124 | FT_MOUTH_FROWN_RIGHT, // Right corner lip pulls down. |
| 125 | FT_MOUTH_FROWN_LEFT, // Left corner lip pulls down. |
| 126 | FT_MOUTH_STRETCH_RIGHT, // Mouth corner lip pulls out and down. |
| 127 | FT_MOUTH_STRETCH_LEFT, // Mouth corner lip pulls out and down. |
| 128 | FT_MOUTH_DIMPLE_RIGHT, // Right lip corner is pushed backwards. |
| 129 | FT_MOUTH_DIMPLE_LEFT, // Left lip corner is pushed backwards. |
| 130 | FT_MOUTH_RAISER_UPPER, // Raises and slightly pushes out the upper mouth. |
| 131 | FT_MOUTH_RAISER_LOWER, // Raises and slightly pushes out the lower mouth. |
| 132 | FT_MOUTH_PRESS_RIGHT, // Right side lips press and flatten together vertically. |
| 133 | FT_MOUTH_PRESS_LEFT, // Left side lips press and flatten together vertically. |
| 134 | FT_MOUTH_TIGHTENER_RIGHT, // Right side lips squeeze together horizontally. |
| 135 | FT_MOUTH_TIGHTENER_LEFT, // Left side lips squeeze together horizontally. |
| 136 | FT_TONGUE_OUT, // Tongue visibly sticks out of the mouth. |
| 137 | FT_TONGUE_UP, // Tongue points upwards. |
| 138 | FT_TONGUE_DOWN, // Tongue points downwards. |
| 139 | FT_TONGUE_RIGHT, // Tongue points right. |
| 140 | FT_TONGUE_LEFT, // Tongue points left. |
| 141 | FT_TONGUE_ROLL, // Sides of the tongue funnel, creating a roll. |
| 142 | FT_TONGUE_BLEND_DOWN, // Tongue arches up then down inside the mouth. |
| 143 | FT_TONGUE_CURL_UP, // Tongue arches down then up inside the mouth. |
| 144 | FT_TONGUE_SQUISH, // Tongue squishes together and thickens. |
| 145 | FT_TONGUE_FLAT, // Tongue flattens and thins out. |
| 146 | FT_TONGUE_TWIST_RIGHT, // Tongue tip rotates clockwise, with the rest following gradually. |
| 147 | FT_TONGUE_TWIST_LEFT, // Tongue tip rotates counter-clockwise, with the rest following gradually. |
| 148 | FT_SOFT_PALATE_CLOSE, // Inner mouth throat closes. |
| 149 | FT_THROAT_SWALLOW, // The Adam's apple visibly swallows. |
| 150 | FT_NECK_FLEX_RIGHT, // Right side neck visibly flexes. |
| 151 | FT_NECK_FLEX_LEFT, // Left side neck visibly flexes. |
| 152 | // Blended Shapes |
| 153 | FT_EYE_CLOSED, // Closes both eye lids. |
| 154 | FT_EYE_WIDE, // Widens both eye lids. |
| 155 | FT_EYE_SQUINT, // Squints both eye lids. |
| 156 | FT_EYE_DILATION, // Dilates both pupils. |
| 157 | FT_EYE_CONSTRICT, // Constricts both pupils. |
| 158 | FT_BROW_DOWN_RIGHT, // Pulls the right eyebrow down and in. |
| 159 | FT_BROW_DOWN_LEFT, // Pulls the left eyebrow down and in. |
| 160 | FT_BROW_DOWN, // Pulls both eyebrows down and in. |
| 161 | FT_BROW_UP_RIGHT, // Right brow appears worried. |
| 162 | FT_BROW_UP_LEFT, // Left brow appears worried. |
| 163 | FT_BROW_UP, // Both brows appear worried. |
| 164 | FT_NOSE_SNEER, // Entire face sneers. |
| 165 | FT_NASAL_DILATION, // Both nose canals dilate. |
| 166 | FT_NASAL_CONSTRICT, // Both nose canals constrict. |
| 167 | FT_CHEEK_PUFF, // Puffs both cheeks. |
| 168 | FT_CHEEK_SUCK, // Sucks in both cheeks. |
| 169 | FT_CHEEK_SQUINT, // Raises both cheeks. |
| 170 | FT_LIP_SUCK_UPPER, // Tucks in the upper lips. |
| 171 | FT_LIP_SUCK_LOWER, // Tucks in the lower lips. |
| 172 | FT_LIP_SUCK, // Tucks in both lips. |
| 173 | FT_LIP_FUNNEL_UPPER, // Funnels in the upper lips. |
| 174 | FT_LIP_FUNNEL_LOWER, // Funnels in the lower lips. |
| 175 | FT_LIP_FUNNEL, // Funnels in both lips. |
| 176 | FT_LIP_PUCKER_UPPER, // Upper lip part pushes outwards. |
| 177 | FT_LIP_PUCKER_LOWER, // Lower lip part pushes outwards. |
| 178 | FT_LIP_PUCKER, // Lips push outwards. |
| 179 | FT_MOUTH_UPPER_UP, // Raises the upper lips. |
| 180 | FT_MOUTH_LOWER_DOWN, // Lowers the lower lips. |
| 181 | FT_MOUTH_OPEN, // Mouth opens, revealing teeth. |
| 182 | FT_MOUTH_RIGHT, // Moves mouth right. |
| 183 | FT_MOUTH_LEFT, // Moves mouth left. |
| 184 | FT_MOUTH_SMILE_RIGHT, // Right side of the mouth smiles. |
| 185 | FT_MOUTH_SMILE_LEFT, // Left side of the mouth smiles. |
| 186 | FT_MOUTH_SMILE, // Mouth expresses a smile. |
| 187 | FT_MOUTH_SAD_RIGHT, // Right side of the mouth expresses sadness. |
| 188 | FT_MOUTH_SAD_LEFT, // Left side of the mouth expresses sadness. |
| 189 | FT_MOUTH_SAD, // Mouth expresses sadness. |
| 190 | FT_MOUTH_STRETCH, // Mouth stretches. |
| 191 | FT_MOUTH_DIMPLE, // Lip corners dimple. |
| 192 | FT_MOUTH_TIGHTENER, // Mouth tightens. |
| 193 | FT_MOUTH_PRESS, // Mouth presses together. |
| 194 | FT_MAX // Maximum blend shape. |
| 195 | }; |
| 196 | |
| 197 | void set_tracker_type(XRServer::TrackerType p_type) override; |
| 198 | |
| 199 | float get_blend_shape(BlendShapeEntry p_blend_shape) const; |
| 200 | void set_blend_shape(BlendShapeEntry p_blend_shape, float p_value); |
| 201 | |
| 202 | PackedFloat32Array get_blend_shapes() const; |
| 203 | void set_blend_shapes(const PackedFloat32Array &p_blend_shapes); |
| 204 | |
| 205 | XRFaceTracker(); |
| 206 | |
| 207 | protected: |
| 208 | static void _bind_methods(); |
| 209 | |
| 210 | private: |
| 211 | float blend_shape_values[FT_MAX] = {}; |
| 212 | }; |
| 213 | |
| 214 | VARIANT_ENUM_CAST(XRFaceTracker::BlendShapeEntry); |