Specify a list of positions, orientations, and timings to be followed by an object. The object will be smoothly moved between those keyframes by the simulator.

Collisions with other nonphysical or keyframed objects will be ignored (no script events will fire and collision processing will not occur). Collisions with physical objects will be computed and reported, but the keyframed object will be unaffected by those collisions. (The physical object will be affected, however.)

Syntax

void llSetKeyframedMotion( list keyframes, list options );

Parameters

list keyframes
Strided keyframe list of the form:

Each keyframe is interpreted relative to the previous transform of the object. Time values must be 1/9s. or greater. For example, consider the following list of keyframes:


[<0, 0, 10>, ZERO_ROTATION, 5, <0, 0, 0>, ZERO_ROTATION, 5, <0, 0, -10>, ZERO_ROTATION, 5]

This would cause the object to move up 10m over the course of 5s. It would then remain at the location for 5s before moving down 10m over the course of another 5s.

An empty list will terminate any keyframed animation currently playing.

list options (instructions)
modifiers and future options

Specification

The following flags will be supported within the options list:

Note that if KFM_COMMAND is provided in the options list, it must be the only option in the list, and cannot be specified in the same function call that sets the keyframes list.

Inter-region movement is supported; simply specify a target keyframe that would place the object outside the sim boundaries and it will cross over. This seems to provide the same effect as pausing the animation when it is in limbo between the two regions, but the viewer continues to interpolate its movement. It will jump back to the sim border and continue on the same speed, although the time between waypoints will be increased due to the sim crossing. Make sure you factor this into your system.

Since keyframed motion is a prim property rather than restricted to the script that called it, you can use multiple scripts to control, pause, or restart the same keyframed motion without passing the original keyframe list provided. Just pass an empty list for keyframes list, and the KFM_COMMAND followed by the command in the options list.

Constants

options flagsAdditional ParametersDescription
[ KFM_COMMAND ]0[ integer command ]Sets the command
KFM_CMD_PLAY0?
KFM_CMD_STOP1?
KFM_CMD_PAUSE2?
[ KFM_MODE ]1[ integer mode ]Sets the playback mode

Defaults to KFM_FORWARD

KFM_FORWARD0?
KFM_LOOP1?
KFM_PING_PONG2?
KFM_REVERSE3?
[ KFM_DATA ]2[ integer fields ]Sets what data the keyframes contain

Defaults to (KFM_ROTATION | KFM_TRANSLATION)

KFM_ROTATION0x1?
KFM_TRANSLATION0x2?

Caveats

Examples

A KFM object must use the new Prim Equivalency system in order to work. One of many ways to achieve this is to make sure the object uses Convex Hull for its physics shape. (Mainly new prims need a workaround like this. Mesh objects always use the new Prim Equivalency system.)

llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);

This is a simple example of back-and-forth or "ping pong" motion, using only positions and time.

llSetKeyframedMotion([<0.0, 0.0, 10.0>, 5, <0.0, 0.0, -10.0>, 5], [KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_PING_PONG]);

This example includes position, rotation, and time.

llSetKeyframedMotion(
    [<0.0, 0.0, 10.0>, llEuler2Rot(<90, 45, 180> * DEG_TO_RAD), 5,
     <0.0, 0.0, -10.0>, llEuler2Rot(<270, 225, 360> * DEG_TO_RAD), 5],
    [KFM_MODE, KFM_REVERSE]);

Pause-Play

If you need to update a KFM object's position, you will need to pause KFM and continue it afterwards.

llSetKeyframedMotion([],[KFM_COMMAND, KFM_CMD_PAUSE]);
// Modify prim positions here
llSetKeyframedMotion([],[KFM_COMMAND, KFM_CMD_PLAY]);

Sample Script - Key Framed Follower

Under some circumstances, rotations will generate a run-time error unless they are normalized. This script illustrates a way to use llKeyframedMotion to create a follower -- think, for example, of a cart behind a vehicle -- using normalized target rotation.

key scriptedObjectToFollow = "daf4847b-967d-bff6-69c0-fd7022241be7";
integer isSensorRepeatOn;

rotation NormalizeRotation(rotation Q)
{
    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
    return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_ROOT, [
            PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX,
            PRIM_LINK_TARGET, LINK_ALL_CHILDREN,
            PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE
        ]);
    }

    touch_start(integer total_number)
    {
        isSensorRepeatOn = !isSensorRepeatOn;

        if (isSensorRepeatOn)
        {
            llSay(PUBLIC_CHANNEL, "Sensor repeat switched on!");
            llSensorRepeat("", scriptedObjectToFollow, SCRIPTED, 10.0, PI, 0.3);
        }
        else
        {
            llSensorRemove();
        }
    }

    sensor(integer num_detected)
    {
        vector ownPosition = llGetPos();
        rotation ownRotation = llGetRot();
        vector detectedPosition = llDetectedPos(0);
        rotation detectedRotation = llDetectedRot(0);

        vector kfmPosition = (detectedPosition - ownPosition) + <-1.0, 0.0, 0.2> * detectedRotation;
        rotation kfmRotation = NormalizeRotation(detectedRotation / ownRotation);
        llSetKeyframedMotion([kfmPosition, kfmRotation, 0.15], []);
    }
}

Universal Hinged Motion in 8 Key Frames

The script will turn a box prim around one edge parallel to the prim's Y-axis
The script will work for any prim orientation
Note that the smallest accepted time per frame is 1/9S=0.11111111S and NOT 0.1S

float angleEnd=PI_BY_TWO;
float speed=0.2; // m/S
float steps=8.0; // number of Key Frames
float step=0.0;
list KFMlist=[];
vector V;
integer open=TRUE;
vector basePos;
rotation baseRot;

float motion_time( float mt)
{
    mt = llRound(45.0*mt)/45.0;
    if ( mt > 0.11111111 ) return mt;
    else return 0.11111111;
}

default
{
    state_entry()
    {
        llSetMemoryLimit(0x2000);
        llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
        basePos = llGetPos();
        baseRot = llGetRot();
        vector v1 = 0.5*llGetScale()*llGetRot();
        rotation deltaRot = llEuler2Rot(< 0.0, angleEnd/steps, 0.0>);
        while ( step < steps )
        {
            V = v1*llAxisAngle2Rot(llRot2Left(llGetRot()), angleEnd*step/steps);
            V = v1*llAxisAngle2Rot(llRot2Left(llGetRot()), angleEnd*(step+1.0)/steps) - V;
            KFMlist += [V, deltaRot, motion_time(llVecMag(V)/speed)];
            step += 1.0;
        }
    }
    touch_end( integer n)
    {
        llSetKeyframedMotion( [], []);
        if ( open )
        {
            llSetPrimitiveParams([PRIM_POSITION, basePos, PRIM_ROTATION, baseRot]);
            llSetKeyframedMotion( KFMlist, []);
        }
        else
        {
            llSetKeyframedMotion( KFMlist, [KFM_MODE, KFM_REVERSE]);
        }
        open = !open;
    }
    on_rez( integer n) { llResetScript(); }
}

After editing prim position, rotation and/or size the script should be reset in order to update the motion

Continuous Spin

The following example does the same thing as using llTargetOmega(<0.0,0.0,1.0>,PI,1.0) to make a prim rotate continuously around its Z-axis, assuming that the prim is set to convex hull and is non-physical.

integer gON;

default
{
    touch_end(integer total_number)
    {
        if (gON = !gON)
        {
            // Make repeated rotations of PI radians, each taking 1 seconds
            rotation r = llEuler2Rot(<0.0, 0.0, PI>);
            llSetKeyframedMotion(
                [
                    r, 1,
                    r, 1
                ], 
                [KFM_DATA, KFM_ROTATION, KFM_MODE, KFM_LOOP]
            );
            return;
        }

        llSetKeyframedMotion([], []);
    }
}

More Examples

Notes

Potential Use Cases:

Targeted coordinate systems: The Translation is in Global coordinates, the Rotation in Local coordinates

Deep notes

Issues

History

Date of Release 09/11/2011