Skip to content

Selector Tool

Overview

The Selector Tool is designed for interacting with objects in a VR scene using a highlighter mechanism. This document outlines its functionality, implementation, and usage.

Default Controls

  • VR Mode:
  • Controller grip button (right or left): Turn on the selector (for Vive controllers, these are the Left and Right system buttons)
  • Trigger: Use the selector
  • Desktop Mode:
  • Right mouse button: Toggle the selector on/off
  • Left mouse button: Use the selector

Examples

Locate the following files in the ExampleScripts\Selector Tool directory (also in Multi User ExamplesScripts\Selector Tool:

Selector_Tool_GUI

  • Automatically targets objects tagged for interactions
  • Displays a window with the name of the highlighted object

Selector_Tool_GUI_Grab

  • Allows grabbing objects from a distance
  • Left click to select and move objects, left click again to place

Selector_Tool

  • A simple non-GUI example

Multi User

  • Example for Multiple Users

Implementation Guide

1. Import Required Modules or Add From Main Class

There is a built in highlighter when calling SightLab, but can also import a specific module

Importing Module Method

from sightlab_utils import selector
from tools import highlighter
Built in option
sightlab = sl.SightLab(highlighttool = True)

2. Next Steps

After (sightlab.startTrial() or yield viztask.waitEvent(TRIAL_START)

Set up global variables:

isConfirmingTarget = False
currentHighlightedObject = None

3. Define Target Objects

Manually:

soccerball = env.getChild('soccerball')
basketball = env.getChild('basketball')
target_objects = [basketball, soccerball]

for obj in target_objects:
    selector.tool.setItems([obj])
    selector.tool2.setItems([obj])

targetObject = basketball

Automatically from GUI:

target_names = list(sightlab.sceneObjects[GAZE_OBJECTS].keys())
target_objects = {}
object_name_map = {}

for name in target_names:
    obj = env.getChild(name)
    if obj:
        target_objects[name] = obj
        object_name_map[obj] = name

selector.tool.setItems(list(target_objects.values()))
selector.tool2.setItems(list(target_objects.values()))
targetObject = list(target_objects.values())

4. Define Callback Functions

(After "Action to Perform," place the action you want to happen when the target is clicked on.)

def confirmTarget(e):
    global isConfirmingTarget, currentHighlightedObject
    isConfirmingTarget = True

    if currentHighlightedObject == targetObject:
        # Action to perform
        print('Object is Targeted')
    isConfirmingTarget = False

def onHighlight(e):
    global currentHighlightedObject
    currentHighlightedObject = e.new

    if isConfirmingTarget and currentHighlightedObject == targetObject:
        print(f'{currentHighlightedObject} is highlighted')

5. Set Up Event Callbacks

viz.callback(viz.getEventID("triggerPress"), confirmTarget)
viz.callback(highlighter.HIGHLIGHT_EVENT, onHighlight)

6. Configure Highlighter for Hand Controllers

selector.setupSelector(sightlab.getConfig())

Multi User

For multi-user just add this code for the clients (not needed on the server)

sightlab = sl.SightLabClient(highlighttool = True)

For more information, see this page in the Vizard Documentation.