forked from Kitware/vtk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (70 loc) · 2.64 KB
/
index.js
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
import macro from 'vtk.js/Sources/macro';
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';
// ----------------------------------------------------------------------------
// vtkVRButtonPanManipulator methods
// ----------------------------------------------------------------------------
function vtkVRButtonPanManipulator(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkVRButtonPanManipulator');
publicAPI.onButton3D = (
interactorStyle,
renderer,
state,
device,
input,
pressed
) => {
if (pressed) {
interactorStyle.startCameraPose();
} else if (state === States.IS_CAMERA_POSE) {
interactorStyle.endCameraPose();
}
};
publicAPI.onMove3D = (interactorStyle, renderer, state, data) => {
if (state !== States.IS_CAMERA_POSE) {
return;
}
// move the world in the direction of the
// controller
const camera = renderer.getActiveCamera();
const oldTrans = camera.getPhysicalTranslation();
// look at the y axis to determine how fast / what direction to move
const speed = data.gamepad.axes[1];
// 0.05 meters / frame movement
const pscale = speed * 0.05 / camera.getPhysicalScale();
// convert orientation to world coordinate direction
const dir = camera.physicalOrientationToWorldDirection(data.orientation);
camera.setPhysicalTranslation(
oldTrans[0] + dir[0] * pscale,
oldTrans[1] + dir[1] * pscale,
oldTrans[2] + dir[2] * pscale
);
};
}
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
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);
// Object specific methods
vtkVRButtonPanManipulator(publicAPI, model);
}
// ----------------------------------------------------------------------------
export const newInstance = macro.newInstance(
extend,
'vtkVRButtonPanManipulator'
);
// ----------------------------------------------------------------------------
export default Object.assign({ newInstance, extend });