Exemplo n.º 1
0
        public void DrawNewAgents()
        {
            RegionName = "GamaMap";

            bool isNewAgentCreated      = false;
            List <FeatureMesh> meshList = new List <FeatureMesh>();

            foreach (var agent in GamaManager.gamaAgentList)
            {
                if (!agent.isDrawed)
                {
                    isNewAgentCreated = true;
                    agent.isDrawed    = true;

                    //FeatureMesh featureMesh = new FeatureMesh("NameGama1", agent.geometry, "NameGama13", agent.agentName);

                    FeatureMesh             featureMesh = new FeatureMesh(agent.agentName, agent.getCollection(), agent.getLayer(), agent.agentName);
                    List <Vector3>          Vertices    = new List <Vector3>();
                    List <Vector2>          UVs         = new List <Vector2>();
                    List <int>              Indices     = new List <int>();
                    MeshData                meshData    = featureMesh.Mesh;
                    List <MeshData.Submesh> Submeshes   = new List <MeshData.Submesh>();
                    MeshData.Submesh        submesh     = new MeshData.Submesh();

                    Vector2[] vertices2D = agent.agentCoordinate.getVector2Coordinates();

                    /*
                     * // To delete. This is dealt in the UtilXml Class
                     * List<Vector2> vect = new List<Vector2>();
                     * vect = vertices2D.ToList();
                     * if (agent.geometry.Equals("Polygon"))
                     * {
                     * //  vect.RemoveAt(vect.Count - 1);
                     * }
                     * vertices2D = vect.ToArray();
                     */

                    Triangulator triangulator = new Triangulator(vertices2D);
                    triangulator.setAllPoints(triangulator.get2dVertices());
                    float elevation = this.elevation;
                    if (agent.geometry.Equals("LineString"))
                    {
                        elevation = 0.0f;
                    }
                    //Vertices = triangulator.get3dVerticesList(elevation);
                    Vertices = triangulator.get3dVerticesList(agent.height);
                    Debug.Log("-------------->>>>  " + agent.agentName + " hight is ---------------> " + agent.height);
                    Indices = triangulator.getTriangulesList();
                    Vector3[] VerticesArray = Vertices.ToArray();
                    Vector2[] UvArray       = UvCalculator.CalculateUVs(VerticesArray, 100);
                    UVs = new List <Vector2>();
                    UVs = UvArray.ToList();

                    /*
                     * if (agent.geometry.Equals("Point"))
                     * {
                     *  Vertices = agent.agentCoordinate.getVector3Coordinates().ToList();
                     *  Indices = new List<int>();
                     *  Indices.Add(1);Indices.Add(1);Indices.Add(1);
                     *  UVs = new List<Vector2>();
                     * }
                     */


                    submesh.Indices = Indices;

                    submesh.Material = buildingMaterial;

                    Submeshes.Add(submesh);

                    Debug.Log("addGamaMeshData ------> " + agent.geometry + " Agent name -> " + agent.agentName);

                    meshData.addGamaMeshData(Vertices, UVs, Submeshes, agent);


                    featureMesh.Mesh = meshData;
                    meshList.Add(featureMesh);
                }
            }



            if (isNewAgentCreated)
            {
                if (regionMap != null)
                {
                    //DestroyImmediate(regionMap); Debug.Log("regionMap is Null");
                }

                // Merge all feature meshes
                List <FeatureMesh> features = new List <FeatureMesh>();
                features.AddRange(meshList);
                regionMap = GameObject.Find(RegionName);


                if (regionMap == null)
                {
                    regionMap = new GameObject(RegionName);
                }
                Debug.Log("The rgion Name is : " + RegionName);
                //regionMap = new GameObject(RegionName);
                var sceneGraph = new SceneGraph(regionMap, GroupOptions, GameObjectOptions, features);
                //sceneGraph
                sceneGraph.DrawFromGama();
            }
        }