Exemplo n.º 1
0
    private void DrawControlPoint(float x, float y, float width, float height, Queue <float> values, Color color)
    {
        int   _index = 0;
        float _x     = 0f;
        float _xPrev = 0f;
        float _y     = 0f;
        float _yPrev = 0f;

        foreach (float value in values)
        {
            _x = x + (float)(_index) / (float)(Frames - 1) * width;
            _y = y - height + value * height;
            if (_index > 0)
            {
                UltiDraw.DrawGUILine(
                    new Vector2(_xPrev, _yPrev),
                    new Vector2(_x, _y),
                    0.002f,
                    color
                    );
            }
            _xPrev  = _x;
            _yPrev  = _y;
            _index += 1;
        }
    }
Exemplo n.º 2
0
    void OnRenderObject()
    {
        if (Elements <= Feet.Length)
        {
            return;
        }

        UltiDraw.Begin();

        Color[] colors = UltiDraw.GetRainbowColors(Feet.Length);
        for (int i = 0; i < colors.Length; i++)
        {
            colors[i] = colors[i].Darken(0.25f);
        }
        for (int i = 0; i < Feet.Length; i++)
        {
            UltiDraw.DrawSphere(Feet[i].transform.position, Quaternion.identity, 0.075f, colors[i]);
        }

        float border = 0.01f;
        float width  = Rect.W;
        float height = Feet.Length * Rect.H + (Feet.Length - 1) * border / 2f;

        UltiDraw.DrawGUIRectangle(Rect.GetPosition(), new Vector2(width, height), UltiDraw.DarkGrey.Transparent(0.75f), 0.5f * border, UltiDraw.BlackGrey);
        float pivot = 0.5f * height;

        for (int i = 1; i <= Feet.Length; i++)
        {
            pivot -= Rect.H / 2f;
            UltiDraw.DrawGUIRectangle(Rect.GetPosition() + new Vector2(0f, pivot), new Vector2(Rect.W, Rect.H), UltiDraw.White.Transparent(0.5f));
            for (int j = 0; j < Positions[i - 1].Count; j++)
            {
                float p = (float)j / (float)(Positions[i - 1].Count - 1);
                p = Utility.Normalise(p, 0f, 1f, 0.5f * Thickness / Rect.W, (Rect.W - 0.5f * Thickness) / Rect.W);
                float x    = Rect.X - 0.5f * Rect.W + p * Rect.W;
                float yTop = pivot + Rect.H / 2f;
                float yBot = pivot - Rect.H / 2f;
                float h    = Positions[i - 1][j].y - Utility.GetHeight(Positions[i - 1][j], LayerMask.GetMask("Ground"));
                if (h < Thresholds[i - 1])
                {
                    UltiDraw.DrawGUILine(new Vector2(x, Rect.Y + yTop), new Vector2(x, Rect.Y + yBot), Thickness, colors[i - 1]);
                }
            }
            pivot -= border / 2f;
            pivot -= Rect.H / 2f;
        }

        UltiDraw.End();
    }
    private void DrawGraph()
    {
        UltiDraw.Begin();
        Color[] colors = UltiDraw.GetRainbowColors(Values.Length);
        Vector2 pivot  = Rect.GetPosition();
        float   radius = 0.2f * Rect.W;

        UltiDraw.DrawGUICircle(pivot, Rect.W * 1.05f, UltiDraw.Gold);
        UltiDraw.DrawGUICircle(pivot, Rect.W, UltiDraw.White);
        Vector2[] anchors = new Vector2[Values.Length];
        for (int i = 0; i < Values.Length; i++)
        {
            float step = (float)i / (float)Values.Length;
            anchors[i] = new Vector2((Rect.W - radius / 2f) * Screen.height / Screen.width * Mathf.Cos(step * 2f * Mathf.PI), (Rect.W - radius / 2f) * Mathf.Sin(step * 2f * Mathf.PI));
        }
        Vector2[] positions = new Vector2[Frames];
        for (int i = 0; i < Values.Length; i++)
        {
            int _index = 0;
            foreach (float value in Values[i])
            {
                positions[_index] += value * anchors[i];
                _index            += 1;
            }
        }
        for (int i = 1; i < positions.Length; i++)
        {
            UltiDraw.DrawGUILine(pivot + positions[i - 1], pivot + positions[i], 0.1f * radius, UltiDraw.Black.Transparent((float)(i + 1) / (float)positions.Length));
        }
        for (int i = 0; i < anchors.Length; i++)
        {
            UltiDraw.DrawGUILine(pivot + positions.Last(), pivot + anchors[i], 0.1f * radius, colors[i].Transparent(Weights[i]));
            UltiDraw.DrawGUICircle(pivot + anchors[i], Mathf.Max(0.5f * radius, Utility.Normalise(Weights[i], 0f, 1f, 0.5f, 1f) * radius), Color.Lerp(UltiDraw.Black, colors[i], Weights[i]));
        }
        UltiDraw.DrawGUICircle(pivot + positions.Last(), 0.5f * radius, UltiDraw.Purple);
        UltiDraw.End();
    }
Exemplo n.º 4
0
    void OnRenderObject()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (NN.GetTensor(ID) == null)
        {
            return;
        }

        UltiDraw.Begin();

        float[] values = new float[Values.Length];
        for (int i = 0; i < Values.Length; i++)
        {
            values[i] = NN.GetTensor(ID).GetValue(i, 0);
        }

        //Utility.SoftMax(ref values);

        for (int i = 0; i < Values.Length; i++)
        {
            Values[i].Dequeue();
            Values[i].Enqueue(values[i]);
        }

        switch (Mode)
        {
        case MODE.Function:
            Vector2 center = new Vector2(X, Y);
            float   border = 0.0025f;
            UltiDraw.DrawGUIRectangle(
                center,
                new Vector2(W + 2f * border / Screen.width * Screen.height, H + 2f * border),
                UltiDraw.Black);
            UltiDraw.DrawGUIRectangle(
                center,
                new Vector2(W, H),
                UltiDraw.White);

            Color[] colors = UltiDraw.GetRainbowColors(Values.Length);
            for (int i = 0; i < colors.Length; i++)
            {
                DrawControlPoint(center.x - W / 2f, center.y + H / 2f, W, H, Values[i], colors[i]);
            }
            //for(int i=0; i<colors.Length; i++) {
            //	Vector2 start = center - new Vector2(width/2f, -height/2f);
            //	UltiDraw.DrawGUIRectangle(start + (float)i/(float)(colors.Length-1)*new Vector2(width, 0f), new Vector2(0.025f, 0.025f), colors[i]);
            //}
            break;

        case MODE.Bars:

            break;

        case MODE.Graph:
            Vector2 pivot  = new Vector2(X, Y);
            float   radius = 0.2f * W;
            UltiDraw.DrawGUICircle(pivot, W * 1.05f, UltiDraw.Gold);
            UltiDraw.DrawGUICircle(pivot, W, UltiDraw.White);
            Vector2[] anchors = new Vector2[Values.Length];
            for (int i = 0; i < Values.Length; i++)
            {
                float step = (float)i / (float)Values.Length;
                anchors[i] = new Vector2((W - radius / 2f) * Screen.height / Screen.width * Mathf.Cos(step * 2f * Mathf.PI), (W - radius / 2f) * Mathf.Sin(step * 2f * Mathf.PI));
                UltiDraw.DrawGUICircle(pivot + anchors[i], Mathf.Max(0.5f * radius, Utility.Normalise(values[i], 0f, 1f, 0.5f, 1f) * radius), UltiDraw.Black);
            }
            Vector2[] positions = new Vector2[Frames];
            for (int i = 0; i < Values.Length; i++)
            {
                int _index = 0;
                foreach (float value in Values[i])
                {
                    positions[_index] += value * anchors[i];
                    _index            += 1;
                }
            }
            for (int i = 1; i < positions.Length; i++)
            {
                UltiDraw.DrawGUILine(pivot + positions[i - 1], pivot + positions[i], 0.1f * radius, UltiDraw.Black.Transparent((float)(i + 1) / (float)positions.Length));
            }
            for (int i = 0; i < Values.Length; i++)
            {
                UltiDraw.DrawGUILine(pivot + positions[positions.Length - 1], pivot + anchors[i], 0.1f * radius, UltiDraw.Black.Transparent(values[i]));
            }
            UltiDraw.DrawGUICircle(pivot + positions[positions.Length - 1], 0.5f * radius, UltiDraw.Purple);
            break;
        }

        UltiDraw.End();
    }
Exemplo n.º 5
0
    public void Draw()
    {
        if (GetCurrentFile() == null)
        {
            return;
        }

        //if(ShowMotion) {
        //	for(int i=0; i<GetState().PastBoneTransformations.Count; i++) {
        //		GetActor().DrawSimple(Color.Lerp(UltiDraw.Blue, UltiDraw.Cyan, 1f - (float)(i+1)/6f).Transparent(0.75f), GetState().PastBoneTransformations[i]);
        //	}
        //	for(int i=0; i<GetState().FutureBoneTransformations.Count; i++) {
        //		GetActor().DrawSimple(Color.Lerp(UltiDraw.Red, UltiDraw.Orange, (float)i/5f).Transparent(0.75f), GetState().FutureBoneTransformations[i]);
        //	}
        //}

        /*
         * UltiDraw.Begin();
         * //Exp Map
         * int window = 10;
         * for(int k=0; k<3; k++) {
         *      List<float[]> functions = new List<float[]>();
         *      for(int i=0; i<Actor.Bones.Length; i++) {
         *              List<float> values = new List<float>();
         *              for(int j=Mathf.Clamp(GetCurrentFrame().Index - window, 1, GetCurrentFile().Data.GetTotalFrames()); j<=Mathf.Clamp(GetCurrentFrame().Index + window, 1, GetCurrentFile().Data.GetTotalFrames()); j++) {
         *                      Frame frame = GetCurrentFile().Data.GetFrame(j);
         *                      Vector3 exp = frame.Local[i].GetRotation().GetLog();
         *                      if(k==0) {
         *                              values.Add(exp.x);
         *                      }
         *                      if(k==1) {
         *                              values.Add(exp.y);
         *                      }
         *                      if(k==2) {
         *                              values.Add(exp.z);
         *                      }
         *              }
         *              functions.Add(values.ToArray());
         *      }
         *      UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.1f + k*0.2f), new Vector2(0.8f, 0.175f), functions, -1f, 1f, UltiDraw.DarkGrey, UltiDraw.GetRainbowColors(functions.Count));
         *      UltiDraw.DrawGUILine(new Vector2(0.5f, 0f), new Vector2(0.5f, 1f), 0.0025f, UltiDraw.Green.Transparent(0.5f));
         * }
         * UltiDraw.End();
         */


        UltiDraw.Begin();

        Trajectory previous = ((TrajectoryModule)GetCurrentFile().Data.GetModule(Module.TYPE.Trajectory)).GetTrajectory(GetCurrentFrame().GetPreviousFrame(), Mirror);
        Trajectory current  = ((TrajectoryModule)GetCurrentFile().Data.GetModule(Module.TYPE.Trajectory)).GetTrajectory(GetCurrentFrame(), Mirror);
        Trajectory next     = ((TrajectoryModule)GetCurrentFile().Data.GetModule(Module.TYPE.Trajectory)).GetTrajectory(GetCurrentFrame().GetNextFrame(), Mirror);

        Color[] colors = UltiDraw.GetRainbowColors(previous.Styles.Length);

        List <float[]> signalInput = new List <float[]>();

        for (int i = 0; i < current.Styles.Length; i++)
        {
            float[] s = new float[current.Points.Length];
            for (int j = 0; j < current.Points.Length; j++)
            {
                s[j] = current.Points[j].Signals[i];
            }
            signalInput.Add(s);
        }
        UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.9f), new Vector2(0.75f, 0.1f), signalInput, -1f, 1f, UltiDraw.DarkGrey, colors);

        List <float[]> stateInput = new List <float[]>();

        for (int i = 0; i < current.Styles.Length; i++)
        {
            float[] s = new float[current.Points.Length];
            for (int j = 0; j < current.Points.Length; j++)
            {
                s[j] = current.Points[j].Styles[i];
            }
            stateInput.Add(s);
        }
        UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.75f), new Vector2(0.75f, 0.1f), stateInput, 0f, 1f, UltiDraw.DarkGrey, colors);

        /*
         * List<float[]> stateUpdateInput = new List<float[]>();
         * for(int i=0; i<current.Styles.Length; i++) {
         *      float[] s = new float[current.Points.Length];
         *      for(int j=0; j<current.Points.Length; j++) {
         *              s[j] = current.Points[j].Styles[i] - previous.Points[j].Styles[i];
         *      }
         *      stateUpdateInput.Add(s);
         * }
         * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.6f), new Vector2(0.75f, 0.1f), stateUpdateInput, -1f, 1f, UltiDraw.DarkGrey, colors);
         */
        List <float[]> stateOutput = new List <float[]>();

        for (int i = 0; i < next.Styles.Length; i++)
        {
            float[] s = new float[next.Points.Length];
            for (int j = 0; j < next.Points.Length; j++)
            {
                s[j] = next.Points[j].Styles[i];
            }
            stateOutput.Add(s);
        }
        UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.6f), new Vector2(0.75f, 0.1f), stateOutput, 0f, 1f, UltiDraw.DarkGrey, colors);

        /*
         * List<float[]> stateUpdateOutput = new List<float[]>();
         * for(int i=0; i<next.Styles.Length; i++) {
         *      float[] s = new float[next.Points.Length];
         *      for(int j=0; j<next.Points.Length; j++) {
         *              s[j] = next.Points[j].Styles[i] - current.Points[j].Styles[i];
         *      }
         *      stateUpdateOutput.Add(s);
         * }
         * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.1f), new Vector2(0.75f, 0.1f), stateUpdateOutput, -1f, 1f, UltiDraw.DarkGrey, colors);
         */
        UltiDraw.DrawGUILine(new Vector2(0.5f - 0.75f / 2f + 6f / 11f * 0.75f, 1f), new Vector2(0.5f - 0.75f / 2f + 6f / 11f * 0.75f, 0f), 0.0025f, UltiDraw.Green);

        UltiDraw.End();


        for (int i = 0; i < GetCurrentFile().Data.Modules.Length; i++)
        {
            GetCurrentFile().Data.Modules[i].Draw(this);
        }
    }
Exemplo n.º 6
0
    public void Draw()
    {
        if (ShowMotion)
        {
            for (int i = 0; i < GetState().PastBoneTransformations.Count; i++)
            {
                GetActor().DrawSimple(Color.Lerp(UltiDraw.Blue, UltiDraw.Cyan, 1f - (float)(i + 1) / 6f).Transparent(0.75f), GetState().PastBoneTransformations[i]);
            }

            /*
             * for(int i=1; i<=5; i++) {
             *      MotionData.Frame future = Data.GetFrame(Mathf.Clamp(GetState().Timestamp + (float)i/5f, 0f, Data.GetTotalTime()));
             *      GetActor().DrawSimple(Color.Lerp(UltiDraw.Red, UltiDraw.Orange, (float)(i+1)/5f).Transparent(0.75f), future.GetBoneTransformations(Mirror));
             * }
             */
        }
        if (ShowVelocities)
        {
            UltiDraw.Begin();
            for (int i = 0; i < GetActor().Bones.Length; i++)
            {
                UltiDraw.DrawArrow(
                    GetActor().Bones[i].Transform.position,
                    GetActor().Bones[i].Transform.position + GetState().BoneVelocities[i],
                    0.75f,
                    0.0075f,
                    0.05f,
                    UltiDraw.Purple.Transparent(0.5f)
                    );
            }
            UltiDraw.End();
        }
        if (ShowTrajectory)
        {
            GetState().Trajectory.Draw();
        }

        if (ShowHeightMap)
        {
            GetState().HeightMap.Draw();
        }

        if (ShowDepthMap)
        {
            GetState().DepthMap.Draw();
        }

        UltiDraw.Begin();
        UltiDraw.DrawGUIRectangle(Vector2.one / 2f, Vector2.one, UltiDraw.Mustard);
        UltiDraw.End();

        if (ShowDepthImage)
        {
            UltiDraw.Begin();
            Vector2 size = new Vector2(0.5f, 0.5f * Screen.width / Screen.height);
            for (int x = 0; x < GetState().DepthMap.GetResolution(); x++)
            {
                for (int y = 0; y < GetState().DepthMap.GetResolution(); y++)
                {
                    float distance  = Vector3.Distance(GetState().DepthMap.Points[GetState().DepthMap.GridToArray(x, y)], GetState().DepthMap.Pivot.GetPosition());
                    float intensity = 1f - distance / GetState().DepthMap.GetDistance();
                    //intensity = Utility.TanH(intensity);
                    UltiDraw.DrawGUIRectangle(Vector2.one / 2f - size / 2f + new Vector2((float)x * size.x, (float)y * size.y) / (GetState().DepthMap.GetResolution() - 1), size / (GetState().DepthMap.GetResolution() - 1), Color.Lerp(Color.black, Color.white, intensity));
                }
            }
            UltiDraw.End();
        }

        //Motion Function
        MotionData.Frame[] frames = Data.GetFrames(Mathf.Clamp(GetState().Timestamp - 1f, 0f, Data.GetTotalTime()), Mathf.Clamp(GetState().Timestamp + 1f, 0f, Data.GetTotalTime()));
        float[]            values = new float[frames.Length];
        for (int i = 0; i < frames.Length; i++)
        {
            values[i] = frames[i].GetBoneVelocity(0, Mirror).magnitude;
        }
        Debug.Log(values[0]);
        UltiDraw.Begin();
        UltiDraw.DrawGUIFunction(new Vector2(0.5f, 0.5f), new Vector2(1f, 1f), values, -2f, 2f, 0.0025f, UltiDraw.DarkGrey, UltiDraw.Green);
        UltiDraw.DrawGUILine(new Vector2(0.5f, 1f), new Vector2(0.5f, 0f), 0.0025f, UltiDraw.IndianRed);
        UltiDraw.End();

        /*
         * MotionData.Frame[] frames = Data.GetFrames(Mathf.Clamp(GetState().Timestamp-1f, 0f, Data.GetTotalTime()), Mathf.Clamp(GetState().Timestamp+1f, 0f, Data.GetTotalTime()));
         * List<float[]> values = new List<float[]>();
         * for(int i=0; i<Actor.Bones.Length; i++) {
         *      values.Add(new float[frames.Length]);
         * }
         * for(int i=0; i<frames.Length; i++) {
         *      for(int j=0; j<Actor.Bones.Length; j++) {
         *              values[j][i] = frames[i].GetBoneVelocity(j, Mirror).magnitude;
         *      }
         *      //Vector3 motion = frames[i].GetRootMotion(Mirror);
         *      //values[0][i] = motion.x;
         *      //values[1][i] = motion.y / 180f;
         *      //values[2][i] = motion.z;
         * }
         * UltiDraw.Begin();
         * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.5f), new Vector2(1f, 1f), values, -2f, 2f, 0.0025f, UltiDraw.DarkGrey, UltiDraw.GetRainbowColors(values.Count));
         * UltiDraw.DrawGUILine(new Vector2(0.5f, 1f), new Vector2(0.5f, 0f), 0.0025f, UltiDraw.Green);
         * UltiDraw.End();
         */
        //Agility Function

        /*
         * MotionData.Frame[] frames = Data.GetFrames(Mathf.Clamp(GetState().Timestamp-1f, 0f, Data.GetTotalTime()), Mathf.Clamp(GetState().Timestamp+1f, 0f, Data.GetTotalTime()));
         * List<float[]> values = new List<float[]>();
         * for(int i=0; i<Data.Source.Bones.Length; i++) {
         *      values.Add(new float[frames.Length]);
         *      for(int j=0; j<frames.Length; j++) {
         *              values[i][j] = frames[j].GetAgility(i, Mirror);
         *      }
         * }
         * UltiDraw.Begin();
         * UltiDraw.DrawGUIFunctions(new Vector2(0.5f, 0.5f), new Vector2(1f, 1f), values, -1f, 1f, 0.0025f, UltiDraw.DarkGrey, UltiDraw.GetRainbowColors(values.Count));
         * UltiDraw.DrawGUILine(new Vector2(0.5f, 1f), new Vector2(0.5f, 0f), 0.0025f, UltiDraw.Green);
         * UltiDraw.End();
         */
    }