Inheritance: MonoBehaviour
示例#1
0
        private void LoadMap()
        {
            var directoryPickerDialog = new CommonOpenFileDialog()
            {
                IsFolderPicker = true
            };

            if (directoryPickerDialog.ShowDialog() != CommonFileDialogResult.Ok)
            {
                return;
            }

            if (Game.LocalPlayer == null)
            {
                return;
            }

            /// All the geometry is loaded Z-up:
            ///   Z
            ///   |
            ///   ._ Y
            ///  /
            /// X
            Task.Factory.StartNew(() => {
                GeometryLoader = new GeometryLoader(directoryPickerDialog.FileName, Game.CurrentMap);
            });
        }
示例#2
0
        private void OnWorldUpdate()
        {
            _playerExplorer.SetDataSource(Game.Players);
            _unitExplorer.SetDataSource(Game.Units);
            _gameObjectExplorer.SetDataSource(Game.GameObjects);

            Invoke((Action)(() =>
            {
                if (!GeometryLoader.Initialized && Game.IsLoggedIn)
                {
                    var directoryPickerDialog = new CommonOpenFileDialog()
                    {
                        IsFolderPicker = true
                    };
                    if (directoryPickerDialog.ShowDialog() != CommonFileDialogResult.Ok)
                    {
                        return;
                    }

                    DBC.AsyncInitialize(directoryPickerDialog.FileName);

                    GeometryLoader.Initialize(string.Intern(directoryPickerDialog.FileName), Game.CurrentMap);
                }

                _renderControl.Invalidate();
            }));
        }
示例#3
0
    // Use this for initialization
    void Start()
    {
        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader>();

        gl.setTheme(new NatureThemingMode());

        string path = "";

        if (Application.platform == RuntimePlatform.OSXEditor)
        {
            path = "Data/";
        }
        else if (Application.platform == RuntimePlatform.OSXPlayer)
        {
            path = "../../";
        }
        else if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = "Data/";
        }
        else if (Application.platform == RuntimePlatform.WindowsPlayer)
        {
            path = "../";
        }

        loadPedestrianFile(path + "b090_combined.txt");
        loadGeometryFile(path + "geometry.txt");
    }
示例#4
0
    public static void create(string name, List <Vector2> verticesList, float height, float width, float zOffset)
    {
        int   wallpoints = verticesList.Count;
        float wall       = width;

        //extrude the wall
        for (int i = wallpoints - 1; i >= 0; i--)
        {
            Vector2 extrudePoint;

            if (i == wallpoints - 1)
            {
                Vector2 lot = verticesList[i - 1] - verticesList[i];
                lot = new Vector2(-lot.y, lot.x);
                lot.Normalize();
                extrudePoint = verticesList[i] + lot * wall;
            }
            else if (i == 0)
            {
                Vector2 lot = verticesList[0] - verticesList[1];
                lot = new Vector2(-lot.y, lot.x);
                lot.Normalize();
                extrudePoint = verticesList[0] + lot * wall;
            }
            else
            {
                float angle = Vector2.Angle(verticesList[i] - verticesList[i - 1], verticesList[i] - verticesList[i + 1]);

                float thickness;

                if (Mathf.Cos(angle / 2) != 0)
                {
                    thickness = wall / Mathf.Sin(angle * Mathf.Deg2Rad / 2);
                }
                else
                {
                    thickness = 100;
                }

                Vector3 cross = Vector3.Cross(verticesList[i] - verticesList[i - 1], verticesList[i] - verticesList[i + 1]);
                if (cross.z > 0)
                {
                    angle = 360 - angle;
                }

                Vector2 lot = verticesList[i] - verticesList[i + 1];
                lot = Quaternion.AngleAxis(angle / 2, Vector3.forward) * lot;
                lot.Normalize();

                extrudePoint = verticesList[i] + lot * thickness;
            }

            verticesList.Add(extrudePoint);
        }

        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader> ();

        ExtrudeGeometry.create(name, verticesList, height, zOffset, gl.theme.getWallsMaterial(), gl.theme.getWallsMaterialST());
    }
    void Start()
    {
        gameObject.AddComponent <BoxCollider>();
        transform.Rotate(0, 90, 0);
        myColor = new Color(Random.value, Random.value, Random.value);
        GetComponentInChildren <Renderer>().materials[1].color = myColor;
        addTile();

        it = GameObject.Find("InfoText").GetComponent <InfoText>();
        pl = GameObject.Find("PedestrianLoader").GetComponent <PedestrianLoader>();
        pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl>();
        r  = GetComponentInChildren <Renderer>() as Renderer;
        gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader>();
        gp = gl.groundplane;
    }
示例#6
0
        private void RenderGeometry()
        {
            if (InvokeRequired)
            {
                Invoke((Action)(() => RenderGeometry()));
            }
            else if (Game.IsValid && GeometryLoader.Initialized && Game.LocalPlayer != null)
            {
                var tileX = (int)Math.Floor(32 - Game.LocalPlayer.X / 533.3333f);
                var tileY = (int)Math.Floor(32 - Game.LocalPlayer.Y / 533.3333f);
                GeometryLoader.Render(tileY, tileX, toolStripTrackBar1.Value);

                _renderControl.SwapBuffers();
            }
        }
示例#7
0
    // Use this for initialization
    void Start()
    {
        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader>();

        gl.setTheme(new LabThemingMode());

        var GeometryXML = EditorUtility.OpenFilePanel(
            "Load Geometry", "", "xml");

        var TrajectoryXML = EditorUtility.OpenFilePanel(
            "Load Trajectory", "", "xml");

        loadPedestrianFile(TrajectoryXML);
        loadGeometryFile(GeometryXML);
    }
    public static void create(string name, List <Vector2> verticesList, float height)
    {
        Material topMaterial;
        Material sideMaterial;

        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader>();

        if (height <= 4.0)
        {
            sideMaterial = gl.theme.getBoxMaterial();
            topMaterial  = gl.theme.getBoxMaterial();
        }
        else
        {
            topMaterial  = gl.theme.getRoofMaterial();
            sideMaterial = gl.theme.getHouseMaterial();
            sideMaterial.SetTextureScale("_MainTex", gl.theme.getTextureScaleForHeight((float)height));
        }

        ExtrudeGeometry.create(name, verticesList, height, topMaterial, sideMaterial);
    }
    public static void create(string name, List <Vector2> verticesList, float zOffset)
    {
        Material sideMaterial;

        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader>();

        sideMaterial = gl.theme.getWallsMaterialST();

        GameObject floor       = new GameObject(name, typeof(MeshFilter), typeof(MeshRenderer));
        MeshFilter mesh_filter = floor.GetComponent <MeshFilter>();
        Mesh       mesh        = mesh_filter.mesh;

        floor.GetComponent <Renderer>().material = sideMaterial;
        mesh.Clear();

        floor.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        floor.GetComponent <Renderer>().material          = sideMaterial;

        Vector2[] vertices2D = verticesList.ToArray();

        Triangulator tr = new Triangulator(vertices2D);

        int[] indices = tr.Triangulate();

        // Create the Vector3 vertices
        Vector3[] vertices = new Vector3[vertices2D.Length];
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i] = new Vector3(vertices2D[i].x, zOffset + 0.05f, vertices2D[i].y);
        }

        // Create the mesh
        mesh           = TangentHelper.TangentSolver(mesh);
        mesh.vertices  = vertices;
        mesh.triangles = indices;
        mesh.RecalculateBounds();
    }
    public static void create(string name, List <Vector2> coordFirst, List <Vector2> coordSecond, float A_x, float B_y, float C_z, float pxUp, float pyUp, float pxDown, float pyDown)
    {
        Material topMaterial;

        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader>();

        topMaterial = gl.theme.getWallsMaterial();

        GameObject stair       = new GameObject(name, typeof(MeshFilter), typeof(MeshRenderer));
        MeshFilter mesh_filter = stair.GetComponent <MeshFilter>();
        Mesh       mesh        = mesh_filter.mesh;

        mesh.Clear();

        stair.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
        stair.GetComponent <Renderer>().material          = topMaterial;


        #region Vertices

        Vector2 origin = new Vector2((pxDown + pxUp) / 2, (pyDown + pyUp) / 2);

        Vector2[] pointsArray = new Vector2[]
        {
            coordFirst[0],
            coordFirst[1],
            coordSecond[0],
            coordSecond[1]
        };

        float[] angles = angleToOrigin(pointsArray, origin).ToArray();

        Array.Sort(angles, pointsArray);

        Vector3[] p = generateEdges(pointsArray, A_x, B_y, C_z).ToArray();

        Vector3[] vertices = new Vector3[]
        {
            // Bottom
            p[0], p[1], p[2], p[3],

            // Left
            p[7], p[4], p[0], p[3],

            // Front
            p[4], p[5], p[1], p[0],

            // Back
            p[6], p[7], p[3], p[2],

            // Right
            p[5], p[6], p[2], p[1],

            // Top
            p[7], p[6], p[5], p[4]
        };
        #endregion

        #region Normals
        Vector3 up    = Vector3.up;
        Vector3 down  = Vector3.down;
        Vector3 front = Vector3.forward;
        Vector3 back  = Vector3.back;
        Vector3 left  = Vector3.left;
        Vector3 right = Vector3.right;

        Vector3[] normals = new Vector3[]
        {
            // Bottom
            down, down, down, down,

            // Left
            left, left, left, left,

            // Front
            front, front, front, front,

            // Back
            back, back, back, back,

            // Right
            right, right, right, right,

            // Top
            up, up, up, up
        };
        #endregion

        #region UVs
        float lenghtRelX = 1; //(float) Math.Sqrt(Math.Pow(p[1].x - p[0].x, 2) + Math.Pow(p[1].y - p[0].y, 2));   //calculate actual length of stairs for correct texture mapping
        float lenghtRelY = 1; //(float) Math.Sqrt(Math.Pow(p[2].z - p[1].z, 2) + Math.Pow(p[2].y - p[1].y, 2));

        //Debug.Log(lenghtRelX + "  " + lenghtRelY);

        Vector2 _00 = new Vector2(0f, 0f);
        Vector2 _10 = new Vector2(lenghtRelX, 0f);
        Vector2 _01 = new Vector2(0f, lenghtRelY);
        Vector2 _11 = new Vector2(lenghtRelX, lenghtRelY);

        Vector2[] uvs = new Vector2[]
        {
            // Bottom
            _11, _01, _00, _10,

            // Left
            _11, _01, _00, _10,

            // Front
            _11, _01, _00, _10,

            // Back
            _11, _01, _00, _10,

            // Right
            _11, _01, _00, _10,

            // Top
            _11, _01, _00, _10,
        };
        #endregion

        #region Triangles
        int[] triangles = new int[]
        {
            // Bottom
            3, 1, 0,
            3, 2, 1,

            // Left
            3 + 4 * 1, 1 + 4 * 1, 0 + 4 * 1,
            3 + 4 * 1, 2 + 4 * 1, 1 + 4 * 1,

            // Front
            3 + 4 * 2, 1 + 4 * 2, 0 + 4 * 2,
            3 + 4 * 2, 2 + 4 * 2, 1 + 4 * 2,

            // Back
            3 + 4 * 3, 1 + 4 * 3, 0 + 4 * 3,
            3 + 4 * 3, 2 + 4 * 3, 1 + 4 * 3,

            // Right
            3 + 4 * 4, 1 + 4 * 4, 0 + 4 * 4,
            3 + 4 * 4, 2 + 4 * 4, 1 + 4 * 4,

            // Top
            3 + 4 * 5, 1 + 4 * 5, 0 + 4 * 5,
            3 + 4 * 5, 2 + 4 * 5, 1 + 4 * 5,
        };
        #endregion

        mesh           = TangentHelper.TangentSolver(mesh);
        mesh.vertices  = vertices;
        mesh.normals   = normals;
        mesh.uv        = uvs;
        mesh.triangles = triangles;
        mesh.RecalculateBounds();
    }
示例#11
0
    void OnGUI()
    {
        playing      = GUI.Toggle(new Rect(30, 25, 100, 30), playing, " PLAY");
        current_time = (decimal)GUI.HorizontalSlider(new Rect(100, 30, 400, 30), (float)current_time, 0.0f, (float)total_time);

        string btnText = "show trajectories";

        if (trajectoriesShown)
        {
            btnText = "hide trajectories";
        }

        if (GUI.Button(new Rect(510, 20, 120, 30), btnText))
        {
            PedestrianLoader pl = GameObject.Find("PedestrianLoader").GetComponent <PedestrianLoader>();
            if (trajectoriesShown)
            {
                foreach (GameObject p in pl.pedestirans)
                {
                    p.GetComponent <Pedestrian>().hideTrajectory();
                }
                trajectoriesShown = false;
            }
            else
            {
                foreach (GameObject p in pl.pedestirans)
                {
                    p.GetComponent <Pedestrian>().showTrajectory();
                }
                trajectoriesShown = true;
            }
        }



        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader> ();
        Groundplane    gp = gl.groundplane;

        btnText = "add line";
        if (drawLine)
        {
            GUI.color = Color.red;
        }
        if (lineIsDrawn)
        {
            btnText = "remove line";
        }

        if (GUI.Button(new Rect(640, 20, 80, 30), btnText))
        {
            if (lineIsDrawn)
            {
                gp.removeLine();
                drawLine    = false;
                lineIsDrawn = false;
            }
            else
            {
                drawLine = !drawLine;
                if (!drawLine)
                {
                    gp.removeLine();
                }
            }
        }
        GUI.color = Color.white;

        if (tiles == 0)
        {
            btnText = "colors by speed";
        }
        if (tiles == 1)
        {
            btnText = "colors by density";
        }
        if (tiles == 2)
        {
            btnText = "hide colors";
        }

        if (GUI.Button(new Rect(730, 20, 120, 30), btnText))
        {
            tiles = (tiles + 1) % 3;

            InfoText it = GameObject.Find("InfoText").GetComponent <InfoText> ();
            if (it.diagram)
            {
                it.removeDiagram();
            }

            if (tiles == 0)
            {
                tileColoringMode = TileColoringMode.TileColoringNone;
            }
            if (tiles == 1)
            {
                tileColoringMode = TileColoringMode.TileColoringSpeed;
            }
            if (tiles == 2)
            {
                tileColoringMode = TileColoringMode.TileColoringDensity;
            }
        }

        if (tileColoringMode == TileColoringMode.TileColoringDensity)
        {
            threshold = GUI.HorizontalSlider(new Rect(730, 55, 120, 30), threshold, 0.0f, 6.0f);
            GUI.Label(new Rect(730, 70, 120, 30), "Threshold: " + System.Math.Round(threshold, 2) + "/m²");
        }
    }
示例#12
0
    void OnGUI()
    {
        PlaybackControl  pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl> ();
        PedestrianLoader pl = GameObject.Find("PedestrianLoader").GetComponent <PedestrianLoader> ();
        GeometryLoader   gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader> ();
        Groundplane      gp = gl.groundplane;

        infos = new List <Entry> ();

        string text    = "";
        string minutes = Mathf.Floor((float)pc.current_time / 60).ToString("00");;
        string seconds = ((float)pc.current_time % 60).ToString("00");;

        text += "current time: " + minutes + ":" + seconds + "\n";

        if (pl.population != null)
        {
            infos.Add(new Entry("population", "", pl.population[(int)pc.current_time], 0, true, pl.pedestirans.Count));
        }

        if (gp.point1active && gp.point2active)
        {
            infos.Add(new Entry("line length", "m", Vector3.Distance(gp.point1, gp.point2), 2, false, 0));
            infos.Add(new Entry("line crossings", "", gp.lineCrossed, 0, true, pl.pedestirans.Count));
            infos.Add(new Entry("line flow", "/s", gp.crossings.Count, 0, true, 10.0f));
            infos.Add(new Entry("avg. crossing speed", "m/s", gp.crossingSpeed, 2, true, 3.0f));
            infos.Add(new Entry("current flow", "/ms", gp.crossings.Count / Vector3.Distance(gp.point1, gp.point2), 2, true, 3.0f));
        }

        if (pc.tileColoringMode == TileColoringMode.TileColoringSpeed)
        {
            infos.Add(new Entry("current speed", "m/s", currentValue(currentSpeed), 2, true, 3.0f));
            infos.Add(new Entry("min. speed", "m/s", minSpeed, 2, false, 3.0f));
            infos.Add(new Entry("max. speed", "m/s", maxSpeed, 2, false, 3.0f));
        }
        else
        {
            maxSpeed = float.MinValue;
            minSpeed = float.MaxValue;
        }

        if (pc.tileColoringMode == TileColoringMode.TileColoringDensity)
        {
            infos.Add(new Entry("current density", "/m²", currentValue(currentDensity), 2, true, 3.0f));
            infos.Add(new Entry("min. density", "/m²", minDenstiy, 2, false, 5.0f));
            infos.Add(new Entry("max. density", "/m²", maxDensity, 2, false, 5.0f));
        }
        else
        {
            maxDensity = float.MinValue;
            minDenstiy = float.MaxValue;
            crossings  = 0;
        }

        for (int i = 0; i < infos.Count; i++)
        {
            Entry e = infos[i];
            text += infos[i].name + ": " + System.Math.Round(e.value, e.decimals) + e.unit + "\n";
            if (e.graphable)
            {
                if (GUI.Toggle(new Rect(Screen.width * (transform.position.x) - 20, Screen.height * (1 - transform.position.y) - (15 * (infos.Count - i) + 17), 100, 15), i == activeEntry, "") && i != activeEntry)
                {
                    removeDiagram();
                    activeEntry = i;
                    Rect position = new Rect(30, 30, 400, 300);
                    position.x = Screen.width - position.x - position.width;
                    drawDiagram(position);
                }
            }
        }
        guiText.text = text;

        if (diagram)
        {
            GUI.Label(new Rect(diagramPosition.x, Screen.height - diagramPosition.y - diagramPosition.height - 30, diagramPosition.width, 30), infos[activeEntry].name);
            GUI.Label(new Rect(diagramPosition.x - 15, Screen.height - diagramPosition.y, 30, 30), "[s]");
            GUI.Label(new Rect(diagramPosition.x - 35, Screen.height - diagramPosition.y - diagramPosition.height - 10, 30, 30), System.Math.Round(infos[activeEntry].maxValue, infos[activeEntry].decimals) + "");
            if (infos[activeEntry].unit != "")
            {
                GUI.Label(new Rect(diagramPosition.x - 35, Screen.height - diagramPosition.y - diagramPosition.height - 30, 30, 30), "[" + infos[activeEntry].unit + "]");
            }
        }
    }