Vizard 7 » Tutorials & Examples » Getting your feet wet » Manipulating 3D Models
7.6

Tutorial: Manipulating 3D Models

In a previous section we saw how to add and position a single plant model. Let's use the power of scripting to quickly fill the piazza with plants. Copy and replace your code with the following:

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)

viz.move([0,0,-8])

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

for x in [-3, -1, 1, 3]:
    for z in [4, 2, 0, -2, -4]:
        plant = viz.addChild('plant.osgb',cache=viz.CACHE_CLONE)
        plant.setPosition([x,0,z])

Run the script and you'll see with four lines of code you are able to create 20 plants and place them in exact locations. You can probably guess that the same four lines could just as easily create 600 plants. That's just a glimpse of the power of scripts.

We can specify an object's orientation with yaw, pitch and roll like we did for the viewpoint using the node3D.setEuler command. Add the line that's highlighted (make sure it's also indented as shown below) and run the script:

for x in [-3, -1, 1, 3]:
    for z in [4, 2, 0, -2, -4]:
        plant = viz.addChild('plant.osgb',cache=viz.CACHE_CLONE)
        plant.setPosition([x,0,z])
        plant.setEuler([0,0,20])

So far we've manipulated position and orientation, two aspects of an object's transform. The third aspect, scale, can be changed with the <node3D>.setScale command. This command takes 3 scale factors that are applied independently to each of the three dimensions. For example, the result of the following line would be a uniform scaling (same across all dimensions) and a plant that's 50% of it's original size:

        plant.setScale([0.5,0.5,0.5])

Add this line after the setEuler command line in the for loop (same indentation) to see the effect of scaling. Try experimenting with some different scale factors and non-uniform scaling.

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