Esempio n. 1
0
    private IEnumerator ExportData()
    {
        Exporting = true;

        StreamWriter input  = CreateFile("Input");
        StreamWriter output = CreateFile("Output");

        for (int e = 0; e < Editors.Length; e++)
        {
            if (Export[e])
            {
                MotionEditor editor = Editors[e];
                int          items  = 0;
                for (int i = 0; i < editor.GetFiles().Length; i++)
                {
                    if (editor.Files[i].Data.Export)
                    {
                        editor.LoadFile(editor.Files[i]);

                        //StyleModule styleModule = editor.GetFile().Data.GetModule(Module.TYPE.Style) == null ? null : (StyleModule)editor.GetFile().Data.GetModule(Module.TYPE.Style);
                        PhaseModule phaseModule = editor.GetFile().Data.GetModule(Module.TYPE.Phase) == null ? null : (PhaseModule)editor.GetFile().Data.GetModule(Module.TYPE.Phase);

                        for (int m = 1; m <= (Mirror ? 2 : 1); m++)
                        {
                            if (m == 1)
                            {
                                editor.SetMirror(false);
                            }
                            if (m == 2)
                            {
                                editor.SetMirror(true);
                            }
                            for (int s = 0; s < editor.GetFile().Data.Sequences.Length; s++)
                            {
                                MotionData.Sequence.Interval[] intervals = editor.GetFile().Data.Sequences[s].GetIntervals();
                                for (int interval = 0; interval < intervals.Length; interval++)
                                {
                                    Generating = 0f;
                                    Writing    = 0f;

                                    List <State> states = new List <State>();
                                    float        start  = editor.GetFile().Data.GetFrame(intervals[interval].Start).Timestamp;
                                    float        end    = editor.GetFile().Data.GetFrame(intervals[interval].End).Timestamp;

                                    for (float t = start; t <= end; t += 1f / Framerate)
                                    {
                                        Generating = (t - start) / (end - start - 1f / Framerate);
                                        editor.LoadFrame(t);
                                        states.Add(editor.GetState());
                                        //Spin
                                        items += 1;
                                        if (items == BatchSize)
                                        {
                                            items = 0;
                                            yield return(new WaitForSeconds(0f));
                                        }
                                    }

                                    for (int state = 0; state < states.Count - 1; state++)
                                    {
                                        Writing = (float)(state) / (float)(states.Count - 2);
                                        State current = states[state];
                                        State next    = states[state + 1];
                                        editor.LoadFrame(current);

                                        //Input
                                        string inputLine = string.Empty;
                                        for (int k = 0; k < 12; k++)
                                        {
                                            Vector3 position  = current.Trajectory.Points[k].GetPosition().GetRelativePositionTo(current.Root);
                                            Vector3 direction = current.Trajectory.Points[k].GetDirection().GetRelativeDirectionTo(current.Root);
                                            Vector3 velocity  = current.Trajectory.Points[k].GetVelocity().GetRelativeDirectionTo(current.Root);
                                            float[] style     = current.Trajectory.Points[k].Styles;
                                            inputLine += FormatValue(position.x);
                                            inputLine += FormatValue(position.z);
                                            inputLine += FormatValue(direction.x);
                                            inputLine += FormatValue(direction.z);
                                            inputLine += FormatValue(velocity.x);
                                            inputLine += FormatValue(velocity.z);
                                            inputLine += FormatArray(style);
                                        }
                                        for (int k = 0; k < current.BoneTransformations.Length; k++)
                                        {
                                            Vector3 position = current.BoneTransformations[k].GetPosition().GetRelativePositionTo(current.Root);
                                            Vector3 forward  = current.BoneTransformations[k].GetForward().GetRelativeDirectionTo(current.Root);
                                            Vector3 up       = current.BoneTransformations[k].GetUp().GetRelativeDirectionTo(current.Root);
                                            Vector3 velocity = current.BoneVelocities[k].GetRelativeDirectionTo(current.Root);
                                            inputLine += FormatVector3(position);
                                            inputLine += FormatVector3(forward);
                                            inputLine += FormatVector3(up);
                                            inputLine += FormatVector3(velocity);
                                        }
                                        if (phaseModule != null)
                                        {
                                            float currentPhase = phaseModule.GetPhase(editor.GetFile().Data.GetFrame(current.Index), editor.ShowMirror);
                                            //inputLine += FormatVector2(Utility.GetCirclePhase(currentPhase));
                                            inputLine += FormatArray(Utility.StylePhase(current.Trajectory.Points[6].Styles, currentPhase));
                                        }

                                        inputLine = inputLine.Remove(inputLine.Length - 1);
                                        inputLine = inputLine.Replace(",", ".");
                                        input.WriteLine(inputLine);

                                        //Output
                                        string outputLine = string.Empty;
                                        for (int k = 6; k < 12; k++)
                                        {
                                            Vector3 position  = next.Trajectory.Points[k].GetPosition().GetRelativePositionTo(current.Root);
                                            Vector3 direction = next.Trajectory.Points[k].GetDirection().GetRelativeDirectionTo(current.Root);
                                            Vector3 velocity  = next.Trajectory.Points[k].GetVelocity().GetRelativeDirectionTo(current.Root);
                                            float[] style     = next.Trajectory.Points[k].Styles;
                                            outputLine += FormatValue(position.x);
                                            outputLine += FormatValue(position.z);
                                            outputLine += FormatValue(direction.x);
                                            outputLine += FormatValue(direction.z);
                                            outputLine += FormatValue(velocity.x);
                                            outputLine += FormatValue(velocity.z);
                                            outputLine += FormatArray(style);
                                        }
                                        for (int k = 0; k < next.BoneTransformations.Length; k++)
                                        {
                                            Vector3 position = next.BoneTransformations[k].GetPosition().GetRelativePositionTo(current.Root);
                                            Vector3 forward  = next.BoneTransformations[k].GetForward().GetRelativeDirectionTo(current.Root);
                                            Vector3 up       = next.BoneTransformations[k].GetUp().GetRelativeDirectionTo(current.Root);
                                            Vector3 velocity = next.BoneVelocities[k].GetRelativeDirectionTo(current.Root);
                                            outputLine += FormatVector3(position);
                                            outputLine += FormatVector3(forward);
                                            outputLine += FormatVector3(up);
                                            outputLine += FormatVector3(velocity);
                                        }
                                        //outputLine += FormatVector3(next.RootMotion);
                                        if (phaseModule != null)
                                        {
                                            float currentPhase = phaseModule.GetPhase(editor.GetFile().Data.GetFrame(current.Index), editor.ShowMirror);
                                            float nextPhase    = phaseModule.GetPhase(editor.GetFile().Data.GetFrame(next.Index), editor.ShowMirror);
                                            outputLine += FormatValue(Utility.GetLinearPhaseUpdate(currentPhase, nextPhase));
                                        }

                                        outputLine = outputLine.Remove(outputLine.Length - 1);
                                        outputLine = outputLine.Replace(",", ".");
                                        output.WriteLine(outputLine);

                                        //Spin
                                        items += 1;
                                        if (items == BatchSize)
                                        {
                                            items = 0;
                                            yield return(new WaitForSeconds(0f));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        input.Close();
        output.Close();

        Exporting = false;
        yield return(new WaitForSeconds(0f));
    }
Esempio n. 2
0
    public Trajectory GetTrajectory(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 ? 0 : styleModule.Functions.Length);

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

        //Past
        for (int i = 0; i < 6; i++)
        {
            float delta = -1f + (float)i / 6f;
            if (Timestamp + delta < 0f)
            {
                float pivot     = -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(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 (Timestamp + delta > Data.GetTotalTime())
            {
                float pivot     = 2f * Data.GetTotalTime() - 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(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 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());

        int window = 5;

        //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, window);
        trajectory.Points[6].Phase   = phaseModule == null ? 0f : phaseModule.GetPhase(frame, mirrored, window);
        trajectory.Points[6].Signals = styleModule == null ? new float[0] : styleModule.GetSignal(frame, window);

        //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, window);
                trajectory.Points[i].Phase   = phaseModule == null ? 0f : Mathf.Repeat(phaseModule.GetPhase(Data.GetFirstFrame(), mirrored, window) - Utility.GetLinearPhaseUpdate(phaseModule.GetPhase(Data.GetFirstFrame(), mirrored, window), phaseModule.GetPhase(reference, mirrored, window)), 1f);
                trajectory.Points[i].Signals = styleModule == null ? new float[0] : styleModule.GetInverseSignal(reference, window);
            }
            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, window);
                trajectory.Points[i].Phase   = phaseModule == null ? 0f : phaseModule.GetPhase(previous, mirrored, window);
                trajectory.Points[i].Signals = styleModule == null ? new float[0] : styleModule.GetSignal(previous, window);
            }
        }

        //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, window);
                trajectory.Points[6 + i].Phase   = phaseModule == null ? 0f : Mathf.Repeat(phaseModule.GetPhase(Data.GetLastFrame(), mirrored, window) + Utility.GetLinearPhaseUpdate(phaseModule.GetPhase(reference, mirrored, window), phaseModule.GetPhase(Data.GetLastFrame(), mirrored, window)), 1f);
                trajectory.Points[6 + i].Signals = styleModule == null ? new float[0] : styleModule.GetInverseSignal(reference, window);
            }
            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, window);
                trajectory.Points[6 + i].Phase   = phaseModule == null ? 0f : phaseModule.GetPhase(future, mirrored, window);
                trajectory.Points[6 + i].Signals = styleModule == null ? new float[0] : styleModule.GetSignal(future, window);
            }
        }
        return(trajectory);
    }
Esempio n. 4
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. 5
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);
    }