public void FloodEffect (ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { float sum = 0; float steps = 0; int x, y; for (x = (int)west; x < (int)east; x++) { for (y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand (userID, new Vector3 (x, y, 0))) continue; sum += map [x, y]; steps += 1; } } float avg = sum / steps; float str = 0.1f * strength; // == 0.2 in the default client for (x = (int)west; x < (int)east; x++) { for (y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand (userID, new Vector3 (x, y, 0))) continue; map [x, y] = (map [x, y] * (1 - str)) + (avg * str); } } }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength, int startX, int endX, int startY, int endY) { double sum = 0.0; double steps = 0.0; int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (fillArea[x, y]) { sum += map[x, y]; steps += 1.0; } } } double avg = sum / steps; double str = 0.1 * strength; // == 0.2 in the default client for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (fillArea[x, y]) map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); } } }
private void BuildTiles(ITerrainChannel map, double height) { int channelWidth = (int) Math.Floor((map.Width / num_w) * 0.8); int channelHeight = (int) Math.Floor((map.Height / num_h) * 0.8); int channelXOffset = (map.Width / num_w) - channelWidth; int channelYOffset = (map.Height / num_h) - channelHeight; for (int x = 0; x < num_w; x++) { for (int y = 0; y < num_h; y++) { int xoff = ((channelXOffset + channelWidth) * x) + (channelXOffset / 2); int yoff = ((channelYOffset + channelHeight) * y) + (channelYOffset / 2); Boolean[,] bitmap = new bool[map.Width,map.Height]; for (int dx = 0; dx < channelWidth; dx++) { for (int dy = 0; dy < channelHeight; dy++) { bitmap[dx + xoff, dy + yoff] = true; } } raiseFunction.FloodEffect(map, bitmap, height); } } }
public bool Compare(ITerrainChannel terrainChannel) { if (m_terrainChannel != terrainChannel) return false; else return false; }
private static Bitmap CreateBitmapFromMap(ITerrainChannel map) { Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); int pallete = gradientmapLd.Height; Bitmap bmp = new Bitmap(map.Width, map.Height); Color[] colours = new Color[pallete]; for (int i = 0; i < pallete; i++) { colours[i] = gradientmapLd.GetPixel(0, i); } for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { // 512 is the largest possible height before colours clamp int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); } } return bmp; }
public void FloodEffect(ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { float area = strength; float step = strength/4; for (int x = (int) west; x < (int) east; x++) { for (int y = (int) south; y < (int) north; y++) { if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) continue; float average = 0; int avgsteps = 0; float n; for (n = 0 - area; n < area; n += step) { float l; for (l = 0 - area; l < area; l += step) { avgsteps++; average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); } } map[x, y] = average/avgsteps; } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) { strength = TerrainUtil.MetersToSphericalStrength(strength); int x; for (x = 0; x < map.Width; x++) { int y; for (y = 0; y < map.Height; y++) { if (!mask[x,y]) continue; // Calculate a sphere and add it to the heighmap double z = strength; z *= z; z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0); if (z > 0.0) map[x, y] += noise * z * duration; } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration, int startX, int endX, int startY, int endY) { strength = TerrainUtil.MetersToSphericalStrength(strength); int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (!mask[x, y]) continue; // Calculate a sphere and add it to the heighmap double z = strength; z *= z; z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); double noise = TerrainUtil.PerlinNoise2D(x / (double) map.Width, y / (double) map.Height, 8, 1.0); if (z > 0.0) map[x, y] += noise * z * duration; } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration, int startX, int endX, int startY, int endY) { int s = (int) (Math.Pow(2, strength) + 0.5); int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (!mask[x, y]) continue; // Calculate a cos-sphere and add it to the heighmap double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); double z = Math.Cos(r * Math.PI / (s * 2)); if (z > 0.0) { double newz = map[x, y] - z * duration; if (newz < 0.0) map[x, y] = 0.0; else map[x, y] = newz; } } } }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) { double area = strength; double step = strength / 4.0; int x, y; for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { if (!fillArea[x, y]) continue; double average = 0.0; int avgsteps = 0; double n; for (n = 0.0 - area; n < area; n += step) { double l; for (l = 0.0 - area; l < area; l += step) { avgsteps++; average += GetBilinearInterpolate(x + n, y + l, map); } } map[x, y] = average / avgsteps; } } }
public static double GetBilinearInterpolate(double x, double y, ITerrainChannel map) { int w = map.Width; int h = map.Height; if (x > w - 2.0) x = w - 2.0; if (y > h - 2.0) y = h - 2.0; if (x < 0.0) x = 0.0; if (y < 0.0) y = 0.0; const int stepSize = 1; double h00 = map[(int) x, (int) y]; double h10 = map[(int) x + stepSize, (int) y]; double h01 = map[(int) x, (int) y + stepSize]; double h11 = map[(int) x + stepSize, (int) y + stepSize]; double h1 = h00; double h2 = h10; double h3 = h01; double h4 = h11; double a00 = h1; double a10 = h2 - h1; double a01 = h3 - h1; double a11 = h1 - h2 - h3 + h4; double partialx = x - (int) x; double partialz = y - (int) y; double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); return hi; }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration, float BrushSize) { strength = TerrainUtil.MetersToSphericalStrength(BrushSize); duration = 0.03; //MCP Should be read from ini file if (duration > 1.0) duration = 1.0; if (duration < 0) return; int x; for (x = 0; x < map.Width; x++) { int y; for (y = 0; y < map.Height; y++) { if (!mask[x,y]) continue; // Calculate a sphere and add it to the heighmap double z = 0; if (duration < 4.0) z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration * 0.25; if (z > 0.0) { map[x, y] = (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); } } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration, int startX, int endX, int startY, int endY) { strength = TerrainUtil.MetersToSphericalStrength(strength); duration = 0.03; //MCP Should be read from ini file if (duration > 1.0) duration = 1.0; if (duration < 0) return; int x,y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (!mask[x, y]) continue; // Calculate a sphere and add it to the heighmap double z = strength; z *= z; z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); if (z > 0.0) { z *= duration; map[x, y] = (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); } } } }
public virtual void SaveFile(ITerrainChannel m_channel, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY) { throw new System.Exception("Not Implemented"); }
public void PaintEffect (ITerrainChannel map, UUID userID, float rx, float ry, float rz, float strength, float duration, float BrushSize) { int x; int xFrom = (int)(rx - BrushSize + 0.5); int xTo = (int)(rx + BrushSize + 0.5) + 1; int yFrom = (int)(ry - BrushSize + 0.5); int yTo = (int)(ry + BrushSize + 0.5) + 1; if (xFrom < 0) xFrom = 0; if (yFrom < 0) yFrom = 0; if (xTo > map.Width) xTo = map.Width; if (yTo > map.Height) yTo = map.Height; for (x = xFrom; x < xTo; x++) { int y; for (y = yFrom; y < yTo; y++) { if (!map.Scene.Permissions.CanTerraformLand (userID, new Vector3 (x, y, 0))) continue; // Calculate a cos-sphere and add it to the heightmap double r = Math.Sqrt ((x - rx) * (x - rx) + ((y - ry) * (y - ry))); double z = Math.Cos (r * Math.PI / (BrushSize * 2)); if (z > 0.0) map [x, y] += (float)(z * duration); } } }
public override string ModifyTerrain(ITerrainChannel map, string[] args) { string result; if (args.Length < 3) { result = "Usage: " + GetUsage(); } else { TerrainModifierData data; result = this.parseParameters(args, out data); // Context-specific validation if (result == String.Empty) { if (data.shape == String.Empty) { data.shape = "rectangle"; data.x0 = 0; data.y0 = 0; data.dx = map.Width; data.dy = map.Height; } } // if it's all good, then do the work if (result == String.Empty) { this.applyModification(map, data); } } return result; }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) { double sum = 0.0; double steps = 0.0; int x, y; for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { if (fillArea[x, y]) { sum += map[x, y]; steps += 1.0; } } } double avg = sum / steps; double str = 0.1 * strength; // == 0.2 in the default client for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { if (fillArea[x, y]) map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) { strength = TerrainUtil.MetersToSphericalStrength(strength); int x, y; double[,] tweak = new double[map.Width,map.Height]; double area = strength; double step = strength / 4.0; duration = 0.03; //MCP Should be read from ini file // compute delta map for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); if (z > 0) // add in non-zero amount { double average = 0.0; int avgsteps = 0; double n; for (n = 0.0 - area; n < area; n += step) { double l; for (l = 0.0 - area; l < area; l += step) { avgsteps++; average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); } } tweak[x, y] = average / avgsteps; } } } // blend in map for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { if (!mask[x,y]) continue; double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); if (z > 0) // add in non-zero amount { double da = z; double a = (map[x, y] - tweak[x, y]) * da; double newz = map[x, y] - (a * duration); if (newz > 0.0) map[x, y] = newz; } } } }
public void RunEffect(ITerrainChannel map) { ITerrainPaintableEffect eroder = new WeatherSphere(); bool[,] cliffMask = new bool[map.Width,map.Height]; bool[,] channelMask = new bool[map.Width,map.Height]; bool[,] smoothMask = new bool[map.Width,map.Height]; m_log.Info("S1"); // Step one, generate rough mask int x, y; for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { m_log.Info("."); smoothMask[x, y] = true; // Start underwater map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 5; // Add a little height. (terrain should now be above water, mostly.) map[x, y] += 20; const int channelsX = 4; int channelWidth = (map.Width / channelsX / 4); const int channelsY = 4; int channelHeight = (map.Height / channelsY / 4); SetLowerChannel(map, cliffMask, channelMask, x, y, channelsX, channelWidth, map.Width, x); SetLowerChannel(map, cliffMask, channelMask, x, y, channelsY, channelHeight, map.Height, y); } } m_log.Info("S2"); //smooth.FloodEffect(map, smoothMask, 4.0); m_log.Info("S3"); for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { if (cliffMask[x, y]) eroder.PaintEffect(map, UUID.Zero, x, y, -1, 4, 0.1f, 4, null); } } for (x = 0; x < map.Width; x += 2) { for (y = 0; y < map.Height; y += 2) { if (map[x, y] < 0.1) map[x, y] = 0.1; if (map[x, y] > 256) map[x, y] = 256; } } //smooth.FloodEffect(map, smoothMask, 4.0); }
public void PaintEffect(ITerrainChannel map, UUID userID, float rx, float ry, float rz, float strength, float duration, float BrushSize) { strength = TerrainUtil.MetersToSphericalStrength(strength); int x; for (x = 0; x < map.Width; x++) { int y; for (y = 0; y < map.Height; y++) { if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) continue; float z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); if (z > 0) // add in non-zero amount { const int NEIGHBOUR_ME = 4; const int NEIGHBOUR_MAX = 9; for (int j = 0; j < NEIGHBOUR_MAX; j++) { if (j != NEIGHBOUR_ME) { int[] coords = Neighbours(type, j); coords[0] += x; coords[1] += y; if (coords[0] > map.Width - 1) continue; if (coords[1] > map.Height - 1) continue; if (coords[0] < 0) continue; if (coords[1] < 0) continue; float heightF = map[x, y]; float target = map[coords[0], coords[1]]; if (target > heightF + talus) { float calc = duration*((target - heightF) - talus)*z; heightF += calc; target -= calc; } map[x, y] = heightF; map[coords[0], coords[1]] = target; } } } } } }
public override void SaveFile(string filename, ITerrainChannel map) { Bitmap colours = CreateGrayscaleBitmapFromMap(map); try { colours.Save (filename, ImageFormat.Tiff); } catch { } colours.Dispose (); }
/// <summary> /// Exports a stream using a System.Drawing exporter. /// </summary> /// <param name="stream">The target stream</param> /// <param name="map">The terrain channel being saved</param> public override void SaveStream(Stream stream, ITerrainChannel map) { Bitmap colours = CreateGrayscaleBitmapFromMap(map); try { colours.Save (stream, ImageFormat.Gif); } catch { } colours.Dispose (); }
public void PaintEffect (ITerrainChannel map, UUID userID, float rx, float ry, float rz, float strength, float duration, float BrushSize) { int n = (int)(BrushSize + 0.5f); if (BrushSize > 6) //If it gets too high, it will start roughening at an ever increasing rate when held down BrushSize = 6; strength = TerrainUtil.MetersToSphericalStrength (BrushSize); float area = BrushSize; float step = BrushSize / 4; duration *= 0.03f; //MCP Should be read from ini file int zx = (int)(rx + 0.5); int zy = (int)(ry + 0.5); int dx; for (dx = -n; dx <= n; dx++) { int dy; for (dy = -n; dy <= n; dy++) { int x = zx + dx; int y = zy + dy; if (x >= 0 && y >= 0 && x < map.Width && y < map.Height) { if (!map.Scene.Permissions.CanTerraformLand (userID, new Vector3 (x, y, 0))) continue; float z = TerrainUtil.SphericalFactor (x, y, rx, ry, strength) / (strength); if (z > 0) // add in non-zero amount { float average = 0; int avgsteps = 0; float nn; for (nn = 0 - area; nn < area; nn += step) { float l; for (l = 0 - area; l < area; l += step) { avgsteps++; average += TerrainUtil.GetBilinearInterpolate (x + nn, y + l, map); } } float avg; if (avgsteps > 0) avg = average / avgsteps; else avg = 0f; float da = z; float a = (map [x, y] - avg) * da; float newz = map [x, y] - (a * duration); if (newz > 0.0) map [x, y] = newz; } } } } }
public void AddRegion(RegionData rData, ITerrainChannel thisRegionTerrainChannel) { if (RegData == null) { //Root region RegData = rData; } RegionConnections.Add(rData, thisRegionTerrainChannel); RegData.RegionScene.RegisterModuleInterface<ITerrainChannel>(this); }
public void AddRegion(RegionData rData, ITerrainChannel thisRegionTerrainChannel) { if (RegData == null) { //Root region RegData = rData; } RegionConnections.Add(rData, thisRegionTerrainChannel); RegData.RegionScene.Heightmap = this; }
/// <summary> /// Reverts an area of the map to the heightfield stored in the revertmap /// </summary> /// <param name="map">The current heightmap</param> /// <param name="userID"></param> /// <param name="north"></param> /// <param name="west"></param> /// <param name="south"></param> /// <param name="east"></param> /// <param name="strength">unused</param> public void FloodEffect (ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { for (int x = (int)west; x < (int)east; x++) { for (int y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand (userID, new Vector3 (x, y, 0))) continue; map [x, y] = m_module.TerrainRevertMap [x, y]; } } }
public override string ModifyTerrain(ITerrainChannel map, string[] args) { string result; if (args.Length < 3) { result = "Usage: " + GetUsage(); } else { TerrainModifierData data; result = this.parseParameters(args, out data); // Context-specific validation if (result == String.Empty) { if (data.bevel == "taper") { if (data.bevelevation < 0.0 || data.bevelevation > 1.0) { result = String.Format("Taper must be 0.0 to 1.0: {0}", data.bevelevation); } } else { data.bevelevation = 1.0f; } if (data.elevation < 0.0 || data.elevation > 1.0) { result = String.Format("Noise strength must be 0.0 to 1.0: {0}", data.elevation); } if (data.shape == String.Empty) { data.shape = "rectangle"; data.x0 = 0; data.y0 = 0; data.dx = map.Width; data.dy = map.Height; } } // if it's all good, then do the work if (result == String.Empty) { this.applyModification(map, data); } } return result; }
public void FloodEffect (ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { for (int x = (int)west; x < (int)east; x++) { for (int y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand (userID, new Vector3 (x, y, 0))) continue; float noise = TerrainUtil.PerlinNoise2D (x / map.Scene.RegionInfo.RegionSizeX, y / map.Scene.RegionInfo.RegionSizeY, 8, 1); map [x, y] += noise * strength; } } }
public void FloodEffect(ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { int x, y; for (x = (int)west; x < (int)east; x++) { for (y = (int)south; y < (int)north; y++) { if (!((Scene)map.Scene).Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) continue; map[x, y] -= strength; } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration, float BrushSize) { if(BrushSize > 8) //If it gets too high, it will start roughening at an ever increasing rate when held down BrushSize = 8; strength = TerrainUtil.MetersToSphericalStrength(BrushSize); int x, y; double area = BrushSize; double step = BrushSize / 4; duration *= 0.03; //MCP Should be read from ini file // compute delta and blend in for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { if (!mask[x, y]) continue; double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) / (strength); if (z < 0) { } if (z > 0) // add in non-zero amount { double average = 0.0; int avgsteps = 0; double n; for (n = 0.0 - area; n < area; n += step) { double l; for (l = 0.0 - area; l < area; l += step) { avgsteps++; average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); } } double da = z; double a = (map[x, y] - (average / avgsteps)) * da; double newz = map[x, y] - (a * duration); if (newz > 0.0) map[x, y] = newz; } } } }
public void FloodEffect(ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { for (int x = (int)west; x < (int)east; x++) { for (int y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) { continue; } map [x, y] += strength; } } }
private Point project(ITerrainChannel hm, 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)((hm.Width - 1) - point3d.Y); //(int)(255 - (((topos.y - point3d.y) / z * d))); return(returnpt); }
public void PaintEffect(ITerrainChannel map, UUID userID, float rx, float ry, float rz, float strength, float duration, float BrushSize, List <Scene> scene) { int x; int xFrom = (int)(rx - BrushSize + 0.5); int xTo = (int)(rx + BrushSize + 0.5) + 1; int yFrom = (int)(ry - BrushSize + 0.5); int yTo = (int)(ry + BrushSize + 0.5) + 1; if (xFrom < 0) { xFrom = 0; } if (yFrom < 0) { yFrom = 0; } if (xTo > map.Width) { xTo = map.Width; } if (yTo > map.Height) { yTo = map.Height; } for (x = xFrom; x < xTo; x++) { int y; for (y = yFrom; y < yTo; y++) { if (!((Scene)map.Scene).Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) { continue; } // Calculate a cos-sphere and add it to the heighmap double r = Math.Sqrt((x - rx) * (x - rx) + ((y - ry) * (y - ry))); double z = Math.Cos(r * Math.PI / (BrushSize * 2)); if (z > 0.0) { map[x, y] += (float)(z * duration); } } } }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength, int startX, int endX, int startY, int endY) { double area = strength; double step = strength / 4.0; double[,] manipulate = new double[map.Width, map.Height]; int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (!fillArea[x, y]) { continue; } double average = 0.0; int avgsteps = 0; double n; for (n = 0.0 - area; n < area; n += step) { double l; for (l = 0.0 - area; l < area; l += step) { avgsteps++; average += GetBilinearInterpolate(x + n, y + l, map); } } manipulate[x, y] = average / avgsteps; } } for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (!fillArea[x, y]) { continue; } map[x, y] = manipulate[x, y]; } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration, int startX, int endX, int startY, int endY) { strength = TerrainUtil.MetersToSphericalStrength(strength); int x, y; // blend in map for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (!mask[x, y]) { continue; } double z; if (duration < 4.0) { z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration * 0.25; } else { z = 1.0; } double delta = rz - map[x, y]; if (Math.Abs(delta) > 0.1) { if (z > 1.0) { z = 1.0; } else if (z < 0.0) { z = 0.0; } delta *= z; } if (delta != 0) // add in non-zero amount { map[x, y] += delta; } } } }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (fillArea[x, y]) { map[x, y] += strength; } } } }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) { int x; for (x = 0; x < map.Width; x++) { int y; for (y = 0; y < map.Height; y++) { if (fillArea[x, y]) { map[x, y] += strength; } } } }
/// <summary> /// reverts an area of the map to the heightfield stored in the revertmap /// </summary> /// <param name="map">the current heightmap</param> /// <param name="fillArea">array indicating which sections of the map are to be reverted</param> /// <param name="strength">unused</param> public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength, int startX, int endX, int startY, int endY) { int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (fillArea[x, y]) { map[x, y] = m_revertmap[x, y]; } } } }
private void SmoothMap(ITerrainChannel map, int rounds) { Boolean[,] bitmap = new bool[map.Width, map.Height]; for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { bitmap[x, y] = true; } } for (int i = 0; i < rounds; i++) { smoothFunction.FloodEffect(map, bitmap, 1.0); } }
public virtual void SaveFile(ITerrainChannel m_channel, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY) { // We need to do this because: // "Saving the image to the same file it was constructed from is not allowed and throws an exception." string tempName = offsetX + "_ " + offsetY + "_" + filename; Bitmap entireBitmap = null; Bitmap thisBitmap = null; if (File.Exists(filename)) { File.Copy(filename, tempName); entireBitmap = new Bitmap(tempName); if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY) { // old file, let's overwrite it entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); } } else { entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); } thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); for (int x = 0; x < regionSizeX; x++) { for (int y = 0; y < regionSizeY; y++) { entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); } } Save(entireBitmap, filename); thisBitmap.Dispose(); entireBitmap.Dispose(); if (File.Exists(tempName)) { File.Delete(tempName); } }
public void SaveStream(Stream s, ITerrainChannel map) { BinaryWriter bs = new BinaryWriter(s); int y; for (y = 0; y < map.Height; y++) { int x; for (x = 0; x < map.Width; x++) { bs.Write((float)map[x, y]); } } bs.Close(); }
public void RunEffect(ITerrainChannel map) { int x, y; for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25f) * 10; float spherFac = TerrainUtil.SphericalFactor(x, y, map.Scene.RegionInfo.RegionSizeX / 2, map.Scene.RegionInfo.RegionSizeY / 2, 50) * 0.01f; if (map[x, y] < spherFac) { map[x, y] = spherFac; } } } }
public void RunEffect(ITerrainChannel map) { int x, y; for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; double spherFac = TerrainUtil.SphericalFactor(x, y, map.Width / 2, map.Height / 2, 50) * 0.01; if (map[x, y] < spherFac) { map[x, y] = spherFac; } } } }
protected void applyModification(ITerrainChannel map, TerrainModifierData data) { bool[,] mask; int xMax; int yMax; int xMid; int yMid; if (data.shape == "ellipse") { mask = this.ellipticalMask(data.dx, data.dy); xMax = mask.GetLength(0); yMax = mask.GetLength(1); xMid = xMax / 2 + xMax % 2; yMid = yMax / 2 + yMax % 2; } else { mask = this.rectangularMask(data.dx, data.dy); xMax = mask.GetLength(0); yMax = mask.GetLength(1); xMid = 0; yMid = 0; } // m_log.DebugFormat("Apply {0} mask {1}x{2} @ {3},{4}", data.shape, xMax, yMax, xMid, yMid); double[,] buffer = map.GetDoubles(); int yDim = yMax; while (--yDim >= 0) { int yPos = data.y0 + yDim - yMid; if ((yPos >= 0) && (yPos < map.Height)) { int xDim = xMax; while (--xDim >= 0) { int xPos = data.x0 + xDim - xMid; if ((xPos >= 0) && (xPos < map.Width) && (mask[xDim, yDim])) { double endElevation = this.operate(buffer, data, xPos, yPos); map[xPos, yPos] = endElevation; } } } } }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength, int startX, int endX, int startY, int endY) { int x, y; for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (fillArea[x, y]) { double noise = TerrainUtil.PerlinNoise2D((double)x / map.Width, (double)y / map.Height, 8, 1.0); map[x, y] += noise * strength; } } } }
public void FloodEffect(ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { for (int x = (int)west; x < (int)east; x++) { for (int y = (int)south; y < (int)north; y++) { if (!((Scene)map.Scene).Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) { continue; } float noise = TerrainUtil.PerlinNoise2D(x / map.Scene.RegionInfo.RegionSizeX, y / map.Scene.RegionInfo.RegionSizeY, 8, 1); map[x, y] += noise * strength; } } }
private static IScene FindScene(ITerrainChannel map, List <IScene> scenes, int X, int Y) { int RegX = map.Scene.RegionInfo.RegionLocX + X; int RegY = map.Scene.RegionInfo.RegionLocY + Y; #if (!ISWIN) foreach (IScene scene in scenes) { if (scene.RegionInfo.RegionLocX == RegX && scene.RegionInfo.RegionLocY == RegY) { return(scene); } } return(null); #else return(scenes.FirstOrDefault(scene => scene.RegionInfo.RegionLocX == RegX && scene.RegionInfo.RegionLocY == RegY)); #endif }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) { int x; for (x = 0; x < map.Width; x++) { int y; for (y = 0; y < map.Height; y++) { if (fillArea[x, y]) { double noise = TerrainUtil.PerlinNoise2D((double)x / map.Width, (double)y / map.Height, 8, 1.0); map[x, y] += noise * strength; } } } }
public LSL_Float llGround(LSL_Vector offset) { if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID)) { return(new LSL_Float()); } Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x, (float)offset.y, (float)offset.z); //Get the slope normal. This gives us the equation of the plane tangent to the slope. LSL_Vector vsn = llGroundNormal(offset); ITerrainChannel heightmap = World.RequestModuleInterface <ITerrainChannel>(); // Clamp to valid position if (pos.X < 0) { pos.X = 0; } else if (pos.X >= heightmap.Width) { pos.X = heightmap.Width - 1; } if (pos.Y < 0) { pos.Y = 0; } else if (pos.Y >= heightmap.Height) { pos.Y = heightmap.Height - 1; } //Get the height for the integer coordinates from the Heightmap float baseheight = heightmap[(int)pos.X, (int)pos.Y]; //Calculate the difference between the actual coordinates and the integer coordinates float xdiff = pos.X - (int)pos.X; float ydiff = pos.Y - (int)pos.Y; //Use the equation of the tangent plane to adjust the height to account for slope return((((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight); }
public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { strength *= 0.04f; if (strength > 1.0f) { strength = 1.0f; } for (int x = startX; x <= endX; x++) { for (int y = startY; y <= endY; y++) { if (fillArea[x, y]) { map[x, y] = (map[x, y] * (1.0f - strength)) + (height * strength); } } } }
private static double GetBilinearInterpolate(double x, double y, ITerrainChannel map) { int w = map.Width; int h = map.Height; if (x > w - 2.0) { x = w - 2.0; } if (y > h - 2.0) { y = h - 2.0; } if (x < 0.0) { x = 0.0; } if (y < 0.0) { y = 0.0; } const int stepSize = 1; double h00 = map[(int)x, (int)y]; double h10 = map[(int)x + stepSize, (int)y]; double h01 = map[(int)x, (int)y + stepSize]; double h11 = map[(int)x + stepSize, (int)y + stepSize]; double h1 = h00; double h2 = h10; double h3 = h01; double h4 = h11; double a00 = h1; double a10 = h2 - h1; double a01 = h3 - h1; double a11 = h1 - h2 - h3 + h4; double partialx = x - (int)x; double partialz = y - (int)y; double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); return(hi); }
public void FloodEffect(ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { float area = strength; float step = strength / 4; for (int x = (int)west; x < (int)east; x++) { for (int y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) { continue; } float average = 0; int avgsteps = 0; float n; for (n = 0 - area; n < area; n += step) { float l; for (l = 0 - area; l < area; l += step) { avgsteps++; average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); } } if (avgsteps > 0) { map [x, y] = average / avgsteps; } else { map [x, y] = 0; } } } }
/// <summary> /// Protected method, generates a coloured bitmap /// image from a specified terrain channel. /// </summary> /// <param name="map">The terrain channel to export to bitmap</param> /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> protected static Bitmap CreateBitmapFromMap(ITerrainChannel map) { int pallete; Bitmap bmp; Color[] colours; using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png")) { pallete = gradientmapLd.Height; bmp = new Bitmap(map.Width, map.Height); colours = new Color[pallete]; for (int i = 0; i < pallete; i++) { colours[i] = gradientmapLd.GetPixel(0, i); } } for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { // 512 is the largest possible height before colours clamp int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); // Handle error conditions if (colorindex > pallete - 1 || colorindex < 0) { bmp.SetPixel(x, map.Height - y - 1, Color.Red); } else { bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); } } } return(bmp); }
/// <summary> /// Protected method, generates a grayscale bitmap /// image from a specified terrain channel. /// </summary> /// <param name="map">The terrain channel to export to bitmap</param> /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) { // Bitmap bmp = new Bitmap(map.Width, map.Height, PixelFormat.Format24bppRgb); Bitmap bmp = new Bitmap(map.Width, map.Height); const int pallete = 256; Color[] grays = new Color[pallete]; for (int i = 0; i < grays.Length; i++) { grays[i] = Color.FromArgb(i, i, i); } for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { // to change this, loading also needs change // int colorindex = (int)map[x, y]; // one to one conversion 0 - 255m range // int colorindex = (int)map[x, y] / 2; // 0 - 510 range int colorindex = (int)map[x, y] * 2; // the original 0 - 127.5 range // clamp it not adding the red warning if (colorindex < 0) { colorindex = 0; } else if (colorindex >= pallete) { colorindex = pallete - 1; } bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); } } return(bmp); }
public void RunEffect(ITerrainChannel map) { int x, y; int cx = map.Width / 2; int cy = map.Height / 2; float h; float b; for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { h = 25 * TerrainUtil.SphericalFactor(x - cx, y - cy, 50); b = 10 * TerrainUtil.SphericalFactor(x - cx, y - cy, 100); if (h < b) { h = b; } map[x, y] = h; } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, float rx, float ry, float rz, float size, float strength, int startX, int endX, int startY, int endY) { if (strength < 0) { return; } if (strength > 1.0f) { strength = 1.0f; } int x, y; float distancefactor; float dx2; for (x = startX; x <= endX; x++) { dx2 = (x - rx) * (x - rx); for (y = startY; y <= endY; y++) { if (!mask[x, y]) { continue; } // Calculate a sphere and add it to the heighmap distancefactor = (dx2 + (y - ry) * (y - ry)) / size; if (distancefactor > 1.0f) { continue; } distancefactor = strength * (1.0f - distancefactor); map[x, y] = (map[x, y] * (1.0f - distancefactor)) + (m_revertmap[x, y] * distancefactor); } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) { strength = TerrainUtil.MetersToSphericalStrength(strength); duration = 0.03; //MCP Should be read from ini file if (duration > 1.0) { duration = 1.0; } if (duration < 0) { return; } int x; for (x = 0; x < map.Width; x++) { int y; for (y = 0; y < map.Height; y++) { if (!mask[x, y]) { continue; } // Calculate a sphere and add it to the heighmap double z = strength; z *= z; z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); if (z > 0.0) { z *= duration; map[x, y] = (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); } } } }
/// <summary> /// reverts an area of the map to the heightfield stored in the revertmap /// </summary> /// <param name="map">the current heightmap</param> /// <param name="fillArea">array indicating which sections of the map are to be reverted</param> /// <param name="strength">unused</param> public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { int x, y; strength *= 2f; if (strength > 1.0f) { strength = 1.0f; } for (x = startX; x <= endX; x++) { for (y = startY; y <= endY; y++) { if (fillArea[x, y]) { map[x, y] = map[x, y] * (1.0f - strength) + m_revertmap[x, y] * strength; } } } }
public void PaintEffect(ITerrainChannel map, bool[,] mask, float rx, float ry, float rz, float size, float strength, int startX, int endX, int startY, int endY) { int x, y; float distancefactor; float dx2; size *= 2 * size; // blend in map for (x = startX; x <= endX; ++x) { dx2 = (x - rx) * (x - rx); for (y = startY; y <= endY; ++y) { if (!mask[x, y]) { continue; } distancefactor = (dx2 + (y - ry) * (y - ry)) / size; if (distancefactor > 1.0f) { continue; } distancefactor = strength * (1.0f - distancefactor); if (distancefactor >= 1.0f) { map[x, y] = rz; } else { map[x, y] += (rz - (float)map[x, y]) * distancefactor; } } } }
public void FloodEffect(ITerrainChannel map, UUID userID, float north, float west, float south, float east, float strength) { float sum = 0; float steps = 0; int x, y; for (x = (int)west; x < (int)east; x++) { for (y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) { continue; } sum += map[x, y]; steps += 1; } } float avg = sum / steps; float str = 0.1f * strength; // == 0.2 in the default client for (x = (int)west; x < (int)east; x++) { for (y = (int)south; y < (int)north; y++) { if (!map.Scene.Permissions.CanTerraformLand(userID, new Vector3(x, y, 0))) { continue; } map[x, y] = (map[x, y] * (1 - str)) + (avg * str); } } }