Friday, August 04, 2006

Facial Animation - Open Mouth

I have a need to make an avatar's mouth open wide, and stay open. After a little bit of research, it sounds like it's not possible to create new facial animations for Second Life, but there are a number of built-in face animations that you can access via LSL. This thread discusses the matter. It also features the following LSL example (courtesy of Gattz Gilman), which does exactly what I need it to do:

default
{
attach(key on)
{
if (on != NULL_KEY)
{
integer perm = llGetPermissions();
if (!(perm & PERMISSION_TRIGGER_ANIMATION))
{
llRequestPermissions(on, PERMISSION_TRIGGER_ANIMATION);
}
else
{
llSetTimerEvent(0.5);
}
}
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llSetTimerEvent(0.5);
}
}

timer()
{
llStopAnimation("express_open_mouth");
llStartAnimation("express_open_mouth");
}
}

The attach method is an event handler that is triggered when the scripted item is attached to or detached from an avatar. The key parameter is the key of the avatar during attachment, or NULL_KEY on detachment.

As a complete aside, I had to use the <pre> and </pre> HTML tags in order to get the code sample up there to show up properly indented. I'm a bit of an HTML newbie as well...