Exemple #1
0
        void OnRenderObject()
        {
            if (Root == null)
            {
                Root = transform;
            }

            UltiDraw.Begin();
            UltiDraw.DrawGUICircle(new Vector2(0.5f, 0.85f), 0.075f, UltiDraw.Black.Transparent(0.5f));
            Quaternion rotation = Quaternion.AngleAxis(-360f * ((PFNN)NN.Model).GetPhase() / (2f * Mathf.PI), Vector3.forward);
            Vector2    a        = rotation * new Vector2(-0.005f, 0f);
            Vector2    b        = rotation * new Vector3(0.005f, 0f);
            Vector3    c        = rotation * new Vector3(0f, 0.075f);

            UltiDraw.DrawGUITriangle(new Vector2(0.5f + b.x / Screen.width * Screen.height, 0.85f + b.y), new Vector2(0.5f + a.x / Screen.width * Screen.height, 0.85f + a.y), new Vector2(0.5f + c.x / Screen.width * Screen.height, 0.85f + c.y), UltiDraw.Cyan);
            UltiDraw.End();

            if (Application.isPlaying)
            {
                UltiDraw.Begin();
                UltiDraw.DrawLine(Trajectory.Points[RootPointIndex].GetPosition(), Trajectory.Points[RootPointIndex].GetPosition() + TargetDirection, 0.05f, 0f, UltiDraw.Red.Transparent(0.75f));
                UltiDraw.DrawLine(Trajectory.Points[RootPointIndex].GetPosition(), Trajectory.Points[RootPointIndex].GetPosition() + TargetVelocity, 0.05f, 0f, UltiDraw.Green.Transparent(0.75f));
                UltiDraw.End();
                Trajectory.Draw(10);
            }

            if (!Application.isPlaying)
            {
                Character.FetchTransformations(Root);
            }
            Character.Draw();

            if (Application.isPlaying)
            {
                UltiDraw.Begin();
                for (int i = 0; i < Joints.Length; i++)
                {
                    Character.Segment segment = Character.FindSegment(Joints[i].name);
                    if (segment != null)
                    {
                        UltiDraw.DrawArrow(
                            Joints[i].position,
                            Joints[i].position + Velocities[i] * 60f,
                            0.75f,
                            0.0075f,
                            0.05f,
                            UltiDraw.Purple.Transparent(0.5f)
                            );
                    }
                }
                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();
    }
    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();
    }