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

Tutorial: vizconnect Tools

In this section we'll add a grabber tool to pick up objects in the environment. Depending on the tool, setup is a three or four step process:

  1. Add an input device.
  2. Add the tool and map input signals to trigger the tool's action.
  3. Link the tool to an avatar or other model to control it's movement.
  4. Define the list of objects that the tools is allowed to manipulate through the script. (Required for some tools)

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

Add an Input Device

Now add a mouse buttons input to use with the grabber. From the Inputs tab, click Add a New Input, select the Mouse Buttons option, and click Apply & Exit.

Add a Tool

From the Tools tab, click Add a New Tool, and select the Grabber option. The using physics parameter should only be checked if physics is enabled in the script that uses the grabber. Our script will not use physics so uncheck the box and click Apply & Exit. The grabber is automatically applied to the avatar's r_hand slot:

Open the Mappings dialog box to view or change how input signals are mapped to a tool's actions. Map the left mouse button to the grabAndHold action:

Use the Tool

The last thing we need to do before we can use the tool is to define some objects that it can manipulate. This part is done through the script that imports the configuration. Create a new Vizard script and add the code below to set the scene. Save the script in your avatars and tools tutorial folder with the vizconnect_config.py file.

import viz
import vizconnect
import vizshape

viz.setMultiSample(4)
vizconnect.go('vizconnect_config.py')

# Add a background environment
dojo = viz.addChild('dojo.osgb')

#Add shapes
pyramid = vizshape.addPyramid(base=(0.2,0.2),height=0.2,pos=[-0.5,1.7,1],alpha=0.7)
torus = vizshape.addTorus(radius=0.1,tubeRadius=0.015,axis=vizshape.AXIS_X, pos=[0,1.7,1])
box = vizshape.addCube(size=0.1, pos=[0.5,1.7,1],alpha=0.8)
pyramid.texture(viz.addTexture('images/tile_slate.jpg'))
torus.texture(viz.addTexture('images/tile_wood.jpg'))

#Animate shapes
pyramid.addAction(vizact.spin(0,-1,0,15))
torus.addAction(vizact.spin(0,1,0,15))
box.addAction(vizact.spin(1,1,1,15))

shapes = [pyramid,torus,box]

Next, get a handle to the grabber tool and pass it a list of the objects that it grab:

# Code to get the grabber tool by name and supply the list of items which can be grabbed
grabber = vizconnect.getRawTool('grabber')
grabber.setItems(shapes)

Run the script and move the hand over to one of the shapes. When the grabber tool intersects an object in its items list it will highlight the object. Hold the left mouse button to grab and move an object.  

Avatar and Tool Introduction

Avatars

Tools

Tool Events

Avatar Gestures

Avatar Head and Hands