|
4 | 4 |
|
5 | 5 | if ( /(Helio)/g.test( navigator.userAgent ) && "xr" in navigator ) { |
6 | 6 |
|
7 | | - if ( 'isSessionSupported' in navigator.xr ) return; |
8 | | - |
9 | | - console.log( "Helio WebXR Polyfill (Lumin 0.97.0)" ); |
10 | | - |
11 | | - const isHelio96 = navigator.userAgent.includes( "Chrome/73" ); |
12 | | - |
13 | | - // WebXRManager - XR.supportSession() Polyfill - WebVR.js line 147 |
14 | | - |
15 | | - if ( |
16 | | - "supportsSession" in navigator.xr === false && |
17 | | - "supportsSessionMode" in navigator.xr |
18 | | - ) { |
19 | | - |
20 | | - navigator.xr.supportsSession = function ( /*sessionType*/ ) { |
21 | | - |
22 | | - // Force using immersive-ar |
23 | | - return navigator.xr.supportsSessionMode( 'immersive-ar' ); |
24 | | - |
25 | | - }; |
26 | | - |
27 | | - } |
28 | | - |
29 | | - if ( "requestSession" in navigator.xr ) { |
30 | | - |
31 | | - const tempRequestSession = navigator.xr.requestSession.bind( navigator.xr ); |
32 | | - |
33 | | - navigator.xr.requestSession = function ( /*sessionType*/ ) { |
34 | | - |
35 | | - return new Promise( function ( resolve, reject ) { |
36 | | - |
37 | | - const sessionType = ( isHelio96 ? { |
38 | | - mode: 'immersive-ar' // Force using immersive-ar |
39 | | - } : 'immersive-ar' ); |
40 | | - |
41 | | - tempRequestSession( sessionType ) |
42 | | - .then( function ( session ) { |
43 | | - |
44 | | - // WebXRManager - xrFrame.getPose() Polyfill - line 279 |
45 | | - |
46 | | - const tempRequestAnimationFrame = session.requestAnimationFrame.bind( |
47 | | - session |
48 | | - ); |
49 | | - |
50 | | - session.requestAnimationFrame = function ( callback ) { |
51 | | - |
52 | | - return tempRequestAnimationFrame( function ( time, frame ) { |
53 | | - |
54 | | - // WebXRManager - xrFrame.getViewerPose() Polyfill - line 279 |
55 | | - // Transforms view.viewMatrix to view.transform.inverse.matrix |
56 | | - |
57 | | - const tempGetViewerPose = frame.getViewerPose.bind( frame ); |
58 | | - |
59 | | - frame.getViewerPose = function ( referenceSpace ) { |
60 | | - |
61 | | - const pose = tempGetViewerPose( referenceSpace ); |
62 | | - |
63 | | - pose.views.forEach( function ( view ) { |
64 | | - |
65 | | - view.transform = { |
66 | | - inverse: { |
67 | | - matrix: view.viewMatrix |
68 | | - } |
69 | | - }; |
70 | | - |
71 | | - } ); |
72 | | - |
73 | | - return pose; |
74 | | - |
75 | | - }; |
76 | | - |
77 | | - // WebXRManager - xrFrame.getPose() Polyfill - line 259 |
78 | | - |
79 | | - const tempGetPose = ( isHelio96 ? null : frame.getPose.bind( frame ) ); |
80 | | - |
81 | | - frame.getPose = function ( targetRaySpace, referenceSpace ) { |
82 | | - |
83 | | - if ( isHelio96 ) { |
84 | | - |
85 | | - const inputPose = frame.getInputPose( |
86 | | - targetRaySpace, |
87 | | - referenceSpace |
88 | | - ); |
89 | | - |
90 | | - inputPose.transform = { |
91 | | - matrix: inputPose.targetRay.transformMatrix |
92 | | - }; |
93 | | - |
94 | | - return inputPose; |
95 | | - |
96 | | - } else { |
97 | | - |
98 | | - return tempGetPose( targetRaySpace.gripSpace, referenceSpace ); |
99 | | - |
100 | | - } |
101 | | - |
102 | | - }; |
103 | | - |
104 | | - callback( time, frame ); |
105 | | - |
106 | | - } ); |
107 | | - |
108 | | - }; |
109 | | - |
110 | | - // WebXRManager - xrFrame.getPose( inputSource.targetRaySpace, referenceSpace) Polyfill - line 279 |
111 | | - |
112 | | - const tempGetInputSources = session.getInputSources.bind( session ); |
113 | | - |
114 | | - session.getInputSources = function () { |
115 | | - |
116 | | - const res = tempGetInputSources(); |
117 | | - |
118 | | - res.forEach( function ( xrInputSource ) { |
119 | | - |
120 | | - Object.defineProperty( xrInputSource, "targetRaySpace", { |
121 | | - get: function () { |
122 | | - |
123 | | - return xrInputSource; |
124 | | - |
125 | | - } |
126 | | - } ); |
127 | | - |
128 | | - } ); |
129 | | - |
130 | | - return res; |
131 | | - |
132 | | - }; |
133 | | - |
134 | | - // WebXRManager - xrSession.getInputSources() Polyfill Line 132 - 136 |
135 | | - |
136 | | - session.inputSources = Object.defineProperty( |
137 | | - session, |
138 | | - "inputSources", |
139 | | - { |
140 | | - get: session.getInputSources |
141 | | - } |
142 | | - ); |
143 | | - |
144 | | - // WebXRManager - xrSession.updateRenderState() Polyfill Line 129 |
145 | | - |
146 | | - if ( isHelio96 ) { |
147 | | - |
148 | | - session.updateRenderState = function ( { baseLayer } ) { |
149 | | - |
150 | | - session.baseLayer = baseLayer; |
151 | | - |
152 | | - // WebXRManager - xrSession.renderState.baseLayer Polyfill Line 219 |
153 | | - |
154 | | - session.renderState = { |
155 | | - baseLayer: baseLayer |
156 | | - }; |
157 | | - |
158 | | - }; |
159 | | - |
160 | | - } |
161 | | - |
162 | | - // WebXRManager - xrSession.requestReferenceSpace() Polyfill Line 130 |
163 | | - |
164 | | - const tempRequestReferenceSpace = session.requestReferenceSpace.bind( |
165 | | - session |
166 | | - ); |
167 | | - |
168 | | - session.requestReferenceSpace = function () { |
169 | | - |
170 | | - return tempRequestReferenceSpace( { |
171 | | - type: "stationary", |
172 | | - subtype: "floor-level" |
173 | | - } ); |
174 | | - |
175 | | - }; |
176 | | - |
177 | | - resolve( session ); |
178 | | - |
179 | | - } ) |
180 | | - .catch( function ( error ) { |
181 | | - |
182 | | - return reject( error ); |
183 | | - |
184 | | - } ); |
185 | | - |
186 | | - } ); |
187 | | - |
188 | | - }; |
189 | | - |
190 | | - } |
191 | | - |
| 7 | + if ( 'isSessionSupported' in navigator.xr === false) { |
| 8 | + |
| 9 | + console.log( "Helio WebXR Polyfill (Lumin 0.97.0)" ); |
| 10 | + |
| 11 | + const isHelio96 = navigator.userAgent.includes( "Chrome/73" ); |
| 12 | + |
| 13 | + // WebXRManager - XR.supportSession() Polyfill - WebVR.js line 147 |
| 14 | + |
| 15 | + if ( |
| 16 | + "supportsSession" in navigator.xr === false && |
| 17 | + "supportsSessionMode" in navigator.xr |
| 18 | + ) { |
| 19 | + |
| 20 | + navigator.xr.supportsSession = function ( /*sessionType*/ ) { |
| 21 | + |
| 22 | + // Force using immersive-ar |
| 23 | + return navigator.xr.supportsSessionMode( 'immersive-ar' ); |
| 24 | + |
| 25 | + }; |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + if ( "requestSession" in navigator.xr ) { |
| 30 | + |
| 31 | + const tempRequestSession = navigator.xr.requestSession.bind( navigator.xr ); |
| 32 | + |
| 33 | + navigator.xr.requestSession = function ( /*sessionType*/ ) { |
| 34 | + |
| 35 | + return new Promise( function ( resolve, reject ) { |
| 36 | + |
| 37 | + const sessionType = ( isHelio96 ? { |
| 38 | + mode: 'immersive-ar' // Force using immersive-ar |
| 39 | + } : 'immersive-ar' ); |
| 40 | + |
| 41 | + tempRequestSession( sessionType ) |
| 42 | + .then( function ( session ) { |
| 43 | + |
| 44 | + // WebXRManager - xrFrame.getPose() Polyfill - line 279 |
| 45 | + |
| 46 | + const tempRequestAnimationFrame = session.requestAnimationFrame.bind( |
| 47 | + session |
| 48 | + ); |
| 49 | + |
| 50 | + session.requestAnimationFrame = function ( callback ) { |
| 51 | + |
| 52 | + return tempRequestAnimationFrame( function ( time, frame ) { |
| 53 | + |
| 54 | + // WebXRManager - xrFrame.getViewerPose() Polyfill - line 279 |
| 55 | + // Transforms view.viewMatrix to view.transform.inverse.matrix |
| 56 | + |
| 57 | + const tempGetViewerPose = frame.getViewerPose.bind( frame ); |
| 58 | + |
| 59 | + frame.getViewerPose = function ( referenceSpace ) { |
| 60 | + |
| 61 | + const pose = tempGetViewerPose( referenceSpace ); |
| 62 | + |
| 63 | + pose.views.forEach( function ( view ) { |
| 64 | + |
| 65 | + view.transform = { |
| 66 | + inverse: { |
| 67 | + matrix: view.viewMatrix |
| 68 | + } |
| 69 | + }; |
| 70 | + |
| 71 | + } ); |
| 72 | + |
| 73 | + return pose; |
| 74 | + |
| 75 | + }; |
| 76 | + |
| 77 | + // WebXRManager - xrFrame.getPose() Polyfill - line 259 |
| 78 | + |
| 79 | + const tempGetPose = ( isHelio96 ? null : frame.getPose.bind( frame ) ); |
| 80 | + |
| 81 | + frame.getPose = function ( targetRaySpace, referenceSpace ) { |
| 82 | + |
| 83 | + if ( isHelio96 ) { |
| 84 | + |
| 85 | + const inputPose = frame.getInputPose( |
| 86 | + targetRaySpace, |
| 87 | + referenceSpace |
| 88 | + ); |
| 89 | + |
| 90 | + inputPose.transform = { |
| 91 | + matrix: inputPose.targetRay.transformMatrix |
| 92 | + }; |
| 93 | + |
| 94 | + return inputPose; |
| 95 | + |
| 96 | + } else { |
| 97 | + |
| 98 | + return tempGetPose( targetRaySpace.gripSpace, referenceSpace ); |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + }; |
| 103 | + |
| 104 | + callback( time, frame ); |
| 105 | + |
| 106 | + } ); |
| 107 | + |
| 108 | + }; |
| 109 | + |
| 110 | + // WebXRManager - xrFrame.getPose( inputSource.targetRaySpace, referenceSpace) Polyfill - line 279 |
| 111 | + |
| 112 | + const tempGetInputSources = session.getInputSources.bind( session ); |
| 113 | + |
| 114 | + session.getInputSources = function () { |
| 115 | + |
| 116 | + const res = tempGetInputSources(); |
| 117 | + |
| 118 | + res.forEach( function ( xrInputSource ) { |
| 119 | + |
| 120 | + Object.defineProperty( xrInputSource, "targetRaySpace", { |
| 121 | + get: function () { |
| 122 | + |
| 123 | + return xrInputSource; |
| 124 | + |
| 125 | + } |
| 126 | + } ); |
| 127 | + |
| 128 | + } ); |
| 129 | + |
| 130 | + return res; |
| 131 | + |
| 132 | + }; |
| 133 | + |
| 134 | + // WebXRManager - xrSession.getInputSources() Polyfill Line 132 - 136 |
| 135 | + |
| 136 | + session.inputSources = Object.defineProperty( |
| 137 | + session, |
| 138 | + "inputSources", |
| 139 | + { |
| 140 | + get: session.getInputSources |
| 141 | + } |
| 142 | + ); |
| 143 | + |
| 144 | + // WebXRManager - xrSession.updateRenderState() Polyfill Line 129 |
| 145 | + |
| 146 | + if ( isHelio96 ) { |
| 147 | + |
| 148 | + session.updateRenderState = function ( { baseLayer } ) { |
| 149 | + |
| 150 | + session.baseLayer = baseLayer; |
| 151 | + |
| 152 | + // WebXRManager - xrSession.renderState.baseLayer Polyfill Line 219 |
| 153 | + |
| 154 | + session.renderState = { |
| 155 | + baseLayer: baseLayer |
| 156 | + }; |
| 157 | + |
| 158 | + }; |
| 159 | + |
| 160 | + } |
| 161 | + |
| 162 | + // WebXRManager - xrSession.requestReferenceSpace() Polyfill Line 130 |
| 163 | + |
| 164 | + const tempRequestReferenceSpace = session.requestReferenceSpace.bind( |
| 165 | + session |
| 166 | + ); |
| 167 | + |
| 168 | + session.requestReferenceSpace = function () { |
| 169 | + |
| 170 | + return tempRequestReferenceSpace( { |
| 171 | + type: "stationary", |
| 172 | + subtype: "floor-level" |
| 173 | + } ); |
| 174 | + |
| 175 | + }; |
| 176 | + |
| 177 | + resolve( session ); |
| 178 | + |
| 179 | + } ) |
| 180 | + .catch( function ( error ) { |
| 181 | + |
| 182 | + return reject( error ); |
| 183 | + |
| 184 | + } ); |
| 185 | + |
| 186 | + } ); |
| 187 | + |
| 188 | + }; |
| 189 | + |
| 190 | + } |
| 191 | + } |
192 | 192 | } |
0 commit comments