scale method

dynamic scale(
  1. dynamic size,
  2. dynamic point, [
  3. dynamic scaleGizmos = true
])

Perform uniform scale operation around a given point @param {Number} size Scale factor @param {Vector3} point Point around which scale @param {Boolean} scaleGizmos If gizmos should be scaled (Perspective only) @returns {Object} Object with 'camera' and 'gizmo' fields containing transformation matrices resulting from the operation to be applied to the camera and gizmos

Implementation

scale(size, point, [scaleGizmos = true]) {
  _scalePointTemp.copy(point);
  var sizeInverse = 1 / size;

  if (camera is OrthographicCamera) {
    //camera zoom
    camera.zoom = _zoomState;
    camera.zoom *= size;

    //check min and max zoom
    if (camera.zoom > maxZoom) {
      camera.zoom = maxZoom;
      sizeInverse = _zoomState / maxZoom;
    } else if (camera.zoom < minZoom) {
      camera.zoom = minZoom;
      sizeInverse = _zoomState / minZoom;
    }

    camera.updateProjectionMatrix();

    _v3_1.setFromMatrixPosition(_gizmoMatrixState); //gizmos position

    //scale gizmos so they appear in the same spot having the same dimension
    _scaleMatrix.makeScale(sizeInverse, sizeInverse, sizeInverse);
    _translationMatrix.makeTranslation(-_v3_1.x, -_v3_1.y, -_v3_1.z);

    _m4_2.makeTranslation(_v3_1.x, _v3_1.y, _v3_1.z).multiply(_scaleMatrix);
    _m4_2.multiply(_translationMatrix);

    //move camera and gizmos to obtain pinch effect
    _scalePointTemp.sub(_v3_1);

    var amount = _scalePointTemp.clone().multiplyScalar(sizeInverse);
    _scalePointTemp.sub(amount);

    _m4_1.makeTranslation(_scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z);
    _m4_2.premultiply(_m4_1);

    setTransformationMatrices(_m4_1, _m4_2);
    return _transformation;
  } else if (camera is PerspectiveCamera) {
    _v3_1.setFromMatrixPosition(_cameraMatrixState);
    _v3_2.setFromMatrixPosition(_gizmoMatrixState);

    //move camera
    var distance = _v3_1.distanceTo(_scalePointTemp);
    var amount = distance - (distance * sizeInverse);

    //check min and max distance
    var newDistance = distance - amount;
    if (newDistance < minDistance) {
      sizeInverse = minDistance / distance;
      amount = distance - (distance * sizeInverse);
    } else if (newDistance > maxDistance) {
      sizeInverse = maxDistance / distance;
      amount = distance - (distance * sizeInverse);
    }

    _offset.copy(_scalePointTemp).sub(_v3_1).normalize().multiplyScalar(amount);

    _m4_1.makeTranslation(_offset.x, _offset.y, _offset.z);

    if (scaleGizmos) {
      //scale gizmos so they appear in the same spot having the same dimension
      var pos = _v3_2;

      distance = pos.distanceTo(_scalePointTemp);
      amount = distance - (distance * sizeInverse);
      _offset.copy(_scalePointTemp).sub(_v3_2).normalize().multiplyScalar(amount);

      _translationMatrix.makeTranslation(pos.x, pos.y, pos.z);
      _scaleMatrix.makeScale(sizeInverse, sizeInverse, sizeInverse);

      _m4_2.makeTranslation(_offset.x, _offset.y, _offset.z).multiply(_translationMatrix);
      _m4_2.multiply(_scaleMatrix);

      _translationMatrix.makeTranslation(-pos.x, -pos.y, -pos.z);

      _m4_2.multiply(_translationMatrix);
      setTransformationMatrices(_m4_1, _m4_2);
    } else {
      setTransformationMatrices(_m4_1);
    }

    return _transformation;
  }
}