Animated Textures – Tutorial 1

With the recent release of the Animated Steampunk Textures pack, this would be a good time to do some tutorials on animated textures, so here we go…

This is the first of a three-part tutorial about using animated textures in Second Life. There three parts, because there are three different ways of animating textures, each with their own use. Two of them make use of the LSL function, llSetTextureAnim, which is the usual way of animating textures. The third way uses a timer and offsets to manually animate the texture — it is a lot less efficient, but can occasionally be useful.

In this first part, however, I’ll look at the simplest and easiest way of animating a texture, using the ‘smooth scroll’ option. This simply moves the texture across the surface of the prim, and doesn’t need a specially designed texture — any texture can be scrolled, although some will obviously work better than others!

A common use of this is to create a flowing water animation, and that’s the example I’ll use here, especially as suitable textures are available from the built-in Library in every Second Life avatar’s inventory.

So…

Rez a simple cube, and apply a water texture to it — the Water – ripple layer 1 texture in the Library\Textures\Waterfalls folder should work well. Resize it into something fairly long and flat (5 x 2 should be effective).

On the Contents tab of the Build window, click the ‘New Script’, and wait for it to appear in the Contents list (if SL is being laggy this might take a few seconds). Double-click to open it.

Replace the existing code with the following:

[sourcecode language="cpp"]
default
{
    state_entry()
    {
        llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 0, 1, 1, 1, 1, 0.12);
    }
}
[/sourcecode]

Save the script, and the texture will start scrolling. Assuming that you haven’t rotated the prim, this will scroll the top surface.

Ok, now you’ve seen it in action, let’s look at the parameters.

The first parameter is a set of flags which specify how the texture should be animated. You can string together several flags (as in the above example) by using the ‘|’ symbol (technically an ‘OR’ operator). Note that some combinations don’t make sense.

You can check the LSL Wiki page for details of what each flag means, but in the example we are switching the animation on (rather important!), and we are saying that we want a ‘SMOOTH’ animation, which means that the texture will simply be scrolled across the surface of the prim (actually, this is not quite an accurate description of what SMOOTH does, but I’ll explain it in more detail in the next article).

Finally we are specifying ‘LOOP’, which means that the animation will keep going continuously.

Instead of LOOP we could have specified PING-PONG, which reverses the animation when it reaches the end. In the case of a smooth animation, it will scroll the texture for the entire length, then reverse direction and scroll it back again.

If you want to stop an animation, simply set this parameter to 0. All the other parameters are irrelevant in this case.

The next parameter — 0 in this example — is the face of the prim that the animation should be applied to. All the other faces will be static. However, if you use ALL_SIDES for this parameter, all the faces of the prim will animate.

Unfortunately, it isn’t possible to animate some but not all of the faces — it’s either 1 face or all faces.

A couple of final notes. You’ll notice that the Repeat and Flip options for textures don’t have any effect on animated textures. Rotate, however, does.

That will do for now. In the next article, I’ll take a look at the traditional animated texture, which uses a sequence of frames like an animated movie.


Posted

in

,

by

Comments

Leave a Reply