Polyfill.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. if( 'xr' in navigator ) {
  2. console.log('Helio: Chrome m73 WebXR Polyfill:', navigator.xr);
  3. // WebXRManager - XR.supportSession() Polyfill - WebVR.js line 147
  4. navigator.xr.supportsSession = navigator.xr.supportsSessionMode;
  5. if( 'supportsSessionMode' in navigator.xr ) {
  6. const temp = navigator.xr.requestSession.bind(navigator.xr);
  7. navigator.xr.requestSession = function (sessionType) {
  8. return new Promise((resolve, reject) => {
  9. temp({ mode: sessionType })
  10. .then(session => {
  11. // WebXRManager - xrFrame.getPose() Polyfill - line 279
  12. const tempRequestAnimationFrame = session.requestAnimationFrame.bind(session);
  13. session.requestAnimationFrame = function (callback) {
  14. return tempRequestAnimationFrame(function (time, frame) {
  15. frame.getPose = function (targetRaySpace, referenceSpace) {
  16. console.log('targetRay', targetRaySpace)
  17. return frame.getInputPose(targetRaySpace, referenceSpace);
  18. }
  19. callback(time, frame);
  20. })
  21. };
  22. // WebXRManager - xrFrame.getPose( inputSource.targetRaySpace, referenceSpace) Polyfill - line 279
  23. const tempGetInputSources = session.getInputSources.bind(session);
  24. session.getInputSources = function () {
  25. const res = tempGetInputSources();
  26. res.forEach(xrInputSource => {
  27. Object.defineProperty(xrInputSource, 'targetRaySpace', {
  28. get: function () {
  29. return xrInputSource
  30. },
  31. });
  32. });
  33. return res;
  34. }
  35. // WebXRManager - xrSession.getInputSources() Polyfill Line 132 - 136
  36. session.inputSources = Object.defineProperty(session, 'inputSources', {
  37. get: session.getInputSources
  38. });
  39. // WebXRManager - xrSession.updateRenderState() Polyfill Line 129
  40. session.updateRenderState = function ({ baseLayer }) {
  41. session.baseLayer = baseLayer;
  42. // WebXRManager - xrSession.renderState.baseLayer Polyfill Line 219
  43. session.renderState = {
  44. baseLayer: baseLayer,
  45. }
  46. }
  47. // WebXRManager - xrSession.requestReferenceSpace() Polyfill Line 130
  48. const temp = session.requestReferenceSpace.bind(session);
  49. session.requestReferenceSpace = function () {
  50. return temp({ type: 'stationary', subtype: 'floor-level' });
  51. }
  52. resolve(session);
  53. });
  54. })
  55. }
  56. }
  57. }