Vizard 7 » Tutorials & Examples » Example scripts » Avatars » Bones
7.6

Bones

\examples\avatar\linkbones.py

This script demonstrates how to link objects to an avatar.

"""
This script demonstrates how to link objects to an avatar.
In this example a hat is placed on the avatars head.
Also, a cellphone is placed in the right hand.
Press the 'w' key to make the avatar use the phone.
"""
import viz
import vizinfo
import vizact

viz.setMultiSample(4)
viz.fov(60)
viz.go()

vizinfo.InfoPanel()

#Add a sky.
viz.addChild('sky_day.osgb')

#Add a ground plane
ground = viz.addChild('ground_stone.osgb')

#Add the avatar
avatar = viz.addAvatar('vcc_male.cfg')

#Have the avatar walk in a circle in front of the viewer
avatar.addAction(vizact.spin(0,1,0,30))
avatar.setCenter([2,0,0])
avatar.setPosition([-2,0,6])
avatar.state(2)

#Add the hat model
hat = viz.addChild('tophat.3ds')

#Get the head bone of the avatar
head = avatar.getBone('Bip01 Head')

#Link the hat to the head
HatLink = viz.link(head,hat)

#Tweek the hat link so it fits snuggly on the head
HatLink.preTrans( [0,0.2,-0.0] )
HatLink.preEuler( [0,-10,0] )

#Add the cellphone model
cell = viz.addChild('phone.3ds')

#Get the right hand bone of the avatar
hand = avatar.getBone('Bip01 R Hand')

#Link the cellphone to the hand
CellLink = viz.link(hand,cell)

#Tweek the cellphone link so it fits snuggly in the hand
CellLink.preTrans( [0.06,-0.08,0.08] )
CellLink.preEuler( [0,0,180] )

#Make the avatar use the cellphone when the 'w' key is pressed
vizact.onkeydown('w',avatar.execute,15)