[SESI logo]

Prisms Development Toolkit Documentation

Side Effects Software Inc. 1997

Expression Functions

The .func file

Custom functions are stored in a file. Prisms is shipped with several examples of small, useful functions already written for you, and saved in a .func file. The default location of this file is

/ufs/prisms/support/funcs/sample.func

You can (and should) copy this file to another location, and create your own functions there. Let's say you copy the above file to
/usr/staff/bob/myfunctions.func

Then whenever you start a new action, type

exread /usr/staff/bob/myfunctions.func

in the textport, or use the SOURCE button at the bottom of the EXPR FUNC page in action. This will tell action where to find the expression functions. This information is stored in subsequent .bmot files, so it need not be entered again for saved .bmots.

To edit the custom function file, click on the Edit button in the Expression page; this opens the vi editor. To close, use the vi command ZZ. This reinterprets the functions, ready for use. You can edit the file outside of action, but then you will need to reload the file using the Source button or the exread command.

You can force action to always look elsewhere for the expression functions. To do this, go to your home directory, and create a directory called .prisms (if there isn't one already). In that directory, using a text editor, create or modify the file action.rc to contain the line:

exread /usr/staff/bob/myfunctions.func

You can do the same thing by modifying $HOME/.action/123.rc, but here you must place the exread... line before the line that reads
rcread $HOME/.prisms/action.rc

Syntax

The syntax is very C-like - statements end with a semi-colon, and blocks of code are enclosed in curly brackets. Variables do not need to be declared before use. For example:
 
simple(val)
{
    j = 0;
    for (i = 0; i < val; i++)
	j = j + i;
}
 
Because the language is interpreted, you may reference other functions before you define them. For example:
 
dothis(val)
{
    return(dothat(val)+val);
}

dothat(val)
{
    a = sqrt(val);
    return(a);
}
 

Scope

It is easiest to think of expression functions as macros that are interpreted during the execution of the SOP. This means that the function may reference any local or global variable which you could use in the SOP itself. For example, an expression function which was to be used within the point SOP (which is very common) can assume access to the local variables PT, NPT, TX, TY, etc. It can also assume access to all the global variables, eg NFRAMES, FPS, etc. An example:
 
center(x, y, z)
{
    dx = x - $CEX;
    dy = y - $CEY;
    dz = z - $CEZ;

    return(sqrt(dx*dx + dy*dy + dz*dz));
}
 
Then in the point SOP, the expression
$TY+center($TX, $TY, $TZ)
in the 'pos Y' field will work properly. Used in other SOPs, it may not, depending on whether or not $CEX etc are defined within that SOP.

All of the mathematical functions are available within the function, as the use of sqrt() shows above. In addition, the other functions, such as point(), may be used. For example, a restricted version of the point() function could be defined as:

 
pt(p)
{
    return(point(reference_obj, 1, p, TX));
}
 

Debugging

Basically, debugging is hard. There is no print statement, and syntax errors are caught at the file-loading stage, but not a lot of help is given to the animator in knowing what they are. One useful command, however, is print(), which returns the value of the expression within parentheses, as well as printing it out to the textport. For example:
 
$TY + print(center($TX, $TY, $TZ))
will print each value to the textport as it is calculated. It is not possible to use the print() function within an expression function.

Performance

Using expression functions allows better understanding of complex mathematical relationships, and better control of frequently used ideas. But it is not faster than the equivalent expression, and in many cases may actually be slower, since it is interpreted. Sometimes it is possible to use expression functions to prototype a concept, then turn to a custom SOP to get the required performance.
Tookit Overview
Expression Functions | User Functions | Custom SOPs
Prisms Internal Format | Programmer's Reference
Compiling SOPs | Using sopbuild | SOP Routine Reference
Dynamic SOPs | Prisms Types | Macros
Math Routines | Data Routines | Polygon Routines | Winged-edge Routines

Copyright © 1997 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7