fix: eye falloff logic and handling, add comments

This commit is contained in:
Prohurtz 2024-02-19 12:53:47 -08:00
parent 2ceb0619e0
commit eb865ab544
3 changed files with 41 additions and 73 deletions

View File

@ -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.config.gui_osc_vrcft_v1:
if self.main_config.eye_display_id in [ if self.main_config.eye_display_id in [
EyeId.RIGHT, EyeId.RIGHT,
EyeId.LEFT, 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.config.gui_vrc_native: # VRC NATIVE
if self.main_config.eye_display_id in [ if self.main_config.eye_display_id in [
EyeId.RIGHT, EyeId.RIGHT,
EyeId.LEFT, EyeId.LEFT,
]: # we are in single eye mode ]: # we are in single eye mode
se = True se = True
if eye_blink == 0.0: 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. 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 se = False
if self.eye_id in [EyeId.LEFT] and not se: # left eye, send data to left 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_x = eye_x
self.l_eye_blink = eye_blink self.l_eye_blink = eye_blink
self.left_y = eye_y 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 eye_y = (self.right_y + self.left_y) / 2
if not se: if not se:
# vrc native ET (z values may need tweaking, they act like a scalar) # vrc native ET (z values may need tweaking, they act like a scalar)
self.client.send_message( self.client.send_message(
"/tracking/eye/LeftRightVec", "/tracking/eye/LeftRightVec",

View File

@ -79,6 +79,10 @@ class var:
l_eye_velocity = 0.0 l_eye_velocity = 0.0
r_eye_velocity = 0.0 r_eye_velocity = 0.0
overlay_active = False overlay_active = False
falloff_latch = False
single_eye = True
left_enb = 0
right_enb = 0
@Async @Async

View File

@ -1,85 +1,44 @@
import numpy as np import numpy as np
from enum import IntEnum from enum import IntEnum
class EyeId(IntEnum): class EyeId(IntEnum):
RIGHT = 0 RIGHT = 0
LEFT = 1 LEFT = 1
BOTH = 2 BOTH = 2
SETTINGS = 3 SETTINGS = 3
def velocity_falloff(self, var, out_x, out_y): def velocity_falloff(self, var, out_x, out_y):
# Calculate the distance between the two eyes
falloff = False 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 in [EyeId.LEFT]: if self.eye_id == EyeId.LEFT:
var.l_eye_velocity = var.average_velocity var.l_eye_x = out_x
if self.settings.gui_outer_side_falloff: var.left_y = out_y
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
if self.eye_id == EyeId.RIGHT: if self.eye_id == EyeId.RIGHT:
var.r_eye_velocity = var.average_velocity var.r_eye_x = out_x
if self.settings.gui_outer_side_falloff: var.right_y = out_y
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
# 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: else:
falloff = False # Mirror the position of the eye with lower velocity to the other eye
var.r_eye_x = out_x out_x, out_y = var.l_eye_x, var.left_y
var.right_y = out_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