public void DrawMapInEditor() { Map map = GenerateMap(Vector2.zero); var texture = new Texture2D(map.heightMap.Width, map.heightMap.Height); texture.SetPixels(map.colorMap); texture.wrapMode = TextureWrapMode.Clamp; texture.filterMode = FilterMode.Point; // makes changes between regions more rough texture.Apply(); // Draw as texture textureRenderer.material.mainTexture = texture; textureRenderer.transform.localScale = new Vector3(mapSize.x, 1, mapSize.y); // Draw as mesh MeshBuilder meshBuilder = TerrainMeshGenerator.GenerateFlatTerrainMesh(map.heightMap, levelOfDetail); meshFilter.sharedMesh = meshBuilder.Build(); meshRenderer.sharedMaterial.mainTexture = texture; //meshRenderer.material.mainTexture = texture; }
private async Task <LodMesh> createMesh(MapGenerator generator, int levelOfDetail) { (Map, MeshBuilder)result = await Task.Run(() => { Map map = generator.GenerateMap(coord); MeshBuilder builder = TerrainMeshGenerator.GenerateFlatTerrainMesh(map.heightMap, levelOfDetail); return(map, builder); }); var texture = new Texture2D(result.Item1.heightMap.Width, result.Item1.heightMap.Height); texture.SetPixels(result.Item1.colorMap); texture.wrapMode = TextureWrapMode.Clamp; texture.filterMode = FilterMode.Point; // makes changes between regions more rough texture.Apply(); LodMesh mesh = new LodMesh(levelOfDetail); mesh.Load(result.Item2.Build(), texture); return(mesh); }