From 1998f81497372f7b65ae382e2a6dbd66c8a572b5 Mon Sep 17 00:00:00 2001 From: Christopher Pruijsen Date: Fri, 9 Oct 2026 05:40:46 +0100 Subject: [PATCH] fix(InteractorStyleImage): stop mouse move slicing during wheel handleStartMouseWheel and handleEndMouseWheel called startSlice and endSlice, which set model.state to IS_SLICE for the whole wheel gesture. Any mouse move in that window was routed to slice() and dragged the camera distance. Deleting the overrides lets the trackball parent handle the wheel with its wheelDolly guard, so wheel zoom and mouse move stay independent. Ctrl plus left button still starts a slice. --- .../Style/InteractorStyleImage/index.js | 10 ---- .../test/testMouseWheel.js | 47 +++++++++++++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 Sources/Interaction/Style/InteractorStyleImage/test/testMouseWheel.js diff --git a/Sources/Interaction/Style/InteractorStyleImage/index.js b/Sources/Interaction/Style/InteractorStyleImage/index.js index e46c812c6a7..80b13dc33b5 100644 --- a/Sources/Interaction/Style/InteractorStyleImage/index.js +++ b/Sources/Interaction/Style/InteractorStyleImage/index.js @@ -89,16 +89,6 @@ function vtkInteractorStyleImage(publicAPI, model) { } }; - //-------------------------------------------------------------------------- - publicAPI.handleStartMouseWheel = () => { - publicAPI.startSlice(); - }; - - //-------------------------------------------------------------------------- - publicAPI.handleEndMouseWheel = () => { - publicAPI.endSlice(); - }; - //-------------------------------------------------------------------------- publicAPI.handleMouseWheel = (callData) => { const camera = model.getRenderer(callData).getActiveCamera(); diff --git a/Sources/Interaction/Style/InteractorStyleImage/test/testMouseWheel.js b/Sources/Interaction/Style/InteractorStyleImage/test/testMouseWheel.js new file mode 100644 index 00000000000..d693fa07271 --- /dev/null +++ b/Sources/Interaction/Style/InteractorStyleImage/test/testMouseWheel.js @@ -0,0 +1,47 @@ +import { it, expect } from 'vitest'; +import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; +import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource'; +import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; +import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow'; +import vtkInteractorStyleImage from 'vtk.js/Sources/Interaction/Style/InteractorStyleImage'; + +function setup() { + const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ + background: [0.2, 0.3, 0.4], + }); + const renderWindow = fullScreenRenderer.getRenderWindow(); + const renderer = fullScreenRenderer.getRenderer(); + renderWindow.addRenderer(renderer); + const interactor = fullScreenRenderer.getInteractor(); + const interactorStyle = vtkInteractorStyleImage.newInstance(); + interactor.setInteractorStyle(interactorStyle); + const coneSource = vtkConeSource.newInstance({ height: 1.0 }); + const mapper = vtkMapper.newInstance(); + mapper.setInputConnection(coneSource.getOutputPort()); + const actor = vtkActor.newInstance(); + actor.setMapper(mapper); + renderer.addActor(actor); + renderer.resetCamera(); + renderWindow.render(); + return { renderer, interactorStyle }; +} + +it('Test vtkInteractorStyleImage mouse move during mouse wheel does not slice', () => { + const { renderer, interactorStyle } = setup(); + const camera = renderer.getActiveCamera(); + + const distance = camera.getDistance(); + const focalPoint = [...camera.getFocalPoint()]; + interactorStyle.handleStartMouseWheel(); + interactorStyle.handleMouseMove({ + position: { x: 10, y: 50 }, + pokedRenderer: renderer, + }); + interactorStyle.handleEndMouseWheel(); + + expect( + camera.getDistance(), + 'Make sure moving the mouse while the mouse wheel is handled leaves the camera unchanged.' + ).toEqual(distance); + expect(camera.getFocalPoint()).toEqual(focalPoint); +});