My preferred method for rotating objects is by utilizing quaternions.
function rotateObject( obj, degrees, axis )
{
// Axis parameter represents a THREE.Vector3
var quaternion = new THREE.Quaternion();
quaternion.setFromAxisAngle(axis, THREE.MathUtils.degToRad( degrees ) ); // Radians are required
quaternion.normalize();
obj.quaternion.multiply( quaternion );
}
If I want to rotate an object by 90 degrees along the Z axis, the function call would be
rotateObject( myMesh, 90, new THREE.Vector3( 0, 0, 1 );
For a gradual rotation over time, the slerp method can be used, adjusting the progress parameter from 0 to 1.
function rotateSlerp( obj, degrees, axis, progress )
{
var quaternion = new THREE.Quaternion();
quaternion.setFromAxisAngle( axis, THREE.MathUtils.degToRad( degrees ) );
quaternion.normalize();
obj.quaternion.slerp( quaternion, progress );
}
To implement this, the function call would be
let progress = 0;
function animateRotation()
{
progress += 0.05;
rotateSlerp( myMesh, 90, new THREE.Vector3( 0, 0, 1), progress );
requestAnimationFrame( animateRotation );
}