Vizard 8 » Tutorials & Examples » Example scripts » 3D Models » Hierarchical
8.0

Hierarchial

\examples\hierarchicalNodes\hierarchical.py

This script demonstrates how to add objects to one another, creating a hierarchical chain.

"""
This script demonstrates how to add objects to one another,
creating a hierarchical chain
"""
import viz
import vizact
import math

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

import vizinfo
vizinfo.InfoPanel()

CYCLES_PER_SEC      = 1.0
AMPLITUDE           = 45.0

c1 = viz.addChild('cylinder.wrl')
c2 = viz.addChild('cylinder.wrl',parent=c1)
c3 = viz.addChild('cylinder.wrl',parent=c2)
j1 = viz.addChild('joint.wrl',parent=c3)
c4 = viz.addChild('cylinder.wrl',parent=j1)
t1 = viz.addText('help',parent=c4)

c2.setPosition([0, 0.5, 0])
c3.setPosition([0, 0.5, 0])
j1.setPosition([0, 0.5, 0])
c4.setPosition([0, 0.0, 0])

t1.setScale([.2,.2,.2])
t1.setPosition([0,.5,0])
t1.setAxisAngle([0,1,0, 180])

c3.setAxisAngle([1,0,0, 90])
j1.setAxisAngle([1,0,0, 90])

def AnimateNode():
    angle = math.sin(viz.tick() * CYCLES_PER_SEC * 2*math.pi) * AMPLITUDE
    c4.setAxisAngle([0,0,1, angle])
vizact.ontimer(0,AnimateNode)

viz.addChild('ground_grass.osgb')
viz.clearcolor(viz.SLATE)
viz.MainView.move([-1, -1, -3])