Vizard 8 » Reference » Animation » Paths » Animation path events
8.0

Animation path events

Animation paths support adding multiple event triggers along the path. These event triggers can be used to determine when the path reaches a certain point. A full sample script can be found at \examples\animationPaths\animationPathEvents.py.

Adding event triggers

Event triggers can be placed at any time, distance, control point, or at the end of the path. You must specify a name when creating an event trigger. The name will be provided when the event is triggered, allowing you to distinguish between multiple event triggers. The following animation path commands can be used to add event triggers:

Method Description
<animationpath>.addEventAtEnd(name) Add an event to the path which will be triggered when the path reaches the end of one full loop.
<animationpath>.addEventAtTime(name, time) Add an event to the path which will be triggered when the path reaches the specified time (in seconds) from the start.
<animationpath>.addEventAtControlPoint(name, index) Add an event to the path which will be triggered when the path reaches the specified control point index.
<animationpath>.addEventAtDistance(name, distance) Add an event to the path which will be triggered when the path reaches the specified distance from the start.

The following example code demonstrates how to add event triggers:

# Add event when path reaches the end
path.addEventAtEnd('end')

# Add event when path reaches 2 seconds from the start
path.addEventAtTime('time=2', 2.0)

# Add event when path reaches 7 meters from the start
path.addEventAtDistance('distance=7', 7.0)

# Add event when path reaches control point index 1
path.addEventAtControlPoint('point=1', 1)

Event triggers can be removed by name using the <animationpath>.removeEvent command, or all event triggers can be removed using the <animationpath>.clearEvents command.

Handling event triggers

When the animation path reaches the location of an event trigger during an update, it will trigger a viz.PATH_EVENT. The event will provide a single event structure containing the following attributes:

Name Description
e.object The animation path object generating the event
e.name The user specified name of the event trigger
e.time

The time within the path the event was scheduled to trigger

The following sample demonstrates how to handle a viz.PATH_EVENT:

def onPathEvent(e): 
    print(e.object,'triggered event',e.name)

viz.callback(viz.PATH_EVENT, onPathEvent)

The <vizact>.onPathEvent command can also be used to handle events from a specified path and name:

path.addEventAtEnd('end')

def onPathEnd():
    print('Path reached end')
    
vizact.onPathEvent(path, 'end', onPathEnd)

The <viztask>.waitPathEvent command can be used within a task to wait for an event from a specified path and name:

import  viztask

path = viz.addAnimationPath()
# ... Add control points
path.addEventAtEnd('end')

def PathPlayTask():

    path.play()

    yield viztask.waitPathEvent(path, 'end')

    print('Path finished playing')

viztask.schedule( PathPlayTask() )

See also

In this section:

Animation path basics

Animation path modes

Animation path command table

Other sections:

Action basics

Linking basics

Physics basics

Viewpoint basics

Example scripts:

Animation paths