restrict terrain PaintBrushes to the requested area
parent
f9efa23d5e
commit
bd4ec5f26c
|
@ -31,6 +31,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
|
|||
{
|
||||
public interface ITerrainPaintableEffect
|
||||
{
|
||||
void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z, double strength, double duration);
|
||||
void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z,
|
||||
double strength, double duration, int startX, int endX, int startY, int endY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,7 +151,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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);
|
||||
|
||||
|
@ -163,18 +164,23 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height);
|
||||
|
||||
// Fill with rain
|
||||
for (x = 0; x < water.Width; x++)
|
||||
for (y = 0; y < water.Height; y++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (mask[x, y])
|
||||
water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < rounds; i++)
|
||||
{
|
||||
// Erode underlying terrain
|
||||
for (x = 0; x < water.Width; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
for (y = 0; y < water.Height; y++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (mask[x,y])
|
||||
if (mask[x, y])
|
||||
{
|
||||
const double solConst = (1.0 / rounds);
|
||||
double sedDelta = water[x, y] * solConst;
|
||||
|
@ -185,9 +191,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
}
|
||||
|
||||
// Move water
|
||||
for (x = 0; x < water.Width; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
for (y = 0; y < water.Height; y++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (water[x, y] <= 0)
|
||||
continue;
|
||||
|
@ -296,7 +302,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
double sedimentDeposit = sediment[x, y] - waterCapacity;
|
||||
if (sedimentDeposit > 0)
|
||||
{
|
||||
if (mask[x,y])
|
||||
if (mask[x, y])
|
||||
{
|
||||
sediment[x, y] -= sedimentDeposit;
|
||||
map[x, y] += sedimentDeposit;
|
||||
|
@ -309,10 +315,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
// Deposit any remainder (should be minimal)
|
||||
for (x = 0; x < water.Width; x++)
|
||||
for (y = 0; y < water.Height; y++)
|
||||
if (mask[x,y] && sediment[x, y] > 0)
|
||||
if (mask[x, y] && sediment[x, y] > 0)
|
||||
map[x, y] += sediment[x, y];
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
{
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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);
|
||||
|
||||
|
|
|
@ -34,34 +34,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
{
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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;
|
||||
int xFrom = (int)(rx-s+0.5);
|
||||
int xTo = (int)(rx+s+0.5) + 1;
|
||||
int yFrom = (int)(ry-s+0.5);
|
||||
int yTo = (int)(ry+s+0.5) + 1;
|
||||
int x, y;
|
||||
|
||||
if (xFrom < 0)
|
||||
xFrom = 0;
|
||||
|
||||
if (yFrom < 0)
|
||||
yFrom = 0;
|
||||
|
||||
if (xTo > map.Width)
|
||||
xTo = map.Width;
|
||||
|
||||
if (yTo > map.Width)
|
||||
yTo = map.Width;
|
||||
|
||||
for (x = xFrom; x < xTo; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
int y;
|
||||
for (y = yFrom; y < yTo; y++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (!mask[x,y])
|
||||
if (!mask[x, y])
|
||||
continue;
|
||||
|
||||
// Calculate a cos-sphere and add it to the heighmap
|
||||
|
|
|
@ -35,17 +35,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
{
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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;
|
||||
for (x = 0; x < map.Width; x++)
|
||||
int x, y;
|
||||
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
int y;
|
||||
for (y = 0; y < map.Height; y++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (!mask[x,y])
|
||||
if (!mask[x, y])
|
||||
continue;
|
||||
|
||||
// Calculate a sphere and add it to the heighmap
|
||||
|
|
|
@ -152,18 +152,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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;
|
||||
int x, y;
|
||||
|
||||
for (x = 0; x < map.Width; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
int y;
|
||||
for (y = 0; y < map.Height; y++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (!mask[x,y])
|
||||
if (!mask[x, y])
|
||||
continue;
|
||||
|
||||
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
|
||||
|
|
|
@ -35,38 +35,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
#region ITerrainPaintableEffect Members
|
||||
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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;
|
||||
int xFrom = (int)(rx-s+0.5);
|
||||
int xTo = (int)(rx+s+0.5) + 1;
|
||||
int yFrom = (int)(ry-s+0.5);
|
||||
int yTo = (int)(ry+s+0.5) + 1;
|
||||
int x,y;
|
||||
|
||||
if (xFrom < 0)
|
||||
xFrom = 0;
|
||||
|
||||
if (yFrom < 0)
|
||||
yFrom = 0;
|
||||
|
||||
if (xTo > map.Width)
|
||||
xTo = map.Width;
|
||||
|
||||
if (yTo > map.Width)
|
||||
yTo = map.Width;
|
||||
|
||||
for (x = xFrom; x < xTo; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
int y;
|
||||
for (y = yFrom; y < yTo; y++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
if (!mask[x,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 r = Math.Sqrt((x - rx) * (x - rx) + ((y - ry) * (y - ry)));
|
||||
double z = Math.Cos(r * Math.PI / (s * 2));
|
||||
if (z > 0.0)
|
||||
map[x, y] += z * duration;
|
||||
|
|
|
@ -41,7 +41,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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);
|
||||
duration = 0.03; //MCP Should be read from ini file
|
||||
|
@ -51,13 +52,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
if (duration < 0)
|
||||
return;
|
||||
|
||||
int x;
|
||||
for (x = 0; x < map.Width; x++)
|
||||
int x,y;
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
int y;
|
||||
for (y = 0; y < map.Height; y++)
|
||||
for (y = startY; y < endY; y++)
|
||||
{
|
||||
if (!mask[x,y])
|
||||
if (!mask[x, y])
|
||||
continue;
|
||||
|
||||
// Calculate a sphere and add it to the heighmap
|
||||
|
|
|
@ -34,7 +34,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
{
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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);
|
||||
|
||||
|
@ -47,10 +48,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
|
||||
|
||||
// compute delta map
|
||||
for (x = 0; x < map.Width; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
for (y = 0; y < map.Height; y++)
|
||||
for (y = startY; y < endY; y++)
|
||||
{
|
||||
if (!mask[x, y])
|
||||
continue;
|
||||
|
||||
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
|
||||
|
||||
if (z > 0) // add in non-zero amount
|
||||
|
@ -73,11 +77,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
}
|
||||
}
|
||||
// blend in map
|
||||
for (x = 0; x < map.Width; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
for (y = 0; y < map.Height; y++)
|
||||
for (y = startY; y < endY; y++)
|
||||
{
|
||||
if (!mask[x,y])
|
||||
if (!mask[x, y])
|
||||
continue;
|
||||
|
||||
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
|
||||
|
|
|
@ -148,16 +148,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
|
|||
|
||||
#region ITerrainPaintableEffect Members
|
||||
|
||||
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double 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;
|
||||
int x,y;
|
||||
|
||||
for (x = 0; x < map.Width; x++)
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
int y;
|
||||
for (y = 0; y < map.Height; y++)
|
||||
for (y = startY; y < endY; y++)
|
||||
{
|
||||
if (!mask[x,y])
|
||||
continue;
|
||||
|
|
|
@ -1128,28 +1128,41 @@ namespace OpenSim.Region.CoreModules.World.Terrain
|
|||
int zx = (int) (west + 0.5);
|
||||
int zy = (int) (north + 0.5);
|
||||
|
||||
int dx,dy;
|
||||
for (dx=-n; dx<=n; dx++)
|
||||
|
||||
int startX = zx - n;
|
||||
if (startX < 0)
|
||||
startX = 0;
|
||||
|
||||
int startY = zy - n;
|
||||
if (startY < 0)
|
||||
startY = 0;
|
||||
|
||||
int endX = zx + n;
|
||||
if (endX >= m_channel.Width)
|
||||
endX = m_channel.Width - 1;
|
||||
int endY = zy + n;
|
||||
if (endY >= m_channel.Height)
|
||||
endY = m_channel.Height - 1;
|
||||
|
||||
int x, y;
|
||||
|
||||
for (x = startX; x <= endX; x++)
|
||||
{
|
||||
for (dy=-n; dy<=n; dy++)
|
||||
for (y = startY; y <= endY; y++)
|
||||
{
|
||||
int x = zx + dx;
|
||||
int y = zy + dy;
|
||||
if (x>=0 && y>=0 && x<m_channel.Width && y<m_channel.Height)
|
||||
{
|
||||
if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x,y,0)))
|
||||
if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
|
||||
{
|
||||
allowMask[x, y] = true;
|
||||
allowed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allowed)
|
||||
{
|
||||
StoreUndoState();
|
||||
m_painteffects[(StandardTerrainEffects) action].PaintEffect(
|
||||
m_channel, allowMask, west, south, height, size, seconds);
|
||||
m_channel, allowMask, west, south, height, size, seconds,
|
||||
startX, endX, startY, endY);
|
||||
|
||||
//block changes outside estate limits
|
||||
if (!god)
|
||||
|
|
|
@ -60,7 +60,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
|
|||
TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
|
||||
ITerrainPaintableEffect effect = new RaiseSphere();
|
||||
|
||||
effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0);
|
||||
effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
|
||||
0, midRegion - 1,0, (int)Constants.RegionSize -1);
|
||||
Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128).");
|
||||
Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128).");
|
||||
Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128).");
|
||||
|
@ -79,7 +80,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
|
|||
}
|
||||
effect = new LowerSphere();
|
||||
|
||||
effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0);
|
||||
effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
|
||||
0, (int)Constants.RegionSize -1,0, (int)Constants.RegionSize -1);
|
||||
Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
|
||||
Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
|
||||
Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128).");
|
||||
|
|
Loading…
Reference in New Issue