Importing Sightlab into Your Existing Code

See also Code Attributes and Methods


Short summary of steps:

import sightlab_utils.sightlab as slfrom sightlab_utils.settings import *
#Set GUI to false to not see the GUI setup optionssightlab = sl.SightLab(gui = False)
env = vizfx.addChild('resources/environments/dojo2.osgb')sightlab.setEnvironment(env)
    • yield sightlab.startTrial()
    • yield sightlab.endTrial()
viztask.schedule(sightlab.runExperiment)

Example

import sightlab_utils.sightlab as slfrom sightlab_utils.settings import *
#Setup SightLab Optionssightlab = sl.SightLab(gui = False)
#Setup Environmentenv = vizfx.addChild('resources/environment/dojo2.osgb')sightlab.setEnvironment(env)
#set number of trialssightlab.setTrialCount(3)
#add objects of interestbasketball = env.getChild('basketball')sightlab.addSceneObject('basketball',basketball,gaze = True, grab = True)
#Need some event that calls sightlab.startTrial() and endTrial(). This can also be inside your own functiondef sightLabExperiment(): while True: yield viztask.waitKeyDown(' ') yield sightlab.startTrial()
yield viztask.waitKeyDown(' ') yield sightlab.endTrial()
viztask.schedule(sightlab.runExperiment)viztask.schedule(sightLabExperiment)

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


Custom Vizconnect Files

If needing to use your own vizconnect file or files use this code when creating the SightLab instance. Define the name for the vizconnect and then give the path. For multiple custom vizconnects, will need to create a dictionary first and give that dictionary after vizconnectconfig = )

i.e. sightlab = sl.SightLab(gui=False, vizconnectconfig = {'Desktop':'vizconnect_files/vizconnect_config_desktop.py'})


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. Also, you may need to rename certain objects such as "main_transport", "head_tracker", "r_hand_tracker","l_hand_tracker", "r_hand_input", "l_hand_input", "main_display", etc. (see a sample SightLab vizconnect for these names).  For desktop vizconnects you can add a group tracker for the left hand. 


We recommend copying one of the SightLab vizconnect files into your project and copying and pasting your custom events into it, otherwise you would have to manually add the relevant code. 


Adding Custom Start Text

sightlab.setStartText('Your starting condition here')

Setting the Environment and SceneObjects from a class in an External Module

If you have your environment object or sceneObjects (objects you're wanting to collect data on) inside of a class in an external module, make sure that the node is accessible by adding "self" (i.e. self. node)

class Kitchen(viz.VizNode, viz.EventClass):    

    def __init__(self):

        self.node = vizfx.addChild('Assets/Environments/Kitchen.osgb')

        viz.VizNode.__init__(self, self.node.id)

        viz.EventClass.__init__(self)


Then use the class as the object for the environment:

import kitchen

env = kitchen.Kitchen()

sightlab.setEnvironment(env)

Questions, contact support@worldviz.com