Advertisement
tnorman

JS____THREEjs GEOMETRY _____ RotateMeshByLine

Jan 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.    
  3.     function rotateByLine ( mesh, from, to ){
  4.         var
  5.                 up          = new THREE.Vector3(0, 1, 0),
  6.                 tangent = new THREE.Vector3().subVectors(from, to).normalize().negate(),
  7.                 radians = Math.acos(up.dot(tangent)),
  8.             axis        = new THREE.Vector3().crossVectors(up, tangent).normalize();
  9.            
  10.         mesh.position.copy( from.lerp( to, 0.5 ) );
  11.         mesh.quaternion.setFromAxisAngle( axis, radians );
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement