aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.Terrain.BasicTerrain/TerrainEngine.cs')
-rw-r--r--OpenSim.Terrain.BasicTerrain/TerrainEngine.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
index 38a4989..e766f71 100644
--- a/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
@@ -1,6 +1,7 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.Drawing;
4using libTerrain; 5using libTerrain;
5 6
6namespace OpenSim.Terrain 7namespace OpenSim.Terrain
@@ -403,5 +404,45 @@ namespace OpenSim.Terrain
403 heightmap.set(x,y,(double)value); 404 heightmap.set(x,y,(double)value);
404 } 405 }
405 } 406 }
407
408 /// <summary>
409 /// Exports the current heightmap to a PNG file
410 /// </summary>
411 /// <param name="filename">The destination filename for the image</param>
412 /// <param name="gradientmap">A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal.</param>
413 public void exportImage(string filename, string gradientmap)
414 {
415 try
416 {
417 Bitmap gradientmapLd = new Bitmap(gradientmap);
418
419 int pallete = gradientmapLd.Width;
420
421 Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
422 Color[] colours = new Color[pallete];
423
424 for (int i = 0; i < pallete; i++)
425 {
426 colours[i] = gradientmapLd.GetPixel(1, i);
427 }
428
429 Channel copy = heightmap.copy();
430 for (int x = 0; x < copy.w; x++)
431 {
432 for (int y = 0; y < copy.h; y++)
433 {
434 // 512 is the largest possible height before colours clamp
435 int colorindex = (int)(Math.Max(Math.Min(1.0, copy.get(x, y) / 512.0), 0.0) * pallete);
436 bmp.SetPixel(x, y, colours[colorindex]);
437 }
438 }
439
440 bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
441 }
442 catch (Exception e)
443 {
444 Console.WriteLine("Failed generating terrain map: " + e.ToString());
445 }
446 }
406 } 447 }
407} 448}