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
parent
86128ba4d4
commit
7fcffa3a3a
|
@ -506,6 +506,11 @@ namespace OpenSim
|
|||
m_moduleLoader.InitialiseSharedModules(scene);
|
||||
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
|
||||
scene.PermissionsMngr.BypassPermissions = !m_permissions;
|
||||
|
||||
|
|
|
@ -124,7 +124,10 @@ namespace OpenSim.Region.ClientStack
|
|||
udpServer.LocalScene = scene;
|
||||
|
||||
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.SetTerrain(scene.Heightmap.GetFloatsSerialised());
|
||||
|
|
|
@ -70,4 +70,9 @@ namespace OpenSim.Region.Environment.Interfaces
|
|||
void ExportImage(string filename, string gradientmap);
|
||||
byte[] ExportJpegImage(string gradientmap);
|
||||
}
|
||||
|
||||
public interface ITerrainTemp
|
||||
{
|
||||
byte[] WriteJpegImage(string gradientmap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,5 +35,6 @@ namespace OpenSim.Region.Environment.Interfaces
|
|||
float[] GetFloatsSerialised();
|
||||
double[,] GetDoubles();
|
||||
bool Tainted(int x, int y);
|
||||
ITerrainChannel MakeCopy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain
|
|||
return copy;
|
||||
}
|
||||
|
||||
public ITerrainChannel MakeCopy()
|
||||
{
|
||||
TerrainChannel copy = new TerrainChannel(false);
|
||||
copy.map = (double[,])this.map.Clone();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
public float[] GetFloatsSerialised()
|
||||
{
|
||||
float[] heights = new float[Width * Height];
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -946,6 +946,7 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
{
|
||||
Heightmap = new Modules.Terrain.TerrainChannel(map);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -981,19 +982,23 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
public void CreateTerrainTexture(bool temporary)
|
||||
{
|
||||
//TODOADAM: Move this to TerrainModule
|
||||
/*
|
||||
|
||||
//create a texture asset of the terrain
|
||||
byte[] data = Terrain.WriteJpegImage("defaultstripe.png");
|
||||
m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = m_regInfo.EstateSettings.terrainImageID;
|
||||
asset.Data = data;
|
||||
asset.Name = "terrainImage";
|
||||
asset.Description = RegionInfo.RegionName;
|
||||
asset.Type = 0;
|
||||
asset.Temporary = temporary;
|
||||
AssetCache.AddAsset(asset);
|
||||
*/
|
||||
ITerrainTemp terrain = RequestModuleInterface<ITerrainTemp>();
|
||||
if (terrain != null)
|
||||
{
|
||||
byte[] data = terrain.WriteJpegImage("defaultstripe.png");
|
||||
m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = m_regInfo.EstateSettings.terrainImageID;
|
||||
asset.Data = data;
|
||||
asset.Name = "terrainImage";
|
||||
asset.Description = RegionInfo.RegionName;
|
||||
asset.Type = 0;
|
||||
asset.Temporary = temporary;
|
||||
AssetCache.AddAsset(asset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in New Issue