@kitware/vtk.js 27.4.6 → 27.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.
|
@@ -3,8 +3,9 @@ var XrSessionTypes = {
|
|
|
3
3
|
// Head-mounted display (HMD), two-camera virtual reality session
|
|
4
4
|
MobileAR: 1,
|
|
5
5
|
// Mobile device, single-camera augmented reality session
|
|
6
|
-
LookingGlassVR: 2
|
|
7
|
-
|
|
6
|
+
LookingGlassVR: 2,
|
|
7
|
+
// Looking Glass hologram display, N-camera virtual reality session
|
|
8
|
+
HmdAR: 3
|
|
8
9
|
};
|
|
9
10
|
var Constants = {
|
|
10
11
|
XrSessionTypes: XrSessionTypes
|
|
@@ -26,17 +26,10 @@ var SCREENSHOT_PLACEHOLDER = {
|
|
|
26
26
|
height: '100%'
|
|
27
27
|
};
|
|
28
28
|
var DEFAULT_RESET_FACTORS = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
rescaleFactor: 0.25,
|
|
30
|
+
// isotropic scale factor reduces apparent size of objects
|
|
31
|
+
translateZ: -1.5 // default translation initializes object in front of camera
|
|
32
32
|
|
|
33
|
-
},
|
|
34
|
-
ar: {
|
|
35
|
-
rescaleFactor: 0.25,
|
|
36
|
-
// scale down AR for viewing comfort by default
|
|
37
|
-
translateZ: -0.5 // 0.5 m forward from the camera
|
|
38
|
-
|
|
39
|
-
}
|
|
40
33
|
};
|
|
41
34
|
|
|
42
35
|
function checkRenderTargetSupport(gl, format, type) {
|
|
@@ -274,11 +267,11 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
274
267
|
}
|
|
275
268
|
|
|
276
269
|
model.xrSessionType = xrSessionType !== undefined ? xrSessionType : XrSessionTypes.HmdVR;
|
|
277
|
-
var
|
|
278
|
-
var sessionType =
|
|
270
|
+
var isXrSessionAR = [XrSessionTypes.HmdAR, XrSessionTypes.MobileAR].includes(model.xrSessionType);
|
|
271
|
+
var sessionType = isXrSessionAR ? 'immersive-ar' : 'immersive-vr';
|
|
279
272
|
|
|
280
273
|
if (!navigator.xr.isSessionSupported(sessionType)) {
|
|
281
|
-
if (
|
|
274
|
+
if (isXrSessionAR) {
|
|
282
275
|
throw new Error('Device does not support AR session');
|
|
283
276
|
} else {
|
|
284
277
|
throw new Error('VR display is not available');
|
|
@@ -298,7 +291,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
298
291
|
|
|
299
292
|
publicAPI.enterXR = /*#__PURE__*/function () {
|
|
300
293
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(xrSession) {
|
|
301
|
-
var gl, glLayer;
|
|
294
|
+
var gl, glLayer, isXrSessionAR, ren;
|
|
302
295
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
303
296
|
while (1) {
|
|
304
297
|
switch (_context.prev = _context.next) {
|
|
@@ -307,7 +300,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
307
300
|
model.oldCanvasSize = model.size.slice();
|
|
308
301
|
|
|
309
302
|
if (!(model.xrSession !== null)) {
|
|
310
|
-
_context.next =
|
|
303
|
+
_context.next = 17;
|
|
311
304
|
break;
|
|
312
305
|
}
|
|
313
306
|
|
|
@@ -324,17 +317,26 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
324
317
|
});
|
|
325
318
|
model.xrSession.requestReferenceSpace('local').then(function (refSpace) {
|
|
326
319
|
model.xrReferenceSpace = refSpace;
|
|
327
|
-
});
|
|
320
|
+
}); // Initialize transparent background for augmented reality session
|
|
321
|
+
|
|
322
|
+
isXrSessionAR = [XrSessionTypes.HmdAR, XrSessionTypes.MobileAR].includes(model.xrSessionType);
|
|
323
|
+
|
|
324
|
+
if (isXrSessionAR) {
|
|
325
|
+
ren = model.renderable.getRenderers()[0];
|
|
326
|
+
model.preXrSessionBackground = ren.getBackground();
|
|
327
|
+
ren.setBackground([0, 0, 0, 0]);
|
|
328
|
+
}
|
|
329
|
+
|
|
328
330
|
publicAPI.resetXRScene();
|
|
329
331
|
model.renderable.getInteractor().switchToXRAnimation();
|
|
330
332
|
model.xrSceneFrame = model.xrSession.requestAnimationFrame(publicAPI.xrRender);
|
|
331
|
-
_context.next =
|
|
333
|
+
_context.next = 18;
|
|
332
334
|
break;
|
|
333
335
|
|
|
334
|
-
case
|
|
335
|
-
throw new Error('Failed to enter
|
|
336
|
+
case 17:
|
|
337
|
+
throw new Error('Failed to enter XR with a null xrSession.');
|
|
336
338
|
|
|
337
|
-
case
|
|
339
|
+
case 18:
|
|
338
340
|
case "end":
|
|
339
341
|
return _context.stop();
|
|
340
342
|
}
|
|
@@ -348,32 +350,17 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
348
350
|
}();
|
|
349
351
|
|
|
350
352
|
publicAPI.resetXRScene = function () {
|
|
351
|
-
var
|
|
352
|
-
var
|
|
353
|
+
var rescaleFactor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_RESET_FACTORS.rescaleFactor;
|
|
354
|
+
var translateZ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_RESET_FACTORS.translateZ;
|
|
353
355
|
// Adjust world-to-physical parameters for different modalities
|
|
354
|
-
// Default parameter values are for HMD VR
|
|
355
|
-
var rescaleFactor = inputRescaleFactor;
|
|
356
|
-
var translateZ = inputTranslateZ;
|
|
357
|
-
var isXrSessionAR = model.xrSessionType === XrSessionTypes.MobileAR;
|
|
358
|
-
|
|
359
|
-
if (isXrSessionAR && rescaleFactor === DEFAULT_RESET_FACTORS.vr.rescaleFactor) {
|
|
360
|
-
// Scale down by default in AR
|
|
361
|
-
rescaleFactor = DEFAULT_RESET_FACTORS.ar.rescaleFactor;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (isXrSessionAR && translateZ === DEFAULT_RESET_FACTORS.vr.translateZ) {
|
|
365
|
-
// Default closer to the camera in AR
|
|
366
|
-
translateZ = DEFAULT_RESET_FACTORS.ar.translateZ;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
356
|
var ren = model.renderable.getRenderers()[0];
|
|
370
357
|
ren.resetCamera();
|
|
371
358
|
var camera = ren.getActiveCamera();
|
|
372
359
|
var physicalScale = camera.getPhysicalScale();
|
|
373
360
|
var physicalTranslation = camera.getPhysicalTranslation();
|
|
361
|
+
var rescaledTranslateZ = translateZ * physicalScale;
|
|
374
362
|
physicalScale /= rescaleFactor;
|
|
375
|
-
|
|
376
|
-
physicalTranslation[2] += translateZ;
|
|
363
|
+
physicalTranslation[2] += rescaledTranslateZ;
|
|
377
364
|
camera.setPhysicalScale(physicalScale);
|
|
378
365
|
camera.setPhysicalTranslation(physicalTranslation); // Clip at 0.1m, 100.0m in physical space by default
|
|
379
366
|
|
|
@@ -420,12 +407,18 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
420
407
|
|
|
421
408
|
|
|
422
409
|
ren = model.renderable.getRenderers()[0];
|
|
410
|
+
|
|
411
|
+
if (model.preXrSessionBackground != null) {
|
|
412
|
+
ren.setBackground(model.preXrSessionBackground);
|
|
413
|
+
model.preXrSessionBackground = null;
|
|
414
|
+
}
|
|
415
|
+
|
|
423
416
|
ren.getActiveCamera().setProjectionMatrix(null);
|
|
424
417
|
ren.resetCamera();
|
|
425
418
|
ren.setViewport(0.0, 0, 1.0, 1.0);
|
|
426
419
|
publicAPI.traverseAllPasses();
|
|
427
420
|
|
|
428
|
-
case
|
|
421
|
+
case 17:
|
|
429
422
|
case "end":
|
|
430
423
|
return _context2.stop();
|
|
431
424
|
}
|
|
@@ -435,12 +428,13 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
435
428
|
|
|
436
429
|
publicAPI.xrRender = /*#__PURE__*/function () {
|
|
437
430
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(t, frame) {
|
|
438
|
-
var xrSession, xrPose, gl, glLayer, ren;
|
|
431
|
+
var xrSession, isXrSessionHMD, xrPose, gl, glLayer, ren;
|
|
439
432
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
440
433
|
while (1) {
|
|
441
434
|
switch (_context3.prev = _context3.next) {
|
|
442
435
|
case 0:
|
|
443
436
|
xrSession = frame.session;
|
|
437
|
+
isXrSessionHMD = [XrSessionTypes.HmdVR, XrSessionTypes.HmdAR].includes(model.xrSessionType);
|
|
444
438
|
model.renderable.getInteractor().updateXRGamepads(xrSession, frame, model.xrReferenceSpace);
|
|
445
439
|
model.xrSceneFrame = model.xrSession.requestAnimationFrame(publicAPI.xrRender);
|
|
446
440
|
xrPose = frame.getViewerPose(model.xrReferenceSpace);
|
|
@@ -462,10 +456,9 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
462
456
|
ren = model.renderable.getRenderers()[0]; // Do a render pass for each eye
|
|
463
457
|
|
|
464
458
|
xrPose.views.forEach(function (view, index) {
|
|
465
|
-
var viewport = glLayer.getViewport(view);
|
|
466
|
-
// with two eyes will require further investigation.
|
|
459
|
+
var viewport = glLayer.getViewport(view);
|
|
467
460
|
|
|
468
|
-
if (
|
|
461
|
+
if (isXrSessionHMD) {
|
|
469
462
|
if (view.eye === 'left') {
|
|
470
463
|
ren.setViewport(0, 0, 0.5, 1.0);
|
|
471
464
|
} else if (view.eye === 'right') {
|
|
@@ -494,7 +487,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
494
487
|
gl.disable(gl.SCISSOR_TEST);
|
|
495
488
|
}
|
|
496
489
|
|
|
497
|
-
case
|
|
490
|
+
case 6:
|
|
498
491
|
case "end":
|
|
499
492
|
return _context3.stop();
|
|
500
493
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitware/vtk.js",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.5.0",
|
|
4
4
|
"description": "Visualization Toolkit for the Web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"3d",
|
|
@@ -144,7 +144,8 @@
|
|
|
144
144
|
"doc:publish": "kw-doc -c ./Documentation/config.js -mp",
|
|
145
145
|
"doc:generate-api": "node ./Documentation/generate-api-docs.js",
|
|
146
146
|
"example": "node ./Utilities/ExampleRunner/example-runner-cli.js -c ./Documentation/config.js",
|
|
147
|
-
"example:
|
|
147
|
+
"example:https": "node ./Utilities/ExampleRunner/example-runner-cli.js --server-type https -c ./Documentation/config.js",
|
|
148
|
+
"example:webgpu": "cross-env WEBGPU=1 NO_WEBGL=1 node ./Utilities/ExampleRunner/example-runner-cli.js --server-type https -c ./Documentation/config.js",
|
|
148
149
|
"dev:esm": "npm run build:esm -- -w",
|
|
149
150
|
"dev:umd": "webpack --watch --config webpack.dev.js --progress",
|
|
150
151
|
"build": "npm run build:release",
|