bool GetHandFromHandsArray(int handIndex, ref WebXRHandData handObject)
        {
            int arrayPosition = handIndex * 205;
            int frameNumber   = (int)handsArray[arrayPosition++];

            if (handObject.frame == frameNumber)
            {
                return(false);
            }

            handObject.frame   = frameNumber;
            handObject.enabled = handsArray[arrayPosition++] != 0;
            handObject.hand    = (int)handsArray[arrayPosition++];
            handObject.trigger = handsArray[arrayPosition++];
            handObject.squeeze = handsArray[arrayPosition++];
            if (!handObject.enabled)
            {
                return(true);
            }

            for (int i = 0; i <= (int)WebXRHandJoint.pinky_finger_tip; i++)
            {
                handObject.joints[i].position = new Vector3(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++]);
                handObject.joints[i].rotation = new Quaternion(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++],
                                                               handsArray[arrayPosition++]);
                handObject.joints[i].radius = handsArray[arrayPosition++];
            }

            return(true);
        }
Exemple #2
0
    bool GetHandFromHandsArray(int handIndex, ref WebXRHandData handObject)
    {
      int arrayPosition = handIndex * 230;
      int frameNumber = (int)handsArray[arrayPosition++];
      if (handObject.frame == frameNumber)
      {
        return false;
      }

      handObject.frame = frameNumber;
      handObject.enabled = handsArray[arrayPosition++] != 0;
      handObject.hand = (int)handsArray[arrayPosition++];
      handObject.trigger = handsArray[arrayPosition++];
      handObject.squeeze = handsArray[arrayPosition++];
      if (!handObject.enabled)
      {
        return true;
      }

      for (int i = 0; i <= WebXRHandData.LITTLE_PHALANX_TIP; i++)
      {
        handObject.joints[i].enabled = handsArray[arrayPosition++] != 0;
        handObject.joints[i].position = new Vector3(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++]);
        handObject.joints[i].rotation = new Quaternion(handsArray[arrayPosition++], handsArray[arrayPosition++], handsArray[arrayPosition++],
            handsArray[arrayPosition++]);
        handObject.joints[i].radius = handsArray[arrayPosition++];
      }

      return true;
    }
Exemple #3
0
        private void OnHandUpdateInternal(WebXRHandData handData)
        {
            if (handData.hand == (int)hand)
            {
                if (!handData.enabled)
                {
                    SetHandActive(false);
                    return;
                }
                SetControllerActive(false);
                SetHandActive(true);

                transform.localPosition = handData.joints[0].position;
                transform.localRotation = handData.joints[0].rotation;

                Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);

                trigger = handData.trigger;
                squeeze = handData.squeeze;

                WebXRControllerButton[] buttons = new WebXRControllerButton[2];
                buttons[(int)ButtonTypes.Trigger] = new WebXRControllerButton(trigger == 1, trigger);
                buttons[(int)ButtonTypes.Grip]    = new WebXRControllerButton(squeeze == 1, squeeze);
                UpdateButtons(buttons);

                OnHandUpdate?.Invoke(handData);
            }
        }
        private void OnHandUpdateInternal(WebXRHandData handData)
        {
            if (handData.hand == (int)hand)
            {
                if (!handData.enabled)
                {
                    SetHandActive(false);
                    return;
                }
                SetControllerActive(false);
                SetHandActive(true);

                transform.localPosition = handData.joints[0].position;
                transform.localRotation = handData.joints[0].rotation;

                trigger = handData.trigger;
                squeeze = handData.squeeze;

                if (buttons?.Length != 6)
                {
                    InitButtons();
                }
                else
                {
                    UpdateHandButtons();
                }

                OnHandUpdate?.Invoke(handData);
            }
        }
Exemple #5
0
        private void OnHandUpdate(WebXRHandData handData)
        {
            if (handData.hand == (int)hand)
            {
                if (!handData.enabled)
                {
                    SetHandJointsVisible(false);
                    return;
                }
                SetVisible(false);
                SetHandJointsVisible(true);

                transform.localPosition = handData.joints[0].position;
                transform.localRotation = handData.joints[0].rotation;

                Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);

                for (int i = 0; i <= WebXRHandData.LITTLE_PHALANX_TIP; i++)
                {
                    if (handData.joints[i].enabled)
                    {
                        if (handJoints.ContainsKey(i))
                        {
                            handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
                            handJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
                        }
                        else
                        {
                            var clone = Instantiate(handJointPrefab,
                                                    rotationOffset * (handData.joints[i].position - handData.joints[0].position),
                                                    rotationOffset * handData.joints[i].rotation,
                                                    transform);
                            if (handData.joints[i].radius > 0f)
                            {
                                clone.localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
                            }
                            else
                            {
                                clone.localScale = new Vector3(0.005f, 0.005f, 0.005f);
                            }
                            handJoints.Add(i, clone);
                        }
                    }
                }

                trigger = handData.trigger;
                squeeze = handData.squeeze;

                WebXRControllerButton[] buttons = new WebXRControllerButton[2];
                buttons[0] = new WebXRControllerButton(trigger == 1, trigger);
                buttons[1] = new WebXRControllerButton(squeeze == 1, squeeze);
                UpdateButtons(buttons);
            }
        }