How to use the aframe/src.THREE.Quaternion function in aframe

To help you get started, we’ve selected a few aframe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kabbi / zanzarah-tools / src / three / OrbitControls.js View on Github external
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().inverse();

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

    return function update() {
      const position = scope.object.position;

      offset.copy(position).sub(scope.target);

      // rotate offset to "y-axis-is-up" space
      offset.applyQuaternion(quat);

      // angle from z-axis around y-axis
      spherical.setFromVector3(offset);

      if (scope.autoRotate && state === STATE.NONE) {
        rotateLeft(getAutoRotationAngle());
      }
github kabbi / zanzarah-tools / src / three / OrbitControls.js View on Github external
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().inverse();

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

    return function update() {
      const position = scope.object.position;

      offset.copy(position).sub(scope.target);

      // rotate offset to "y-axis-is-up" space
      offset.applyQuaternion(quat);

      // angle from z-axis around y-axis
      spherical.setFromVector3(offset);
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
this.update = function (rotation, eye2) {
    THREE.TransformGizmo.prototype.update.apply(this, arguments);

    const tempMatrix = new THREE.Matrix4();
    const worldRotation = new THREE.Euler(0, 0, 1);
    const tempQuaternion = new THREE.Quaternion();
    const unitX = new THREE.Vector3(1, 0, 0);
    const unitY = new THREE.Vector3(0, 1, 0);
    const unitZ = new THREE.Vector3(0, 0, 1);
    const quaternionX = new THREE.Quaternion();
    const quaternionY = new THREE.Quaternion();
    const quaternionZ = new THREE.Quaternion();
    const eye = eye2.clone();

    worldRotation.copy(this.planes.XY.rotation);
    tempQuaternion.setFromEuler(worldRotation);

    tempMatrix.makeRotationFromQuaternion(tempQuaternion).getInverse(tempMatrix);
    eye.applyMatrix4(tempMatrix);

    this.traverse(child => {
      tempQuaternion.setFromEuler(worldRotation);

      if (child.name === 'X') {
        quaternionX.setFromAxisAngle(unitX, Math.atan2(-eye.y, eye.z));
        tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionX);
        child.quaternion.copy(tempQuaternion);
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
const ray = new THREE.Raycaster();
  const pointerVector = new THREE.Vector2();

  const point = new THREE.Vector3();
  const offset = new THREE.Vector3();

  const rotation = new THREE.Vector3();
  const offsetRotation = new THREE.Vector3();
  let scale = 1;

  const lookAtMatrix = new THREE.Matrix4();
  const eye = new THREE.Vector3();

  const tempMatrix = new THREE.Matrix4();
  const tempVector = new THREE.Vector3();
  const tempQuaternion = new THREE.Quaternion();
  const unitX = new THREE.Vector3(1, 0, 0);
  const unitY = new THREE.Vector3(0, 1, 0);
  const unitZ = new THREE.Vector3(0, 0, 1);

  const quaternionXYZ = new THREE.Quaternion();
  const quaternionX = new THREE.Quaternion();
  const quaternionY = new THREE.Quaternion();
  const quaternionZ = new THREE.Quaternion();
  const quaternionE = new THREE.Quaternion();

  const oldPosition = new THREE.Vector3();
  const oldScale = new THREE.Vector3();
  const oldRotationMatrix = new THREE.Matrix4();

  const parentRotationMatrix = new THREE.Matrix4();
  const parentScale = new THREE.Vector3();
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
this.update = function (rotation, eye2) {
    THREE.TransformGizmo.prototype.update.apply(this, arguments);

    const tempMatrix = new THREE.Matrix4();
    const worldRotation = new THREE.Euler(0, 0, 1);
    const tempQuaternion = new THREE.Quaternion();
    const unitX = new THREE.Vector3(1, 0, 0);
    const unitY = new THREE.Vector3(0, 1, 0);
    const unitZ = new THREE.Vector3(0, 0, 1);
    const quaternionX = new THREE.Quaternion();
    const quaternionY = new THREE.Quaternion();
    const quaternionZ = new THREE.Quaternion();
    const eye = eye2.clone();

    worldRotation.copy(this.planes.XY.rotation);
    tempQuaternion.setFromEuler(worldRotation);

    tempMatrix.makeRotationFromQuaternion(tempQuaternion).getInverse(tempMatrix);
    eye.applyMatrix4(tempMatrix);

    this.traverse(child => {
      tempQuaternion.setFromEuler(worldRotation);
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
this.update = function (rotation, eye2) {
    THREE.TransformGizmo.prototype.update.apply(this, arguments);

    const tempMatrix = new THREE.Matrix4();
    const worldRotation = new THREE.Euler(0, 0, 1);
    const tempQuaternion = new THREE.Quaternion();
    const unitX = new THREE.Vector3(1, 0, 0);
    const unitY = new THREE.Vector3(0, 1, 0);
    const unitZ = new THREE.Vector3(0, 0, 1);
    const quaternionX = new THREE.Quaternion();
    const quaternionY = new THREE.Quaternion();
    const quaternionZ = new THREE.Quaternion();
    const eye = eye2.clone();

    worldRotation.copy(this.planes.XY.rotation);
    tempQuaternion.setFromEuler(worldRotation);

    tempMatrix.makeRotationFromQuaternion(tempQuaternion).getInverse(tempMatrix);
    eye.applyMatrix4(tempMatrix);

    this.traverse(child => {
      tempQuaternion.setFromEuler(worldRotation);

      if (child.name === 'X') {
        quaternionX.setFromAxisAngle(unitX, Math.atan2(-eye.y, eye.z));
        tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionX);
github kabbi / zanzarah-tools / src / three / SKALoader.js View on Github external
boneIndexByKeyFrameIndex[keyFrameIndex] = boneIndex;
        keyFramesByBoneIndex[boneIndex].push(keyFrame);
      }
    }

    const tracks = [];
    const boneCount = size(keyFramesByBoneIndex);
    for (let boneIndex = 0; boneIndex < boneCount; boneIndex++) {
      const boneKeyFrames = keyFramesByBoneIndex[boneIndex];
      const timeStops = [];
      const positionValues = [];
      const quaternionValues = [];
      for (const { time, position, rotation } of boneKeyFrames) {
        timeStops.push(time);
        positionValues.push(...position);
        const quaternion = new THREE.Quaternion(...rotation);
        quaternion.inverse();
        quaternion.toArray(quaternionValues, quaternionValues.length);
      }

      const path = `.bones[${boneIndex}]`;
      tracks.push(new THREE.VectorKeyframeTrack(`${path}.position`, timeStops, positionValues));
      tracks.push(new THREE.QuaternionKeyframeTrack(`${path}.quaternion`, timeStops, quaternionValues));
    }

    return new THREE.AnimationClip(this.name, duration, tracks);
  }
};
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
const lookAtMatrix = new THREE.Matrix4();
  const eye = new THREE.Vector3();

  const tempMatrix = new THREE.Matrix4();
  const tempVector = new THREE.Vector3();
  const tempQuaternion = new THREE.Quaternion();
  const unitX = new THREE.Vector3(1, 0, 0);
  const unitY = new THREE.Vector3(0, 1, 0);
  const unitZ = new THREE.Vector3(0, 0, 1);

  const quaternionXYZ = new THREE.Quaternion();
  const quaternionX = new THREE.Quaternion();
  const quaternionY = new THREE.Quaternion();
  const quaternionZ = new THREE.Quaternion();
  const quaternionE = new THREE.Quaternion();

  const oldPosition = new THREE.Vector3();
  const oldScale = new THREE.Vector3();
  const oldRotationMatrix = new THREE.Matrix4();

  const parentRotationMatrix = new THREE.Matrix4();
  const parentScale = new THREE.Vector3();

  const worldPosition = new THREE.Vector3();
  const worldRotation = new THREE.Euler();
  const worldRotationMatrix = new THREE.Matrix4();
  const camPosition = new THREE.Vector3();
  const camRotation = new THREE.Euler();

  domElement.addEventListener('mousedown', onPointerDown, false);
  domElement.addEventListener('touchstart', onPointerDown, false);
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
const rotation = new THREE.Vector3();
  const offsetRotation = new THREE.Vector3();
  let scale = 1;

  const lookAtMatrix = new THREE.Matrix4();
  const eye = new THREE.Vector3();

  const tempMatrix = new THREE.Matrix4();
  const tempVector = new THREE.Vector3();
  const tempQuaternion = new THREE.Quaternion();
  const unitX = new THREE.Vector3(1, 0, 0);
  const unitY = new THREE.Vector3(0, 1, 0);
  const unitZ = new THREE.Vector3(0, 0, 1);

  const quaternionXYZ = new THREE.Quaternion();
  const quaternionX = new THREE.Quaternion();
  const quaternionY = new THREE.Quaternion();
  const quaternionZ = new THREE.Quaternion();
  const quaternionE = new THREE.Quaternion();

  const oldPosition = new THREE.Vector3();
  const oldScale = new THREE.Vector3();
  const oldRotationMatrix = new THREE.Matrix4();

  const parentRotationMatrix = new THREE.Matrix4();
  const parentScale = new THREE.Vector3();

  const worldPosition = new THREE.Vector3();
  const worldRotation = new THREE.Euler();
  const worldRotationMatrix = new THREE.Matrix4();
  const camPosition = new THREE.Vector3();
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
this.update = function (rotation, eye2) {
    THREE.TransformGizmo.prototype.update.apply(this, arguments);

    const tempMatrix = new THREE.Matrix4();
    const worldRotation = new THREE.Euler(0, 0, 1);
    const tempQuaternion = new THREE.Quaternion();
    const unitX = new THREE.Vector3(1, 0, 0);
    const unitY = new THREE.Vector3(0, 1, 0);
    const unitZ = new THREE.Vector3(0, 0, 1);
    const quaternionX = new THREE.Quaternion();
    const quaternionY = new THREE.Quaternion();
    const quaternionZ = new THREE.Quaternion();
    const eye = eye2.clone();

    worldRotation.copy(this.planes.XY.rotation);
    tempQuaternion.setFromEuler(worldRotation);

    tempMatrix.makeRotationFromQuaternion(tempQuaternion).getInverse(tempMatrix);
    eye.applyMatrix4(tempMatrix);

    this.traverse(child => {
      tempQuaternion.setFromEuler(worldRotation);

      if (child.name === 'X') {
        quaternionX.setFromAxisAngle(unitX, Math.atan2(-eye.y, eye.z));
        tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionX);
        child.quaternion.copy(tempQuaternion);
      }