.children[1].skeleton.bones[x].quaternion
When you create an AnimationMixer
you specify a root object - in this case it looks like you want to animate children[1]
so you would do
const mixer = new THREE.AnimationMixer( children[1] )
Then in the KeyFrameTrack
you can reference set the name as bones[x].quaternion
in a previous post, you seemed to only use NumberKeyframeTrack
You should use the Quaternion track for quaternions. Internally it uses ‘slerp’ instead of ‘lerp’ to interpolate between values. If you use NumberKeyframeTrack it will still work, but interpolation will probably be wrong - this was a mistake on my part.
3 functions to get a Quaternion (setFromAxisAngle, setFromRotationMatrix and setFromEuler)
- setFromAxisAngle
Rotate around an axis. This is the method used in the misc animation keyframes example you linked and should be fairly intuitive. You set up an axis (below, the x-axis, but this can be any normalised vector), and then the object will rotate around this axis.
// set up rotation about x axis
var xAxis = new THREE.Vector3( 1, 0, 0 );
var qInitial = new THREE.Quaternion().setFromAxisAngle( xAxis, 0 );
var qFinal = new THREE.Quaternion().setFromAxisAngle( xAxis, Math.PI );
var quaternionKF = new THREE.QuaternionKeyframeTrack( '.quaternion', [ 0, 1, 2 ], [ qInitial.x, qInitial.y, qInitial.z,
qInitial.w, qFinal.x, qFinal.y, qFinal.z, qFinal.w, qInitial.x, qInitial.y, qInitial.z, qInitial.w ] );
-
setFromRotationMatrix - you probably don’t want to use this, unless you are already using transformation matrices to specify things.
-
setFromEuler
This is also an intuitive way to use the rotation, since you can use Euler angles to specify the rotations, and just convert them to quaternions as you use them.
In general, you can think of the Euler angle as a ‘normal’ angle, where you specify the amount to rotate around the x, y, z axes.
Every examples I see online seems to use 0, 1, 2 and so on for the value passed as “times” to the KeyframeTrack constructor.
This is just for simplicity - 0, 1, 2 here means 0 seconds, 1 second, 2 seconds. You can use any incrementing values you like, they don’t have to be integers.