Esempio n. 1
0
    public Trajectory GetTrajectory(Frame frame, bool mirrored)
    {
        StyleModule styleModule = Data.GetModule(Module.TYPE.Style) == null ? null : (StyleModule)Data.GetModule(Module.TYPE.Style);
        PhaseModule phaseModule = Data.GetModule(Module.TYPE.Phase) == null ? null : (PhaseModule)Data.GetModule(Module.TYPE.Phase);

        Trajectory trajectory = new Trajectory(12, styleModule == null ? new string[0] : styleModule.GetNames());

        //Current
        trajectory.Points[6].SetTransformation(frame.GetRootTransformation(mirrored));
        trajectory.Points[6].SetVelocity(frame.GetRootVelocity(mirrored));
        trajectory.Points[6].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(frame);
        trajectory.Points[6].Phase  = phaseModule == null ? 0f : phaseModule.GetPhase(frame, mirrored);

        //Past
        for (int i = 0; i < 6; i++)
        {
            float delta = -1f + (float)i / 6f;
            if (frame.Timestamp + delta < 0f)
            {
                float pivot     = -frame.Timestamp - delta;
                float clamped   = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
                float ratio     = pivot == clamped ? 1f : Mathf.Abs(pivot / clamped);
                Frame reference = Data.GetFrame(clamped);
                trajectory.Points[i].SetPosition(Data.GetFirstFrame().GetRootPosition(mirrored) - ratio * (reference.GetRootPosition(mirrored) - Data.GetFirstFrame().GetRootPosition(mirrored)));
                trajectory.Points[i].SetRotation(reference.GetRootRotation(mirrored));
                trajectory.Points[i].SetVelocity(reference.GetRootVelocity(mirrored));
                trajectory.Points[i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(reference);
                trajectory.Points[i].Phase  = phaseModule == null ? 0f : Mathf.Repeat(phaseModule.GetPhase(Data.GetFirstFrame(), mirrored) - Utility.PhaseUpdate(phaseModule.GetPhase(Data.GetFirstFrame(), mirrored), phaseModule.GetPhase(reference, mirrored)), 1f);
            }
            else
            {
                Frame previous = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
                trajectory.Points[i].SetTransformation(previous.GetRootTransformation(mirrored));
                trajectory.Points[i].SetVelocity(previous.GetRootVelocity(mirrored));
                trajectory.Points[i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(previous);
                trajectory.Points[i].Phase  = phaseModule == null ? 0f : phaseModule.GetPhase(previous, mirrored);
            }
        }

        //Future
        for (int i = 1; i <= 5; i++)
        {
            float delta = (float)i / 5f;
            if (frame.Timestamp + delta > Data.GetTotalTime())
            {
                float pivot     = 2f * Data.GetTotalTime() - frame.Timestamp - delta;
                float clamped   = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
                float ratio     = pivot == clamped ?1f : Mathf.Abs((Data.GetTotalTime() - pivot) / (Data.GetTotalTime() - clamped));
                Frame reference = Data.GetFrame(clamped);
                trajectory.Points[6 + i].SetPosition(Data.GetLastFrame().GetRootPosition(mirrored) - ratio * (reference.GetRootPosition(mirrored) - Data.GetLastFrame().GetRootPosition(mirrored)));
                trajectory.Points[6 + i].SetRotation(reference.GetRootRotation(mirrored));
                trajectory.Points[6 + i].SetVelocity(reference.GetRootVelocity(mirrored));
                trajectory.Points[6 + i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(reference);
                trajectory.Points[6 + i].Phase  = phaseModule == null ? 0f : Mathf.Repeat(phaseModule.GetPhase(Data.GetLastFrame(), mirrored) + Utility.PhaseUpdate(phaseModule.GetPhase(reference, mirrored), phaseModule.GetPhase(Data.GetLastFrame(), mirrored)), 1f);
            }
            else
            {
                Frame future = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
                trajectory.Points[6 + i].SetTransformation(future.GetRootTransformation(mirrored));
                trajectory.Points[6 + i].SetVelocity(future.GetRootVelocity(mirrored));
                trajectory.Points[6 + i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(future);
                trajectory.Points[6 + i].Phase  = phaseModule == null ? 0f : phaseModule.GetPhase(future, mirrored);
            }
        }

        /*
         * //Signals
         * for(int i=0; i<7; i++) {
         *      float delta = -2f + (float)i/6f;
         *      if(frame.Timestamp + delta < 0f) {
         *              float pivot = - frame.Timestamp - delta;
         *              float clamped = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
         *              Frame reference = Data.GetFrame(clamped);
         *              trajectory.Points[i].Signals = ArrayExtensions.Sub(styleModule.GetInverseSignal(reference, window), styleModule.GetStyle(reference, window));
         *      } else {
         *              Frame pivot = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
         *              trajectory.Points[i].Signals = ArrayExtensions.Sub(styleModule.GetSignal(pivot, window), styleModule.GetStyle(pivot, window));
         *      }
         * }
         * for(int i=1; i<=5; i++) {
         *      float delta = -1f + (float)i/5f;
         *      if(frame.Timestamp + delta < 0f) {
         *              float pivot = - frame.Timestamp - delta;
         *              float clamped = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
         *              Frame reference = Data.GetFrame(clamped);
         *              trajectory.Points[6+i].Signals = ArrayExtensions.Sub(styleModule.GetInverseSignal(reference, window), styleModule.GetStyle(reference, window));
         *      } else {
         *              Frame pivot = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
         *              trajectory.Points[6+i].Signals = ArrayExtensions.Sub(styleModule.GetSignal(pivot, window), styleModule.GetStyle(pivot, window));
         *      }
         * }
         *
         * //Finish
         * for(int i=0; i<trajectory.GetLast().Signals.Length; i++) {
         *      for(int j=7; j<12; j++) {
         *              if(trajectory.GetLast().Signals[i] > 0f && trajectory.GetLast().Signals[i] < 1f) {
         *                      int pivot = j-1;
         *                      trajectory.Points[j].Styles[i] = Mathf.Max(trajectory.Points[pivot].Styles[i], trajectory.Points[j].Styles[i]);
         *              }
         *              if(trajectory.GetLast().Signals[i] < 0f && trajectory.GetLast().Signals[i] > -1f) {
         *                      int pivot = j-1;
         *                      trajectory.Points[j].Styles[i] = Mathf.Min(trajectory.Points[pivot].Styles[i], trajectory.Points[j].Styles[i]);
         *              }
         *              if(trajectory.GetLast().Signals[i] == 0f) {
         *                      trajectory.Points[j].Styles[i] = 0f;
         *              }
         *              if(trajectory.GetLast().Signals[i] == 1f || trajectory.GetLast().Signals[i] == -1f) {
         *                      trajectory.Points[j].Styles[i] = trajectory.Points[6].Styles[i];
         *              }
         *      }
         * }
         * if(trajectory.GetLast().Signals.AbsSum() == 0f) {
         *      for(int j=7; j<12; j++) {
         *              trajectory.Points[j].Styles = trajectory.Points[6].Styles;
         *      }
         * }
         */

        //Signals
        for (int i = 0; i < 7; i++)
        {
            float delta = -1f + (float)i / 6f;
            if (frame.Timestamp + delta < 0f)
            {
                float pivot     = -frame.Timestamp - delta;
                float clamped   = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
                Frame reference = Data.GetFrame(clamped);
                trajectory.Points[i].Signals = styleModule.GetInverseSignal(reference);
            }
            else
            {
                Frame pivot = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
                trajectory.Points[i].Signals = styleModule.GetSignal(pivot);
            }
        }
        for (int i = 7; i < 12; i++)
        {
            trajectory.Points[i].Signals = (float[])trajectory.Points[6].Signals.Clone();
        }

        //Finish
        for (int i = 0; i < trajectory.GetLast().Signals.Length; i++)
        {
            for (int j = 7; j < 12; j++)
            {
                if (trajectory.GetLast().Signals[i] > 0f && trajectory.GetLast().Signals[i] < 1f)
                {
                    int pivot = j - 1;
                    trajectory.Points[j].Styles[i] = Mathf.Max(trajectory.Points[pivot].Styles[i], trajectory.Points[j].Styles[i]);
                }
                if (trajectory.GetLast().Signals[i] < 0f && trajectory.GetLast().Signals[i] > -1f)
                {
                    int pivot = j - 1;
                    trajectory.Points[j].Styles[i] = Mathf.Min(trajectory.Points[pivot].Styles[i], trajectory.Points[j].Styles[i]);
                }
                if (trajectory.GetLast().Signals[i] == 0f)
                {
                    trajectory.Points[j].Styles[i] = trajectory.Points[6].Styles[i];
                }
                if (trajectory.GetLast().Signals[i] == 1f || trajectory.GetLast().Signals[i] == -1f)
                {
                    trajectory.Points[j].Styles[i] = trajectory.Points[6].Styles[i];
                }
            }
        }
        if (trajectory.GetLast().Signals.AbsSum() == 0f)
        {
            for (int j = 7; j < 12; j++)
            {
                trajectory.Points[j].Styles = (float[])trajectory.Points[6].Styles.Clone();
            }
        }

        //for(int i=0; i<trajectory.Points.Length; i++) {
        //	for(int j=0; j<trajectory.Points[i].Signals.Length; j++) {
        //		trajectory.Points[i].Signals[j] = Mathf.Sign(trajectory.Points[i].Signals[j]) * Mathf.Pow(Mathf.Abs(trajectory.Points[i].Signals[j]), 0.5f);
        //	}
        //}

        return(trajectory);
    }
Esempio n. 2
0
    public Trajectory GetTrajectory(Frame frame, bool mirrored)
    {
        StyleModule styleModule = Data.GetModule(Module.TYPE.Style) == null ? null : (StyleModule)Data.GetModule(Module.TYPE.Style);
        PhaseModule phaseModule = Data.GetModule(Module.TYPE.Phase) == null ? null : (PhaseModule)Data.GetModule(Module.TYPE.Phase);

        Trajectory trajectory = new Trajectory(12, styleModule == null ? new string[0] : styleModule.GetNames());

        //Current
        trajectory.Points[6].SetTransformation(frame.GetRootTransformation(mirrored));
        trajectory.Points[6].SetVelocity(frame.GetRootVelocity(mirrored));
        trajectory.Points[6].SetSpeed(frame.GetSpeed(mirrored));
        trajectory.Points[6].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(frame);
        trajectory.Points[6].Phase  = phaseModule == null ? 0f : phaseModule.GetPhase(frame, mirrored);

        //Past
        for (int i = 0; i < 6; i++)
        {
            float delta = -1f + (float)i / 6f;
            if (frame.Timestamp + delta < 0f)
            {
                float pivot     = -frame.Timestamp - delta;
                float clamped   = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
                float ratio     = pivot == clamped ? 1f : Mathf.Abs(pivot / clamped);
                Frame reference = Data.GetFrame(clamped);
                trajectory.Points[i].SetPosition(Data.GetFirstFrame().GetRootPosition(mirrored) - ratio * (reference.GetRootPosition(mirrored) - Data.GetFirstFrame().GetRootPosition(mirrored)));
                trajectory.Points[i].SetRotation(reference.GetRootRotation(mirrored));
                trajectory.Points[i].SetVelocity(reference.GetRootVelocity(mirrored));
                trajectory.Points[i].SetSpeed(reference.GetSpeed(mirrored));
                trajectory.Points[i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(reference);
                trajectory.Points[i].Phase  = phaseModule == null ? 0f : 1f - phaseModule.GetPhase(reference, mirrored);
            }
            else
            {
                Frame previous = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
                trajectory.Points[i].SetTransformation(previous.GetRootTransformation(mirrored));
                trajectory.Points[i].SetVelocity(previous.GetRootVelocity(mirrored));
                trajectory.Points[i].SetSpeed(previous.GetSpeed(mirrored));
                trajectory.Points[i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(previous);
                trajectory.Points[i].Phase  = phaseModule == null ? 0f : phaseModule.GetPhase(previous, mirrored);
            }
        }

        //Future
        for (int i = 1; i <= 5; i++)
        {
            float delta = (float)i / 5f;
            if (frame.Timestamp + delta > Data.GetTotalTime())
            {
                float pivot     = 2f * Data.GetTotalTime() - frame.Timestamp - delta;
                float clamped   = Mathf.Clamp(pivot, 0f, Data.GetTotalTime());
                float ratio     = pivot == clamped ?1f : Mathf.Abs((Data.GetTotalTime() - pivot) / (Data.GetTotalTime() - clamped));
                Frame reference = Data.GetFrame(clamped);
                trajectory.Points[6 + i].SetPosition(Data.GetLastFrame().GetRootPosition(mirrored) - ratio * (reference.GetRootPosition(mirrored) - Data.GetLastFrame().GetRootPosition(mirrored)));
                trajectory.Points[6 + i].SetRotation(reference.GetRootRotation(mirrored));
                trajectory.Points[6 + i].SetVelocity(reference.GetRootVelocity(mirrored));
                trajectory.Points[6 + i].SetSpeed(reference.GetSpeed(mirrored));
                trajectory.Points[6 + i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(reference);
                trajectory.Points[6 + i].Phase  = phaseModule == null ? 0f : 1f - phaseModule.GetPhase(reference, mirrored);
            }
            else
            {
                Frame future = Data.GetFrame(Mathf.Clamp(frame.Timestamp + delta, 0f, Data.GetTotalTime()));
                trajectory.Points[6 + i].SetTransformation(future.GetRootTransformation(mirrored));
                trajectory.Points[6 + i].SetVelocity(future.GetRootVelocity(mirrored));
                trajectory.Points[6 + i].SetSpeed(future.GetSpeed(mirrored));
                trajectory.Points[6 + i].Styles = styleModule == null ? new float[0] : styleModule.GetStyle(future);
                trajectory.Points[6 + i].Phase  = phaseModule == null ? 0f : phaseModule.GetPhase(future, mirrored);
            }
        }
        return(trajectory);
    }
Esempio n. 3
0
    public TimeSeries GetTimeSeries(Frame frame, bool mirrored, int pastKeys, int futureKeys, float pastWindow, float futureWindow, int resolution, float delta)
    {
        TimeSeries timeSeries = new TimeSeries(pastKeys, futureKeys, pastWindow, futureWindow, resolution);

        foreach (Module module in Data.Modules)
        {
            if (module is RootModule)
            {
                RootModule      m      = (RootModule)module;
                TimeSeries.Root series = new TimeSeries.Root(timeSeries);
                for (int i = 0; i < timeSeries.Samples.Length; i++)
                {
                    float t = frame.Timestamp + timeSeries.Samples[i].Timestamp;
                    if (t < 0f || t > Data.GetTotalTime())
                    {
                        series.Transformations[i] = m.GetEstimatedRootTransformation(frame, timeSeries.Samples[i].Timestamp, mirrored);
                        series.Velocities[i]      = m.GetEstimatedRootVelocity(frame, timeSeries.Samples[i].Timestamp, mirrored, delta);
                    }
                    else
                    {
                        series.Transformations[i] = m.GetRootTransformation(Data.GetFrame(t), mirrored);
                        series.Velocities[i]      = m.GetRootVelocity(Data.GetFrame(t), mirrored, delta);
                    }
                }
            }
            if (module is StyleModule)
            {
                StyleModule      m      = (StyleModule)module;
                TimeSeries.Style series = new TimeSeries.Style(timeSeries, m.GetNames());
                for (int i = 0; i < timeSeries.Samples.Length; i++)
                {
                    float t = frame.Timestamp + timeSeries.Samples[i].Timestamp;
                    series.Values[i] = m.GetStyles(Data.GetFrame(t));
                }
            }
            if (module is GoalModule)
            {
                GoalModule      m      = (GoalModule)module;
                TimeSeries.Goal series = new TimeSeries.Goal(timeSeries, m.GetNames());
                for (int i = 0; i < timeSeries.Samples.Length; i++)
                {
                    float t = frame.Timestamp + timeSeries.Samples[i].Timestamp;
                    series.Transformations[i] = m.Target.GetGoalTransformation(frame, timeSeries.Samples[i].Timestamp, mirrored, delta);
                    series.Values[i]          = m.GetActions(Data.GetFrame(t), delta);
                }
            }
            if (module is ContactModule)
            {
                ContactModule      m      = (ContactModule)module;
                TimeSeries.Contact series = new TimeSeries.Contact(timeSeries, m.GetNames());
                for (int i = 0; i < timeSeries.Samples.Length; i++)
                {
                    float t = frame.Timestamp + timeSeries.Samples[i].Timestamp;
                    series.Values[i] = m.GetContacts(Data.GetFrame(t), mirrored);
                }
            }
            if (module is PhaseModule)
            {
                PhaseModule      m      = (PhaseModule)module;
                TimeSeries.Phase series = new TimeSeries.Phase(timeSeries);
                for (int i = 0; i < timeSeries.Samples.Length; i++)
                {
                    float t = frame.Timestamp + timeSeries.Samples[i].Timestamp;
                    series.Values[i] = m.GetPhase(Data.GetFrame(t), mirrored);
                }
            }
        }
        return(timeSeries);
    }