Skip to content

Commit 013d2c2

Browse files
committed
Add targetRaySpace for hands
1 parent 21e59ad commit 013d2c2

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private void OnHandUpdate(WebXRHandData handData)
274274
MetaAimHand.left.UpdateHand(
275275
true,
276276
aimFlags,
277-
new Pose(handData.joints[10].position, handData.joints[10].rotation),
277+
new Pose(handData.pointerPosition, handData.pointerRotation),
278278
handData.trigger,
279279
0,
280280
0,
@@ -286,7 +286,7 @@ private void OnHandUpdate(WebXRHandData handData)
286286
MetaAimHand.right.UpdateHand(
287287
true,
288288
aimFlags,
289-
new Pose(handData.joints[10].position, handData.joints[10].rotation),
289+
new Pose(handData.pointerPosition, handData.pointerRotation),
290290
handData.trigger,
291291
0,
292292
0,

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ setTimeout(function () {
142142
this.handIndex = 0;
143143
this.triggerIndex = 0;
144144
this.squeezeIndex = 0;
145+
this.pointerPositionXIndex = 0;
146+
this.pointerPositionYIndex = 0;
147+
this.pointerPositionZIndex = 0;
148+
this.pointerRotationXIndex = 0;
149+
this.pointerRotationYIndex = 0;
150+
this.pointerRotationZIndex = 0;
151+
this.pointerRotationWIndex = 0;
145152
this.jointsStartIndex = 0;
146153
this.poses = new Float32Array(16 * 25);
147154
this.radii = new Float32Array(25);
@@ -157,6 +164,13 @@ setTimeout(function () {
157164
this.handIndex = index++;
158165
this.triggerIndex = index++;
159166
this.squeezeIndex = index++;
167+
this.pointerPositionXIndex = index++;
168+
this.pointerPositionYIndex = index++;
169+
this.pointerPositionZIndex = index++;
170+
this.pointerRotationXIndex = index++;
171+
this.pointerRotationYIndex = index++;
172+
this.pointerRotationZIndex = index++;
173+
this.pointerRotationWIndex = index++;
160174
this.jointsStartIndex = index;
161175
}
162176
}
@@ -718,6 +732,19 @@ setTimeout(function () {
718732
xrHand.bufferJointIndex++;
719733
}
720734
}
735+
// Get pointer pose for hand
736+
var inputRayPose = frame.getPose(inputSource.targetRaySpace, refSpace);
737+
if (inputRayPose) {
738+
var position = inputRayPose.transform.position;
739+
var orientation = inputRayPose.transform.orientation;
740+
Module.HEAPF32[xrHand.pointerPositionXIndex] = position.x; // XRHandData.pointerPositionX
741+
Module.HEAPF32[xrHand.pointerPositionYIndex] = position.y; // XRHandData.pointerPositionY
742+
Module.HEAPF32[xrHand.pointerPositionZIndex] = -position.z; // XRHandData.pointerPositionZ
743+
Module.HEAPF32[xrHand.pointerRotationXIndex] = -orientation.x; // XRHandData.pointerRotationX
744+
Module.HEAPF32[xrHand.pointerRotationYIndex] = -orientation.y; // XRHandData.pointerRotationY
745+
Module.HEAPF32[xrHand.pointerRotationZIndex] = orientation.z; // XRHandData.pointerRotationZ
746+
Module.HEAPF32[xrHand.pointerRotationWIndex] = orientation.w; // XRHandData.pointerRotationW
747+
}
721748
} else if (inputSource.gripSpace) {
722749
var inputRayPose = frame.getPose(inputSource.targetRaySpace, refSpace);
723750
if (inputRayPose) {
@@ -890,7 +917,7 @@ setTimeout(function () {
890917
this.xrData.controllerA.setIndices(Module.ControllersArrayOffset);
891918
this.xrData.controllerB.setIndices(Module.ControllersArrayOffset + 34);
892919
this.xrData.handLeft.setIndices(Module.HandsArrayOffset);
893-
this.xrData.handRight.setIndices(Module.HandsArrayOffset + 205);
920+
this.xrData.handRight.setIndices(Module.HandsArrayOffset + 212);
894921
this.xrData.viewerHitTestPose.setIndices(Module.ViewerHitTestPoseArrayOffset);
895922
this.xrData.controllerA.updatedProfiles = 0;
896923
this.xrData.controllerB.updatedProfiles = 0;

Packages/webxr/Runtime/Scripts/WebXRControllerData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class WebXRHandData
7575
public int hand;
7676
public float trigger;
7777
public float squeeze;
78+
public Vector3 pointerPosition;
79+
public Quaternion pointerRotation;
7880
public WebXRJointData[] joints = new WebXRJointData[25];
7981
}
8082

Packages/webxr/Runtime/XRPlugin/WebXRSubsystem.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ internal delegate void StartXREvent(int viewsCount,
358358
float[] controllersArray = new float[2 * 34];
359359

360360
// Shared array for hands data
361-
float[] handsArray = new float[2 * (25 * 8 + 5)];
361+
float[] handsArray = new float[2 * (25 * 8 + 5 + 7)]; // 2 hands, 25 joints
362362

363363
// Shared array for hit-test pose data
364364
float[] viewerHitTestPoseArray = new float[9];
@@ -587,7 +587,7 @@ bool GetGamepadFromControllersArray(int controllerIndex, ref WebXRControllerData
587587

588588
bool GetHandFromHandsArray(int handIndex, ref WebXRHandData handObject)
589589
{
590-
int arrayPosition = handIndex * 205;
590+
int arrayPosition = handIndex * 212;
591591
int frameNumber = (int)handsArray[arrayPosition++];
592592
if (handObject.frame == frameNumber)
593593
{
@@ -604,6 +604,9 @@ bool GetHandFromHandsArray(int handIndex, ref WebXRHandData handObject)
604604
return true;
605605
}
606606

607+
handObject.pointerPosition = new Vector3(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++]);
608+
handObject.pointerRotation = new Quaternion(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++],
609+
handsArray[arrayPosition++]);
607610
for (int i = 0; i <= (int)WebXRHandJoint.pinky_finger_tip; i++)
608611
{
609612
handObject.joints[i].position = new Vector3(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++]);

0 commit comments

Comments
 (0)