From 12d0f631b41db4f85a1fdc541d66653dd95fb300 Mon Sep 17 00:00:00 2001 From: Jules BOURDAIS Date: Wed, 20 Mar 2024 15:28:17 +0100 Subject: [PATCH] fix(3d interactions): update doc and TS definitions --- .../index.d.ts | 19 ++++++++++++++ .../index.js | 4 ++- .../CompositeVRManipulator/index.d.ts | 18 ++++++------- .../CompositeVRManipulator/index.js | 18 ++----------- .../VRButtonPanManipulator/index.js | 19 +++++--------- .../Style/InteractorStyleHMDXR/index.d.ts | 22 ++++++++++++++++ .../Core/RenderWindowInteractor/index.d.ts | 26 +++++++++++++++---- 7 files changed, 83 insertions(+), 43 deletions(-) create mode 100644 Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.d.ts create mode 100644 Sources/Interaction/Style/InteractorStyleHMDXR/index.d.ts diff --git a/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.d.ts b/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.d.ts new file mode 100644 index 00000000000..b16405e40c2 --- /dev/null +++ b/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.d.ts @@ -0,0 +1,19 @@ +import vtkCompositeVRManipulator from '../CompositeVRManipulator'; + +export interface vtk3DControllerModelSelectorManipulator + extends vtkCompositeVRManipulator {} + +export interface I3DControllerModelSelectorManipulatorInitialValues + extends vtkCompositeVRManipulator {} + +export function extend( + publicAPI: object, + model: object, + initialValues?: I3DControllerModelSelectorManipulatorInitialValues +): void; + +export const vtk3DControllerModelSelectorManipulator: { + extend: typeof extend; +}; + +export default vtk3DControllerModelSelectorManipulator; diff --git a/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.js b/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.js index ce5f5c44728..0dae652938a 100644 --- a/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.js +++ b/Sources/Interaction/Manipulators/3DControllerModelSelectorManipulator/index.js @@ -115,6 +115,8 @@ function vtk3DControllerModelSelectorManipulator(publicAPI, model) { const camera = renderer.getActiveCamera(); camera.getPhysicalToWorldMatrix(physicalToWorldMatrix); + const { targetPosition, targetOrientation } = eventData; + // Since targetPosition is in physical coordinates, // transform it using the physicalToWorldMatrix to get it in world coordinates const targetRayWorldPosition = vec3.transformMat4( @@ -160,7 +162,7 @@ function vtk3DControllerModelSelectorManipulator(publicAPI, model) { const currentTargetRayWorldPosition = new Float64Array(3); const currentTargetRayOrientation = new Float64Array(4); - publicAPI.onMove3D = (_interactorStyle, renderer, _state, eventData) => { + publicAPI.onMove3D = (interactorStyle, renderer, state, eventData) => { // If we are not interacting with any prop, we have nothing to do. // Also check for dragable if (state !== States.IS_CAMERA_POSE || pickedProp == null) { diff --git a/Sources/Interaction/Manipulators/CompositeVRManipulator/index.d.ts b/Sources/Interaction/Manipulators/CompositeVRManipulator/index.d.ts index 625cf5edb3e..f33f17b7316 100644 --- a/Sources/Interaction/Manipulators/CompositeVRManipulator/index.d.ts +++ b/Sources/Interaction/Manipulators/CompositeVRManipulator/index.d.ts @@ -1,28 +1,28 @@ import { States } from '../../../Rendering/Core/InteractorStyle/Constants'; import vtkRenderer from '../../../Rendering/Core/Renderer'; -import vtkRenderWindowInteractor from '../../../Rendering/Core/RenderWindowInteractor'; +import vtkInteractorObserver from '../../../Rendering/Core/InteractorObserver'; import { Device, Input, } from '../../../Rendering/Core/RenderWindowInteractor/Constants'; +import { + I3DEvent, + IButton3DEvent, +} from '../../../Rendering/Core/RenderWindowInteractor'; export interface vtkCompositeVRManipulator { onButton3D( - interactor: vtkRenderWindowInteractor, + interactorStyle: vtkInteractorObserver, renderer: vtkRenderer, state: States, - device: Device, - input: Input, - pressed: boolean + eventData: IButton3DEvent ): void; onMove3D( - interactor: vtkRenderWindowInteractor, + interactorStyle: vtkInteractorObserver, renderer: vtkRenderer, state: States, - device: Device, - input: Input, - pressed: boolean + eventData: I3DEvent ): void; } diff --git a/Sources/Interaction/Manipulators/CompositeVRManipulator/index.js b/Sources/Interaction/Manipulators/CompositeVRManipulator/index.js index f28aa5240da..a01d6907935 100644 --- a/Sources/Interaction/Manipulators/CompositeVRManipulator/index.js +++ b/Sources/Interaction/Manipulators/CompositeVRManipulator/index.js @@ -12,22 +12,8 @@ function vtkCompositeVRManipulator(publicAPI, model) { // Set our className model.classHierarchy.push('vtkCompositeVRManipulator'); - publicAPI.onButton3D = ( - interactor, - renderer, - state, - device, - input, - pressed - ) => {}; - publicAPI.onMove3D = ( - interactor, - renderer, - state, - device, - input, - pressed - ) => {}; + publicAPI.onButton3D = (interactorStyle, renderer, state, eventData) => {}; + publicAPI.onMove3D = (interactorStyle, renderer, state, eventData) => {}; } // ---------------------------------------------------------------------------- diff --git a/Sources/Interaction/Manipulators/VRButtonPanManipulator/index.js b/Sources/Interaction/Manipulators/VRButtonPanManipulator/index.js index 40e5eee43c8..7982c896f10 100644 --- a/Sources/Interaction/Manipulators/VRButtonPanManipulator/index.js +++ b/Sources/Interaction/Manipulators/VRButtonPanManipulator/index.js @@ -14,22 +14,15 @@ function vtkVRButtonPanManipulator(publicAPI, model) { // Set our className model.classHierarchy.push('vtkVRButtonPanManipulator'); - publicAPI.onButton3D = ( - interactorStyle, - renderer, - state, - device, - input, - pressed - ) => { - if (pressed) { + 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, data) => { + publicAPI.onMove3D = (interactorStyle, renderer, state, eventData) => { if (state !== States.IS_CAMERA_POSE) { return; } @@ -40,13 +33,15 @@ function vtkVRButtonPanManipulator(publicAPI, model) { const oldTrans = camera.getPhysicalTranslation(); // look at the y axis to determine how fast / what direction to move - const speed = data.gamepad.axes[1]; + const speed = eventData.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); + const dir = camera.physicalOrientationToWorldDirection( + eventData.orientation + ); camera.setPhysicalTranslation( oldTrans[0] + dir[0] * pscale, diff --git a/Sources/Interaction/Style/InteractorStyleHMDXR/index.d.ts b/Sources/Interaction/Style/InteractorStyleHMDXR/index.d.ts new file mode 100644 index 00000000000..6605756b5ad --- /dev/null +++ b/Sources/Interaction/Style/InteractorStyleHMDXR/index.d.ts @@ -0,0 +1,22 @@ +import vtkInteractorStyleManipulator, { IInteractorStyleManipulatorInitialValues } from '../../../Interaction/Style/InteractorStyleManipulator'; + +export interface vtkInteractorStyleHMDXR extends vtkInteractorStyleManipulator {} + +export interface IInteractorStyleHMDXRInitialValues extends IInteractorStyleManipulatorInitialValues {} + +export function newInstance( + initialValues?: IInteractorStyleHMDXRInitialValues +): vtkInteractorStyleHMDXR; + +export function extend( + publicAPI: object, + model: object, + initialValues?: IInteractorStyleHMDXRInitialValues +): void; + +export const vtkInteractorStyleHMDXR: { + newInstance: typeof newInstance; + extend: typeof extend; +}; + +export default vtkInteractorStyleHMDXR; diff --git a/Sources/Rendering/Core/RenderWindowInteractor/index.d.ts b/Sources/Rendering/Core/RenderWindowInteractor/index.d.ts index 5404690aef4..1cc8bb5a722 100755 --- a/Sources/Rendering/Core/RenderWindowInteractor/index.d.ts +++ b/Sources/Rendering/Core/RenderWindowInteractor/index.d.ts @@ -81,6 +81,20 @@ export interface IRenderWindowInteractorEvent { type: InteractorEventType; } +export interface I3DEvent { + gamepad: Gamepad; + position: DOMPointReadOnly; + orientation: DOMPointReadOnly; + targetPosition: DOMPointReadOnly; + targetOrientation: DOMPointReadOnly; + device: Device; +} + +export interface IButton3DEvent extends I3DEvent { + pressed: boolean; + input: Input; +} + export interface vtkRenderWindowInteractor extends vtkObject { /** @@ -678,10 +692,11 @@ export interface vtkRenderWindowInteractor extends vtkObject { animationEvent(args: any): any; /** - * + * Triggers the 'Button3D' event. + * * @param args */ - button3DEvent(args: any): any; + button3DEvent(eventPayload: IButton3DEvent): void; /** * @@ -804,10 +819,11 @@ export interface vtkRenderWindowInteractor extends vtkObject { mouseWheelEvent(args: any): any; /** - * - * @param args + * Triggers the 'Move3D' event. + * + * @param eventPayload */ - move3DEvent(args: any): any; + move3DEvent(eventPayload: I3DEvent): void; /** *