Skip to content

Importing Sightlab into Your Existing Code

See also Code Attributes and Methods

Short summary of steps:

For adding data collection and replay follow these steps:

  1. Import the sightlab module and create an instance of SightLab

    import sightlab_utils.sightlab as sl
    from sightlab_utils.settings import *
    
    # Set GUI to false to not see the GUI setup options
    sightlab = sl.SightLab(gui=False)
    
  2. Let sightlab know what the environment model is (or provide a handle to it)

    env = vizfx.addChild("resources/environments/dojo2.osgb")
    sightlab.setEnvironment(env)
    
  3. If wanting to have any objects of interest, add those to the scene objects (optional). Can also set grabbable, visible or as avatar for replay.

    basketball = env.getChild("basketball")
    sightlab.addSceneObject("basketball", basketball, gaze=True, grab=True)
    
  4. Start Sightlab after whatever event or function starts your session (can use viztask.waitTime(0) if it starts right away). Also place sightlab.endTrial() where the session ends. Certain functions and code can only be accessible after sightlab.startTrial()

    • yield sightlab.startTrial()
    • yield sightlab.endTrial()
  5. Schedule sightlab

    viztask.schedule(sightlab.runExperiment)
    
  6. To use the Replay you will need to manually copy over the SightLabVR_Replay.py file from the Projects-SampleProject folder

Example

import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *

# Setup SightLab Options
sightlab = sl.SightLab(gui=False)

# Setup Environment
env = vizfx.addChild("resources/environment/dojo2.osgb")
sightlab.setEnvironment(env)

# set number of trials
sightlab.setTrialCount(3)

# add objects of interest
basketball = 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 function

def 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')

Running without Data Collection

Note: these steps are to add the data collection and replay, to just run a Vizard script in sightlab without data collection you only need to add these lines

import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *

sightlab = sl.SightLab(gui = False, pid = False, fadequad = False, headlight = True)

sightlab.setStartText(' ')

Also see the SightLab 2.0 Code Overview Page

Making Any Vizard Script Multi-User

To make any existing Vizard script multi-user, you can just plug-in the code to import SightLab, create an instance of either the SightLabServer or SightLabClient class (will need one machine to run as the server and then can add as many clients as you like), then just schedule the SightLab loop so they can be synchronized. This is the most basic setup, for additional Multi-User functionality see multi-user-custom-experiments or running-a-session-with-multi-user.

import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *

#Change to sl.SightLabClient() for client script
sightlab = sl.SightLabServer()

#Set environment
env = vizfx.addChild('piazza.osgb')

def sightLabExperiment(): 
    yield viztask.waitEvent(EXPERIMENT_START)
    viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)


    for trial in range(sightlab.getTrialCount()):
        yield viztask.waitEvent(TRIAL_START)

        yield viztask.waitEvent(TRIAL_END)

#change to sightlab.runClient for Client script
viztask.schedule(sightlab.runServer)
viztask.schedule(sightLabExperiment)

Questions, contact support@worldviz.com