- Home /
 
How to get the vertices positions of the meshes on the hand in Oculus Quest?
Sorry I'm new to this field and don't really know anything. In a script I'm writing I wish to get the position vectors of the vertices on the hand, I think they are in OVRPlugin.cs and OVRMesh.cs but I don't know how to refer to them (or if it's possible to refer) in the script I'm writing. How should I do this correctly?
Sorry I didn't make myself clear, I'm trying to get the vertices of the meshes on the hand
Answer by rh_galaxy · Oct 13, 2021 at 11:13 AM
[Update: See now that it doesn't answer the question, but I leave it, maybe it helps someone. This is how I get position and rotation of the hand controllers or the head in my VR game. ] This works for me on both Rift and Quest. Unity 2021.1.6f1.
 using UnityEngine;
 using UnityEngine.XR; //new xr system
 using UnityEngine.InputSystem; //new input system
 int iRightHanded = 0;
 internal Vector3 vPosition;
 internal Vector3 vDirection;
 internal Quaternion qRotation;
 //runs every frame, put it on a relevant object. I have it in my singleton CameraController object
 private void Update()
 {
     Mouse mouse = Mouse.current;
     Gamepad gamepad = Gamepad.current;
     UnityEngine.XR.InputDevice handRDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
     UnityEngine.XR.InputDevice handLDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
     //switch hand/use gamepad?
     {
         bool triggerRSupported = handRDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.trigger, out float triggerR);
         bool button1RSupported = handRDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.primaryButton, out bool button1R);
         bool button2RSupported = handRDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.secondaryButton, out bool button2R);
         bool triggerLSupported = handLDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.trigger, out float triggerL);
         bool button1LSupported = handLDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.primaryButton, out bool button1L);
         bool button2LSupported = handLDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.secondaryButton, out bool button2L);
         if (triggerR > 0.5f || button1R || button2R)
         {
             iRightHanded = 1;
         }
         else if (triggerL > 0.5f || button1L || button2L)
         {
             iRightHanded = 2;
         }
         if (gamepad != null)
         {
             if (gamepad.rightTrigger.ReadValue() > 0.5f || gamepad.buttonSouth.isPressed
                 || gamepad.buttonEast.isPressed)
             {
                 iRightHanded = 0;
             }
         }
         if (mouse != null)
         {
             if (mouse.rightButton.isPressed)
             {
                 iRightHanded = 0;
             }
         }
     }
     //update pointing movement (first head)
     vPosition = Camera.main.transform.position;
     vDirection = Camera.main.transform.forward;
     qRotation = Camera.main.transform.rotation;
     //then right hand
     if (iRightHanded == 1)
     {
         bool posRSupported = handRDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.devicePosition, out Vector3 posR);
         vPosition = transform.TransformPoint(posR); //to world coords
         bool rotRSupported = handRDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.deviceRotation, out Quaternion rotR);
         vDirection = rotR * Vector3.forward;
         vDirection = transform.TransformDirection(vDirection);
         qRotation = Quaternion.LookRotation(vDirection);
     }
     //then left hand
     if (iRightHanded == 2)
     {
         bool posLSupported = handLDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.devicePosition, out Vector3 posL);
         vPosition = transform.TransformPoint(posL); //to world coords
         bool rotLSupported = handLDevice.TryGetFeatureValue(
             UnityEngine.XR.CommonUsages.deviceRotation, out Quaternion rotL);
         vDirection = rotL * Vector3.forward;
         vDirection = transform.TransformDirection(vDirection);
         qRotation = Quaternion.LookRotation(vDirection);
     }
 
     //vPosition is world position of either head, right or left hand
     //vDirection is the pointing vector of either head, right or left hand
     //qRotation can be used as direction also
 }
 
               Also includes how to handle gamepad and point with your head. If you don't want world coordinates just take them before transform.
Thank you for your answer!! Actually I want to ask for the position vector array of the vertices of the mesh on the hand, sorry I didn't make myself clear, but still your answer is very useful thanks a lot!
Your answer