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.
0.6.0-stable
MW 2008-03-29 17:18:47 +00:00
parent 86128ba4d4
commit 7fcffa3a3a
8 changed files with 90 additions and 15 deletions

View File

@ -506,6 +506,11 @@ namespace OpenSim
m_moduleLoader.InitialiseSharedModules(scene); m_moduleLoader.InitialiseSharedModules(scene);
scene.SetModuleInterfaces(); scene.SetModuleInterfaces();
//moved these here as the terrain texture has to be created after the modules are initialized
// and has to happen before the region is registered with the grid.
scene.CreateTerrainTexture(true);
scene.RegisterRegionWithGrid();
//Server side object editing permissions checking //Server side object editing permissions checking
scene.PermissionsMngr.BypassPermissions = !m_permissions; scene.PermissionsMngr.BypassPermissions = !m_permissions;

View File

@ -124,7 +124,10 @@ namespace OpenSim.Region.ClientStack
udpServer.LocalScene = scene; udpServer.LocalScene = scene;
scene.LoadWorldMap(); scene.LoadWorldMap();
scene.RegisterRegionWithGrid();
//moved to opensimMain as these have to happen after modules are initialised
// scene.CreateTerrainTexture(true);
// scene.RegisterRegionWithGrid();
scene.PhysicsScene = GetPhysicsScene(); scene.PhysicsScene = GetPhysicsScene();
scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised()); scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());

View File

@ -70,4 +70,9 @@ namespace OpenSim.Region.Environment.Interfaces
void ExportImage(string filename, string gradientmap); void ExportImage(string filename, string gradientmap);
byte[] ExportJpegImage(string gradientmap); byte[] ExportJpegImage(string gradientmap);
} }
public interface ITerrainTemp
{
byte[] WriteJpegImage(string gradientmap);
}
} }

View File

@ -35,5 +35,6 @@ namespace OpenSim.Region.Environment.Interfaces
float[] GetFloatsSerialised(); float[] GetFloatsSerialised();
double[,] GetDoubles(); double[,] GetDoubles();
bool Tainted(int x, int y); bool Tainted(int x, int y);
ITerrainChannel MakeCopy();
} }
} }

View File

@ -56,6 +56,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain
return copy; return copy;
} }
public ITerrainChannel MakeCopy()
{
TerrainChannel copy = new TerrainChannel(false);
copy.map = (double[,])this.map.Clone();
return copy;
}
public float[] GetFloatsSerialised() public float[] GetFloatsSerialised()
{ {
float[] heights = new float[Width * Height]; float[] heights = new float[Width * Height];

View File

@ -27,15 +27,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using libsecondlife; using libsecondlife;
using Nini.Config; using Nini.Config;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment.Modules.Terrain namespace OpenSim.Region.Environment.Modules.Terrain
{ {
public class TerrainModule : IRegionModule public class TerrainModule : IRegionModule , ITerrainTemp
{ {
public enum StandardTerrainEffects : byte public enum StandardTerrainEffects : byte
{ {
@ -139,6 +141,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
public void Initialise(Scene scene, IConfigSource config) public void Initialise(Scene scene, IConfigSource config)
{ {
m_scene = scene; m_scene = scene;
m_scene.RegisterModuleInterface<ITerrainTemp>(this);
m_gConfig = config; m_gConfig = config;
// Install terrain module in the simulator // 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() public void PostInitialise()
{ {
InstallDefaultEffects(); InstallDefaultEffects();

View File

@ -946,6 +946,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
Heightmap = new Modules.Terrain.TerrainChannel(map); Heightmap = new Modules.Terrain.TerrainChannel(map);
} }
} }
catch (Exception e) catch (Exception e)
{ {
@ -981,19 +982,23 @@ namespace OpenSim.Region.Environment.Scenes
public void CreateTerrainTexture(bool temporary) public void CreateTerrainTexture(bool temporary)
{ {
//TODOADAM: Move this to TerrainModule //TODOADAM: Move this to TerrainModule
/*
//create a texture asset of the terrain //create a texture asset of the terrain
byte[] data = Terrain.WriteJpegImage("defaultstripe.png"); ITerrainTemp terrain = RequestModuleInterface<ITerrainTemp>();
m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); if (terrain != null)
AssetBase asset = new AssetBase(); {
asset.FullID = m_regInfo.EstateSettings.terrainImageID; byte[] data = terrain.WriteJpegImage("defaultstripe.png");
asset.Data = data; m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();
asset.Name = "terrainImage"; AssetBase asset = new AssetBase();
asset.Description = RegionInfo.RegionName; asset.FullID = m_regInfo.EstateSettings.terrainImageID;
asset.Type = 0; asset.Data = data;
asset.Temporary = temporary; asset.Name = "terrainImage";
AssetCache.AddAsset(asset); asset.Description = RegionInfo.RegionName;
*/ asset.Type = 0;
asset.Temporary = temporary;
AssetCache.AddAsset(asset);
}
} }
#endregion #endregion