ent_blendpose(
ENTITY*, var target, var source, var percent)
Linearly interpolates between a source and a target bones pose, and
copies the result to the target pose. Can also be used to copy a pose
to another one by setting the percent value at 100.
Parameters:
ENTITY* |
entity pointer |
target |
the target pose number, 1..4 |
source |
the source pose number, 1..4 |
percent |
the blending percentage, 0..100 |
Speed:
Medium (percent >= 100)
Slow (percent < 100)
Remarks:
- A pose is a state of the entity's bones, built through ent_animate or
bones_ instructions after setting the pose number by entity.pose. For
blending entity animations in a complex way, a model entity can have
up to 4 different poses that can be blended by this instruction. The
visible pose is pose 1.
- Blending by linear interpolation computes intermediate vertex
positions rather than intermediate bones angles. Thus it produces the
best results when the bones angles of source and target pose are not
too different, like less than 90 degrees.
- Using poses for animation blending is slower and requires more code
and more memory than using the ent_blend instruction, but is easier
to script - using ent_blend can sometimes be a little tricky. Poses
also offer more freedom for complex blending operations.
Example (lite-C):
// let a model run, and smoothly blend over to shooting when [Ctrl] is pressed
action bones_test()
{
while(1)
{
my.skill1 += 3*time_step; // running torso animation
my.skill2 += 3*time_step; // running legs animation
if (key_ctrl) // fire key pressed?
{
my.skill3 += 20*time_step; // shoot blending percentage
my.skill3 = minv(my.skill3,100); // limit at 100 percent
}
else
{
my.skill3 -= 20*time_step;
my.skill3 = maxv(my.skill3,0); // limit at 0 percent
}
// reset skeletion and then compose the animation (order is important):
ent_animate(me,NULL,0,0); // reset all poses
#ifdef USE_POSES
// compose the poses: 1 = running, 2 = shooting
// animate the running legs in pose 1 and pose 2
my.pose = 1;
ent_animate(me,"run_legs",my.skill2,ANM_CYCLE);
// copy the running legs from pose 1 to pose 2 - faster than animating separately
ent_blendpose(my,2,1,100);
// animate the torso in pose 1 only
ent_animate(me,"run_torso",my.skill1,ANM_CYCLE+ANM_ADD);
// if [Ctrl] pressed, animate the shooting torso in pose 2 only
if (my.skill3 > 0)
{
my.pose = 2;
ent_animate(me,"shoot",0,ANM_ADD); // we assume only one shooting frame
// now blend shooting (pose 2) into running (pose 1)
ent_blendpose(my,1,2,my.skill3);
}
#else
// alternatively, same animation without poses - order is important
// first, move the torso during running
ent_animate(me,"run_torso",my.skill1,ANM_CYCLE);
// then blend over to, or blend back from shooting (only affects the torso)
if (my.skill3 > 0) ent_blend("shoot",0,my.skill3);
// finally animate the legs
ent_animate(me,"run_legs",my.skill2,ANM_CYCLE+ANM_ADD);
#endif
wait(1);
}
}
See also:
ent_animate, ent_blend, entity.pose
► latest
version online