Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Sources/Rendering/Core/RenderWindowInteractor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const handledEvents = [
'StartInteraction',
'Interaction',
'EndInteraction',
'StartXrSelect',
'XrSelect',
'EndXrSelect',
'StartXrSqueeze',
'XrSqueeze',
'EndXrSqueeze',
Comment on lines +62 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think capitalizing the 'R' in 'XR' for consistency is a good idea here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still relevant?

];

function preventDefault(event) {
Expand Down Expand Up @@ -247,6 +253,16 @@ function vtkRenderWindowInteractor(publicAPI, model) {
container.addEventListener('touchstart', publicAPI.handleTouchStart, false);
};

publicAPI.bindXREvents = (xrSession) => {
model.xrSession = xrSession;
xrSession.addEventListener('selectstart', publicAPI.handleXRSelectStart);
xrSession.addEventListener('select', publicAPI.handleXRSelect);
xrSession.addEventListener('selectend', publicAPI.handleXRSelectEnd);
xrSession.addEventListener('squeezestart', publicAPI.handleXRSqueezeStart);
xrSession.addEventListener('squeeze', publicAPI.handleXRSqueeze);
xrSession.addEventListener('squeezeend', publicAPI.handleXRSqueezeEnd);
};

publicAPI.unbindEvents = () => {
// force unbinding listeners
interactionRegistration(false, true);
Expand Down Expand Up @@ -281,6 +297,28 @@ function vtkRenderWindowInteractor(publicAPI, model) {
model.container = null;
};

publicAPI.unbindXREvents = () => {
model.xrSession.removeEventListener(
'selectstart',
publicAPI.handleXRSelectStart
);
model.xrSession.removeEventListener('select', publicAPI.handleXRSelect);
model.xrSession.removeEventListener(
'selectend',
publicAPI.handleXRSelectEnd
);
model.xrSession.removeEventListener(
'squeezestart',
publicAPI.handleXRSqueezeStart
);
model.xrSession.removeEventListener('squeeze', publicAPI.handleXRSqueeze);
model.xrSession.removeEventListener(
'squeezeend',
publicAPI.handleXRSqueezeEnd
);
model.xrSession = null;
};

publicAPI.handleKeyPress = (event) => {
const data = getKeysFor(event);
publicAPI.keyPressEvent(data);
Expand Down Expand Up @@ -325,6 +363,26 @@ function vtkRenderWindowInteractor(publicAPI, model) {
}
};

publicAPI.handleXRSelect = (event) => {
publicAPI.xrSelectEvent({ xrEvent: event });
};

publicAPI.handleXRSelectStart = (event) => {
publicAPI.startXrSelectEvent({ xrEvent: event });
};
publicAPI.handleXRSelectEnd = (event) => {
publicAPI.endXrSelectEvent({ xrEvent: event });
};
publicAPI.handleXRSqueezeStart = (event) => {
publicAPI.startXrSqueezeEvent({ xrEvent: event });
};
publicAPI.handleXRSqueeze = (event) => {
publicAPI.xrSqueezeEvent({ xrEvent: event });
};
publicAPI.handleXRSqueezeEnd = (event) => {
publicAPI.endXrSqueezeEvent({ xrEvent: event });
};

//----------------------------------------------------------------------
publicAPI.requestPointerLock = () => {
const canvas = publicAPI.getView().getCanvas();
Expand Down Expand Up @@ -1036,6 +1094,7 @@ const DEFAULT_VALUES = {
wheelTimeoutID: 0,
moveTimeoutID: 0,
lastGamepadValues: {},
xrSession: null,
};

// ----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions Sources/Rendering/OpenGL/RenderWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
model.xrSession = xrSession;
model.oldCanvasSize = model.size.slice();

model.renderable.getInteractor().bindXREvents(xrSession);

if (model.xrSession !== null) {
const gl = publicAPI.get3DContext();
await gl.makeXRCompatible();
Expand Down Expand Up @@ -384,6 +386,8 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
}

if (model.xrSession !== null) {
model.renderable.getInteractor().unbindXREvents();

model.xrSession.cancelAnimationFrame(model.xrSceneFrame);
model.renderable.getInteractor().returnFromXRAnimation();
const gl = publicAPI.get3DContext();
Expand Down