@@ -73,38 +73,10 @@ setTimeout(function () {
73
73
}
74
74
75
75
function XRControllerData ( ) {
76
- this . frame = 0 ;
77
- // TODO: set enabled 0 if controller was enable and then disable
78
- this . enabled = 0 ;
79
- this . hand = 0 ;
80
- this . positionX = 0 ;
81
- this . positionY = 0 ;
82
- this . positionZ = 0 ;
83
- this . rotationX = 0 ;
84
- this . rotationY = 0 ;
85
- this . rotationZ = 0 ;
86
- this . rotationW = 0 ;
87
- this . gripPositionX = 0 ;
88
- this . gripPositionY = 0 ;
89
- this . gripPositionZ = 0 ;
90
- this . gripRotationX = 0 ;
91
- this . gripRotationY = 0 ;
92
- this . gripRotationZ = 0 ;
93
- this . gripRotationW = 0 ;
94
- this . trigger = 0 ;
95
- this . squeeze = 0 ;
96
- this . thumbstick = 0 ;
97
- this . thumbstickX = 0 ;
98
- this . thumbstickY = 0 ;
99
- this . touchpad = 0 ;
100
- this . touchpadX = 0 ;
101
- this . touchpadY = 0 ;
102
- this . buttonA = 0 ;
103
- this . buttonB = 0 ;
76
+ this . bufferIndex = 0 ;
104
77
this . gamepad = null ;
105
78
this . profiles = [ ] ;
106
79
this . updatedProfiles = 0 ;
107
- this . updatedGrip = 0 ;
108
80
}
109
81
110
82
function XRHandData ( ) {
@@ -327,25 +299,17 @@ setTimeout(function () {
327
299
}
328
300
329
301
this . removeRemainingTouches ( ) ;
330
-
331
- this . xrData . controllerA . enabled = 0 ;
332
- this . xrData . controllerB . enabled = 0 ;
333
-
334
- this . xrData . controllerA . frame = - 1 ;
335
- this . xrData . controllerB . frame = - 1 ;
336
302
337
- this . xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
338
- this . xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
303
+ Module . HEAPF32 [ this . xrData . controllerA . bufferIndex ] = - 1 ; // XRControllerData.frame
304
+ Module . HEAPF32 [ this . xrData . controllerB . bufferIndex ] = - 1 ; // XRControllerData.frame
305
+ Module . HEAPF32 [ this . xrData . controllerA . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
306
+ Module . HEAPF32 [ this . xrData . controllerB . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
307
+
339
308
Module . HEAPF32 [ this . xrData . handLeft . bufferIndex ] = - 1 ; // XRHandData.frame
340
309
Module . HEAPF32 [ this . xrData . handRight . bufferIndex ] = - 1 ; // XRHandData.frame
341
310
Module . HEAPF32 [ this . xrData . handLeft . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
342
311
Module . HEAPF32 [ this . xrData . handRight . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
343
-
344
- this . updateUnityXRControllersData ( {
345
- controllerA : this . xrData . controllerA ,
346
- controllerB : this . xrData . controllerB
347
- } ) ;
348
-
312
+
349
313
this . gameModule . WebXR . OnEndXR ( ) ;
350
314
this . didNotifyUnity = false ;
351
315
this . canvas . width = this . canvas . parentElement . clientWidth * this . gameModule . asmLibraryArg . _JS_SystemInfo_GetPreferredDevicePixelRatio ( ) ;
@@ -384,40 +348,36 @@ setTimeout(function () {
384
348
hand = 2 ;
385
349
}
386
350
387
- controller . enabled = 1 ;
388
- controller . hand = hand ;
351
+ Module . HEAPF32 [ controller . bufferIndex + 1 ] = 1 ; // XRControllerData.enabled
352
+ Module . HEAPF32 [ controller . bufferIndex + 2 ] = hand ; // XRControllerData.hand
389
353
390
354
switch ( xrInputSourceEvent . type ) {
391
355
case "select" :
392
- controller . trigger = 1 ;
356
+ Module . HEAPF32 [ controller . bufferIndex + 10 ] = 1 ; // XRControllerData.trigger
393
357
break ;
394
358
case "selectstart" :
395
- controller . trigger = 1 ;
359
+ Module . HEAPF32 [ controller . bufferIndex + 10 ] = 1 ; // XRControllerData.trigger
396
360
break ;
397
361
case "selectend" :
398
- controller . trigger = 0 ;
362
+ Module . HEAPF32 [ controller . bufferIndex + 10 ] = 0 ; // XRControllerData.trigger
399
363
break ;
400
364
case "squeeze" :
401
- controller . squeeze = 1 ;
365
+ Module . HEAPF32 [ controller . bufferIndex + 11 ] = 1 ; // XRControllerData.squeeze
402
366
break ;
403
367
case "squeezestart" :
404
- controller . squeeze = 1 ;
368
+ Module . HEAPF32 [ controller . bufferIndex + 11 ] = 1 ; // XRControllerData.squeeze
405
369
break ;
406
370
case "squeezeend" :
407
- controller . squeeze = 0 ;
371
+ Module . HEAPF32 [ controller . bufferIndex + 11 ] = 0 ; // XRControllerData.squeeze
408
372
break ;
409
373
}
410
374
411
375
if ( hand == 0 || hand == 2 ) {
412
- xrData . controllerA = controller ;
413
- xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
414
- Module . HEAPF32 [ xrData . handRight . bufferIndex + 3 ] = controller . trigger ; // XRHandData.trigger
415
- Module . HEAPF32 [ xrData . handRight . bufferIndex + 4 ] = controller . squeeze ; // XRHandData.squeeze
376
+ Module . HEAPF32 [ xrData . handRight . bufferIndex + 3 ] = Module . HEAPF32 [ controller . bufferIndex + 10 ] ; // XRHandData.trigger
377
+ Module . HEAPF32 [ xrData . handRight . bufferIndex + 4 ] = Module . HEAPF32 [ controller . bufferIndex + 11 ] ; // XRHandData.squeeze
416
378
} else {
417
- xrData . controllerB = controller ;
418
- xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
419
- Module . HEAPF32 [ xrData . handLeft . bufferIndex + 3 ] = controller . trigger ; // XRHandData.trigger
420
- Module . HEAPF32 [ xrData . handLeft . bufferIndex + 4 ] = controller . squeeze ; // XRHandData.squeeze
379
+ Module . HEAPF32 [ xrData . handLeft . bufferIndex + 3 ] = Module . HEAPF32 [ controller . bufferIndex + 10 ] ; // XRHandData.trigger
380
+ Module . HEAPF32 [ xrData . handLeft . bufferIndex + 4 ] = Module . HEAPF32 [ controller . bufferIndex + 11 ] ; // XRHandData.squeeze
421
381
}
422
382
} else {
423
383
var xPercentage = 0.5 ;
@@ -588,16 +548,14 @@ setTimeout(function () {
588
548
}
589
549
590
550
XRManager . prototype . getXRControllersData = function ( frame , inputSources , refSpace , xrData ) {
591
- xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
592
- xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
593
551
Module . HEAPF32 [ xrData . handLeft . bufferIndex ] = xrData . frameNumber ; // XRHandData.frame
594
552
Module . HEAPF32 [ xrData . handRight . bufferIndex ] = xrData . frameNumber ; // XRHandData.frame
595
553
Module . HEAPF32 [ xrData . handLeft . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
596
554
Module . HEAPF32 [ xrData . handRight . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
597
- xrData . controllerA . enabled = 0 ;
598
- xrData . controllerB . enabled = 0 ;
599
- xrData . controllerA . frame = xrData . frameNumber ;
600
- xrData . controllerB . frame = xrData . frameNumber ;
555
+ Module . HEAPF32 [ xrData . controllerA . bufferIndex ] = xrData . frameNumber ; // XRControllerData.frame
556
+ Module . HEAPF32 [ xrData . controllerB . bufferIndex ] = xrData . frameNumber ; // XRControllerData.frame
557
+ Module . HEAPF32 [ xrData . controllerA . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
558
+ Module . HEAPF32 [ xrData . controllerB . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
601
559
if ( ! inputSources || ! inputSources . length || inputSources . length == 0 ) {
602
560
this . removeRemainingTouches ( ) ;
603
561
return ;
@@ -666,105 +624,99 @@ setTimeout(function () {
666
624
hand = 2 ;
667
625
}
668
626
669
- controller . enabled = 1 ;
670
- controller . hand = hand ;
627
+ Module . HEAPF32 [ controller . bufferIndex + 1 ] = 1 ; // XRControllerData.enabled
628
+ Module . HEAPF32 [ controller . bufferIndex + 2 ] = hand ; // XRControllerData.hand
671
629
672
630
if ( controller . updatedProfiles == 0 ) {
673
631
controller . profiles = inputSource . profiles ;
674
632
controller . updatedProfiles = 1 ;
675
633
}
676
634
677
- controller . positionX = position . x ;
678
- controller . positionY = position . y ;
679
- controller . positionZ = - position . z ;
635
+ Module . HEAPF32 [ controller . bufferIndex + 3 ] = position . x ; // XRControllerData.positionX
636
+ Module . HEAPF32 [ controller . bufferIndex + 4 ] = position . y ; // XRControllerData.positionY
637
+ Module . HEAPF32 [ controller . bufferIndex + 5 ] = - position . z ; // XRControllerData.positionZ
680
638
681
- controller . rotationX = - orientation . x ;
682
- controller . rotationY = - orientation . y ;
683
- controller . rotationZ = orientation . z ;
684
- controller . rotationW = orientation . w ;
639
+ Module . HEAPF32 [ controller . bufferIndex + 6 ] = - orientation . x ; // XRControllerData.rotationX
640
+ Module . HEAPF32 [ controller . bufferIndex + 7 ] = - orientation . y ; // XRControllerData.rotationY
641
+ Module . HEAPF32 [ controller . bufferIndex + 8 ] = orientation . z ; // XRControllerData.rotationZ
642
+ Module . HEAPF32 [ controller . bufferIndex + 9 ] = orientation . w ; // XRControllerData.rotationW
685
643
686
- if ( controller . updatedGrip == 0 ) {
644
+ if ( Module . HEAPF32 [ controller . bufferIndex + 20 ] == 0 && inputSource . gripSpace ) { // XRControllerData.updatedGrip
687
645
var inputPose = frame . getPose ( inputSource . gripSpace , refSpace ) ;
688
646
if ( inputPose ) {
689
647
var gripPosition = inputPose . transform . position ;
690
648
var gripOrientation = inputPose . transform . orientation ;
691
649
692
- controller . gripPositionX = gripPosition . x ;
693
- controller . gripPositionY = gripPosition . y ;
694
- controller . gripPositionZ = - gripPosition . z ;
650
+ Module . HEAPF32 [ controller . bufferIndex + 21 ] = gripPosition . x ; // XRControllerData.gripPositionX
651
+ Module . HEAPF32 [ controller . bufferIndex + 22 ] = gripPosition . y ; // XRControllerData.gripPositionY
652
+ Module . HEAPF32 [ controller . bufferIndex + 23 ] = - gripPosition . z ; // XRControllerData.gripPositionZ
695
653
696
- controller . gripRotationX = - gripOrientation . x ;
697
- controller . gripRotationY = - gripOrientation . y ;
698
- controller . gripRotationZ = gripOrientation . z ;
699
- controller . gripRotationW = gripOrientation . w ;
654
+ Module . HEAPF32 [ controller . bufferIndex + 24 ] = - gripOrientation . x ; // XRControllerData.gripRotationX
655
+ Module . HEAPF32 [ controller . bufferIndex + 25 ] = - gripOrientation . y ; // XRControllerData.gripRotationY
656
+ Module . HEAPF32 [ controller . bufferIndex + 26 ] = gripOrientation . z ; // XRControllerData.gripRotationZ
657
+ Module . HEAPF32 [ controller . bufferIndex + 27 ] = gripOrientation . w ; // XRControllerData.gripRotationW
700
658
701
- controller . updatedGrip = 1 ;
659
+ Module . HEAPF32 [ controller . bufferIndex + 20 ] = 1 ; // XRControllerData.updatedGrip
702
660
}
703
- } else if ( controller . updatedGrip == 1 ) {
704
- controller . updatedGrip = 2 ;
705
661
}
706
662
663
+ var triggerIndex = controller . bufferIndex + 10 ;
664
+ var squeezeIndex = controller . bufferIndex + 11 ;
707
665
// if there's gamepad, use the xr-standard mapping
708
666
if ( inputSource . gamepad ) {
709
667
for ( var j = 0 ; j < inputSource . gamepad . buttons . length ; j ++ ) {
710
668
switch ( j ) {
711
669
case 0 :
712
- controller . trigger = inputSource . gamepad . buttons [ j ] . value ;
670
+ Module . HEAPF32 [ triggerIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.trigger
713
671
break ;
714
672
case 1 :
715
- controller . squeeze = inputSource . gamepad . buttons [ j ] . value ;
673
+ Module . HEAPF32 [ squeezeIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.squeeze
716
674
break ;
717
675
case 2 :
718
- controller . touchpad = inputSource . gamepad . buttons [ j ] . value ;
676
+ Module . HEAPF32 [ controller . bufferIndex + 15 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.touchpad
719
677
break ;
720
678
case 3 :
721
- controller . thumbstick = inputSource . gamepad . buttons [ j ] . value ;
679
+ Module . HEAPF32 [ controller . bufferIndex + 12 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.thumbstick
722
680
break ;
723
681
case 4 :
724
- controller . buttonA = inputSource . gamepad . buttons [ j ] . value ;
682
+ Module . HEAPF32 [ controller . bufferIndex + 18 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.buttonA
725
683
break ;
726
684
case 5 :
727
- controller . buttonB = inputSource . gamepad . buttons [ j ] . value ;
685
+ Module . HEAPF32 [ controller . bufferIndex + 19 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.buttonB
728
686
break ;
729
687
}
730
688
}
731
689
732
- if ( controller . trigger <= 0.02 ) {
733
- controller . trigger = 0 ;
734
- } else if ( controller . trigger >= 0.98 ) {
735
- controller . trigger = 1 ;
690
+ if ( Module . HEAPF32 [ triggerIndex ] <= 0.02 ) {
691
+ Module . HEAPF32 [ triggerIndex ] = 0 ;
692
+ } else if ( Module . HEAPF32 [ triggerIndex ] >= 0.98 ) {
693
+ Module . HEAPF32 [ triggerIndex ] = 1 ;
736
694
}
737
695
738
- if ( controller . squeeze <= 0.02 ) {
739
- controller . squeeze = 0 ;
740
- } else if ( controller . squeeze >= 0.98 ) {
741
- controller . squeeze = 1 ;
696
+ if ( Module . HEAPF32 [ squeezeIndex ] <= 0.02 ) {
697
+ Module . HEAPF32 [ squeezeIndex ] = 0 ;
698
+ } else if ( Module . HEAPF32 [ squeezeIndex ] >= 0.98 ) {
699
+ Module . HEAPF32 [ squeezeIndex ] = 1 ;
742
700
}
743
701
744
702
for ( var j = 0 ; j < inputSource . gamepad . axes . length ; j ++ ) {
745
703
switch ( j ) {
746
704
case 0 :
747
- controller . touchpadX = inputSource . gamepad . axes [ j ] ;
705
+ Module . HEAPF32 [ controller . bufferIndex + 16 ] = inputSource . gamepad . axes [ j ] ; // XRControllerData.touchpadX
748
706
break ;
749
707
case 1 :
750
- controller . touchpadY = - inputSource . gamepad . axes [ j ] ;
708
+ Module . HEAPF32 [ controller . bufferIndex + 17 ] = - inputSource . gamepad . axes [ j ] ; // XRControllerData.touchpadY
751
709
break ;
752
710
case 2 :
753
- controller . thumbstickX = inputSource . gamepad . axes [ j ] ;
711
+ Module . HEAPF32 [ controller . bufferIndex + 13 ] = inputSource . gamepad . axes [ j ] ; // XRControllerData.thumbstickX
754
712
break ;
755
713
case 3 :
756
- controller . thumbstickY = - inputSource . gamepad . axes [ j ] ;
714
+ Module . HEAPF32 [ controller . bufferIndex + 14 ] = - inputSource . gamepad . axes [ j ] ; // XRControllerData.thumbstickY
757
715
break ;
758
716
}
759
717
}
760
718
}
761
719
controller . gamepad = inputSource . gamepad ;
762
-
763
- if ( hand == 0 || hand == 2 ) {
764
- xrData . controllerA = controller ;
765
- } else {
766
- xrData . controllerB = controller ;
767
- }
768
720
}
769
721
} else if ( inputSource . xrTouchObject && ! inputSource . xrTouchObject . ended && inputSource . gamepad && inputSource . gamepad . axes ) {
770
722
inputSource . xrTouchObject . UpdateTouch ( this . canvas ,
@@ -787,8 +739,6 @@ setTimeout(function () {
787
739
var glLayer = new XRWebGLLayer ( session , this . ctx ) ;
788
740
session . updateRenderState ( { baseLayer : glLayer } ) ;
789
741
790
-
791
-
792
742
var refSpaceType = 'viewer' ;
793
743
if ( session . isImmersive ) {
794
744
refSpaceType = this . gameModule . WebXR . Settings . VRRequiredReferenceSpace [ 0 ] ;
@@ -810,12 +760,16 @@ setTimeout(function () {
810
760
session . addEventListener ( 'squeezeend' , this . onInputEvent ) ;
811
761
session . addEventListener ( 'visibilitychange' , this . onSessionVisibilityEvent ) ;
812
762
763
+ this . xrData . controllerA . bufferIndex = Module . ControllersArrayOffset ;
764
+ this . xrData . controllerB . bufferIndex = Module . ControllersArrayOffset + 28 ;
765
+ this . xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
766
+ this . xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
813
767
this . xrData . controllerA . updatedProfiles = 0 ;
814
768
this . xrData . controllerB . updatedProfiles = 0 ;
815
769
this . xrData . controllerA . profiles = [ ] ;
816
770
this . xrData . controllerB . profiles = [ ] ;
817
- this . xrData . controllerA . updatedGrip = 0 ;
818
- this . xrData . controllerB . updatedGrip = 0 ;
771
+ Module . HEAPF32 [ this . xrData . controllerA . bufferIndex + 20 ] = 0 ; // XRControllerData.updatedGrip
772
+ Module . HEAPF32 [ this . xrData . controllerB . bufferIndex + 20 ] = 0 ; // XRControllerData.updatedGrip
819
773
}
820
774
var thisXRMananger = this ;
821
775
session . requestReferenceSpace ( refSpaceType ) . then ( function ( refSpace ) {
@@ -944,11 +898,6 @@ setTimeout(function () {
944
898
leftViewPosition : xrData . leftViewPosition ,
945
899
rightViewPosition : xrData . rightViewPosition
946
900
} ) ;
947
-
948
- this . updateUnityXRControllersData ( {
949
- controllerA : xrData . controllerA ,
950
- controllerB : xrData . controllerB
951
- } ) ;
952
901
953
902
if ( ! this . didNotifyUnity )
954
903
{
@@ -1012,47 +961,6 @@ setTimeout(function () {
1012
961
} ) ;
1013
962
}
1014
963
1015
- XRManager . prototype . updateUnityXRControllersData = function ( data ) {
1016
- var index = 0 ;
1017
- if ( Module . ControllersArray . byteLength == 0 ) {
1018
- Module . ControllersArray = new Float32Array ( buffer , Module . ControllersArrayOffset , Module . ControllersArrayLength ) ;
1019
- }
1020
- Object . keys ( data ) . forEach ( function ( key , i ) {
1021
- Module . ControllersArray [ index ++ ] = data [ key ] . frame ;
1022
- Module . ControllersArray [ index ++ ] = data [ key ] . enabled ;
1023
- Module . ControllersArray [ index ++ ] = data [ key ] . hand ;
1024
- Module . ControllersArray [ index ++ ] = data [ key ] . positionX ;
1025
- Module . ControllersArray [ index ++ ] = data [ key ] . positionY ;
1026
- Module . ControllersArray [ index ++ ] = data [ key ] . positionZ ;
1027
- Module . ControllersArray [ index ++ ] = data [ key ] . rotationX ;
1028
- Module . ControllersArray [ index ++ ] = data [ key ] . rotationY ;
1029
- Module . ControllersArray [ index ++ ] = data [ key ] . rotationZ ;
1030
- Module . ControllersArray [ index ++ ] = data [ key ] . rotationW ;
1031
- Module . ControllersArray [ index ++ ] = data [ key ] . trigger ;
1032
- Module . ControllersArray [ index ++ ] = data [ key ] . squeeze ;
1033
- Module . ControllersArray [ index ++ ] = data [ key ] . thumbstick ;
1034
- Module . ControllersArray [ index ++ ] = data [ key ] . thumbstickX ;
1035
- Module . ControllersArray [ index ++ ] = data [ key ] . thumbstickY ;
1036
- Module . ControllersArray [ index ++ ] = data [ key ] . touchpad ;
1037
- Module . ControllersArray [ index ++ ] = data [ key ] . touchpadX ;
1038
- Module . ControllersArray [ index ++ ] = data [ key ] . touchpadY ;
1039
- Module . ControllersArray [ index ++ ] = data [ key ] . buttonA ;
1040
- Module . ControllersArray [ index ++ ] = data [ key ] . buttonB ;
1041
- Module . ControllersArray [ index ++ ] = data [ key ] . updatedGrip ;
1042
- if ( data [ key ] . updatedGrip == 1 ) {
1043
- Module . ControllersArray [ index ++ ] = data [ key ] . gripPositionX ;
1044
- Module . ControllersArray [ index ++ ] = data [ key ] . gripPositionY ;
1045
- Module . ControllersArray [ index ++ ] = data [ key ] . gripPositionZ ;
1046
- Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationX ;
1047
- Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationY ;
1048
- Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationZ ;
1049
- Module . ControllersArray [ index ++ ] = data [ key ] . gripRotationW ;
1050
- } else {
1051
- index += 7 ;
1052
- }
1053
- } ) ;
1054
- }
1055
-
1056
964
XRManager . prototype . updateUnityXRViewerHitTestPose = function ( data ) {
1057
965
var index = 0 ;
1058
966
if ( Module . ViewerHitTestPoseArray . byteLength == 0 ) {
0 commit comments