@@ -19,6 +19,17 @@ const SCREENSHOT_PLACEHOLDER = {
19
19
height : '100%' ,
20
20
} ;
21
21
22
+ const DEFAULT_RESET_FACTORS = {
23
+ vr : {
24
+ rescaleFactor : 1.0 ,
25
+ translateZ : - 0.7 , // 0.7 m forward from the camera
26
+ } ,
27
+ ar : {
28
+ rescaleFactor : 0.25 , // scale down AR for viewing comfort by default
29
+ translateZ : - 0.5 , // 0.5 m forward from the camera
30
+ } ,
31
+ } ;
32
+
22
33
function checkRenderTargetSupport ( gl , format , type ) {
23
34
// create temporary frame buffer and texture
24
35
const framebuffer = gl . createFramebuffer ( ) ;
@@ -315,6 +326,8 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
315
326
model . xrReferenceSpace = refSpace ;
316
327
} ) ;
317
328
329
+ publicAPI . resetXRScene ( ) ;
330
+
318
331
model . renderable . getInteractor ( ) . switchToXRAnimation ( ) ;
319
332
model . xrSceneFrame = model . xrSession . requestAnimationFrame (
320
333
publicAPI . xrRender
@@ -324,6 +337,46 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
324
337
}
325
338
} ;
326
339
340
+ publicAPI . resetXRScene = (
341
+ inputRescaleFactor = DEFAULT_RESET_FACTORS . vr . rescaleFactor ,
342
+ inputTranslateZ = DEFAULT_RESET_FACTORS . vr . translateZ
343
+ ) => {
344
+ // Adjust world-to-physical parameters for different modalities
345
+ // Default parameter values are for VR (model.xrSessionIsAR == false)
346
+ let rescaleFactor = inputRescaleFactor ;
347
+ let translateZ = inputTranslateZ ;
348
+
349
+ if (
350
+ model . xrSessionIsAR &&
351
+ rescaleFactor === DEFAULT_RESET_FACTORS . vr . rescaleFactor
352
+ ) {
353
+ // Scale down by default in AR
354
+ rescaleFactor = DEFAULT_RESET_FACTORS . ar . rescaleFactor ;
355
+ }
356
+
357
+ if (
358
+ model . xrSessionIsAR &&
359
+ translateZ === DEFAULT_RESET_FACTORS . vr . translateZ
360
+ ) {
361
+ // Default closer to the camera in AR
362
+ translateZ = DEFAULT_RESET_FACTORS . ar . translateZ ;
363
+ }
364
+
365
+ const ren = model . renderable . getRenderers ( ) [ 0 ] ;
366
+ ren . resetCamera ( ) ;
367
+
368
+ const camera = ren . getActiveCamera ( ) ;
369
+ let physicalScale = camera . getPhysicalScale ( ) ;
370
+ const physicalTranslation = camera . getPhysicalTranslation ( ) ;
371
+
372
+ physicalScale /= rescaleFactor ;
373
+ translateZ *= physicalScale ;
374
+ physicalTranslation [ 2 ] += translateZ ;
375
+
376
+ camera . setPhysicalScale ( physicalScale ) ;
377
+ camera . setPhysicalTranslation ( physicalTranslation ) ;
378
+ } ;
379
+
327
380
publicAPI . stopXR = async ( ) => {
328
381
if ( navigator . xr === undefined ) {
329
382
// WebXR polyfill not available so nothing to do
0 commit comments