import macro from 'vtk.js/Sources/macros'; import vtkCompositeVRManipulator from 'vtk.js/Sources/Interaction/Manipulators/CompositeVRManipulator'; import { Device, Input, } from 'vtk.js/Sources/Rendering/Core/RenderWindowInteractor/Constants'; import { States } from 'vtk.js/Sources/Rendering/Core/InteractorStyle/Constants';
function vtkVRButtonPanManipulator(publicAPI, model) { model.classHierarchy.push('vtkVRButtonPanManipulator');
publicAPI.onButton3D = (interactorStyle, renderer, state, eventData) => { if (eventData.pressed) { interactorStyle.startCameraPose(); } else if (state === States.IS_CAMERA_POSE) { interactorStyle.endCameraPose(); } };
publicAPI.onMove3D = (interactorStyle, renderer, state, eventData) => { if (state !== States.IS_CAMERA_POSE) { return; }
const camera = renderer.getActiveCamera(); const oldTrans = camera.getPhysicalTranslation();
const speed = eventData.gamepad.axes[1];
const pscale = speed * 0.05 * camera.getPhysicalScale();
const dir = camera.physicalOrientationToWorldDirection( eventData.orientation );
camera.setPhysicalTranslation( oldTrans[0] + dir[0] * pscale, oldTrans[1] + dir[1] * pscale, oldTrans[2] + dir[2] * pscale ); }; }
const DEFAULT_VALUES = { device: Device.RightController, input: Input.TrackPad, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model); vtkCompositeVRManipulator.extend(publicAPI, model, initialValues);
vtkVRButtonPanManipulator(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkVRButtonPanManipulator' );
export default { newInstance, extend };
|