Vizard 7 » Tutorials & Examples » 3D models » Creating 3D models on-the-fly » Tutorial: Creating an on-the-fly object
7.6

Tutorial: On-the-fly objects

This tutorial will teach you how to create On-The-Fly (OTF) geometry and vizshape models. OTF objects are useful for dynamically creating simple geometry like lines, points, and squares. The vizshape library provides commands for building more complex shapes likes boxes, spheres, and pyramids.

 

In this example, we'll create a game where the user needs to navigate a maze and find hidden shapes. The viewpoint path will be drawn dynamically using lines strips in a bird's eye view of the maze.

This content is discussed in more detail in the reference section.

Creating an on-the-fly object

If you have trouble getting the code in this tutorial to work, you can find the complete example script onTheFly.py in the \tutorials\3Dmodels directory.

 

Add the following initial code to create the maze environment and a sub-window with a bird's eye view of the scene.

import viz
import vizact
import vizshape
import vizinfo

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

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

BirdEyeWindow = viz.addWindow()
BirdEyeWindow.fov(60)
BirdEyeWindow.visible(0,viz.SCREEN)
BirdEyeView = viz.addView()
BirdEyeWindow.setView(BirdEyeView)
BirdEyeView.setPosition([0,25,0])
BirdEyeView.setEuler([0,90,0])

Next, let's add an OTF line strip object. This will allow us to create a series of connected lines to represent the user's movement. In the code below, the first line starts the creation of the object and defines it's type. The third line ends it's creation and specifies that it will be drawn to the BirdsEyeWindow. OTF objects can be rendered to the screen, as it is here, and to the 3D world.

viz.startLayer(viz.LINE_STRIP)
viz.vertexColor(viz.YELLOW)
lines = viz.endLayer(parent=viz.ORTHO,scene=BirdEyeWindow)

Every OTF object includes the viz.startLayer and viz.endLayer commands. In between these commands various properties of the object are specified (e.g vertex position, color, size). In this case, the vertices are not created but their color is set. They will be added dynamically as the user moves through the maze in the next section.

Creating an on-the-fly object

Changing vertices on-the-fly

Adding shapes

Finding Shapes