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

View File

@@ -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<ITerrainTemp>(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();