Selector Tool
Selector Tool Documentation
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:
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
- Implementation Guide
- 1. Import Required Modules
from sightlab_utils import selector
from tools import highlighter
2. Next Steps After (sightlab.startTrial() or yield viztask.waitEvent(TRIAL_START)
Set Up Global Variables
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 Peform" is where you place what you want to happen, when target is clicked on)
(After "Action to Peform" is where you place what you want to happen, when target is clicked on)
def confirmTarget(e):
global isConfirmingTarget, currentHighlightedObject
isConfirmingTarget = True
if currentHighlightedObject == targetObject:
# Action to perform
print('Object is Targetted')
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())
For more information see also this page in the Vizard Documentation