How to use the aframe/src.THREE.Matrix4 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 / TransformControls.js View on Github external
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);

  domElement.addEventListener('mousemove', onPointerHover, false);
  domElement.addEventListener('touchmove', onPointerHover, false);
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
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);

  domElement.addEventListener('mousemove', onPointerHover, false);
  domElement.addEventListener('touchmove', onPointerHover, false);

  domElement.addEventListener('mousemove', onPointerMove, false);
  domElement.addEventListener('touchmove', onPointerMove, false);
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
const objectChangeEvent = { type: 'objectChange' };

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

  domElement.addEventListener('mousemove', onPointerHover, false);
  domElement.addEventListener('touchmove', onPointerHover, false);

  domElement.addEventListener('mousemove', onPointerMove, false);
  domElement.addEventListener('touchmove', onPointerMove, false);

  domElement.addEventListener('mouseup', onPointerUp, false);
  domElement.addEventListener('mouseout', onPointerUp, false);
  domElement.addEventListener('touchend', onPointerUp, false);
  domElement.addEventListener('touchcancel', onPointerUp, false);
github kabbi / zanzarah-tools / src / three / DFFLoader.js View on Github external
}
    }
    this._geometry.addAttribute('skinIndex', indicesBuffer);
    this._geometry.addAttribute('skinWeight', weightsBuffer);

    const frameByBoneId = keyBy(this._frames, 'extensions.RwAnimPlugin.data.boneId');
    const threeBoneById = {};
    const threeBones = [];

    for (const bone of bones) {
      const frame = frameByBoneId[bone.id];
      if (!frame) {
        throw new Error('Each bone must have an associated frame');
      }
      const threeBone = new THREE.Bone();
      const transform = new THREE.Matrix4();
      transform.set(
        frame.transform[0], frame.transform[3], frame.transform[6], frame.offset[0],
        frame.transform[1], frame.transform[4], frame.transform[7], frame.offset[1],
        frame.transform[2], frame.transform[5], frame.transform[8], frame.offset[2],
        0, 0, 0, 1
      );
      threeBone.applyMatrix(transform);
      threeBoneById[bone.id] = threeBone;
      threeBones.push(threeBone);
      if (frame.parentFrame !== -1) {
        const parentFrame = this._frames[frame.parentFrame];
        const parentBoneId = parentFrame.extensions.RwAnimPlugin.data.boneId;
        const parentThreeBone = threeBoneById[parentBoneId];
        if (parentThreeBone) {
          parentThreeBone.add(threeBone);
        }
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
const changeEvent = { type: 'change' };
  const mouseDownEvent = { type: 'mouseDown' };
  const mouseUpEvent = { type: 'mouseUp', mode: _mode };
  const objectChangeEvent = { type: 'objectChange' };

  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();
github kabbi / zanzarah-tools / src / three / TransformControls.js View on Github external
THREE.TransformGizmo.prototype.update = function (rotation, eye) {
  const vec1 = new THREE.Vector3(0, 0, 0);
  const vec2 = new THREE.Vector3(0, 1, 0);
  const lookAtMatrix = new THREE.Matrix4();

  this.traverse(child => {
    if (child.name.search('E') !== -1) {
      child.quaternion.setFromRotationMatrix(lookAtMatrix.lookAt(eye, vec1, vec2));
    } else if (child.name.search('X') !== -1 || child.name.search('Y') !== -1 || child.name.search('Z') !== -1) {
      child.quaternion.setFromEuler(rotation);
    }
  });
};
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);