Example #1
0
    private IEnumerator Record()
    {
        Data           = ScriptableObject.CreateInstance <BVHAnimation>();
        Data.Character = Animation.Character;
        Data.FrameTime = FrameTime;

        Data.Trajectory            = new Trajectory(0, Animation.Controller.Styles.Length);
        Data.PhaseFunction         = new BVHAnimation.BVHPhaseFunction(Data);
        Data.MirroredPhaseFunction = new BVHAnimation.BVHPhaseFunction(Data);
        Data.StyleFunction         = new BVHAnimation.BVHStyleFunction(Data);
        for (int i = 0; i < Animation.Controller.Styles.Length; i++)
        {
            Data.StyleFunction.AddStyle(Animation.Controller.Styles[i].Name);
        }
        //Data.StyleFunction.SetStyle(BVHAnimation.BVHStyleFunction.STYLE.Quadruped);

        int index = 0;

        while (Recording && Application.isPlaying)
        {
            yield return(new WaitForEndOfFrame());

            //Frames
            BVHAnimation.BVHFrame frame = new BVHAnimation.BVHFrame(Data, Data.GetTotalFrames() + 1, Data.GetTotalFrames() * FrameTime);
            frame.Local = Data.Character.GetLocalTransformations();
            frame.World = Data.Character.GetWorldTransformations();
            Utility.Add(ref Data.Frames, frame);

            //Trajectory
            Trajectory.Point point = new Trajectory.Point(Data.Trajectory.Points.Length, Animation.Controller.Styles.Length);
            point.SetTransformation(Animation.GetTrajectory().Points[60].GetTransformation());
            point.SetLeftsample(Animation.GetTrajectory().Points[60].GetLeftSample());
            point.SetRightSample(Animation.GetTrajectory().Points[60].GetRightSample());
            point.SetSlope(Animation.GetTrajectory().Points[60].GetSlope());
            for (int i = 0; i < Animation.Controller.Styles.Length; i++)
            {
                point.Styles[i] = Animation.GetTrajectory().Points[60].Styles[i];
            }
            Utility.Add(ref Data.Trajectory.Points, point);

            //Phase Function

            /*
             * Utility.Add(ref Data.PhaseFunction.Phase, Mathf.Repeat(Animation.GetPhase() / (2f*Mathf.PI), 1f));
             * Utility.Add(ref Data.PhaseFunction.Keys, index == 0 ? true : Data.PhaseFunction.Phase[index-1] > Data.PhaseFunction.Phase[index]);
             * Utility.Add(ref Data.PhaseFunction.Cycle, 0f);
             * Utility.Add(ref Data.PhaseFunction.NormalisedCycle, 0f);
             * Utility.Add(ref Data.PhaseFunction.Velocities, 0f);
             * Utility.Add(ref Data.PhaseFunction.NormalisedVelocities, 0f);
             * Utility.Add(ref Data.PhaseFunction.Heights, 0f);
             */
            Utility.Add(ref Data.PhaseFunction.Phase, 0f);
            Utility.Add(ref Data.PhaseFunction.Keys, false);
            Utility.Add(ref Data.PhaseFunction.Cycle, 0f);
            Utility.Add(ref Data.PhaseFunction.NormalisedCycle, 0f);
            Utility.Add(ref Data.PhaseFunction.Velocities, 0f);
            Utility.Add(ref Data.PhaseFunction.NormalisedVelocities, 0f);
            Utility.Add(ref Data.PhaseFunction.Heights, 0f);
            Utility.Add(ref Data.PhaseFunction.RootVelocities, 0f);
            Utility.Add(ref Data.PhaseFunction.NormalisedRootVelocities, 0f);

            //Mirrored Phase Function
            Utility.Add(ref Data.MirroredPhaseFunction.Phase, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.Keys, false);
            Utility.Add(ref Data.MirroredPhaseFunction.Cycle, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.NormalisedCycle, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.Velocities, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.NormalisedVelocities, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.Heights, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.RootVelocities, 0f);
            Utility.Add(ref Data.MirroredPhaseFunction.NormalisedRootVelocities, 0f);

            //Style Function
            bool styleUpdate = false;
            for (int i = 0; i < Animation.Controller.Styles.Length; i++)
            {
                Utility.Add(ref Data.StyleFunction.Styles[i].Flags, Animation.Controller.Styles[i].Query());
                Utility.Add(ref Data.StyleFunction.Styles[i].Values, Animation.GetTrajectory().Points[60].Styles[i]);
                if (index == 0)
                {
                    styleUpdate = true;
                }
                else
                {
                    if (Data.StyleFunction.Styles[i].Flags[index - 1] != Data.StyleFunction.Styles[i].Flags[index])
                    {
                        styleUpdate = true;
                    }
                }
            }
            Utility.Add(ref Data.StyleFunction.Keys, styleUpdate);

            index += 1;
        }

        //Setup
        Data.TimeWindow  = Data.GetTotalTime();
        Data.Corrections = new Vector3[Animation.Character.Hierarchy.Length];
        Data.DetectSymmetry();

        //Postprocess
        Data.PhaseFunction.Keys[index - 1] = true;
        Data.StyleFunction.Keys[index - 1] = true;
        Data.PhaseFunction.Recompute();
        Data.StyleFunction.Recompute();

        //Finish
        Recording = false;
    }