Skip to content

Commit 674d03b

Browse files
authored
Merge pull request #502 from agirault/pinch-manipulator
feat(cameraManipulator): expose pinch/scroll event to manipulators
2 parents ba74cac + b2a8194 commit 674d03b

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

Sources/Interaction/Manipulators/CameraManipulator/example/controller.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,18 @@
116116
</select>
117117
</td>
118118
</tr>
119+
<tr>
120+
<td>Scroll</td>
121+
<td>
122+
</td>
123+
<td>
124+
<select class='scrollMiddleButton' style="width: 100%">
125+
<option value='None'>None</option>
126+
<option value='Zoom'>Zoom</option>
127+
</select>
128+
</td>
129+
<td>
130+
</td>
131+
</tr>
119132
</tbody>
120133
</table>

Sources/Interaction/Manipulators/CameraManipulator/example/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const selectMap = {
6767
controlLeftButton: { button: 1, shift: false, control: true },
6868
controlMiddleButton: { button: 2, shift: false, control: true },
6969
controlRightButton: { button: 3, shift: false, control: true },
70+
scrollMiddleButton: { pinch: true },
7071
};
7172

7273
const manipulatorFactory = {
@@ -88,6 +89,7 @@ function reassignManipulators() {
8889
manipulator.setButton(selectMap[keyName].button);
8990
manipulator.setShift(selectMap[keyName].shift);
9091
manipulator.setControl(selectMap[keyName].control);
92+
manipulator.setPinch(selectMap[keyName].pinch);
9193
interactorStyle.addManipulator(manipulator);
9294
});
9395
}

Sources/Interaction/Manipulators/CameraManipulator/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const DEFAULT_VALUES = {
4343
center: [0, 0, 0],
4444
rotationFactor: 1,
4545
displayCenter: [0, 0],
46+
47+
pinch: false,
4648
};
4749

4850
// ----------------------------------------------------------------------------
@@ -61,6 +63,7 @@ export function extend(publicAPI, model, initialValues = {}) {
6163
'control',
6264
'alt',
6365
'rotationFactor',
66+
'pinch',
6467
]);
6568

6669
macro.setGetArray(publicAPI, model, ['displayCenter'], 2);

Sources/Interaction/Manipulators/TrackballZoom/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ function vtkTrackballZoom(publicAPI, model) {
7676
renderer.resetCameraClippingRange();
7777
}
7878
};
79+
80+
publicAPI.onPinch = (interactor) => {
81+
const { x, y } =
82+
interactor.getAnimationEventPosition(interactor.getPointerIndex()) ||
83+
DEFAULT_POSITION;
84+
const interactorStyle = interactor.getInteractorStyle();
85+
const renderer =
86+
interactorStyle.getCurrentRenderer() ||
87+
interactor.findPokedRenderer(x, y);
88+
89+
const camera = renderer.getActiveCamera();
90+
91+
const dyf = interactor.getScale() / interactor.getLastScale();
92+
93+
if (camera.getParallelProjection()) {
94+
camera.setParallelScale(camera.getParallelScale() / dyf);
95+
} else {
96+
camera.dolly(dyf);
97+
renderer.resetCameraClippingRange();
98+
}
99+
100+
if (interactor.getLightFollowCamera()) {
101+
renderer.updateLightsGeometryToFollowCamera();
102+
}
103+
};
79104
}
80105

81106
// ----------------------------------------------------------------------------

Sources/Interaction/Style/InteractorStyleManipulator/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,12 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
356356
}
357357
};
358358

359+
//-------------------------------------------------------------------------
359360
publicAPI.handlePinch = () => {
360361
model.cameraManipulators.filter((m) => m.onPinch).forEach((manipulator) => {
361-
manipulator.onPinch(model.interactor);
362+
if (manipulator && manipulator.getPinch()) {
363+
manipulator.onPinch(model.interactor);
364+
}
362365
});
363366
publicAPI.invokeInteractionEvent({ type: 'InteractionEvent' });
364367
};

0 commit comments

Comments
 (0)