Example #1
0
        // Update is called once per frame
        void Update()
        {
            switch (Controller.Mode)
            {
            case PlayMode.Stream:
            {
                // Update data
                if (StreamFrameController.DataNew)
                {
                    frameData = StreamFrameController.GetCurrentFrame();
                    //interpolateFrameRest = UDPReceiver.EstimatedRestFrameTime;
                    if (frameData.isValid)
                    {
                        // Calculate vertical stablization
                        if (AllowVerticalStablization)
                        {
                            UpdateModel(1f);         // set to next state
                            PushNewFeetHeights();    // calculate feet heights
                            if (IsVerticalStable() || GetLowestFeetHeight() < 0f)
                            {
                                HeightDiff -= GetLowestFeetHeight();
                            }
                            ChangeModelToLastSavedState();         // change the model state back
                        }
                        // New insert coroutine for new data
                        //if (AllowInterpolation)
                        {
                            StopCoroutine(InsertStepsCoroutine());
                            StartCoroutine(InsertStepsCoroutine());
                        }
                    }
                }
                // Update model every frame for interpolation

                /*if (AllowInterpolation)
                 * {
                 *  if (frameData.isValid)
                 *  {
                 *      UpdateModelAndFace(Time.deltaTime / interpolateFrameRest);
                 *  }
                 * }*/
            }
            break;

            case PlayMode.FileJson:
            {
                frameData = DataFrameController.GetCurrentFrame();
                bool newData = DataFrameController.RestFrameTime > interpolateFrameRest;
                interpolateFrameRest = DataFrameController.RestFrameTime;
                if (frameData.isValid)
                {
                    if (AllowVerticalStablization)
                    {
                        if (newData)                       // push new feet data
                        {
                            UpdateModel(1f);               // set to next state
                            PushNewFeetHeights();          // calculate feet heights
                            ChangeModelToLastSavedState(); // change the model state back
                        }

                        if (IsVerticalStable() || GetLowestFeetHeight() < 0f)
                        {
                            HeightDiff -= GetLowestFeetHeight();
                        }
                    }
                    if (AllowInterpolation)
                    {
                        UpdateModelAndFace(Time.deltaTime / interpolateFrameRest);
                    }
                    else
                    {
                        UpdateModelAndFace();
                    }
                }
            }
            break;

            case PlayMode.FileBvh:
            {
                frameData = DataFrameController.GetCurrentFrame();
                bool newData = DataFrameController.RestFrameTime > interpolateFrameRest;
                interpolateFrameRest = DataFrameController.RestFrameTime;
                if (frameData.isValid)
                {
                    if (AllowVerticalStablization)
                    {
                        if (newData)                       // push new feet data
                        {
                            UpdateModel(1f);               // set to next state
                            PushNewFeetHeights();          // calculate feet heights
                            ChangeModelToLastSavedState(); // change the model state back
                        }

                        if (IsVerticalStable() || GetLowestFeetHeight() < 0f)
                        {
                            HeightDiff -= GetLowestFeetHeight();
                        }
                    }
                    if (AllowInterpolation)
                    {
                        UpdateModel(Time.deltaTime / interpolateFrameRest);
                    }
                    else
                    {
                        UpdateModel();
                    }
                }
            }
            break;
            }
        }
 private void Awake()
 {
     instance = this;
 }