How to use the Quaternion function from three

Find comprehensive JavaScript three.Quaternion code examples handpicked from public code repositorys.

122
123
124
125
126
127
128
129
130
131
// so camera.up is the orbit axis
var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
var quatInverse = quat.clone().inverse();

var lastPosition = new THREE.Vector3();
var lastQuaternion = new THREE.Quaternion();

return function () {

        var position = scope.object.position;
fork icon185
star icon870
watch icon40

+ 3 other calls in file

178
179
180
181
182
183
184
185
186
187
    quaternion.set(0, 0, 0, 1);
} else if (direction.y < -0.99999) {
    quaternion.set(1, 0, 0, 0);
} else {
    axis.set(direction.z, 0, -direction.x).normalize();
    quaternion = new THREE.Quaternion().setFromAxisAngle(axis, Math.acos(direction.y));
}

coneGeometry.applyMatrix4(new THREE.Matrix4().makeRotationFromQuaternion(quaternion));
coneGeometry.translate(destination.x, destination.y, destination.z);
fork icon117
star icon808
watch icon24

+ 9 other calls in file

23
24
25
26
27
28
29
30
31
32

const randomMul = typeof (window.randomMul) !== 'undefined' ? window.randomMul : 255.0;
const geometry = new THREE.BoxBufferGeometry(1, 1, 1);
const modelMatrix = new THREE.Matrix4();
const translation = new THREE.Vector3();
const rotation = new THREE.Quaternion();
const scale = new THREE.Vector3();
const colorMap = (config.color_map && config.color_map.data) || null;
let mask = null;
let maskEnabled = false;
fork icon115
star icon803
watch icon0

29
30
31
32
33
34
35
36
37
38
var keyState = {};

var curCamZoom = 60;
var curCamHeight = 70;

var cameraReferenceOrientation = new THREE.Quaternion();
var cameraReferenceOrientationObj = new THREE.Object3D();
var poleDir = new THREE.Vector3(1,0,0);

this.update = function() {
fork icon15
star icon47
watch icon10

+ 15 other calls in file

184
185
186
187
188
189
190
191
192
193
  object.updateMatrix();
  geometry.applyMatrix(object.matrix);
  return geometry;
}

function quatFromDir (dir, quaternion = new THREE.Quaternion()) {
  // dir is assumed to be normalized
  if (dir.y > 0.99999) {
    quaternion.set(0, 0, 0, 1);
  } else if (dir.y < -0.99999) {
fork icon3
star icon39
watch icon2

+ 15 other calls in file

152
153
154
155
156
157
158
159
160
161
}());

this.rotateCamera = (function () {

  let axis = new THREE.Vector3(),
    quaternion = new THREE.Quaternion(),
    eyeDirection = new THREE.Vector3(),
    objectUpDirection = new THREE.Vector3(),
    objectSidewaysDirection = new THREE.Vector3(),
    moveDirection = new THREE.Vector3(),
fork icon17
star icon31
watch icon4

+ 9 other calls in file

32
33
34
35
36
37
38
39
40
this.beta = 0;
this.gamma = 0;
this.orient = 0;

this.alignQuaternion = new THREE.Quaternion();
this.orientationQuaternion = new THREE.Quaternion();

var quaternion = new THREE.Quaternion();
var quaternionLerp = new THREE.Quaternion();
fork icon6
star icon30
watch icon7

+ 13 other calls in file

23
24
25
26
27
28
29
30
31
32
// internals

this.movementSpeedMultiplier = 1.0;
this.yawSpeedMultiplier = 1.0;

this.tmpQuaternion = new THREE.Quaternion();

this.mouseStatus = 0;

this.moveState = { up: 0, down: 0, left: 0, right: 0, forward: 0, back: 0, pitchUp: 0, pitchDown: 0, yawLeft: 0, yawRight: 0, rollLeft: 0, rollRight: 0 };
fork icon6
star icon11
watch icon16

47
48
49
50
51
52
53
54
55
56

var ray = new THREE.Raycaster();

var _tempVector = new THREE.Vector3();
var _tempVector2 = new THREE.Vector3();
var _tempQuaternion = new THREE.Quaternion();
var _unit = {
    X: new THREE.Vector3( 1, 0, 0 ),
    Y: new THREE.Vector3( 0, 1, 0 ),
    Z: new THREE.Vector3( 0, 0, 1 )
fork icon4
star icon26
watch icon11

+ 41 other calls in file

43
44
45
46
47
48
49
50
51
52
const ringGeometry = new THREE.RingGeometry(0.75, 0.6, 6, 1);

this.groundRingMesh = new THREE.Group();

// rotation of quaternion which we'll re-use later
this.groundRingRotationQuaternion = new THREE.Quaternion().setFromAxisAngle(
  new THREE.Vector3(1, 0, 0), -Math.PI / 2
);

// ringGeometry.applyMatrix(new THREE.Matrix4().makeRotationX(-Math.PI / 2));
fork icon4
star icon25
watch icon2

+ 11 other calls in file

127
128
129
130
131
132
133
134
135
    //convert to camera space
    target.add(this.camera.position);
    this.spot.position.copy(target);
    this.controller1.lookAt(target);
    //have to flip over because the UP is down on controllers
    var flip = new _threeModule.Quaternion().setFromAxisAngle(new _threeModule.Vector3(0, 1, 0), toRad(180));
    this.controller1.quaternion.multiply(flip);
}
this._processMove();
fork icon4
star icon10
watch icon1

+ 3 other calls in file

38
39
40
41
42
43
44
45
46
47

var zee = new THREE.Vector3( 0, 0, 1 );

var euler = new THREE.Euler();

var q0 = new THREE.Quaternion();

var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis

return function ( quaternion, alpha, beta, gamma, orient ) {
fork icon4
star icon9
watch icon5

+ 3 other calls in file

129
130
131
132
133
134
135
136
137
    color: 0xffff00,
    side: THREE.DoubleSide
});
this.ringBufferMesh = new THREE.Mesh(ringBufferGeometry, ringBufferMaterial);
this.ringBufferMesh.position.copy(position).multiplyScalar(200);
var cameraRotationQuaternion = (new THREE.Quaternion())
    .setFromUnitVectors(new THREE.Vector3(0, 0, 1), position);
this.ringBufferMesh.rotation.setFromQuaternion(cameraRotationQuaternion);
this.scene.add(this.ringBufferMesh);
fork icon3
star icon20
watch icon5

1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
var tempEuler = new THREE.Euler();
var alignVector = new THREE.Vector3( 0, 1, 0 );
var zeroVector = new THREE.Vector3( 0, 0, 0 );
var lookAtMatrix = new THREE.Matrix4();
var tempQuaternion = new THREE.Quaternion();
var tempQuaternion2 = new THREE.Quaternion();
var identityQuaternion = new THREE.Quaternion();

var unitX = new THREE.Vector3( 1, 0, 0 );
var unitY = new THREE.Vector3( 0, 1, 0 );
fork icon4
star icon26
watch icon0

+ 10 other calls in file

1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
const offset = new THREE.Vector3(); // so camera.up is the orbit axis

const quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
const quatInverse = quat.clone().invert();
const lastPosition = new THREE.Vector3();
const lastQuaternion = new THREE.Quaternion();
const twoPI = 2 * Math.PI;
return function update() {

	const position = scope.object.position;
fork icon3
star icon7
watch icon0

+ 35 other calls in file

1910
1911
1912
1913
1914
1915
1916
1917
1918
1919

this.update = function () {

	const offset = new THREE.Vector3(); // so camera.up is the orbit axis

	const quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
	const quatInverse = quat.clone().invert();
	const lastPosition = new THREE.Vector3();
	const lastQuaternion = new THREE.Quaternion();
	const twoPI = 2 * Math.PI;
fork icon3
star icon7
watch icon0

+ 33 other calls in file

1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801


    }


}


const _q = new THREE.Quaternion();


class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {


    interpolate_( i1, t0, t, t1 ) {
fork icon2
star icon10
watch icon0

1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
        }
        return result;
    }
    ;
}
const _q = new three.Quaternion();
class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
    interpolate_(i1, t0, t, t1) {
        const result = super.interpolate_(i1, t0, t, t1);
        _q.fromArray(result).normalize().toArray(result);
fork icon2
star icon7
watch icon0

123
124
125
126
127
128
129
130
131
132
this.update = function () {

  var offset = new THREE.Vector3();

  // so camera.up is the orbit axis
  var quat = new THREE.Quaternion().setFromUnitVectors(object.up, new THREE.Vector3(0, 1, 0));
  var quatInverse = quat.clone().inverse();

  var lastPosition = new THREE.Vector3();
  var lastQuaternion = new THREE.Quaternion();
fork icon2
star icon7
watch icon3

+ 17 other calls in file

130
131
132
133
134
135
136
137
138
139
// so camera.up is the orbit axis
var quat = new THREE.Quaternion().setFromUnitVectors(object.up, new THREE.Vector3(0, 1, 0))
var quatInverse = quat.clone().inverse()

var lastPosition = new THREE.Vector3()
var lastQuaternion = new THREE.Quaternion()

return function update() {

    var position = scope.object.position
fork icon2
star icon14
watch icon0

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)