Game Development Reference
In-Depth Information
Set the object's
matrixWorldNeedsUpdate
value to
true
so that
updateWorldMatrix
of the bone calculates our new
skinMatrix
.
object.matrixAutoUpdate = true;
object.matrixWorldNeedsUpdate = true;
Calculate
scale
to interpolate between the
prevKey
and
nextKey
values.
scale = ( currentTime - prevKey.time ) /
( nextKey.time - prevKey.time );
prevXYZ = prevKey[ type ];
nextXYZ = nextKey[ type ];
if ( scale < 0 || scale > 1 ) {
scale = scale < 0 ? 0 : 1;
}
If the
type
value equals position, calculate the new position between the
preyKey
and
nextKey
values and update the bones' position vector with the new interpolated
value. Thus, we interpolate based on the value of
scale
. We use spherical linear
interpolation to calculate the new quaternion between
prevKey
and
nextKey
.
if ( type === "pos" ) {
vector = object.position;
vector.x = prevXYZ[ 0 ] +
( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
vector.y = prevXYZ[ 1 ] +
( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
vector.z = prevXYZ[ 2 ] +
( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
} else if ( type === "rot" ) {
quat.slerp(object.quaternion, prevXYZ, nextXYZ, scale );
} else if ( type === "scl" ) {
vector = object.scale;
vector.x = prevXYZ[ 0 ] +
( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
vector.y = prevXYZ[ 1 ] +
( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
vector.z = prevXYZ[ 2 ] +
( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
}
}
}
};