Use the vizproximity library to detect proximity between Vizard objects and trigger events whenever a target enters or exits a sensor’s range. The library provides three main classes:
Sensor – Monitors an area or volume in your scene.
Target – Represents any linkable object (e.g., node, view, tracker, bone) whose position is checked against the sensor.
Manager – Oversees a collection of sensors and targets, automatically triggering events when a target crosses a sensor boundary.
For a quick introduction, see the example script ExampleScripts/Proximity Sensors/proximitySensors_example.py.
If you’re using SightLab 2.1.1 or higher, check out proximitySensors_Areas.py and proximitySensors_Areas2.py. These scripts demonstrate how you can place a proximity_area.osgb object (from sightlab_resources/objects) directly in a 3D scene, then move, rotate, or scale it. The object automatically updates its sensor area based on the transformations you apply.
importvizinputimportvizshapeimportsightlab_utils.sightlabasslfromsightlab_utils.settingsimport*sightlab=sl.SightLab(gui=False)sightlab.headLight.enable()env=vizfx.addChild('sightlab_resources/environments/DeckersOffice.OSGB')sightlab.setEnvironment(env)# Create objectsball=vizshape.addSphere(radius=0.1)ball.color(viz.BLUE)ball.setPosition(0,1.5,2)audio1=viz.playSound('sightlab_resources/audio/beep.wav',viz.SOUND_PRELOAD)importvizproximitymanager=vizproximity.Manager()# Add main viewpoint as proximity targettarget=vizproximity.Target(viz.MainView)manager.addTarget(target)#Add hand or finger as second targetavatar=vizconnect.getAvatar()rhand=avatar.getAttachmentPoint('r_hand').getNode3d()rhand_target=vizproximity.Target(rhand)lhand=avatar.getAttachmentPoint('l_hand').getNode3d()lhand_target=vizproximity.Target(lhand)manager.addTarget(lhand_target)manager.addTarget(rhand_target)#Add sensors. Replace the ball with whatever you want to use as a sensorBallSensor=vizproximity.addBoundingSphereSensor(ball)manager.addSensor(BallSensor)# Add circle areashape=vizproximity.Sensor(vizproximity.RectangleArea([1,1],center=[0,0.5]),None)manager.addSensor(shape)# Register callbacks for proximity sensorsdefEnterProximity(e):viz.playSound('sightlab_resources/audio/beep.wav')print('Entered Sensor')defExitProximity(e):print('Exited Sensor')manager.onEnter(None,EnterProximity)manager.onExit(None,ExitProximity)defactivateBallSensor(e):viz.playSound('sightlab_resources/audio/beep.wav')print('sensor entered')manager.onEnter(BallSensor,activateBallSensor)# Press "d" to toggle debug shapesmanager.setDebug(True)vizact.onkeydown('d',manager.setDebug,viz.TOGGLE)defsightLabExperiment():whileTrue:yieldviztask.waitKeyDown(' ')yieldsightlab.startTrial()yieldvizproximity.waitEnter(BallSensor,rhand_target)print('hand sensor activated')yieldviztask.waitKeyDown(' ')yieldsightlab.endTrial()viztask.schedule(sightlab.runExperiment)viztask.schedule(sightLabExperiment)viz.callback(viz.getEventID('ResetPosition'),sightlab.resetViewPoint)
Second Method (add proximity_area.osgb to a 3D scene in the scene editor, move, rotate and scale it how you want. To add multiple sensors add the same object and name the geode a different name (i.e. geode1, geode2, etc.). Can right click and choose "Rename".