@@ -108,30 +108,16 @@ setTimeout(function () {
108
108
}
109
109
110
110
function XRHandData ( ) {
111
- this . frame = 0 ;
112
- // TODO: set enabled 0 if hand was enable and then disable
113
- this . enabled = 0 ;
114
- this . hand = 0 ;
115
- this . trigger = 0 ;
116
- this . squeeze = 0 ;
117
- this . joints = [ ] ;
118
- for ( var i = 0 ; i < 25 ; i ++ ) {
119
- this . joints . push ( new XRJointData ( ) ) ;
120
- }
111
+ this . bufferIndex = 0 ;
121
112
this . poses = new Float32Array ( 16 * 25 ) ;
122
113
this . radii = new Float32Array ( 25 ) ;
123
114
this . jointQuaternion = new Float32Array ( 4 ) ;
124
115
this . jointIndex = 0 ;
116
+ this . unityJointIndex = 0 ;
125
117
this . handValuesType = 0 ;
126
118
this . hasRadii = false ;
127
119
}
128
120
129
- function XRJointData ( ) {
130
- this . position = [ 0 , 0 , 0 ] ;
131
- this . rotation = [ 0 , 0 , 0 , 1 ] ;
132
- this . radius = 0 ;
133
- }
134
-
135
121
function XRHitPoseData ( ) {
136
122
this . frame = 0 ;
137
123
this . available = 0 ;
@@ -344,23 +330,21 @@ setTimeout(function () {
344
330
345
331
this . xrData . controllerA . enabled = 0 ;
346
332
this . xrData . controllerB . enabled = 0 ;
347
- this . xrData . handLeft . enabled = 0 ;
348
- this . xrData . handRight . enabled = 0 ;
349
333
350
334
this . xrData . controllerA . frame = - 1 ;
351
335
this . xrData . controllerB . frame = - 1 ;
352
- this . xrData . handLeft . frame = - 1 ;
353
- this . xrData . handRight . frame = - 1 ;
336
+
337
+ this . xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
338
+ this . xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
339
+ Module . HEAPF32 [ this . xrData . handLeft . bufferIndex ] = - 1 ; // XRHandData.frame
340
+ Module . HEAPF32 [ this . xrData . handRight . bufferIndex ] = - 1 ; // XRHandData.frame
341
+ Module . HEAPF32 [ this . xrData . handLeft . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
342
+ Module . HEAPF32 [ this . xrData . handRight . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
354
343
355
344
this . updateUnityXRControllersData ( {
356
345
controllerA : this . xrData . controllerA ,
357
346
controllerB : this . xrData . controllerB
358
347
} ) ;
359
-
360
- this . updateUnityXRHandsData ( {
361
- handLeft : this . xrData . handLeft ,
362
- handRight : this . xrData . handRight
363
- } ) ;
364
348
365
349
this . gameModule . WebXR . OnEndXR ( ) ;
366
350
this . didNotifyUnity = false ;
@@ -426,12 +410,14 @@ setTimeout(function () {
426
410
427
411
if ( hand == 0 || hand == 2 ) {
428
412
xrData . controllerA = controller ;
429
- xrData . handRight . trigger = controller . trigger ;
430
- xrData . handRight . squeeze = controller . squeeze ;
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
431
416
} else {
432
417
xrData . controllerB = controller ;
433
- xrData . handLeft . trigger = controller . trigger ;
434
- xrData . handLeft . squeeze = controller . squeeze ;
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
435
421
}
436
422
} else {
437
423
var xPercentage = 0.5 ;
@@ -602,12 +588,14 @@ setTimeout(function () {
602
588
}
603
589
604
590
XRManager . prototype . getXRControllersData = function ( frame , inputSources , refSpace , xrData ) {
605
- xrData . handLeft . enabled = 0 ;
606
- xrData . handRight . enabled = 0 ;
591
+ xrData . handLeft . bufferIndex = Module . HandsArrayOffset ;
592
+ xrData . handRight . bufferIndex = Module . HandsArrayOffset + 205 ;
593
+ Module . HEAPF32 [ xrData . handLeft . bufferIndex ] = xrData . frameNumber ; // XRHandData.frame
594
+ Module . HEAPF32 [ xrData . handRight . bufferIndex ] = xrData . frameNumber ; // XRHandData.frame
595
+ Module . HEAPF32 [ xrData . handLeft . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
596
+ Module . HEAPF32 [ xrData . handRight . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
607
597
xrData . controllerA . enabled = 0 ;
608
598
xrData . controllerB . enabled = 0 ;
609
- xrData . handLeft . frame = xrData . frameNumber ;
610
- xrData . handRight . frame = xrData . frameNumber ;
611
599
xrData . controllerA . frame = xrData . frameNumber ;
612
600
xrData . controllerB . frame = xrData . frameNumber ;
613
601
if ( ! inputSources || ! inputSources . length || inputSources . length == 0 ) {
@@ -620,12 +608,12 @@ setTimeout(function () {
620
608
// Show the input source if it has a grip space
621
609
if ( inputSource . hand ) {
622
610
var xrHand = xrData . handLeft ;
623
- xrHand . hand = 1 ;
611
+ Module . HEAPF32 [ xrHand . bufferIndex + 2 ] = 1 ; // XRHandData.hand
624
612
if ( inputSource . handedness == 'right' ) {
625
613
xrHand = xrData . handRight ;
626
- xrHand . hand = 2 ;
614
+ Module . HEAPF32 [ xrHand . bufferIndex + 2 ] = 2 ; // XRHandData.hand
627
615
}
628
- xrHand . enabled = 1 ;
616
+ Module . HEAPF32 [ xrHand . bufferIndex + 1 ] = 1 ; // XRHandData.enabled
629
617
630
618
if ( xrHand . handValuesType == 0 ) {
631
619
if ( inputSource . hand . values ) {
@@ -638,7 +626,7 @@ setTimeout(function () {
638
626
xrHand . handValuesType == 1 ? inputSource . hand . values ( ) : inputSource . hand ,
639
627
refSpace ,
640
628
xrHand . poses ) ) {
641
- xrHand . enabled = 0 ;
629
+ Module . HEAPF32 [ xrHand . bufferIndex + 1 ] = 0 ; // XRHandData.enabled
642
630
continue ;
643
631
}
644
632
if ( ! xrHand . hasRadii )
@@ -649,17 +637,18 @@ setTimeout(function () {
649
637
}
650
638
for ( var j = 0 ; j < 25 ; j ++ ) {
651
639
xrHand . jointIndex = j * 16 ;
640
+ xrHand . unityJointIndex = xrHand . bufferIndex + 5 + ( j * 8 ) ;
652
641
if ( ! isNaN ( xrHand . poses [ xrHand . jointIndex ] ) ) {
653
- xrHand . joints [ j ] . position [ 0 ] = xrHand . poses [ xrHand . jointIndex + 12 ] ;
654
- xrHand . joints [ j ] . position [ 1 ] = xrHand . poses [ xrHand . jointIndex + 13 ] ;
655
- xrHand . joints [ j ] . position [ 2 ] = - xrHand . poses [ xrHand . jointIndex + 14 ] ;
642
+ Module . HEAPF32 [ xrHand . unityJointIndex ] = xrHand . poses [ xrHand . jointIndex + 12 ] ; // XRJointData.position.x
643
+ Module . HEAPF32 [ xrHand . unityJointIndex + 1 ] = xrHand . poses [ xrHand . jointIndex + 13 ] ; // XRJointData.position.y
644
+ Module . HEAPF32 [ xrHand . unityJointIndex + 2 ] = - xrHand . poses [ xrHand . jointIndex + 14 ] ; // XRJointData.position.z
656
645
this . quaternionFromMatrix ( xrHand . jointIndex , xrHand . poses , xrHand . jointQuaternion ) ;
657
- xrHand . joints [ j ] . rotation [ 0 ] = - xrHand . jointQuaternion [ 0 ] ;
658
- xrHand . joints [ j ] . rotation [ 1 ] = - xrHand . jointQuaternion [ 1 ] ;
659
- xrHand . joints [ j ] . rotation [ 2 ] = xrHand . jointQuaternion [ 2 ] ;
660
- xrHand . joints [ j ] . rotation [ 3 ] = xrHand . jointQuaternion [ 3 ] ;
646
+ Module . HEAPF32 [ xrHand . unityJointIndex + 3 ] = - xrHand . jointQuaternion [ 0 ] ; // XRJointData.rotation.x
647
+ Module . HEAPF32 [ xrHand . unityJointIndex + 4 ] = - xrHand . jointQuaternion [ 1 ] ; // XRJointData.rotation.y
648
+ Module . HEAPF32 [ xrHand . unityJointIndex + 5 ] = xrHand . jointQuaternion [ 2 ] ; // XRJointData.rotation.z
649
+ Module . HEAPF32 [ xrHand . unityJointIndex + 6 ] = xrHand . jointQuaternion [ 3 ] ; // XRJointData.rotation.w
661
650
if ( ! isNaN ( xrHand . radii [ j ] ) ) {
662
- xrHand . joints [ j ] . radius = xrHand . radii [ j ] ;
651
+ Module . HEAPF32 [ xrHand . unityJointIndex + 7 ] = xrHand . radii [ j ] ; // XRJointData.radius
663
652
}
664
653
}
665
654
}
@@ -960,11 +949,6 @@ setTimeout(function () {
960
949
controllerA : xrData . controllerA ,
961
950
controllerB : xrData . controllerB
962
951
} ) ;
963
-
964
- this . updateUnityXRHandsData ( {
965
- handLeft : xrData . handLeft ,
966
- handRight : xrData . handRight
967
- } ) ;
968
952
969
953
if ( ! this . didNotifyUnity )
970
954
{
@@ -1069,30 +1053,6 @@ setTimeout(function () {
1069
1053
} ) ;
1070
1054
}
1071
1055
1072
- XRManager . prototype . updateUnityXRHandsData = function ( data ) {
1073
- var index = 0 ;
1074
- if ( Module . HandsArray . byteLength == 0 ) {
1075
- Module . HandsArray = new Float32Array ( buffer , Module . HandsArrayOffset , Module . HandsArrayLength ) ;
1076
- }
1077
- Object . keys ( data ) . forEach ( function ( key , i ) {
1078
- Module . HandsArray [ index ++ ] = data [ key ] . frame ;
1079
- Module . HandsArray [ index ++ ] = data [ key ] . enabled ;
1080
- Module . HandsArray [ index ++ ] = data [ key ] . hand ;
1081
- Module . HandsArray [ index ++ ] = data [ key ] . trigger ;
1082
- Module . HandsArray [ index ++ ] = data [ key ] . squeeze ;
1083
- for ( var j = 0 ; j < 25 ; j ++ ) {
1084
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . position [ 0 ] ;
1085
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . position [ 1 ] ;
1086
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . position [ 2 ] ;
1087
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 0 ] ;
1088
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 1 ] ;
1089
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 2 ] ;
1090
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . rotation [ 3 ] ;
1091
- Module . HandsArray [ index ++ ] = data [ key ] . joints [ j ] . radius ;
1092
- }
1093
- } ) ;
1094
- }
1095
-
1096
1056
XRManager . prototype . updateUnityXRViewerHitTestPose = function ( data ) {
1097
1057
var index = 0 ;
1098
1058
if ( Module . ViewerHitTestPoseArray . byteLength == 0 ) {
0 commit comments