Skip to content

mattdesl/three-quaternion-from-normal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Builds a ThreeJS quaternion from a normal vector

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages