コード例 #1
0
        public void Queue(ArmModel newArmModel)
        {
            if (newArmModel == null)
            {
                return;
            }
            if (m_CurrentArmModelComponent == null)
            {
                m_CurrentArmModelComponent = newArmModel;
            }

            RemoveJustStartingTransitions();
            if (armModelBlendData.Count == MAX_ACTIVE_TRANSITIONS)
            {
                RemoveOldestTransition();
            }

            var ambd = new ArmModelBlendData();

            ambd.armModel           = newArmModel;
            ambd.currentBlendAmount = 0.0f;

            armModelBlendData.Add(ambd);
        }
コード例 #2
0
        bool UpdateBlends()
        {
            if (currentArmModelComponent == null)
            {
                return(false);
            }

            if (m_CurrentArmModelComponent.OnControllerInputUpdated())
            {
                m_NeckPosition       = m_CurrentArmModelComponent.neckPosition;
                m_ElbowPosition      = m_CurrentArmModelComponent.elbowPosition;
                m_WristPosition      = m_CurrentArmModelComponent.wristPosition;
                m_ControllerPosition = m_CurrentArmModelComponent.controllerPosition;

                m_ElbowRotation      = m_CurrentArmModelComponent.elbowRotation;
                m_WristRotation      = m_CurrentArmModelComponent.wristRotation;
                m_ControllerRotation = m_CurrentArmModelComponent.controllerRotation;

#if UNITY_EDITOR
                m_TorsoDirection = m_CurrentArmModelComponent.torsoDirection;
                m_TorsoRotation  = m_CurrentArmModelComponent.torsoRotation;
#endif


                Vector3 angVel;
                if (TryGetAngularVelocity(poseSource, out angVel) && armModelBlendData.Count > 0)
                {
                    float angularVelocity = angVel.magnitude;
                    float lerpValue       = Mathf.Clamp(((angularVelocity) - MIN_ANGULAR_VELOCITY) / ANGULAR_VELOCITY_DIVISOR, 0.0f, 0.1f);

                    for (int i = 0; i < armModelBlendData.Count; ++i)
                    {
                        ArmModelBlendData ambd = armModelBlendData[i];
                        ambd.currentBlendAmount = Mathf.Lerp(ambd.currentBlendAmount, 1.0f, lerpValue);
                        if (ambd.currentBlendAmount > LERP_CLAMP_THRESHOLD)
                        {
                            ambd.currentBlendAmount = 1.0f;
                        }
                        else
                        {
                            ambd.armModel.OnControllerInputUpdated();

                            m_NeckPosition       = Vector3.Slerp(neckPosition, ambd.armModel.neckPosition, ambd.currentBlendAmount);
                            m_ElbowPosition      = Vector3.Slerp(elbowPosition, ambd.armModel.elbowPosition, ambd.currentBlendAmount);
                            m_WristPosition      = Vector3.Slerp(wristPosition, ambd.armModel.wristPosition, ambd.currentBlendAmount);
                            m_ControllerPosition = Vector3.Slerp(controllerPosition, ambd.armModel.controllerPosition, ambd.currentBlendAmount);

                            m_ElbowRotation      = Quaternion.Slerp(elbowRotation, ambd.armModel.elbowRotation, ambd.currentBlendAmount);
                            m_WristRotation      = Quaternion.Slerp(wristRotation, ambd.armModel.wristRotation, ambd.currentBlendAmount);
                            m_ControllerRotation = Quaternion.Slerp(controllerRotation, ambd.armModel.controllerRotation, ambd.currentBlendAmount);
                        }
                        // write back.
                        armModelBlendData[i] = ambd;

                        if (ambd.currentBlendAmount >= 1.0f)
                        {
                            m_CurrentArmModelComponent = ambd.armModel;
                            armModelBlendData.RemoveRange(0, i + 1);
                        }
                    }
                }
                else if (armModelBlendData.Count > 0)
                {
                    Debug.LogErrorFormat(this.gameObject, "Unable to get angular acceleration for node");
                    return(false);
                }

                finalPose = new Pose(controllerPosition, controllerRotation);
                return(true);
            }
            else
            {
                return(false);
            }
        }