@@ -56,8 +56,43 @@ const ofun = vtkPiecewiseFunction.newInstance();
56
56
57
57
const {
58
58
fileURL = 'https://data.kitware.com/api/v1/file/59de9dca8d777f31ac641dc2/download' ,
59
+ xrSessionType = null ,
59
60
} = vtkURLExtract . extractURLParameters ( ) ;
60
61
62
+ // Validate input parameters
63
+ let requestedXrSessionType = xrSessionType ;
64
+ if ( ! Object . values ( XrSessionTypes ) . includes ( requestedXrSessionType ) ) {
65
+ console . warn (
66
+ 'Could not parse requested XR session type: ' ,
67
+ requestedXrSessionType
68
+ ) ;
69
+ requestedXrSessionType = null ;
70
+ }
71
+
72
+ if ( requestedXrSessionType === XrSessionTypes . LookingGlassVR ) {
73
+ // Import the Looking Glass WebXR Polyfill override
74
+ // Assumes that the Looking Glass Bridge native application is already running.
75
+ // See https://docs.lookingglassfactory.com/developer-tools/webxr
76
+ import (
77
+ // eslint-disable-next-line import/no-unresolved, import/extensions
78
+ /* webpackIgnore: true */ 'https://unpkg.com/@lookingglass/[email protected] /dist/@lookingglass/bundle/webxr.js'
79
+ ) . then ( ( obj ) => {
80
+ // eslint-disable-next-line no-new
81
+ new obj . LookingGlassWebXRPolyfill ( { numViews : 12 } ) ;
82
+ } ) ;
83
+ } else if ( requestedXrSessionType === null ) {
84
+ // Determine supported session type
85
+ navigator . xr . isSessionSupported ( 'immersive-ar' ) . then ( ( arSupported ) => {
86
+ if ( arSupported ) {
87
+ requestedXrSessionType = XrSessionTypes . MobileAR ;
88
+ } else {
89
+ navigator . xr . isSessionSupported ( 'immersive-vr' ) . then ( ( vrSupported ) => {
90
+ requestedXrSessionType = vrSupported ? XrSessionTypes . HmdVR : null ;
91
+ } ) ;
92
+ }
93
+ } ) ;
94
+ }
95
+
61
96
HttpDataAccessHelper . fetchBinary ( fileURL ) . then ( ( fileContents ) => {
62
97
// Read data
63
98
vtiReader . parseAsArrayBuffer ( fileContents ) ;
@@ -110,7 +145,6 @@ HttpDataAccessHelper.fetchBinary(fileURL).then((fileContents) => {
110
145
renderWindow . render ( ) ;
111
146
112
147
// Add button to launch AR (default) or VR scene
113
- let xrSessionType = 0 ;
114
148
const xrButton = document . createElement ( 'button' ) ;
115
149
let enterText = 'XR not available!' ;
116
150
const exitText = 'Exit XR' ;
@@ -119,28 +153,20 @@ HttpDataAccessHelper.fetchBinary(fileURL).then((fileContents) => {
119
153
navigator . xr !== undefined &&
120
154
fullScreenRenderer . getApiSpecificRenderWindow ( ) . getXrSupported ( )
121
155
) {
122
- navigator . xr . isSessionSupported ( 'immersive-ar' ) . then ( ( arSupported ) => {
123
- if ( arSupported ) {
124
- xrSessionType = XrSessionTypes . MobileAR ;
125
- enterText = 'Start AR' ;
126
- xrButton . textContent = enterText ;
127
- } else {
128
- navigator . xr . isSessionSupported ( 'immersive-vr' ) . then ( ( vrSupported ) => {
129
- if ( vrSupported ) {
130
- xrSessionType = XrSessionTypes . HmdVR ;
131
- enterText = 'Start VR' ;
132
- xrButton . textContent = enterText ;
133
- }
134
- } ) ;
135
- }
136
- } ) ;
156
+ enterText =
157
+ requestedXrSessionType === XrSessionTypes . MobileAR
158
+ ? 'Start AR'
159
+ : 'Start VR' ;
160
+ xrButton . textContent = enterText ;
137
161
}
138
162
xrButton . addEventListener ( 'click' , ( ) => {
139
163
if ( xrButton . textContent === enterText ) {
140
- if ( xrSessionType === XrSessionTypes . MobileAR ) {
164
+ if ( requestedXrSessionType === XrSessionTypes . MobileAR ) {
141
165
fullScreenRenderer . setBackground ( [ 0 , 0 , 0 , 0 ] ) ;
142
166
}
143
- fullScreenRenderer . getApiSpecificRenderWindow ( ) . startXR ( xrSessionType ) ;
167
+ fullScreenRenderer
168
+ . getApiSpecificRenderWindow ( )
169
+ . startXR ( requestedXrSessionType ) ;
144
170
xrButton . textContent = exitText ;
145
171
} else {
146
172
fullScreenRenderer . setBackground ( [ ...background , 255 ] ) ;
0 commit comments