Animating Fish

 

CSE 557 Final Project Report

by

Masaharu Kobashi and Noah Snavely

 

 

The goal of our project is to automatically produce realistic animations of a moving fish. As the recent film "Finding Nemo" has proved, animating fish is a lucrative business, and having automatic techniques to do this would reduce the labor associated with traditional animation. We took two fundamentally different approaches to this problem:

1) Attempt to create physically valid motion by simulating an aquatic environment and having the fish learn to move.
2) Create a set of rules that govern how the body of the fish moves then synthesize motion based on those rules.


I. Physically-based motion

A. Overview

This approach closely follows the work of Tu and Terzopoulos in [1]. The essential idea is to model a fish as a network of masses and springs, then attach muscle controllers to the model that will generate the forces necessary for locomotion in simulated water. Muscles are modeled as springs with variable rest lengths; by decreasing and increasing the rest length of a muscle, the muscle will contract and relax accordingly. The muscles of the fish lie along the the edges of the fish model, as shown in Figure 1. The figure also shows the structural springs that hold the body of the fish together. We will refer to this network of springs as the scaffolding of the fish; later, we will make the distinction between the scaffolding and the actual body of the fish.

Figure 1

Fish structure

B. Modeling

For creating 3D fish conveniently we built a fish builder with graphic user interface. It is created to serve our initial ambitious objective that we make an aqualium with variety of fish swimming in it, although we ended up to using it to show some basic mechanisms of fish due to the time constraint. It has the following functionalities and its output is read by our animator program which builds the specified fish and animates it. The fish builder is written in tcl/tk.

  • It can create both fish body and scaffolding around the fish.
  • 3D designing is done by using two views, the right side view and the vertical view from above. These two veiew can specify usual type of fish, since they are symmetric along the spine.
  • The correspondence between the two views can be visually recognizable by a button which invokes the function to color the corresponding vertices in the same color.
  • It has all basic editing fuctions for creating, modifying, and deleting vertices and edges for both fish and scaffolding.

C. Physical simulation

In order to move, an external force must act on the fish. This force is generated when the fish pushes against the water and the water pushes back. The force generated is opposite the normal to the body and proportional to the volume of the water displaced. As in [1], we approximate this force by triangulating the body of the fish and computing the force against each triangle as min{0, -A * (n.v)} * n, where A is the area of the triangle, n is its normal, and v is the velocity of the triangle (in general each point on the triangle has a different velocity, but rather than integrate over the triangle we simply take the velocity of the center of mass to be the velocity of every point; this is not necessarily the best scheme).

At first we used Euler's method to solve the differential equations governing the simulation state, but because the springs of the scaffolding are stiff, Euler's method diverges extremely quickly, even with small time steps (Movie 1 demonstrates this in a dramatic fashion). To avoid this problem we implemented a simple, stable implicit Euler integration scheme [2].

Movie 1

Movie 1

D. Muscle controllers

We use three muscle controllers to control the fish: a swim-forward controller, a left-turn controller, and a right-turn controller.

In order to swim forward, fish have been observed waggling their tail back and forth, i.e. alternately flexing and relaxing the tail muscles on opposite sides of the body out of phase with each other. However, other than using the observationg that the fish swims by moving its muscles in a periodic fashion, we do not explicitly instruct the muscles how to swim forward. Instead, we parameterize the muscle controls and create a swim-forward muscle controller by learning parameters that result in the desired motion. To parameterize the controller we modulate the rest length of each muscle with a sinusoid of variable amplitude, frequency, and phase. To learn a swim-forward controller, we evaluate a set of control parameters by running the simulation with those parameters for a given number of time steps, and giving a score based on how far the center of mass of the fish moves in the forward direction. We then find an optimum of this non-linear evaluation function using simulated annealing. There are practical limits to how fast a fish can move its muscles and the extent to which they contract, so we bound the search space; it turns out that even by using a sine wave with a small amplitude (on the order of hundredths of the length of the muscle itself) we can obtain results that look realistic. In fact, allowing amplitudes that are too high can cause the body of the fish to fold in on itself.

To find good controllers for left and right turns, we use the same technique, but optimize for change in orientation of the fish. Once we have computed parameters for each of the three muscle controllers, the fish can swim to any point by first orienting its body in the correct direction using the turn controllers then swimming forward. To switch between different controllers we simply transition between two sets of control parameters using linear interpolation.


II. Non-Physics based motion emulation

One way to simulate the motion of the fish is bypassing the emulation of the underlying physics and directly creating the motions by observing the regularities of the motion of real fish. Our fish is created by simulating the spine movement only. Once the spine motion is defined, the whole body of the fish can be easily created around the spine, since all the surface points of the body can be assumed to be at a fixed distance from a certain spine unit.

Figure 2

Fish structure

Most common type of fish has the three inflection points as indicated by the black arrows in the above diagram. Our graphical fish is designed in the following fashion:

  1. First we focus on the swinging motion of the central inflection point and design a function which generates the amount of swing perpendicular to the spine. We tested sinusoidal functions and simple linear functions.
  2. 3D designing is done by using two views, the right side view and the vertical view from above. These two veiew can specify usual type of fish, since they are symmetric along the spine.
  3. The correspondence between the two views can be visually recognizable by a button which invokes the function to color the corresponding vertices in the same color.
  4. It has all basic editing fuctions for creating, modifying, and deleting vertices and edges for both fish and scaffolding.

In this design the characteristics of the motion is determined by the following four factors:

  • Swinging function
  • Location of the four inflection points
  • Propagation rules of the swinging to the rest of the spine units from the central inflection point.
  • Stiffness factors of each portion of the spine (e.g. hard around the head, soft around the tail).

In our experimental fish we tried two types of swinging functions, sinusoidal and linear. The propagation of the swing is delivered by an equal amount of angle change in both directions. However, the delivered swing is tapered or amplified depending on the portion of the spine by the stiffness factor. For example, the head part suppresses the swing and the tail amplifies the delivered motion. The results are shown in the below movies. Movie B1 is the result of sinusoidal swinging function, B2 linear function.

Movie B1

Movie 1

Movie B2

Movie 2

III. Rendering the fish

A. Fish of physycally-based motion

As discussed earlier, the fish consists of a scaffolding of springs and a set of vertices and edges that constitute the geometry of the body. When the fish moves its muscles, the scaffolding deforms, and we would like the body of the fish to deform in a similar way. To do this, we consider that the scaffolding consists of a set of juxtaposed eight-sided polyhedra that entirely contain the body of the fish. We considered thinking of these polyhedra as deformed cubes and using trilinear interpolation to compute coordinates of each body vertex relative to the deformed cube that contains it. However, we could not think of a very systematic way to do this. Instead, we divide each polyhedron into five tetrahedra. Then, to determine the relationship of each body vertex to the scaffolding, we locate the tetrahedron that contains that point and compute barycentric coordinates of the point in the coordinate system defined by the tetrahedron. When the scaffolding deforms, we can compute the new location of the vertex by computing a convex combination of the four vertices of the containing tetrahedron using the barycentric coordinates.

B. Fish of non-Physics based motion

Unlike the above type of fish, the fish of non-physics based motion can be rendered very easily. The first step is to determine the shape and the position of the spine. It is done by the algorithm described above. Next the positions of all the vertices on the surface of the body is computed. It is straight forward since each vertex has a constant distance from its reference spine unit (i.e. the distance of the normal to the spine unit). This way the whole of the fish body can be easily computed at any time.

IV. Results

A. Physically-based motion

We first implemented our system for a two-dimensional fish. In learning the swim-forward controller for our fish, we found that when we allowed a sine wave with a different frequency to modulate each muscle length, the simulated annealing got stuck in a local minimum and the resulting motion was not very effective. The best results were obtained when we learned a single global frequency to modulate all muscles. Since the phase and amplitude are allowed to vary, there are still enough parameters to allow the fish to swim in a visually pleasing, physically plausible way. The results are shown in Movie 2. The black lines show the scaffolding of the fish, and the blue lines and vertices show the body of the fish. Movie 3 shows the results of learning the controls for a different fish.

Movie 2

Movie 2

Movie 3

Movie 3

The results were not as good for the turn controllers. The fish learns to turn successfully, but instead of turning in a natural way, the fish appears to be thrashing. We think that this is because when a fish turns, its muscle lengths cannot be well approximated with a sinusoid, because the fish contracts its muscles faster than it relaxes them. Treating the oscillation of the muscles in a more general way might produce better results. In addition, we observed problems when the fish transitions between two controllers; some intermediate controls cause the scaffolding to fold over itself. In Movie 4, we give the fish the goal of swimming to the red point along the bottom of the screen. The fish makes it, but the turning looks unrealistic and along the way the body loses consistency at times.

Movie 4

Movie 4

In three dimensions, the results are promising, but far from perfect. When moving, the fish tends to rotate around the axis running along the length of its body, and tends to drift away from the path representing a straight swim. We suspect that this is because of the simplified way in which we treat the force of the water on the body; the scaffolding is coarsely triangulated and some bias may be introduced with the triangulation; in addition, we approximate the velocity of each face very roughly. This can be easily improved, and may result in much more stable motion. The results of learning a swim-forward controller for a 3D fish are shown in Movie 5. The scaffolding has been removed to make the body easy to see.

Movie 5

Movie 5


B. Non-Physics based motion emulation

Although the result of this experiment is not very impressive, it is due to the lack of extensive trial of wide variety of coefficients and propagation functions. (This type of motion emulation was not in our agenda until the late stage of our work.) The non-physics based emulation has various favorable characteristics:

  • Easy to implement the motion compared to the physics-based ones.
  • Little risk of unstability of motion.
  • Easy to render as stated in the above section for rendering.

Therefore, we believe it deserves more attention to make interesting fish emulations, especially of very complex ones such as the motion of stingray.


V. Works cited

[1] Xiaoyuan Tu and Demetri Terzopoulos. Artificial fishes: Physics, locomotion, perception, behavior. Proc. 21st annual conference on Computer graphics and interactive techniques, p.43-50, July 1994.

[2] David Baraff. Implicit methods for differential equations. SIGGRAPH course notes, 2001.

Special "thank yous" to Zoran Popovic, Brian Curless, Steve Seitz, and Steve Capell for your helpful suggestions.