예제 #1
0
        private void ApplyBlend(HVRHandPoseData targetHand, HVRHandPoseBlend targetBlend, HVRHandPoseData sourceHand)
        {
            //var target = targetBlend.Pose.GetPose(Hand.IsLeft);
            var lerp = targetBlend.Value * targetBlend.Weight;

            if (targetBlend.Mask == HVRHandPoseMask.None || targetBlend.Mask.HasFlag(HVRHandPoseMask.Hand))
            {
                targetHand.Position = Vector3.Lerp(targetHand.Position, sourceHand.Position, lerp);
                targetHand.Rotation = Quaternion.Lerp(targetHand.Rotation, sourceHand.Rotation, lerp);
            }

            for (var i = 0; i < targetHand.Fingers.Length; i++)
            {
                var targetFinger = targetHand.Fingers[i];
                var sourceFinger = sourceHand.Fingers[i];

                HVRHandPoseMask mask;
                if (i == 0)
                {
                    mask = HVRHandPoseMask.Thumb;
                }
                else if (i == 1)
                {
                    mask = HVRHandPoseMask.Index;
                }
                else if (i == 2)
                {
                    mask = HVRHandPoseMask.Middle;
                }
                else if (i == 3)
                {
                    mask = HVRHandPoseMask.Ring;
                }
                else if (i == 4)
                {
                    mask = HVRHandPoseMask.Pinky;
                }
                else
                {
                    continue;
                }

                if (targetBlend.Mask == HVRHandPoseMask.None || targetBlend.Mask.HasFlag(mask))
                {
                    for (var j = 0; j < targetFinger.Bones.Count; j++)
                    {
                        var targetBone = targetFinger.Bones[j];
                        var sourceBone = sourceFinger.Bones[j];
                        targetBone.Position = Vector3.Lerp(targetBone.Position, sourceBone.Position, lerp);
                        targetBone.Rotation = Quaternion.Lerp(targetBone.Rotation, sourceBone.Rotation, lerp);
                    }
                }
            }
        }
예제 #2
0
        private void UpdateBlend(HVRHandPoseBlend blend)
        {
            var blendTarget = 0f;

            if (blend.Type == BlendType.Immediate)
            {
                blendTarget = 1f;
            }
            else if (blend.ButtonParameter)
            {
                var button = HVRController.GetButtonState(Hand.Side, blend.Button);
                if (blend.Type == BlendType.BooleanParameter)
                {
                    blendTarget = button.Active ? 1f : 0f;
                }
                else if (blend.Type == BlendType.FloatParameter)
                {
                    blendTarget = button.Value;
                }
            }
            else if (!string.IsNullOrWhiteSpace(blend.AnimationParameter) && blend.AnimationParameter != "None")
            {
                if (blend.Type == BlendType.BooleanParameter)
                {
                    blendTarget = HVRAnimationParameters.GetBoolParameter(Hand.Side, blend.AnimationParameter) ? 1f : 0f;
                }
                else if (blend.Type == BlendType.FloatParameter)
                {
                    blendTarget = HVRAnimationParameters.GetFloatParameter(Hand.Side, blend.AnimationParameter);
                }
            }

            if (blend.Speed > .1f)
            {
                blend.Value = Mathf.Lerp(blend.Value, blendTarget, Time.deltaTime * blend.Speed);
            }
            else
            {
                blend.Value = blendTarget;
            }
        }
예제 #3
0
        private void ApplyFingerCurls(HVRHandPoseData targetHand, HVRHandPoseData defaultHand, HVRHandPoseData sourceHand, HVRHandPoseBlend blend)
        {
            for (int i = 0; i < targetHand.Fingers.Length; i++)
            {
                var targetFinger  = targetHand.Fingers[i];
                var defaultFinger = defaultHand.Fingers[i];
                var sourceFinger  = sourceHand.Fingers[i];

                var fingerType  = blend.GetFingerType(i);
                var fingerStart = blend.GetFingerStart(i);
                var curl        = _fingerCurls[i];
                var remainder   = 1 - fingerStart;
                curl = fingerStart + curl * remainder;
                curl = Mathf.Clamp(curl, 0f, 1f);


                for (int j = 0; j < targetFinger.Bones.Count; j++)
                {
                    if (fingerType == HVRFingerType.Close)
                    {
                        targetFinger.Bones[j].Position = Vector3.Lerp(sourceFinger.Bones[j].Position, defaultFinger.Bones[j].Position, 1 - curl);
                        targetFinger.Bones[j].Rotation = Quaternion.Lerp(sourceFinger.Bones[j].Rotation, defaultFinger.Bones[j].Rotation, 1 - curl);
                    }
                }
            }
        }