Vizard 7 » Tutorials & Examples » Vizconnect » Avatars and Tools » Tutorial: Tool Events
7.7

Tutorial: vizconnect Tools Events

There are times when its necessary to know if a tool has been activated or deactivated and based on that perform some operation. Each tool has its own specific events that can be handled; for the grabber tool, there are grab and release events. The following code shows how to register callback functions for both events and determine which object is being grabbed:

Note: This section continues with the configuration and script used in the previous section.

scaleAction = vizact.sequence([vizact.sizeTo(size=[1.3,1.3,1.3],time=1),vizact.sizeTo(size=[1,1,1],time=1)], viz.FOREVER)
fadeAction = vizact.sequence([vizact.fadeTo([0.63,0.32,0.18],time=2),vizact.fadeTo(viz.WHITE,time=2)], viz.FOREVER)

def onGrab(e):
    if e.grabbed == torus:
        torus.runAction(fadeAction,pool=1)
    else:
        e.grabbed.runAction(scaleAction,pool=1)

def onRelease(e):
    e.released.endAction(pool=1)

from tools import grabber
viz.callback(grabber.GRAB_EVENT, onGrab)
viz.callback(grabber.RELEASE_EVENT, onRelease)

Run the script and pick up the different objects. A sequence of color fades is applied to the torus when it is grabbed while a sequence of scale actions is applied to the box and pyramid. When a release event occurs, the action added in the grab callback is removed.

Avatar and Tool Introduction

Avatars

Tools

Tool Events

Avatar Gestures

Avatar Head and Hands