Importing Sightlab into Your Existing Code

See also Modifying the Code


Short summary of steps:


Those are the basics, here are some more details: 


Note, there are two options for importing SightLab (both of these would then require you import the sightlab module into your script)


import sys

sys.path.insert(0, 'C:/Users/UserName/Documents/SightLab VR Pro 1.9/SightLabVRPro')


OR you can change the working directory using code like this:

import os
os.chdir('C:/Users/UserName/Documents/SightLab VR Multi User 1.9/SightLab VR Multi User 1.9')

If you want to then point to a directory where your script is located you need to use something like the following code, where "resources" is a folder in your current directory:

 current_script_dir = os.path.dirname(os.path.abspath(__file__))

 your_path = os.path.join(current_script_dir, 'resources/')


For this method can also use the "New Projects" folder


For  both of these methods  add this code:

import viz

import vizfx

from utils import sightlab

from settings import *

import vizconnect


Use “from utils import sightlab.py” at the top of your script. You then need to schedule the sightlab.experiment function and can add objects of interest manually (if they are not added directly in your environment). The only necessary element is adding the environment. Much of the additional functionality can be modified in the "settings.py" file. Here's an example: 


import vizimport vizfxfrom utils import sightlab
#Code to disable the GUI from showing (set to 1 if you want the GUI)sightlab.is_GUI = 0
#Example showing how to set environment. Note that environment should be defined before #objects of interestenv = vizfx.addChild("utils/resources/environment/dojo.osgb")sightlab.objects.append(env)
#set number of trialssightlab.sceneConfigDict["trials"] = 1
#add objects of interestbasketball = env.getChild('basketball')sightlab.gazeObjectsDict["basketball"] = basketball
#add object for only tracking replay animations, but not fixationsball = vizfx.addChild("soccerball.osgb")ball.setPosition(1,1,1)sightlab.objects.append(ball)
#run sightlab experimentimport viztaskviztask.schedule(sightlab.experiment)

Note: Make sure to schedule the experiment function after you’ve initialized all the other objects in the scene

If needing to use your own vizconnect files add your vizconnect to the “vizconnect_configs” folder and you can use this code to set a custom vizconnect list (make sure this is added before importing sightlab so that it uses this list):


import settings

def setVizconnectConfigs(new_configs):

    settings.VIZCONNECT_CONFIGS = new_configs

setVizconnectConfigs(['Desktop'])

from utils import sightlab


Additionally you can change the vizconnect.go() line in your code to use 

vizconnect_path = sightlab.vizconnect_path

vizconnect.go(vizconnect_path)


If you wish to use a custom vizconnect file, you will need to integrate the eye_tracker tracker into the “trackers” section and the “postinit” section. 


Note that when you disable the GUI the participant ID will be automatically set to current date and time. You can add back the participant info field in the code. 


Questions, contact support@worldviz.com