three-quaternion-from-normal

1.0.0 • Public • Published

three-quaternion-from-normal

Builds a ThreeJS quaternion from a normal vector.

This is useful for getting meshes to 'point' in the direction of a vector.

const quaternionFromNormal = require('three-quaternion-from-normal');
 
// Say we want mesh to point from A to B point
const A = new THREE.Vector3(1, 0, 0);
const B = new THREE.Vector3(2, 5, -1);
 
// Get normal A->B
const normal = B.clone().sub(A).normalize();
 
// Get orientation
const quaternion = quaternionFromNormal(normal);
 
// Apply orientation to mesh
mesh.quaternion.copy(quaternion);

Install

Use npm to install.

npm install three-quaternion-from-normal --save

Usage

quat = quaternionFromNormal(normal, [quaternionTarget])

Builds a quaternion from the normal (a normalized THREE.Vector3), storing the result in quaternionTarget (a THREE.Quaternion) or creating a new quaternion object if no target is specified.

The quaternion target is returned.

License

MIT, see LICENSE.md for details.

Package Sidebar

Install

npm i three-quaternion-from-normal

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

3.65 kB

Total Files

4

Last publish

Collaborators

  • mattdesl