From e5ad3e02ebf28587c4ce67fb8a6a1041b4e00b33 Mon Sep 17 00:00:00 2001 From: Sebby Date: Mon, 31 Aug 2026 23:20:44 -0500 Subject: [PATCH] Toe tracking server rewrite (#1897) Co-authored-by: Erimel Co-authored-by: Erimel Co-authored-by: loucass003 --- gui/app/public/i18n/en/translation.ftl | 143 ++++++++ gui/app/src/components/Toolbar.tsx | 9 +- .../src/components/commons/BodyPartIcon.tsx | 36 +- .../components/commons/PersonFrontIcon.tsx | 21 ++ gui/app/src/components/home/ResetButton.tsx | 1 + .../pages/mounting/MountingSelectionMenu.tsx | 18 +- gui/app/src/hooks/body-parts.ts | 9 + gui/app/src/hooks/reset.ts | 5 +- gui/app/src/hooks/tracker-assignment.ts | 8 +- gui/app/src/utils/skeletonHelper.ts | 61 +++- gui/app/src/utils/skeletonParts.ts | 11 + .../java/dev/slimevr/resets/bodypart-sets.kt | 19 +- .../slimevr/skeleton/bodypart-structure.kt | 16 + .../toe-direct-link-input-processor.kt | 44 +++ .../main/java/dev/slimevr/skeleton/module.kt | 2 + .../java/dev/slimevr/skeleton/proportions.kt | 12 + .../src/main/java/dev/slimevr/vmc/mapping.kt | 132 +++++--- .../java/dev/slimevr/vmc/output-encoder.kt | 8 +- .../core/src/main/java/dev/slimevr/vmc/vrm.kt | 2 +- .../java/dev/slimevr/vrcosc/output-encoder.kt | 4 +- .../vrcosc/toe-plugin-output-encoder.kt | 113 +++++++ .../skeleton/ToeDirectLinkProcessorTest.kt | 320 ++++++++++++++++++ solarxr-protocol | 2 +- 23 files changed, 923 insertions(+), 73 deletions(-) create mode 100644 server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/toe-direct-link-input-processor.kt create mode 100644 server/core/src/main/java/dev/slimevr/vrcosc/toe-plugin-output-encoder.kt create mode 100644 server/core/src/test/java/dev/slimevr/skeleton/ToeDirectLinkProcessorTest.kt diff --git a/gui/app/public/i18n/en/translation.ftl b/gui/app/public/i18n/en/translation.ftl index 345c7a2a4..2a21e53b7 100644 --- a/gui/app/public/i18n/en/translation.ftl +++ b/gui/app/public/i18n/en/translation.ftl @@ -23,6 +23,8 @@ version_update-close = Close tips-find_tracker = Not sure which tracker is which? Shake a tracker and it will highlight the corresponding item. tips-do_not_move_heels = Ensure your heels do not move during recording! tips-file_select = Drag & drop files to use, or browse. +tips-tap_setup = You can slowly tap your tracker 2 times to choose it instead of selecting it from the menu. +tips-turn_on_tracker = Using official SlimeVR trackers? Don't forget to turn on your tracker after connecting it to the PC! tips-failed_webgl = Failed to initialize WebGL. ## Units @@ -226,14 +228,22 @@ skeleton_bone-HAND_Z-desc = ## Tracker reset buttons reset-reset_all = Reset all proportions +reset-reset_all_warning-v2 = + Warning: Your proportions will be reset to defaults scaled to your configured height. + Are you sure you want to do this? reset-reset_all_warning-reset = Reset proportions reset-reset_all_warning-cancel = Cancel +reset-reset_all_warning_default-v2 = + Warning: Your height has not been configured, your proportions will be reset to defaults with the default height. + Are you sure you want to do this? reset-full = Full Reset reset-mounting = Mounting Calibration reset-mounting-feet = Feet Calibration reset-mounting-fingers = Fingers Calibration reset-yaw = Yaw Reset +reset-error-no_feet_tracker = No feet tracker assigned +reset-error-no_fingers_tracker = No finger tracker assigned reset-error-mounting-need_full_reset = Need a full reset before mounting reset-error-yaw-need_full_reset = Need a full reset before yaw reset @@ -265,6 +275,14 @@ bvh-save_title = Save BVH recording tracking-unpaused = Pause tracking tracking-paused = Unpause tracking +## Widget: Overlay settings +widget-overlay = Overlay +widget-overlay-is_visible_label = Show Overlay in SteamVR +widget-overlay-is_mirrored_label = Display Overlay as Mirror + +## Widget: Clear Mounting calibration +widget-clear_mounting = Clear mounting calibration + ## Widget: Developer settings widget-developer_mode = Developer Mode widget-developer_mode-high_contrast = High contrast @@ -284,6 +302,10 @@ widget-imu_visualizer-acceleration = Acceleration widget-imu_visualizer-position = Position widget-imu_visualizer-stay_aligned = Stay Aligned +## Widget: Skeleton Visualizer +widget-skeleton_visualizer-preview = Skeleton preview +widget-skeleton_visualizer-hide = Hide + ## Tracker status tracker-status-none = No Status tracker-status-busy = Busy @@ -324,6 +346,8 @@ tracker-infos-manufacturer = Manufacturer tracker-infos-display_name = Display Name tracker-infos-custom_name = Custom Name tracker-infos-url = Tracker URL +tracker-infos-version = Firmware Version +tracker-infos-hardware_rev = Hardware Revision tracker-infos-hardware_identifier = Hardware ID tracker-infos-data_type = Data type tracker-infos-imu = IMU Sensor @@ -386,6 +410,7 @@ dongle-settings-title = Dongle settings dongle-settings-name_section = Dongle name dongle-settings-name_section-description = Give it a cute nickname :3 dongle-settings-name_section-placeholder = Futura's usb thingie +dongle-settings-name_section-label = Dongle name dongle-settings-update = Update now dongle-settings-update-title = Firmware version dongle-settings-paired_trackers = Paired Trackers @@ -403,11 +428,13 @@ dongle-settings-telemetry-footnote = Loss gap events mark regions where packet u ## Tracker part card info +tracker-part_card-no_name = No name tracker-part_card-unassigned = Unassigned ## Body assignment menu body_assignment_menu = Where do you want this tracker to be? body_assignment_menu-description = Choose a location where you want this tracker to be assigned. Alternatively, you can choose to manage all trackers at once instead of one by one. +body_assignment_menu-show_advanced_locations = Show advanced assign locations body_assignment_menu-manage_trackers = Manage all trackers body_assignment_menu-unassign_tracker = Unassign tracker @@ -417,6 +444,69 @@ body_assignment_menu-unassign_tracker = Unassign tracker # # We are using it here because english doesn't require changing the text in each case but # maybe your language does. +-tracker_selection-part = Which tracker to assign to your +tracker_selection_menu-NONE = Which tracker do you want to be unassigned? +tracker_selection_menu-HEAD = { -tracker_selection-part } head? +tracker_selection_menu-NECK = { -tracker_selection-part } neck? +tracker_selection_menu-RIGHT_SHOULDER = { -tracker_selection-part } right shoulder? +tracker_selection_menu-RIGHT_UPPER_ARM = { -tracker_selection-part } right upper arm? +tracker_selection_menu-RIGHT_LOWER_ARM = { -tracker_selection-part } right lower arm? +tracker_selection_menu-RIGHT_HAND = { -tracker_selection-part } right hand? +tracker_selection_menu-RIGHT_UPPER_LEG = { -tracker_selection-part } right thigh? +tracker_selection_menu-RIGHT_LOWER_LEG = { -tracker_selection-part } right ankle? +tracker_selection_menu-RIGHT_FOOT = { -tracker_selection-part } right foot? +tracker_selection_menu-UPPER_CHEST = { -tracker_selection-part } upper chest? +tracker_selection_menu-CHEST = { -tracker_selection-part } chest? +tracker_selection_menu-WAIST = { -tracker_selection-part } waist? +tracker_selection_menu-HIP = { -tracker_selection-part } hip? +tracker_selection_menu-LEFT_SHOULDER = { -tracker_selection-part } left shoulder? +tracker_selection_menu-LEFT_UPPER_ARM = { -tracker_selection-part } left upper arm? +tracker_selection_menu-LEFT_LOWER_ARM = { -tracker_selection-part } left lower arm? +tracker_selection_menu-LEFT_HAND = { -tracker_selection-part } left hand? +tracker_selection_menu-LEFT_UPPER_LEG = { -tracker_selection-part } left thigh? +tracker_selection_menu-LEFT_LOWER_LEG = { -tracker_selection-part } left ankle? +tracker_selection_menu-LEFT_FOOT = { -tracker_selection-part } left foot? + +tracker_selection_menu-unassigned = Unassigned Trackers +tracker_selection_menu-assigned = Assigned Trackers +tracker_selection_menu-dont_assign = Unassign + +-tracker_selection-part = Which tracker to assign to your +tracker_selection_menu-NONE = Which tracker do you want to be unassigned? +tracker_selection_menu-HEAD = { -tracker_selection-part } head? +tracker_selection_menu-NECK = { -tracker_selection-part } neck? +tracker_selection_menu-RIGHT_SHOULDER = { -tracker_selection-part } right shoulder? +tracker_selection_menu-RIGHT_UPPER_ARM = { -tracker_selection-part } right upper arm? +tracker_selection_menu-RIGHT_LOWER_ARM = { -tracker_selection-part } right lower arm? +tracker_selection_menu-RIGHT_HAND = { -tracker_selection-part } right hand? +tracker_selection_menu-RIGHT_UPPER_LEG = { -tracker_selection-part } right thigh? +tracker_selection_menu-RIGHT_LOWER_LEG = { -tracker_selection-part } right ankle? +tracker_selection_menu-RIGHT_FOOT = { -tracker_selection-part } right foot? +tracker_selection_menu-UPPER_CHEST = { -tracker_selection-part } upper chest? +tracker_selection_menu-CHEST = { -tracker_selection-part } chest? +tracker_selection_menu-WAIST = { -tracker_selection-part } waist? +tracker_selection_menu-HIP = { -tracker_selection-part } hip? +tracker_selection_menu-LEFT_SHOULDER = { -tracker_selection-part } left shoulder? +tracker_selection_menu-LEFT_UPPER_ARM = { -tracker_selection-part } left upper arm? +tracker_selection_menu-LEFT_LOWER_ARM = { -tracker_selection-part } left lower arm? +tracker_selection_menu-LEFT_HAND = { -tracker_selection-part } left hand? +tracker_selection_menu-LEFT_UPPER_LEG = { -tracker_selection-part } left thigh? +tracker_selection_menu-LEFT_LOWER_LEG = { -tracker_selection-part } left ankle? +tracker_selection_menu-LEFT_FOOT = { -tracker_selection-part } left foot? +tracker_selection_menu-LEFT_BIG_TOE = { -tracker_selection-part } left big toe? +tracker_selection_menu-LEFT_INDEX_TOE = { -tracker_selection-part } left index toe? +tracker_selection_menu-LEFT_MIDDLE_TOE = { -tracker_selection-part } left middle toe? +tracker_selection_menu-LEFT_RING_TOE = { -tracker_selection-part } left ring toe? +tracker_selection_menu-LEFT_LITTLE_TOE = { -tracker_selection-part } left little toe? +tracker_selection_menu-RIGHT_BIG_TOE = { -tracker_selection-part } right big toe? +tracker_selection_menu-RIGHT_INDEX_TOE = { -tracker_selection-part } right index toe? +tracker_selection_menu-RIGHT_MIDDLE_TOE = { -tracker_selection-part } right middle toe? +tracker_selection_menu-RIGHT_RING_TOE = { -tracker_selection-part } right ring toe? +tracker_selection_menu-RIGHT_LITTLE_TOE = { -tracker_selection-part } right little toe? +tracker_selection_menu-unassigned = Unassigned Trackers +tracker_selection_menu-assigned = Assigned Trackers +tracker_selection_menu-dont_assign = Unassign + # This line cares about multilines. # text means that the text should be bold. tracker_selection_menu-neck_warning = @@ -564,6 +654,7 @@ settings-stay_aligned-description = Stay Aligned reduces drift by gradually adju settings-stay_aligned-setup-label = Setup Stay Aligned settings-stay_aligned-setup-description = You must complete "Setup Stay Aligned" to enable Stay Aligned. settings-stay_aligned-enabled-label = Adjust trackers +settings-stay_aligned-hide_yaw_correction-label = Hide adjustment (to compare without Stay Aligned) settings-stay_aligned-general-label = General settings-stay_aligned-relaxed_poses-label = Relaxed Poses settings-stay_aligned-relaxed_poses-description = Stay Aligned uses your relaxed poses to keep the trackers aligned. Use "Setup Stay Aligned" to update these poses. @@ -1189,6 +1280,42 @@ onboarding-assign_trackers-warning-WAIST = Waist is assigned but you need { $una *[unknown] Unknown unassigned body part } to also be assigned! +onboarding-assign_trackers-warning-LEFT_BIG_TOE = Left Big Toe is assigned but you need { $unassigned -> + [0] the left foot + *[unknown] Unknown unassigned body part +} to also be assigned! +onboarding-assign_trackers-warning-LEFT_INDEX_TOE = Left Index Toe is assigned but you need { $unassigned -> + [0] the left foot + *[unknown] Unknown unassigned body part +} to also be assigned! +onboarding-assign_trackers-warning-LEFT_MIDDLE_TOE = Left Middle Toe is assigned but you need { $unassigned -> + [0] the left foot + *[unknown] Unknown unassigned body part} to also be assigned! +onboarding-assign_trackers-warning-LEFT_RING_TOE = Left Ring Toe is assigned but you need { $unassigned -> + [0] the left foot + *[unknown] Unknown unassigned body part} to also be assigned! +onboarding-assign_trackers-warning-LEFT_LITTLE_TOE = Left Little Toe is assigned but you need { $unassigned -> + [0] the left foot + *[unknown] Unknown unassigned body part} to also be assigned! +onboarding-assign_trackers-warning-RIGHT_BIG_TOE = Left Big Toe is assigned but you need { $unassigned -> + [0] the right foot + *[unknown] Unknown unassigned body part +} to also be assigned! +onboarding-assign_trackers-warning-RIGHT_INDEX_TOE = Right Index Toe is assigned but you need { $unassigned -> + [0] the right foot + *[unknown] Unknown unassigned body part +} to also be assigned! +onboarding-assign_trackers-warning-RIGHT_MIDDLE_TOE = Right Middle Toe is assigned but you need { $unassigned -> + [0] the right foot + *[unknown] Unknown unassigned body part} to also be assigned! +onboarding-assign_trackers-warning-RIGHT_RING_TOE = Right Ring Toe is assigned but you need { $unassigned -> + [0] the right foot + *[unknown] Unknown unassigned body part} to also be assigned! +onboarding-assign_trackers-warning-RIGHT_LITTLE_TOE = Right Little Toe is assigned but you need { $unassigned -> + [0] the right foot + *[unknown] Unknown unassigned body part} to also be assigned! + + ## Tracker mounting method choose onboarding-choose_mounting = What mounting calibration method to use? # Multiline text @@ -1636,6 +1763,8 @@ toolbar-mounting_calibration-default = Body toolbar-mounting_calibration-feet = Feet toolbar-mounting_calibration-fingers = Fingers toolbar-drift_reset = Drift Reset +toolbar-assigned_trackers = {$count} trackers assigned +toolbar-unassigned_trackers = {$count} trackers unassigned toolbar-assigned_trackers = { $count -> [one] { $count } tracker assigned *[other] { $count } trackers assigned @@ -1644,3 +1773,17 @@ toolbar-unassigned_trackers = { $count -> [one] { $count } tracker unassigned *[other] { $count } trackers unassigned } +toolbar-assigned_trackers = {$count} trackers assigned +toolbar-unassigned_trackers = {$count} trackers unassigned +body_part-LEFT_BIG_TOE = Left Big Toe +body_part-LEFT_INDEX_TOE = Left Index Toe +body_part-LEFT_MIDDLE_TOE = Left Middle Toe +body_part-LEFT_RING_TOE = Left Ring Toe +body_part-LEFT_LITTLE_TOE = Left Little Toe + +body_part-RIGHT_TOES = Right Toes +body_part-RIGHT_BIG_TOE = Right Big Toe +body_part-RIGHT_INDEX_TOE = Right Index Toe +body_part-RIGHT_MIDDLE_TOE = Right Middle Toe +body_part-RIGHT_RING_TOE = Right Ring Toe +body_part-RIGHT_LITTLE_TOE = Right Little Toe diff --git a/gui/app/src/components/Toolbar.tsx b/gui/app/src/components/Toolbar.tsx index 90eccf75f..1eb0bf9b5 100644 --- a/gui/app/src/components/Toolbar.tsx +++ b/gui/app/src/components/Toolbar.tsx @@ -147,7 +147,7 @@ export function Toolbar() { const { visibleGroups, groupVisibility } = useMemo(() => { const groupVisibility = Object.keys(BODY_PARTS_GROUPS) - .filter((k) => ['fingers'].includes(k)) + .filter((k) => ['fingers', 'toes'].includes(k)) .reduce( (curr, key) => { const group = key as MountingResetGroup; @@ -200,6 +200,13 @@ export function Toolbar() { group={'feet'} customName="toolbar-mounting_calibration-feet" /> + {groupVisibility['toes'] && ( + + )} {groupVisibility['fingers'] && ( ), [BodyPart.RIGHT_LITTLE_DISTAL]: ({ width }) => , + [BodyPart.LEFT_BIG_TOE]: renderFootLeft, + [BodyPart.LEFT_INDEX_TOE]: renderFootLeft, + [BodyPart.LEFT_MIDDLE_TOE]: renderFootLeft, + [BodyPart.LEFT_RING_TOE]: renderFootLeft, + [BodyPart.LEFT_LITTLE_TOE]: renderFootLeft, + [BodyPart.RIGHT_BIG_TOE]: renderFootRight, + [BodyPart.RIGHT_INDEX_TOE]: renderFootRight, + [BodyPart.RIGHT_MIDDLE_TOE]: renderFootLeft, + [BodyPart.RIGHT_RING_TOE]: renderFootLeft, + [BodyPart.RIGHT_LITTLE_TOE]: renderFootRight, }; +export function renderFootLeft({ + width, + currentLocales, +}: { + width?: number; + currentLocales: string[]; +}) { + if (currentLocales.includes('en-x-owo')) { + return ; + } + return ; +} +export function renderFootRight({ + width, + currentLocales, +}: { + width?: number; + currentLocales: string[]; +}) { + if (currentLocales.includes('en-x-owo')) { + return ; + } + return ; +} export function BodyPartIcon({ bodyPart = BodyPart.NONE, width = 24, @@ -192,7 +226,7 @@ export function BodyPartIcon({ ) : ( - {mapPart[bodyPart]({ width, currentLocales })} + {mapPart[bodyPart]?.({ width, currentLocales })} ); } diff --git a/gui/app/src/components/commons/PersonFrontIcon.tsx b/gui/app/src/components/commons/PersonFrontIcon.tsx index c5ea32759..1b114ab8f 100644 --- a/gui/app/src/components/commons/PersonFrontIcon.tsx +++ b/gui/app/src/components/commons/PersonFrontIcon.tsx @@ -9,6 +9,9 @@ export const SIDES = [ upperLeg: BodyPart.LEFT_UPPER_LEG, lowerLeg: BodyPart.LEFT_LOWER_LEG, foot: BodyPart.LEFT_FOOT, + bigToe: BodyPart.LEFT_BIG_TOE, + indexToe: BodyPart.LEFT_INDEX_TOE, + littleToe: BodyPart.LEFT_LITTLE_TOE, }, { shoulder: BodyPart.RIGHT_SHOULDER, @@ -18,6 +21,9 @@ export const SIDES = [ upperLeg: BodyPart.RIGHT_UPPER_LEG, lowerLeg: BodyPart.RIGHT_LOWER_LEG, foot: BodyPart.RIGHT_FOOT, + bigToe: BodyPart.RIGHT_BIG_TOE, + indexToe: BodyPart.RIGHT_INDEX_TOE, + littleToe: BodyPart.RIGHT_LITTLE_TOE, }, ]; @@ -136,6 +142,14 @@ export function PersonFrontIcon({ id={BodyPart[SIDES[right].foot]} /> + + + ); } diff --git a/gui/app/src/components/home/ResetButton.tsx b/gui/app/src/components/home/ResetButton.tsx index 0d5f1d0fc..356bdbcd7 100644 --- a/gui/app/src/components/home/ResetButton.tsx +++ b/gui/app/src/components/home/ResetButton.tsx @@ -23,6 +23,7 @@ export function ResetButtonIcon(options: UseResetOptions) { if (options.type === ResetType.POSE_MOUNTING) { if (options.group === 'default') return ; if (options.group === 'feet') return ; + if (options.group === 'toes') return ; if (options.group === 'fingers') return ; } } diff --git a/gui/app/src/components/onboarding/pages/mounting/MountingSelectionMenu.tsx b/gui/app/src/components/onboarding/pages/mounting/MountingSelectionMenu.tsx index eaf0aba3d..151d95401 100644 --- a/gui/app/src/components/onboarding/pages/mounting/MountingSelectionMenu.tsx +++ b/gui/app/src/components/onboarding/pages/mounting/MountingSelectionMenu.tsx @@ -11,6 +11,10 @@ import { BodyPart } from 'solarxr-protocol'; import { PawIcon } from '@/components/commons/icon/PawIcon'; import { useLocaleConfig } from '@/i18n/config'; import { FingersIcon } from '@/components/commons/icon/FingersIcon'; +import { + renderFootLeft, + renderFootRight, +} from '@/components/commons/BodyPartIcon'; // All body parts that are right or left, are by default left! export const mapPart: Record< @@ -148,6 +152,16 @@ export const mapPart: Record< ), [BodyPart.RIGHT_LITTLE_DISTAL]: ({ width }) => , + [BodyPart.LEFT_BIG_TOE]: renderFootLeft, + [BodyPart.LEFT_INDEX_TOE]: renderFootLeft, + [BodyPart.LEFT_MIDDLE_TOE]: renderFootLeft, + [BodyPart.LEFT_RING_TOE]: renderFootLeft, + [BodyPart.LEFT_LITTLE_TOE]: renderFootLeft, + [BodyPart.RIGHT_BIG_TOE]: renderFootRight, + [BodyPart.RIGHT_INDEX_TOE]: renderFootRight, + [BodyPart.RIGHT_MIDDLE_TOE]: renderFootLeft, + [BodyPart.RIGHT_RING_TOE]: renderFootLeft, + [BodyPart.RIGHT_LITTLE_TOE]: renderFootRight, }; export function MountingBodyPartIcon({ @@ -158,7 +172,9 @@ export function MountingBodyPartIcon({ width?: number; }) { const { currentLocales } = useLocaleConfig(); - return mapPart[bodyPart]({ width, currentLocales }); + return ( + mapPart[bodyPart]?.({ width, currentLocales }) || + ); } function PieSliceOfFeet({ diff --git a/gui/app/src/hooks/body-parts.ts b/gui/app/src/hooks/body-parts.ts index 6862696f4..48e837866 100644 --- a/gui/app/src/hooks/body-parts.ts +++ b/gui/app/src/hooks/body-parts.ts @@ -62,6 +62,15 @@ export const RIGHT_FINGER_BODY_PARTS = [ BodyPart.RIGHT_LITTLE_INTERMEDIATE, BodyPart.RIGHT_LITTLE_DISTAL, ]; + +export const TOE_BODY_PARTS = [ + BodyPart.LEFT_BIG_TOE, + BodyPart.LEFT_INDEX_TOE, + BodyPart.LEFT_LITTLE_TOE, + BodyPart.RIGHT_BIG_TOE, + BodyPart.RIGHT_INDEX_TOE, + BodyPart.RIGHT_LITTLE_TOE, +]; export const FINGER_BODY_PARTS = [ ...LEFT_FINGER_BODY_PARTS, ...RIGHT_FINGER_BODY_PARTS, diff --git a/gui/app/src/hooks/reset.ts b/gui/app/src/hooks/reset.ts index 793440925..97d899ac5 100644 --- a/gui/app/src/hooks/reset.ts +++ b/gui/app/src/hooks/reset.ts @@ -10,13 +10,13 @@ import { import { useWebsocketAPI } from './websocket-api'; import { useAtomValue } from 'jotai'; import { assignedTrackersAtom, serverGuardsAtom } from '@/store/app-store'; -import { FEET_BODY_PARTS, FINGER_BODY_PARTS } from './body-parts'; +import { FEET_BODY_PARTS, FINGER_BODY_PARTS, TOE_BODY_PARTS } from './body-parts'; import { useLocaleConfig } from '@/i18n/config'; import * as Sentry from '@sentry/react'; export type ResetBtnStatus = 'idle' | 'counting' | 'finished'; -export type MountingResetGroup = 'default' | 'feet' | 'fingers'; +export type MountingResetGroup = 'default' | 'feet' | 'fingers' | 'toes'; export type UseResetOptions = | { type: ResetType.FULL | ResetType.YAW } | { type: ResetType.POSE_MOUNTING; group: MountingResetGroup }; @@ -24,6 +24,7 @@ export type UseResetOptions = export const BODY_PARTS_GROUPS: Record = { default: [], feet: FEET_BODY_PARTS, + toes: TOE_BODY_PARTS, fingers: FINGER_BODY_PARTS, }; diff --git a/gui/app/src/hooks/tracker-assignment.ts b/gui/app/src/hooks/tracker-assignment.ts index 56ba070fe..ed9abd9f2 100644 --- a/gui/app/src/hooks/tracker-assignment.ts +++ b/gui/app/src/hooks/tracker-assignment.ts @@ -1,11 +1,5 @@ import { useLocalization } from '@fluent/react'; -import { - createContext, - useContext, - useEffect, - useMemo, - useState, -} from 'react'; +import { createContext, useContext, useEffect, useMemo, useState } from 'react'; import { AssignTrackerRequestT, BodyPart, diff --git a/gui/app/src/utils/skeletonHelper.ts b/gui/app/src/utils/skeletonHelper.ts index c29f3d0ca..e9e438004 100644 --- a/gui/app/src/utils/skeletonHelper.ts +++ b/gui/app/src/utils/skeletonHelper.ts @@ -239,6 +239,17 @@ export class BoneKind extends Bone { case BodyPart.RIGHT_LITTLE_INTERMEDIATE: case BodyPart.RIGHT_LITTLE_DISTAL: return new Color('pink'); + case BodyPart.LEFT_BIG_TOE: + case BodyPart.LEFT_INDEX_TOE: + case BodyPart.LEFT_MIDDLE_TOE: + case BodyPart.LEFT_RING_TOE: + case BodyPart.LEFT_LITTLE_TOE: + case BodyPart.RIGHT_BIG_TOE: + case BodyPart.RIGHT_INDEX_TOE: + case BodyPart.RIGHT_MIDDLE_TOE: + case BodyPart.RIGHT_RING_TOE: + case BodyPart.RIGHT_LITTLE_TOE: + return new Color('pink'); } } @@ -274,10 +285,21 @@ export class BoneKind extends Bone { case BodyPart.RIGHT_LOWER_LEG: return [BodyPart.RIGHT_FOOT]; case BodyPart.LEFT_FOOT: - return []; + return [ + BodyPart.LEFT_BIG_TOE, + BodyPart.LEFT_INDEX_TOE, + BodyPart.LEFT_MIDDLE_TOE, + BodyPart.LEFT_RING_TOE, + BodyPart.LEFT_LITTLE_TOE, + ]; case BodyPart.RIGHT_FOOT: - return []; - + return [ + BodyPart.RIGHT_BIG_TOE, + BodyPart.RIGHT_INDEX_TOE, + BodyPart.RIGHT_MIDDLE_TOE, + BodyPart.RIGHT_RING_TOE, + BodyPart.RIGHT_LITTLE_TOE, + ]; case BodyPart.LEFT_SHOULDER: return [BodyPart.LEFT_UPPER_ARM]; case BodyPart.RIGHT_SHOULDER: @@ -367,6 +389,18 @@ export class BoneKind extends Bone { return [BodyPart.RIGHT_LITTLE_DISTAL]; case BodyPart.RIGHT_LITTLE_DISTAL: return []; + return []; + case BodyPart.LEFT_BIG_TOE: + case BodyPart.LEFT_INDEX_TOE: + case BodyPart.LEFT_MIDDLE_TOE: + case BodyPart.LEFT_RING_TOE: + case BodyPart.LEFT_LITTLE_TOE: + case BodyPart.RIGHT_BIG_TOE: + case BodyPart.RIGHT_INDEX_TOE: + case BodyPart.RIGHT_MIDDLE_TOE: + case BodyPart.RIGHT_RING_TOE: + case BodyPart.RIGHT_LITTLE_TOE: + return []; } } @@ -479,6 +513,27 @@ export class BoneKind extends Bone { return BodyPart.RIGHT_LITTLE_PROXIMAL; case BodyPart.RIGHT_LITTLE_DISTAL: return BodyPart.RIGHT_LITTLE_INTERMEDIATE; + + case BodyPart.LEFT_BIG_TOE: + return BodyPart.LEFT_FOOT; + case BodyPart.LEFT_INDEX_TOE: + return BodyPart.LEFT_FOOT; + case BodyPart.LEFT_MIDDLE_TOE: + return BodyPart.LEFT_FOOT; + case BodyPart.LEFT_RING_TOE: + return BodyPart.LEFT_FOOT; + case BodyPart.LEFT_LITTLE_TOE: + return BodyPart.LEFT_FOOT; + case BodyPart.RIGHT_BIG_TOE: + return BodyPart.RIGHT_FOOT; + case BodyPart.RIGHT_INDEX_TOE: + return BodyPart.RIGHT_FOOT; + case BodyPart.RIGHT_MIDDLE_TOE: + return BodyPart.RIGHT_FOOT; + case BodyPart.RIGHT_RING_TOE: + return BodyPart.RIGHT_FOOT; + case BodyPart.RIGHT_LITTLE_TOE: + return BodyPart.RIGHT_FOOT; } } } diff --git a/gui/app/src/utils/skeletonParts.ts b/gui/app/src/utils/skeletonParts.ts index be973df32..3ab00d53a 100644 --- a/gui/app/src/utils/skeletonParts.ts +++ b/gui/app/src/utils/skeletonParts.ts @@ -197,6 +197,17 @@ export const SKELETON_PART_PRESETS: Record = { [BodyPart.RIGHT_LITTLE_PROXIMAL]: finger(), [BodyPart.RIGHT_LITTLE_INTERMEDIATE]: finger(), [BodyPart.RIGHT_LITTLE_DISTAL]: finger(), + + [BodyPart.LEFT_BIG_TOE]: finger(), + [BodyPart.LEFT_INDEX_TOE]: finger(), + [BodyPart.LEFT_MIDDLE_TOE]: finger(), + [BodyPart.LEFT_RING_TOE]: finger(), + [BodyPart.LEFT_LITTLE_TOE]: finger(), + [BodyPart.RIGHT_BIG_TOE]: finger(), + [BodyPart.RIGHT_MIDDLE_TOE]: finger(), + [BodyPart.RIGHT_INDEX_TOE]: finger(), + [BodyPart.RIGHT_RING_TOE]: finger(), + [BodyPart.RIGHT_LITTLE_TOE]: finger(), }; export function computeShapeScale( diff --git a/server/core/src/main/java/dev/slimevr/resets/bodypart-sets.kt b/server/core/src/main/java/dev/slimevr/resets/bodypart-sets.kt index 9d396b86f..b1efd44b0 100644 --- a/server/core/src/main/java/dev/slimevr/resets/bodypart-sets.kt +++ b/server/core/src/main/java/dev/slimevr/resets/bodypart-sets.kt @@ -8,10 +8,27 @@ object ResetBodyParts { BodyPart.RIGHT_UPPER_LEG, ) + val LEFT_TOES = setOf( + BodyPart.LEFT_BIG_TOE, + BodyPart.LEFT_INDEX_TOE, + BodyPart.LEFT_MIDDLE_TOE, + BodyPart.LEFT_RING_TOE, + BodyPart.LEFT_LITTLE_TOE, + ) + val RIGHT_TOES = setOf( + BodyPart.RIGHT_BIG_TOE, + BodyPart.RIGHT_INDEX_TOE, + BodyPart.RIGHT_MIDDLE_TOE, + BodyPart.RIGHT_RING_TOE, + BodyPart.RIGHT_LITTLE_TOE, + ) + val FEET = setOf( BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT, - ) + ) + + LEFT_TOES + + RIGHT_TOES val LEFT_FINGERS = setOf( BodyPart.LEFT_THUMB_METACARPAL, diff --git a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt index 9c3550f60..347a9f1d1 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/bodypart-structure.kt @@ -63,6 +63,22 @@ val BODY_PART_HIERARCHY_MAP: BodyPartMap> = BodyPartMap( BodyPart.RIGHT_HIP to arrayOf(BodyPart.RIGHT_UPPER_LEG), BodyPart.RIGHT_UPPER_LEG to arrayOf(BodyPart.RIGHT_LOWER_LEG), BodyPart.RIGHT_LOWER_LEG to arrayOf(BodyPart.RIGHT_FOOT), + + BodyPart.LEFT_FOOT to arrayOf( + BodyPart.LEFT_BIG_TOE, + BodyPart.LEFT_INDEX_TOE, + BodyPart.LEFT_MIDDLE_TOE, + BodyPart.LEFT_RING_TOE, + BodyPart.LEFT_LITTLE_TOE, + ), + + BodyPart.RIGHT_FOOT to arrayOf( + BodyPart.RIGHT_BIG_TOE, + BodyPart.RIGHT_INDEX_TOE, + BodyPart.RIGHT_MIDDLE_TOE, + BodyPart.RIGHT_RING_TOE, + BodyPart.RIGHT_LITTLE_TOE, + ), ), ) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/toe-direct-link-input-processor.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/toe-direct-link-input-processor.kt new file mode 100644 index 000000000..04db16ccf --- /dev/null +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/toe-direct-link-input-processor.kt @@ -0,0 +1,44 @@ +package dev.slimevr.skeleton.processors + +import dev.slimevr.skeleton.BodyPartMap +import dev.slimevr.skeleton.InputSkeleton +import dev.slimevr.skeleton.SkeletonInputProcessor +import dev.slimevr.skeleton.SkeletonState +import dev.slimevr.skeleton.mutateCopy +import solarxr_protocol.datatypes.BodyPart + +/** + * Handles rotations of inactive toe bones. + */ +class ToeDirectLinkInputProcessor : SkeletonInputProcessor { + /** + * First element is the linked BodyPart. + * + * Second element is the BodyPart the first element is linked to. + */ + private val toesToSource = arrayOf( + BodyPart.LEFT_BIG_TOE to BodyPart.LEFT_FOOT, + BodyPart.LEFT_INDEX_TOE to BodyPart.LEFT_BIG_TOE, + BodyPart.LEFT_MIDDLE_TOE to BodyPart.LEFT_INDEX_TOE, + BodyPart.LEFT_RING_TOE to BodyPart.LEFT_MIDDLE_TOE, + BodyPart.LEFT_LITTLE_TOE to BodyPart.LEFT_RING_TOE, + + BodyPart.RIGHT_BIG_TOE to BodyPart.RIGHT_FOOT, + BodyPart.RIGHT_INDEX_TOE to BodyPart.RIGHT_BIG_TOE, + BodyPart.RIGHT_MIDDLE_TOE to BodyPart.RIGHT_INDEX_TOE, + BodyPart.RIGHT_RING_TOE to BodyPart.RIGHT_MIDDLE_TOE, + BodyPart.RIGHT_LITTLE_TOE to BodyPart.RIGHT_RING_TOE, + ) + + override fun process(inputSkeleton: InputSkeleton, skeletonHeight: Float): InputSkeleton { + return inputSkeleton.mutateCopy{ updated -> + for ((bodyPart, source) in toesToSource) { + val bone = updated.getValue(bodyPart) + if (bone.isRotationActive) continue + val sourceBone = updated[source] + updated[bodyPart] = + bone.copy(rawRotation = sourceBone?.rawRotation ?: bone.rawRotation) + } + } + } +} diff --git a/server/core/src/main/java/dev/slimevr/skeleton/module.kt b/server/core/src/main/java/dev/slimevr/skeleton/module.kt index ee4f19693..63e91b391 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/module.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/module.kt @@ -17,6 +17,7 @@ import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackProcessor import dev.slimevr.skeleton.inputprocessors.HipYawRollAlignInputProcessor import dev.slimevr.skeleton.inputprocessors.SpineImputeInputProcessor import dev.slimevr.skeleton.inputprocessors.UpperLegsRollAlignInputProcessor +import dev.slimevr.skeleton.processors.ToeDirectLinkInputProcessor import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import kotlinx.coroutines.CoroutineScope @@ -188,6 +189,7 @@ class Skeleton( UpperLegsRollAlignInputProcessor(settings), BoneDirectLinkInputProcessor(), FingerImputeInputProcessor(), + ToeDirectLinkInputProcessor(), BonePredictionInputProcessor(settings), BoneSmoothingInputProcessor(settings), ), diff --git a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt index 508f1d292..13490782e 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/proportions.kt @@ -118,6 +118,8 @@ fun Map.toBoneOffsets(): BodyPartMap { } // Fingers this[SkeletonBone.HAND_Y]?.let { offsets.putAll(getFingerOffsets(it)) } + // Toes + this[SkeletonBone.FOOT_LENGTH]?.let { offsets.putAll(getToeOffsets(it)) } return offsets } @@ -206,3 +208,13 @@ private fun getFingerOffsets(handLength: Float) = ( private const val PROXIMAL_RATIO = 0.5f private const val INTERMEDIATE_RATIO = 0.283f private const val DISTAL_RATIO = 0.217f + +/** + * Returns the offsets for the toe bones scaled from the handLength. + */ +private fun getToeOffsets(footLength: Float) = ( + iterateBodyPartHierarchy(BodyPart.LEFT_FOOT, true) + + iterateBodyPartHierarchy(BodyPart.RIGHT_FOOT, true) + ).map { it.second }.associateWith { + Vector3(0f, 0f, -footLength * 0.2f) + } diff --git a/server/core/src/main/java/dev/slimevr/vmc/mapping.kt b/server/core/src/main/java/dev/slimevr/vmc/mapping.kt index a63444b0c..afcd9cd14 100644 --- a/server/core/src/main/java/dev/slimevr/vmc/mapping.kt +++ b/server/core/src/main/java/dev/slimevr/vmc/mapping.kt @@ -8,58 +8,68 @@ import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import solarxr_protocol.datatypes.BodyPart -val BODY_PART_TO_UNITY_BONE: BodyPartMap = BodyPartMap( +val BODY_PART_TO_UNITY_BONE: BodyPartMap> = BodyPartMap( mapOf( - BodyPart.HEAD to "Head", - BodyPart.NECK to "Neck", - BodyPart.UPPER_CHEST to "UpperChest", - BodyPart.CHEST to "Chest", - BodyPart.WAIST to "Spine", - BodyPart.HIP to "Hips", - BodyPart.LEFT_SHOULDER to "LeftShoulder", - BodyPart.RIGHT_SHOULDER to "RightShoulder", - BodyPart.LEFT_UPPER_ARM to "LeftUpperArm", - BodyPart.RIGHT_UPPER_ARM to "RightUpperArm", - BodyPart.LEFT_LOWER_ARM to "LeftLowerArm", - BodyPart.RIGHT_LOWER_ARM to "RightLowerArm", - BodyPart.LEFT_HAND to "LeftHand", - BodyPart.RIGHT_HAND to "RightHand", - BodyPart.LEFT_UPPER_LEG to "LeftUpperLeg", - BodyPart.RIGHT_UPPER_LEG to "RightUpperLeg", - BodyPart.LEFT_LOWER_LEG to "LeftLowerLeg", - BodyPart.RIGHT_LOWER_LEG to "RightLowerLeg", - BodyPart.LEFT_FOOT to "LeftFoot", - BodyPart.RIGHT_FOOT to "RightFoot", - BodyPart.LEFT_THUMB_METACARPAL to "LeftThumbProximal", - BodyPart.LEFT_THUMB_PROXIMAL to "LeftThumbIntermediate", - BodyPart.LEFT_THUMB_DISTAL to "LeftThumbDistal", - BodyPart.LEFT_INDEX_PROXIMAL to "LeftIndexProximal", - BodyPart.LEFT_INDEX_INTERMEDIATE to "LeftIndexIntermediate", - BodyPart.LEFT_INDEX_DISTAL to "LeftIndexDistal", - BodyPart.LEFT_MIDDLE_PROXIMAL to "LeftMiddleProximal", - BodyPart.LEFT_MIDDLE_INTERMEDIATE to "LeftMiddleIntermediate", - BodyPart.LEFT_MIDDLE_DISTAL to "LeftMiddleDistal", - BodyPart.LEFT_RING_PROXIMAL to "LeftRingProximal", - BodyPart.LEFT_RING_INTERMEDIATE to "LeftRingIntermediate", - BodyPart.LEFT_RING_DISTAL to "LeftRingDistal", - BodyPart.LEFT_LITTLE_PROXIMAL to "LeftLittleProximal", - BodyPart.LEFT_LITTLE_INTERMEDIATE to "LeftLittleIntermediate", - BodyPart.LEFT_LITTLE_DISTAL to "LeftLittleDistal", - BodyPart.RIGHT_THUMB_METACARPAL to "RightThumbProximal", - BodyPart.RIGHT_THUMB_PROXIMAL to "RightThumbIntermediate", - BodyPart.RIGHT_THUMB_DISTAL to "RightThumbDistal", - BodyPart.RIGHT_INDEX_PROXIMAL to "RightIndexProximal", - BodyPart.RIGHT_INDEX_INTERMEDIATE to "RightIndexIntermediate", - BodyPart.RIGHT_INDEX_DISTAL to "RightIndexDistal", - BodyPart.RIGHT_MIDDLE_PROXIMAL to "RightMiddleProximal", - BodyPart.RIGHT_MIDDLE_INTERMEDIATE to "RightMiddleIntermediate", - BodyPart.RIGHT_MIDDLE_DISTAL to "RightMiddleDistal", - BodyPart.RIGHT_RING_PROXIMAL to "RightRingProximal", - BodyPart.RIGHT_RING_INTERMEDIATE to "RightRingIntermediate", - BodyPart.RIGHT_RING_DISTAL to "RightRingDistal", - BodyPart.RIGHT_LITTLE_PROXIMAL to "RightLittleProximal", - BodyPart.RIGHT_LITTLE_INTERMEDIATE to "RightLittleIntermediate", - BodyPart.RIGHT_LITTLE_DISTAL to "RightLittleDistal", + BodyPart.HEAD to arrayOf("Head"), + BodyPart.NECK to arrayOf("Neck"), + BodyPart.UPPER_CHEST to arrayOf("UpperChest"), + BodyPart.CHEST to arrayOf("Chest"), + BodyPart.WAIST to arrayOf("Spine"), + BodyPart.HIP to arrayOf("Hips"), + BodyPart.LEFT_SHOULDER to arrayOf("LeftShoulder"), + BodyPart.RIGHT_SHOULDER to arrayOf("RightShoulder"), + BodyPart.LEFT_UPPER_ARM to arrayOf("LeftUpperArm"), + BodyPart.RIGHT_UPPER_ARM to arrayOf("RightUpperArm"), + BodyPart.LEFT_LOWER_ARM to arrayOf("LeftLowerArm"), + BodyPart.RIGHT_LOWER_ARM to arrayOf("RightLowerArm"), + BodyPart.LEFT_HAND to arrayOf("LeftHand"), + BodyPart.RIGHT_HAND to arrayOf("RightHand"), + BodyPart.LEFT_UPPER_LEG to arrayOf("LeftUpperLeg"), + BodyPart.RIGHT_UPPER_LEG to arrayOf("RightUpperLeg"), + BodyPart.LEFT_LOWER_LEG to arrayOf("LeftLowerLeg"), + BodyPart.RIGHT_LOWER_LEG to arrayOf("RightLowerLeg"), + BodyPart.LEFT_FOOT to arrayOf("LeftFoot"), + BodyPart.RIGHT_FOOT to arrayOf("RightFoot"), + BodyPart.LEFT_THUMB_METACARPAL to arrayOf("LeftThumbProximal"), + BodyPart.LEFT_THUMB_PROXIMAL to arrayOf("LeftThumbIntermediate"), + BodyPart.LEFT_THUMB_DISTAL to arrayOf("LeftThumbDistal"), + BodyPart.LEFT_INDEX_PROXIMAL to arrayOf("LeftIndexProximal"), + BodyPart.LEFT_INDEX_INTERMEDIATE to arrayOf("LeftIndexIntermediate"), + BodyPart.LEFT_INDEX_DISTAL to arrayOf("LeftIndexDistal"), + BodyPart.LEFT_MIDDLE_PROXIMAL to arrayOf("LeftMiddleProximal"), + BodyPart.LEFT_MIDDLE_INTERMEDIATE to arrayOf("LeftMiddleIntermediate"), + BodyPart.LEFT_MIDDLE_DISTAL to arrayOf("LeftMiddleDistal"), + BodyPart.LEFT_RING_PROXIMAL to arrayOf("LeftRingProximal"), + BodyPart.LEFT_RING_INTERMEDIATE to arrayOf("LeftRingIntermediate"), + BodyPart.LEFT_RING_DISTAL to arrayOf("LeftRingDistal"), + BodyPart.LEFT_LITTLE_PROXIMAL to arrayOf("LeftLittleProximal"), + BodyPart.LEFT_LITTLE_INTERMEDIATE to arrayOf("LeftLittleIntermediate"), + BodyPart.LEFT_LITTLE_DISTAL to arrayOf("LeftLittleDistal"), + BodyPart.RIGHT_THUMB_METACARPAL to arrayOf("RightThumbProximal"), + BodyPart.RIGHT_THUMB_PROXIMAL to arrayOf("RightThumbIntermediate"), + BodyPart.RIGHT_THUMB_DISTAL to arrayOf("RightThumbDistal"), + BodyPart.RIGHT_INDEX_PROXIMAL to arrayOf("RightIndexProximal"), + BodyPart.RIGHT_INDEX_INTERMEDIATE to arrayOf("RightIndexIntermediate"), + BodyPart.RIGHT_INDEX_DISTAL to arrayOf("RightIndexDistal"), + BodyPart.RIGHT_MIDDLE_PROXIMAL to arrayOf("RightMiddleProximal"), + BodyPart.RIGHT_MIDDLE_INTERMEDIATE to arrayOf("RightMiddleIntermediate"), + BodyPart.RIGHT_MIDDLE_DISTAL to arrayOf("RightMiddleDistal"), + BodyPart.RIGHT_RING_PROXIMAL to arrayOf("RightRingProximal"), + BodyPart.RIGHT_RING_INTERMEDIATE to arrayOf("RightRingIntermediate"), + BodyPart.RIGHT_RING_DISTAL to arrayOf("RightRingDistal"), + BodyPart.RIGHT_LITTLE_PROXIMAL to arrayOf("RightLittleProximal"), + BodyPart.RIGHT_LITTLE_INTERMEDIATE to arrayOf("RightLittleIntermediate"), + BodyPart.RIGHT_LITTLE_DISTAL to arrayOf("RightLittleDistal"), + BodyPart.LEFT_BIG_TOE to arrayOf("LeftToes", "LeftBigToe"), + BodyPart.LEFT_INDEX_TOE to arrayOf("LeftIndexToe"), + BodyPart.LEFT_MIDDLE_TOE to arrayOf("LeftMiddleToe"), + BodyPart.LEFT_RING_TOE to arrayOf("LeftRingToe"), + BodyPart.LEFT_LITTLE_TOE to arrayOf("LeftLittleToe"), + BodyPart.RIGHT_BIG_TOE to arrayOf("RightToes", "RightBigToe"), + BodyPart.RIGHT_INDEX_TOE to arrayOf("RightIndexToe"), + BodyPart.RIGHT_MIDDLE_TOE to arrayOf("RightMiddleToe"), + BodyPart.RIGHT_RING_TOE to arrayOf("RightRingToe"), + BodyPart.RIGHT_LITTLE_TOE to arrayOf("RightLittleToe"), ), ) @@ -119,6 +129,20 @@ val VMC_HIERARCHY_MAP: BodyPartMap> = BodyPartMap( BodyPart.RIGHT_RING_INTERMEDIATE to arrayOf(BodyPart.RIGHT_RING_DISTAL), BodyPart.RIGHT_LITTLE_PROXIMAL to arrayOf(BodyPart.RIGHT_LITTLE_INTERMEDIATE), BodyPart.RIGHT_LITTLE_INTERMEDIATE to arrayOf(BodyPart.RIGHT_LITTLE_DISTAL), + BodyPart.LEFT_FOOT to arrayOf( + BodyPart.LEFT_BIG_TOE, + BodyPart.LEFT_INDEX_TOE, + BodyPart.LEFT_MIDDLE_TOE, + BodyPart.LEFT_RING_TOE, + BodyPart.LEFT_LITTLE_TOE, + ), + BodyPart.RIGHT_FOOT to arrayOf( + BodyPart.RIGHT_BIG_TOE, + BodyPart.RIGHT_INDEX_TOE, + BodyPart.RIGHT_MIDDLE_TOE, + BodyPart.RIGHT_RING_TOE, + BodyPart.RIGHT_LITTLE_TOE, + ), ), ) @@ -155,6 +179,12 @@ val VMC_MIRROR_BONE_PAIRS: List> = listOf( BodyPart.LEFT_LITTLE_PROXIMAL to BodyPart.RIGHT_LITTLE_PROXIMAL, BodyPart.LEFT_LITTLE_INTERMEDIATE to BodyPart.RIGHT_LITTLE_INTERMEDIATE, BodyPart.LEFT_LITTLE_DISTAL to BodyPart.RIGHT_LITTLE_DISTAL, + BodyPart.LEFT_BIG_TOE to BodyPart.RIGHT_BIG_TOE, + BodyPart.LEFT_BIG_TOE to BodyPart.RIGHT_BIG_TOE, + BodyPart.LEFT_INDEX_TOE to BodyPart.RIGHT_INDEX_TOE, + BodyPart.LEFT_MIDDLE_TOE to BodyPart.RIGHT_MIDDLE_TOE, + BodyPart.LEFT_RING_TOE to BodyPart.RIGHT_RING_TOE, + BodyPart.LEFT_LITTLE_TOE to BodyPart.RIGHT_LITTLE_TOE, ) val VMC_MIRROR_BONES: BodyPartMap = BodyPartMap( diff --git a/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt b/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt index b11f45eb6..4754915ca 100644 --- a/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt +++ b/server/core/src/main/java/dev/slimevr/vmc/output-encoder.kt @@ -27,7 +27,7 @@ internal fun buildOutgoingBundle( add(OscContent.Message(transformMessage("/VMC/Ext/Root/Pos", "root", Vector3.NULL, Quaternion.IDENTITY))) // TODO UpperChest + shoulders affecting arms local rot - for ((targetBodyPart, unityName) in BODY_PART_TO_UNITY_BONE) { + for ((targetBodyPart, unityNames) in BODY_PART_TO_UNITY_BONE) { if (targetBodyPart !in routedBones) continue val targetParentBodyPart = VMC_BONE_PARENTS[targetBodyPart] @@ -38,7 +38,7 @@ internal fun buildOutgoingBundle( // TODO anchorHip https://github.com/SlimeVR/SlimeVR-Server/blob/main/server/core/src/main/java/dev/slimevr/osc/VMCHandler.kt#L371 val pos = vrm?.hipLocalPosition ?: Vector3.NULL val rot = vmcLocalRotation(trackingBone, null, targetBodyPart, null, config.mirrorTracking) - add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", unityName, pos, rot))) + add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", unityNames.first(), pos, rot))) continue } @@ -61,7 +61,9 @@ internal fun buildOutgoingBundle( targetParentBodyPart, config.mirrorTracking, ) - add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", unityName, pos, rot))) + for (outputName in unityNames) { + add(OscContent.Message(transformMessage("/VMC/Ext/Bone/Pos", outputName, pos, rot))) + } } } diff --git a/server/core/src/main/java/dev/slimevr/vmc/vrm.kt b/server/core/src/main/java/dev/slimevr/vmc/vrm.kt index 5ad30ef7b..980142263 100644 --- a/server/core/src/main/java/dev/slimevr/vmc/vrm.kt +++ b/server/core/src/main/java/dev/slimevr/vmc/vrm.kt @@ -91,7 +91,7 @@ data class VrmGeometry( fun buildVrmGeometry(reader: VrmReader): VrmGeometry { val bindOffsets = BodyPartMap( - BODY_PART_TO_UNITY_BONE.mapValues { (_, unityName) -> reader.offsetForBone(unityName) ?: Vector3.NULL }, + BODY_PART_TO_UNITY_BONE.mapValues { (_, unityNames) -> reader.offsetForBone(unityNames.first()) ?: Vector3.NULL }, ) fun offset(bodyPart: BodyPart) = bindOffsets[bodyPart] ?: Vector3.NULL diff --git a/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt b/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt index 844406243..baa5ac49f 100644 --- a/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt +++ b/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt @@ -30,7 +30,7 @@ internal fun buildOutgoingBundle( bones: ComputedSkeleton, routedBones: Set, ): OscBundle? { - val messages = buildList { + val messages = buildList { for ((bodyPart, trackerId) in trackerIdsByBodyPart) { if (bodyPart !in routedBones) continue @@ -54,6 +54,8 @@ internal fun buildOutgoingBundle( ), ) } + + addAll(buildToeMessages(bones)) } return messages.takeIf { it.isNotEmpty() }?.let { OscBundle(1L, it) } diff --git a/server/core/src/main/java/dev/slimevr/vrcosc/toe-plugin-output-encoder.kt b/server/core/src/main/java/dev/slimevr/vrcosc/toe-plugin-output-encoder.kt new file mode 100644 index 000000000..bae580730 --- /dev/null +++ b/server/core/src/main/java/dev/slimevr/vrcosc/toe-plugin-output-encoder.kt @@ -0,0 +1,113 @@ +package dev.slimevr.vrcosc + +import dev.slimevr.osc.OscArg +import dev.slimevr.osc.OscContent +import dev.slimevr.osc.OscMessage +import dev.slimevr.skeleton.BoneState +import dev.slimevr.util.Side +import dev.slimevr.util.opposite +import io.github.axisangles.ktmath.EulerOrder +import io.github.axisangles.ktmath.Quaternion +import io.github.axisangles.ktmath.Vector3 +import solarxr_protocol.datatypes.BodyPart +import kotlin.math.* + +private const val ABSOLUTE_SPLAY_THRESHOLD_ANGLE = 7 +private const val MINIMUM_TIP_TOE_PITCH = -14 +private const val MINIMUM_BENDING_PITCH = 15 +private const val MAXIMUM_ABSOLUTE_TOE_RANGE = 90 + +internal fun buildToeMessages(bones: Map): List { + val messages = mutableListOf() + + // LEFT FOOT + TOES + val leftFoot = bones[BodyPart.LEFT_FOOT] + if (leftFoot != null) { + val leftToes = listOf( + bones[BodyPart.LEFT_BIG_TOE], + bones[BodyPart.LEFT_INDEX_TOE], + bones[BodyPart.LEFT_MIDDLE_TOE], + bones[BodyPart.LEFT_RING_TOE], + bones[BodyPart.LEFT_LITTLE_TOE], + ) + processToesForFoot(leftFoot, leftToes, Side.LEFT, messages) + } + + // RIGHT FOOT + TOES + val rightFoot = bones[BodyPart.RIGHT_FOOT] + if (rightFoot != null) { + val rightToes = listOf( + bones[BodyPart.RIGHT_BIG_TOE], + bones[BodyPart.RIGHT_INDEX_TOE], + bones[BodyPart.RIGHT_MIDDLE_TOE], + bones[BodyPart.RIGHT_RING_TOE], + bones[BodyPart.RIGHT_LITTLE_TOE], + ) + processToesForFoot(rightFoot, rightToes, Side.RIGHT, messages) + } + + return messages +} + +private fun processToesForFoot( + foot: BoneState, + toeBones: List, + side: Side, + messages: MutableList, +) { + var lastAssigned: BoneState? = null + + for ((segmentIndex, toe) in toeBones.withIndex()) { + if (toe != null) { + lastAssigned = toe + } + + if (lastAssigned == null) continue + + val splayDirection = if (segmentIndex > 0) side else side.opposite + + processToe(foot, lastAssigned, side, segmentIndex, splayDirection, messages) + } +} + +private val Side.oscName: String + get() = when (this) { + Side.LEFT -> "Left" + Side.RIGHT -> "Right" + } + +private fun processToe( + foot: BoneState, + toe: BoneState, + side: Side, + toeNumber: Int, + splayDirection: Side, + messages: MutableList, +) { + val oscToeNumber = toeNumber + 1 + val footRot = foot.rotation + val toeRot = toe.rotation + val currentRelative = footRot.inv() * toeRot + + val euler = currentRelative.toEulerAngles(EulerOrder.XYZ) + + val pitch = Math.toDegrees(euler.x.toDouble()).toFloat() + val yaw = Math.toDegrees(euler.z.toDouble()).toFloat() + val tipToe = pitch < MINIMUM_TIP_TOE_PITCH + val bending = pitch > MINIMUM_BENDING_PITCH + val splayed = when (splayDirection) { + Side.LEFT -> yaw < -ABSOLUTE_SPLAY_THRESHOLD_ANGLE + Side.RIGHT -> yaw > ABSOLUTE_SPLAY_THRESHOLD_ANGLE + } + val toeCurlValue = (pitch / MAXIMUM_ABSOLUTE_TOE_RANGE).coerceIn(-1f, 1f) + val toeSplayValue = (yaw / MAXIMUM_ABSOLUTE_TOE_RANGE).coerceIn(-1f, 1f) + messages.addAll( + listOf( + OscContent.Message(OscMessage("/avatar/parameters/TipToes${side.oscName}", listOf(if (tipToe) OscArg.True else OscArg.False))), + OscContent.Message(OscMessage("/avatar/parameters/ToeBent${side.oscName}${oscToeNumber}Bool", listOf(if (bending) OscArg.True else OscArg.False))), + OscContent.Message(OscMessage("/avatar/parameters/ToeSplay${side.oscName}$oscToeNumber", listOf(if (splayed) OscArg.True else OscArg.False))), + OscContent.Message(OscMessage("/avatar/parameters/Toe${side.oscName}${oscToeNumber}Float", listOf(OscArg.Float(toeCurlValue)))), + OscContent.Message(OscMessage("/avatar/parameters/ToeSplay${side.oscName}${oscToeNumber}Float", listOf(OscArg.Float(toeSplayValue)))), + ), + ) +} diff --git a/server/core/src/test/java/dev/slimevr/skeleton/ToeDirectLinkProcessorTest.kt b/server/core/src/test/java/dev/slimevr/skeleton/ToeDirectLinkProcessorTest.kt new file mode 100644 index 000000000..60d244a63 --- /dev/null +++ b/server/core/src/test/java/dev/slimevr/skeleton/ToeDirectLinkProcessorTest.kt @@ -0,0 +1,320 @@ +package dev.slimevr.skeleton + +import dev.slimevr.skeleton.processors.ToeDirectLinkInputProcessor +import io.github.axisangles.ktmath.Quaternion +import org.junit.jupiter.api.Test +import solarxr_protocol.datatypes.BodyPart +import kotlin.test.assertTrue + +class ToeDirectLinkProcessorTest { + @Test + fun `test missing all toe trackers`() { + val processor = ToeDirectLinkInputProcessor() + val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutate { map -> + map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(10f, 40f, 15f), + isActive = true, + ) + map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(20f, 50f, 25f), + isActive = true, + ) + } + + val state = SkeletonState( + boneInputs = inputs, + skeletonHeight = 1.7f, + paused = false, + ) + + val newInputs = processor.process(state) + + val leftBigToeIsSameRotationAsLeftFoot = + newInputs.boneInputs[BodyPart.LEFT_BIG_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_FOOT]?.rawRotation + val leftIndexToeIsSameRotationAsLeftBigToe = + newInputs.boneInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_BIG_TOE]?.rawRotation + val leftMiddleToeIsSameRotationAsLeftIndexToe = + newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation + val leftRingToeIsSameRotationAsLeftMiddleToe = + newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation + val leftLittleToeIsSameRotationAsLeftRingToe = + newInputs.boneInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation + + val rightBigToeIsSameRotationAsRightFoot = + newInputs.boneInputs[BodyPart.RIGHT_BIG_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_FOOT]?.rawRotation + val rightIndexToeIsSameRotationAsRightBigToe = + newInputs.boneInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_BIG_TOE]?.rawRotation + val rightMiddleToeIsSameRotationAsRightIndexToe = + newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation + val rightRingToeIsSameRotationAsRightMiddleToe = + newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation + val rightLittleToeIsSameRotationAsRightRingToe = + newInputs.boneInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation + + assertTrue( + leftBigToeIsSameRotationAsLeftFoot && + leftIndexToeIsSameRotationAsLeftBigToe && + leftMiddleToeIsSameRotationAsLeftIndexToe && + leftRingToeIsSameRotationAsLeftMiddleToe && + leftLittleToeIsSameRotationAsLeftRingToe, + ) + assertTrue( + rightBigToeIsSameRotationAsRightFoot && + rightIndexToeIsSameRotationAsRightBigToe && + rightMiddleToeIsSameRotationAsRightIndexToe && + rightRingToeIsSameRotationAsRightMiddleToe && + rightLittleToeIsSameRotationAsRightRingToe, + ) + } + + @Test + fun `test missing toe trackers from index toe downwards`() { + val processor = ToeDirectLinkInputProcessor() + val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutate { map -> + map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(10f, 40f, 15f), + isActive = true, + ) + map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(11f, 41f, 16f), + isActive = true, + ) + map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(20f, 50f, 25f), + isActive = true, + ) + map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(21f, 51f, 26f), + isActive = true, + ) + } + + val state = SkeletonState( + boneInputs = inputs, + skeletonHeight = 1.7f, + paused = false, + ) + + val newInputs = processor.process(state) + + val leftIndexToeIsSameRotationAsLeftBigToe = + newInputs.boneInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_BIG_TOE]?.rawRotation + val leftMiddleToeIsSameRotationAsLeftIndexToe = + newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation + val leftRingToeIsSameRotationAsLeftMiddleToe = + newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation + val leftLittleToeIsSameRotationAsLeftRingToe = + newInputs.boneInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation + + val rightIndexToeIsSameRotationAsRightBigToe = + newInputs.boneInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_BIG_TOE]?.rawRotation + val rightMiddleToeIsSameRotationAsRightIndexToe = + newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation + val rightRingToeIsSameRotationAsRightMiddleToe = + newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation + val rightLittleToeIsSameRotationAsRightRingToe = + newInputs.boneInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation + + assertTrue( + leftIndexToeIsSameRotationAsLeftBigToe && + leftMiddleToeIsSameRotationAsLeftIndexToe && + leftRingToeIsSameRotationAsLeftMiddleToe && + leftLittleToeIsSameRotationAsLeftRingToe, + ) + assertTrue( + rightIndexToeIsSameRotationAsRightBigToe && + rightMiddleToeIsSameRotationAsRightIndexToe && + rightRingToeIsSameRotationAsRightMiddleToe && + rightLittleToeIsSameRotationAsRightRingToe, + ) + } + + @Test + fun `test missing toe trackers from middle toe downwards`() { + val processor = ToeDirectLinkInputProcessor() + val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutate { map -> + map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(10f, 40f, 15f), + isActive = true, + ) + map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(11f, 41f, 16f), + isActive = true, + ) + map[BodyPart.LEFT_INDEX_TOE] = map.getValue(BodyPart.LEFT_INDEX_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(12f, 42f, 17f), + isActive = true, + ) + + map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(20f, 50f, 25f), + isActive = true, + ) + map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(21f, 51f, 26f), + isActive = true, + ) + map[BodyPart.RIGHT_INDEX_TOE] = map.getValue(BodyPart.RIGHT_INDEX_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(22f, 52f, 27f), + isActive = true, + ) + } + + val state = SkeletonState( + boneInputs = inputs, + skeletonHeight = 1.7f, + paused = false, + ) + + val newInputs = processor.process(state) + + val leftMiddleToeIsSameRotationAsLeftIndexToe = + newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_INDEX_TOE]?.rawRotation + val leftRingToeIsSameRotationAsLeftMiddleToe = + newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation + val leftLittleToeIsSameRotationAsLeftRingToe = + newInputs.boneInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation + + val rightMiddleToeIsSameRotationAsRightIndexToe = + newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_INDEX_TOE]?.rawRotation + val rightRingToeIsSameRotationAsRightMiddleToe = + newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation + val rightLittleToeIsSameRotationAsRightRingToe = + newInputs.boneInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation + + assertTrue( + leftMiddleToeIsSameRotationAsLeftIndexToe && + leftRingToeIsSameRotationAsLeftMiddleToe && + leftLittleToeIsSameRotationAsLeftRingToe, + ) + assertTrue( + rightMiddleToeIsSameRotationAsRightIndexToe && + rightRingToeIsSameRotationAsRightMiddleToe && + rightLittleToeIsSameRotationAsRightRingToe, + ) + } + + @Test + fun `test missing toe trackers from ring toe downwards`() { + val processor = ToeDirectLinkInputProcessor() + val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutate { map -> + map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(10f, 40f, 15f), + isActive = true, + ) + map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(11f, 41f, 16f), + isActive = true, + ) + map[BodyPart.LEFT_INDEX_TOE] = map.getValue(BodyPart.LEFT_INDEX_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(12f, 42f, 17f), + isActive = true, + ) + map[BodyPart.LEFT_MIDDLE_TOE] = map.getValue(BodyPart.LEFT_MIDDLE_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(13f, 43f, 18f), + isActive = true, + ) + + map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(20f, 50f, 25f), + isActive = true, + ) + map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(21f, 51f, 26f), + isActive = true, + ) + map[BodyPart.RIGHT_INDEX_TOE] = map.getValue(BodyPart.RIGHT_INDEX_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(22f, 52f, 27f), + isActive = true, + ) + map[BodyPart.RIGHT_MIDDLE_TOE] = map.getValue(BodyPart.RIGHT_MIDDLE_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(23f, 53f, 28f), + isActive = true, + ) + } + + val state = SkeletonState( + boneInputs = inputs, + skeletonHeight = 1.7f, + paused = false, + ) + + val newInputs = processor.process(state) + + val leftRingToeIsSameRotationAsLeftMiddleToe = + newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_MIDDLE_TOE]?.rawRotation + val leftLittleToeIsSameRotationAsLeftRingToe = + newInputs.boneInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation + + val rightRingToeIsSameRotationAsRightMiddleToe = + newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_MIDDLE_TOE]?.rawRotation + val rightLittleToeIsSameRotationAsRightRingToe = + newInputs.boneInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation + + assertTrue(leftRingToeIsSameRotationAsLeftMiddleToe && leftLittleToeIsSameRotationAsLeftRingToe) + assertTrue(rightRingToeIsSameRotationAsRightMiddleToe && rightLittleToeIsSameRotationAsRightRingToe) + } + + @Test + fun `test missing little toe tracker`() { + val processor = ToeDirectLinkInputProcessor() + val inputs = DEFAULT_SKELETON_STATE.boneInputs.mutate { map -> + map[BodyPart.LEFT_FOOT] = map.getValue(BodyPart.LEFT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(10f, 40f, 15f), + isActive = true, + ) + map[BodyPart.LEFT_BIG_TOE] = map.getValue(BodyPart.LEFT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(11f, 41f, 16f), + isActive = true, + ) + map[BodyPart.LEFT_INDEX_TOE] = map.getValue(BodyPart.LEFT_INDEX_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(12f, 42f, 17f), + isActive = true, + ) + map[BodyPart.LEFT_MIDDLE_TOE] = map.getValue(BodyPart.LEFT_MIDDLE_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(15f, 45f, 19f), + isActive = true, + ) + map[BodyPart.LEFT_RING_TOE] = map.getValue(BodyPart.LEFT_RING_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(13f, 43f, 18f), + isActive = true, + ) + + map[BodyPart.RIGHT_FOOT] = map.getValue(BodyPart.RIGHT_FOOT).copy( + rawRotation = Quaternion.Companion.fromRotationVector(20f, 50f, 25f), + isActive = true, + ) + map[BodyPart.RIGHT_BIG_TOE] = map.getValue(BodyPart.RIGHT_BIG_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(21f, 51f, 26f), + isActive = true, + ) + map[BodyPart.RIGHT_INDEX_TOE] = map.getValue(BodyPart.RIGHT_INDEX_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(22f, 52f, 27f), + isActive = true, + ) + map[BodyPart.RIGHT_MIDDLE_TOE] = map.getValue(BodyPart.RIGHT_MIDDLE_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(23f, 53f, 28f), + isActive = true, + ) + map[BodyPart.RIGHT_RING_TOE] = map.getValue(BodyPart.RIGHT_RING_TOE).copy( + rawRotation = Quaternion.Companion.fromRotationVector(24f, 54f, 29f), + isActive = true, + ) + } + + val state = SkeletonState( + boneInputs = inputs, + skeletonHeight = 1.7f, + paused = false, + ) + + val newInputs = processor.process(state) + + val leftLittleToeIsSameRotationAsLeftRingToe = + newInputs.boneInputs[BodyPart.LEFT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.LEFT_RING_TOE]?.rawRotation + val rightLittleToeIsSameRotationAsRightRingToe = + newInputs.boneInputs[BodyPart.RIGHT_LITTLE_TOE]?.rawRotation == newInputs.boneInputs[BodyPart.RIGHT_RING_TOE]?.rawRotation + + assertTrue(leftLittleToeIsSameRotationAsLeftRingToe && rightLittleToeIsSameRotationAsRightRingToe) + } +} diff --git a/solarxr-protocol b/solarxr-protocol index 0e107b6b9..f1bf9d386 160000 --- a/solarxr-protocol +++ b/solarxr-protocol @@ -1 +1 @@ -Subproject commit 0e107b6b9f7de493d24f61cb20e7bf76ced79edd +Subproject commit f1bf9d386f56ec1c371b44d7de862034a4844fa8