applyMatrix4 method

dynamic applyMatrix4(
  1. dynamic matrix
)

Implementation

applyMatrix4(matrix) {
  var e = matrix.elements;

  var sx = v1.set(e[0], e[1], e[2]).length();
  var sy = v1.set(e[4], e[5], e[6]).length();
  var sz = v1.set(e[8], e[9], e[10]).length();

  var det = matrix.determinant();
  if (det < 0) sx = -sx;

  rotationMatrix.setFromMatrix4(matrix);

  var invSX = 1 / sx;
  var invSY = 1 / sy;
  var invSZ = 1 / sz;

  rotationMatrix.elements[0] *= invSX;
  rotationMatrix.elements[1] *= invSX;
  rotationMatrix.elements[2] *= invSX;

  rotationMatrix.elements[3] *= invSY;
  rotationMatrix.elements[4] *= invSY;
  rotationMatrix.elements[5] *= invSY;

  rotationMatrix.elements[6] *= invSZ;
  rotationMatrix.elements[7] *= invSZ;
  rotationMatrix.elements[8] *= invSZ;

  this.rotation.multiply(rotationMatrix);

  this.halfSize.x *= sx;
  this.halfSize.y *= sy;
  this.halfSize.z *= sz;

  v1.setFromMatrixPosition(matrix);
  this.center.add(v1);

  return this;
}