void Awake()
        {
            textureSettings.ApplyToMaterial(mapMaterial);
            textureSettings.UpdateMeshHeights(mapMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);

            float maxViewDst = detailLevels[detailLevels.Length - 1].visibleDstThreshold;

            meshChunksize          = meshSettings.meshWorldSize;
            chunksVisibleInViewDst = Mathf.RoundToInt(maxViewDst / meshChunksize);

            //retrieve the values needed to generate things
            _heighestTerrainPoint = HeightMapGenerator.GetHeighestPoint(GetWorldHeightMap());
            _lowestTerrainPoint   = HeightMapGenerator.GetLowestPoint(GetWorldHeightMap());

            _environmentGenerator = new EnvironmentGenerator(GetWorldHeightMap(), meshSettings, textureSettings);

            //Assign all the chunks
            int minX = -Mathf.RoundToInt(_terrainSizeInChunks.x * 0.5f);
            int maxX = Mathf.RoundToInt(_terrainSizeInChunks.x * 0.5f);
            int minY = -Mathf.RoundToInt(_terrainSizeInChunks.y * 0.5f);
            int maxY = Mathf.RoundToInt(_terrainSizeInChunks.y * 0.5f);

            for (int x = minX; x <= maxX; x++)
            {
                for (int y = minY; y <= maxY; y++)
                {
                    Vector2 chunkCoord = new Vector2(x, y);

                    TerrainChunk newChunk = new TerrainChunk(chunkCoord, heightMapSettings, meshSettings, textureSettings, detailLevels, colliderLODIndex, transform, viewer, mapMaterial);
                    terrainChunkDictionary.Add(chunkCoord, newChunk);
                    newChunk.onVisibilityChanged += OnTerrainChunkVisibilityChanged;
                    newChunk.Load();

                    Debug.Log(chunkCoord);

                    _environmentGenerator.RegisterChunk(chunkCoord, GetChunkHeightMap(chunkCoord)); //register this chunk to the EnvironmentGenerator
                }
            }

            UpdateVisibleChunks();

            GetAllChunksTransforms();

            // ----->>> SpawnMultipleTrees();
        }
예제 #2
0
        public void DrawMapInEditor()
        {
            textureData.ApplyToMaterial(terrainMaterial);
            textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
            HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);

            if (drawMode == DrawMode.NoiseMap)
            {
                DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
            }
            else if (drawMode == DrawMode.Mesh)
            {
                DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            }
            else if (drawMode == DrawMode.FalloffMap)
            {
                DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
            }
        }
예제 #3
0
 public void Load()
 {
     ThreadedDataRequester.RequestData(() => HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, sampleCentre), OnHeightMapReceived);
 }
        private HeightMap GetChunkHeightMap(Vector2 ChunkCoord)
        {
            Vector2 sampleCenter = ChunkCoord * meshSettings.meshWorldSize / meshSettings.meshScale;

            return(HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, sampleCenter));
        }