Skip to content

Commit bad3ae1

Browse files
authored
Merge pull request #351 from De-Panther/apple_vision_pro_support
Manually detect XR Hand pinch to support Apple Vision Pro
2 parents 6cc008e + 5ad2c82 commit bad3ae1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Packages/webxr/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- XR Hand pinch is now detected manually instead of relying on system select event, to support Apple Vision Pro.
11+
912
### Fixed
1013
- Errors of Module._malloc and Module._free are not functions.
1114

Packages/webxr/Runtime/Plugins/WebGL/webxr.jspre

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ void main()
210210
this.bufferJointIndex = 0;
211211
this.handValuesType = 0;
212212
this.hasRadii = false;
213+
this.pinchSelectDistanceStart = 0.014;
214+
this.pinchSelectDistanceEnd = 0.015;
215+
this.pinchDistance = 1;
216+
this.thumbTip = 4 * 16;
217+
this.indexTip = 9 * 16;
213218

214219
this.setIndices = function(index) {
215220
this.frameIndex = index++;
@@ -546,10 +551,8 @@ void main()
546551
}
547552

548553
if (hand == 0 || hand == 2) {
549-
Module.HEAPF32[xrData.handRight.triggerIndex] = Module.HEAPF32[controller.triggerIndex]; // XRHandData.trigger
550554
Module.HEAPF32[xrData.handRight.squeezeIndex] = Module.HEAPF32[controller.squeezeIndex]; // XRHandData.squeeze
551555
} else {
552-
Module.HEAPF32[xrData.handLeft.triggerIndex] = Module.HEAPF32[controller.triggerIndex]; // XRHandData.trigger
553556
Module.HEAPF32[xrData.handLeft.squeezeIndex] = Module.HEAPF32[controller.squeezeIndex]; // XRHandData.squeeze
554557
}
555558
} else {
@@ -804,6 +807,21 @@ void main()
804807
Module.HEAPF32[xrHand.pointerRotationZIndex] = orientation.z; // XRHandData.pointerRotationZ
805808
Module.HEAPF32[xrHand.pointerRotationWIndex] = orientation.w; // XRHandData.pointerRotationW
806809
}
810+
xrHand.pinchDistance = 1;
811+
if (!isNaN(xrHand.poses[xrHand.thumbTip])
812+
&& !isNaN(xrHand.poses[xrHand.indexTip])) {
813+
xrHand.pinchDistance = this.vector3Distance(xrHand.poses[xrHand.thumbTip + 12],
814+
xrHand.poses[xrHand.thumbTip + 13],
815+
xrHand.poses[xrHand.thumbTip + 14],
816+
xrHand.poses[xrHand.indexTip + 12],
817+
xrHand.poses[xrHand.indexTip + 13],
818+
xrHand.poses[xrHand.indexTip + 14]);
819+
}
820+
if (Module.HEAPF32[xrHand.triggerIndex] === 0) {
821+
Module.HEAPF32[xrHand.triggerIndex] = xrHand.pinchDistance <= xrHand.pinchSelectDistanceStart ? 1 : 0;
822+
} else {
823+
Module.HEAPF32[xrHand.triggerIndex] = xrHand.pinchDistance > xrHand.pinchSelectDistanceEnd ? 0 : 1;
824+
}
807825
} else if (inputSource.gripSpace) {
808826
var inputRayPose = frame.getPose(inputSource.targetRaySpace, refSpace);
809827
if (inputRayPose) {

0 commit comments

Comments
 (0)