From 7fcffa3a3a231a77d00bf2ec1772f0914073d28f Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 29 Mar 2008 17:18:47 +0000 Subject: Re-enabled terrain texture generation for the world map. Adam can clean up/ sort it out when he gets time. Most likely doesn't really work in grid mode as the generated textures are marked as temporary and I don't think they are updated to the asset server. We have to either live with these textures being sent to the asset server, and manually clean them out from time to time or wait until there is some asset management system in place. Also currently the texture is only generated at region startup, it is not updated after terraforming. --- .../Environment/Modules/Terrain/TerrainChannel.cs | 8 ++++ .../Environment/Modules/Terrain/TerrainModule.cs | 50 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Environment/Modules') diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs index 4ab7782..74af2c1 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs @@ -56,6 +56,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain return copy; } + public ITerrainChannel MakeCopy() + { + TerrainChannel copy = new TerrainChannel(false); + copy.map = (double[,])this.map.Clone(); + + return copy; + } + public float[] GetFloatsSerialised() { float[] heights = new float[Width * Height]; diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs index cdcc648..742ea5b 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs @@ -27,15 +27,17 @@ using System; using System.Collections.Generic; +using System.Drawing; using libsecondlife; using Nini.Config; using OpenSim.Framework; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; + namespace OpenSim.Region.Environment.Modules.Terrain { - public class TerrainModule : IRegionModule + public class TerrainModule : IRegionModule , ITerrainTemp { public enum StandardTerrainEffects : byte { @@ -139,6 +141,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain public void Initialise(Scene scene, IConfigSource config) { m_scene = scene; + m_scene.RegisterModuleInterface(this); m_gConfig = config; // Install terrain module in the simulator @@ -312,6 +315,51 @@ namespace OpenSim.Region.Environment.Modules.Terrain } } + public byte[] WriteJpegImage(string gradientmap) + { + byte[] imageData = null; + try + { + Bitmap bmp = TerrainToBitmap(gradientmap); + + imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); + + } + catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke + { + Console.WriteLine("Failed generating terrain map: " + e.ToString()); + } + + return imageData; + } + + private Bitmap TerrainToBitmap(string gradientmap) + { + Bitmap gradientmapLd = new Bitmap(gradientmap); + + int pallete = gradientmapLd.Height; + + Bitmap bmp = new Bitmap(m_channel.Width, m_channel.Height); + Color[] colours = new Color[pallete]; + + for (int i = 0; i < pallete; i++) + { + colours[i] = gradientmapLd.GetPixel(0, i); + } + + TerrainChannel copy =(TerrainChannel) m_channel.MakeCopy(); + for (int y = 0; y < copy.Height; y++) + { + for (int x = 0; x < copy.Width; x++) + { + // 512 is the largest possible height before colours clamp + int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); + bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); + } + } + return bmp; + } + public void PostInitialise() { InstallDefaultEffects(); -- cgit v1.1