@kitware/vtk.js 21.4.1 → 21.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -245,21 +245,28 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
245
245
  // typically in response to a user request such as a button press
246
246
 
247
247
 
248
- publicAPI.startXR = function () {
248
+ publicAPI.startXR = function (isAR) {
249
249
  if (navigator.xr === undefined) {
250
250
  throw new Error('WebXR is not available');
251
251
  }
252
252
 
253
- if (!navigator.xr.isSessionSupported('immersive-vr')) {
254
- throw new Error('VR display is not available');
253
+ model.xrSessionIsAR = isAR;
254
+ var sessionType = isAR ? 'immersive-ar' : 'immersive-vr';
255
+
256
+ if (!navigator.xr.isSessionSupported(sessionType)) {
257
+ if (isAR) {
258
+ throw new Error('Device does not support AR session');
259
+ } else {
260
+ throw new Error('VR display is not available');
261
+ }
255
262
  }
256
263
 
257
264
  if (model.xrSession === null) {
258
- navigator.xr.requestSession('immersive-vr').then(publicAPI.enterXR, function () {
259
- throw new Error('Failed to create VR session!');
265
+ navigator.xr.requestSession(sessionType).then(publicAPI.enterXR, function () {
266
+ throw new Error('Failed to create XR session!');
260
267
  });
261
268
  } else {
262
- throw new Error('VR Session already exists!');
269
+ throw new Error('XR Session already exists!');
263
270
  }
264
271
  }; // When an XR session is available, set up the XRWebGLLayer
265
272
  // and request the first animation frame for the device
@@ -348,7 +355,10 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
348
355
  model.xrSession = null;
349
356
 
350
357
  case 10:
351
- publicAPI.setSize.apply(publicAPI, _toConsumableArray(model.oldCanvasSize)); // Reset to default canvas
358
+ if (model.oldCanvasSize !== undefined) {
359
+ publicAPI.setSize.apply(publicAPI, _toConsumableArray(model.oldCanvasSize));
360
+ } // Reset to default canvas
361
+
352
362
 
353
363
  ren = model.renderable.getRenderers()[0];
354
364
  ren.getActiveCamera().setProjectionMatrix(null);
@@ -378,6 +388,12 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
378
388
 
379
389
  if (xrPose) {
380
390
  gl = publicAPI.get3DContext();
391
+
392
+ if (model.xrSessionIsAR && model.oldCanvasSize !== undefined) {
393
+ gl.canvas.width = model.oldCanvasSize[0];
394
+ gl.canvas.height = model.oldCanvasSize[1];
395
+ }
396
+
381
397
  glLayer = xrSession.renderState.baseLayer;
382
398
  gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
383
399
  gl.clear(gl.COLOR_BUFFER_BIT);
@@ -387,15 +403,18 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
387
403
 
388
404
  xrPose.views.forEach(function (view) {
389
405
  var viewport = glLayer.getViewport(view);
390
- gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
391
-
392
- if (view.eye === 'left') {
393
- ren.setViewport(0, 0, 0.5, 1.0);
394
- } else if (view.eye === 'right') {
395
- ren.setViewport(0.5, 0, 1.0, 1.0);
396
- } else {
397
- // No handling for non-eye viewport
398
- return;
406
+ gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); // TODO: Appropriate handling for AR passthrough on HMDs
407
+ // with two eyes will require further investigation.
408
+
409
+ if (!model.xrSessionIsAR) {
410
+ if (view.eye === 'left') {
411
+ ren.setViewport(0, 0, 0.5, 1.0);
412
+ } else if (view.eye === 'right') {
413
+ ren.setViewport(0.5, 0, 1.0, 1.0);
414
+ } else {
415
+ // No handling for non-eye viewport
416
+ return;
417
+ }
399
418
  }
400
419
 
401
420
  ren.getActiveCamera().computeViewParametersFromPhysicalMatrix(view.transform.inverse.matrix);
@@ -777,7 +796,9 @@ var DEFAULT_VALUES = {
777
796
  // attempt webgl2 on by default
778
797
  activeFramebuffer: null,
779
798
  xrSession: null,
799
+ xrSessionIsAR: false,
780
800
  xrReferenceSpace: null,
801
+ xrSupported: true,
781
802
  imageFormat: 'image/png',
782
803
  useOffScreen: false,
783
804
  useBackgroundImage: false
@@ -820,7 +841,7 @@ function extend(publicAPI, model) {
820
841
  macro.event(publicAPI, model, 'imageReady');
821
842
  macro.event(publicAPI, model, 'haveVRDisplay'); // Build VTK API
822
843
 
823
- macro.get(publicAPI, model, ['shaderCache', 'textureUnitManager', 'webgl2', 'vrDisplay', 'useBackgroundImage']);
844
+ macro.get(publicAPI, model, ['shaderCache', 'textureUnitManager', 'webgl2', 'vrDisplay', 'useBackgroundImage', 'xrSupported']);
824
845
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'renderPasses', 'notifyStartCaptureImage', 'defaultToWebgl2', 'cursor', 'useOffScreen', // might want to make this not call modified as
825
846
  // we change the active framebuffer a lot. Or maybe
826
847
  // only mark modified if the size or depth
@@ -616,7 +616,8 @@ var DEFAULT_VALUES = {
616
616
  imageFormat: 'image/png',
617
617
  useOffScreen: false,
618
618
  useBackgroundImage: false,
619
- nextPropID: 1
619
+ nextPropID: 1,
620
+ xrSupported: false
620
621
  }; // ----------------------------------------------------------------------------
621
622
 
622
623
  function extend(publicAPI, model) {
@@ -652,7 +653,7 @@ function extend(publicAPI, model) {
652
653
  macro.event(publicAPI, model, 'imageReady');
653
654
  macro.event(publicAPI, model, 'initialized'); // Build VTK API
654
655
 
655
- macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage']);
656
+ macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage', 'xrSupported']);
656
657
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'device', 'renderPasses', 'notifyStartCaptureImage', 'cursor', 'useOffScreen']);
657
658
  macro.setGetArray(publicAPI, model, ['size'], 2); // Object methods
658
659
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "21.4.1",
3
+ "version": "21.5.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",