Vizard 7 » Tutorials & Examples » 3D models » Creating 3D models on-the-fly » Tutorial: Changing vertices on-the-fly
7.7

Tutorial: Changing vertices on-the-fly

Since the object will be changing frequently the following line is added to notify Vizard of this and speed up rendering:

lines.dynamic()

Now, add the following function which draws a new vertex and updates the line strip when the user has changed position:

def UpdatePath():

    # Get main view position in bird eye window pixel coordinates
    x,y,z = BirdEyeWindow.worldToScreen(viz.MainView.getPosition(),mode=viz.WINDOW_PIXELS)

    # Get position of last line vertex
    lx,ly,lz = lines.getVertex(-1)

    # Add new vertex if current position is different from last position
    if x != lx or y != ly:
        lines.addVertex([x,y,0.0])

vizact.ontimer(0,UpdatePath)

Run the code and see how the viewpoint path is updated as you navigate through the maze.

Finally, add the following code so that each time the spacebar is pressed the viewpoint path will be cleared. The <node3d:onthefly>.clearVertices command will remove all the vertices of the lines object so that a new path can be drawn from that point on:

vizact.onkeydown(' ',lines.clearVertices)

Creating an on-the-fly object

Changing vertices on-the-fly

Adding shapes

Finding Shapes