To answer the question that is asked in the title. The reason for this is that at some points of the curve the up (1,0,0) vector and the tangent are parallel. This means that their cross product is zero, and the construction of a quaternion fails.
You could follow WestLangley's suggestion. You really want the upward direction to be normal for the plane the track is in.
Quaternion rotation is difficult to understand that the setFromAxisAngle function rotates around an axis by a given angle.
If the track lies in the XY plane, then we want to rotate around the Z axis. To find the angle, use Math.atan2 to find the angle of the tangent
var angle = Math.atan2(tangent.y,tangent.x);
combining this set
var ZZ = new THREE.Vector3( 0, 0, 1 );
and
tangent = spline.getTangentAt(counter).normalize(); var angle = Math.atan2(tangent.y,tangent.x); box.quaternion.setFromAxisAngle(ZZ, angle);
If the track leaves the XY plane, the situation will become more complicated.
source share