Here you will find the code that accompanied the first edition, published in 1996, as well as a more update version published in 2008 of Computer Facial Animation.
Over the years there have been several derivations of the code. In some cases it has been used as a rendering and animation examplar for OpenGL in other cases it has been adapted to variety of interactive animation systems.The original work for the muscle model was created from the Siggraph paper: A Muscle Model for Three-Dimensional Facial Animation in 1987. This movie, generated in 1986, were the first examples demonstrating the technique.
The enduring nature of the code is its simplicity; the code is easy to understand and has been broken down into straightforward modules with as few “bells and whistles” as possible. For clarity, this webiste contains the orignal generic code as well as the most popular derivations for OpenGL. For more recent activity see the appendix additions for more details.
The code bases
The downloadable files 2 & 3, are derivations of the first generic code base 1. The later versions contain enriched OpenGL features specifically for Windows.
- The original code base first edition appendix1
- An executable and data file Open GLSimpleFaceData
- The code, data files and executable OpenGL SimpleFaceV1
This Appendix briefly outlines a program that constructs a face model from three input data files, articulates the face geometry with muscles, and displays the results. The underlying muscle model algorithms are described in Chapter 6 and represents the code used to generated some of the illustrations in this book. The code should be viewed as a basic boiler plate for muscle modeling with the distinct advantage that the muscles are not ‘hard-wired’ into a specific facial geometry. Therefore, with a little effort, it is possible to use your favorite facial geometry with this version of the muscle model.
This version of the code uses simple keyboard bindings to drive the face and was written in ‘C’ using OpenGL display commands. The data structures are more complex than necessary, however they do provide a certain amount of design flexiblity and scope for further development. The geometry is based on a discrete triangle representation documented in the header files. Once you have understood this simple geometry configuration it should be straight forward to convert your face data into this representation. As a final step, the muscle geometry file will have to be adapted to the face geometry you provide. This simply involves the specification of the head and tail of each muscle as a pair of 3-space vectors.
Zip file 1 is an executable ready to run (Try this from here) to provide some instant gratification for Windows users. The file contains the necessary datafiles to run the program. To find the runtime help, click focus on the display window and type “h”.
Zip file 2 contains code and data needed to construct the executable. Originally, the program was constructed in MSVC++ 5.0 sometime in the last century. So loading the source into the latest MS IDE might need some tweaking to get the code to compile, however this should be nothing too strenuous. This code attempts to be as close to the very original first edition code as possible (circa 1995). Module names and function definitions have been maintained for clarity. A few extra components have been added, in particular expression I/O so you can make your own expressions. In addition transparency has been added to observe the location of facial muscles.
The Data Files
The polygon index list provides indices into the three dimensional node list file which represents the facial geometry as a collection of triangular polygons to be displayed and rendered. In addition pre-determined indices are defined for the jaw and eyelid pointers so they can be opened and closed. There are four basic input files:
- faceline.dat — the face data file
- index.dat — the polygon index file
- muscle.dat — the muscle data file
- expression-macros.dat — six expression macro vectors
Both zip files contain version 1.0 of the data files listed above. The muscle data file contains a list of muscle descriptions in the form of a head and tail 3-space vector, two zones of influence, an angular zone, and a muscle bias factor. In this version there are eighteen paired muscle types: the zygomatic majors, depressor anguli oris, inner portion of the frontalis majors, mid portion of the frontalis majors, outer portion of the frontalis majors, levator labii superioris alaeque nasi, levator anguli oris, and the corrugators supercilli. These basic muscles are combined into a muscle expression macro to create a single facial expression.
The base source code comes in five modules: a face data reader, a face data structure, a display, and a muscle module. Some modules are vanilla C code so you can adapt it to your application, others are influenced by OpenGL, especially SimpleFace.c and display.c modules.
- head.h — face data stuctures
- memory.h — memory allocation
- fileio.c — face data I/O utilities to read ASCII text files
- display.c — display functionality, dependent on OpenGL
- SimpleFace.c — contains main and initialization proceedures
- makeface.c — face data initialization manipulation
- muscle.c — the muscle model algorithms
This zip file contains version 1.0 of the code modules listed above.
Simple keyboard bindings are used to control the face to avoid code overload. The principle controls are for individual muscle activation. For example, the c key will progressively increment the activation of the current muscle, while C progressively decrements the current muscle activation. To select another muscle the n key is used, which cycles through the muscle list. The full listing of the bindings are in the source code. The h key prints out all the key bindings.
Operating Systems and Architectures
A majority of the email I recieve concern operating systems and particular processors. Over the past decade many different port have been done, SGI, Win95, WNT, Vista, X Windows, SUN and MAC. As we complete the second edition of the book, I intend providing some “best-of-breed” pointers.
Suggestions and Improvements
If you have suggestions, or better still, make improvements to the code that you would be willing to share, please do send me mail. Alternatively, if you have images, generated from this source code, that you would like to share on the examples page let me know.
I would like to update this source with logical additions. However, this will depend on how many people provide me with feedback. So if you are downloading the code please send me a note at the same time!
If another book on this subject were to be written, what would you like to see included in the book?
Code download first edition appendix 2
The following is sketchy documentation for a simple interactive parameterized three-dimensional face model implemented in “C”. Input to the model consists of three data files and user keyboard commands. Output consists of face images in a GL screen window.
This version uses a very simple keyboard driven user interface. It should run on GL supported systems. The simple interface was used to avoid as much GL specific code as possible. This should make it relatively easy to port to your favorite system and your favorite user interface. The input data files consist of two three- dimensional vertex data files and one polygon topology file. The two vertex files describe the basic face and extreme position values for those points which are computed using interpolation. The program asks for the two vertex file names. The standard topology file name is assumed. The standard files used are:
- st1.pts the first vertex set
- st2.pts the second vertex set
- stt.top the face topology
- stface.c the code
- Zipfile of the files above
You are certainly free to construct and use your own data files. Brief study of the standard files will give you the required file formats. Warning: The face polygon topology, as specified in the topology file, is intimately related to the parameterized manipulation of the face. Changes in this topology will usually require corresponding changes in the “points” procedure of the program.
Hints: In the topology file, vertices specified with the following form “n.m” have the following meaning; n refers to the vertex number, m refers to the normal to be used for this instance. Multiple normals are used for vertices along creases. Also, the first value on each line is a surface attribute (primarily color) index for that polygon.
In the first vertices file, points not specified are part of the eyelid and are computed by the program. For vertices 184 through 221, the eyelid, the first value is a radius scale factor used to fit the eyelid to the eyeball. In the second vertices file, points not specified are at the same position as in the first vertices file.
Positions consist of X, Y, Z values in the face coordinate system – X forward, Y to the face’s left, Z up. The program first asks for the vertices data file names and reads in the desired data. It then prompts with a “>”. At this point it is expecting a command. Commands consist of single characters followed by “return.” The following commands are valid: “p” change a parameter value. The program asks for a parameter number and then the new parameter value. The valid parameters and their initial values are indicated in the source code. “d” display a new face image. “r” reads (prints) out a current parameter value. “q” exit. This program is a fairly primitive direct descendent of the original Utah face model. It and its associated data files should be viewed as a “starter kit” for parameterized facial modeling. You will undoubtedly find many ways to improve and enhance the model, its user interface, and its associated data files.