Texture animations

Big subject! Texture animations is a good way to give some presence to your object. It based on a single function llSetTextureAnim(), but its usage is not always clear. Let's decorticate this.

Introduction

2 functions, not 1

In fact, the llSetTextureAnim() function is the usual one, when animations need to be applied on the prim the script is. But you might want to control texture animations on other prims from a central script, or animate several textures on different prims at once (reducing the script count and then the simulator load).

This other function is llSetLinkTextureAnim(). It works exactly the same than llSetTextureAnim(), but with an additionnal prefix parameter giving the link number to apply the animation to.

Complicated API

One of the weakness of this function, is that it is used for different kinds of animations, needing different kind of settings. This implies that the function parameters do not mean the same thing depending on the type of animation :

llSetLinkTextureAnim( integer link, integer flags, integer face, integer x, integer y, float start, float length, float rate );

  • integer link (only on llSetLinkTextureAnim() function) : the prim on which to set the animation
  • integer flags : set of constants to determine the type of animation. To get any animation played, it must contain at least ANIM_ON
  • integer face : as we talk about texture, we have to tell which face on the prim is concerned (ALL_SIDES applies to all faces)
  • integer x : depends on the type of animation
  • integer y : depends on the type of animation
  • float start : depends on the type of animation
  • float length : depends on the type of animation
  • float rate : speed of the animation in frames per second

One animation per prim

Be warned that texture animation is an object property, so you cannot have several animations on different faces, even if animation is the same! The only exception is when applying the animation to ALL_SIDES. If you want to animate several faces, you will have to duplicate your prim and animate a different face on each.

Delete once done

As texture animation is a property of objects, once you have set your animation as you wanted, you can delete the script that initiated the animation. That will save some simulator resources.

Note that sometimes, during hypergrid transfer, the animation can be lost. It does not occur everytime, but it's good to know when it appends (if someone has a clear information about the reasons, let me know, I will update this section).

Common flags

LOOP

An animation is by default played only once. To enable an endless loop, specify this flag.

PING_PONG

This flags tells that once the animation has been played, it should be played in reverse order until reaching the beginning. Combined with LOOP, that's like watching a ball striked on a ping-pong table.

REVERSE

Think of this one as only the second part of the PING_PONG flag (playing in reverse order). Combined with PING_PONG, that will play first in reverse order, then the normal way.

SMOOTH

The normal mode is to play each frame separately. The SMOOTH flag indicates to slide from one frame smoothly to another instead of changing them instantly.

Framed animations

The most common usage of animations is the framed one. The principle is simple : you use a texture which has been designed to be splitted in small blocks. Each block will be played one after the other, giving that impress of animation.

This is the default mode of the function, so no special flag is needed to activate it

Let's use a sexy texture to illustrate it :)


This one is particulary interesting (beside the butts) because it clearly shows 4 cells with 4 different colors, so it's easy to identify frames. We can say that the texture has 2 cells horizontally, and 2 cells vertically. This tells us what to put in the x and y parameters, which are the number of frames on x direction (horizontal) and y direction (vertical).

Next two parameters are :

  • start : on which frame to start. Frames are indexes left to right, top to bottom, starting at 0. So the first frame (top left) is 0, the second (top right) is 1, the third (bottom left) is 2 and the fourth (bottom right) is 3. Usually we start at 0, but nothing prevents to start at any frame index
  • length : the number of frames to play. Usually this is x * y (in our case 4), but nothing prevents to play only a subset of available frames (calling the function with different values for different effects).

llSetTextureAnim(ANIM_ON|LOOP, ALL_SIDES, 2, 2, 0, 4rate);

The last parameter is the number of frames to play per second. So this value depdends on the number of frames. Casual values are 0.1, 1.0, 5.0, 10.0... play with it. On our exemple, if we want to change of frame twice a second, we will put 2 (2 frames per second = 0.5 second per frame).

Sliding

One usage with SMOOTH flag is when you have a seamless texture, for example for a falling water. Without frames, you can still get an animation :

llSetTextureAnim(ANIM_ON|LOOP|SMOOTH, ALL_SIDES, 1, 1, 0, 1rate);

This tells to play 1x1 frame (so only 1 frame) for one frame length. Useless? The SMOOTH flag tells to simply slide the texture!

Scale animations

Another type of animation is done by scaling the texture (playing with the displayed size) and is activated with the SCALE flag. Note that the SMOOTH flag is mandatory to make SCALE working!

Rotation animations

The third and last animation type is the rotation one, activated with the ROTATE flag.

Rotation is treated in term of radians (remember your course of geometry at school!). One circle is measured in radians between 0 and 2 * PI, corresponding to an angle. The start parameter is the angle to start with, and length is the amount of rotation to operate.

  • To rotate all way without break, you will have start=0 and length=2*PI.
  • To rotate from 90° (one quarter rotated right) to 180° (half rotated), you will have start=PI/2 and length=PI/2.

With small smooth rotations, nice vegetation animation can be done, to simulate wind of leaves (for example starting at 0 and during PI/36).


Comments