void OnMapDataReceived(MapData mapData) { this.mapData = mapData; mapDataReceived = true; Texture2D texture = TextureGeneration.TextureFromColourMap(mapData.colourMap, MapGenerator.mapChunkSize, MapGenerator.mapChunkSize); meshRenderer.material.mainTexture = texture; UpdateTerrainChunk(); }
public void GenerateTexture() { // Fun fact, Unity does not GC new Terrains, which results in a memory leak, to prevent this we call destroy and have the texture as static Destroy(texture); // The debug terrain is driven by the TerrainGeneration (the main terrain that we are working on) texture = new Texture2D(tg.TerrainInfo.TerrainWidth, tg.TerrainInfo.TerrainHeight); GetComponent <Renderer>().material.mainTexture = texture; if (tg.TerrainInfo.HeightMap == null) { return; } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.SetPixels(TextureGeneration.GenerateHeightmapTexture(tg, planeContent)); texture.Apply(); }
public void GenerateTexture() { // TODO, CHECK THE WIDTH/HEIGHT AND UPDATE TYPE, THIS RAPES 1km * 1km TERRAINS ! FIX BY MAKING IT CALLABLE TROUGH EDITOR // Fun fact, Unity does not GC new Terrains, which results in a memory leak, to prevent this we call destroy and have the texture as static Destroy(texture); // The debug terrain is driven by the TerrainGeneration (the main terrain that we are working on) texture = new Texture2D(tg.TerrainInfo.TerrainWidth, tg.TerrainInfo.TerrainHeight); GetComponent <Renderer>().material.mainTexture = texture; if (tg.TerrainInfo.HeightMap == null) { return; } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.SetPixels(TextureGeneration.GenerateHeightmapTexture(tg, planeContent)); texture.Apply(); }
public void DrawMapInEditor() { MapData mapData = GenerateMapData(Vector2.zero); MapDisplay display = FindObjectOfType <MapDisplay> (); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGeneration.TextureFromHeightMap(mapData.heightMap)); } else if (drawMode == DrawMode.ColourMap) { display.DrawTexture(TextureGeneration.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGeneration.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD, useFlatShading), TextureGeneration.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.FallOffMap) { display.DrawTexture(TextureGeneration.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize))); } }