Skip to content

Commit 4f1dda2

Browse files
authored
Merge branch 'master' into webgpu_update_jan22
2 parents 8e332b6 + 1594f65 commit 4f1dda2

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Please follow the coding style:
6262
If committing changes to `vtk.js@next` or `vtk.js@next-major`, then set your base branch to be `next`
6363
or `next-major`, respectively. For more info see the section on release channels below.
6464

65-
8. vtk.js uses GitHub for code review and Travis-CI to test proposed patches before they are merged.
65+
8. vtk.js uses GitHub for code review and Github Actions to validate proposed patches before they are merged.
6666

6767
## Release Channels
6868

@@ -110,7 +110,7 @@ you are satisfied with the staging branch changes, you can then merge into eithe
110110

111111
To create and debug a test:
112112
- Create a testFuncNameToTest.js in a "test" folder of the class to test.
113-
- Add the test path into Sources/tests.js and temporarily comment the other tests
113+
- If you want to run just your test, use `test.only(...)` instead of `test(...)`.
114114
- Run `npm run test:debug`
115115
- In the opened window, click the Debug button and place breakpoints in browser debugger.
116116

Sources/Rendering/OpenGL/RenderWindow/index.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ const SCREENSHOT_PLACEHOLDER = {
1919
height: '100%',
2020
};
2121

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+
2233
function checkRenderTargetSupport(gl, format, type) {
2334
// create temporary frame buffer and texture
2435
const framebuffer = gl.createFramebuffer();
@@ -315,6 +326,8 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
315326
model.xrReferenceSpace = refSpace;
316327
});
317328

329+
publicAPI.resetXRScene();
330+
318331
model.renderable.getInteractor().switchToXRAnimation();
319332
model.xrSceneFrame = model.xrSession.requestAnimationFrame(
320333
publicAPI.xrRender
@@ -324,6 +337,46 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
324337
}
325338
};
326339

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+
327380
publicAPI.stopXR = async () => {
328381
if (navigator.xr === undefined) {
329382
// WebXR polyfill not available so nothing to do

0 commit comments

Comments
 (0)