Vizard 6 » Reference » Flow control » Actions » Action basics

Actions Basics

Actions are an easy way to animate 3D geometry nodes and views. They're also handy in setting up a variety of events (timing, input, etc.). Actions can do things that would otherwise have to be done frame by frame in a callback function.  There are many built-in Vizard actions.  Some examples:


vizact.moveTo( [xyz], speed ) : animates a node moving from its current position to the given point at the given speed. function, arguments ) : calls the given function and immediately finishes.


#Use a moveTo action to move a node to the point [0,0,25] at 2 meters per second
flyToPoint = vizact.moveTo([0,0,25],speed=2)


Each node and view object has a queue of actions.  For an action to operate on a node, you must add it to the node's action queue.  When one action is finished, the next one in the queue starts.


The vizact library contains many commonly used actions.  Actions can be animations (translating, rotating, scaling, fading, morphing …), synchronizations (waiting for key press, elapsed time, signal …), or simply a single command (playing sound, applying texture, changing appearance, etc.).  You can find a list of actions in the vizact module here.

Adding Actions

Here is a very simple example of creating an action to spin a node forever:


#Use a spin action to rotate a node
spinForever = vizact.spin(0,1,0, 90, viz.FOREVER)


The variable spinForever contains the ActionData object that has the kind of spin we want the node to perform. This action can now be added to any object, any number of times. When you add an action to an object it will be placed at the end of the objects queue or waiting list. Once the object is finished performing an action it will begin the next action in the list. The action controller handles all the details of updating an action, checking when it is finished, and moving on to the next action.  The following code makes the node spin to the given orientation, then moves the node after the spinning is complete.  


spinToYaw90 = vizact.spinTo(euler=[90,0,0], speed=50)
moveForward = vizact.move([0,0,4], 5)
#Spin then move
node.addAction( spinToYaw90 )
node.addAction( moveForward )


The ActionData object returned by vizact functions, such as <vizact>.moveTo(), contains instructions that modify any 3D object.  When an ActionData object is added to a node, the node places an instance/copy, of the ActionData in its own queue/pool.   Thus, ActionData objects are reusable and can be applied to many nodes.  

Managing Currently Executing Actions

You can tell a node to stop its current action, clear its queue of actions, or both. The following command will force an object to stop performing any actions and move on to the next action in the list:


<node3d>.endAction( pool = 0 ) : Kills the current action and executes next action in queue.

<node3d>.clearActionList( pool = 0 ) : Removes all actions in the queue.  Current action is unaffected.

<node3d>.clearActions( pool = 0 ) : Kills the current action and removes all actions in the queue

Parallel Actions

What if you wanted to perform two actions simultaneously? Let's say you wanted an object to spin while it was moving. If you add the spin action then the move action, the object will move only after it has finished spinning.


To perform actions at the same time, each node has multiple queue/waiting lists.  Vizard calls these pools and each pool executes its actions independently of the others.  The following code makes an object do the move and spin simultaneously.


spinToYaw90 = vizact.spinTo(euler=[90,0,0], speed=50)
moveForward = vizact.move([0,0,4], 5)
#Spin and move
node.addAction( spinToYaw90, 0 )
node.addAction( moveForward, 1 )


The above code sample adds the spin action to pool 0 and the move action to pool 1. If you do not specify a pool when adding actions, it will default to pool 0.  The action controller has an infinite number of action pools.  


You can also use the vizact.parallel( [action1, action2, ...] ) action to have multiple actions execute at once in a single action pool.  

Action Interpolators

Many of the animation-based actions in the vizact module support non-linear interpolations. For example, the vizact.easeInOut interpolator can be used to slowly ease in and out of the animation.


# Create action that eases in and out of the movement
moveAction = vizact.moveTo([0,0,5], time=2.0, interpolate=vizact.easeInOut)


The following table describes all the available interpolators in the vizact module:





Linear interpolation. Animation will occur at a constant speed.


Cubic interpolation. The default control points are 0.1 and 0.9, which causes a slight easing in and out of the animation. You can specify different control points by creating an instance and passing the values into the constructor (e.g. vizact.cubic(0.1,1.1))




An alias for quadratic easing.




An alias for quintic easing.




Use quadratic (x^2) easing when going in and/or out of animation.




Use cubic (x^3) easing when going in and/or out of animation.




Use quartic (x^4) easing when going in and/or out of animation.




Use quintic (x^5) easing when going in and/or out of animation.




Use sinusoidal (sin(x)) easing when going in and/or out of animation.




Use exponential (2^x) easing when going in and/or out of animation.




Use circular (sqrt(x)) easing when going in and/or out of animation.




Back up in opposite direction when going in and/or out of animation.




Bounce when going in and/or out of animation.


Vizard comes with a script that allows you to easily view the effect of the various easing interpolators included with vizact. The script is located at \examples\actions\

Turning function calls into animated actions

Many Vizard functions can be turned into animated actions using vizact.mix in combination with one of the following commands:




This is best illustrated with an example. The viz.clearcolor function accepts a single RGB value and uses that to set the background color. Calling this function every frame with gradual changes to the RGB value would result in a background that fades from one color to another. With just a few lines of code we can implement this action using vizact.mix.


First, a mix object is created. A start value (viz.BLACK), end value (viz.WHITE), duration (5 seconds), and interpolation method are defined:


black_to_white = vizact.mix(viz.BLACK,viz.WHITE,time=5.0,interpolate=vizact.easeOutStrong)


Next, the viz.clearcolor function is called every frame from viztask.waitCall until the mix conditions are complete. The resulting animation is a background fade from black to white:


def colorTask():

    yield viztask.waitKeyDown(' ')
    yield viztask.waitCall(viz.clearcolor,black_to_white)
    print 'Color action complete'
viztask.schedule( colorTask() )

Creating your own actions

You can create your own actions with Python code. Vizard's built-in actions are all coded in the Python file which you can use as a starting point for your own actions.  This page describes how to create your own actions.  

See also

In this section:

Action synchronization and management


Dynamic parameters

Node commands as actions

Creating your own actions

Actions command table

Other sections:

Tutorial: Using actions

Task basics

Director basics

Timer basics

Animation path basics

Event Basics

Event Reference


Example scripts:


Event callbacks