Exemple #1
0
        public void DrawNewAgents()
        {
            List <FeatureMesh> meshList = new List <FeatureMesh>();

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

                    FeatureMesh             featureMesh = new FeatureMesh("NameGama1", "GamaRoads", "NameGama13", 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();

                    Triangulator triangulator = new Triangulator(vertices2D);
                    Vertices = triangulator.get3dVerticesList(vertices2D, 2);
                    Indices  = triangulator.getTriangulesList();
                    UVs      = new List <Vector2>();

                    Vector3[] VerticesArray = Vertices.ToArray();

                    Vector2[] UvArray = UvCalculator.CalculateUVs(VerticesArray, 1);

                    UVs = UvArray.ToList();

                    submesh.Indices = Indices;
                    Submeshes.Add(submesh);

                    meshData.addGamaMeshData(Vertices, UVs, Submeshes);
                    featureMesh.Mesh = meshData;
                    meshList.Add(featureMesh);

                    meshList.Add(featureMesh);
                }
            }

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

            // Merge all feature meshes
            List <FeatureMesh> features = new List <FeatureMesh>();

            /*
             * foreach (var task in tasks)
             * {
             *  if (task.Generation == generation)
             *  {
             *      features.AddRange(task.Data);
             *  }
             * }
             *
             * tasks.Clear();
             * nTasksForArea = 0;
             */

            features.AddRange(meshList);
            regionMap = new GameObject(RegionName);
            var sceneGraph = new SceneGraph(regionMap, GroupOptions, GameObjectOptions, features);

            sceneGraph.Generate();
        }
        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();
            }
        }
Exemple #3
0
        public void GenerateSceneGraph()
        {
            // Add tasks here!
            //------------------------------------------------------------------
            Debug.Log("Calling method - > GenerateSceneGraph ");

            List <FeatureMesh> meshList    = new List <FeatureMesh>();
            FeatureMesh        featureMesh = new FeatureMesh("NameGama1", "GamaBlocks", "NameGama3", "Blok1"); meshList.Add(featureMesh);

            featureMesh = new FeatureMesh("NameGama1", "GamaBlocks", "GamaBlocks", "Block2"); meshList.Add(featureMesh);
            featureMesh = new FeatureMesh("NameGama1", "GamaBlocks", "Na6", "Block3"); meshList.Add(featureMesh);
            featureMesh = new FeatureMesh("NameGama1", "GamaRoads", "NameGama9", "Road1"); meshList.Add(featureMesh);



            featureMesh = new FeatureMesh("NameGama11", "GamaRoads", "NameGama13", "Road2");
            // featureMesh.Mesh = new MeshData();

            MeshData meshData = featureMesh.Mesh;
            // List<Submesh> Submeshes = new List<Submesh>();
            List <Vector3> Vertices = new List <Vector3>();
            List <Vector2> UVs      = new List <Vector2>();
            List <int>     Indices  = new List <int>();

            List <MeshData.Submesh> Submeshes = new List <MeshData.Submesh>();

            MeshData.Submesh submesh = new MeshData.Submesh();


            //Material Material = new Material(contents: "UVGrid");
            submesh.Indices = Indices;
            Submeshes.Add(submesh);



            meshData.addGamaMeshData(Vertices, UVs, Submeshes);
            featureMesh.Mesh = meshData;

            //meshData.Meshes

            meshList.Add(featureMesh);



            featureMesh = new FeatureMesh("NameGama11", "GamaRoads", "NameGama13", "Cube3");
            // featureMesh.Mesh = new MeshData();

            meshData = featureMesh.Mesh;

            Vector2[] vertices2D = new Vector2[] {
                new Vector2(0, 0),
                new Vector2(10, 0),
                new Vector2(10, 10),
                new Vector2(0, 10),
            };
            Triangulator triangulator = new Triangulator(vertices2D);

            Vertices = triangulator.get3dVerticesList(vertices2D, 2);
            Indices  = triangulator.getTriangulesList();

            UVs = new List <Vector2>();

            UVs.AddRange(new List <Vector2> {
                new Vector2(0.0f, 0.2f), new Vector2(0.0f, 0.2f), new Vector2(0.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(0.1f, 0.2f), new Vector2(0.0f, 0.2f), new Vector2(0.1f, 0f), new Vector2(0.0f, 0.0f)
            });
            Submeshes = new List <MeshData.Submesh>();
            submesh   = new MeshData.Submesh();

            submesh.Indices = Indices;
            Submeshes.Add(submesh);

            meshData.addGamaMeshData(Vertices, UVs, Submeshes);
            featureMesh.Mesh = meshData;
            meshList.Add(featureMesh);


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

            // Merge all feature meshes
            List <FeatureMesh> features = new List <FeatureMesh>();

            foreach (var task in tasks)
            {
                if (task.Generation == generation)
                {
                    features.AddRange(task.Data);
                }
            }

            tasks.Clear();
            nTasksForArea = 0;

            features.AddRange(meshList);
            regionMap = new GameObject(RegionName);
            var sceneGraph = new SceneGraph(regionMap, GroupOptions, GameObjectOptions, features);

            sceneGraph.Generate();
        }