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. Add From Main Class
sightlab=sl.SightLab(highlighttool=True)
2. Next Steps
After (sightlab.startTrial() or yield viztask.waitEvent(TRIAL_START)
soccerball=env.getChild('soccerball')basketball=env.getChild('basketball')target_objects=[basketball,soccerball]forobjintarget_objects:#Can also use enable = True to have it automatically on at the startsightlab.setHighlighter(mode=sl.highlighter.MODE_BOX,setItems=target_objects)targetObject=basketball
(After "Action to Perform," place the action you want to happen when the target is clicked on.)
defconfirmTarget(e):globalisConfirmingTarget,currentHighlightedObjectisConfirmingTarget=TrueifcurrentHighlightedObject==targetObject:# Action to performprint('Object is Targeted')isConfirmingTarget=FalsedefonHighlight(e):globalcurrentHighlightedObjectcurrentHighlightedObject=e.newifisConfirmingTargetandcurrentHighlightedObject==targetObject:print(f'{currentHighlightedObject} is highlighted')
For multi-user just add this code for the clients (not needed on the server)
sightlab=sl.SightLabClient(highlighttool=True)
Highlight and confirm events are then sent as network events and callbacks
defid(name):"""Generate unique ID for use over viznet"""returnf'viznet:{name}'ON_HIGHLIGHT_EVENT=id('ON_HIGHLIGHT_EVENT')ON_HIGHLIGHT_EVENT2=id('ON_HIGHLIGHT_EVENT2')CONFIRM_EVENT=id('CONFIRM_EVENT')CONFIRM_EVENT2=id('CONFIRM_EVENT2')STOP_HIGHLIGHT_EVENT=id('STOP_HIGHLIGHT_EVENT')
target_objects=[targetObject]forobjintarget_objects:sightlab.setHighlighter(mode=sl.highlighter.MODE_BOX,setItems=target_objects)#Global variables and key event handlersglobalisConfirmingTarget,currentHighlightedObjectisConfirmingTarget=FalsecurrentHighlightedObject=NonedefconfirmTarget(e):globalisConfirmingTargetisConfirmingTarget=TrueifcurrentHighlightedObject==targetObject:print('targetObject is confirmed')viznet.client.sendAll(CONFIRM_EVENT,client=viz.net.getName())elifcurrentHighlightedObject==targetObject2:print('targetObject2 is confirmed')viznet.client.sendAll(CONFIRM_EVENT2,client=viz.net.getName())isConfirmingTarget=Falseviz.callback(viz.getEventID('triggerPress'),confirmTarget)viz.callback(viz.getEventID('triggerPressLeft'),confirmTarget)defonHighlight(e):globalcurrentHighlightedObjectife.new:# Check if there's a new object being highlightedcurrentHighlightedObject=e.newifcurrentHighlightedObject==targetObject:print('This happens on highlight for target 1')viznet.client.sendAll(ON_HIGHLIGHT_EVENT,client=viz.net.getName())ifisConfirmingTarget:print(f'{targetObject} is highlighted')elifcurrentHighlightedObject==targetObject2:print('This happens on highlight for target 2')viznet.client.sendAll(ON_HIGHLIGHT_EVENT2,client=viz.net.getName())ifisConfirmingTarget:print(f'{targetObject2} is highlighted')else:# No object is highlighted, reset the alphaifcurrentHighlightedObject==targetObject:viznet.client.sendAll(STOP_HIGHLIGHT_EVENT,client=viz.net.getName())elifcurrentHighlightedObject==targetObject2:viznet.client.sendAll(STOP_HIGHLIGHT_EVENT,client=viz.net.getName())currentHighlightedObject=Noneviz.callback(sl.highlighter.HIGHLIGHT_EVENT,onHighlight)#Receive highlight or confirm from other clients and place on server scriptdefhighlightAction(e):print('receive highlight action from other client for target 1')viz.callback(ON_HIGHLIGHT_EVENT,highlightAction)defhighlightAction2(e):print('receive highlight action from other client for target 2')viz.callback(ON_HIGHLIGHT_EVENT2,highlightAction2)defnoHighlightAction(e):print('stop highlight actions')viz.callback(STOP_HIGHLIGHT_EVENT,noHighlightAction)defreceiveConfirm1(e):print('received confirm from other client for target 1')viz.callback(CONFIRM_EVENT,showInfo)defreceiveConfirm2(e):print('received confirm from other client for target 2')viz.callback(CONFIRM_EVENT2,showInfo2)
For more information, see this page in the Vizard Documentation.