Gaze Based Interactions

There is an end condition in the GUI for gaze based events that allow you to trigger ending the current trial or progressing to the next one using an onGazeTime event. For additional gaze based triggers see below. 

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 "ExampleScripts" folder 

import sightlab_utils.sightlab as sl

from sightlab_utils.settings import *


sightlab = sl.SightLab()


sightlab.setEnvironmentDirectory('..\..\Projects\SampleProject\Resources\environments')


#Gaze interaction objects

chick1 = vizfx.addAvatar('sightlab_resources/objects/chick.osgb')

#basketball = vizfx.addChild('basketball.osgb')

chick1.setPosition([0, 0, 2.5])


creature1 = vizfx.addAvatar('sightlab_resources/objects/Creature.osgb')

creature1.setPosition([1.67, 0.5, 2])

creature1.setEuler(22,0,0); 

creature1.state(5)


sightlab.addSceneObject("chick1", chick1, gaze = True, avatar = True)

sightlab.addSceneObject("creature1", creature1, gaze = True,avatar = True)


def gazeActionEnd(e):

    if e.object == sightlab.sceneObjects[GAZE_OBJECTS]['creature1']:

        creature1.state(4)

        print('stopped looking')

        

    if e.object == sightlab.sceneObjects[GAZE_OBJECTS]['chick1']:

        chick1.state(0)

        print('stopped looking')


def gazeActionStart(e):

    if e.object == sightlab.sceneObjects[GAZE_OBJECTS]['creature1']:

        creature1.state(6)

        print('saw creature')

        

    if e.object == sightlab.sceneObjects[GAZE_OBJECTS]['chick1']:

        chick1.state(10)

        print('stopped looking')

    

vizact.addCallback(sightlab.GAZE_TIME_EVENT, gazeActionStart)    

vizact.addCallback(sightlab.GAZE_END_EVENT, gazeActionEnd)

    

import viztask

def sightLabExperiment():

while True:

yield viztask.waitKeyDown(' ')

yield sightlab.startTrial()

yield viztask.waitKeyDown(' ')

yield sightlab.endTrial()


viztask.schedule(sightlab.runExperiment)

viztask.schedule(sightLabExperiment)


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)