Vizard 7 » Tutorials & Examples » Getting your feet wet » Adding Avatars
7.6

Tutorial: Adding Avatars

For this section we'll add some human avatars in conversation and a flock of pigeons. Avatars are a special subset of 3D models that can change their shape with animations. The avatar functionality in Vizard is very extensive so in this example we're going to stick with the basics. First, we'll add two sample avatars that are included with Vizard. To load an avatar file use the viz.addAvatar command. Run the following script showing two avatars to the right of the fountain:

import viz

#Enable full screen anti-aliasing (FSAA) to smooth edges
viz.setMultiSample(4)

viz.go()

#Increase the Field of View
viz.MainWindow.fov(60)

piazza = viz.addChild('piazza.osgb')

male = viz.addAvatar('vcc_male.cfg')
male.setPosition([4.5, 0, 7])
male.setEuler([0,0,0])

female = viz.addAvatar('vcc_female.cfg')
female.setPosition([4.5,0,9])
female.setEuler([180,0,0])

It only takes one line of code to apply a built-in animation to an avatar. Add the following code to set the avatars' talking states:

#Set the male and female to the talking state
male.state(14)
female.state(14)

 

Vizard also includes a pigeon avatar. With a for loop we'll create a flock of birds at random positions in front of the fountain. Python's random module has a number of commands that are useful for selecting random values. Here we'll use random.randint to choose the positions. Add the following code to the end of your script and then run it:

import random

pigeons = []
for i in range(10):

    #Generate random values for position and orientation
    x = random.randint(-4,3)
    z = random.randint(4,8)
    yaw = random.randint(0,360)

    #Load a pigeon
    pigeon = viz.addAvatar('pigeon.cfg')

    #Set position, orientation, and state
    pigeon.setPosition([x,0,z])
    pigeon.setEuler([yaw,0,0])
    pigeon.state(1)

    #Append the pigeon to a list of pigeons
    pigeons.append(pigeon)

Launch into a new world

Creating a new Script

Setting the Scene

Moving the Viewpoint

Manipulating 3D Models

Animating 3D Models

Timer Events

Adding Avatars

Inserting User Interaction