Importing Sightlab into Your Existing Code
See also Code Attributes and Methods
Short summary of steps:
- 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)
- Let sightlab know what the environment model is (or provide a handle to it)
env = vizfx.addChild("resources/environments/dojo2.osgb")
sightlab.setEnvironment(env)
-
Start Sightlab after whatever event or function starts your session (can use viztask.waitTime(0)) if it starts right away. Also can place sightlab.endTrial() where the session ends. Certain functions and code can only be accessible after sightlab.startTrial()
- yield sightlab.startTrial()
- yield sightlab.endTrial()
- Schedule sightlab
viztask.schedule(sightlab.runExperiment)
- 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')
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