1
+ Module [ 'WebXR' ] = Module [ 'WebXR' ] || { } ;
2
+
1
3
setTimeout ( function ( ) {
2
4
if ( GL && GL . createContext )
3
5
{
@@ -228,7 +230,7 @@ setTimeout(function () {
228
230
var thisXRMananger = this ;
229
231
navigator . xr . isSessionSupported ( 'immersive-vr' ) . then ( function ( supported ) {
230
232
thisXRMananger . isVRSupported = supported ;
231
- if ( document . body . dataset . unityLoaded )
233
+ if ( Module . WebXR . unityLoaded )
232
234
{
233
235
document . dispatchEvent ( new CustomEvent ( 'onVRSupportedCheck' , { detail :{ supported :thisXRMananger . isVRSupported } } ) ) ;
234
236
thisXRMananger . UpdateXRCapabilities ( ) ;
@@ -237,7 +239,7 @@ setTimeout(function () {
237
239
238
240
navigator . xr . isSessionSupported ( 'immersive-ar' ) . then ( function ( supported ) {
239
241
thisXRMananger . isARSupported = supported ;
240
- if ( document . body . dataset . unityLoaded )
242
+ if ( Module . WebXR . unityLoaded )
241
243
{
242
244
document . dispatchEvent ( new CustomEvent ( 'onARSupportedCheck' , { detail :{ supported :thisXRMananger . isARSupported } } ) ) ;
243
245
thisXRMananger . UpdateXRCapabilities ( ) ;
@@ -350,15 +352,15 @@ setTimeout(function () {
350
352
this . xrData . handLeft . frame = - 1 ;
351
353
this . xrData . handRight . frame = - 1 ;
352
354
353
- document . dispatchEvent ( new CustomEvent ( 'XRControllersData' , { detail : {
355
+ this . updateUnityXRControllersData ( {
354
356
controllerA : this . xrData . controllerA ,
355
357
controllerB : this . xrData . controllerB
356
- } } ) ) ;
358
+ } ) ;
357
359
358
- document . dispatchEvent ( new CustomEvent ( 'XRHandsData' , { detail : {
360
+ this . updateUnityXRHandsData ( {
359
361
handLeft : this . xrData . handLeft ,
360
362
handRight : this . xrData . handRight
361
- } } ) ) ;
363
+ } ) ;
362
364
363
365
this . gameModule . WebXR . OnEndXR ( ) ;
364
366
this . didNotifyUnity = false ;
@@ -561,7 +563,7 @@ setTimeout(function () {
561
563
}
562
564
563
565
XRManager . prototype . unityLoaded = function ( event ) {
564
- document . body . dataset . unityLoaded = 'true' ;
566
+ Module . WebXR . unityLoaded = 'true' ;
565
567
566
568
this . setGameModule ( event . detail . module ) ;
567
569
@@ -896,9 +898,9 @@ setTimeout(function () {
896
898
} else {
897
899
xrData . viewerHitTestPose . available = 0 ;
898
900
}
899
- document . dispatchEvent ( new CustomEvent ( 'XRViewerHitTestPose' , { detail : {
901
+ this . updateUnityXRViewerHitTestPose ( {
900
902
viewerHitTestPose : xrData . viewerHitTestPose
901
- } } ) ) ;
903
+ } ) ;
902
904
}
903
905
904
906
if ( xrData . controllerA . updatedProfiles == 1 || xrData . controllerB . updatedProfiles == 1 )
@@ -918,24 +920,24 @@ setTimeout(function () {
918
920
}
919
921
920
922
// Dispatch event with headset data to be handled in webxr.jslib
921
- document . dispatchEvent ( new CustomEvent ( 'XRData' , { detail : {
923
+ this . updateUnityXRData ( {
922
924
leftProjectionMatrix : xrData . leftProjectionMatrix ,
923
925
rightProjectionMatrix : xrData . rightProjectionMatrix ,
924
926
leftViewRotation : xrData . leftViewRotation ,
925
927
rightViewRotation : xrData . rightViewRotation ,
926
928
leftViewPosition : xrData . leftViewPosition ,
927
929
rightViewPosition : xrData . rightViewPosition
928
- } } ) ) ;
930
+ } ) ;
929
931
930
- document . dispatchEvent ( new CustomEvent ( 'XRControllersData' , { detail : {
932
+ this . updateUnityXRControllersData ( {
931
933
controllerA : xrData . controllerA ,
932
934
controllerB : xrData . controllerB
933
- } } ) ) ;
935
+ } ) ;
934
936
935
- document . dispatchEvent ( new CustomEvent ( 'XRHandsData' , { detail : {
937
+ this . updateUnityXRHandsData ( {
936
938
handLeft : xrData . handLeft ,
937
939
handRight : xrData . handRight
938
- } } ) ) ;
940
+ } ) ;
939
941
940
942
if ( ! this . didNotifyUnity )
941
943
{
@@ -981,6 +983,103 @@ setTimeout(function () {
981
983
this . didNotifyUnity = true ;
982
984
}
983
985
}
986
+
987
+ XRManager . prototype . updateUnityXRData = function ( data ) {
988
+ var index = 0 ;
989
+ if ( Module . XRSharedArray . byteLength == 0 ) {
990
+ Module . XRSharedArray = new Float32Array ( buffer , Module . XRSharedArrayOffset , Module . XRSharedArrayLength ) ;
991
+ }
992
+ Object . keys ( data ) . forEach ( function ( key , i ) {
993
+ var dataLength = data [ key ] . length ;
994
+ if ( dataLength ) {
995
+ for ( var x = 0 ; x < dataLength ; x ++ ) {
996
+ Module . XRSharedArray [ index ++ ] = data [ key ] [ x ] ;
997
+ }
998
+ }
999
+ } ) ;
1000
+ }
1001
+
1002
+ XRManager . prototype . updateUnityXRControllersData = function ( data ) {
1003
+ var index = 0 ;
1004
+ if ( Module . ControllersArray . byteLength == 0 ) {
1005
+ Module . ControllersArray = new Float32Array ( buffer , Module . ControllersArrayOffset , Module . ControllersArrayLength ) ;
1006
+ }
1007
+ Object . keys ( data ) . forEach ( function ( key , i ) {
1008
+ Module . ControllersArray [ index ++ ] = data [ key ] . frame ;
1009
+ Module . ControllersArray [ index ++ ] = data [ key ] . enabled ;
1010
+ Module . ControllersArray [ index ++ ] = data [ key ] . hand ;
1011
+ Module . ControllersArray [ index ++ ] = data [ key ] . positionX ;
1012
+ Module . ControllersArray [ index ++ ] = data [ key ] . positionY ;
1013
+ Module . ControllersArray [ index ++ ] = data [ key ] . positionZ ;
1014
+ Module . ControllersArray [ index ++ ] = data [ key ] . rotationX ;
1015
+ Module . ControllersArray [ index ++ ] = data [ key ] . rotationY ;
1016
+ Module . ControllersArray [ index ++ ] = data [ key ] . rotationZ ;
1017
+ Module . ControllersArray [ index ++ ] = data [ key ] . rotationW ;
1018
+ Module . ControllersArray [ index ++ ] = data [ key ] . trigger ;
1019
+ Module . ControllersArray [ index ++ ] = data [ key ] . squeeze ;
1020
+ Module . ControllersArray [ index ++ ] = data [ key ] . thumbstick ;
1021
+ Module . ControllersArray [ index ++ ] = data [ key ] . thumbstickX ;
1022
+ Module . ControllersArray [ index ++ ] = data [ key ] . thumbstickY ;
1023
+ Module . ControllersArray [ index ++ ] = data [ key ] . touchpad ;
1024
+ Module . ControllersArray [ index ++ ] = data [ key ] . touchpadX ;
1025
+ Module . ControllersArray [ index ++ ] = data [ key ] . touchpadY ;
1026
+ Module . ControllersArray [ index ++ ] = data [ key ] . buttonA ;
1027
+ Module . ControllersArray [ index ++ ] = data [ key ] . buttonB ;
1028
+ Module . ControllersArray [ index ++ ] = data [ key ] . updatedGrip ;
1029
+ if ( data [ key ] . updatedGrip == 1 ) {
1030
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripPositionX ;
1031
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripPositionY ;
1032
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripPositionZ ;
1033
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationX ;
1034
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationY ;
1035
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationZ ;
1036
+ Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationW ;
1037
+ } else {
1038
+ index += 7 ;
1039
+ }
1040
+ } ) ;
1041
+ }
1042
+
1043
+ XRManager . prototype . updateUnityXRHandsData = function ( data ) {
1044
+ var index = 0 ;
1045
+ if ( Module . HandsArray . byteLength == 0 ) {
1046
+ Module . HandsArray = new Float32Array ( buffer , Module . HandsArrayOffset , Module . HandsArrayLength ) ;
1047
+ }
1048
+ Object . keys ( data ) . forEach ( function ( key , i ) {
1049
+ Module . HandsArray [ index ++ ] = data [ key ] . frame ;
1050
+ Module . HandsArray [ index ++ ] = data [ key ] . enabled ;
1051
+ Module . HandsArray [ index ++ ] = data [ key ] . hand ;
1052
+ Module . HandsArray [ index ++ ] = data [ key ] . trigger ;
1053
+ Module . HandsArray [ index ++ ] = data [ key ] . squeeze ;
1054
+ for ( var j = 0 ; j < 25 ; j ++ ) {
1055
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . enabled ;
1056
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . position [ 0 ] ;
1057
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . position [ 1 ] ;
1058
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . position [ 2 ] ;
1059
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 0 ] ;
1060
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 1 ] ;
1061
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 2 ] ;
1062
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 3 ] ;
1063
+ Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . radius ;
1064
+ }
1065
+ } ) ;
1066
+ }
1067
+
1068
+ XRManager . prototype . updateUnityXRViewerHitTestPose = function ( data ) {
1069
+ var index = 0 ;
1070
+ if ( Module . ViewerHitTestPoseArray . byteLength == 0 ) {
1071
+ Module . ViewerHitTestPoseArray = new Float32Array ( buffer , Module . ViewerHitTestPoseArrayOffset , Module . ViewerHitTestPoseArrayLength ) ;
1072
+ }
1073
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . frame ;
1074
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . available ;
1075
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . position [ 0 ] ;
1076
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . position [ 1 ] ;
1077
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . position [ 2 ] ;
1078
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . rotation [ 0 ] ;
1079
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . rotation [ 1 ] ;
1080
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . rotation [ 2 ] ;
1081
+ Module . ViewerHitTestPoseArray [ index ++ ] = data . viewerHitTestPose . rotation [ 3 ] ;
1082
+ }
984
1083
985
1084
function initWebXRManager ( ) {
986
1085
var xrManager = window . xrManager = new XRManager ( ) ;
@@ -1021,8 +1120,6 @@ setTimeout(function () {
1021
1120
1022
1121
} , 0 ) ;
1023
1122
1024
- Module [ 'WebXR' ] = Module [ 'WebXR' ] || { } ;
1025
-
1026
1123
Module [ 'WebXR' ] . GetBrowserObject = function ( ) {
1027
1124
return Browser ;
1028
1125
}
0 commit comments