Skip to content

Commit

Permalink
fix(3d interactions): update doc and TS definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
bourdaisj authored and finetjul committed Mar 22, 2024
1 parent 60cc0f9 commit 12d0f63
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
18 changes: 2 additions & 16 deletions Sources/Interaction/Manipulators/CompositeVRManipulator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {};
}

// ----------------------------------------------------------------------------
Expand Down
19 changes: 7 additions & 12 deletions Sources/Interaction/Manipulators/VRButtonPanManipulator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions Sources/Interaction/Style/InteractorStyleHMDXR/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
26 changes: 21 additions & 5 deletions Sources/Rendering/Core/RenderWindowInteractor/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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;

/**
*
Expand Down

0 comments on commit 12d0f63

Please sign in to comment.