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
#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)
def sightLabExperiment(): while True: yield viztask.waitKeyDown(' ') yield sightlab.startTrial()
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 food item 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 by using the rating scale at the end of each trial. 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)