Gaze Based Interactions
Single User
To add your own, custom events when an object is in view, (such as gaze based interactions, etc.) you can place code inside the following functions.
onGazeBegin for your event to be triggered as soon as a gazeObject is seen
onGazeEnd to trigger something to happen when a user’s gaze point is no longer intersecting with that object
onGazeTime to trigger something that happens only when an object is being focused on over the set threshold
Note: If you plan on reviewing with the Session Replay you will need both an onGazeBegin and onGazeEnd function for the replay data to be saved properly
This example code is also in the "Examples" folder. You can also add this to a new script that is importing Sightlab.
#Gaze interaction objects
chick1 = vizfx.addAvatar('utils/resources/objects/chick.osgb')
chick1.setPosition([0, 0, 2.5])
creature1 = vizfx.addAvatar('utils/resources/objects/Creature.osgb')
creature1.setPosition([1.5, 0.5, 2])
creature1.setEuler(22,0,0);
creature1.state(5)
sightlab.gazeObjectsDict = {'chick1':chick1, 'creature1':creature1}
def gazeActionEnd(e):
if e.object == sightlab.gazeObjectsDict['creature1']:
creature1.state(4)
print('stopped looking')
if e.object == sightlab.gazeObjectsDict['chick1']:
chick1.state(0)
print('stopped looking')
def gazeActionStart(e):
if e.object == sightlab.gazeObjectsDict['creature1']:
creature1.state(6)
print('saw creature')
if e.object == sightlab.gazeObjectsDict['chick1']:
chick1.state(10)
print('stopped looking')
viz.callback(sightlab.eye_tracker_utils.GAZE_TIME_EVENT2,gazeActionStart)
viz.callback(sightlab.eye_tracker_utils.GAZE_END_EVENT2,gazeActionEnd)
Multi-User
On SightLabVR_Server.py script:
In the function onNetworkEvent (for when an object is fixated on) or onFixationEndEvent (when the fixation stops), add the code for whatever you want to have happen (i.e. a print statement) underneath each respective client's id number
def onNetworkEvent(e):
print(f'** Fixation end from: {e.sender}')
if e.clientNumber=="1":
print('client 1 interaction')
elif e.clientNumber=="2":
print('client 2 interaction')
elif e.clientNumber=="3":
print('client 3 interaction')
elif e.clientNumber=="4":
print('client 4 interaction')
elif e.clientNumber=="5":
print('client 5 interaction')
viz.callback(FIXATION_NETWORK_KEY_EVENT, onNetworkEvent)
On SightLabVR_Client.py script:
Add whatever you want to have happen in the functions for onGazeTime (for when an object has been fixated on), onGazeBegin or OnGazeEnd, as well as the code to add another FIXATION_NETWORK_KEY_EVENT
def onGazeEnd(e):
if e.object == sightlab_client.gazeObjectsDict['creature1']:
creature1.state(4)
print('stopped looking')
viznet.client.sendAll(sightlab_client.FIXATION_STOPPED_NETWORK_KEY_EVENT,clientNumber = sightlab_client.clientChoice,client=viz.net.getName())
def onGazeTime(e):
if e.object == sightlab_client.gazeObjectsDict['creature1']:
creature1.state(6)
print('saw creature')
viznet.client.sendAll(sightlab_client.FIXATION_NETWORK_KEY_EVENT,clientNumber = sightlab_client.clientChoice,client=viz.net.getName())
viz.callback(sightlab_client.eye_tracker_utils.GAZE_TIME_EVENT,onGazeTime)
viz.callback(sightlab_client.eye_tracker_utils.GAZE_END_EVENT,onGazeEnd)