Building Virtual Environments
Arts Col 762, 5 credits
TR 12:30-2:18
 

Professor Alan Price
aprice@accad.osu.edu
office hours: T&W 2:30-3:30
by appointment



The Anatomy of a Script in Virtools

You can add a script to any object.
To do this, select the object in the level manager and click the "create script" button ("A" in the illustration).

Most times it makes sense to create the script on the object you are manipulating with that particular script (see "C") - but the script can be on one object and still control any other objects!

You can also create scripts that are NOT attached to any objects - at the root "Level" of the scene. Just select "Level" in the level manager and create a script there (see "B").


In the Schematic window, the left side of every script is the start point. When the scene first runs (or otherwise when the script is first activated) everything begins from this point.


The process flow of a script is determined by the black line links between Building Blocks (BBs).

The numbers (0 or 1 in this image) represent the frame delay (link delay) between BBs. In most cases you can let Virtools take care of the delays automatically, as a minimum one-frame delay is absolutely required on the return point of a loop.

The blue dotted lines are parameter links. This connects the parameter output calculated by one BB and can send it as an input parameter to another BB.


In any open space in the script area, you can access this menu with the right mouse button. This menu allows you to add the most common components of a script:

  • Building Blocks
  • Local Parameters
  • <This> Parameters
  • Parameter Operations


The following is information on each of the above:


BUILDING BLOCKS (BBs)
These are the heart of the script. Each BB has a unique process. There are over 300, placed in categories. See the virtools online docs, "Behavior Building Blocks: Categories" for review.

Double-click a BB to edit its parameters.

On a BB, use the right-mouse to see other options:

  • HTML documentation for the BB.
  • Note some BBs have an "S" in the bottom left. This means they have settings you can alter.
  • Some have a "V" in the corner. These you can vary the types of parameters they input or output or add additional outputs, inputs, parameter ins or outs, etc. (The "Random" BB is an example, in which you can randomly generate floats, vectors, angles, whatever you choose.)
  • T - "Add Target Parameter" is important!
    By default, most BBs do their operation on the object to which the script is attached. If you want the BB to act upon some other object, add the Target Parameter which will allow you to affect the selected object.



Some BBs need to be looped to operate. The "Move To" BB is one example. In the parameters you set the duration of the movement to the destination. The looping duration is externalized, which allows you to include other BBs into that loop if desired! Otherwise, when the BB is done looping, it will only then trigger the output (top right) and continue to the next BB in the script.

(If you want something else to happen and not wait for the "Move To" to finish, just connect a link from the "Random" BB to that other BB! Virtools can run massive amounts of scripts and BBs in parallel!

LOCAL PARAMETERS

You can create parameters of any type that virtools supports (again, see the online docs for a huge list). Some of which are vectors, euler angles, floats, 3DEntities (in the scene), colors, etc.
The parameters attached to a BB are exactly the same.
Creating standalone (local) parameters are just another way of maintaining a variable.


<THIS> PARAMETER

A desirable variable in many scripting languages.
In other words, it is saying "whatever this script is attached to, refer to that object".

Using a "This" parameter makes a script more "portable". You can copy the script to other objects more easily.



PARAMETER OPERATORS
These take one or two parameters and operate on them to give a result. Think of them as a calculator, a converter, or a way to grab the current value of an object in the scenes:

  • As a calculator: Add, subtract, multiply, etc. with floats, vectors, etc.
  • As a converter: convert degrees to radians, floats to integers, floats to strings, etc.
  • To get values (see the image example): Get Position, Get Euler Angles, Get Mesh, Get Texture, etc.

The number of combinations available in Parameter Operators is immense. See the online docs under "Parameters and Attributes: Parameter Operations".



One helpful feature of the Parameter Operator dialog are the little "padlock" icons. If you "lock" the operation, for example, the inputs and outputs will only list parameters upon which that operation is valid. If you lock the Output selection, only operations that are valid will be in the list, etc.

Consider: A parameter operator that gets a value of an object in the scene, such as "Get Euler Angles" or "Get Position", will always give the current value at the moment you call it. If you want to get the value and "store" it in a variable (so that you can compare it with a new value later for instance), you can used the "Identity" BB to set the value - since "Identity" is part of the linked sequence, it gets the value on that frame and leaves it at that value wherever it is sent to other BBs down the line.

And guess what? There is a BB called "Op" that is the exact same thing as a Parameter Operator (edit its settings and it looks the same as the dialog above). This is the same idea, as it gets the value at only the current frame when the BB is activated.


This overview covered local parameters, parameter operators, "this" parameter, and a little about Behavior Blocks. There are so many BBs and so many uses for them that it takes time to get acquanted with what's possible.
You can "browse" through the list of BBs to get an idea of what's available, but don't expect that to show you how to develop an idea or solve a problem.
The best approach is to develop your idea, lay out the problems that need to be solved, then study the particular BBs that may provide the solution. Experiment, and start with small steps. Simple loops can grow into complex decision trees.