Description
When calling navigator.xr.isSessionSupported
you can optionally pass features as part of the options
optional parameter. See.
Some optional parameters such as hand tracking add new methods to the interface, in this case navigator.xr.hand
. Currently there is no way to test if the current device supports various features without running a null test, which is an antipattern.
navigator.xr.isSessionSupported("immersive-vr"); // This example assumes the answer here is true, this should not be done normally
navigator.xr.requestSession("immsersive-vr", { optionalFeatures: [ "hand-tracking" ] });
// This is bad
const has_hand_tracking = typeof navigator.xr.hand !== "undefined" || !navigator.xr.hand;
What should be supported is either options
as a part of isSessionSupported or a new function isFeatureSupported(feature: string[]): boolean
.
navigator.xr.isSessionSupported("immsersive-vr");
navigator.xr.requestSession("immsersive-vr", { optionalFeatures: [ "hand-tracking" ] });
// Option 1
const has_hand_tracking = navigator.xr.isSessionSupported("immsersive-vr", [ "hand-tracking" ]);
// Option 2
const has_hand_tracking = navigator.xr.isFeatureSupported([ "hand-tracking" ]);
This allows developers to create apps that support features that are not available on all headsets/controllers. In this example the developer could render fully tracked hands if the feature is available or hands in preset poses based on the triggers squeezed.
const has_hand_tracking = navigator.xr.isFeatureSupported([ "hand-tracking" ]);
function render_hand() {
if(has_hand_tracking) {
// ...
} else {
switch(triggers) {
// ...
}
}
}