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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 7x 7x 7x 7x 7x 7x 7x 1x 7x 7x 7x 7x 7x 1x | import macro from 'vtk.js/Sources/macros'; import vtkCompositeCameraManipulator from 'vtk.js/Sources/Interaction/Manipulators/CompositeCameraManipulator'; import vtkCompositeGestureManipulator from 'vtk.js/Sources/Interaction/Manipulators/CompositeGestureManipulator'; import vtkInteractorStyleManipulator from 'vtk.js/Sources/Interaction/Style/InteractorStyleManipulator'; // ---------------------------------------------------------------------------- // vtkGestureCameraManipulator methods // ---------------------------------------------------------------------------- function vtkGestureCameraManipulator(publicAPI, model) { // Set our className model.classHierarchy.push('vtkGestureCameraManipulator'); //-------------------------------------------------------------------------- publicAPI.onStartPinch = (interactor, scale) => { model.previousScale = scale; }; //--------------------------------------------------------------------------- publicAPI.onStartRotate = (interactor, rotation) => { model.previousRotation = rotation; }; //--------------------------------------------------------------------------- publicAPI.onStartPan = (interactor, translation) => { model.previousTranslation = translation; }; //--------------------------------------------------------------------------- publicAPI.onPinch = (interactor, renderer, scale) => { vtkInteractorStyleManipulator.dollyByFactor( interactor, renderer, scale / model.previousScale ); model.previousScale = scale; }; //--------------------------------------------------------------------------- publicAPI.onPan = (interactor, renderer, translation) => { const camera = renderer.getActiveCamera(); const style = interactor.getInteractorStyle(); // Calculate the focal depth since we'll be using it a lot let viewFocus = camera.getFocalPoint(); viewFocus = style.computeWorldToDisplay( renderer, viewFocus[0], viewFocus[1], viewFocus[2] ); const focalDepth = viewFocus[2]; const trans = translation; const lastTrans = model.previousTranslation; const newPickPoint = style.computeDisplayToWorld( renderer, viewFocus[0] + trans[0] - lastTrans[0], viewFocus[1] + trans[1] - lastTrans[1], focalDepth ); // Has to recalc old mouse point since the viewport has moved, // so can't move it outside the loop const oldPickPoint = style.computeDisplayToWorld( renderer, viewFocus[0], viewFocus[1], focalDepth ); // Camera motion is reversed const motionVector = []; motionVector[0] = oldPickPoint[0] - newPickPoint[0]; motionVector[1] = oldPickPoint[1] - newPickPoint[1]; motionVector[2] = oldPickPoint[2] - newPickPoint[2]; viewFocus = camera.getFocalPoint(); const viewPoint = camera.getPosition(); camera.setFocalPoint( motionVector[0] + viewFocus[0], motionVector[1] + viewFocus[1], motionVector[2] + viewFocus[2] ); camera.setPosition( motionVector[0] + viewPoint[0], motionVector[1] + viewPoint[1], motionVector[2] + viewPoint[2] ); if (interactor.getLightFollowCamera()) { renderer.updateLightsGeometryToFollowCamera(); } camera.orthogonalizeViewUp(); model.previousTranslation = translation; }; //--------------------------------------------------------------------------- publicAPI.onRotate = (interactor, renderer, rotation) => { const camera = renderer.getActiveCamera(); camera.roll(rotation - model.previousRotation); camera.orthogonalizeViewUp(); model.previousRotation = rotation; }; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- const DEFAULT_VALUES = {}; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance macro.obj(publicAPI, model); vtkCompositeGestureManipulator.extend(publicAPI, model, initialValues); vtkCompositeCameraManipulator.extend(publicAPI, model, initialValues); // Object specific methods vtkGestureCameraManipulator(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance( extend, 'vtkGestureCameraManipulator' ); // ---------------------------------------------------------------------------- export default { newInstance, extend }; |