From ab4be3ffdfd8f68e5650077eeb75d155a0223f53 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 3 Oct 2010 16:34:17 +0100 Subject: Initial port of the Warp3D map tile renderer --- .../Resources/CoreModulePlugin.addin.xml | 1 + .../World/WorldMap/IMapTileTerrainRenderer.cs | 39 -- .../CoreModules/World/WorldMap/MapImageModule.cs | 588 --------------------- .../World/WorldMap/ShadedMapTileRenderer.cs | 244 --------- .../World/WorldMap/TexturedMapTileRenderer.cs | 418 --------------- .../CoreModules/World/WorldMap/WorldMapModule.cs | 2 +- OpenSim/Region/Framework/Interfaces/ITerrain.cs | 4 +- .../SimianGrid/SimianGridServiceConnector.cs | 2 +- prebuild.xml | 3 + 9 files changed, 8 insertions(+), 1293 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/World/WorldMap/IMapTileTerrainRenderer.cs delete mode 100644 OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs delete mode 100644 OpenSim/Region/CoreModules/World/WorldMap/ShadedMapTileRenderer.cs delete mode 100644 OpenSim/Region/CoreModules/World/WorldMap/TexturedMapTileRenderer.cs diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml index ee07075..e85e4e9 100644 --- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml +++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml @@ -18,6 +18,7 @@ + diff --git a/OpenSim/Region/CoreModules/World/WorldMap/IMapTileTerrainRenderer.cs b/OpenSim/Region/CoreModules/World/WorldMap/IMapTileTerrainRenderer.cs deleted file mode 100644 index de9bb1d..0000000 --- a/OpenSim/Region/CoreModules/World/WorldMap/IMapTileTerrainRenderer.cs +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System.Drawing; -using Nini.Config; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.CoreModules.World.WorldMap -{ - public interface IMapTileTerrainRenderer - { - void Initialise(Scene scene, IConfigSource config); - void TerrainToBitmap(Bitmap mapbmp); - } -} diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs deleted file mode 100644 index c83ac85..0000000 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs +++ /dev/null @@ -1,588 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Reflection; -using log4net; -using Nini.Config; -using OpenMetaverse; -using OpenMetaverse.Imaging; -using OpenSim.Framework; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.CoreModules.World.WorldMap -{ - public enum DrawRoutine - { - Rectangle, - Polygon, - Ellipse - } - - public struct face - { - public Point[] pts; - } - - public struct DrawStruct - { - public DrawRoutine dr; - public Rectangle rect; - public SolidBrush brush; - public face[] trns; - } - - public class MapImageModule : IMapImageGenerator, IRegionModule - { - private static readonly ILog m_log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Scene m_scene; - private IConfigSource m_config; - private IMapTileTerrainRenderer terrainRenderer; - - #region IMapImageGenerator Members - - public Bitmap CreateMapTile(string gradientmap) - { - bool drawPrimVolume = true; - bool textureTerrain = false; - - try - { - IConfig startupConfig = m_config.Configs["Startup"]; - drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume); - textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain); - } - catch - { - m_log.Warn("[MAPTILE]: Failed to load StartupConfig"); - } - - if (textureTerrain) - { - terrainRenderer = new TexturedMapTileRenderer(); - } - else - { - terrainRenderer = new ShadedMapTileRenderer(); - } - terrainRenderer.Initialise(m_scene, m_config); - - Bitmap mapbmp = new Bitmap((int)Constants.RegionSize, (int)Constants.RegionSize, System.Drawing.Imaging.PixelFormat.Format24bppRgb); - //long t = System.Environment.TickCount; - //for (int i = 0; i < 10; ++i) { - terrainRenderer.TerrainToBitmap(mapbmp); - //} - //t = System.Environment.TickCount - t; - //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t); - - - if (drawPrimVolume) - { - DrawObjectVolume(m_scene, mapbmp); - } - - return mapbmp; - } - - public byte[] WriteJpeg2000Image(string gradientmap) - { - try - { - using (Bitmap mapbmp = CreateMapTile(gradientmap)) - return OpenJPEG.EncodeFromImage(mapbmp, true); - } - catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke - { - m_log.Error("Failed generating terrain map: " + e); - } - - return null; - } - - #endregion - - #region IRegionModule Members - - public void Initialise(Scene scene, IConfigSource source) - { - m_scene = scene; - m_config = source; - - IConfig startupConfig = m_config.Configs["Startup"]; - if (startupConfig.GetString("MapImageModule", "MapImageModule") != - "MapImageModule") - return; - - m_scene.RegisterModuleInterface(this); - } - - public void PostInitialise() - { - } - - public void Close() - { - } - - public string Name - { - get { return "MapImageModule"; } - } - - public bool IsSharedModule - { - get { return false; } - } - - #endregion - -// TODO: unused: -// private void ShadeBuildings(Bitmap map) -// { -// lock (map) -// { -// lock (m_scene.Entities) -// { -// foreach (EntityBase entity in m_scene.Entities.Values) -// { -// if (entity is SceneObjectGroup) -// { -// SceneObjectGroup sog = (SceneObjectGroup) entity; -// -// foreach (SceneObjectPart primitive in sog.Children.Values) -// { -// int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); -// int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); -// int w = (int) primitive.Scale.X; -// int h = (int) primitive.Scale.Y; -// -// int dx; -// for (dx = x; dx < x + w; dx++) -// { -// int dy; -// for (dy = y; dy < y + h; dy++) -// { -// if (x < 0 || y < 0) -// continue; -// if (x >= map.Width || y >= map.Height) -// continue; -// -// map.SetPixel(dx, dy, Color.DarkGray); -// } -// } -// } -// } -// } -// } -// } -// } - - private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp) - { - int tc = 0; - double[,] hm = whichScene.Heightmap.GetDoubles(); - tc = Environment.TickCount; - m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); - EntityBase[] objs = whichScene.GetEntities(); - Dictionary z_sort = new Dictionary(); - //SortedList z_sort = new SortedList(); - List z_sortheights = new List(); - List z_localIDs = new List(); - - lock (objs) - { - foreach (EntityBase obj in objs) - { - // Only draw the contents of SceneObjectGroup - if (obj is SceneObjectGroup) - { - SceneObjectGroup mapdot = (SceneObjectGroup)obj; - Color mapdotspot = Color.Gray; // Default color when prim color is white - - // Loop over prim in group - foreach (SceneObjectPart part in mapdot.Parts) - { - if (part == null) - continue; - - // Draw if the object is at least 1 meter wide in any direction - if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) - { - // Try to get the RGBA of the default texture entry.. - // - try - { - // get the null checks out of the way - // skip the ones that break - if (part == null) - continue; - - if (part.Shape == null) - continue; - - if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass) - continue; // eliminates trees from this since we don't really have a good tree representation - // if you want tree blocks on the map comment the above line and uncomment the below line - //mapdotspot = Color.PaleGreen; - - Primitive.TextureEntry textureEntry = part.Shape.Textures; - - if (textureEntry == null || textureEntry.DefaultTexture == null) - continue; - - Color4 texcolor = textureEntry.DefaultTexture.RGBA; - - // Not sure why some of these are null, oh well. - - int colorr = 255 - (int)(texcolor.R * 255f); - int colorg = 255 - (int)(texcolor.G * 255f); - int colorb = 255 - (int)(texcolor.B * 255f); - - if (!(colorr == 255 && colorg == 255 && colorb == 255)) - { - //Try to set the map spot color - try - { - // If the color gets goofy somehow, skip it *shakes fist at Color4 - mapdotspot = Color.FromArgb(colorr, colorg, colorb); - } - catch (ArgumentException) - { - } - } - } - catch (IndexOutOfRangeException) - { - // Windows Array - } - catch (ArgumentOutOfRangeException) - { - // Mono Array - } - - Vector3 pos = part.GetWorldPosition(); - - // skip prim outside of retion - if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f) - continue; - - // skip prim in non-finite position - if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) || - Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y)) - continue; - - // Figure out if object is under 256m above the height of the terrain - bool isBelow256AboveTerrain = false; - - try - { - isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f)); - } - catch (Exception) - { - } - - if (isBelow256AboveTerrain) - { - // Translate scale by rotation so scale is represented properly when object is rotated - Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); - Vector3 scale = new Vector3(); - Vector3 tScale = new Vector3(); - Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z); - - Quaternion llrot = part.GetWorldRotation(); - Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); - scale = lscale * rot; - - // negative scales don't work in this situation - scale.X = Math.Abs(scale.X); - scale.Y = Math.Abs(scale.Y); - scale.Z = Math.Abs(scale.Z); - - // This scaling isn't very accurate and doesn't take into account the face rotation :P - int mapdrawstartX = (int)(pos.X - scale.X); - int mapdrawstartY = (int)(pos.Y - scale.Y); - int mapdrawendX = (int)(pos.X + scale.X); - int mapdrawendY = (int)(pos.Y + scale.Y); - - // If object is beyond the edge of the map, don't draw it to avoid errors - if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1) - || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0 - || mapdrawendY > ((int)Constants.RegionSize - 1)) - continue; - -#region obb face reconstruction part duex - Vector3[] vertexes = new Vector3[8]; - - // float[] distance = new float[6]; - Vector3[] FaceA = new Vector3[6]; // vertex A for Facei - Vector3[] FaceB = new Vector3[6]; // vertex B for Facei - Vector3[] FaceC = new Vector3[6]; // vertex C for Facei - Vector3[] FaceD = new Vector3[6]; // vertex D for Facei - - tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z); - scale = ((tScale * rot)); - vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - // vertexes[0].x = pos.X + vertexes[0].x; - //vertexes[0].y = pos.Y + vertexes[0].y; - //vertexes[0].z = pos.Z + vertexes[0].z; - - FaceA[0] = vertexes[0]; - FaceB[3] = vertexes[0]; - FaceA[4] = vertexes[0]; - - tScale = lscale; - scale = ((tScale * rot)); - vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - // vertexes[1].x = pos.X + vertexes[1].x; - // vertexes[1].y = pos.Y + vertexes[1].y; - //vertexes[1].z = pos.Z + vertexes[1].z; - - FaceB[0] = vertexes[1]; - FaceA[1] = vertexes[1]; - FaceC[4] = vertexes[1]; - - tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z); - scale = ((tScale * rot)); - - vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - //vertexes[2].x = pos.X + vertexes[2].x; - //vertexes[2].y = pos.Y + vertexes[2].y; - //vertexes[2].z = pos.Z + vertexes[2].z; - - FaceC[0] = vertexes[2]; - FaceD[3] = vertexes[2]; - FaceC[5] = vertexes[2]; - - tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z); - scale = ((tScale * rot)); - vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - //vertexes[3].x = pos.X + vertexes[3].x; - // vertexes[3].y = pos.Y + vertexes[3].y; - // vertexes[3].z = pos.Z + vertexes[3].z; - - FaceD[0] = vertexes[3]; - FaceC[1] = vertexes[3]; - FaceA[5] = vertexes[3]; - - tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z); - scale = ((tScale * rot)); - vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - // vertexes[4].x = pos.X + vertexes[4].x; - // vertexes[4].y = pos.Y + vertexes[4].y; - // vertexes[4].z = pos.Z + vertexes[4].z; - - FaceB[1] = vertexes[4]; - FaceA[2] = vertexes[4]; - FaceD[4] = vertexes[4]; - - tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z); - scale = ((tScale * rot)); - vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - // vertexes[5].x = pos.X + vertexes[5].x; - // vertexes[5].y = pos.Y + vertexes[5].y; - // vertexes[5].z = pos.Z + vertexes[5].z; - - FaceD[1] = vertexes[5]; - FaceC[2] = vertexes[5]; - FaceB[5] = vertexes[5]; - - tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z); - scale = ((tScale * rot)); - vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - // vertexes[6].x = pos.X + vertexes[6].x; - // vertexes[6].y = pos.Y + vertexes[6].y; - // vertexes[6].z = pos.Z + vertexes[6].z; - - FaceB[2] = vertexes[6]; - FaceA[3] = vertexes[6]; - FaceB[4] = vertexes[6]; - - tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z); - scale = ((tScale * rot)); - vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); - - // vertexes[7].x = pos.X + vertexes[7].x; - // vertexes[7].y = pos.Y + vertexes[7].y; - // vertexes[7].z = pos.Z + vertexes[7].z; - - FaceD[2] = vertexes[7]; - FaceC[3] = vertexes[7]; - FaceD[5] = vertexes[7]; -#endregion - - //int wy = 0; - - //bool breakYN = false; // If we run into an error drawing, break out of the - // loop so we don't lag to death on error handling - DrawStruct ds = new DrawStruct(); - ds.brush = new SolidBrush(mapdotspot); - //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); - - ds.trns = new face[FaceA.Length]; - - for (int i = 0; i < FaceA.Length; i++) - { - Point[] working = new Point[5]; - working[0] = project(FaceA[i], axPos); - working[1] = project(FaceB[i], axPos); - working[2] = project(FaceD[i], axPos); - working[3] = project(FaceC[i], axPos); - working[4] = project(FaceA[i], axPos); - - face workingface = new face(); - workingface.pts = working; - - ds.trns[i] = workingface; - } - - z_sort.Add(part.LocalId, ds); - z_localIDs.Add(part.LocalId); - z_sortheights.Add(pos.Z); - - //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) - //{ - //for (wy = mapdrawstartY; wy < mapdrawendY; wy++) - //{ - //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); - //try - //{ - // Remember, flip the y! - // mapbmp.SetPixel(wx, (255 - wy), mapdotspot); - //} - //catch (ArgumentException) - //{ - // breakYN = true; - //} - - //if (breakYN) - // break; - //} - - //if (breakYN) - // break; - //} - } // Object is within 256m Z of terrain - } // object is at least a meter wide - } // loop over group children - } // entitybase is sceneobject group - } // foreach loop over entities - - float[] sortedZHeights = z_sortheights.ToArray(); - uint[] sortedlocalIds = z_localIDs.ToArray(); - - // Sort prim by Z position - Array.Sort(sortedZHeights, sortedlocalIds); - - Graphics g = Graphics.FromImage(mapbmp); - - for (int s = 0; s < sortedZHeights.Length; s++) - { - if (z_sort.ContainsKey(sortedlocalIds[s])) - { - DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; - for (int r = 0; r < rectDrawStruct.trns.Length; r++) - { - g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts); - } - //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect); - } - } - - g.Dispose(); - } // lock entities objs - - m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms"); - return mapbmp; - } - - private Point project(Vector3 point3d, Vector3 originpos) - { - Point returnpt = new Point(); - //originpos = point3d; - //int d = (int)(256f / 1.5f); - - //Vector3 topos = new Vector3(0, 0, 0); - // float z = -point3d.z - topos.z; - - returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d); - returnpt.Y = (int)(((int)Constants.RegionSize - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d))); - - return returnpt; - } - -// TODO: unused: -// #region Deprecated Maptile Generation. Adam may update this -// private Bitmap TerrainToBitmap(string gradientmap) -// { -// Bitmap gradientmapLd = new Bitmap(gradientmap); -// -// int pallete = gradientmapLd.Height; -// -// Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); -// Color[] colours = new Color[pallete]; -// -// for (int i = 0; i < pallete; i++) -// { -// colours[i] = gradientmapLd.GetPixel(0, i); -// } -// -// lock (m_scene.Heightmap) -// { -// ITerrainChannel copy = m_scene.Heightmap; -// 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)); -// -// // Handle error conditions -// if (colorindex > pallete - 1 || colorindex < 0) -// bmp.SetPixel(x, copy.Height - y - 1, Color.Red); -// else -// bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); -// } -// } -// ShadeBuildings(bmp); -// return bmp; -// } -// } -// #endregion - } -} diff --git a/OpenSim/Region/CoreModules/World/WorldMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/WorldMap/ShadedMapTileRenderer.cs deleted file mode 100644 index fef2ef3..0000000 --- a/OpenSim/Region/CoreModules/World/WorldMap/ShadedMapTileRenderer.cs +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Drawing; -using System.Reflection; -using log4net; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.CoreModules.World.WorldMap -{ - public class ShadedMapTileRenderer : IMapTileTerrainRenderer - { - private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); - - private static readonly ILog m_log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Scene m_scene; - //private IConfigSource m_config; // not used currently - - public void Initialise(Scene scene, IConfigSource config) - { - m_scene = scene; - // m_config = config; // not used currently - } - - public void TerrainToBitmap(Bitmap mapbmp) - { - int tc = Environment.TickCount; - m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain"); - - double[,] hm = m_scene.Heightmap.GetDoubles(); - bool ShadowDebugContinue = true; - - bool terraincorruptedwarningsaid = false; - - float low = 255; - float high = 0; - for (int x = 0; x < (int)Constants.RegionSize; x++) - { - for (int y = 0; y < (int)Constants.RegionSize; y++) - { - float hmval = (float)hm[x, y]; - if (hmval < low) - low = hmval; - if (hmval > high) - high = hmval; - } - } - - float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; - - for (int x = 0; x < (int)Constants.RegionSize; x++) - { - for (int y = 0; y < (int)Constants.RegionSize; y++) - { - // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left - int yr = ((int)Constants.RegionSize - 1) - y; - - float heightvalue = (float)hm[x, y]; - - if (heightvalue > waterHeight) - { - // scale height value - // No, that doesn't scale it: - // heightvalue = low + mid * (heightvalue - low) / mid; => low + (heightvalue - low) * mid / mid = low + (heightvalue - low) * 1 = low + heightvalue - low = heightvalue - - if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) - heightvalue = 0; - else if (heightvalue > 255f) - heightvalue = 255f; - else if (heightvalue < 0f) - heightvalue = 0f; - - Color color = Color.FromArgb((int)heightvalue, 100, (int)heightvalue); - - mapbmp.SetPixel(x, yr, color); - - try - { - //X - // . - // - // Shade the terrain for shadows - if (x < ((int)Constants.RegionSize - 1) && yr < ((int)Constants.RegionSize - 1)) - { - float hfvalue = (float)hm[x, y]; - float hfvaluecompare = 0f; - - if ((x + 1 < (int)Constants.RegionSize) && (y + 1 < (int)Constants.RegionSize)) - { - hfvaluecompare = (float)hm[x + 1, y + 1]; // light from north-east => look at land height there - } - if (Single.IsInfinity(hfvalue) || Single.IsNaN(hfvalue)) - hfvalue = 0f; - - if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare)) - hfvaluecompare = 0f; - - float hfdiff = hfvalue - hfvaluecompare; // => positive if NE is lower, negative if here is lower - - int hfdiffi = 0; - int hfdiffihighlight = 0; - float highlightfactor = 0.18f; - - try - { - // hfdiffi = Math.Abs((int)((hfdiff * 4) + (hfdiff * 0.5))) + 1; - hfdiffi = Math.Abs((int)(hfdiff * 4.5f)) + 1; - if (hfdiff % 1f != 0) - { - // hfdiffi = hfdiffi + Math.Abs((int)(((hfdiff % 1) * 0.5f) * 10f) - 1); - hfdiffi = hfdiffi + Math.Abs((int)((hfdiff % 1f) * 5f) - 1); - } - - hfdiffihighlight = Math.Abs((int)((hfdiff * highlightfactor) * 4.5f)) + 1; - if (hfdiff % 1f != 0) - { - // hfdiffi = hfdiffi + Math.Abs((int)(((hfdiff % 1) * 0.5f) * 10f) - 1); - hfdiffihighlight = hfdiffihighlight + Math.Abs((int)(((hfdiff * highlightfactor) % 1f) * 5f) - 1); - } - } - catch (OverflowException) - { - m_log.Debug("[MAPTILE]: Shadow failed at value: " + hfdiff.ToString()); - ShadowDebugContinue = false; - } - - if (hfdiff > 0.3f) - { - // NE is lower than here - // We have to desaturate and lighten the land at the same time - // we use floats, colors use bytes, so shrink are space down to - // 0-255 - - if (ShadowDebugContinue) - { - int r = color.R; - int g = color.G; - int b = color.B; - color = Color.FromArgb((r + hfdiffihighlight < 255) ? r + hfdiffihighlight : 255, - (g + hfdiffihighlight < 255) ? g + hfdiffihighlight : 255, - (b + hfdiffihighlight < 255) ? b + hfdiffihighlight : 255); - } - } - else if (hfdiff < -0.3f) - { - // here is lower than NE: - // We have to desaturate and blacken the land at the same time - // we use floats, colors use bytes, so shrink are space down to - // 0-255 - - if (ShadowDebugContinue) - { - if ((x - 1 > 0) && (yr + 1 < (int)Constants.RegionSize)) - { - color = mapbmp.GetPixel(x - 1, yr + 1); - int r = color.R; - int g = color.G; - int b = color.B; - color = Color.FromArgb((r - hfdiffi > 0) ? r - hfdiffi : 0, - (g - hfdiffi > 0) ? g - hfdiffi : 0, - (b - hfdiffi > 0) ? b - hfdiffi : 0); - - mapbmp.SetPixel(x-1, yr+1, color); - } - } - } - } - } - catch (ArgumentException) - { - if (!terraincorruptedwarningsaid) - { - m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName); - terraincorruptedwarningsaid = true; - } - color = Color.Black; - mapbmp.SetPixel(x, yr, color); - } - } - else - { - // We're under the water level with the terrain, so paint water instead of land - - // Y flip the cordinates - heightvalue = waterHeight - heightvalue; - if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) - heightvalue = 0f; - else if (heightvalue > 19f) - heightvalue = 19f; - else if (heightvalue < 0f) - heightvalue = 0f; - - heightvalue = 100f - (heightvalue * 100f) / 19f; - - try - { - mapbmp.SetPixel(x, yr, WATER_COLOR); - } - catch (ArgumentException) - { - if (!terraincorruptedwarningsaid) - { - m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName); - terraincorruptedwarningsaid = true; - } - Color black = Color.Black; - mapbmp.SetPixel(x, ((int)Constants.RegionSize - y) - 1, black); - } - } - } - } - m_log.Info("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); - } - } -} diff --git a/OpenSim/Region/CoreModules/World/WorldMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/WorldMap/TexturedMapTileRenderer.cs deleted file mode 100644 index 8b34f6e..0000000 --- a/OpenSim/Region/CoreModules/World/WorldMap/TexturedMapTileRenderer.cs +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Reflection; -using log4net; -using Nini.Config; -using OpenMetaverse; -using OpenMetaverse.Imaging; -using OpenSim.Framework; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.CoreModules.World.WorldMap -{ - // Hue, Saturation, Value; used for color-interpolation - struct HSV { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - public float h; - public float s; - public float v; - - public HSV(float h, float s, float v) - { - this.h = h; - this.s = s; - this.v = v; - } - - // (for info about algorithm, see http://en.wikipedia.org/wiki/HSL_and_HSV) - public HSV(Color c) - { - float r = c.R / 255f; - float g = c.G / 255f; - float b = c.B / 255f; - float max = Math.Max(Math.Max(r, g), b); - float min = Math.Min(Math.Min(r, g), b); - float diff = max - min; - - if (max == min) h = 0f; - else if (max == r) h = (g - b) / diff * 60f; - else if (max == g) h = (b - r) / diff * 60f + 120f; - else h = (r - g) / diff * 60f + 240f; - if (h < 0f) h += 360f; - - if (max == 0f) s = 0f; - else s = diff / max; - - v = max; - } - - // (for info about algorithm, see http://en.wikipedia.org/wiki/HSL_and_HSV) - public Color toColor() - { - if (s < 0f) m_log.Debug("S < 0: " + s); - else if (s > 1f) m_log.Debug("S > 1: " + s); - if (v < 0f) m_log.Debug("V < 0: " + v); - else if (v > 1f) m_log.Debug("V > 1: " + v); - - float f = h / 60f; - int sector = (int)f % 6; - f = f - (int)f; - int pi = (int)(v * (1f - s) * 255f); - int qi = (int)(v * (1f - s * f) * 255f); - int ti = (int)(v * (1f - (1f - f) * s) * 255f); - int vi = (int)(v * 255f); - - if (pi < 0) pi = 0; - if (pi > 255) pi = 255; - if (qi < 0) qi = 0; - if (qi > 255) qi = 255; - if (ti < 0) ti = 0; - if (ti > 255) ti = 255; - if (vi < 0) vi = 0; - if (vi > 255) vi = 255; - - switch (sector) - { - case 0: - return Color.FromArgb(vi, ti, pi); - case 1: - return Color.FromArgb(qi, vi, pi); - case 2: - return Color.FromArgb(pi, vi, ti); - case 3: - return Color.FromArgb(pi, qi, vi); - case 4: - return Color.FromArgb(ti, pi, vi); - default: - return Color.FromArgb(vi, pi, qi); - } - } - } - - public class TexturedMapTileRenderer : IMapTileTerrainRenderer - { - #region Constants - - private static readonly ILog m_log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - // some hardcoded terrain UUIDs that work with SL 1.20 (the four default textures and "Blank"). - // The color-values were choosen because they "look right" (at least to me) ;-) - private static readonly UUID defaultTerrainTexture1 = new UUID("0bc58228-74a0-7e83-89bc-5c23464bcec5"); - private static readonly Color defaultColor1 = Color.FromArgb(165, 137, 118); - private static readonly UUID defaultTerrainTexture2 = new UUID("63338ede-0037-c4fd-855b-015d77112fc8"); - private static readonly Color defaultColor2 = Color.FromArgb(69, 89, 49); - private static readonly UUID defaultTerrainTexture3 = new UUID("303cd381-8560-7579-23f1-f0a880799740"); - private static readonly Color defaultColor3 = Color.FromArgb(162, 154, 141); - private static readonly UUID defaultTerrainTexture4 = new UUID("53a2f406-4895-1d13-d541-d2e3b86bc19c"); - private static readonly Color defaultColor4 = Color.FromArgb(200, 200, 200); - - private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); - - #endregion - - - private Scene m_scene; - // private IConfigSource m_config; // not used currently - - // mapping from texture UUIDs to averaged color. This will contain 5-9 values, in general; new values are only - // added when the terrain textures are changed in the estate dialog and a new map is generated (and will stay in - // that map until the region-server restarts. This could be considered a memory-leak, but it's a *very* small one. - // TODO does it make sense to use a "real" cache and regenerate missing entries on fetch? - private Dictionary m_mapping; - - - public void Initialise(Scene scene, IConfigSource source) - { - m_scene = scene; - // m_config = source; // not used currently - m_mapping = new Dictionary(); - m_mapping.Add(defaultTerrainTexture1, defaultColor1); - m_mapping.Add(defaultTerrainTexture2, defaultColor2); - m_mapping.Add(defaultTerrainTexture3, defaultColor3); - m_mapping.Add(defaultTerrainTexture4, defaultColor4); - m_mapping.Add(Util.BLANK_TEXTURE_UUID, Color.White); - } - - #region Helpers - // This fetches the texture from the asset server synchroneously. That should be ok, as we - // call map-creation only in those places: - // - on start: We can wait here until the asset server returns the texture - // TODO (- on "map" command: We are in the command-line thread, we will wait for completion anyway) - // TODO (- on "automatic" update after some change: We are called from the mapUpdateTimer here and - // will wait anyway) - private Bitmap fetchTexture(UUID id) - { - AssetBase asset = m_scene.AssetService.Get(id.ToString()); - m_log.DebugFormat("Fetched texture {0}, found: {1}", id, asset != null); - if (asset == null) return null; - - ManagedImage managedImage; - Image image; - - try - { - if (OpenJPEG.DecodeToImage(asset.Data, out managedImage, out image)) - return new Bitmap(image); - else - return null; - } - catch (DllNotFoundException) - { - m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg is not installed correctly on this system. Asset Data is emtpy for {0}", id); - - } - catch (IndexOutOfRangeException) - { - m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg was unable to encode this. Asset Data is emtpy for {0}", id); - - } - catch (Exception) - { - m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg was unable to encode this. Asset Data is emtpy for {0}", id); - - } - return null; - - } - - // Compute the average color of a texture. - private Color computeAverageColor(Bitmap bmp) - { - // we have 256 x 256 pixel, each with 256 possible color-values per - // color-channel, so 2^24 is the maximum value we can get, adding everything. - // int is be big enough for that. - int r = 0, g = 0, b = 0; - for (int y = 0; y < bmp.Height; ++y) - { - for (int x = 0; x < bmp.Width; ++x) - { - Color c = bmp.GetPixel(x, y); - r += (int)c.R & 0xff; - g += (int)c.G & 0xff; - b += (int)c.B & 0xff; - } - } - - int pixels = bmp.Width * bmp.Height; - return Color.FromArgb(r / pixels, g / pixels, b / pixels); - } - - // return either the average color of the texture, or the defaultColor if the texturID is invalid - // or the texture couldn't be found - private Color computeAverageColor(UUID textureID, Color defaultColor) { - if (textureID == UUID.Zero) return defaultColor; // not set - if (m_mapping.ContainsKey(textureID)) return m_mapping[textureID]; // one of the predefined textures - - Bitmap bmp = fetchTexture(textureID); - Color color = bmp == null ? defaultColor : computeAverageColor(bmp); - // store it for future reference - m_mapping[textureID] = color; - - return color; - } - - // S-curve: f(x) = 3x² - 2x³: - // f(0) = 0, f(0.5) = 0.5, f(1) = 1, - // f'(x) = 0 at x = 0 and x = 1; f'(0.5) = 1.5, - // f''(0.5) = 0, f''(x) != 0 for x != 0.5 - private float S(float v) { - return (v * v * (3f - 2f * v)); - } - - // interpolate two colors in HSV space and return the resulting color - private HSV interpolateHSV(ref HSV c1, ref HSV c2, float ratio) { - if (ratio <= 0f) return c1; - if (ratio >= 1f) return c2; - - // make sure we are on the same side on the hue-circle for interpolation - // We change the hue of the parameters here, but we don't change the color - // represented by that value - if (c1.h - c2.h > 180f) c1.h -= 360f; - else if (c2.h - c1.h > 180f) c1.h += 360f; - - return new HSV(c1.h * (1f - ratio) + c2.h * ratio, - c1.s * (1f - ratio) + c2.s * ratio, - c1.v * (1f - ratio) + c2.v * ratio); - } - - // the heigthfield might have some jumps in values. Rendered land is smooth, though, - // as a slope is rendered at that place. So average 4 neighbour values to emulate that. - private float getHeight(double[,] hm, int x, int y) { - if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) - return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112); - else - return (float)hm[x, y]; - } - #endregion - - public void TerrainToBitmap(Bitmap mapbmp) - { - int tc = Environment.TickCount; - m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain"); - - // These textures should be in the AssetCache anyway, as every client conneting to this - // region needs them. Except on start, when the map is recreated (before anyone connected), - // and on change of the estate settings (textures and terrain values), when the map should - // be recreated. - RegionSettings settings = m_scene.RegionInfo.RegionSettings; - - // the four terrain colors as HSVs for interpolation - HSV hsv1 = new HSV(computeAverageColor(settings.TerrainTexture1, defaultColor1)); - HSV hsv2 = new HSV(computeAverageColor(settings.TerrainTexture2, defaultColor2)); - HSV hsv3 = new HSV(computeAverageColor(settings.TerrainTexture3, defaultColor3)); - HSV hsv4 = new HSV(computeAverageColor(settings.TerrainTexture4, defaultColor4)); - - float levelNElow = (float)settings.Elevation1NE; - float levelNEhigh = (float)settings.Elevation2NE; - - float levelNWlow = (float)settings.Elevation1NW; - float levelNWhigh = (float)settings.Elevation2NW; - - float levelSElow = (float)settings.Elevation1SE; - float levelSEhigh = (float)settings.Elevation2SE; - - float levelSWlow = (float)settings.Elevation1SW; - float levelSWhigh = (float)settings.Elevation2SW; - - float waterHeight = (float)settings.WaterHeight; - - double[,] hm = m_scene.Heightmap.GetDoubles(); - - for (int x = 0; x < (int)Constants.RegionSize; x++) - { - float columnRatio = x / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation - for (int y = 0; y < (int)Constants.RegionSize; y++) - { - float rowRatio = y / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation - - // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left - int yr = ((int)Constants.RegionSize - 1) - y; - - float heightvalue = getHeight(hm, x, y); - if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) - heightvalue = 0; - - if (heightvalue > waterHeight) - { - // add a bit noise for breaking up those flat colors: - // - a large-scale noise, for the "patches" (using an doubled s-curve for sharper contrast) - // - a small-scale noise, for bringing in some small scale variation - //float bigNoise = (float)TerrainUtil.InterpolatedNoise(x / 8.0, y / 8.0) * .5f + .5f; // map to 0.0 - 1.0 - //float smallNoise = (float)TerrainUtil.InterpolatedNoise(x + 33, y + 43) * .5f + .5f; - //float hmod = heightvalue + smallNoise * 3f + S(S(bigNoise)) * 10f; - float hmod = - heightvalue + - (float)TerrainUtil.InterpolatedNoise(x + 33, y + 43) * 1.5f + 1.5f + // 0 - 3 - S(S((float)TerrainUtil.InterpolatedNoise(x / 8.0, y / 8.0) * .5f + .5f)) * 10f; // 0 - 10 - - // find the low/high values for this point (interpolated bilinearily) - // (and remember, x=0,y=0 is SW) - float low = levelSWlow * (1f - rowRatio) * (1f - columnRatio) + - levelSElow * (1f - rowRatio) * columnRatio + - levelNWlow * rowRatio * (1f - columnRatio) + - levelNElow * rowRatio * columnRatio; - float high = levelSWhigh * (1f - rowRatio) * (1f - columnRatio) + - levelSEhigh * (1f - rowRatio) * columnRatio + - levelNWhigh * rowRatio * (1f - columnRatio) + - levelNEhigh * rowRatio * columnRatio; - if (high < low) - { - // someone tried to fool us. High value should be higher than low every time - float tmp = high; - high = low; - low = tmp; - } - - HSV hsv; - if (hmod <= low) hsv = hsv1; // too low - else if (hmod >= high) hsv = hsv4; // too high - else - { - // HSV-interpolate along the colors - // first, rescale h to 0.0 - 1.0 - hmod = (hmod - low) / (high - low); - // now we have to split: 0.00 => color1, 0.33 => color2, 0.67 => color3, 1.00 => color4 - if (hmod < 1f/3f) hsv = interpolateHSV(ref hsv1, ref hsv2, hmod * 3f); - else if (hmod < 2f/3f) hsv = interpolateHSV(ref hsv2, ref hsv3, (hmod * 3f) - 1f); - else hsv = interpolateHSV(ref hsv3, ref hsv4, (hmod * 3f) - 2f); - } - - // Shade the terrain for shadows - if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) - { - float hfvaluecompare = getHeight(hm, x + 1, y + 1); // light from north-east => look at land height there - if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare)) - hfvaluecompare = 0f; - - float hfdiff = heightvalue - hfvaluecompare; // => positive if NE is lower, negative if here is lower - hfdiff *= 0.06f; // some random factor so "it looks good" - if (hfdiff > 0.02f) - { - float highlightfactor = 0.18f; - // NE is lower than here - // We have to desaturate and lighten the land at the same time - hsv.s = (hsv.s - (hfdiff * highlightfactor) > 0f) ? hsv.s - (hfdiff * highlightfactor) : 0f; - hsv.v = (hsv.v + (hfdiff * highlightfactor) < 1f) ? hsv.v + (hfdiff * highlightfactor) : 1f; - } - else if (hfdiff < -0.02f) - { - // here is lower than NE: - // We have to desaturate and blacken the land at the same time - hsv.s = (hsv.s + hfdiff > 0f) ? hsv.s + hfdiff : 0f; - hsv.v = (hsv.v + hfdiff > 0f) ? hsv.v + hfdiff : 0f; - } - } - mapbmp.SetPixel(x, yr, hsv.toColor()); - } - else - { - // We're under the water level with the terrain, so paint water instead of land - - heightvalue = waterHeight - heightvalue; - if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) - heightvalue = 0f; - else if (heightvalue > 19f) - heightvalue = 19f; - else if (heightvalue < 0f) - heightvalue = 0f; - - heightvalue = 100f - (heightvalue * 100f) / 19f; // 0 - 19 => 100 - 0 - - mapbmp.SetPixel(x, yr, WATER_COLOR); - } - } - } - m_log.Info("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); - } - } -} diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index fbc8a50..a182eea 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -1011,7 +1011,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap if (terrain == null) return; - byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png"); + byte[] data = terrain.WriteJpeg2000Image(); if (data == null) return; diff --git a/OpenSim/Region/Framework/Interfaces/ITerrain.cs b/OpenSim/Region/Framework/Interfaces/ITerrain.cs index b42e872..8aacb35 100644 --- a/OpenSim/Region/Framework/Interfaces/ITerrain.cs +++ b/OpenSim/Region/Framework/Interfaces/ITerrain.cs @@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Interfaces public interface IMapImageGenerator { - System.Drawing.Bitmap CreateMapTile(string gradientmap); - byte[] WriteJpeg2000Image(string gradientmap); + System.Drawing.Bitmap CreateMapTile(); + byte[] WriteJpeg2000Image(); } } diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs index 4409d5c..168b233 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs @@ -413,7 +413,7 @@ namespace OpenSim.Services.Connectors.SimianGrid return; } - using (Image mapTile = tileGenerator.CreateMapTile("defaultstripe.png")) + using (Image mapTile = tileGenerator.CreateMapTile()) { using (MemoryStream stream = new MemoryStream()) { diff --git a/prebuild.xml b/prebuild.xml index 530c417..5746890 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1370,11 +1370,13 @@ ../../../bin/ + true ../../../bin/ + true @@ -1389,6 +1391,7 @@ + -- cgit v1.1