Ejemplo n.º 1
0
        /// <summary>
        /// Gets updated hand data for the current frame.
        /// </summary>
        /// <param name="spatialInteractionSourceState">Platform provided current input source state for the hand.</param>
        /// <param name="includeMeshData">If set, hand mesh information will be included in <see cref="HandData.Mesh"/>.</param>
        /// <param name="handData">The output <see cref="HandData"/>.</param>
        /// <returns>True, if data conversion was a success.</returns>
        public bool TryGetHandData(SpatialInteractionSourceState spatialInteractionSourceState, bool includeMeshData, out HandData handData)
        {
            // Here we check whether the hand is being tracked at all by the WMR system.
            HandPose handPose = spatialInteractionSourceState.TryGetHandPose();

            if (handPose == null)
            {
                handData = default;
                return(false);
            }

            // The hand is being tracked, next we verify it meets our confidence requirements to consider
            // it tracked.
            var platformJointPoses = new JointPose[jointIndices.Length];

            handData = new HandData
            {
                TrackingState = handPose.TryGetJoints(spatialCoordinateSystem, jointIndices, platformJointPoses) ? TrackingState.Tracked : TrackingState.NotTracked,
                UpdatedAt     = DateTimeOffset.UtcNow.Ticks
            };

            // If the hand is tracked per requirements, we get updated joint data
            // and other data needed for updating the hand controller's state.
            if (handData.TrackingState == TrackingState.Tracked)
            {
                handData.RootPose    = GetHandRootPose(platformJointPoses);
                handData.Joints      = GetJointPoses(platformJointPoses, handData.RootPose);
                handData.PointerPose = GetPointerPose(spatialInteractionSourceState);

                if (includeMeshData && TryGetUpdatedHandMeshData(spatialInteractionSourceState, handPose, out HandMeshData data))
                {
                    handData.Mesh = data;
                }
                else
                {
                    // if hand mesh visualization is disabled make sure to destroy our hand mesh observer
                    // if it has already been created.
                    if (handMeshObservers.ContainsKey(spatialInteractionSourceState.Source.Handedness))
                    {
                        if (spatialInteractionSourceState.Source.Handedness == SpatialInteractionSourceHandedness.Left)
                        {
                            hasRequestedHandMeshObserverLeftHand = false;
                        }
                        else if (spatialInteractionSourceState.Source.Handedness == SpatialInteractionSourceHandedness.Right)
                        {
                            hasRequestedHandMeshObserverRightHand = false;
                        }

                        handMeshObservers.Remove(spatialInteractionSourceState.Source.Handedness);
                    }

                    handData.Mesh = HandMeshData.Empty;
                }
            }

            // Even if the hand is being tracked by the system but the confidence did not
            // meet our requirements, we return true. This allows the hand controller and visualizers
            // to react to tracking loss and keep the hand up for a given time before destroying the controller.
            return(true);
        }
Ejemplo n.º 2
0
        private void AssignHandJoint(RigidPose handPose, bool isLeft, JointEnumArray joints, HandJointName jointName, VRBoneTransform_t[] boneTransforms, int steamBoneIndex)
        {
            VRBoneTransform_t bone     = boneTransforms[steamBoneIndex];
            Vector3           position = new Vector3(-bone.position.v0, bone.position.v1, bone.position.v2);
            Quaternion        rotation = new Quaternion(bone.orientation.x, -bone.orientation.y, -bone.orientation.z, bone.orientation.w);

            if (steamBoneIndex == SteamVR_Skeleton_JointIndexes.wrist)
            {
                if (isLeft)
                {
                    rotation *= s_leftSkeletonWristFixRotation;
                }
                else
                {
                    rotation *= s_rightSkeletonWristFixRotation;
                }
            }
            else
            {
                if (isLeft)
                {
                    rotation *= s_leftSkeletonFixRotation;
                }
                else
                {
                    rotation *= s_rightSkeletonFixRotation;
                }
            }

            joints[jointName] = new JointPose(handPose * new RigidPose(position, rotation));
        }
            public bool TryGetHandJointPose(HandJointName jointName, out JointPose pose)
            {
                if (m_handJoints == null || !m_handJoints[jointName].isValid)
                {
                    pose = default(JointPose);
                    return(false);
                }

                pose = m_handJoints[jointName];
                return(true);
            }
Ejemplo n.º 4
0
    public void CopyFrom(JointPose pose)
    {
        Quaternion quaternion = pose.rotation;
        Vector3    vector     = pose.translation;

        this.rotation.x    = quaternion.x;
        this.rotation.y    = quaternion.y;
        this.rotation.z    = quaternion.z;
        this.rotation.w    = quaternion.w;
        this.translation.x = vector.x;
        this.translation.y = vector.y;
        this.translation.z = vector.z;
    }
 public void SetCurrentPose(string poseName)
 {
     if (Poses == null)
     {
         return;
     }
     foreach (var item in Poses)
     {
         if (item.name == poseName)
         {
             PoseTime01      = 0.0f;
             CurrentPoseName = poseName;
             currentPose     = item;
         }
     }
 }
Ejemplo n.º 6
0
            public bool parseAnimation(AnimationChunk a, LuaObject data)
            {
                parseChunkHeader(a, data);
                a.duration     = data.get <float>("duration");
                a.skeletonName = data.get <string>("skeleton");
                a.numBones     = data.get <int>("numBones");
                LuaObject events = data["events"];

                for (int i = 0; i < events.count(); i++)
                {
                    LuaObject      e        = events[i + 1];
                    AnimationEvent aniEvent = new AnimationEvent();
                    aniEvent.time = e.get <int>("time");
                    aniEvent.name = e.get <string>("name");
                    a.events.Add(aniEvent);
                }

                //create an animiation channel for each bone
                for (int i = 0; i < a.numBones; i++)
                {
                    a.channels.Add(new AnimationChannel());
                }

                LuaObject channels = data["channels"];

                for (int i = 0; i < a.numBones; i++)
                {
                    LuaObject channelData = channels[i + 1];
                    int       idx         = 1;
                    while (idx < channelData.count())
                    {
                        JointPose jp = new JointPose();
                        jp.time     = (float)channelData[idx++];
                        jp.position = new Vector3(channelData[idx++], channelData[idx++], channelData[idx++]);
                        jp.rotation = new Quaternion(channelData[idx++], channelData[idx++], channelData[idx++], channelData[idx++]);
                        a.channels[i].poses.Add(jp);
                    }
                }

                return(true);
            }
 public void RemovePose(string PoseName)
 {
     if (Poses == null)
     {
         return;
     }
     foreach (var item in Poses)
     {
         if (item.name == PoseName)
         {
             Poses.Remove(item);
             if (currentPose == item)
             {
                 currentPose = null;
             }
             if (newPose == item)
             {
                 newPose = null;
             }
             return;
         }
     }
 }
Ejemplo n.º 8
0
 public static bool TryGetHandJointPose(uint deviceIndex, HandJointName jointName, out JointPose pose)
 {
     return(VRModule.GetCurrentDeviceState(deviceIndex).TryGetHandJointPose(jointName, out pose));
 }
Ejemplo n.º 9
0
 public static bool TryGetHandJointPoseEx(Type roleType, int roleValue, HandJointName jointName, out JointPose pose)
 {
     return(TryGetHandJointPose(ViveRole.GetDeviceIndexEx(roleType, roleValue), jointName, out pose));
 }
Ejemplo n.º 10
0
 public static bool TryGetHandJointPoseEx <TRole>(TRole role, HandJointName jointName, out JointPose pose)
 {
     return(TryGetHandJointPose(ViveRole.GetDeviceIndexEx(role), jointName, out pose));
 }
Ejemplo n.º 11
0
 public static bool TryGetHandJointPose(ViveRoleProperty role, HandJointName jointName, out JointPose pose)
 {
     return(TryGetHandJointPose(role.GetDeviceIndex(), jointName, out pose));
 }
Ejemplo n.º 12
0
    private void UpdateGlobalProperties()
    {
        this._globalPropertiesDirty = false;
        int num = 0;
        List <JointPose>     jointPoses = this._globalPose.jointPoses;
        List <SkeletonJoint> joints     = this._skeleton.joints;

        for (int i = 0; i < this._numJoints; i++)
        {
            JointPose  jointPose   = jointPoses[i];
            Quaternion rotation    = jointPose.rotation;
            Vector3    translation = jointPose.translation;
            float      num2        = rotation.x;
            float      num3        = rotation.y;
            float      num4        = rotation.z;
            float      num5        = rotation.w;
            float      num7;
            float      num6  = (num7 = 2f * num2) * num3;
            float      num8  = num7 * num4;
            float      num9  = num7 * num5;
            float      num10 = (num7 = 2f * num3) * num4;
            float      num11 = num7 * num5;
            float      num12 = 2f * num4 * num5;
            num10 = 2f * num3 * num4;
            num11 = 2f * num3 * num5;
            num12 = 2f * num4 * num5;
            num2 *= num2;
            num3 *= num3;
            num4 *= num4;
            num5 *= num5;
            float   num13           = (num7 = num2 - num3) - num4 + num5;
            float   num14           = num6 - num12;
            float   num15           = num8 + num11;
            float   num16           = num6 + num12;
            float   num17           = -num7 - num4 + num5;
            float   num18           = num10 - num9;
            float   num19           = num8 - num11;
            float   num20           = num10 + num9;
            float   num21           = -num2 - num3 + num4 + num5;
            float[] inverseBindPose = joints[i].inverseBindPose;
            float   num22           = inverseBindPose[0];
            float   num23           = inverseBindPose[4];
            float   num24           = inverseBindPose[8];
            float   num25           = inverseBindPose[12];
            float   num26           = inverseBindPose[1];
            float   num27           = inverseBindPose[5];
            float   num28           = inverseBindPose[9];
            float   num29           = inverseBindPose[13];
            float   num30           = inverseBindPose[2];
            float   num31           = inverseBindPose[6];
            float   num32           = inverseBindPose[10];
            float   num33           = inverseBindPose[14];
            this._globalMatrices[num]      = num13 * num22 + num14 * num26 + num15 * num30;
            this._globalMatrices[num + 1]  = num13 * num23 + num14 * num27 + num15 * num31;
            this._globalMatrices[num + 2]  = num13 * num24 + num14 * num28 + num15 * num32;
            this._globalMatrices[num + 3]  = num13 * num25 + num14 * num29 + num15 * num33 + translation.x;
            this._globalMatrices[num + 4]  = num16 * num22 + num17 * num26 + num18 * num30;
            this._globalMatrices[num + 5]  = num16 * num23 + num17 * num27 + num18 * num31;
            this._globalMatrices[num + 6]  = num16 * num24 + num17 * num28 + num18 * num32;
            this._globalMatrices[num + 7]  = num16 * num25 + num17 * num29 + num18 * num33 + translation.y;
            this._globalMatrices[num + 8]  = num19 * num22 + num20 * num26 + num21 * num30;
            this._globalMatrices[num + 9]  = num19 * num23 + num20 * num27 + num21 * num31;
            this._globalMatrices[num + 10] = num19 * num24 + num20 * num28 + num21 * num32;
            this._globalMatrices[num + 11] = num19 * num25 + num20 * num29 + num21 * num33 + translation.z;
            num += 12;
        }
    }
Ejemplo n.º 13
0
    private void LocalToGlobalPose(SkeletonPose sourcePose, SkeletonPose targetPose, Skeleton skeleton)
    {
        List <JointPose>     jointPoses = targetPose.jointPoses;
        List <SkeletonJoint> joints     = skeleton.joints;
        int numJointPoses            = sourcePose.numJointPoses;
        List <JointPose> jointPoses2 = sourcePose.jointPoses;

        for (int i = 0; i < numJointPoses; i++)
        {
            JointPose jointPose = jointPoses[i];
            if (jointPose == null)
            {
                jointPose = new JointPose();
            }
            SkeletonJoint skeletonJoint = joints[i];
            int           parentIndex   = skeletonJoint.parentIndex;
            JointPose     jointPose2    = jointPoses2[i];
            Quaternion    rotation      = jointPose.rotation;
            Vector3       translation   = jointPose.translation;
            if (parentIndex < 0)
            {
                Vector3    translation2 = jointPose2.translation;
                Quaternion rotation2    = jointPose2.rotation;
                rotation.x    = rotation2.x;
                rotation.y    = rotation2.y;
                rotation.z    = rotation2.z;
                rotation.w    = rotation2.w;
                translation.x = translation2.x;
                translation.y = translation2.y;
                translation.z = translation2.z;
            }
            else
            {
                JointPose  jointPose3   = jointPoses[parentIndex];
                Quaternion rotation2    = jointPose3.rotation;
                Vector3    translation2 = jointPose2.translation;
                float      x            = rotation2.x;
                float      y            = rotation2.y;
                float      z            = rotation2.z;
                float      w            = rotation2.w;
                float      x2           = translation2.x;
                float      y2           = translation2.y;
                float      z2           = translation2.z;
                float      num          = -x * x2 - y * y2 - z * z2;
                float      num2         = w * x2 + y * z2 - z * y2;
                float      num3         = w * y2 - x * z2 + z * x2;
                float      num4         = w * z2 + x * y2 - y * x2;
                translation2  = jointPose3.translation;
                translation.x = -num * x + num2 * w - num3 * z + num4 * y + translation2.x;
                translation.y = -num * y + num2 * z + num3 * w - num4 * x + translation2.y;
                translation.z = -num * z - num2 * y + num3 * x + num4 * w + translation2.z;
                num2          = rotation2.x;
                num3          = rotation2.y;
                num4          = rotation2.z;
                num           = rotation2.w;
                rotation2     = jointPose2.rotation;
                x             = rotation2.x;
                y             = rotation2.y;
                z             = rotation2.z;
                w             = rotation2.w;
                rotation.w    = num * w - num2 * x - num3 * y - num4 * z;
                rotation.x    = num * x + num2 * w + num3 * z - num4 * y;
                rotation.y    = num * y - num2 * z + num3 * w + num4 * x;
                rotation.z    = num * z + num2 * y - num3 * x + num4 * w;
            }
        }
    }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets a single joint's <see cref="MixedRealityPose"/> relative to the hand root pose.
        /// </summary>
        /// <param name="trackedHandJoint">The <see cref="TrackedHandJoint"/> Id for the joint to get a <see cref="MixedRealityPose"/> for.</param>
        /// <param name="handRootPose">The hand's root <see cref="MixedRealityPose"/>. Joint poses are always relative to the root pose.</param>
        /// <param name="jointPose"><see cref="JointPose"/> retrieved from the platform.</param>
        /// <returns>Joint <see cref="MixedRealityPose"/> relative to the hand's root pose.</returns>
        private MixedRealityPose GetJointPose(TrackedHandJoint trackedHandJoint, MixedRealityPose handRootPose, JointPose jointPose)
        {
            var jointTransform = GetProxyTransform(trackedHandJoint);

            if (trackedHandJoint == TrackedHandJoint.Wrist)
            {
                jointTransform.localPosition = handRootPose.Position;
                jointTransform.localRotation = handRootPose.Rotation;
            }
            else
            {
                jointTransform.parent        = RigTransform;
                jointTransform.localPosition = RigTransform.InverseTransformPoint(RigTransform.position + RigTransform.rotation * jointPose.Position.ToUnity());
                jointTransform.localRotation = Quaternion.Inverse(RigTransform.rotation) * RigTransform.rotation * jointPose.Orientation.ToUnity();
                jointTransform.parent        = conversionProxyRootTransform;
            }

            return(new MixedRealityPose(
                       conversionProxyRootTransform.InverseTransformPoint(jointTransform.position),
                       Quaternion.Inverse(conversionProxyRootTransform.rotation) * jointTransform.rotation));
        }
 public void RemoveAllPoses()
 {
     Poses       = null;
     currentPose = null;
     newPose     = null;
 }
 public void FixCurrentPose(string poseName, Transform[] joints)
 {
     currentPose = null;
     currentPose = new JointPose("Some in " + poseName, joints);
     PoseTime01  = 0.0f;
 }
Ejemplo n.º 17
0
 private void ApplyPose(Transform transform, JointPose jointPose)
 {
     transform.position = SystemVector3ToUnity(jointPose.Position);
     transform.rotation = SystemQuaternionToUnity(jointPose.Orientation);
 }