Dynamic face tracking icon

This commit is contained in:
Patrick Nicolas
2024-09-21 20:51:08 +02:00
committed by Guillaume Meunier
parent 6a0e703538
commit e99b400e26
2 changed files with 207 additions and 4 deletions
+206 -3
View File
@@ -609,7 +609,210 @@ static void ScrollWhenDraggingOnVoid(ImVec2 delta)
ImGui::SetScrollY(window, window->Scroll.y + delta.y);
}
void scenes::lobby::draw_features_status()
static auto face_weights()
{
using weights = decltype(xrt::drivers::wivrn::from_headset::fb_face2{}.weights);
using item = std::pair<const char *, std::array<float, XR_FACE_EXPRESSION2_COUNT_FB>>;
std::vector<item> res;
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_SMILE, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_TIRED, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1;
res.emplace_back(ICON_FA_FACE_SURPRISE, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB] = 1;
res.emplace_back(ICON_FA_FACE_SMILE_WINK, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_SMILE_WINK, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_SMILE_BEAM, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB] = 1;
face[XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_SAD_CRY, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB] = 1;
face[XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_ROLLING_EYES, face);
}
{
weights face{};
res.emplace_back(ICON_FA_FACE_MEH, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB] = 1;
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1;
res.emplace_back(ICON_FA_FACE_LAUGH_WINK, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB] = 1;
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1;
res.emplace_back(ICON_FA_FACE_LAUGH_WINK, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1;
res.emplace_back(ICON_FA_FACE_LAUGH_SQUINT, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 1;
res.emplace_back(ICON_FA_FACE_LAUGH, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_GRIN_WIDE, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB] = 1;
face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1;
res.emplace_back(ICON_FA_FACE_GRIN_TONGUE_WINK, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB] = 1;
face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1;
res.emplace_back(ICON_FA_FACE_GRIN_TONGUE_WINK, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1;
res.emplace_back(ICON_FA_FACE_GRIN_TONGUE_SQUINT, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_TONGUE_OUT_FB] = 1;
res.emplace_back(ICON_FA_FACE_GRIN_TONGUE, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 0.5;
res.emplace_back(ICON_FA_FACE_GRIN, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB] = 0.5;
face[XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB] = 0.5;
res.emplace_back(ICON_FA_FACE_GRIMACE, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1;
face[XR_FACE_EXPRESSION2_JAW_DROP_FB] = 0.5;
res.emplace_back(ICON_FA_FACE_FROWN_OPEN, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_FROWN, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB] = 1;
face[XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB] = 0.5;
face[XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB] = 0.5;
res.emplace_back(ICON_FA_FACE_FLUSHED, face);
}
{
weights face{};
face[XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB] = 1;
face[XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB] = 1;
res.emplace_back(ICON_FA_FACE_ANGRY, face);
}
return res;
}
static const char * get_face_icon(XrTime predicted_display_time)
{
static const auto w = face_weights();
xrt::drivers::wivrn::from_headset::fb_face2 expression;
application::get_fb_face_tracker2().get_weights(predicted_display_time, &expression);
if (not expression.is_valid)
return ICON_FA_FACE_MEH;
return std::ranges::min_element(w, std::ranges::less(), [&](const auto & p) {
float res = 0;
for (size_t i = 0; i < XR_FACE_EXPRESSION2_COUNT_FB; ++i)
{
float d = expression.weights[i] - p.second[i];
res += d * d;
}
return res;
})
->first;
}
void scenes::lobby::draw_features_status(XrTime predicted_display_time)
{
const float win_width = ImGui::GetWindowSize().x;
float text_width = 0;
@@ -644,7 +847,7 @@ void scenes::lobby::draw_features_status()
{
items.push_back({
.f = feature::face_tracking,
.icon_enabled = ICON_FA_FACE_SMILE,
.icon_enabled = get_face_icon(predicted_display_time),
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
});
}
@@ -715,7 +918,7 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
switch (current_tab)
{
case tab::server_list:
draw_features_status();
draw_features_status(predicted_display_time);
gui_server_list();
break;