public void RepareTerrains()
        {
            List <TerrainObject> List_terrainsObj = new List <TerrainObject>();

            foreach (var item in terrains)
            {
                if (item != null)
                {
                    List_terrainsObj.Add(item);
                }
            }

            if (UseTerrainHeightSmoother)
            {
                GISTerrainLoaderTerrainSmoother.SmoothTerrainHeights(List_terrainsObj, 1 - TerrainHeightSmoothFactor);
            }

            if (UseTerrainSurfaceSmoother)
            {
                GISTerrainLoaderTerrainSmoother.SmoothTerrainSurface(List_terrainsObj, TerrainSurfaceSmoothFactor);
            }

            GISTerrainLoaderBlendTerrainEdge.StitchTerrain(List_terrainsObj, 50f, 20);

            GISTerrainLoaderBlendTerrainEdge.StitchTerrain(List_terrainsObj, 20f, 20);

            CurrentTerrainIndex = 0;

            phase = GeneratingTerrainPhase.generateTextures;
        }
        private void GenerateTextures(int index)
        {
            if (index >= terrains.Length || textureMode == TextureMode.WithoutTexture)
            {
                phase = GeneratingTerrainPhase.generateEnvironement;
                return;
            }

            int x = index % terrainCount.x;
            int y = index / terrainCount.x;


            DirectoryInfo di = new DirectoryInfo(TerrainFilePath);

            var TextureFolderPath = TerrainFile.name + "_Textures";

            for (int i = 0; i <= 5; i++)
            {
                di = di.Parent;
                TextureFolderPath = di.Name + "/" + TextureFolderPath;
                if (di.Name == "GIS Terrains")
                {
                    break;
                }

                if (i == 5)
                {
                    Debug.LogError("Texture folder not found! : Please put your terrain in GIS Terrain Loader/Recources/GIS Terrains/");
                }
            }

            AddTextureToTerrain(TextureFolderPath, terrains[x, y]);

            CurrentTerrainIndex++;
        }
Exemple #3
0
        private void GenerateTextures()
        {
            if (prefs.textureMode == TextureMode.WithTexture)
            {
                int index = 0;

                foreach (var Tile in ListTerrainObjects)
                {
                    GISTerrainLoaderTextureGenerator.AddTextures(FilePath, Tile, new Vector2(prefs.textureWidth, prefs.textureHeight));

                    float prog = ((index) * 100 / (terrains.GetLength(0) * terrains.GetLength(1))) / 100f;

                    index++;

                    if (OnProgression != null)
                    {
                        OnProgression("Generate Textures", prog);
                    }
                }
                phase = GeneratingTerrainPhase.finish;
            }
            else
            {
                phase = GeneratingTerrainPhase.finish;
            }
        }
Exemple #4
0
        private void Finish()
        {
            if (OnProgression != null)
            {
                OnProgression("Finalization", progress);
            }

            foreach (TerrainObject item in terrains)
            {
                item.terrain.Flush();
            }
            phase = GeneratingTerrainPhase.idle;


            if (Camera.main.GetComponent <Camera3D>())
            {
                var cam = Camera.main.GetComponent <Camera3D>();
                cam.cameraTarget = new Vector3(75f * prefs.terrainScale.x, 30f * prefs.terrainScale.y, 75f * prefs.terrainScale.z);
                cam.enabled      = true;
            }


            if (OnProgression != null)
            {
                SendTerrainOrigine(floatReader.Origine, floatReader.MinElevation, floatReader.MaxElevation);
            }
        }
Exemple #5
0
        private void GenerateHeightmap()
        {
            int index = 0;

            foreach (var Tile in ListTerrainObjects)
            {
                if (index >= terrains.Length - 1)
                {
                    Debug.Log("GeneratingTerrainPhase.RepareTerrains : " + index);
                    phase = GeneratingTerrainPhase.RepareTerrains;
                }
                var terrainCount = new Vector2Int(prefs.terrainCount.x, prefs.terrainCount.y);

                int x = index % terrainCount.x;
                int y = index / terrainCount.x;

                float prog = ((index) * 100 / (terrains.GetLength(0) * terrains.GetLength(1))) / 100f;

                floatReader.GenerateHeightMap(Terrainscontainer, terrains[x, y]);
                index++;
                if (floatReader.generateComplete)
                {
                    progress = 0;
                    floatReader.generateComplete = false;
                }

                if (OnProgression != null)
                {
                    OnProgression("Generating Heightmap", (float)prog);
                }
            }
        }
 private void Finish()
 {
     foreach (TerrainObject item in terrains)
     {
         item.terrain.Flush();
     }
     phase = GeneratingTerrainPhase.idle;
 }
Exemple #7
0
        public void RepareTerrains()
        {
            GISTerrainLoaderBlendTerrainEdge.StitchTerrain(ListTerrainObjects, 50f, 20);

            GISTerrainLoaderBlendTerrainEdge.StitchTerrain(ListTerrainObjects, 20f, 20);

            phase = GeneratingTerrainPhase.generateTextures;
        }
        private void GenerateEnvironment()
        {
            var nodes     = new Dictionary <string, OSMNode>();
            var ways      = new Dictionary <string, OSMWay>();
            var relations = new List <OSMMapMembers>();

            //Load OSM File
            if (EnableTreeGeneration || EnableGrassGeneration)
            {
                bool OSMExist;

                var OSMFilePath = Extensions.CheckForOSMFile(TerrainFilePath, TerrainFile.name, out OSMExist);

                if (OSMExist)
                {
                    GISTerrainLoaderOSMFileLoader.LoadOSMFile(OSMFilePath, out nodes, out ways, out relations);
                }
                else
                {
                    Debug.LogError("OSM File Not Found : please set your osm file into 'GIS Terrains'\'TerrainName'\'TerrainName_VectorData'");
                    phase = GeneratingTerrainPhase.finish;
                }
            }
            //Generate Trees
            if (EnableTreeGeneration)
            {
                if (TreePrefabs.Count > 0)
                {
                    var m_TreeDensity = 100 - TreeDensity;
                    GISTerrainLoaderTreeGenerator.GenerateTrees(GeneratedContainer, TreePrefabs, m_TreeDensity, TreeScaleFactor, TreeRandomScaleFactor, TreeDistance, BillBoardStartDistance, nodes, ways, relations);
                }
                else
                {
                    Debug.LogError("Error : Tree Prefabs List is empty ");
                }
            }

            //Generate Grass
            if (EnableGrassGeneration)
            {
                if (GrassPrefabs.Count > 0)
                {
                    var m_GrassDensity = 100 - GrassDensity;

                    GISTerrainLoaderGrassGenerator.GenerateGrass(GeneratedContainer, GrassPrefabs, GrassDensity, GrassScaleFactor, DetailDistance, nodes, ways, relations);
                }
                else
                {
                    Debug.LogError("Error : Grass Prefabs List is empty ");
                }
            }

            phase = GeneratingTerrainPhase.finish;
        }
 private void CheckForFile()
 {
     if (File.Exists(TerrainFilePath))
     {
         phase = GeneratingTerrainPhase.LoadElevation;
     }
     else
     {
         phase = GeneratingTerrainPhase.idle;
     }
 }
 private void Initialization()
 {
     if (!string.IsNullOrEmpty(TerrainFilePath) && File.Exists(TerrainFilePath))
     {
         phase = GeneratingTerrainPhase.CheckFile;
     }
     else
     {
         Debug.LogError("File Not Exist : " + TerrainFilePath + " Please set (*.flt) File.. Try againe");
     }
 }
Exemple #11
0
        public void LoadFloatFile(string filepath)
        {
            try
            {
                if (File.Exists(filepath))
                {
                    floatReader = new FloatReader();

                    floatReader.LoadFloatGrid(filepath);

                    if (floatReader.LoadComplet)
                    {
                        phase = GeneratingTerrainPhase.generateTerrains;

                        floatReader.LoadComplet = false;

                        if (floatReader.Terrain_Dimension.x == 0 || floatReader.Terrain_Dimension.y == 0)
                        {
                            Debug.LogError("Can't detecte terrain dimension please try againe .");
                            return;
                        }
                        else
                        {
                            prefs.terrainDimensions = new Vector2((float)floatReader.Terrain_Dimension.x, (float)floatReader.Terrain_Dimension.y);
                        }


                        if (floatReader.Tiles.x != 0 || floatReader.Tiles.y != 0)
                        {
                            prefs.terrainCount = new Vector2Int((int)floatReader.Tiles.x, (int)floatReader.Tiles.y);
                        }
                        else
                        {
                            Debug.LogError(floatReader.Tiles + "Terrain textures Tiles Count not set in Hdr file ... try againe");

                            phase = GeneratingTerrainPhase.idle;
                        }

                        if (OnProgression != null)
                        {
                            OnProgression("Loading Elevation File", 1);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Couldn't convert Terrain file:");
                Debug.Log(ex.Message + Environment.NewLine);
                phase = GeneratingTerrainPhase.idle;
            };
        }
        private void GenerateHeightmap(int index)
        {
            if (index >= terrains.Length)
            {
                phase = GeneratingTerrainPhase.RepareTerrains;
                return;
            }

            int x = index % terrainCount.x;
            int y = index / terrainCount.x;

            Prefs prefs = new Prefs(detailResolution, resolutionPerPatch, baseMapResolution, heightmapResolution, terrainCount);

            floatReader.GenerateHeightMap(prefs, terrains[x, y]);

            if (floatReader.generateComplete)
            {
                CurrentTerrainIndex++;

                floatReader.generateComplete = false;
            }
        }
 static void OnError()
 {
     phase = GeneratingTerrainPhase.idle;
 }
        public void GenerateTerrains()
        {
            const string containerName = "Terrains";
            string       cName         = containerName;

            //Destroy prv created terrain
            if (RemovePrvTerrain)
            {
                DestroyImmediate(GameObject.Find(cName));
            }
            else
            {
                int index = 1;
                while (GameObject.Find(cName) != null)
                {
                    cName = containerName + " " + index.ToString();
                    index++;
                }
            }


            var container = new GameObject(cName);

            container.transform.position = new Vector3(0, 0, 0);
            CurrentTerrainIndex          = 0;

            Vector2Int tCount = new Vector2Int(terrainCount.x, terrainCount.y);

            float maxElevation   = floatReader.MaxElevation;
            float minElevation   = floatReader.MinElevation;
            float ElevationRange = maxElevation - minElevation;

            var sizeX = Mathf.Floor(m_terrainDimensions.x * terrainScale.x * 10) / terrainCount.x;
            var sizeZ = Mathf.Floor(m_terrainDimensions.y * terrainScale.z * 10) / terrainCount.y;
            var sizeY = (ElevationRange) / ElevationScaleValue * TerrainExaggeration * 100 * terrainScale.y * 10;

            Vector3 size;

            if (terrainElevation == TerrainElevation.RealWorldElevation)
            {
                sizeY = ((ElevationRange)) * terrainScale.y;
                size  = new Vector3(sizeX, sizeY, sizeZ);
            }
            else
            {
                sizeY = sizeY * 10;
                size  = new Vector3(sizeX, sizeY, sizeZ);
            }

            string resultFolder   = "Assets/Generated GIS Terrains";
            string resultFullPath = Path.Combine(Application.dataPath, "Generated GIS Terrains");

            if (!Directory.Exists(resultFullPath))
            {
                Directory.CreateDirectory(resultFullPath);
            }
            string dateStr = DateTime.Now.ToString("yyyy-MM-dd HH-mm-") + DateTime.Now.Second.ToString();

            resultFolder  += "/" + dateStr;
            resultFullPath = Path.Combine(resultFullPath, dateStr);
            if (!Directory.Exists(resultFullPath))
            {
                Directory.CreateDirectory(resultFullPath);
            }



            terrains = new TerrainObject[tCount.x, tCount.y];

            container.AddComponent <TerrainContainerObject>();

            var terrainContainer = container.GetComponent <TerrainContainerObject>();

            terrainContainer.terrainCount = new Vector2Int(terrainCount.x, terrainCount.y);

            terrainContainer.GeneratedTerrainfolder = resultFolder;

            terrainContainer.scale = terrainScale;

            terrainContainer.size = new Vector3(size.x * tCount.x, size.y, size.z * tCount.y);

            //Set Terrain Coordinates to the container TerrainContainer script (Lat/lon) + Mercator
            terrainContainer.TLPointLatLong = floatReader.TopLeftPoint;
            terrainContainer.DRPointLatLong = floatReader.DownRightPoint;

            terrainContainer.TLPointMercator = GeoRefConversion.LatLongToMercat(terrainContainer.TLPointLatLong.x, terrainContainer.TLPointLatLong.y);
            terrainContainer.DRPointMercator = GeoRefConversion.LatLongToMercat(terrainContainer.DRPointLatLong.x, terrainContainer.DRPointLatLong.y);

            //Terrain Size Bounds
            var centre = new Vector3(terrainContainer.size.x / 2, 0, terrainContainer.size.z / 2);

            terrainContainer.GlobalTerrainBounds = new Bounds(centre, new Vector3(centre.x + terrainContainer.size.x / 2, 0, centre.z + terrainContainer.size.z / 2));



            for (int x = 0; x < tCount.x; x++)
            {
                for (int y = 0; y < tCount.y; y++)
                {
                    terrains[x, y]           = CreateTerrain(terrainContainer, x, y, size, terrainScale);
                    terrains[x, y].container = terrainContainer;
                }
            }

            terrainContainer.terrains = terrains;

            GeneratedContainer = terrainContainer;

            phase = GeneratingTerrainPhase.generateHeightmaps;
        }
Exemple #15
0
 void Start()
 {
     prefs = TerrainPrefs.Get;
     phase = GeneratingTerrainPhase.idle;
     FloatReader.OnReadError += OnError;
 }
Exemple #16
0
        public void GenerateTerrains()
        {
            ListTerrainObjects = new List <TerrainObject>();

            const string containerName = "Terrains";
            string       cName         = containerName;

            //Destroy prv created terrain
            if (RemovePrevTerrain)
            {
                Destroy(GameObject.Find(cName));
            }
            else
            {
                int index = 1;
                while (GameObject.Find(cName) != null)
                {
                    cName = containerName + " " + index.ToString();
                    index++;
                }
            }


            var container = new GameObject(cName);

            container.transform.position = new Vector3(0, 0, 0);

            progress = 0;

            Vector2 TlimiteFrom = new Vector2(prefs.terrainDimensions.x, 0);
            Vector2 TlimiteTo   = new Vector2(prefs.terrainDimensions.y, 0);

            Vector2Int tCount = new Vector2Int((int)prefs.terrainCount.x, (int)prefs.terrainCount.y);

            float maxElevation   = floatReader.MaxElevation;
            float minElevation   = floatReader.MinElevation;
            float ElevationRange = maxElevation - minElevation;

            var sizeX = Mathf.Floor(prefs.terrainDimensions.x * prefs.terrainScale.x) / prefs.terrainCount.x;
            var sizeZ = Mathf.Floor(prefs.terrainDimensions.y * prefs.terrainScale.z) / prefs.terrainCount.y;
            var sizeY = (ElevationRange) / ElevationScaleValue * prefs.TerrainExaggeration * 100 * prefs.terrainScale.y;

            Vector3 size;

            if (prefs.TerrainElevation == TerrainElevation.RealWorldElevation)
            {
                sizeY = ((ElevationRange)) * prefs.terrainScale.y / 100;
                size  = new Vector3(sizeX, sizeY, sizeZ);
            }
            else
            {
                size = new Vector3(sizeX, sizeY, sizeZ);
            }

            terrains = new TerrainObject[tCount.x, tCount.y];

            container.AddComponent <TerrainContainerObject>();

            var terrainContainer = container.GetComponent <TerrainContainerObject>();

            Terrainscontainer = terrainContainer;

            terrainContainer.terrainCount = prefs.terrainCount;

            terrainContainer.scale = prefs.terrainScale;

            terrainContainer.size = new Vector3(size.x * tCount.x, size.y, size.z * tCount.y);

            //Set Terrain Coordinates to the container TerrainContainer script (Lat/lon) + Mercator
            terrainContainer.TLPointLatLong = floatReader.TopLeftPoint;
            terrainContainer.DRPointLatLong = floatReader.DownRightPoint;

            terrainContainer.TLPointMercator = GeoRefConversion.LatLongToMercat(terrainContainer.TLPointLatLong.x, terrainContainer.TLPointLatLong.y);
            terrainContainer.DRPointMercator = GeoRefConversion.LatLongToMercat(terrainContainer.DRPointLatLong.x, terrainContainer.DRPointLatLong.y);



            progress = 0;

            for (int x = 0; x < tCount.x; x++)
            {
                for (int y = 0; y < tCount.y; y++)
                {
                    terrains[x, y]           = CreateTerrain(container.transform, x, y, size, prefs.terrainScale);
                    terrains[x, y].container = terrainContainer;

                    ListTerrainObjects.Add(terrains[x, y]);
                }
            }

            terrainContainer.terrains = terrains;

            phase = GeneratingTerrainPhase.generateHeightmaps;
        }