The following page contains a description of all the core Vizard events. Here is an overview of the available events:
|
Event code |
Description |
|
A key is pressed | |
|
A key is released | |
|
A mouse button is pressed | |
|
A mouse button is released | |
|
The mouse wheel is scrolled | |
|
The mouse has moved | |
|
A mouse button is double clicked | |
|
The graphics window is initialized | |
|
The program is exiting | |
|
A timer has expired | |
|
A GUI object has changed state | |
|
A GUI slider has been dragged | |
|
A key was pressed in a GUI textbox | |
|
A GUI droplist selection has changed | |
|
A hotspot has been triggered | |
|
The viewpoint has collided into an object | |
|
Called every frame | |
|
Received a network message | |
|
Graphics window has been resized | |
|
Avatar animation has completed | |
|
A frame has rendered to the display | |
|
Two physics objects have collided | |
|
Two physics objects have finished colliding | |
|
An action has started executing | |
|
An action has finished executing | |
|
An action pool has run out of actions | |
|
Special events for audio/video objects | |
|
Sensor button has been pressed | |
|
Sensor button has been released |
This event is generated when a key is pressed. If the key is held down, multiple keydown events will be generated. The viz.getInputTime() command can be used with key down events.
key
The character or code of the key that was pressed. Click here for a list of keyboard codes.
def onKeyDown(key):
if
key == ' ':
print 'Space key pressed'
elif
key == viz.KEY_UP:
print 'Up arrow pressed'
viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
This event is generated when a key is released. The viz.getInputTime() command can be used with key up events.
key
The character or code of the key that was released. Click here for a list of keyboard codes.
def onKeyUp(key):
if
key == 'q':
print 'q key released'
elif
key == viz.KEY_HOME:
print 'Home key released'
viz.callback(viz.KEYUP_EVENT,onKeyUp)
This event is generated when a mouse button is pressed. The viz.getInputTime() command can be used with mouse down events.
button
The mouse button that was pressed. Can be one of the following mouse button codes:
|
Mouse buttons |
|
viz.MOUSEBUTTON_LEFT |
|
viz.MOUSEBUTTON_MIDDLE |
|
viz.MOUSEBUTTON_RIGHT |
def onMouseDown(button):
if
button == viz.MOUSEBUTTON_LEFT:
print 'Left button pressed'
viz.callback(viz.MOUSEDOWN_EVENT,onMouseDown)
This event is generated when a mouse button is released. The viz.getInputTime() command can be used with mouse up events.
button
The mouse button that was released. Can be one of the following mouse button codes:
|
Mouse buttons |
|
viz.MOUSEBUTTON_LEFT |
|
viz.MOUSEBUTTON_MIDDLE |
|
viz.MOUSEBUTTON_RIGHT |
def onMouseUp(button):
if
button == viz.MOUSEBUTTON_RIGHT:
print 'Right button released'
viz.callback(viz.MOUSEUP_EVENT,onMouseUp)
This event is generated when a mouse wheel is scrolled. The viz.getInputTime() command can be used with mouse wheel events.
dir
The direction the mouse wheel was scrolled. A value greater than zero indicates the mouse wheel was scrolled upwards. A value less than zero indicates the mouse wheel was scrolled downwards.
def onMouseWheel(dir):
if
dir > 0:
print 'Mouse wheel scrolled up'
else:
print 'Mouse wheel scrolled down'
viz.callback(viz.MOUSEWHEEL_EVENT,onMouseWheel)
This event is generated when the mouse is moved. The viz.getInputTime() command can be used with mouse move events. The event provides the absolute position of the mouse normalized to the graphics window and the relative movement of the mouse. The absolute position is not updated when the mouse leaves the graphics window, however the event will still be generated in order to provide the relative movement.
This event provides a single event structure e with the following attributes:
e.x
The absolute X position of the mouse relative to the left side of the graphics window. The value is in the range [0,1].
e.y
The absolute Y position of the mouse relative to the bottom of the graphics window. The value is in the range [0,1].
e.dx
The relative movement of the mouse in the X direction. The value is in raw mouse units. Negative values indicate the mouse was moved to the left. Positive values indicate the mouse was moved to the right.
e.dy
The relative movement of the mouse in the Y direction. The value is in raw mouse units. Negative values indicate the mouse was moved downward. Positive values indicate the mouse was moved upward.
def onMouseMove(e):
print
'Relative movement:',e.dx,e.dy
viz.callback(viz.MOUSE_MOVE_EVENT,onMouseMove)
This event is generated when a mouse button is double clicked. The viz.getInputTime() command can be used with double click events.
This event provides a single event structure e with the following attributes:
e.button
The mouse button that was double clicked. Can be one of the following mouse button codes:
|
Mouse buttons |
|
viz.MOUSEBUTTON_LEFT |
|
viz.MOUSEBUTTON_MIDDLE |
|
viz.MOUSEBUTTON_RIGHT |
def onDoubleClick(e):
if
e.button == viz.MOUSEBUTTON_LEFT:
print 'Left button double clicked'
viz.callback(viz.DOUBLE_CLICK_EVENT,onDoubleClick)
This event is generated when the graphics window is initialized (i.e. after viz.go() is called).
None
This event is generated when the simulation exits.
None
def onExit():
viz.message('goodbye')
viz.callback(viz.EXIT_EVENT,onExit)
This event is generated when a timer expires. The viz.elapsed() command can be used with timer events.
num
The timer number that expired.
def onTimer(num):
print
'Timer id',num,'expired'
viz.callback(viz.TIMER_EVENT,onTimer)
viz.starttimer(0,1,viz.FOREVER)
This event is generated when a GUI button has changed state. This event is also used by other GUI objects to signal state changes.
obj
The node3d object that has changed state.
state
The new state of the object. Can be one of the following values:
|
Button States |
|
|
viz.DOWN |
Signals one of the following:
|
|
viz.UP |
Signals one of the following:
|
checkbox = viz.addCheckbox(pos=(0.5,0.5,0))
def onButton(obj,state):
if
obj == checkbox:
if state == viz.DOWN:
print 'Checked'
else:
print 'Unchecked'
viz.callback(viz.BUTTON_EVENT,onButton)
This event is generated when the value of GUI slider or progress bar has been changed by the user. This event is NOT generated if the value is manually modified through code.
obj
The slider or progress bar object that has changed value.
pos
The new value of the slider. The value is in the range [0,1].
slider = viz.addSlider(pos=(0.5,0.5,0))
def onSlider(obj,pos):
if
obj == slider:
print 'Slider value',pos
viz.callback(viz.SLIDER_EVENT,onSlider)
This event is generated when a key has been pressed inside a GUI textbox. This event will be generated even if the actual text was not modified.
This event provides a single event structure e with the following attributes:
e.object
The textbox object generating the event.
e.oldText
The textbox value before the key was pressed.
e.newText
The textbox value after the key was pressed.
e.key
The character or code of the key that was pressed. Click here for a list of keyboard codes.
textbox = viz.addTextbox(pos=(0.5,0.5,0))
def onTextbox(e):
if
e.object == textbox:
print 'New text:',e.newText
viz.callback(viz.TEXTBOX_EVENT,onTextbox)
This event is generated when the selected item of a GUI droplist has changed.
This event provides a single event structure e with the following attributes:
e.object
The droplist object generating the event.
e.oldSel
The zero-based index of the previously selected item.
e.newSel
The zero-based index of the newly selected item.
droplist = viz.addDropList(pos=(0.5,0.5,0))
droplist.addItems(['item 1','item 2','item 3'])
def onList(e):
if
e.object == droplist:
print 'Droplist selection',e.newSel
viz.callback(viz.LIST_EVENT,onList)
This event is generated when a hotspot has been triggered.
id
The hotspot ID that has been triggered.
x
X position of viewpoint that triggered the hotspot.
y
Y position of viewpoint that triggered the hotspot.
z
Z position of viewpoint that triggered the hotspot.
def onHotspot(id,x,y,z):
print
'Hotspot',id,'triggered'
viz.callback(viz.HOTSPOT_EVENT,onHotspot)
viz.starthotspot(1,viz.CIRCLE_HOTSPOT_IN,0,0,1)
This event is generated when the viewpoint collides with an object. Viewpoint collision must be enabled for the event to be generated.
info
An intersect info object containing details of the collision. The object has the following attributes:
|
Attribute name |
Description |
|
object |
node3d object the viewpoint collided with |
|
point |
[x,y,z] position of collision |
|
normal |
[x,y,z] normal vector of collision point |
|
name |
Name of sub-node involved in collision |
def onCollision(info):
print
'Collided with object',info.object
viz.callback(viz.COLLISION_EVENT, onCollision)
This event is generated during the update cycle of every frame. The viz.elapsed() command can be used with update events.
This event provides a single event structure e with the following attributes:
e.elapsed
The elapsed time (in seconds) since the last frame. Same as the value returned by viz.getFrameElapsed()
e.frame
The frame number of the new frame. Same as the value returned by viz.getFrameNumber()
e.time
The start time of the new frame (in seconds) relative to the start of the main graphics loop. Same as the value returned by viz.getFrameTime()
def onUpdate(e):
print
'Updating frame',e.frame
viz.callback(viz.UPDATE_EVENT,onUpdate)
This event is generated when Vizard receives a network message from another Vizard client.
This event provides a single event structure e with the following attributes:
e.sender
The name of the computer that sent the message.
e.address
The IP address of the computer that sent the message.
e.port
The port number the message was received on.
e.data
A tuple containing the positional data.
e.<keyword>
The value of the specified keyword argument.
network = viz.addNetwork('localhost')
def onKeyDown(key):
if
key == ' ':
network.send(1,2,3,foo=4,bar=5)
viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
def onNetwork(e):
print
'Positional data:',e.data
print
e.foo,e.bar
viz.callback(viz.NETWORK_EVENT,onNetwork)
This event is generated when the Vizard graphics window is resized. This event will be triggered before the first frame is rendered and when the window is resized manually through code.
This event provides a single event structure e with the following attributes:
e.width
The new width of the graphics window.
e.height
The new height of the graphics window.
def onWindowSize(e):
print
'New size',e.width,e.height
viz.callback(viz.WINDOW_SIZE_EVENT,onWindowSize)
This event is generated when an avatar finishes executing an animation.
This event provides a single event structure e with the following attributes:
e.object
The avatar object generating the event.
e.animation
The animation number that has finished executing.
e.userTriggered
Indicates whether the user triggered the end of the animation manually through code (i.e. the <node3d:avatar>.stopAction() command) . Can be either True or False.
male = viz.add('vcc_male.cfg',pos=(0,0,5),euler=(180,0,0))
male.execute(2)
def onAnimationEnd(e):
if
e.object == male:
print 'Animation ended',e.animation
viz.callback(viz.ANIMATION_END_EVENT,onAnimationEnd)
This event is generated when a frame has finished being rendered and has been displayed on screen. When a user registers a callback for this event, Vizard will block at the end of the frame until the frame buffer has been copied to the screen.
This event provides a single event structure e with the following attributes:
e.time
The time of the frame display. The time value is relative to the viz.tick() command.
def onPostSwap(e):
print
'Frame display time',e.time
viz.callback(viz.POST_SWAP_EVENT,onPostSwap)
This event is generated when two physics objects collide. To be notified of physics collisions you need to first enable the viz.COLLIDE_NOTIFY flag on the node. If two objects that have collision notification enabled collide, two separate events will be generated.
This event provides a single event structure e with the following attributes:
e.obj1
The first object in the collision. This is the object which has collision notification enabled.
e.obj2
The second object in the collision.
e.pos
The [x,y,z] position of the collision point.
e.normal
The [x,y,z] normal vector of the collision point.
def onCollideBegin(e):
print
'Objects collided',e.obj1,e.obj2
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)
This event is generated when two physics objects finish colliding. To be notified of physics collisions you need to first enable the viz.COLLIDE_NOTIFY flag on the node. If two objects that have collision notification enabled collide, two separate events will be generated.
This event provides a single event structure e with the following attributes:
e.obj1
The first object in the collision. This is the object which has collision notification enabled.
e.obj2
The second object in the collision.
def onCollideEnd(e):
print
'Finished colliding',e.obj1,e.obj2
viz.callback(viz.COLLIDE_END_EVENT,onCollideEnd)
This event is generated when an action has started on an object.
This event provides a single event structure e with the following attributes:
e.object
The object generating the event.
e.action
The action object that has started executing. An instance of viz.ActionData.
e.pool
The pool number the action has started on.
e.instance
The viz.ActionClass instance of the action object.
spin = vizact.spin(0,1,0,90,1)
ball = viz.add('ball.wrl',pos=(0,1.8,2))
ball.addAction(vizact.waittime(1))
ball.addAction(spin)
def onActionBegin(e):
if
e.object is ball and e.action is spin:
print 'Ball started spinning'
viz.callback(viz.ACTION_BEGIN_EVENT,onActionBegin)
This event is generated when an action is completed on an object. The event will occur even if the action is manually completed by the user through code (i.e. the <node3d>.endAction() command).
This event provides a single event structure e with the following attributes:
e.object
The object generating the event.
e.action
The action object that has finished completing. An instance of viz.ActionData.
e.pool
The pool number the action has completed on.
e.instance
The viz.ActionClass instance of the action object.
spin = vizact.spin(0,1,0,90,1)
ball = viz.add('ball.wrl',pos=(0,1.8,2))
ball.runAction(spin)
def onActionEnd(e):
if
e.object is ball and e.action is spin:
print 'Ball finished spinning'
viz.callback(viz.ACTION_END_EVENT,onActionEnd)
This event is generated when an action pool runs out of actions to execute.
This event provides a single event structure e with the following attributes:
e.object
The object generating the event.
e.pool
The pool number that has run out of actions.
ball = viz.add('ball.wrl',pos=(0,1.8,2))
ball.addAction(vizact.spin(0,1,0,90,1))
def onActionEmpty(e):
if
e.object is ball:
print 'No more actions for ball :('
viz.callback(viz.ACTION_EMPTY_EVENT,onActionEmpty)
This event is generated when a media object enters certain states.
This event provides a single event structure e with the following attributes:
e.object
The media object generating the event.
e.event
The event that occurred on the media object. Can be one of the following values:
|
Event code |
Description |
|
viz.MEDIA_END |
The media object has reached the end |
sound = viz.add('boing!.wav')
sound.play()
def onMedia(e):
if
e.object is sound and e.event == viz.MEDIA_END:
print 'sound ended'
viz.callback(viz.MEDIA_EVENT,onMedia)
This event is generated when a sensor button is pressed.
This event provides a single event structure e with the following attributes:
e.object
The extension sensor object generating the event.
e.button
ID of the sensor button that was pressed.
#Create vrpn extension
vrpn = viz.add('vrpn7.dle')
#Add button object at specified address
button = vrpn.addButton('Joystick0@localhost')
#Register a callback for button down event
def onButtonDown(e):
if
e.object is button:
print 'button',e.button,'down'
viz.callback(viz.SENSOR_DOWN_EVENT,onButtonDown)
This event is generated when a sensor button is released.
This event provides a single event structure e with the following attributes:
e.object
The extension sensor object generating the event.
e.button
ID of the sensor button that was released.
#Create vrpn extension
vrpn = viz.add('vrpn7.dle')
#Add button object at specified address
button = vrpn.addButton('Joystick0@localhost')
#Register a callback for button up event
def onButtonUp(e):
if
e.object is button:
print 'button',e.button,'up'
viz.callback(viz.SENSOR_UP_EVENT,onButtonUp)