All files / Sources/Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator index.js

38.46% Statements 10/26
0% Branches 0/11
40% Functions 2/5
38.46% Lines 10/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93                    1x   1x 1x         1x                                         1x                                             1x             1x     1x             1x         1x                
import macro from 'vtk.js/Sources/macros';
import vtkInteractorStyleManipulator from 'vtk.js/Sources/Interaction/Style/InteractorStyleManipulator';
import vtkMouseCameraTrackballZoomManipulator from 'vtk.js/Sources/Interaction/Manipulators/MouseCameraTrackballZoomManipulator';
 
// ----------------------------------------------------------------------------
// vtkMouseCameraTrackballZoomToMouseManipulator methods
// ----------------------------------------------------------------------------
 
function vtkMouseCameraTrackballZoomToMouseManipulator(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkMouseCameraTrackballZoomToMouseManipulator');
 
  const superOnButtonDown = publicAPI.onButtonDown;
  publicAPI.onButtonDown = (interactor, renderer, position) => {
    superOnButtonDown(interactor, renderer, position);
    model.zoomPosition = position;
  };
 
  publicAPI.onMouseMove = (interactor, renderer, position) => {
    if (!position) {
      return;
    }
 
    const dy = model.previousPosition.y - position.y;
    const k = dy * model.zoomScale;
    vtkInteractorStyleManipulator.dollyToPosition(
      1.0 - k,
      model.zoomPosition,
      renderer,
      interactor
    );
 
    if (interactor.getLightFollowCamera()) {
      renderer.updateLightsGeometryToFollowCamera();
    }
 
    model.previousPosition = position;
  };
 
  publicAPI.onScroll = (interactor, renderer, delta, position) => {
    if (!delta || !position) {
      return;
    }
 
    const dyf = 1 - delta * 0.1;
    vtkInteractorStyleManipulator.dollyToPosition(
      dyf,
      position,
      renderer,
      interactor
    );
 
    if (interactor.getLightFollowCamera()) {
      renderer.updateLightsGeometryToFollowCamera();
    }
  };
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  zoomPosition: null,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Inheritance
  vtkMouseCameraTrackballZoomManipulator.extend(
    publicAPI,
    model,
    initialValues
  );
 
  // Object specific methods
  vtkMouseCameraTrackballZoomToMouseManipulator(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(
  extend,
  'vtkMouseCameraTrackballZoomToMouseManipulator'
);
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };