private void OnEnable()
 {
     if (IsInstance)
     {
         m_viveRole.onDeviceIndexChanged += OnDeviceIndexChanged;
         OnDeviceIndexChanged(m_viveRole.GetDeviceIndex());
     }
 }
        public uint GetModelDeviceIndex()
        {
            if (!enabled)
            {
                return(VRModule.INVALID_DEVICE_INDEX);
            }

            uint result;

            switch (m_mode)
            {
            case Mode.ViveRole:
                result = m_viveRole.GetDeviceIndex();
                break;

            case Mode.DeivceIndex:
                result = (uint)m_deviceIndex;
                break;

            case Mode.Disable:
            default:
                return(VRModule.INVALID_DEVICE_INDEX);
            }

            return(result);
        }
Exemple #3
0
        public bool TryGetValidTooltipRig(ControllerButton button, out TooltipRig rig)
        {
            rig = default(TooltipRig);
            if (!EnumArrayBase <ControllerButton> .StaticIsValidIndex((int)button))
            {
                return(false);
            }

            var model       = VRModule.GetDeviceState(m_viveRole.GetDeviceIndex()).deviceModel;
            var rigSetAsset = (TooltipRigAsset)null;

            if (m_customTooltipRigSet != null)
            {
                rigSetAsset = m_customTooltipRigSet[(int)model];
            }

            if (rigSetAsset != null || TooltipRigAsset.TryGetDefaultAsset(model, out rigSetAsset))
            {
                var entries = rigSetAsset.rigEntries;
                if (entries != null && entries.Count > 0)
                {
                    for (int i = 0, imax = entries.Count; i < imax; ++i)
                    {
                        var entry = entries[i];
                        if (entry.button == button)
                        {
                            rig = entry.tooltipRig;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        public virtual void OnNewPoses()
        {
            var deviceIndex = m_viveRole.GetDeviceIndex();
            var isValid     = VivePose.IsValid(deviceIndex);

            if (isValid)
            {
                TrackPose(VivePose.GetPose(deviceIndex), origin);
            }

            SetIsValid(isValid);
        }
        public void Update()
        {
            deviceState.Update(viveRole.GetDeviceIndex());
            controllerState.Update(viveRole);

            if (sendHaptics)
            {
                sendHaptics = false;
                ViveInput.TriggerHapticVibration(viveRole, hapticParam.durationSeconds, hapticParam.frequency, hapticParam.amplitude, hapticParam.startSecondsFromNow);
            }

            if (sendLegacyHaptics)
            {
                sendLegacyHaptics = false;
                ViveInput.TriggerHapticPulse(viveRole, legacyHapticParam.durationMicroSec);
            }
        }
        public virtual void OnNewPoses()
        {
            var deviceIndex = m_viveRole.GetDeviceIndex();
            var isValid     = VivePose.IsValid(deviceIndex);

            if (isValid)
            {
                var pose = VivePose.GetPose(deviceIndex);
                if (m_origin != null && m_origin != transform.parent)
                {
                    pose = new RigidPose(m_origin.transform) * pose;
                    TrackPose(pose, false);
                }
                else
                {
                    TrackPose(pose, true);
                }
            }

            SetIsValid(isValid);
        }
 public static bool IsCalibrating(ViveRoleProperty role)
 {
     return(IsCalibrating(role.GetDeviceIndex()));
 }
Exemple #8
0
 public static bool TryGetHandJointPose(ViveRoleProperty role, HandJointName jointName, out JointPose pose)
 {
     return(TryGetHandJointPose(role.GetDeviceIndex(), jointName, out pose));
 }
 /// <summary>
 /// Set target pose to tracking pose of the device identified by role relative to the origin
 /// </summary>
 public static void SetPose(Transform target, ViveRoleProperty role, Transform origin = null)
 {
     SetPose(target, role.GetDeviceIndex(), origin);
 }
 /// <summary>
 /// Returns tracking pose of the device identified by role
 /// </summary>
 public static RigidPose GetPose(ViveRoleProperty role, Transform origin = null)
 {
     return(GetPose(role.GetDeviceIndex(), origin));
 }
 public static Vector3 GetAngularVelocity(ViveRoleProperty role, Transform origin = null)
 {
     return(GetAngularVelocity(role.GetDeviceIndex(), origin));
 }
 public static bool IsUninitialized(ViveRoleProperty role)
 {
     return(IsUninitialized(role.GetDeviceIndex()));
 }
        private void UpdatePoses()
        {
            if (!m_isValidModel)
            {
                return;
            }

            var deviceIndex = m_viveRole.GetDeviceIndex();

            if (!VRModule.IsValidDeviceIndex(deviceIndex))
            {
                return;
            }

            var deviceState = VRModule.GetCurrentDeviceState(deviceIndex);

            if (deviceState.GetValidHandJointCount() <= 0)
            {
                return;
            }

            // Store last pose
            foreach (var pair in m_modelJoints.EnumValues)
            {
                if (pair.Value)
                {
                    s_lastJointPoses[pair.Key] = new JointPose(pair.Value.position, pair.Value.rotation);
                }
                else
                {
                    s_lastJointPoses[pair.Key] = default(JointPose);
                }
            }

            var roomSpaceJoints           = deviceState.readOnlyHandJoints;
            var roomSpaceWristPose        = roomSpaceJoints[HandJointName.Wrist].pose;
            var roomSpaceWristPoseInverse = roomSpaceWristPose.GetInverse();
            var roomSpaceHandPoseInverse  = deviceState.pose.GetInverse();
            var wristTransform            = m_modelJoints[HandJointName.Wrist];

            wristTransform.localScale = Vector3.one;

            RigidPose wristLocalPose = roomSpaceHandPoseInverse * roomSpaceWristPose * m_modelOffsetInverse;

            wristTransform.localPosition = wristLocalPose.pos;
            wristTransform.localRotation = wristLocalPose.rot;

            var palmTransform = m_modelJoints[HandJointName.Palm];

            if (palmTransform != null)
            {
                var data = roomSpaceJoints[HandJointName.Palm];
                if (data.isValid)
                {
                    UpdateJointTransformLocal(wristTransform, palmTransform, roomSpaceWristPoseInverse * data.pose);
                }
            }

            UpdateFingerJoints(roomSpaceJoints, wristTransform, roomSpaceWristPoseInverse, HandJointName.ThumbTrapezium, HandJointName.ThumbTip);
            UpdateFingerJoints(roomSpaceJoints, wristTransform, roomSpaceWristPoseInverse, HandJointName.IndexMetacarpal, HandJointName.IndexTip);
            UpdateFingerJoints(roomSpaceJoints, wristTransform, roomSpaceWristPoseInverse, HandJointName.MiddleMetacarpal, HandJointName.MiddleTip);
            UpdateFingerJoints(roomSpaceJoints, wristTransform, roomSpaceWristPoseInverse, HandJointName.RingMetacarpal, HandJointName.RingTip);
            UpdateFingerJoints(roomSpaceJoints, wristTransform, roomSpaceWristPoseInverse, HandJointName.PinkyMetacarpal, HandJointName.PinkyTip);

            if (m_rigMode == RigMode.RotateAndScale)
            {
                wristTransform.localScale = Vector3.one * (CalculateJointLength(deviceState.readOnlyHandJoints) / m_modelLength);
            }

            // Stabilize
            if (m_stabilizerAngleThreshold > 0)
            {
                foreach (var pair in m_modelJoints.EnumValues)
                {
                    if (!pair.Value)
                    {
                        continue;
                    }

                    Quaternion lastRotation    = s_lastJointPoses[pair.Key].pose.rot;
                    Quaternion currentRotation = pair.Value.rotation;
                    float      diffAngle       = Quaternion.Angle(lastRotation, currentRotation);
                    if (diffAngle < m_stabilizerAngleThreshold)
                    {
                        if (m_stabilizerSlerpSpeedCoef > 0)
                        {
                            pair.Value.rotation = Quaternion.Slerp(lastRotation, currentRotation, m_stabilizerSlerpSpeedCoef * Time.deltaTime);
                        }
                        else
                        {
                            pair.Value.rotation = lastRotation;
                        }
                    }
                    else
                    {
                        pair.Value.rotation = Quaternion.RotateTowards(currentRotation, lastRotation, m_stabilizerAngleThreshold);
                    }
                }
            }

            if (m_debugJoint != null)
            {
                foreach (var joint in deviceState.readOnlyHandJoints.EnumValues)
                {
                    var index    = joint.Key;
                    var poseData = joint.Value;

                    if (poseData.isValid && TryInitDebugJoints())
                    {
                        var debugJointTransform = m_debugJoints[index];
                        if (debugJointTransform == null)
                        {
                            var obj = Instantiate(m_debugJoint);
                            obj.name = index.ToString();
                            obj.transform.SetParent(m_debugJointRoot.transform, false);
                            m_debugJoints[index] = debugJointTransform = obj.transform;
                        }

                        RigidPose.SetPose(debugJointTransform, roomSpaceHandPoseInverse * poseData.pose);
                    }
                }
            }
        }
 public static bool IsOutOfRange(ViveRoleProperty role)
 {
     return(IsOutOfRange(role.GetDeviceIndex()));
 }
 /// <summary>
 /// Returns true if tracking data of the device identified by role has valid value.
 /// </summary>
 public static bool HasTracking(ViveRoleProperty role)
 {
     return(HasTracking(role.GetDeviceIndex()));
 }
 /// <summary>
 /// Returns true if the device identified by role is connected.
 /// </summary>
 public static bool IsConnected(ViveRoleProperty role)
 {
     return(IsConnected(role.GetDeviceIndex()));
 }
Exemple #17
0
 public static int GetHandJointCount(ViveRoleProperty role)
 {
     return(GetHandJointCount(role.GetDeviceIndex()));
 }
Exemple #18
0
 public static JointEnumArray.IReadOnly GetAllHandJoints(ViveRoleProperty role)
 {
     return(GetAllHandJoints(role.GetDeviceIndex()));
 }