Skip to content

Example without GUI

This is an example for running SightLab without the GUI. For additional atributes and methods see this page. Find this under ExampleScripts- SampleCode- SightLabVR_NonGUI

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. env.getChild for objects in environment, or vizfx.addChild if #not
basketball = env.getChild('basketball')
sightlab.addSceneObject('basketball',basketball,gaze = True, grab = True)

def sightLabExperiment():
    while True:
        #Event to start trial
        yield viztask.waitKeyDown(' ')
        yield sightlab.startTrial()

        #Event to end trial
        yield viztask.waitKeyDown(' ')
        yield sightlab.endTrial()

viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)
viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)

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

Simple example with instructions and rating:

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

# Setup SightLab without GUI
sightlab = sl.SightLab(gui=False)

# Setup the virtual environment
env = vizfx.addChild('sightlab_resources/environments/dojo2.osgb')
sightlab.setEnvironment(env)

# Add scene objects
item1 = env.getChild('basketball')  # Adjust the model name as needed
item2 = env.getChild('volleyball')
sightlab.addSceneObject('basketball', item1, gaze=True, grab=False)
sightlab.addSceneObject('volleyball', item2, gaze=True, grab=False)

# Number of trials (adjust as needed)
sightlab.setTrialCount(5)  # For example, 5 trials

def sightLabExperiment():
    for i in range(sightlab.getTrialCount()):
        # Display instructions at the start of each trial
        if i == 0:
        # Wait for an event to start the experiment only on the first trial
            yield viztask.waitEvent(EXPERIMENT_START)

        # Start trial (optionally add trial length, conditions, etc.)
        yield sightlab.startTrial(startExperimentText = "Look at the two items and rate which one you like \n \n by using the rating scale at the end of each trial. \n \n Press trigger to begin")


        # Run the trial for the specified amount of time
        yield viztask.waitTime(4)

        # Show rating scale and wait for participant input
        yield sightlab.showRatings('Rate your preference', ratingScale=["1", "2", "3", "4", "5"], pauseTimer=True)

        # End the trial
        yield sightlab.endTrial(endExperimentText="Thank you for participating")
        yield viztask.waitTime(2)  # Optional cooldown time between trials

viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)
viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)

For more examples with code see this page, the example scripts where you can find examples for simple visual search tasks, perception, memory and much more.