@@ -66,9 +66,69 @@ setTimeout(function () {
66
66
67
67
function XRControllerData ( ) {
68
68
this . bufferIndex = 0 ;
69
+ this . frameIndex = 0 ;
70
+ this . enabledIndex = 0 ;
71
+ this . handIndex = 0 ;
72
+ this . positionXIndex = 0 ;
73
+ this . positionYIndex = 0 ;
74
+ this . positionZIndex = 0 ;
75
+ this . rotationXIndex = 0 ;
76
+ this . rotationYIndex = 0 ;
77
+ this . rotationZIndex = 0 ;
78
+ this . rotationWIndex = 0 ;
79
+ this . gripPositionXIndex = 0 ;
80
+ this . gripPositionYIndex = 0 ;
81
+ this . gripPositionZIndex = 0 ;
82
+ this . gripRotationXIndex = 0 ;
83
+ this . gripRotationYIndex = 0 ;
84
+ this . gripRotationZIndex = 0 ;
85
+ this . gripRotationWIndex = 0 ;
86
+ this . triggerIndex = 0 ;
87
+ this . squeezeIndex = 0 ;
88
+ this . thumbstickIndex = 0 ;
89
+ this . thumbstickXIndex = 0 ;
90
+ this . thumbstickYIndex = 0 ;
91
+ this . touchpadIndex = 0 ;
92
+ this . touchpadXIndex = 0 ;
93
+ this . touchpadYIndex = 0 ;
94
+ this . buttonAIndex = 0 ;
95
+ this . buttonBIndex = 0 ;
96
+ this . updatedGripIndex = 0 ;
69
97
this . gamepad = null ;
70
98
this . profiles = [ ] ;
71
99
this . updatedProfiles = 0 ;
100
+
101
+ this . setIndices = function ( index ) {
102
+ this . bufferIndex = index ;
103
+ this . frameIndex = index ++ ;
104
+ this . enabledIndex = index ++ ;
105
+ this . handIndex = index ++ ;
106
+ this . positionXIndex = index ++ ;
107
+ this . positionYIndex = index ++ ;
108
+ this . positionZIndex = index ++ ;
109
+ this . rotationXIndex = index ++ ;
110
+ this . rotationYIndex = index ++ ;
111
+ this . rotationZIndex = index ++ ;
112
+ this . rotationWIndex = index ++ ;
113
+ this . triggerIndex = index ++ ;
114
+ this . squeezeIndex = index ++ ;
115
+ this . thumbstickIndex = index ++ ;
116
+ this . thumbstickXIndex = index ++ ;
117
+ this . thumbstickYIndex = index ++ ;
118
+ this . touchpadIndex = index ++ ;
119
+ this . touchpadXIndex = index ++ ;
120
+ this . touchpadYIndex = index ++ ;
121
+ this . buttonAIndex = index ++ ;
122
+ this . buttonBIndex = index ++ ;
123
+ this . updatedGripIndex = index ++ ;
124
+ this . gripPositionXIndex = index ++ ;
125
+ this . gripPositionYIndex = index ++ ;
126
+ this . gripPositionZIndex = index ++ ;
127
+ this . gripRotationXIndex = index ++ ;
128
+ this . gripRotationYIndex = index ++ ;
129
+ this . gripRotationZIndex = index ++ ;
130
+ this . gripRotationWIndex = index ++ ;
131
+ }
72
132
}
73
133
74
134
function XRHandData ( ) {
@@ -289,10 +349,10 @@ setTimeout(function () {
289
349
290
350
this . removeRemainingTouches ( ) ;
291
351
292
- Module . HEAPF32 [ this . xrData . controllerA . bufferIndex ] = - 1 ; // XRControllerData.frame
293
- Module . HEAPF32 [ this . xrData . controllerB . bufferIndex ] = - 1 ; // XRControllerData.frame
294
- Module . HEAPF32 [ this . xrData . controllerA . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
295
- Module . HEAPF32 [ this . xrData . controllerB . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
352
+ Module . HEAPF32 [ this . xrData . controllerA . frameIndex ] = - 1 ; // XRControllerData.frame
353
+ Module . HEAPF32 [ this . xrData . controllerB . frameIndex ] = - 1 ; // XRControllerData.frame
354
+ Module . HEAPF32 [ this . xrData . controllerA . enabledIndex ] = 0 ; // XRControllerData.enabled
355
+ Module . HEAPF32 [ this . xrData . controllerB . enabledIndex ] = 0 ; // XRControllerData.enabled
296
356
297
357
Module . HEAPF32 [ this . xrData . handLeft . bufferIndex ] = - 1 ; // XRHandData.frame
298
358
Module . HEAPF32 [ this . xrData . handRight . bufferIndex ] = - 1 ; // XRHandData.frame
@@ -337,36 +397,36 @@ setTimeout(function () {
337
397
hand = 2 ;
338
398
}
339
399
340
- Module . HEAPF32 [ controller . bufferIndex + 1 ] = 1 ; // XRControllerData.enabled
341
- Module . HEAPF32 [ controller . bufferIndex + 2 ] = hand ; // XRControllerData.hand
400
+ Module . HEAPF32 [ controller . enabledIndex ] = 1 ; // XRControllerData.enabled
401
+ Module . HEAPF32 [ controller . handIndex ] = hand ; // XRControllerData.hand
342
402
343
403
switch ( xrInputSourceEvent . type ) {
344
404
case "select" :
345
- Module . HEAPF32 [ controller . bufferIndex + 10 ] = 1 ; // XRControllerData.trigger
405
+ Module . HEAPF32 [ controller . triggerIndex ] = 1 ; // XRControllerData.trigger
346
406
break ;
347
407
case "selectstart" :
348
- Module . HEAPF32 [ controller . bufferIndex + 10 ] = 1 ; // XRControllerData.trigger
408
+ Module . HEAPF32 [ controller . triggerIndex ] = 1 ; // XRControllerData.trigger
349
409
break ;
350
410
case "selectend" :
351
- Module . HEAPF32 [ controller . bufferIndex + 10 ] = 0 ; // XRControllerData.trigger
411
+ Module . HEAPF32 [ controller . triggerIndex ] = 0 ; // XRControllerData.trigger
352
412
break ;
353
413
case "squeeze" :
354
- Module . HEAPF32 [ controller . bufferIndex + 11 ] = 1 ; // XRControllerData.squeeze
414
+ Module . HEAPF32 [ controller . squeezeIndex ] = 1 ; // XRControllerData.squeeze
355
415
break ;
356
416
case "squeezestart" :
357
- Module . HEAPF32 [ controller . bufferIndex + 11 ] = 1 ; // XRControllerData.squeeze
417
+ Module . HEAPF32 [ controller . squeezeIndex ] = 1 ; // XRControllerData.squeeze
358
418
break ;
359
419
case "squeezeend" :
360
- Module . HEAPF32 [ controller . bufferIndex + 11 ] = 0 ; // XRControllerData.squeeze
420
+ Module . HEAPF32 [ controller . squeezeIndex ] = 0 ; // XRControllerData.squeeze
361
421
break ;
362
422
}
363
423
364
424
if ( hand == 0 || hand == 2 ) {
365
- Module . HEAPF32 [ xrData . handRight . bufferIndex + 3 ] = Module . HEAPF32 [ controller . bufferIndex + 10 ] ; // XRHandData.trigger
366
- Module . HEAPF32 [ xrData . handRight . bufferIndex + 4 ] = Module . HEAPF32 [ controller . bufferIndex + 11 ] ; // XRHandData.squeeze
425
+ Module . HEAPF32 [ xrData . handRight . bufferIndex + 3 ] = Module . HEAPF32 [ controller . triggerIndex ] ; // XRHandData.trigger
426
+ Module . HEAPF32 [ xrData . handRight . bufferIndex + 4 ] = Module . HEAPF32 [ controller . squeezeIndex ] ; // XRHandData.squeeze
367
427
} else {
368
- Module . HEAPF32 [ xrData . handLeft . bufferIndex + 3 ] = Module . HEAPF32 [ controller . bufferIndex + 10 ] ; // XRHandData.trigger
369
- Module . HEAPF32 [ xrData . handLeft . bufferIndex + 4 ] = Module . HEAPF32 [ controller . bufferIndex + 11 ] ; // XRHandData.squeeze
428
+ Module . HEAPF32 [ xrData . handLeft . bufferIndex + 3 ] = Module . HEAPF32 [ controller . triggerIndex ] ; // XRHandData.trigger
429
+ Module . HEAPF32 [ xrData . handLeft . bufferIndex + 4 ] = Module . HEAPF32 [ controller . squeezeIndex ] ; // XRHandData.squeeze
370
430
}
371
431
} else {
372
432
var xPercentage = 0.5 ;
@@ -541,10 +601,10 @@ setTimeout(function () {
541
601
Module . HEAPF32 [ xrData . handRight . bufferIndex ] = xrData . frameNumber ; // XRHandData.frame
542
602
Module . HEAPF32 [ xrData . handLeft . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
543
603
Module . HEAPF32 [ xrData . handRight . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
544
- Module . HEAPF32 [ xrData . controllerA . bufferIndex ] = xrData . frameNumber ; // XRControllerData.frame
545
- Module . HEAPF32 [ xrData . controllerB . bufferIndex ] = xrData . frameNumber ; // XRControllerData.frame
546
- Module . HEAPF32 [ xrData . controllerA . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
547
- Module . HEAPF32 [ xrData . controllerB . bufferIndex + 1 ] = 0 ; // XRControllerData.enabled
604
+ Module . HEAPF32 [ xrData . controllerA . frameIndex ] = xrData . frameNumber ; // XRControllerData.frame
605
+ Module . HEAPF32 [ xrData . controllerB . frameIndex ] = xrData . frameNumber ; // XRControllerData.frame
606
+ Module . HEAPF32 [ xrData . controllerA . enabledIndex ] = 0 ; // XRControllerData.enabled
607
+ Module . HEAPF32 [ xrData . controllerB . enabledIndex ] = 0 ; // XRControllerData.enabled
548
608
if ( ! inputSources || ! inputSources . length || inputSources . length == 0 ) {
549
609
this . removeRemainingTouches ( ) ;
550
610
return ;
@@ -613,94 +673,92 @@ setTimeout(function () {
613
673
hand = 2 ;
614
674
}
615
675
616
- Module . HEAPF32 [ controller . bufferIndex + 1 ] = 1 ; // XRControllerData.enabled
617
- Module . HEAPF32 [ controller . bufferIndex + 2 ] = hand ; // XRControllerData.hand
676
+ Module . HEAPF32 [ controller . enabledIndex ] = 1 ; // XRControllerData.enabled
677
+ Module . HEAPF32 [ controller . handIndex ] = hand ; // XRControllerData.hand
618
678
619
679
if ( controller . updatedProfiles == 0 ) {
620
680
controller . profiles = inputSource . profiles ;
621
681
controller . updatedProfiles = 1 ;
622
682
}
623
683
624
- Module . HEAPF32 [ controller . bufferIndex + 3 ] = position . x ; // XRControllerData.positionX
625
- Module . HEAPF32 [ controller . bufferIndex + 4 ] = position . y ; // XRControllerData.positionY
626
- Module . HEAPF32 [ controller . bufferIndex + 5 ] = - position . z ; // XRControllerData.positionZ
684
+ Module . HEAPF32 [ controller . positionXIndex ] = position . x ; // XRControllerData.positionX
685
+ Module . HEAPF32 [ controller . positionYIndex ] = position . y ; // XRControllerData.positionY
686
+ Module . HEAPF32 [ controller . positionZIndex ] = - position . z ; // XRControllerData.positionZ
627
687
628
- Module . HEAPF32 [ controller . bufferIndex + 6 ] = - orientation . x ; // XRControllerData.rotationX
629
- Module . HEAPF32 [ controller . bufferIndex + 7 ] = - orientation . y ; // XRControllerData.rotationY
630
- Module . HEAPF32 [ controller . bufferIndex + 8 ] = orientation . z ; // XRControllerData.rotationZ
631
- Module . HEAPF32 [ controller . bufferIndex + 9 ] = orientation . w ; // XRControllerData.rotationW
688
+ Module . HEAPF32 [ controller . rotationXIndex ] = - orientation . x ; // XRControllerData.rotationX
689
+ Module . HEAPF32 [ controller . rotationYIndex ] = - orientation . y ; // XRControllerData.rotationY
690
+ Module . HEAPF32 [ controller . rotationZIndex ] = orientation . z ; // XRControllerData.rotationZ
691
+ Module . HEAPF32 [ controller . rotationWIndex ] = orientation . w ; // XRControllerData.rotationW
632
692
633
- if ( Module . HEAPF32 [ controller . bufferIndex + 20 ] == 0 && inputSource . gripSpace ) { // XRControllerData.updatedGrip
693
+ if ( Module . HEAPF32 [ controller . updatedGripIndex ] == 0 && inputSource . gripSpace ) { // XRControllerData.updatedGrip
634
694
var inputPose = frame . getPose ( inputSource . gripSpace , refSpace ) ;
635
695
if ( inputPose ) {
636
696
var gripPosition = inputPose . transform . position ;
637
697
var gripOrientation = inputPose . transform . orientation ;
638
698
639
- Module . HEAPF32 [ controller . bufferIndex + 21 ] = gripPosition . x ; // XRControllerData.gripPositionX
640
- Module . HEAPF32 [ controller . bufferIndex + 22 ] = gripPosition . y ; // XRControllerData.gripPositionY
641
- Module . HEAPF32 [ controller . bufferIndex + 23 ] = - gripPosition . z ; // XRControllerData.gripPositionZ
699
+ Module . HEAPF32 [ controller . gripPositionXIndex ] = gripPosition . x ; // XRControllerData.gripPositionX
700
+ Module . HEAPF32 [ controller . gripPositionYIndex ] = gripPosition . y ; // XRControllerData.gripPositionY
701
+ Module . HEAPF32 [ controller . gripPositionZIndex ] = - gripPosition . z ; // XRControllerData.gripPositionZ
642
702
643
- Module . HEAPF32 [ controller . bufferIndex + 24 ] = - gripOrientation . x ; // XRControllerData.gripRotationX
644
- Module . HEAPF32 [ controller . bufferIndex + 25 ] = - gripOrientation . y ; // XRControllerData.gripRotationY
645
- Module . HEAPF32 [ controller . bufferIndex + 26 ] = gripOrientation . z ; // XRControllerData.gripRotationZ
646
- Module . HEAPF32 [ controller . bufferIndex + 27 ] = gripOrientation . w ; // XRControllerData.gripRotationW
703
+ Module . HEAPF32 [ controller . gripRotationXIndex ] = - gripOrientation . x ; // XRControllerData.gripRotationX
704
+ Module . HEAPF32 [ controller . gripRotationYIndex ] = - gripOrientation . y ; // XRControllerData.gripRotationY
705
+ Module . HEAPF32 [ controller . gripRotationZIndex ] = gripOrientation . z ; // XRControllerData.gripRotationZ
706
+ Module . HEAPF32 [ controller . gripRotationWIndex ] = gripOrientation . w ; // XRControllerData.gripRotationW
647
707
648
- Module . HEAPF32 [ controller . bufferIndex + 20 ] = 1 ; // XRControllerData.updatedGrip
708
+ Module . HEAPF32 [ controller . updatedGripIndex ] = 1 ; // XRControllerData.updatedGrip
649
709
}
650
710
}
651
711
652
- var triggerIndex = controller . bufferIndex + 10 ;
653
- var squeezeIndex = controller . bufferIndex + 11 ;
654
712
// if there's gamepad, use the xr-standard mapping
655
713
if ( inputSource . gamepad ) {
656
714
for ( var j = 0 ; j < inputSource . gamepad . buttons . length ; j ++ ) {
657
715
switch ( j ) {
658
716
case 0 :
659
- Module . HEAPF32 [ triggerIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.trigger
717
+ Module . HEAPF32 [ controller . triggerIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.trigger
660
718
break ;
661
719
case 1 :
662
- Module . HEAPF32 [ squeezeIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.squeeze
720
+ Module . HEAPF32 [ controller . squeezeIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.squeeze
663
721
break ;
664
722
case 2 :
665
- Module . HEAPF32 [ controller . bufferIndex + 15 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.touchpad
723
+ Module . HEAPF32 [ controller . touchpadIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.touchpad
666
724
break ;
667
725
case 3 :
668
- Module . HEAPF32 [ controller . bufferIndex + 12 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.thumbstick
726
+ Module . HEAPF32 [ controller . thumbstickIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.thumbstick
669
727
break ;
670
728
case 4 :
671
- Module . HEAPF32 [ controller . bufferIndex + 18 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.buttonA
729
+ Module . HEAPF32 [ controller . buttonAIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.buttonA
672
730
break ;
673
731
case 5 :
674
- Module . HEAPF32 [ controller . bufferIndex + 19 ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.buttonB
732
+ Module . HEAPF32 [ controller . buttonBIndex ] = inputSource . gamepad . buttons [ j ] . value ; // XRControllerData.buttonB
675
733
break ;
676
734
}
677
735
}
678
736
679
- if ( Module . HEAPF32 [ triggerIndex ] <= 0.02 ) {
680
- Module . HEAPF32 [ triggerIndex ] = 0 ;
681
- } else if ( Module . HEAPF32 [ triggerIndex ] >= 0.98 ) {
682
- Module . HEAPF32 [ triggerIndex ] = 1 ;
737
+ if ( Module . HEAPF32 [ controller . triggerIndex ] <= 0.02 ) {
738
+ Module . HEAPF32 [ controller . triggerIndex ] = 0 ;
739
+ } else if ( Module . HEAPF32 [ controller . triggerIndex ] >= 0.98 ) {
740
+ Module . HEAPF32 [ controller . triggerIndex ] = 1 ;
683
741
}
684
742
685
- if ( Module . HEAPF32 [ squeezeIndex ] <= 0.02 ) {
686
- Module . HEAPF32 [ squeezeIndex ] = 0 ;
687
- } else if ( Module . HEAPF32 [ squeezeIndex ] >= 0.98 ) {
688
- Module . HEAPF32 [ squeezeIndex ] = 1 ;
743
+ if ( Module . HEAPF32 [ controller . squeezeIndex ] <= 0.02 ) {
744
+ Module . HEAPF32 [ controller . squeezeIndex ] = 0 ;
745
+ } else if ( Module . HEAPF32 [ controller . squeezeIndex ] >= 0.98 ) {
746
+ Module . HEAPF32 [ controller . squeezeIndex ] = 1 ;
689
747
}
690
748
691
749
for ( var j = 0 ; j < inputSource . gamepad . axes . length ; j ++ ) {
692
750
switch ( j ) {
693
751
case 0 :
694
- Module . HEAPF32 [ controller . bufferIndex + 16 ] = inputSource . gamepad . axes [ j ] ; // XRControllerData.touchpadX
752
+ Module . HEAPF32 [ controller . touchpadXIndex ] = inputSource . gamepad . axes [ j ] ; // XRControllerData.touchpadX
695
753
break ;
696
754
case 1 :
697
- Module . HEAPF32 [ controller . bufferIndex + 17 ] = - inputSource . gamepad . axes [ j ] ; // XRControllerData.touchpadY
755
+ Module . HEAPF32 [ controller . touchpadYIndex ] = - inputSource . gamepad . axes [ j ] ; // XRControllerData.touchpadY
698
756
break ;
699
757
case 2 :
700
- Module . HEAPF32 [ controller . bufferIndex + 13 ] = inputSource . gamepad . axes [ j ] ; // XRControllerData.thumbstickX
758
+ Module . HEAPF32 [ controller . thumbstickXIndex ] = inputSource . gamepad . axes [ j ] ; // XRControllerData.thumbstickX
701
759
break ;
702
760
case 3 :
703
- Module . HEAPF32 [ controller . bufferIndex + 14 ] = - inputSource . gamepad . axes [ j ] ; // XRControllerData.thumbstickY
761
+ Module . HEAPF32 [ controller . thumbstickYIndex ] = - inputSource . gamepad . axes [ j ] ; // XRControllerData.thumbstickY
704
762
break ;
705
763
}
706
764
}
@@ -749,17 +807,17 @@ setTimeout(function () {
749
807
session . addEventListener ( 'squeezeend' , this . onInputEvent ) ;
750
808
session . addEventListener ( 'visibilitychange' , this . onSessionVisibilityEvent ) ;
751
809
752
- this . xrData . controllerA . bufferIndex = Module . ControllersArrayOffset ;
753
- this . xrData . controllerB . bufferIndex = Module . ControllersArrayOffset + 28 ;
810
+ this . xrData . controllerA . setIndices ( Module . ControllersArrayOffset ) ;
811
+ this . xrData . controllerB . setIndices ( Module . ControllersArrayOffset + 28 ) ;
754
812
this . xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
755
813
this . xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
756
814
this . xrData . viewerHitTestPose . bufferIndex = Module . ViewerHitTestPoseArrayOffset ;
757
815
this . xrData . controllerA . updatedProfiles = 0 ;
758
816
this . xrData . controllerB . updatedProfiles = 0 ;
759
817
this . xrData . controllerA . profiles = [ ] ;
760
818
this . xrData . controllerB . profiles = [ ] ;
761
- Module . HEAPF32 [ this . xrData . controllerA . bufferIndex + 20 ] = 0 ; // XRControllerData.updatedGrip
762
- Module . HEAPF32 [ this . xrData . controllerB . bufferIndex + 20 ] = 0 ; // XRControllerData.updatedGrip
819
+ Module . HEAPF32 [ this . xrData . controllerA . updatedGripIndex ] = 0 ; // XRControllerData.updatedGrip
820
+ Module . HEAPF32 [ this . xrData . controllerB . updatedGripIndex ] = 0 ; // XRControllerData.updatedGrip
763
821
Module . HEAPF32 [ this . xrData . viewerHitTestPose . bufferIndex ] = - 1 ; // XRHitPoseData.frame
764
822
Module . HEAPF32 [ this . xrData . viewerHitTestPose . bufferIndex + 1 ] = 0 ; // XRHitPoseData.available
765
823
}
0 commit comments