diff options
author | MW | 2008-03-29 17:18:47 +0000 |
---|---|---|
committer | MW | 2008-03-29 17:18:47 +0000 |
commit | 7fcffa3a3a231a77d00bf2ec1772f0914073d28f (patch) | |
tree | b5fa20f2a997edff3150f6643b7a123751e614f4 | |
parent | Fix compiler warnings in BulletXPlugin. (diff) | |
download | opensim-SC-7fcffa3a3a231a77d00bf2ec1772f0914073d28f.zip opensim-SC-7fcffa3a3a231a77d00bf2ec1772f0914073d28f.tar.gz opensim-SC-7fcffa3a3a231a77d00bf2ec1772f0914073d28f.tar.bz2 opensim-SC-7fcffa3a3a231a77d00bf2ec1772f0914073d28f.tar.xz |
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.
8 files changed, 90 insertions, 15 deletions
diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs index d105069..6e909da 100644 --- a/OpenSim/Framework/Communications/InventoryServiceBase.cs +++ b/OpenSim/Framework/Communications/InventoryServiceBase.cs | |||
@@ -260,7 +260,7 @@ namespace OpenSim.Framework.Communications | |||
260 | { | 260 | { |
261 | AddFolder(folder); | 261 | AddFolder(folder); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | private class UsersInventory | 265 | private class UsersInventory |
266 | { | 266 | { |
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index afaf988..e77aa6b 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs | |||
@@ -506,6 +506,11 @@ namespace OpenSim | |||
506 | m_moduleLoader.InitialiseSharedModules(scene); | 506 | m_moduleLoader.InitialiseSharedModules(scene); |
507 | scene.SetModuleInterfaces(); | 507 | scene.SetModuleInterfaces(); |
508 | 508 | ||
509 | //moved these here as the terrain texture has to be created after the modules are initialized | ||
510 | // and has to happen before the region is registered with the grid. | ||
511 | scene.CreateTerrainTexture(true); | ||
512 | scene.RegisterRegionWithGrid(); | ||
513 | |||
509 | //Server side object editing permissions checking | 514 | //Server side object editing permissions checking |
510 | scene.PermissionsMngr.BypassPermissions = !m_permissions; | 515 | scene.PermissionsMngr.BypassPermissions = !m_permissions; |
511 | 516 | ||
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index ed29e8e..4dd58f2 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs | |||
@@ -124,7 +124,10 @@ namespace OpenSim.Region.ClientStack | |||
124 | udpServer.LocalScene = scene; | 124 | udpServer.LocalScene = scene; |
125 | 125 | ||
126 | scene.LoadWorldMap(); | 126 | scene.LoadWorldMap(); |
127 | scene.RegisterRegionWithGrid(); | 127 | |
128 | //moved to opensimMain as these have to happen after modules are initialised | ||
129 | // scene.CreateTerrainTexture(true); | ||
130 | // scene.RegisterRegionWithGrid(); | ||
128 | 131 | ||
129 | scene.PhysicsScene = GetPhysicsScene(); | 132 | scene.PhysicsScene = GetPhysicsScene(); |
130 | scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); | 133 | scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); |
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 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Drawing; | ||
30 | using libsecondlife; | 31 | using libsecondlife; |
31 | using Nini.Config; | 32 | using Nini.Config; |
32 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
33 | using OpenSim.Region.Environment.Interfaces; | 34 | using OpenSim.Region.Environment.Interfaces; |
34 | using OpenSim.Region.Environment.Scenes; | 35 | using OpenSim.Region.Environment.Scenes; |
35 | 36 | ||
37 | |||
36 | namespace OpenSim.Region.Environment.Modules.Terrain | 38 | namespace 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 |