aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorAdam Frisby2008-04-15 03:07:31 +0000
committerAdam Frisby2008-04-15 03:07:31 +0000
commit0b4a8191a1d69294fa95381bfe7f2fa2aa400cfb (patch)
tree78e5c2ced40f3a941c5b9a0e7f3bf33809d9dc81 /OpenSim/Region
parent* Working towards notifying the client if the inventory service has failed, r... (diff)
downloadopensim-SC_OLD-0b4a8191a1d69294fa95381bfe7f2fa2aa400cfb.zip
opensim-SC_OLD-0b4a8191a1d69294fa95381bfe7f2fa2aa400cfb.tar.gz
opensim-SC_OLD-0b4a8191a1d69294fa95381bfe7f2fa2aa400cfb.tar.bz2
opensim-SC_OLD-0b4a8191a1d69294fa95381bfe7f2fa2aa400cfb.tar.xz
* Quick patch before I start on a bigger project
* Renamed ITerrainTemp to IMapImageGenerator * Renamed WriteJpegImage to WriteJpeg2000Image to better reflect it's function.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Environment/Interfaces/ITerrain.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs19
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs93
3 files changed, 61 insertions, 55 deletions
diff --git a/OpenSim/Region/Environment/Interfaces/ITerrain.cs b/OpenSim/Region/Environment/Interfaces/ITerrain.cs
index 2cef17e..d5e1540 100644
--- a/OpenSim/Region/Environment/Interfaces/ITerrain.cs
+++ b/OpenSim/Region/Environment/Interfaces/ITerrain.cs
@@ -71,8 +71,8 @@ namespace OpenSim.Region.Environment.Interfaces
71 byte[] ExportJpegImage(string gradientmap); 71 byte[] ExportJpegImage(string gradientmap);
72 } 72 }
73 73
74 public interface ITerrainTemp 74 public interface IMapImageGenerator
75 { 75 {
76 byte[] WriteJpegImage(string gradientmap); 76 byte[] WriteJpeg2000Image(string gradientmap);
77 } 77 }
78} 78}
diff --git a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
index c791ac3..458d781 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
@@ -10,7 +10,7 @@ using OpenSim.Region.Environment.Modules.ModuleFramework;
10 10
11namespace OpenSim.Region.Environment.Modules.Terrain 11namespace OpenSim.Region.Environment.Modules.Terrain
12{ 12{
13 class MapImageModule : ITerrainTemp, IRegionModule 13 class MapImageModule : IMapImageGenerator, IRegionModule
14 { 14 {
15 private Scene m_scene; 15 private Scene m_scene;
16 #region IRegionModule Members 16 #region IRegionModule Members
@@ -18,7 +18,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
18 public void Initialise(Scene scene, IConfigSource source) 18 public void Initialise(Scene scene, IConfigSource source)
19 { 19 {
20 m_scene = scene; 20 m_scene = scene;
21 m_scene.RegisterModuleInterface<ITerrainTemp>(this); 21 m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
22 } 22 }
23 23
24 public void PostInitialise() 24 public void PostInitialise()
@@ -40,15 +40,15 @@ namespace OpenSim.Region.Environment.Modules.Terrain
40 } 40 }
41 41
42 42
43 public byte[] WriteJpegImage(string gradientmap) 43 public byte[] WriteJpeg2000Image(string gradientmap)
44 { 44 {
45 byte[] imageData = null; 45 byte[] imageData = null;
46
47 Bitmap bmp = TerrainToBitmap(gradientmap);
48
46 try 49 try
47 { 50 {
48 Bitmap bmp = TerrainToBitmap(gradientmap);
49
50 imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); 51 imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true);
51
52 } 52 }
53 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke 53 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
54 { 54 {
@@ -122,7 +122,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain
122 { 122 {
123 // 512 is the largest possible height before colours clamp 123 // 512 is the largest possible height before colours clamp
124 int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); 124 int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1));
125 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); 125
126 // Handle error conditions
127 if (colorindex > pallete - 1 || colorindex < 0)
128 bmp.SetPixel(x, copy.Height - y - 1, Color.Red);
129 else
130 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
126 } 131 }
127 } 132 }
128 ShadeBuildings(ref bmp); 133 ShadeBuildings(ref bmp);
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index b93367c..ba8a356 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -984,19 +984,21 @@ namespace OpenSim.Region.Environment.Scenes
984 /// </summary> 984 /// </summary>
985 public void CreateTerrainTexture(bool temporary) 985 public void CreateTerrainTexture(bool temporary)
986 { 986 {
987 //TODOADAM: Move this to TerrainModule
988
989 //create a texture asset of the terrain 987 //create a texture asset of the terrain
990 ITerrainTemp terrain = RequestModuleInterface<ITerrainTemp>(); 988 IMapImageGenerator terrain = RequestModuleInterface<IMapImageGenerator>();
991 989
992 if (Heightmap != null) 990 // Cannot create a map for a nonexistant heightmap yet.
991 if (Heightmap == null)
992 return;
993
994 if (terrain == null)
993 { 995 {
994 Bitmap mapbmp = new Bitmap(256, 256); 996 Bitmap mapbmp = new Bitmap(256, 256);
995 double[,] hm = Heightmap.GetDoubles(); 997 double[,] hm = Heightmap.GetDoubles();
996 998
997 float heightvalue = 0; 999 float heightvalue = 0;
998 1000
999 1001
1000 Color prim = Color.FromArgb(120, 120, 120); 1002 Color prim = Color.FromArgb(120, 120, 120);
1001 LLVector3 RayEnd = new LLVector3(0, 0, 0); 1003 LLVector3 RayEnd = new LLVector3(0, 0, 0);
1002 LLVector3 RayStart = new LLVector3(0, 0, 0); 1004 LLVector3 RayStart = new LLVector3(0, 0, 0);
@@ -1038,50 +1040,50 @@ namespace OpenSim.Region.Environment.Scenes
1038 1040
1039 //if (rt.HitTF) 1041 //if (rt.HitTF)
1040 //{ 1042 //{
1041 //mapbmp.SetPixel(x, y, prim); 1043 //mapbmp.SetPixel(x, y, prim);
1042 //} 1044 //}
1043 //else 1045 //else
1044 //{ 1046 //{
1045 float tmpval = (float)hm[x, y]; 1047 float tmpval = (float)hm[x, y];
1046 heightvalue = (float)hm[x, y]; 1048 heightvalue = (float)hm[x, y];
1047 1049
1048 if ((float)heightvalue > m_regInfo.EstateSettings.waterHeight) 1050 if ((float)heightvalue > m_regInfo.EstateSettings.waterHeight)
1049 { 1051 {
1050 // scale height value 1052 // scale height value
1051 heightvalue = low + mid * (heightvalue - low) / mid; 1053 heightvalue = low + mid * (heightvalue - low) / mid;
1052
1053 if (heightvalue > 255)
1054 heightvalue = 255;
1055
1056 if (heightvalue < 0)
1057 heightvalue = 0;
1058
1059
1060 Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue);
1061
1062 // Y flip the cordinates
1063 mapbmp.SetPixel(x, (256 - y) - 1, green);
1064 }
1065 else
1066 {
1067 // Y flip the cordinates
1068 heightvalue = m_regInfo.EstateSettings.waterHeight - heightvalue;
1069 if (heightvalue > 19)
1070 heightvalue = 19;
1071 if (heightvalue < 0)
1072 heightvalue = 0;
1073 1054
1074 heightvalue = 100 - (heightvalue * 100) / 19; 1055 if (heightvalue > 255)
1056 heightvalue = 255;
1075 1057
1076 if (heightvalue > 255) 1058 if (heightvalue < 0)
1077 heightvalue = 255; 1059 heightvalue = 0;
1078 1060
1079 if (heightvalue < 0)
1080 heightvalue = 0;
1081 1061
1082 Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255); 1062 Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue);
1083 mapbmp.SetPixel(x, (256 - y) - 1, water); 1063
1084 } 1064 // Y flip the cordinates
1065 mapbmp.SetPixel(x, (256 - y) - 1, green);
1066 }
1067 else
1068 {
1069 // Y flip the cordinates
1070 heightvalue = m_regInfo.EstateSettings.waterHeight - heightvalue;
1071 if (heightvalue > 19)
1072 heightvalue = 19;
1073 if (heightvalue < 0)
1074 heightvalue = 0;
1075
1076 heightvalue = 100 - (heightvalue * 100) / 19;
1077
1078 if (heightvalue > 255)
1079 heightvalue = 255;
1080
1081 if (heightvalue < 0)
1082 heightvalue = 0;
1083
1084 Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255);
1085 mapbmp.SetPixel(x, (256 - y) - 1, water);
1086 }
1085 //} 1087 //}
1086 1088
1087 1089
@@ -1098,7 +1100,7 @@ namespace OpenSim.Region.Environment.Scenes
1098 { 1100 {
1099 return; 1101 return;
1100 } 1102 }
1101 1103
1102 m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); 1104 m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();
1103 AssetBase asset = new AssetBase(); 1105 AssetBase asset = new AssetBase();
1104 asset.FullID = m_regInfo.EstateSettings.terrainImageID; 1106 asset.FullID = m_regInfo.EstateSettings.terrainImageID;
@@ -1108,12 +1110,11 @@ namespace OpenSim.Region.Environment.Scenes
1108 asset.Type = 0; 1110 asset.Type = 0;
1109 asset.Temporary = temporary; 1111 asset.Temporary = temporary;
1110 AssetCache.AddAsset(asset); 1112 AssetCache.AddAsset(asset);
1111
1112 }
1113 1113
1114 if (terrain != null) 1114 }
1115 else
1115 { 1116 {
1116 byte[] data = terrain.WriteJpegImage("defaultstripe.png"); 1117 byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png");
1117 if (data != null) 1118 if (data != null)
1118 { 1119 {
1119 m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); 1120 m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();