aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r--OpenSim/Region/Environment/Interfaces/ITerrain.cs5
-rw-r--r--OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs1
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs50
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs29
5 files changed, 80 insertions, 13 deletions
diff --git a/OpenSim/Region/Environment/Interfaces/ITerrain.cs b/OpenSim/Region/Environment/Interfaces/ITerrain.cs
index d3070b2..2cef17e 100644
--- a/OpenSim/Region/Environment/Interfaces/ITerrain.cs
+++ b/OpenSim/Region/Environment/Interfaces/ITerrain.cs
@@ -70,4 +70,9 @@ namespace OpenSim.Region.Environment.Interfaces
70 void ExportImage(string filename, string gradientmap); 70 void ExportImage(string filename, string gradientmap);
71 byte[] ExportJpegImage(string gradientmap); 71 byte[] ExportJpegImage(string gradientmap);
72 } 72 }
73
74 public interface ITerrainTemp
75 {
76 byte[] WriteJpegImage(string gradientmap);
77 }
73} 78}
diff --git a/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
index c8b9c98..0db1294 100644
--- a/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
+++ b/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
@@ -35,5 +35,6 @@ namespace OpenSim.Region.Environment.Interfaces
35 float[] GetFloatsSerialised(); 35 float[] GetFloatsSerialised();
36 double[,] GetDoubles(); 36 double[,] GetDoubles();
37 bool Tainted(int x, int y); 37 bool Tainted(int x, int y);
38 ITerrainChannel MakeCopy();
38 } 39 }
39} 40}
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
56 return copy; 56 return copy;
57 } 57 }
58 58
59 public ITerrainChannel MakeCopy()
60 {
61 TerrainChannel copy = new TerrainChannel(false);
62 copy.map = (double[,])this.map.Clone();
63
64 return copy;
65 }
66
59 public float[] GetFloatsSerialised() 67 public float[] GetFloatsSerialised()
60 { 68 {
61 float[] heights = new float[Width * Height]; 69 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 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing;
30using libsecondlife; 31using libsecondlife;
31using Nini.Config; 32using Nini.Config;
32using OpenSim.Framework; 33using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
35 36
37
36namespace OpenSim.Region.Environment.Modules.Terrain 38namespace OpenSim.Region.Environment.Modules.Terrain
37{ 39{
38 public class TerrainModule : IRegionModule 40 public class TerrainModule : IRegionModule , ITerrainTemp
39 { 41 {
40 public enum StandardTerrainEffects : byte 42 public enum StandardTerrainEffects : byte
41 { 43 {
@@ -139,6 +141,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
139 public void Initialise(Scene scene, IConfigSource config) 141 public void Initialise(Scene scene, IConfigSource config)
140 { 142 {
141 m_scene = scene; 143 m_scene = scene;
144 m_scene.RegisterModuleInterface<ITerrainTemp>(this);
142 m_gConfig = config; 145 m_gConfig = config;
143 146
144 // Install terrain module in the simulator 147 // Install terrain module in the simulator
@@ -312,6 +315,51 @@ namespace OpenSim.Region.Environment.Modules.Terrain
312 } 315 }
313 } 316 }
314 317
318 public byte[] WriteJpegImage(string gradientmap)
319 {
320 byte[] imageData = null;
321 try
322 {
323 Bitmap bmp = TerrainToBitmap(gradientmap);
324
325 imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true);
326
327 }
328 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
329 {
330 Console.WriteLine("Failed generating terrain map: " + e.ToString());
331 }
332
333 return imageData;
334 }
335
336 private Bitmap TerrainToBitmap(string gradientmap)
337 {
338 Bitmap gradientmapLd = new Bitmap(gradientmap);
339
340 int pallete = gradientmapLd.Height;
341
342 Bitmap bmp = new Bitmap(m_channel.Width, m_channel.Height);
343 Color[] colours = new Color[pallete];
344
345 for (int i = 0; i < pallete; i++)
346 {
347 colours[i] = gradientmapLd.GetPixel(0, i);
348 }
349
350 TerrainChannel copy =(TerrainChannel) m_channel.MakeCopy();
351 for (int y = 0; y < copy.Height; y++)
352 {
353 for (int x = 0; x < copy.Width; x++)
354 {
355 // 512 is the largest possible height before colours clamp
356 int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1));
357 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
358 }
359 }
360 return bmp;
361 }
362
315 public void PostInitialise() 363 public void PostInitialise()
316 { 364 {
317 InstallDefaultEffects(); 365 InstallDefaultEffects();
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index b8a4831..c07f718 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -946,6 +946,7 @@ namespace OpenSim.Region.Environment.Scenes
946 { 946 {
947 Heightmap = new Modules.Terrain.TerrainChannel(map); 947 Heightmap = new Modules.Terrain.TerrainChannel(map);
948 } 948 }
949
949 } 950 }
950 catch (Exception e) 951 catch (Exception e)
951 { 952 {
@@ -981,19 +982,23 @@ namespace OpenSim.Region.Environment.Scenes
981 public void CreateTerrainTexture(bool temporary) 982 public void CreateTerrainTexture(bool temporary)
982 { 983 {
983 //TODOADAM: Move this to TerrainModule 984 //TODOADAM: Move this to TerrainModule
984 /* 985
985 //create a texture asset of the terrain 986 //create a texture asset of the terrain
986 byte[] data = Terrain.WriteJpegImage("defaultstripe.png"); 987 ITerrainTemp terrain = RequestModuleInterface<ITerrainTemp>();
987 m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); 988 if (terrain != null)
988 AssetBase asset = new AssetBase(); 989 {
989 asset.FullID = m_regInfo.EstateSettings.terrainImageID; 990 byte[] data = terrain.WriteJpegImage("defaultstripe.png");
990 asset.Data = data; 991 m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();
991 asset.Name = "terrainImage"; 992 AssetBase asset = new AssetBase();
992 asset.Description = RegionInfo.RegionName; 993 asset.FullID = m_regInfo.EstateSettings.terrainImageID;
993 asset.Type = 0; 994 asset.Data = data;
994 asset.Temporary = temporary; 995 asset.Name = "terrainImage";
995 AssetCache.AddAsset(asset); 996 asset.Description = RegionInfo.RegionName;
996 */ 997 asset.Type = 0;
998 asset.Temporary = temporary;
999 AssetCache.AddAsset(asset);
1000 }
1001
997 } 1002 }
998 1003
999 #endregion 1004 #endregion