From eb865ab544098dc59d7ec1acf664c071cf2e1f98 Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:53:47 -0800 Subject: [PATCH] fix: eye falloff logic and handling, add comments --- EyeTrackApp/osc.py | 5 ++ EyeTrackApp/osc_calibrate_filter.py | 4 ++ EyeTrackApp/utils/eye_falloff.py | 105 +++++++++------------------- 3 files changed, 41 insertions(+), 73 deletions(-) diff --git a/EyeTrackApp/osc.py b/EyeTrackApp/osc.py index 02be6da..04872b3 100644 --- a/EyeTrackApp/osc.py +++ b/EyeTrackApp/osc.py @@ -33,6 +33,7 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, pupil_dilation, avg_velocity if self.config.gui_osc_vrcft_v1: + if self.main_config.eye_display_id in [ EyeId.RIGHT, EyeId.LEFT, @@ -208,10 +209,12 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, pupil_dilation, avg_velocity if self.config.gui_vrc_native: # VRC NATIVE + if self.main_config.eye_display_id in [ EyeId.RIGHT, EyeId.LEFT, ]: # we are in single eye mode + se = True if eye_blink == 0.0: if last_blink > 0.2: # when binary blink is on, blinks may be too fast for OSC so we repeat them. @@ -231,6 +234,7 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, pupil_dilation, avg_velocity se = False if self.eye_id in [EyeId.LEFT] and not se: # left eye, send data to left + self.l_eye_x = eye_x self.l_eye_blink = eye_blink self.left_y = eye_y @@ -284,6 +288,7 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, pupil_dilation, avg_velocity eye_y = (self.right_y + self.left_y) / 2 if not se: + # vrc native ET (z values may need tweaking, they act like a scalar) self.client.send_message( "/tracking/eye/LeftRightVec", diff --git a/EyeTrackApp/osc_calibrate_filter.py b/EyeTrackApp/osc_calibrate_filter.py index 2a9c9ec..4f5d367 100644 --- a/EyeTrackApp/osc_calibrate_filter.py +++ b/EyeTrackApp/osc_calibrate_filter.py @@ -79,6 +79,10 @@ class var: l_eye_velocity = 0.0 r_eye_velocity = 0.0 overlay_active = False + falloff_latch = False + single_eye = True + left_enb = 0 + right_enb = 0 @Async diff --git a/EyeTrackApp/utils/eye_falloff.py b/EyeTrackApp/utils/eye_falloff.py index 0157782..9f2176d 100644 --- a/EyeTrackApp/utils/eye_falloff.py +++ b/EyeTrackApp/utils/eye_falloff.py @@ -1,85 +1,44 @@ import numpy as np from enum import IntEnum - class EyeId(IntEnum): - RIGHT = 0 - LEFT = 1 - BOTH = 2 - SETTINGS = 3 - + RIGHT = 0 + LEFT = 1 + BOTH = 2 + SETTINGS = 3 def velocity_falloff(self, var, out_x, out_y): - - falloff = False - if self.eye_id in [EyeId.LEFT]: - var.l_eye_velocity = var.average_velocity - if self.settings.gui_outer_side_falloff: - dist = abs( - np.sqrt( - abs(np.square(out_x - var.r_eye_x) - np.square(out_y - var.right_y)) - ) - ) - # print(dist) # TODO remove once testing is done - if dist > self.settings.gui_eye_dominant_diff_thresh: - falloff = True - if ( - not self.settings.gui_left_eye_dominant - and not self.settings.gui_right_eye_dominant - ): - if var.l_eye_velocity < var.r_eye_velocity: - var.r_eye_x = out_x - var.right_y = out_y - else: - out_x = var.l_eye_x - out_y = var.left_y - elif self.settings.gui_left_eye_dominant: - var.r_eye_x = out_x - var.right_y = out_y - falloff = False - else: - var.l_eye_x = out_x - var.left_y = out_y - falloff = False + # Calculate the distance between the two eyes + dist = np.sqrt(np.square(var.l_eye_x - var.r_eye_x) + np.square(var.left_y - var.right_y)) + if self.eye_id == EyeId.LEFT: + var.l_eye_x = out_x + var.left_y = out_y if self.eye_id == EyeId.RIGHT: - var.r_eye_velocity = var.average_velocity - if self.settings.gui_outer_side_falloff: - dist = abs( - np.sqrt( - abs(np.square(var.l_eye_x - out_x) - np.square(var.left_y - out_y)) - ) - ) - # print(dist, "r") # TODO remove once testing is done - if dist > self.settings.gui_eye_dominant_diff_thresh: - falloff = True - if ( - not self.settings.gui_left_eye_dominant - and not self.settings.gui_right_eye_dominant - ): - if var.l_eye_velocity < var.r_eye_velocity: - var.r_eye_x = out_x - var.right_y = out_y - else: - var.l_eye_x = out_x - var.left_y = out_y # need to make sure we send these values... might re think the whole file - elif self.settings.gui_right_eye_dominant: - var.l_eye_x = out_x - var.left_y = out_y - falloff = False + var.r_eye_x = out_x + var.right_y = out_y + + # Check if the distance is greater than the threshold + if dist > self.settings.gui_eye_dominant_diff_thresh: + + if self.settings.gui_right_eye_dominant: + out_x, out_y = var.r_eye_x, var.right_y + + elif self.settings.gui_left_eye_dominant: + out_x, out_y = var.l_eye_x, var.left_y + + else: + # If the distance is too large, identify the eye with the lower velocity + if var.l_eye_velocity < var.r_eye_velocity: + # Mirror the position of the eye with lower velocity to the other eye + out_x, out_y = var.r_eye_x, var.right_y else: - falloff = False - var.r_eye_x = out_x - var.right_y = out_y + # Mirror the position of the eye with lower velocity to the other eye + out_x, out_y = var.l_eye_x, var.left_y + else: + # If the distance is within the threshold, do not mirror the eyes + pass - if self.eye_id == EyeId.LEFT and falloff: - out_x = var.r_eye_x - out_y = var.right_y - if self.eye_id == EyeId.RIGHT and falloff: - out_x = var.l_eye_x - out_y = ( - var.left_y - ) # needs to not be in this file lol... well if we want proper visualization.. - return out_x, out_y + return out_x, out_y \ No newline at end of file