From 497af009bd1aa59385b2aca86987b619f8647616 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Thu, 24 May 2007 05:44:53 +0000
Subject: * Reduced effect of terraforming brushes by 1000%. * Added new
exportImage() function to BasicTerrain which will output a gradient-mapped
image of the terrain which can be uploaded to the grid for things like world
map images. (shiinnny), will update later with an improved version using the
bilinear quad method employed in client terrain rendering. * Rebuild project
& build files for basicterrain with System.Drawing dependency. Prebuild
updated.
---
.../OpenSim.Terrain.BasicTerrain.csproj | 4 +++
.../OpenSim.Terrain.BasicTerrain.dll.build | 1 +
OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 41 ++++++++++++++++++++++
3 files changed, 46 insertions(+)
(limited to 'OpenSim.Terrain.BasicTerrain')
diff --git a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
index 1cdfaf6..5a73897 100644
--- a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
+++ b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.csproj
@@ -66,6 +66,10 @@
System.dll
False
+
+ System.Drawing.dll
+ False
+
System.Data.dll
False
diff --git a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.dll.build b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.dll.build
index d2e6c9f..86c6a5c 100644
--- a/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.dll.build
+++ b/OpenSim.Terrain.BasicTerrain/OpenSim.Terrain.BasicTerrain.dll.build
@@ -21,6 +21,7 @@
+
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 @@
using System;
using System.Collections.Generic;
using System.Text;
+using System.Drawing;
using libTerrain;
namespace OpenSim.Terrain
@@ -403,5 +404,45 @@ namespace OpenSim.Terrain
heightmap.set(x,y,(double)value);
}
}
+
+ ///
+ /// Exports the current heightmap to a PNG file
+ ///
+ /// The destination filename for the image
+ /// A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal.
+ public void exportImage(string filename, string gradientmap)
+ {
+ try
+ {
+ Bitmap gradientmapLd = new Bitmap(gradientmap);
+
+ int pallete = gradientmapLd.Width;
+
+ Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
+ Color[] colours = new Color[pallete];
+
+ for (int i = 0; i < pallete; i++)
+ {
+ colours[i] = gradientmapLd.GetPixel(1, i);
+ }
+
+ Channel copy = heightmap.copy();
+ for (int x = 0; x < copy.w; x++)
+ {
+ for (int y = 0; y < copy.h; y++)
+ {
+ // 512 is the largest possible height before colours clamp
+ int colorindex = (int)(Math.Max(Math.Min(1.0, copy.get(x, y) / 512.0), 0.0) * pallete);
+ bmp.SetPixel(x, y, colours[colorindex]);
+ }
+ }
+
+ bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Failed generating terrain map: " + e.ToString());
+ }
+ }
}
}
--
cgit v1.1