mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
fix: eye falloff logic and handling, add comments
This commit is contained in:
parent
2ceb0619e0
commit
eb865ab544
@ -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",
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
Loading…
Reference in New Issue
Block a user