diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Terrain')
35 files changed, 4474 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/DefaultEffects/ChannelDigger.cs b/OpenSim/Region/CoreModules/World/Terrain/DefaultEffects/ChannelDigger.cs new file mode 100644 index 0000000..f96ab88 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/DefaultEffects/ChannelDigger.cs | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.CoreModules.World.Terrain; | ||
31 | using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; | ||
32 | |||
33 | namespace OpenSim.Region.Modules.Terrain.Extensions.DefaultEffects.Effects | ||
34 | { | ||
35 | public class ChannelDigger : ITerrainEffect | ||
36 | { | ||
37 | private readonly int num_h = 4; | ||
38 | private readonly int num_w = 4; | ||
39 | |||
40 | private readonly ITerrainFloodEffect raiseFunction = new RaiseArea(); | ||
41 | private readonly ITerrainFloodEffect smoothFunction = new SmoothArea(); | ||
42 | |||
43 | #region ITerrainEffect Members | ||
44 | |||
45 | public void RunEffect(ITerrainChannel map) | ||
46 | { | ||
47 | FillMap(map, 15); | ||
48 | BuildTiles(map, 7); | ||
49 | SmoothMap(map, 3); | ||
50 | } | ||
51 | |||
52 | #endregion | ||
53 | |||
54 | private void SmoothMap(ITerrainChannel map, int rounds) | ||
55 | { | ||
56 | Boolean[,] bitmap = new bool[map.Width,map.Height]; | ||
57 | for (int x = 0; x < map.Width; x++) | ||
58 | { | ||
59 | for (int y = 0; y < map.Height; y++) | ||
60 | { | ||
61 | bitmap[x, y] = true; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | for (int i = 0; i < rounds; i++) | ||
66 | { | ||
67 | smoothFunction.FloodEffect(map, bitmap, 1.0); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | private void FillMap(ITerrainChannel map, double val) | ||
72 | { | ||
73 | for (int x = 0; x < map.Width; x++) | ||
74 | for (int y = 0; y < map.Height; y++) | ||
75 | map[x, y] = val; | ||
76 | } | ||
77 | |||
78 | private void BuildTiles(ITerrainChannel map, double height) | ||
79 | { | ||
80 | int channelWidth = (int) Math.Floor((map.Width / num_w) * 0.8); | ||
81 | int channelHeight = (int) Math.Floor((map.Height / num_h) * 0.8); | ||
82 | int channelXOffset = (map.Width / num_w) - channelWidth; | ||
83 | int channelYOffset = (map.Height / num_h) - channelHeight; | ||
84 | |||
85 | for (int x = 0; x < num_w; x++) | ||
86 | { | ||
87 | for (int y = 0; y < num_h; y++) | ||
88 | { | ||
89 | int xoff = ((channelXOffset + channelWidth) * x) + (channelXOffset / 2); | ||
90 | int yoff = ((channelYOffset + channelHeight) * y) + (channelYOffset / 2); | ||
91 | |||
92 | Boolean[,] bitmap = new bool[map.Width,map.Height]; | ||
93 | |||
94 | for (int dx = 0; dx < channelWidth; dx++) | ||
95 | { | ||
96 | for (int dy = 0; dy < channelHeight; dy++) | ||
97 | { | ||
98 | bitmap[dx + xoff, dy + yoff] = true; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | raiseFunction.FloodEffect(map, bitmap, height); | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs new file mode 100644 index 0000000..cb8112c --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | using OpenSim.Region.Framework.Scenes; | ||
30 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.Effects | ||
33 | { | ||
34 | internal class CookieCutter : ITerrainEffect | ||
35 | { | ||
36 | #region ITerrainEffect Members | ||
37 | |||
38 | public void RunEffect(ITerrainChannel map) | ||
39 | { | ||
40 | ITerrainPaintableEffect eroder = new WeatherSphere(); | ||
41 | |||
42 | bool[,] cliffMask = new bool[map.Width,map.Height]; | ||
43 | bool[,] channelMask = new bool[map.Width,map.Height]; | ||
44 | bool[,] smoothMask = new bool[map.Width,map.Height]; | ||
45 | bool[,] allowMask = new bool[map.Width,map.Height]; | ||
46 | |||
47 | Console.WriteLine("S1"); | ||
48 | |||
49 | // Step one, generate rough mask | ||
50 | int x, y; | ||
51 | for (x = 0; x < map.Width; x++) | ||
52 | { | ||
53 | for (y = 0; y < map.Height; y++) | ||
54 | { | ||
55 | Console.Write("."); | ||
56 | smoothMask[x, y] = true; | ||
57 | allowMask[x,y] = true; | ||
58 | |||
59 | // Start underwater | ||
60 | map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 5; | ||
61 | // Add a little height. (terrain should now be above water, mostly.) | ||
62 | map[x, y] += 20; | ||
63 | |||
64 | const int channelsX = 4; | ||
65 | int channelWidth = (map.Width / channelsX / 4); | ||
66 | const int channelsY = 4; | ||
67 | int channelHeight = (map.Height / channelsY / 4); | ||
68 | |||
69 | SetLowerChannel(map, cliffMask, channelMask, x, y, channelsX, channelWidth, map.Width, x); | ||
70 | SetLowerChannel(map, cliffMask, channelMask, x, y, channelsY, channelHeight, map.Height, y); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | Console.WriteLine("S2"); | ||
75 | //smooth.FloodEffect(map, smoothMask, 4.0); | ||
76 | |||
77 | Console.WriteLine("S3"); | ||
78 | for (x = 0; x < map.Width; x++) | ||
79 | { | ||
80 | for (y = 0; y < map.Height; y++) | ||
81 | { | ||
82 | if (cliffMask[x, y]) | ||
83 | eroder.PaintEffect(map, allowMask, x, y, -1, 4, 0.1); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | for (x = 0; x < map.Width; x += 2) | ||
88 | { | ||
89 | for (y = 0; y < map.Height; y += 2) | ||
90 | { | ||
91 | if (map[x, y] < 0.1) | ||
92 | map[x, y] = 0.1; | ||
93 | if (map[x, y] > 256) | ||
94 | map[x, y] = 256; | ||
95 | } | ||
96 | } | ||
97 | //smooth.FloodEffect(map, smoothMask, 4.0); | ||
98 | } | ||
99 | |||
100 | #endregion | ||
101 | |||
102 | private static void SetLowerChannel(ITerrainChannel map, bool[,] cliffMask, bool[,] channelMask, int x, int y, int numChannels, int channelWidth, | ||
103 | int mapSize, int rp) | ||
104 | { | ||
105 | for (int i = 0; i < numChannels; i++) | ||
106 | { | ||
107 | double distanceToLine = Math.Abs(rp - ((mapSize / numChannels) * i)); | ||
108 | |||
109 | if (distanceToLine < channelWidth) | ||
110 | { | ||
111 | if (channelMask[x, y]) | ||
112 | return; | ||
113 | |||
114 | // Remove channels | ||
115 | map[x, y] -= 10; | ||
116 | channelMask[x, y] = true; | ||
117 | } | ||
118 | if (distanceToLine < 1) | ||
119 | { | ||
120 | cliffMask[x, y] = true; | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs new file mode 100644 index 0000000..da6ee12 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using OpenSim.Framework; | ||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | using OpenSim.Region.Framework.Scenes; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain.Effects | ||
32 | { | ||
33 | internal class DefaultTerrainGenerator : ITerrainEffect | ||
34 | { | ||
35 | #region ITerrainEffect Members | ||
36 | |||
37 | public void RunEffect(ITerrainChannel map) | ||
38 | { | ||
39 | int x, y; | ||
40 | for (x = 0; x < map.Width; x++) | ||
41 | { | ||
42 | for (y = 0; y < map.Height; y++) | ||
43 | { | ||
44 | map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; | ||
45 | double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01; | ||
46 | if (map[x, y] < spherFac) | ||
47 | { | ||
48 | map[x, y] = spherFac; | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | #endregion | ||
55 | } | ||
56 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs new file mode 100644 index 0000000..4f395b5 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Drawing; | ||
29 | using System.Drawing.Imaging; | ||
30 | using System.IO; | ||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// A generic windows bitmap loader. | ||
37 | /// Should be capable of handling 24-bit RGB images. | ||
38 | /// | ||
39 | /// Uses the System.Drawing filesystem loader. | ||
40 | /// </summary> | ||
41 | internal class BMP : GenericSystemDrawing | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// Exports a file to a image on the disk using a System.Drawing exporter. | ||
45 | /// </summary> | ||
46 | /// <param name="filename">The target filename</param> | ||
47 | /// <param name="map">The terrain channel being saved</param> | ||
48 | public override void SaveFile(string filename, ITerrainChannel map) | ||
49 | { | ||
50 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
51 | |||
52 | colours.Save(filename, ImageFormat.Bmp); | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Exports a stream using a System.Drawing exporter. | ||
57 | /// </summary> | ||
58 | /// <param name="stream">The target stream</param> | ||
59 | /// <param name="map">The terrain channel being saved</param> | ||
60 | public override void SaveStream(Stream stream, ITerrainChannel map) | ||
61 | { | ||
62 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
63 | |||
64 | colours.Save(stream, ImageFormat.Png); | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// The human readable version of the file format(s) this loader handles | ||
69 | /// </summary> | ||
70 | /// <returns></returns> | ||
71 | public override string ToString() | ||
72 | { | ||
73 | return "BMP"; | ||
74 | } | ||
75 | } | ||
76 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs new file mode 100644 index 0000000..cff82d1 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Drawing; | ||
29 | using System.Drawing.Imaging; | ||
30 | using System.IO; | ||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | internal class GIF : GenericSystemDrawing | ||
36 | { | ||
37 | public override void SaveFile(string filename, ITerrainChannel map) | ||
38 | { | ||
39 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
40 | |||
41 | colours.Save(filename, ImageFormat.Gif); | ||
42 | } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Exports a stream using a System.Drawing exporter. | ||
46 | /// </summary> | ||
47 | /// <param name="stream">The target stream</param> | ||
48 | /// <param name="map">The terrain channel being saved</param> | ||
49 | public override void SaveStream(Stream stream, ITerrainChannel map) | ||
50 | { | ||
51 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
52 | |||
53 | colours.Save(stream, ImageFormat.Gif); | ||
54 | } | ||
55 | |||
56 | public override string ToString() | ||
57 | { | ||
58 | return "GIF"; | ||
59 | } | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs new file mode 100644 index 0000000..477c73c --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Drawing; | ||
30 | using System.Drawing.Imaging; | ||
31 | using System.IO; | ||
32 | using OpenSim.Region.Framework.Interfaces; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | |||
35 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A virtual class designed to have methods overloaded, | ||
39 | /// this class provides an interface for a generic image | ||
40 | /// saving and loading mechanism, but does not specify the | ||
41 | /// format. It should not be insubstantiated directly. | ||
42 | /// </summary> | ||
43 | public class GenericSystemDrawing : ITerrainLoader | ||
44 | { | ||
45 | #region ITerrainLoader Members | ||
46 | |||
47 | public string FileExtension | ||
48 | { | ||
49 | get { return ".gsd"; } | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Loads a file from a specified filename on the disk, | ||
54 | /// parses the image using the System.Drawing parsers | ||
55 | /// then returns a terrain channel. Values are | ||
56 | /// returned based on HSL brightness between 0m and 128m | ||
57 | /// </summary> | ||
58 | /// <param name="filename">The target image to load</param> | ||
59 | /// <returns>A terrain channel generated from the image.</returns> | ||
60 | public virtual ITerrainChannel LoadFile(string filename) | ||
61 | { | ||
62 | return LoadBitmap(new Bitmap(filename)); | ||
63 | } | ||
64 | |||
65 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
66 | { | ||
67 | throw new NotImplementedException(); | ||
68 | } | ||
69 | |||
70 | public virtual ITerrainChannel LoadStream(Stream stream) | ||
71 | { | ||
72 | return LoadBitmap(new Bitmap(stream)); | ||
73 | } | ||
74 | |||
75 | protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap) | ||
76 | { | ||
77 | ITerrainChannel retval = new TerrainChannel(bitmap.Width, bitmap.Height); | ||
78 | |||
79 | int x; | ||
80 | for (x = 0; x < bitmap.Width; x++) | ||
81 | { | ||
82 | int y; | ||
83 | for (y = 0; y < bitmap.Height; y++) | ||
84 | { | ||
85 | retval[x, y] = bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness() * 128; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | return retval; | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Exports a file to a image on the disk using a System.Drawing exporter. | ||
94 | /// </summary> | ||
95 | /// <param name="filename">The target filename</param> | ||
96 | /// <param name="map">The terrain channel being saved</param> | ||
97 | public virtual void SaveFile(string filename, ITerrainChannel map) | ||
98 | { | ||
99 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
100 | |||
101 | colours.Save(filename, ImageFormat.Png); | ||
102 | } | ||
103 | |||
104 | /// <summary> | ||
105 | /// Exports a stream using a System.Drawing exporter. | ||
106 | /// </summary> | ||
107 | /// <param name="stream">The target stream</param> | ||
108 | /// <param name="map">The terrain channel being saved</param> | ||
109 | public virtual void SaveStream(Stream stream, ITerrainChannel map) | ||
110 | { | ||
111 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
112 | |||
113 | colours.Save(stream, ImageFormat.Png); | ||
114 | } | ||
115 | |||
116 | #endregion | ||
117 | |||
118 | public override string ToString() | ||
119 | { | ||
120 | return "SYS.DRAWING"; | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// Protected method, generates a grayscale bitmap | ||
125 | /// image from a specified terrain channel. | ||
126 | /// </summary> | ||
127 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
128 | /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> | ||
129 | protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) | ||
130 | { | ||
131 | Bitmap bmp = new Bitmap(map.Width, map.Height); | ||
132 | |||
133 | const int pallete = 256; | ||
134 | |||
135 | Color[] grays = new Color[pallete]; | ||
136 | for (int i = 0; i < grays.Length; i++) | ||
137 | { | ||
138 | grays[i] = Color.FromArgb(i, i, i); | ||
139 | } | ||
140 | |||
141 | for (int y = 0; y < map.Height; y++) | ||
142 | { | ||
143 | for (int x = 0; x < map.Width; x++) | ||
144 | { | ||
145 | // 512 is the largest possible height before colours clamp | ||
146 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); | ||
147 | |||
148 | // Handle error conditions | ||
149 | if (colorindex > pallete - 1 || colorindex < 0) | ||
150 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
151 | else | ||
152 | bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); | ||
153 | } | ||
154 | } | ||
155 | return bmp; | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Protected method, generates a coloured bitmap | ||
160 | /// image from a specified terrain channel. | ||
161 | /// </summary> | ||
162 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
163 | /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> | ||
164 | protected static Bitmap CreateBitmapFromMap(ITerrainChannel map) | ||
165 | { | ||
166 | Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); | ||
167 | |||
168 | int pallete = gradientmapLd.Height; | ||
169 | |||
170 | Bitmap bmp = new Bitmap(map.Width, map.Height); | ||
171 | Color[] colours = new Color[pallete]; | ||
172 | |||
173 | for (int i = 0; i < pallete; i++) | ||
174 | { | ||
175 | colours[i] = gradientmapLd.GetPixel(0, i); | ||
176 | } | ||
177 | |||
178 | for (int y = 0; y < map.Height; y++) | ||
179 | { | ||
180 | for (int x = 0; x < map.Width; x++) | ||
181 | { | ||
182 | // 512 is the largest possible height before colours clamp | ||
183 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
184 | |||
185 | // Handle error conditions | ||
186 | if (colorindex > pallete - 1 || colorindex < 0) | ||
187 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
188 | else | ||
189 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | ||
190 | } | ||
191 | } | ||
192 | return bmp; | ||
193 | } | ||
194 | } | ||
195 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs new file mode 100644 index 0000000..f8e31f8 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Drawing; | ||
30 | using System.Drawing.Imaging; | ||
31 | using System.IO; | ||
32 | using OpenSim.Region.Framework.Interfaces; | ||
33 | |||
34 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
35 | { | ||
36 | public class JPEG : ITerrainLoader | ||
37 | { | ||
38 | #region ITerrainLoader Members | ||
39 | |||
40 | public string FileExtension | ||
41 | { | ||
42 | get { return ".jpg"; } | ||
43 | } | ||
44 | |||
45 | public ITerrainChannel LoadFile(string filename) | ||
46 | { | ||
47 | throw new NotImplementedException(); | ||
48 | } | ||
49 | |||
50 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
51 | { | ||
52 | throw new NotImplementedException(); | ||
53 | } | ||
54 | |||
55 | public ITerrainChannel LoadStream(Stream stream) | ||
56 | { | ||
57 | throw new NotImplementedException(); | ||
58 | } | ||
59 | |||
60 | public void SaveFile(string filename, ITerrainChannel map) | ||
61 | { | ||
62 | Bitmap colours = CreateBitmapFromMap(map); | ||
63 | |||
64 | colours.Save(filename, ImageFormat.Jpeg); | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Exports a stream using a System.Drawing exporter. | ||
69 | /// </summary> | ||
70 | /// <param name="stream">The target stream</param> | ||
71 | /// <param name="map">The terrain channel being saved</param> | ||
72 | public void SaveStream(Stream stream, ITerrainChannel map) | ||
73 | { | ||
74 | Bitmap colours = CreateBitmapFromMap(map); | ||
75 | |||
76 | colours.Save(stream, ImageFormat.Jpeg); | ||
77 | } | ||
78 | |||
79 | #endregion | ||
80 | |||
81 | public override string ToString() | ||
82 | { | ||
83 | return "JPEG"; | ||
84 | } | ||
85 | |||
86 | private static Bitmap CreateBitmapFromMap(ITerrainChannel map) | ||
87 | { | ||
88 | Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); | ||
89 | |||
90 | int pallete = gradientmapLd.Height; | ||
91 | |||
92 | Bitmap bmp = new Bitmap(map.Width, map.Height); | ||
93 | Color[] colours = new Color[pallete]; | ||
94 | |||
95 | for (int i = 0; i < pallete; i++) | ||
96 | { | ||
97 | colours[i] = gradientmapLd.GetPixel(0, i); | ||
98 | } | ||
99 | |||
100 | for (int y = 0; y < map.Height; y++) | ||
101 | { | ||
102 | for (int x = 0; x < map.Width; x++) | ||
103 | { | ||
104 | // 512 is the largest possible height before colours clamp | ||
105 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
106 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | ||
107 | } | ||
108 | } | ||
109 | return bmp; | ||
110 | } | ||
111 | } | ||
112 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs new file mode 100644 index 0000000..a86ae00 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs | |||
@@ -0,0 +1,250 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using OpenSim.Region.Framework.Interfaces; | ||
31 | using OpenSim.Region.Framework.Scenes; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | public class LLRAW : ITerrainLoader | ||
36 | { | ||
37 | public struct HeightmapLookupValue : IComparable<HeightmapLookupValue> | ||
38 | { | ||
39 | public int Index; | ||
40 | public double Value; | ||
41 | |||
42 | public HeightmapLookupValue(int index, double value) | ||
43 | { | ||
44 | Index = index; | ||
45 | Value = value; | ||
46 | } | ||
47 | |||
48 | public int CompareTo(HeightmapLookupValue val) | ||
49 | { | ||
50 | return Value.CompareTo(val.Value); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | /// <summary>Lookup table to speed up terrain exports</summary> | ||
55 | HeightmapLookupValue[] LookupHeightTable; | ||
56 | |||
57 | public LLRAW() | ||
58 | { | ||
59 | LookupHeightTable = new HeightmapLookupValue[256 * 256]; | ||
60 | |||
61 | for (int i = 0; i < 256; i++) | ||
62 | { | ||
63 | for (int j = 0; j < 256; j++) | ||
64 | { | ||
65 | LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue(i + (j * 256), ((double)i * ((double)j / 128.0d))); | ||
66 | } | ||
67 | } | ||
68 | Array.Sort<HeightmapLookupValue>(LookupHeightTable); | ||
69 | } | ||
70 | |||
71 | #region ITerrainLoader Members | ||
72 | |||
73 | public ITerrainChannel LoadFile(string filename) | ||
74 | { | ||
75 | FileInfo file = new FileInfo(filename); | ||
76 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
77 | ITerrainChannel retval = LoadStream(s); | ||
78 | |||
79 | s.Close(); | ||
80 | |||
81 | return retval; | ||
82 | } | ||
83 | |||
84 | public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) | ||
85 | { | ||
86 | TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); | ||
87 | |||
88 | FileInfo file = new FileInfo(filename); | ||
89 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
90 | BinaryReader bs = new BinaryReader(s); | ||
91 | |||
92 | int currFileYOffset = fileHeight - 1; | ||
93 | |||
94 | // if our region isn't on the first Y section of the areas to be landscaped, then | ||
95 | // advance to our section of the file | ||
96 | while (currFileYOffset > offsetY) | ||
97 | { | ||
98 | // read a whole strip of regions | ||
99 | int heightsToRead = sectionHeight * (fileWidth * sectionWidth); | ||
100 | bs.ReadBytes(heightsToRead * 13); // because there are 13 fun channels | ||
101 | currFileYOffset--; | ||
102 | } | ||
103 | |||
104 | // got to the Y start offset within the file of our region | ||
105 | // so read the file bits associated with our region | ||
106 | int y; | ||
107 | // for each Y within our Y offset | ||
108 | for (y = sectionHeight - 1; y >= 0; y--) | ||
109 | { | ||
110 | int currFileXOffset = 0; | ||
111 | |||
112 | // if our region isn't the first X section of the areas to be landscaped, then | ||
113 | // advance the stream to the X start pos of our section in the file | ||
114 | // i.e. eat X upto where we start | ||
115 | while (currFileXOffset < offsetX) | ||
116 | { | ||
117 | bs.ReadBytes(sectionWidth * 13); | ||
118 | currFileXOffset++; | ||
119 | } | ||
120 | |||
121 | // got to our X offset, so write our regions X line | ||
122 | int x; | ||
123 | for (x = 0; x < sectionWidth; x++) | ||
124 | { | ||
125 | // Read a strip and continue | ||
126 | retval[x, y] = bs.ReadByte() * (bs.ReadByte() / 128.0); | ||
127 | bs.ReadBytes(11); | ||
128 | } | ||
129 | // record that we wrote it | ||
130 | currFileXOffset++; | ||
131 | |||
132 | // if our region isn't the last X section of the areas to be landscaped, then | ||
133 | // advance the stream to the end of this Y column | ||
134 | while (currFileXOffset < fileWidth) | ||
135 | { | ||
136 | // eat the next regions x line | ||
137 | bs.ReadBytes(sectionWidth * 13); //The 13 channels again | ||
138 | currFileXOffset++; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | bs.Close(); | ||
143 | s.Close(); | ||
144 | |||
145 | return retval; | ||
146 | } | ||
147 | |||
148 | public ITerrainChannel LoadStream(Stream s) | ||
149 | { | ||
150 | TerrainChannel retval = new TerrainChannel(); | ||
151 | |||
152 | BinaryReader bs = new BinaryReader(s); | ||
153 | int y; | ||
154 | for (y = 0; y < retval.Height; y++) | ||
155 | { | ||
156 | int x; | ||
157 | for (x = 0; x < retval.Width; x++) | ||
158 | { | ||
159 | retval[x, (retval.Height - 1) - y] = bs.ReadByte() * (bs.ReadByte() / 128.0); | ||
160 | bs.ReadBytes(11); // Advance the stream to next bytes. | ||
161 | } | ||
162 | } | ||
163 | |||
164 | bs.Close(); | ||
165 | |||
166 | return retval; | ||
167 | } | ||
168 | |||
169 | public void SaveFile(string filename, ITerrainChannel map) | ||
170 | { | ||
171 | FileInfo file = new FileInfo(filename); | ||
172 | FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); | ||
173 | SaveStream(s, map); | ||
174 | |||
175 | s.Close(); | ||
176 | } | ||
177 | |||
178 | public void SaveStream(Stream s, ITerrainChannel map) | ||
179 | { | ||
180 | BinaryWriter binStream = new BinaryWriter(s); | ||
181 | |||
182 | // Output the calculated raw | ||
183 | for (int y = 0; y < map.Height; y++) | ||
184 | { | ||
185 | for (int x = 0; x < map.Width; x++) | ||
186 | { | ||
187 | double t = map[x, (map.Height - 1) - y]; | ||
188 | //if height is less than 0, set it to 0 as | ||
189 | //can't save -ve values in a LLRAW file | ||
190 | if (t < 0d) | ||
191 | { | ||
192 | t = 0d; | ||
193 | } | ||
194 | |||
195 | int index = 0; | ||
196 | |||
197 | // The lookup table is pre-sorted, so we either find an exact match or | ||
198 | // the next closest (smaller) match with a binary search | ||
199 | index = Array.BinarySearch<HeightmapLookupValue>(LookupHeightTable, new HeightmapLookupValue(0, t)); | ||
200 | if (index < 0) | ||
201 | index = ~index - 1; | ||
202 | |||
203 | index = LookupHeightTable[index].Index; | ||
204 | |||
205 | byte red = (byte) (index & 0xFF); | ||
206 | byte green = (byte) ((index >> 8) & 0xFF); | ||
207 | const byte blue = 20; | ||
208 | const byte alpha1 = 0; | ||
209 | const byte alpha2 = 0; | ||
210 | const byte alpha3 = 0; | ||
211 | const byte alpha4 = 0; | ||
212 | const byte alpha5 = 255; | ||
213 | const byte alpha6 = 255; | ||
214 | const byte alpha7 = 255; | ||
215 | const byte alpha8 = 255; | ||
216 | byte alpha9 = red; | ||
217 | byte alpha10 = green; | ||
218 | |||
219 | binStream.Write(red); | ||
220 | binStream.Write(green); | ||
221 | binStream.Write(blue); | ||
222 | binStream.Write(alpha1); | ||
223 | binStream.Write(alpha2); | ||
224 | binStream.Write(alpha3); | ||
225 | binStream.Write(alpha4); | ||
226 | binStream.Write(alpha5); | ||
227 | binStream.Write(alpha6); | ||
228 | binStream.Write(alpha7); | ||
229 | binStream.Write(alpha8); | ||
230 | binStream.Write(alpha9); | ||
231 | binStream.Write(alpha10); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | binStream.Close(); | ||
236 | } | ||
237 | |||
238 | public string FileExtension | ||
239 | { | ||
240 | get { return ".raw"; } | ||
241 | } | ||
242 | |||
243 | #endregion | ||
244 | |||
245 | public override string ToString() | ||
246 | { | ||
247 | return "LL/SL RAW"; | ||
248 | } | ||
249 | } | ||
250 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs new file mode 100644 index 0000000..0dea282 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Drawing; | ||
29 | using System.Drawing.Imaging; | ||
30 | using System.IO; | ||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | internal class PNG : GenericSystemDrawing | ||
36 | { | ||
37 | public override void SaveFile(string filename, ITerrainChannel map) | ||
38 | { | ||
39 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
40 | |||
41 | colours.Save(filename, ImageFormat.Png); | ||
42 | } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Exports a stream using a System.Drawing exporter. | ||
46 | /// </summary> | ||
47 | /// <param name="stream">The target stream</param> | ||
48 | /// <param name="map">The terrain channel being saved</param> | ||
49 | public override void SaveStream(Stream stream, ITerrainChannel map) | ||
50 | { | ||
51 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
52 | |||
53 | colours.Save(stream, ImageFormat.Png); | ||
54 | } | ||
55 | |||
56 | public override string ToString() | ||
57 | { | ||
58 | return "PNG"; | ||
59 | } | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs new file mode 100644 index 0000000..178104f --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs | |||
@@ -0,0 +1,170 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
33 | { | ||
34 | public class RAW32 : ITerrainLoader | ||
35 | { | ||
36 | #region ITerrainLoader Members | ||
37 | |||
38 | public string FileExtension | ||
39 | { | ||
40 | get { return ".r32"; } | ||
41 | } | ||
42 | |||
43 | public ITerrainChannel LoadFile(string filename) | ||
44 | { | ||
45 | FileInfo file = new FileInfo(filename); | ||
46 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
47 | ITerrainChannel retval = LoadStream(s); | ||
48 | |||
49 | s.Close(); | ||
50 | |||
51 | return retval; | ||
52 | } | ||
53 | |||
54 | public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) | ||
55 | { | ||
56 | TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); | ||
57 | |||
58 | FileInfo file = new FileInfo(filename); | ||
59 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
60 | BinaryReader bs = new BinaryReader(s); | ||
61 | |||
62 | int currFileYOffset = 0; | ||
63 | |||
64 | // if our region isn't on the first Y section of the areas to be landscaped, then | ||
65 | // advance to our section of the file | ||
66 | while (currFileYOffset < offsetY) | ||
67 | { | ||
68 | // read a whole strip of regions | ||
69 | int heightsToRead = sectionHeight * (fileWidth * sectionWidth); | ||
70 | bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file | ||
71 | currFileYOffset++; | ||
72 | } | ||
73 | |||
74 | // got to the Y start offset within the file of our region | ||
75 | // so read the file bits associated with our region | ||
76 | int y; | ||
77 | // for each Y within our Y offset | ||
78 | for (y = 0; y < sectionHeight; y++) | ||
79 | { | ||
80 | int currFileXOffset = 0; | ||
81 | |||
82 | // if our region isn't the first X section of the areas to be landscaped, then | ||
83 | // advance the stream to the X start pos of our section in the file | ||
84 | // i.e. eat X upto where we start | ||
85 | while (currFileXOffset < offsetX) | ||
86 | { | ||
87 | bs.ReadBytes(sectionWidth * 4); // 4 bytes = single | ||
88 | currFileXOffset++; | ||
89 | } | ||
90 | |||
91 | // got to our X offset, so write our regions X line | ||
92 | int x; | ||
93 | for (x = 0; x < sectionWidth; x++) | ||
94 | { | ||
95 | // Read a strip and continue | ||
96 | retval[x, y] = bs.ReadSingle(); | ||
97 | } | ||
98 | // record that we wrote it | ||
99 | currFileXOffset++; | ||
100 | |||
101 | // if our region isn't the last X section of the areas to be landscaped, then | ||
102 | // advance the stream to the end of this Y column | ||
103 | while (currFileXOffset < fileWidth) | ||
104 | { | ||
105 | // eat the next regions x line | ||
106 | bs.ReadBytes(sectionWidth * 4); // 4 bytes = single | ||
107 | currFileXOffset++; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | bs.Close(); | ||
112 | s.Close(); | ||
113 | |||
114 | return retval; | ||
115 | } | ||
116 | |||
117 | public ITerrainChannel LoadStream(Stream s) | ||
118 | { | ||
119 | TerrainChannel retval = new TerrainChannel(); | ||
120 | |||
121 | BinaryReader bs = new BinaryReader(s); | ||
122 | int y; | ||
123 | for (y = 0; y < retval.Height; y++) | ||
124 | { | ||
125 | int x; | ||
126 | for (x = 0; x < retval.Width; x++) | ||
127 | { | ||
128 | retval[x, y] = bs.ReadSingle(); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | bs.Close(); | ||
133 | |||
134 | return retval; | ||
135 | } | ||
136 | |||
137 | public void SaveFile(string filename, ITerrainChannel map) | ||
138 | { | ||
139 | FileInfo file = new FileInfo(filename); | ||
140 | FileStream s = file.Open(FileMode.Create, FileAccess.Write); | ||
141 | SaveStream(s, map); | ||
142 | |||
143 | s.Close(); | ||
144 | } | ||
145 | |||
146 | public void SaveStream(Stream s, ITerrainChannel map) | ||
147 | { | ||
148 | BinaryWriter bs = new BinaryWriter(s); | ||
149 | |||
150 | int y; | ||
151 | for (y = 0; y < map.Height; y++) | ||
152 | { | ||
153 | int x; | ||
154 | for (x = 0; x < map.Width; x++) | ||
155 | { | ||
156 | bs.Write((float) map[x, y]); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | bs.Close(); | ||
161 | } | ||
162 | |||
163 | #endregion | ||
164 | |||
165 | public override string ToString() | ||
166 | { | ||
167 | return "RAW32"; | ||
168 | } | ||
169 | } | ||
170 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs new file mode 100644 index 0000000..220431f --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Drawing; | ||
29 | using System.Drawing.Imaging; | ||
30 | using System.IO; | ||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | internal class TIFF : GenericSystemDrawing | ||
36 | { | ||
37 | public override void SaveFile(string filename, ITerrainChannel map) | ||
38 | { | ||
39 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
40 | |||
41 | colours.Save(filename, ImageFormat.Tiff); | ||
42 | } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Exports a stream using a System.Drawing exporter. | ||
46 | /// </summary> | ||
47 | /// <param name="stream">The target stream</param> | ||
48 | /// <param name="map">The terrain channel being saved</param> | ||
49 | public override void SaveStream(Stream stream, ITerrainChannel map) | ||
50 | { | ||
51 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
52 | |||
53 | colours.Save(stream, ImageFormat.Tiff); | ||
54 | } | ||
55 | |||
56 | public override string ToString() | ||
57 | { | ||
58 | return "TIFF"; | ||
59 | } | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs new file mode 100644 index 0000000..426708d --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Text; | ||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | |||
34 | namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// Terragen File Format Loader | ||
38 | /// Built from specification at | ||
39 | /// http://www.planetside.co.uk/terragen/dev/tgterrain.html | ||
40 | /// </summary> | ||
41 | internal class Terragen : ITerrainLoader | ||
42 | { | ||
43 | #region ITerrainLoader Members | ||
44 | |||
45 | public ITerrainChannel LoadFile(string filename) | ||
46 | { | ||
47 | FileInfo file = new FileInfo(filename); | ||
48 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
49 | ITerrainChannel retval = LoadStream(s); | ||
50 | |||
51 | s.Close(); | ||
52 | |||
53 | return retval; | ||
54 | } | ||
55 | |||
56 | public ITerrainChannel LoadStream(Stream s) | ||
57 | { | ||
58 | TerrainChannel retval = new TerrainChannel(); | ||
59 | |||
60 | BinaryReader bs = new BinaryReader(s); | ||
61 | |||
62 | bool eof = false; | ||
63 | if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") | ||
64 | { | ||
65 | int w = 256; | ||
66 | int h = 256; | ||
67 | |||
68 | // Terragen file | ||
69 | while (eof == false) | ||
70 | { | ||
71 | string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4)); | ||
72 | switch (tmp) | ||
73 | { | ||
74 | case "SIZE": | ||
75 | int sztmp = bs.ReadInt16() + 1; | ||
76 | w = sztmp; | ||
77 | h = sztmp; | ||
78 | bs.ReadInt16(); | ||
79 | break; | ||
80 | case "XPTS": | ||
81 | w = bs.ReadInt16(); | ||
82 | bs.ReadInt16(); | ||
83 | break; | ||
84 | case "YPTS": | ||
85 | h = bs.ReadInt16(); | ||
86 | bs.ReadInt16(); | ||
87 | break; | ||
88 | case "ALTW": | ||
89 | eof = true; | ||
90 | Int16 heightScale = bs.ReadInt16(); | ||
91 | Int16 baseHeight = bs.ReadInt16(); | ||
92 | retval = new TerrainChannel(w, h); | ||
93 | int x; | ||
94 | for (x = 0; x < w; x++) | ||
95 | { | ||
96 | int y; | ||
97 | for (y = 0; y < h; y++) | ||
98 | { | ||
99 | retval[x, y] = baseHeight + bs.ReadInt16() * (double) heightScale / 65536.0; | ||
100 | } | ||
101 | } | ||
102 | break; | ||
103 | default: | ||
104 | bs.ReadInt32(); | ||
105 | break; | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | bs.Close(); | ||
111 | |||
112 | return retval; | ||
113 | } | ||
114 | |||
115 | public void SaveFile(string filename, ITerrainChannel map) | ||
116 | { | ||
117 | throw new NotImplementedException(); | ||
118 | } | ||
119 | |||
120 | public void SaveStream(Stream stream, ITerrainChannel map) | ||
121 | { | ||
122 | throw new NotImplementedException(); | ||
123 | } | ||
124 | |||
125 | public string FileExtension | ||
126 | { | ||
127 | get { return ".ter"; } | ||
128 | } | ||
129 | |||
130 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
131 | { | ||
132 | throw new NotImplementedException(); | ||
133 | } | ||
134 | |||
135 | #endregion | ||
136 | |||
137 | public override string ToString() | ||
138 | { | ||
139 | return "Terragen"; | ||
140 | } | ||
141 | } | ||
142 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs new file mode 100644 index 0000000..fe79c0b --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes | ||
31 | { | ||
32 | public class FlattenArea : ITerrainFloodEffect | ||
33 | { | ||
34 | #region ITerrainFloodEffect Members | ||
35 | |||
36 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
37 | { | ||
38 | double sum = 0.0; | ||
39 | double steps = 0.0; | ||
40 | |||
41 | int x, y; | ||
42 | for (x = 0; x < map.Width; x++) | ||
43 | { | ||
44 | for (y = 0; y < map.Height; y++) | ||
45 | { | ||
46 | if (fillArea[x, y]) | ||
47 | { | ||
48 | sum += map[x, y]; | ||
49 | steps += 1.0; | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | double avg = sum / steps; | ||
55 | |||
56 | double str = 0.1 * strength; // == 0.2 in the default client | ||
57 | |||
58 | for (x = 0; x < map.Width; x++) | ||
59 | { | ||
60 | for (y = 0; y < map.Height; y++) | ||
61 | { | ||
62 | if (fillArea[x, y]) | ||
63 | map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | #endregion | ||
69 | } | ||
70 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs new file mode 100644 index 0000000..5c0aace --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes | ||
31 | { | ||
32 | public class LowerArea : ITerrainFloodEffect | ||
33 | { | ||
34 | #region ITerrainFloodEffect Members | ||
35 | |||
36 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
37 | { | ||
38 | int x; | ||
39 | for (x = 0; x < map.Width; x++) | ||
40 | { | ||
41 | int y; | ||
42 | for (y = 0; y < map.Height; y++) | ||
43 | { | ||
44 | if (fillArea[x, y]) | ||
45 | { | ||
46 | map[x, y] -= strength; | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | #endregion | ||
53 | } | ||
54 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs new file mode 100644 index 0000000..02f2b53 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Framework; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes | ||
33 | { | ||
34 | public class NoiseArea : ITerrainFloodEffect | ||
35 | { | ||
36 | #region ITerrainFloodEffect Members | ||
37 | |||
38 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
39 | { | ||
40 | int x; | ||
41 | for (x = 0; x < map.Width; x++) | ||
42 | { | ||
43 | int y; | ||
44 | for (y = 0; y < map.Height; y++) | ||
45 | { | ||
46 | if (fillArea[x, y]) | ||
47 | { | ||
48 | double noise = TerrainUtil.PerlinNoise2D((double) x / Constants.RegionSize, (double) y / Constants.RegionSize, 8, 1.0); | ||
49 | |||
50 | map[x, y] += noise * strength; | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | #endregion | ||
57 | } | ||
58 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs new file mode 100644 index 0000000..768b31f --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes | ||
31 | { | ||
32 | public class RaiseArea : ITerrainFloodEffect | ||
33 | { | ||
34 | #region ITerrainFloodEffect Members | ||
35 | |||
36 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
37 | { | ||
38 | int x; | ||
39 | for (x = 0; x < map.Width; x++) | ||
40 | { | ||
41 | int y; | ||
42 | for (y = 0; y < map.Height; y++) | ||
43 | { | ||
44 | if (fillArea[x, y]) | ||
45 | { | ||
46 | map[x, y] += strength; | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | #endregion | ||
53 | } | ||
54 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs new file mode 100644 index 0000000..66b9055 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes | ||
31 | { | ||
32 | public class RevertArea : ITerrainFloodEffect | ||
33 | { | ||
34 | private readonly ITerrainChannel m_revertmap; | ||
35 | |||
36 | public RevertArea(ITerrainChannel revertmap) | ||
37 | { | ||
38 | m_revertmap = revertmap; | ||
39 | } | ||
40 | |||
41 | #region ITerrainFloodEffect Members | ||
42 | |||
43 | /// <summary> | ||
44 | /// reverts an area of the map to the heightfield stored in the revertmap | ||
45 | /// </summary> | ||
46 | /// <param name="map">the current heightmap</param> | ||
47 | /// <param name="fillArea">array indicating which sections of the map are to be reverted</param> | ||
48 | /// <param name="strength">unused</param> | ||
49 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
50 | { | ||
51 | int x; | ||
52 | for (x = 0; x < map.Width; x++) | ||
53 | { | ||
54 | int y; | ||
55 | for (y = 0; y < map.Height; y++) | ||
56 | { | ||
57 | if (fillArea[x, y]) | ||
58 | { | ||
59 | map[x, y] = m_revertmap[x, y]; | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | #endregion | ||
66 | } | ||
67 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs new file mode 100644 index 0000000..a75dde1 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes | ||
31 | { | ||
32 | public class SmoothArea : ITerrainFloodEffect | ||
33 | { | ||
34 | #region ITerrainFloodEffect Members | ||
35 | |||
36 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
37 | { | ||
38 | double area = strength; | ||
39 | double step = strength / 4.0; | ||
40 | |||
41 | double[,] manipulate = new double[map.Width,map.Height]; | ||
42 | int x, y; | ||
43 | for (x = 0; x < map.Width; x++) | ||
44 | { | ||
45 | for (y = 0; y < map.Height; y++) | ||
46 | { | ||
47 | if (!fillArea[x, y]) | ||
48 | continue; | ||
49 | |||
50 | double average = 0.0; | ||
51 | int avgsteps = 0; | ||
52 | |||
53 | double n; | ||
54 | for (n = 0.0 - area; n < area; n += step) | ||
55 | { | ||
56 | double l; | ||
57 | for (l = 0.0 - area; l < area; l += step) | ||
58 | { | ||
59 | avgsteps++; | ||
60 | average += GetBilinearInterpolate(x + n, y + l, map); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | manipulate[x, y] = average / avgsteps; | ||
65 | } | ||
66 | } | ||
67 | for (x = 0; x < map.Width; x++) | ||
68 | { | ||
69 | for (y = 0; y < map.Height; y++) | ||
70 | { | ||
71 | if (!fillArea[x, y]) | ||
72 | continue; | ||
73 | |||
74 | map[x, y] = manipulate[x, y]; | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | #endregion | ||
80 | |||
81 | private static double GetBilinearInterpolate(double x, double y, ITerrainChannel map) | ||
82 | { | ||
83 | int w = map.Width; | ||
84 | int h = map.Height; | ||
85 | |||
86 | if (x > w - 2.0) | ||
87 | x = w - 2.0; | ||
88 | if (y > h - 2.0) | ||
89 | y = h - 2.0; | ||
90 | if (x < 0.0) | ||
91 | x = 0.0; | ||
92 | if (y < 0.0) | ||
93 | y = 0.0; | ||
94 | |||
95 | const int stepSize = 1; | ||
96 | double h00 = map[(int) x, (int) y]; | ||
97 | double h10 = map[(int) x + stepSize, (int) y]; | ||
98 | double h01 = map[(int) x, (int) y + stepSize]; | ||
99 | double h11 = map[(int) x + stepSize, (int) y + stepSize]; | ||
100 | double h1 = h00; | ||
101 | double h2 = h10; | ||
102 | double h3 = h01; | ||
103 | double h4 = h11; | ||
104 | double a00 = h1; | ||
105 | double a10 = h2 - h1; | ||
106 | double a01 = h3 - h1; | ||
107 | double a11 = h1 - h2 - h3 + h4; | ||
108 | double partialx = x - (int) x; | ||
109 | double partialz = y - (int) y; | ||
110 | double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); | ||
111 | return hi; | ||
112 | } | ||
113 | } | ||
114 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainEffect.cs new file mode 100644 index 0000000..40b9f5a --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainEffect.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
31 | { | ||
32 | public interface ITerrainEffect | ||
33 | { | ||
34 | void RunEffect(ITerrainChannel map); | ||
35 | } | ||
36 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs new file mode 100644 index 0000000..eee7a83 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
32 | { | ||
33 | public interface ITerrainFloodEffect | ||
34 | { | ||
35 | void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); | ||
36 | } | ||
37 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs new file mode 100644 index 0000000..c62b897 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainLoader.cs | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
32 | { | ||
33 | public interface ITerrainLoader | ||
34 | { | ||
35 | string FileExtension { get; } | ||
36 | ITerrainChannel LoadFile(string filename); | ||
37 | ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight); | ||
38 | ITerrainChannel LoadStream(Stream stream); | ||
39 | void SaveFile(string filename, ITerrainChannel map); | ||
40 | void SaveStream(Stream stream, ITerrainChannel map); | ||
41 | } | ||
42 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainModule.cs new file mode 100644 index 0000000..8c5d1d9 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainModule.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | |||
29 | using System.IO; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
34 | { | ||
35 | public interface ITerrainModule | ||
36 | { | ||
37 | void LoadFromFile(string filename); | ||
38 | void SaveToFile(string filename); | ||
39 | void ModifyTerrain(UUID user, Vector3 pos, byte size, byte action, UUID agentId); | ||
40 | |||
41 | /// <summary> | ||
42 | /// Load a terrain from a stream. | ||
43 | /// </summary> | ||
44 | /// <param name="filename"> | ||
45 | /// Only required here to identify the image type. Not otherwise used in the loading itself. | ||
46 | /// </param> | ||
47 | /// <param name="stream"></param> | ||
48 | void LoadFromStream(string filename, Stream stream); | ||
49 | |||
50 | /// <summary> | ||
51 | /// Save a terrain to a stream. | ||
52 | /// </summary> | ||
53 | /// <param name="filename"> | ||
54 | /// Only required here to identify the image type. Not otherwise used in the saving itself. | ||
55 | /// </param> | ||
56 | /// <param name="stream"></param> | ||
57 | void SaveToStream(string filename, Stream stream); | ||
58 | |||
59 | void InstallPlugin(string name, ITerrainEffect plug); | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs new file mode 100644 index 0000000..15d9f6e --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
31 | { | ||
32 | public interface ITerrainPaintableEffect | ||
33 | { | ||
34 | void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z, double strength, double duration); | ||
35 | } | ||
36 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs new file mode 100644 index 0000000..6ce6994 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs | |||
@@ -0,0 +1,318 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Hydraulic Erosion Brush | ||
36 | /// </summary> | ||
37 | public class ErodeSphere : ITerrainPaintableEffect | ||
38 | { | ||
39 | private const double rainHeight = 0.2; | ||
40 | private const int rounds = 10; | ||
41 | private const NeighbourSystem type = NeighbourSystem.Moore; | ||
42 | private const double waterSaturation = 0.30; | ||
43 | |||
44 | #region Supporting Functions | ||
45 | |||
46 | private static int[] Neighbours(NeighbourSystem neighbourType, int index) | ||
47 | { | ||
48 | int[] coord = new int[2]; | ||
49 | |||
50 | index++; | ||
51 | |||
52 | switch (neighbourType) | ||
53 | { | ||
54 | case NeighbourSystem.Moore: | ||
55 | switch (index) | ||
56 | { | ||
57 | case 1: | ||
58 | coord[0] = -1; | ||
59 | coord[1] = -1; | ||
60 | break; | ||
61 | |||
62 | case 2: | ||
63 | coord[0] = -0; | ||
64 | coord[1] = -1; | ||
65 | break; | ||
66 | |||
67 | case 3: | ||
68 | coord[0] = +1; | ||
69 | coord[1] = -1; | ||
70 | break; | ||
71 | |||
72 | case 4: | ||
73 | coord[0] = -1; | ||
74 | coord[1] = -0; | ||
75 | break; | ||
76 | |||
77 | case 5: | ||
78 | coord[0] = -0; | ||
79 | coord[1] = -0; | ||
80 | break; | ||
81 | |||
82 | case 6: | ||
83 | coord[0] = +1; | ||
84 | coord[1] = -0; | ||
85 | break; | ||
86 | |||
87 | case 7: | ||
88 | coord[0] = -1; | ||
89 | coord[1] = +1; | ||
90 | break; | ||
91 | |||
92 | case 8: | ||
93 | coord[0] = -0; | ||
94 | coord[1] = +1; | ||
95 | break; | ||
96 | |||
97 | case 9: | ||
98 | coord[0] = +1; | ||
99 | coord[1] = +1; | ||
100 | break; | ||
101 | |||
102 | default: | ||
103 | break; | ||
104 | } | ||
105 | break; | ||
106 | |||
107 | case NeighbourSystem.VonNeumann: | ||
108 | switch (index) | ||
109 | { | ||
110 | case 1: | ||
111 | coord[0] = 0; | ||
112 | coord[1] = -1; | ||
113 | break; | ||
114 | |||
115 | case 2: | ||
116 | coord[0] = -1; | ||
117 | coord[1] = 0; | ||
118 | break; | ||
119 | |||
120 | case 3: | ||
121 | coord[0] = +1; | ||
122 | coord[1] = 0; | ||
123 | break; | ||
124 | |||
125 | case 4: | ||
126 | coord[0] = 0; | ||
127 | coord[1] = +1; | ||
128 | break; | ||
129 | |||
130 | case 5: | ||
131 | coord[0] = -0; | ||
132 | coord[1] = -0; | ||
133 | break; | ||
134 | |||
135 | default: | ||
136 | break; | ||
137 | } | ||
138 | break; | ||
139 | } | ||
140 | |||
141 | return coord; | ||
142 | } | ||
143 | |||
144 | private enum NeighbourSystem | ||
145 | { | ||
146 | Moore, | ||
147 | VonNeumann | ||
148 | } ; | ||
149 | |||
150 | #endregion | ||
151 | |||
152 | #region ITerrainPaintableEffect Members | ||
153 | |||
154 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
155 | { | ||
156 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
157 | |||
158 | int x, y; | ||
159 | // Using one 'rain' round for this, so skipping a useless loop | ||
160 | // Will need to adapt back in for the Flood brush | ||
161 | |||
162 | ITerrainChannel water = new TerrainChannel(map.Width, map.Height); | ||
163 | ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); | ||
164 | |||
165 | // Fill with rain | ||
166 | for (x = 0; x < water.Width; x++) | ||
167 | for (y = 0; y < water.Height; y++) | ||
168 | water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); | ||
169 | |||
170 | for (int i = 0; i < rounds; i++) | ||
171 | { | ||
172 | // Erode underlying terrain | ||
173 | for (x = 0; x < water.Width; x++) | ||
174 | { | ||
175 | for (y = 0; y < water.Height; y++) | ||
176 | { | ||
177 | if (mask[x,y]) | ||
178 | { | ||
179 | const double solConst = (1.0 / rounds); | ||
180 | double sedDelta = water[x, y] * solConst; | ||
181 | map[x, y] -= sedDelta; | ||
182 | sediment[x, y] += sedDelta; | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | // Move water | ||
188 | for (x = 0; x < water.Width; x++) | ||
189 | { | ||
190 | for (y = 0; y < water.Height; y++) | ||
191 | { | ||
192 | if (water[x, y] <= 0) | ||
193 | continue; | ||
194 | |||
195 | // Step 1. Calculate average of neighbours | ||
196 | |||
197 | int neighbours = 0; | ||
198 | double altitudeTotal = 0.0; | ||
199 | double altitudeMe = map[x, y] + water[x, y]; | ||
200 | |||
201 | const int NEIGHBOUR_ME = 4; | ||
202 | const int NEIGHBOUR_MAX = 9; | ||
203 | |||
204 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
205 | { | ||
206 | if (j != NEIGHBOUR_ME) | ||
207 | { | ||
208 | int[] coords = Neighbours(type, j); | ||
209 | |||
210 | coords[0] += x; | ||
211 | coords[1] += y; | ||
212 | |||
213 | if (coords[0] > map.Width - 1) | ||
214 | continue; | ||
215 | if (coords[1] > map.Height - 1) | ||
216 | continue; | ||
217 | if (coords[0] < 0) | ||
218 | continue; | ||
219 | if (coords[1] < 0) | ||
220 | continue; | ||
221 | |||
222 | // Calculate total height of this neighbour | ||
223 | double altitudeNeighbour = water[coords[0], coords[1]] + map[coords[0], coords[1]]; | ||
224 | |||
225 | // If it's greater than me... | ||
226 | if (altitudeNeighbour - altitudeMe < 0) | ||
227 | { | ||
228 | // Add it to our calculations | ||
229 | neighbours++; | ||
230 | altitudeTotal += altitudeNeighbour; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | |||
235 | if (neighbours == 0) | ||
236 | continue; | ||
237 | |||
238 | double altitudeAvg = altitudeTotal / neighbours; | ||
239 | |||
240 | // Step 2. Allocate water to neighbours. | ||
241 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
242 | { | ||
243 | if (j != NEIGHBOUR_ME) | ||
244 | { | ||
245 | int[] coords = Neighbours(type, j); | ||
246 | |||
247 | coords[0] += x; | ||
248 | coords[1] += y; | ||
249 | |||
250 | if (coords[0] > map.Width - 1) | ||
251 | continue; | ||
252 | if (coords[1] > map.Height - 1) | ||
253 | continue; | ||
254 | if (coords[0] < 0) | ||
255 | continue; | ||
256 | if (coords[1] < 0) | ||
257 | continue; | ||
258 | |||
259 | // Skip if we dont have water to begin with. | ||
260 | if (water[x, y] < 0) | ||
261 | continue; | ||
262 | |||
263 | // Calculate our delta average | ||
264 | double altitudeDelta = altitudeMe - altitudeAvg; | ||
265 | |||
266 | if (altitudeDelta < 0) | ||
267 | continue; | ||
268 | |||
269 | // Calculate how much water we can move | ||
270 | double waterMin = Math.Min(water[x, y], altitudeDelta); | ||
271 | double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]]) | ||
272 | / altitudeTotal); | ||
273 | |||
274 | double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]); | ||
275 | |||
276 | if (sedimentDelta > 0) | ||
277 | { | ||
278 | sediment[x, y] -= sedimentDelta; | ||
279 | sediment[coords[0], coords[1]] += sedimentDelta; | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | // Evaporate | ||
287 | |||
288 | for (x = 0; x < water.Width; x++) | ||
289 | { | ||
290 | for (y = 0; y < water.Height; y++) | ||
291 | { | ||
292 | water[x, y] *= 1.0 - (rainHeight / rounds); | ||
293 | |||
294 | double waterCapacity = waterSaturation * water[x, y]; | ||
295 | |||
296 | double sedimentDeposit = sediment[x, y] - waterCapacity; | ||
297 | if (sedimentDeposit > 0) | ||
298 | { | ||
299 | if (mask[x,y]) | ||
300 | { | ||
301 | sediment[x, y] -= sedimentDeposit; | ||
302 | map[x, y] += sedimentDeposit; | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | |||
309 | // Deposit any remainder (should be minimal) | ||
310 | for (x = 0; x < water.Width; x++) | ||
311 | for (y = 0; y < water.Height; y++) | ||
312 | if (mask[x,y] && sediment[x, y] > 0) | ||
313 | map[x, y] += sediment[x, y]; | ||
314 | } | ||
315 | |||
316 | #endregion | ||
317 | } | ||
318 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs new file mode 100644 index 0000000..928a595 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
33 | { | ||
34 | public class FlattenSphere : ITerrainPaintableEffect | ||
35 | { | ||
36 | #region ITerrainPaintableEffect Members | ||
37 | |||
38 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
39 | { | ||
40 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
41 | |||
42 | int x, y; | ||
43 | |||
44 | if (rz < 0) { | ||
45 | double sum = 0.0; | ||
46 | double step2 = 0.0; | ||
47 | duration = 0.009; //MCP Should be read from ini file | ||
48 | |||
49 | |||
50 | // compute delta map | ||
51 | for (x = 0; x < map.Width; x++) | ||
52 | { | ||
53 | for (y = 0; y < map.Height; y++) | ||
54 | { | ||
55 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
56 | |||
57 | if (z > 0) // add in non-zero amount | ||
58 | { | ||
59 | sum += map[x, y] * z; | ||
60 | step2 += z; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | rz = sum / step2; | ||
65 | } | ||
66 | |||
67 | |||
68 | // blend in map | ||
69 | for (x = 0; x < map.Width; x++) | ||
70 | { | ||
71 | for (y = 0; y < map.Height; y++) | ||
72 | { | ||
73 | if (!mask[x,y]) | ||
74 | continue; | ||
75 | |||
76 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration; | ||
77 | |||
78 | if (z > 0) // add in non-zero amount | ||
79 | { | ||
80 | if (z > 1.0) | ||
81 | z = 1.0; | ||
82 | |||
83 | map[x, y] = (map[x, y] * (1.0 - z)) + (rz * z); | ||
84 | } | ||
85 | |||
86 | double delta = rz - map[x, y]; | ||
87 | if (Math.Abs(delta) > 0.1) | ||
88 | delta *= 0.25; | ||
89 | |||
90 | if (delta != 0) // add in non-zero amount | ||
91 | { | ||
92 | map[x, y] += delta; | ||
93 | } | ||
94 | |||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | #endregion | ||
100 | } | ||
101 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs new file mode 100644 index 0000000..8c40088 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | public class LowerSphere : ITerrainPaintableEffect | ||
34 | { | ||
35 | #region ITerrainPaintableEffect Members | ||
36 | |||
37 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
38 | { | ||
39 | int s = (int) (Math.Pow(2, strength) + 0.5); | ||
40 | |||
41 | int x; | ||
42 | int xFrom = (int)(rx-s+0.5); | ||
43 | int xTo = (int)(rx+s+0.5) + 1; | ||
44 | int yFrom = (int)(ry-s+0.5); | ||
45 | int yTo = (int)(ry+s+0.5) + 1; | ||
46 | |||
47 | if (xFrom < 0) | ||
48 | xFrom = 0; | ||
49 | |||
50 | if (yFrom < 0) | ||
51 | yFrom = 0; | ||
52 | |||
53 | if (xTo > map.Width) | ||
54 | xTo = map.Width; | ||
55 | |||
56 | if (yTo > map.Width) | ||
57 | yTo = map.Width; | ||
58 | |||
59 | for (x = xFrom; x < xTo; x++) | ||
60 | { | ||
61 | int y; | ||
62 | for (y = yFrom; y < yTo; y++) | ||
63 | { | ||
64 | if (!mask[x,y]) | ||
65 | continue; | ||
66 | |||
67 | // Calculate a cos-sphere and add it to the heighmap | ||
68 | double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); | ||
69 | double z = Math.Cos(r * Math.PI / (s * 2)); | ||
70 | if (z > 0.0) | ||
71 | { | ||
72 | double newz = map[x, y] - z * duration; | ||
73 | if (newz < 0.0) | ||
74 | map[x, y] = 0.0; | ||
75 | else | ||
76 | map[x, y] = newz; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | } | ||
82 | #endregion | ||
83 | } | ||
84 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs new file mode 100644 index 0000000..95a8c33 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Framework; | ||
30 | using OpenSim.Region.Framework.Interfaces; | ||
31 | using OpenSim.Region.Framework.Scenes; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
34 | { | ||
35 | public class NoiseSphere : ITerrainPaintableEffect | ||
36 | { | ||
37 | #region ITerrainPaintableEffect Members | ||
38 | |||
39 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
40 | { | ||
41 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
42 | |||
43 | int x; | ||
44 | for (x = 0; x < map.Width; x++) | ||
45 | { | ||
46 | int y; | ||
47 | for (y = 0; y < map.Height; y++) | ||
48 | { | ||
49 | if (!mask[x,y]) | ||
50 | continue; | ||
51 | |||
52 | // Calculate a sphere and add it to the heighmap | ||
53 | double z = strength; | ||
54 | z *= z; | ||
55 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
56 | |||
57 | double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0); | ||
58 | |||
59 | if (z > 0.0) | ||
60 | map[x, y] += noise * z * duration; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | #endregion | ||
66 | } | ||
67 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs new file mode 100644 index 0000000..1a2528a --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs | |||
@@ -0,0 +1,223 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Speed-Optimised Hybrid Erosion Brush | ||
36 | /// | ||
37 | /// As per Jacob Olsen's Paper | ||
38 | /// http://www.oddlabs.com/download/terrain_generation.pdf | ||
39 | /// </summary> | ||
40 | public class OlsenSphere : ITerrainPaintableEffect | ||
41 | { | ||
42 | private const double nConst = 1024.0; | ||
43 | private const NeighbourSystem type = NeighbourSystem.Moore; | ||
44 | |||
45 | #region Supporting Functions | ||
46 | |||
47 | private static int[] Neighbours(NeighbourSystem neighbourType, int index) | ||
48 | { | ||
49 | int[] coord = new int[2]; | ||
50 | |||
51 | index++; | ||
52 | |||
53 | switch (neighbourType) | ||
54 | { | ||
55 | case NeighbourSystem.Moore: | ||
56 | switch (index) | ||
57 | { | ||
58 | case 1: | ||
59 | coord[0] = -1; | ||
60 | coord[1] = -1; | ||
61 | break; | ||
62 | |||
63 | case 2: | ||
64 | coord[0] = -0; | ||
65 | coord[1] = -1; | ||
66 | break; | ||
67 | |||
68 | case 3: | ||
69 | coord[0] = +1; | ||
70 | coord[1] = -1; | ||
71 | break; | ||
72 | |||
73 | case 4: | ||
74 | coord[0] = -1; | ||
75 | coord[1] = -0; | ||
76 | break; | ||
77 | |||
78 | case 5: | ||
79 | coord[0] = -0; | ||
80 | coord[1] = -0; | ||
81 | break; | ||
82 | |||
83 | case 6: | ||
84 | coord[0] = +1; | ||
85 | coord[1] = -0; | ||
86 | break; | ||
87 | |||
88 | case 7: | ||
89 | coord[0] = -1; | ||
90 | coord[1] = +1; | ||
91 | break; | ||
92 | |||
93 | case 8: | ||
94 | coord[0] = -0; | ||
95 | coord[1] = +1; | ||
96 | break; | ||
97 | |||
98 | case 9: | ||
99 | coord[0] = +1; | ||
100 | coord[1] = +1; | ||
101 | break; | ||
102 | |||
103 | default: | ||
104 | break; | ||
105 | } | ||
106 | break; | ||
107 | |||
108 | case NeighbourSystem.VonNeumann: | ||
109 | switch (index) | ||
110 | { | ||
111 | case 1: | ||
112 | coord[0] = 0; | ||
113 | coord[1] = -1; | ||
114 | break; | ||
115 | |||
116 | case 2: | ||
117 | coord[0] = -1; | ||
118 | coord[1] = 0; | ||
119 | break; | ||
120 | |||
121 | case 3: | ||
122 | coord[0] = +1; | ||
123 | coord[1] = 0; | ||
124 | break; | ||
125 | |||
126 | case 4: | ||
127 | coord[0] = 0; | ||
128 | coord[1] = +1; | ||
129 | break; | ||
130 | |||
131 | case 5: | ||
132 | coord[0] = -0; | ||
133 | coord[1] = -0; | ||
134 | break; | ||
135 | |||
136 | default: | ||
137 | break; | ||
138 | } | ||
139 | break; | ||
140 | } | ||
141 | |||
142 | return coord; | ||
143 | } | ||
144 | |||
145 | private enum NeighbourSystem | ||
146 | { | ||
147 | Moore, | ||
148 | VonNeumann | ||
149 | } ; | ||
150 | |||
151 | #endregion | ||
152 | |||
153 | #region ITerrainPaintableEffect Members | ||
154 | |||
155 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
156 | { | ||
157 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
158 | |||
159 | int x; | ||
160 | |||
161 | for (x = 0; x < map.Width; x++) | ||
162 | { | ||
163 | int y; | ||
164 | for (y = 0; y < map.Height; y++) | ||
165 | { | ||
166 | if (!mask[x,y]) | ||
167 | continue; | ||
168 | |||
169 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
170 | |||
171 | if (z > 0) // add in non-zero amount | ||
172 | { | ||
173 | const int NEIGHBOUR_ME = 4; | ||
174 | const int NEIGHBOUR_MAX = 9; | ||
175 | |||
176 | double max = Double.MinValue; | ||
177 | int loc = 0; | ||
178 | |||
179 | |||
180 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
181 | { | ||
182 | if (j != NEIGHBOUR_ME) | ||
183 | { | ||
184 | int[] coords = Neighbours(type, j); | ||
185 | |||
186 | coords[0] += x; | ||
187 | coords[1] += y; | ||
188 | |||
189 | if (coords[0] > map.Width - 1) | ||
190 | continue; | ||
191 | if (coords[1] > map.Height - 1) | ||
192 | continue; | ||
193 | if (coords[0] < 0) | ||
194 | continue; | ||
195 | if (coords[1] < 0) | ||
196 | continue; | ||
197 | |||
198 | double cellmax = map[x, y] - map[coords[0], coords[1]]; | ||
199 | if (cellmax > max) | ||
200 | { | ||
201 | max = cellmax; | ||
202 | loc = j; | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | |||
207 | double T = nConst / ((map.Width + map.Height) / 2.0); | ||
208 | // Apply results | ||
209 | if (0 < max && max <= T) | ||
210 | { | ||
211 | int[] maxCoords = Neighbours(type, loc); | ||
212 | double heightDelta = 0.5 * max * z * duration; | ||
213 | map[x, y] -= heightDelta; | ||
214 | map[x + maxCoords[0], y + maxCoords[1]] += heightDelta; | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | |||
221 | #endregion | ||
222 | } | ||
223 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs new file mode 100644 index 0000000..c53bb7d --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
33 | { | ||
34 | public class RaiseSphere : ITerrainPaintableEffect | ||
35 | { | ||
36 | #region ITerrainPaintableEffect Members | ||
37 | |||
38 | |||
39 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
40 | { | ||
41 | int s = (int) (Math.Pow(2, strength) + 0.5); | ||
42 | |||
43 | int x; | ||
44 | int xFrom = (int)(rx-s+0.5); | ||
45 | int xTo = (int)(rx+s+0.5) + 1; | ||
46 | int yFrom = (int)(ry-s+0.5); | ||
47 | int yTo = (int)(ry+s+0.5) + 1; | ||
48 | |||
49 | if (xFrom < 0) | ||
50 | xFrom = 0; | ||
51 | |||
52 | if (yFrom < 0) | ||
53 | yFrom = 0; | ||
54 | |||
55 | if (xTo > map.Width) | ||
56 | xTo = map.Width; | ||
57 | |||
58 | if (yTo > map.Width) | ||
59 | yTo = map.Width; | ||
60 | |||
61 | for (x = xFrom; x < xTo; x++) | ||
62 | { | ||
63 | int y; | ||
64 | for (y = yFrom; y < yTo; y++) | ||
65 | { | ||
66 | if (!mask[x,y]) | ||
67 | continue; | ||
68 | |||
69 | // Calculate a cos-sphere and add it to the heighmap | ||
70 | double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); | ||
71 | double z = Math.Cos(r * Math.PI / (s * 2)); | ||
72 | if (z > 0.0) | ||
73 | map[x, y] += z * duration; | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | } | ||
80 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs new file mode 100644 index 0000000..4ed8a13 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
33 | { | ||
34 | public class RevertSphere : ITerrainPaintableEffect | ||
35 | { | ||
36 | private readonly ITerrainChannel m_revertmap; | ||
37 | |||
38 | public RevertSphere(ITerrainChannel revertmap) | ||
39 | { | ||
40 | m_revertmap = revertmap; | ||
41 | } | ||
42 | |||
43 | #region ITerrainPaintableEffect Members | ||
44 | |||
45 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
46 | { | ||
47 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
48 | duration = 0.03; //MCP Should be read from ini file | ||
49 | |||
50 | if (duration > 1.0) | ||
51 | duration = 1.0; | ||
52 | if (duration < 0) | ||
53 | return; | ||
54 | |||
55 | int x; | ||
56 | for (x = 0; x < map.Width; x++) | ||
57 | { | ||
58 | int y; | ||
59 | for (y = 0; y < map.Height; y++) | ||
60 | { | ||
61 | if (!mask[x,y]) | ||
62 | continue; | ||
63 | |||
64 | // Calculate a sphere and add it to the heighmap | ||
65 | double z = strength; | ||
66 | z *= z; | ||
67 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
68 | |||
69 | if (z > 0.0) | ||
70 | { | ||
71 | z *= duration; | ||
72 | map[x, y] = (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | } | ||
80 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs new file mode 100644 index 0000000..6636d8f --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | using OpenSim.Region.Framework.Scenes; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | public class SmoothSphere : ITerrainPaintableEffect | ||
34 | { | ||
35 | #region ITerrainPaintableEffect Members | ||
36 | |||
37 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
38 | { | ||
39 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
40 | |||
41 | int x, y; | ||
42 | double[,] tweak = new double[map.Width,map.Height]; | ||
43 | |||
44 | double area = strength; | ||
45 | double step = strength / 4.0; | ||
46 | duration = 0.03; //MCP Should be read from ini file | ||
47 | |||
48 | |||
49 | // compute delta map | ||
50 | for (x = 0; x < map.Width; x++) | ||
51 | { | ||
52 | for (y = 0; y < map.Height; y++) | ||
53 | { | ||
54 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
55 | |||
56 | if (z > 0) // add in non-zero amount | ||
57 | { | ||
58 | double average = 0.0; | ||
59 | int avgsteps = 0; | ||
60 | |||
61 | double n; | ||
62 | for (n = 0.0 - area; n < area; n += step) | ||
63 | { | ||
64 | double l; | ||
65 | for (l = 0.0 - area; l < area; l += step) | ||
66 | { | ||
67 | avgsteps++; | ||
68 | average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); | ||
69 | } | ||
70 | } | ||
71 | tweak[x, y] = average / avgsteps; | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | // blend in map | ||
76 | for (x = 0; x < map.Width; x++) | ||
77 | { | ||
78 | for (y = 0; y < map.Height; y++) | ||
79 | { | ||
80 | if (!mask[x,y]) | ||
81 | continue; | ||
82 | |||
83 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
84 | |||
85 | if (z > 0) // add in non-zero amount | ||
86 | { | ||
87 | double da = z; | ||
88 | double a = (map[x, y] - tweak[x, y]) * da; | ||
89 | double newz = map[x, y] - (a * duration); | ||
90 | |||
91 | if (newz > 0.0) | ||
92 | map[x, y] = newz; | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | #endregion | ||
99 | } | ||
100 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs new file mode 100644 index 0000000..6b00cc8 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs | |||
@@ -0,0 +1,211 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Region.Framework.Interfaces; | ||
29 | using OpenSim.Region.Framework.Scenes; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// Thermal Weathering Paint Brush | ||
35 | /// </summary> | ||
36 | public class WeatherSphere : ITerrainPaintableEffect | ||
37 | { | ||
38 | private const double talus = 0.2; | ||
39 | private const NeighbourSystem type = NeighbourSystem.Moore; | ||
40 | |||
41 | #region Supporting Functions | ||
42 | |||
43 | private static int[] Neighbours(NeighbourSystem neighbourType, int index) | ||
44 | { | ||
45 | int[] coord = new int[2]; | ||
46 | |||
47 | index++; | ||
48 | |||
49 | switch (neighbourType) | ||
50 | { | ||
51 | case NeighbourSystem.Moore: | ||
52 | switch (index) | ||
53 | { | ||
54 | case 1: | ||
55 | coord[0] = -1; | ||
56 | coord[1] = -1; | ||
57 | break; | ||
58 | |||
59 | case 2: | ||
60 | coord[0] = -0; | ||
61 | coord[1] = -1; | ||
62 | break; | ||
63 | |||
64 | case 3: | ||
65 | coord[0] = +1; | ||
66 | coord[1] = -1; | ||
67 | break; | ||
68 | |||
69 | case 4: | ||
70 | coord[0] = -1; | ||
71 | coord[1] = -0; | ||
72 | break; | ||
73 | |||
74 | case 5: | ||
75 | coord[0] = -0; | ||
76 | coord[1] = -0; | ||
77 | break; | ||
78 | |||
79 | case 6: | ||
80 | coord[0] = +1; | ||
81 | coord[1] = -0; | ||
82 | break; | ||
83 | |||
84 | case 7: | ||
85 | coord[0] = -1; | ||
86 | coord[1] = +1; | ||
87 | break; | ||
88 | |||
89 | case 8: | ||
90 | coord[0] = -0; | ||
91 | coord[1] = +1; | ||
92 | break; | ||
93 | |||
94 | case 9: | ||
95 | coord[0] = +1; | ||
96 | coord[1] = +1; | ||
97 | break; | ||
98 | |||
99 | default: | ||
100 | break; | ||
101 | } | ||
102 | break; | ||
103 | |||
104 | case NeighbourSystem.VonNeumann: | ||
105 | switch (index) | ||
106 | { | ||
107 | case 1: | ||
108 | coord[0] = 0; | ||
109 | coord[1] = -1; | ||
110 | break; | ||
111 | |||
112 | case 2: | ||
113 | coord[0] = -1; | ||
114 | coord[1] = 0; | ||
115 | break; | ||
116 | |||
117 | case 3: | ||
118 | coord[0] = +1; | ||
119 | coord[1] = 0; | ||
120 | break; | ||
121 | |||
122 | case 4: | ||
123 | coord[0] = 0; | ||
124 | coord[1] = +1; | ||
125 | break; | ||
126 | |||
127 | case 5: | ||
128 | coord[0] = -0; | ||
129 | coord[1] = -0; | ||
130 | break; | ||
131 | |||
132 | default: | ||
133 | break; | ||
134 | } | ||
135 | break; | ||
136 | } | ||
137 | |||
138 | return coord; | ||
139 | } | ||
140 | |||
141 | private enum NeighbourSystem | ||
142 | { | ||
143 | Moore, | ||
144 | VonNeumann | ||
145 | } ; | ||
146 | |||
147 | #endregion | ||
148 | |||
149 | #region ITerrainPaintableEffect Members | ||
150 | |||
151 | public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) | ||
152 | { | ||
153 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
154 | |||
155 | int x; | ||
156 | |||
157 | for (x = 0; x < map.Width; x++) | ||
158 | { | ||
159 | int y; | ||
160 | for (y = 0; y < map.Height; y++) | ||
161 | { | ||
162 | if (!mask[x,y]) | ||
163 | continue; | ||
164 | |||
165 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
166 | |||
167 | if (z > 0) // add in non-zero amount | ||
168 | { | ||
169 | const int NEIGHBOUR_ME = 4; | ||
170 | const int NEIGHBOUR_MAX = 9; | ||
171 | |||
172 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
173 | { | ||
174 | if (j != NEIGHBOUR_ME) | ||
175 | { | ||
176 | int[] coords = Neighbours(type, j); | ||
177 | |||
178 | coords[0] += x; | ||
179 | coords[1] += y; | ||
180 | |||
181 | if (coords[0] > map.Width - 1) | ||
182 | continue; | ||
183 | if (coords[1] > map.Height - 1) | ||
184 | continue; | ||
185 | if (coords[0] < 0) | ||
186 | continue; | ||
187 | if (coords[1] < 0) | ||
188 | continue; | ||
189 | |||
190 | double heightF = map[x, y]; | ||
191 | double target = map[coords[0], coords[1]]; | ||
192 | |||
193 | if (target > heightF + talus) | ||
194 | { | ||
195 | double calc = duration * ((target - heightF) - talus) * z; | ||
196 | heightF += calc; | ||
197 | target -= calc; | ||
198 | } | ||
199 | |||
200 | map[x, y] = heightF; | ||
201 | map[coords[0], coords[1]] = target; | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | #endregion | ||
210 | } | ||
211 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainException.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainException.cs new file mode 100644 index 0000000..ff9b8ec --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainException.cs | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
31 | { | ||
32 | public class TerrainException : Exception | ||
33 | { | ||
34 | public TerrainException() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | public TerrainException(string msg) : base(msg) | ||
39 | { | ||
40 | } | ||
41 | |||
42 | public TerrainException(string msg, Exception e) : base(msg, e) | ||
43 | { | ||
44 | } | ||
45 | } | ||
46 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs new file mode 100644 index 0000000..9de7338 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -0,0 +1,1001 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using OpenMetaverse; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; | ||
39 | using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; | ||
40 | using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; | ||
41 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; | ||
42 | |||
43 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
44 | { | ||
45 | public class TerrainModule : IRegionModule, ICommandableModule, ITerrainModule | ||
46 | { | ||
47 | #region StandardTerrainEffects enum | ||
48 | |||
49 | /// <summary> | ||
50 | /// A standard set of terrain brushes and effects recognised by viewers | ||
51 | /// </summary> | ||
52 | public enum StandardTerrainEffects : byte | ||
53 | { | ||
54 | Flatten = 0, | ||
55 | Raise = 1, | ||
56 | Lower = 2, | ||
57 | Smooth = 3, | ||
58 | Noise = 4, | ||
59 | Revert = 5, | ||
60 | |||
61 | // Extended brushes | ||
62 | Erode = 255, | ||
63 | Weather = 254, | ||
64 | Olsen = 253 | ||
65 | } | ||
66 | |||
67 | #endregion | ||
68 | |||
69 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
70 | |||
71 | private readonly Commander m_commander = new Commander("terrain"); | ||
72 | |||
73 | private readonly Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects = | ||
74 | new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>(); | ||
75 | |||
76 | private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>(); | ||
77 | |||
78 | private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = | ||
79 | new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); | ||
80 | |||
81 | private ITerrainChannel m_channel; | ||
82 | private Dictionary<string, ITerrainEffect> m_plugineffects; | ||
83 | private ITerrainChannel m_revert; | ||
84 | private Scene m_scene; | ||
85 | private bool m_tainted; | ||
86 | |||
87 | #region ICommandableModule Members | ||
88 | |||
89 | public ICommander CommandInterface | ||
90 | { | ||
91 | get { return m_commander; } | ||
92 | } | ||
93 | |||
94 | #endregion | ||
95 | |||
96 | #region IRegionModule Members | ||
97 | |||
98 | /// <summary> | ||
99 | /// Creates and initialises a terrain module for a region | ||
100 | /// </summary> | ||
101 | /// <param name="scene">Region initialising</param> | ||
102 | /// <param name="config">Config for the region</param> | ||
103 | public void Initialise(Scene scene, IConfigSource config) | ||
104 | { | ||
105 | m_scene = scene; | ||
106 | |||
107 | // Install terrain module in the simulator | ||
108 | if (m_scene.Heightmap == null) | ||
109 | { | ||
110 | lock (m_scene) | ||
111 | { | ||
112 | m_channel = new TerrainChannel(); | ||
113 | m_scene.Heightmap = m_channel; | ||
114 | m_revert = new TerrainChannel(); | ||
115 | UpdateRevertMap(); | ||
116 | } | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | m_channel = m_scene.Heightmap; | ||
121 | m_revert = new TerrainChannel(); | ||
122 | UpdateRevertMap(); | ||
123 | } | ||
124 | |||
125 | m_scene.RegisterModuleInterface<ITerrainModule>(this); | ||
126 | m_scene.EventManager.OnNewClient += EventManager_OnNewClient; | ||
127 | m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | ||
128 | m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; | ||
129 | } | ||
130 | |||
131 | /// <summary> | ||
132 | /// Enables terrain module when called | ||
133 | /// </summary> | ||
134 | public void PostInitialise() | ||
135 | { | ||
136 | InstallDefaultEffects(); | ||
137 | InstallInterfaces(); | ||
138 | LoadPlugins(); | ||
139 | } | ||
140 | |||
141 | public void Close() | ||
142 | { | ||
143 | } | ||
144 | |||
145 | public string Name | ||
146 | { | ||
147 | get { return "TerrainModule"; } | ||
148 | } | ||
149 | |||
150 | public bool IsSharedModule | ||
151 | { | ||
152 | get { return false; } | ||
153 | } | ||
154 | |||
155 | #endregion | ||
156 | |||
157 | #region ITerrainModule Members | ||
158 | |||
159 | /// <summary> | ||
160 | /// Loads a terrain file from disk and installs it in the scene. | ||
161 | /// </summary> | ||
162 | /// <param name="filename">Filename to terrain file. Type is determined by extension.</param> | ||
163 | public void LoadFromFile(string filename) | ||
164 | { | ||
165 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
166 | { | ||
167 | if (filename.EndsWith(loader.Key)) | ||
168 | { | ||
169 | lock (m_scene) | ||
170 | { | ||
171 | try | ||
172 | { | ||
173 | ITerrainChannel channel = loader.Value.LoadFile(filename); | ||
174 | if (channel.Width != Constants.RegionSize || channel.Height != Constants.RegionSize) | ||
175 | { | ||
176 | // TerrainChannel expects a RegionSize x RegionSize map, currently | ||
177 | throw new ArgumentException(String.Format("wrong size, use a file with size {0} x {1}", | ||
178 | Constants.RegionSize, Constants.RegionSize)); | ||
179 | } | ||
180 | m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height); | ||
181 | m_scene.Heightmap = channel; | ||
182 | m_channel = channel; | ||
183 | UpdateRevertMap(); | ||
184 | } | ||
185 | catch (NotImplementedException) | ||
186 | { | ||
187 | m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value + | ||
188 | " parser does not support file loading. (May be save only)"); | ||
189 | throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value)); | ||
190 | } | ||
191 | catch (FileNotFoundException) | ||
192 | { | ||
193 | m_log.Error( | ||
194 | "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)"); | ||
195 | throw new TerrainException( | ||
196 | String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", filename)); | ||
197 | } | ||
198 | catch (ArgumentException e) | ||
199 | { | ||
200 | m_log.ErrorFormat("[TERRAIN]: Unable to load heightmap: {0}", e.Message); | ||
201 | throw new TerrainException( | ||
202 | String.Format("Unable to load heightmap: {0}", e.Message)); | ||
203 | } | ||
204 | } | ||
205 | CheckForTerrainUpdates(); | ||
206 | m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully"); | ||
207 | return; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader available for that format."); | ||
212 | throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); | ||
213 | } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Saves the current heightmap to a specified file. | ||
217 | /// </summary> | ||
218 | /// <param name="filename">The destination filename</param> | ||
219 | public void SaveToFile(string filename) | ||
220 | { | ||
221 | try | ||
222 | { | ||
223 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
224 | { | ||
225 | if (filename.EndsWith(loader.Key)) | ||
226 | { | ||
227 | loader.Value.SaveFile(filename, m_channel); | ||
228 | return; | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | catch (NotImplementedException) | ||
233 | { | ||
234 | m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented."); | ||
235 | throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented")); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | /// <summary> | ||
240 | /// Loads a terrain file from a stream and installs it in the scene. | ||
241 | /// </summary> | ||
242 | /// <param name="filename">Filename to terrain file. Type is determined by extension.</param> | ||
243 | /// <param name="stream"></param> | ||
244 | public void LoadFromStream(string filename, Stream stream) | ||
245 | { | ||
246 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
247 | { | ||
248 | if (@filename.EndsWith(loader.Key)) | ||
249 | { | ||
250 | lock (m_scene) | ||
251 | { | ||
252 | try | ||
253 | { | ||
254 | ITerrainChannel channel = loader.Value.LoadStream(stream); | ||
255 | m_scene.Heightmap = channel; | ||
256 | m_channel = channel; | ||
257 | UpdateRevertMap(); | ||
258 | } | ||
259 | catch (NotImplementedException) | ||
260 | { | ||
261 | m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value + | ||
262 | " parser does not support file loading. (May be save only)"); | ||
263 | throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value)); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | CheckForTerrainUpdates(); | ||
268 | m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully"); | ||
269 | return; | ||
270 | } | ||
271 | } | ||
272 | m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader available for that format."); | ||
273 | throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); | ||
274 | } | ||
275 | |||
276 | /// <summary> | ||
277 | /// Modify Land | ||
278 | /// </summary> | ||
279 | /// <param name="pos">Land-position (X,Y,0)</param> | ||
280 | /// <param name="size">The size of the brush (0=small, 1=medium, 2=large)</param> | ||
281 | /// <param name="action">0=LAND_LEVEL, 1=LAND_RAISE, 2=LAND_LOWER, 3=LAND_SMOOTH, 4=LAND_NOISE, 5=LAND_REVERT</param> | ||
282 | /// <param name="agentId">UUID of script-owner</param> | ||
283 | public void ModifyTerrain(UUID user, Vector3 pos, byte size, byte action, UUID agentId) | ||
284 | { | ||
285 | client_OnModifyTerrain(user, (float)pos.Z, (float)0.25, size, action, pos.Y, pos.X, pos.Y, pos.X, agentId); | ||
286 | } | ||
287 | |||
288 | /// <summary> | ||
289 | /// Saves the current heightmap to a specified stream. | ||
290 | /// </summary> | ||
291 | /// <param name="filename">The destination filename. Used here only to identify the image type</param> | ||
292 | /// <param name="stream"></param> | ||
293 | public void SaveToStream(string filename, Stream stream) | ||
294 | { | ||
295 | try | ||
296 | { | ||
297 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
298 | { | ||
299 | if (filename.EndsWith(loader.Key)) | ||
300 | { | ||
301 | loader.Value.SaveStream(stream, m_channel); | ||
302 | return; | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | catch (NotImplementedException) | ||
307 | { | ||
308 | m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented."); | ||
309 | throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented")); | ||
310 | } | ||
311 | } | ||
312 | |||
313 | #region Plugin Loading Methods | ||
314 | |||
315 | private void LoadPlugins() | ||
316 | { | ||
317 | m_plugineffects = new Dictionary<string, ITerrainEffect>(); | ||
318 | // Load the files in the Terrain/ dir | ||
319 | string[] files = Directory.GetFiles("Terrain"); | ||
320 | foreach (string file in files) | ||
321 | { | ||
322 | m_log.Info("Loading effects in " + file); | ||
323 | try | ||
324 | { | ||
325 | Assembly library = Assembly.LoadFrom(file); | ||
326 | foreach (Type pluginType in library.GetTypes()) | ||
327 | { | ||
328 | try | ||
329 | { | ||
330 | if (pluginType.IsAbstract || pluginType.IsNotPublic) | ||
331 | continue; | ||
332 | |||
333 | string typeName = pluginType.Name; | ||
334 | |||
335 | if (pluginType.GetInterface("ITerrainEffect", false) != null) | ||
336 | { | ||
337 | ITerrainEffect terEffect = (ITerrainEffect) Activator.CreateInstance(library.GetType(pluginType.ToString())); | ||
338 | |||
339 | InstallPlugin(typeName, terEffect); | ||
340 | } | ||
341 | else if (pluginType.GetInterface("ITerrainLoader", false) != null) | ||
342 | { | ||
343 | ITerrainLoader terLoader = (ITerrainLoader) Activator.CreateInstance(library.GetType(pluginType.ToString())); | ||
344 | m_loaders[terLoader.FileExtension] = terLoader; | ||
345 | m_log.Info("L ... " + typeName); | ||
346 | } | ||
347 | } | ||
348 | catch (AmbiguousMatchException) | ||
349 | { | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | catch (BadImageFormatException) | ||
354 | { | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | |||
359 | public void InstallPlugin(string pluginName, ITerrainEffect effect) | ||
360 | { | ||
361 | lock (m_plugineffects) | ||
362 | { | ||
363 | if (!m_plugineffects.ContainsKey(pluginName)) | ||
364 | { | ||
365 | m_plugineffects.Add(pluginName, effect); | ||
366 | m_log.Info("E ... " + pluginName); | ||
367 | } | ||
368 | else | ||
369 | { | ||
370 | m_plugineffects[pluginName] = effect; | ||
371 | m_log.Warn("E ... " + pluginName + " (Replaced)"); | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | |||
376 | #endregion | ||
377 | |||
378 | #endregion | ||
379 | |||
380 | /// <summary> | ||
381 | /// Installs into terrain module the standard suite of brushes | ||
382 | /// </summary> | ||
383 | private void InstallDefaultEffects() | ||
384 | { | ||
385 | // Draggable Paint Brush Effects | ||
386 | m_painteffects[StandardTerrainEffects.Raise] = new RaiseSphere(); | ||
387 | m_painteffects[StandardTerrainEffects.Lower] = new LowerSphere(); | ||
388 | m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere(); | ||
389 | m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere(); | ||
390 | m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere(); | ||
391 | m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert); | ||
392 | m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere(); | ||
393 | m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere(); | ||
394 | m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere(); | ||
395 | |||
396 | // Area of effect selection effects | ||
397 | m_floodeffects[StandardTerrainEffects.Raise] = new RaiseArea(); | ||
398 | m_floodeffects[StandardTerrainEffects.Lower] = new LowerArea(); | ||
399 | m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea(); | ||
400 | m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea(); | ||
401 | m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); | ||
402 | m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); | ||
403 | |||
404 | // Filesystem load/save loaders | ||
405 | m_loaders[".r32"] = new RAW32(); | ||
406 | m_loaders[".f32"] = m_loaders[".r32"]; | ||
407 | m_loaders[".ter"] = new Terragen(); | ||
408 | m_loaders[".raw"] = new LLRAW(); | ||
409 | m_loaders[".jpg"] = new JPEG(); | ||
410 | m_loaders[".jpeg"] = m_loaders[".jpg"]; | ||
411 | m_loaders[".bmp"] = new BMP(); | ||
412 | m_loaders[".png"] = new PNG(); | ||
413 | m_loaders[".gif"] = new GIF(); | ||
414 | m_loaders[".tif"] = new TIFF(); | ||
415 | m_loaders[".tiff"] = m_loaders[".tif"]; | ||
416 | } | ||
417 | |||
418 | /// <summary> | ||
419 | /// Saves the current state of the region into the revert map buffer. | ||
420 | /// </summary> | ||
421 | public void UpdateRevertMap() | ||
422 | { | ||
423 | int x; | ||
424 | for (x = 0; x < m_channel.Width; x++) | ||
425 | { | ||
426 | int y; | ||
427 | for (y = 0; y < m_channel.Height; y++) | ||
428 | { | ||
429 | m_revert[x, y] = m_channel[x, y]; | ||
430 | } | ||
431 | } | ||
432 | } | ||
433 | |||
434 | /// <summary> | ||
435 | /// Loads a tile from a larger terrain file and installs it into the region. | ||
436 | /// </summary> | ||
437 | /// <param name="filename">The terrain file to load</param> | ||
438 | /// <param name="fileWidth">The width of the file in units</param> | ||
439 | /// <param name="fileHeight">The height of the file in units</param> | ||
440 | /// <param name="fileStartX">Where to begin our slice</param> | ||
441 | /// <param name="fileStartY">Where to begin our slice</param> | ||
442 | public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) | ||
443 | { | ||
444 | int offsetX = (int) m_scene.RegionInfo.RegionLocX - fileStartX; | ||
445 | int offsetY = (int) m_scene.RegionInfo.RegionLocY - fileStartY; | ||
446 | |||
447 | if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight) | ||
448 | { | ||
449 | // this region is included in the tile request | ||
450 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
451 | { | ||
452 | if (filename.EndsWith(loader.Key)) | ||
453 | { | ||
454 | lock (m_scene) | ||
455 | { | ||
456 | ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY, | ||
457 | fileWidth, fileHeight, | ||
458 | (int) Constants.RegionSize, | ||
459 | (int) Constants.RegionSize); | ||
460 | m_scene.Heightmap = channel; | ||
461 | m_channel = channel; | ||
462 | UpdateRevertMap(); | ||
463 | } | ||
464 | return; | ||
465 | } | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | |||
470 | /// <summary> | ||
471 | /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections | ||
472 | /// </summary> | ||
473 | private void EventManager_OnTerrainTick() | ||
474 | { | ||
475 | if (m_tainted) | ||
476 | { | ||
477 | m_tainted = false; | ||
478 | m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised()); | ||
479 | m_scene.SaveTerrain(); | ||
480 | |||
481 | // Clients who look at the map will never see changes after they looked at the map, so i've commented this out. | ||
482 | //m_scene.CreateTerrainTexture(true); | ||
483 | } | ||
484 | } | ||
485 | |||
486 | /// <summary> | ||
487 | /// Processes commandline input. Do not call directly. | ||
488 | /// </summary> | ||
489 | /// <param name="args">Commandline arguments</param> | ||
490 | private void EventManager_OnPluginConsole(string[] args) | ||
491 | { | ||
492 | if (args[0] == "terrain") | ||
493 | { | ||
494 | if (args.Length == 1) | ||
495 | { | ||
496 | m_commander.ProcessConsoleCommand("help", new string[0]); | ||
497 | return; | ||
498 | } | ||
499 | |||
500 | string[] tmpArgs = new string[args.Length - 2]; | ||
501 | int i; | ||
502 | for (i = 2; i < args.Length; i++) | ||
503 | tmpArgs[i - 2] = args[i]; | ||
504 | |||
505 | m_commander.ProcessConsoleCommand(args[1], tmpArgs); | ||
506 | } | ||
507 | } | ||
508 | |||
509 | /// <summary> | ||
510 | /// Installs terrain brush hook to IClientAPI | ||
511 | /// </summary> | ||
512 | /// <param name="client"></param> | ||
513 | private void EventManager_OnNewClient(IClientAPI client) | ||
514 | { | ||
515 | client.OnModifyTerrain += client_OnModifyTerrain; | ||
516 | client.OnBakeTerrain += client_OnBakeTerrain; | ||
517 | } | ||
518 | |||
519 | /// <summary> | ||
520 | /// Checks to see if the terrain has been modified since last check | ||
521 | /// but won't attempt to limit those changes to the limits specified in the estate settings | ||
522 | /// currently invoked by the command line operations in the region server only | ||
523 | /// </summary> | ||
524 | private void CheckForTerrainUpdates() | ||
525 | { | ||
526 | CheckForTerrainUpdates(false); | ||
527 | } | ||
528 | |||
529 | /// <summary> | ||
530 | /// Checks to see if the terrain has been modified since last check. | ||
531 | /// If it has been modified, every all the terrain patches are sent to the client. | ||
532 | /// If the call is asked to respect the estate settings for terrain_raise_limit and | ||
533 | /// terrain_lower_limit, it will clamp terrain updates between these values | ||
534 | /// currently invoked by client_OnModifyTerrain only and not the Commander interfaces | ||
535 | /// <param name="respectEstateSettings">should height map deltas be limited to the estate settings limits</param> | ||
536 | /// </summary> | ||
537 | private void CheckForTerrainUpdates(bool respectEstateSettings) | ||
538 | { | ||
539 | bool shouldTaint = false; | ||
540 | float[] serialised = m_channel.GetFloatsSerialised(); | ||
541 | int x; | ||
542 | for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize) | ||
543 | { | ||
544 | int y; | ||
545 | for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize) | ||
546 | { | ||
547 | if (m_channel.Tainted(x, y)) | ||
548 | { | ||
549 | // if we should respect the estate settings then | ||
550 | // fixup and height deltas that don't respect them | ||
551 | if (respectEstateSettings && LimitChannelChanges(x, y)) | ||
552 | { | ||
553 | // this has been vetoed, so update | ||
554 | // what we are going to send to the client | ||
555 | serialised = m_channel.GetFloatsSerialised(); | ||
556 | } | ||
557 | |||
558 | SendToClients(serialised, x, y); | ||
559 | shouldTaint = true; | ||
560 | } | ||
561 | } | ||
562 | } | ||
563 | if (shouldTaint) | ||
564 | { | ||
565 | m_tainted = true; | ||
566 | } | ||
567 | } | ||
568 | |||
569 | /// <summary> | ||
570 | /// Checks to see height deltas in the tainted terrain patch at xStart ,yStart | ||
571 | /// are all within the current estate limits | ||
572 | /// <returns>true if changes were limited, false otherwise</returns> | ||
573 | /// </summary> | ||
574 | private bool LimitChannelChanges(int xStart, int yStart) | ||
575 | { | ||
576 | bool changesLimited = false; | ||
577 | double minDelta = m_scene.RegionInfo.RegionSettings.TerrainLowerLimit; | ||
578 | double maxDelta = m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit; | ||
579 | |||
580 | // loop through the height map for this patch and compare it against | ||
581 | // the revert map | ||
582 | for (int x = xStart; x < xStart + Constants.TerrainPatchSize; x++) | ||
583 | { | ||
584 | for (int y = yStart; y < yStart + Constants.TerrainPatchSize; y++) | ||
585 | { | ||
586 | |||
587 | double requestedHeight = m_channel[x, y]; | ||
588 | double bakedHeight = m_revert[x, y]; | ||
589 | double requestedDelta = requestedHeight - bakedHeight; | ||
590 | |||
591 | if (requestedDelta > maxDelta) | ||
592 | { | ||
593 | m_channel[x, y] = bakedHeight + maxDelta; | ||
594 | changesLimited = true; | ||
595 | } | ||
596 | else if (requestedDelta < minDelta) | ||
597 | { | ||
598 | m_channel[x, y] = bakedHeight + minDelta; //as lower is a -ve delta | ||
599 | changesLimited = true; | ||
600 | } | ||
601 | } | ||
602 | } | ||
603 | |||
604 | return changesLimited; | ||
605 | } | ||
606 | |||
607 | /// <summary> | ||
608 | /// Sends a copy of the current terrain to the scenes clients | ||
609 | /// </summary> | ||
610 | /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param> | ||
611 | /// <param name="x">The patch corner to send</param> | ||
612 | /// <param name="y">The patch corner to send</param> | ||
613 | private void SendToClients(float[] serialised, int x, int y) | ||
614 | { | ||
615 | m_scene.ForEachClient( | ||
616 | delegate(IClientAPI controller) | ||
617 | { controller.SendLayerData( | ||
618 | x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised); | ||
619 | } | ||
620 | ); | ||
621 | } | ||
622 | |||
623 | private void client_OnModifyTerrain(UUID user, float height, float seconds, byte size, byte action, | ||
624 | float north, float west, float south, float east, UUID agentId) | ||
625 | { | ||
626 | bool god = m_scene.Permissions.IsGod(user); | ||
627 | bool allowed = false; | ||
628 | if (north == south && east == west) | ||
629 | { | ||
630 | if (m_painteffects.ContainsKey((StandardTerrainEffects) action)) | ||
631 | { | ||
632 | bool[,] allowMask = new bool[m_channel.Width,m_channel.Height]; | ||
633 | allowMask.Initialize(); | ||
634 | int n = size + 1; | ||
635 | if (n > 2) | ||
636 | n = 4; | ||
637 | |||
638 | int zx = (int) (west + 0.5); | ||
639 | int zy = (int) (north + 0.5); | ||
640 | |||
641 | int dx; | ||
642 | for (dx=-n; dx<=n; dx++) | ||
643 | { | ||
644 | int dy; | ||
645 | for (dy=-n; dy<=n; dy++) | ||
646 | { | ||
647 | int x = zx + dx; | ||
648 | int y = zy + dy; | ||
649 | if (x>=0 && y>=0 && x<m_channel.Width && y<m_channel.Height) | ||
650 | { | ||
651 | if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x,y,0))) | ||
652 | { | ||
653 | allowMask[x, y] = true; | ||
654 | allowed = true; | ||
655 | } | ||
656 | } | ||
657 | } | ||
658 | } | ||
659 | if (allowed) | ||
660 | { | ||
661 | m_painteffects[(StandardTerrainEffects) action].PaintEffect( | ||
662 | m_channel, allowMask, west, south, height, size, seconds); | ||
663 | |||
664 | CheckForTerrainUpdates(!god); //revert changes outside estate limits | ||
665 | } | ||
666 | } | ||
667 | else | ||
668 | { | ||
669 | m_log.Debug("Unknown terrain brush type " + action); | ||
670 | } | ||
671 | } | ||
672 | else | ||
673 | { | ||
674 | if (m_floodeffects.ContainsKey((StandardTerrainEffects) action)) | ||
675 | { | ||
676 | bool[,] fillArea = new bool[m_channel.Width,m_channel.Height]; | ||
677 | fillArea.Initialize(); | ||
678 | |||
679 | int x; | ||
680 | for (x = 0; x < m_channel.Width; x++) | ||
681 | { | ||
682 | int y; | ||
683 | for (y = 0; y < m_channel.Height; y++) | ||
684 | { | ||
685 | if (x < east && x > west) | ||
686 | { | ||
687 | if (y < north && y > south) | ||
688 | { | ||
689 | if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x,y,0))) | ||
690 | { | ||
691 | fillArea[x, y] = true; | ||
692 | allowed = true; | ||
693 | } | ||
694 | } | ||
695 | } | ||
696 | } | ||
697 | } | ||
698 | |||
699 | if (allowed) | ||
700 | { | ||
701 | m_floodeffects[(StandardTerrainEffects) action].FloodEffect( | ||
702 | m_channel, fillArea, size); | ||
703 | |||
704 | CheckForTerrainUpdates(!god); //revert changes outside estate limits | ||
705 | } | ||
706 | } | ||
707 | else | ||
708 | { | ||
709 | m_log.Debug("Unknown terrain flood type " + action); | ||
710 | } | ||
711 | } | ||
712 | } | ||
713 | |||
714 | private void client_OnBakeTerrain(IClientAPI remoteClient) | ||
715 | { | ||
716 | // Not a good permissions check (see client_OnModifyTerrain above), need to check the entire area. | ||
717 | // for now check a point in the centre of the region | ||
718 | |||
719 | if (m_scene.Permissions.CanIssueEstateCommand(remoteClient.AgentId, true)) | ||
720 | { | ||
721 | InterfaceBakeTerrain(null); //bake terrain does not use the passed in parameter | ||
722 | } | ||
723 | } | ||
724 | |||
725 | #region Console Commands | ||
726 | |||
727 | private void InterfaceLoadFile(Object[] args) | ||
728 | { | ||
729 | LoadFromFile((string) args[0]); | ||
730 | CheckForTerrainUpdates(); | ||
731 | } | ||
732 | |||
733 | private void InterfaceLoadTileFile(Object[] args) | ||
734 | { | ||
735 | LoadFromFile((string) args[0], | ||
736 | (int) args[1], | ||
737 | (int) args[2], | ||
738 | (int) args[3], | ||
739 | (int) args[4]); | ||
740 | CheckForTerrainUpdates(); | ||
741 | } | ||
742 | |||
743 | private void InterfaceSaveFile(Object[] args) | ||
744 | { | ||
745 | SaveToFile((string) args[0]); | ||
746 | } | ||
747 | |||
748 | private void InterfaceBakeTerrain(Object[] args) | ||
749 | { | ||
750 | UpdateRevertMap(); | ||
751 | } | ||
752 | |||
753 | private void InterfaceRevertTerrain(Object[] args) | ||
754 | { | ||
755 | int x, y; | ||
756 | for (x = 0; x < m_channel.Width; x++) | ||
757 | for (y = 0; y < m_channel.Height; y++) | ||
758 | m_channel[x, y] = m_revert[x, y]; | ||
759 | |||
760 | CheckForTerrainUpdates(); | ||
761 | } | ||
762 | |||
763 | private void InterfaceFlipTerrain(Object[] args) | ||
764 | { | ||
765 | String direction = (String)args[0]; | ||
766 | |||
767 | if (direction.ToLower().StartsWith("y")) | ||
768 | { | ||
769 | for (int x = 0; x < Constants.RegionSize; x++) | ||
770 | { | ||
771 | for (int y = 0; y < Constants.RegionSize / 2; y++) | ||
772 | { | ||
773 | double height = m_channel[x, y]; | ||
774 | double flippedHeight = m_channel[x, (int)Constants.RegionSize - 1 - y]; | ||
775 | m_channel[x, y] = flippedHeight; | ||
776 | m_channel[x, (int)Constants.RegionSize - 1 - y] = height; | ||
777 | |||
778 | } | ||
779 | } | ||
780 | } | ||
781 | else if (direction.ToLower().StartsWith("x")) | ||
782 | { | ||
783 | for (int y = 0; y < Constants.RegionSize; y++) | ||
784 | { | ||
785 | for (int x = 0; x < Constants.RegionSize / 2; x++) | ||
786 | { | ||
787 | double height = m_channel[x, y]; | ||
788 | double flippedHeight = m_channel[(int)Constants.RegionSize - 1 - x, y]; | ||
789 | m_channel[x, y] = flippedHeight; | ||
790 | m_channel[(int)Constants.RegionSize - 1 - x, y] = height; | ||
791 | |||
792 | } | ||
793 | } | ||
794 | } | ||
795 | else | ||
796 | { | ||
797 | m_log.Error("Unrecognised direction - need x or y"); | ||
798 | } | ||
799 | |||
800 | |||
801 | CheckForTerrainUpdates(); | ||
802 | } | ||
803 | |||
804 | private void InterfaceElevateTerrain(Object[] args) | ||
805 | { | ||
806 | int x, y; | ||
807 | for (x = 0; x < m_channel.Width; x++) | ||
808 | for (y = 0; y < m_channel.Height; y++) | ||
809 | m_channel[x, y] += (double) args[0]; | ||
810 | CheckForTerrainUpdates(); | ||
811 | } | ||
812 | |||
813 | private void InterfaceMultiplyTerrain(Object[] args) | ||
814 | { | ||
815 | int x, y; | ||
816 | for (x = 0; x < m_channel.Width; x++) | ||
817 | for (y = 0; y < m_channel.Height; y++) | ||
818 | m_channel[x, y] *= (double) args[0]; | ||
819 | CheckForTerrainUpdates(); | ||
820 | } | ||
821 | |||
822 | private void InterfaceLowerTerrain(Object[] args) | ||
823 | { | ||
824 | int x, y; | ||
825 | for (x = 0; x < m_channel.Width; x++) | ||
826 | for (y = 0; y < m_channel.Height; y++) | ||
827 | m_channel[x, y] -= (double) args[0]; | ||
828 | CheckForTerrainUpdates(); | ||
829 | } | ||
830 | |||
831 | private void InterfaceFillTerrain(Object[] args) | ||
832 | { | ||
833 | int x, y; | ||
834 | |||
835 | for (x = 0; x < m_channel.Width; x++) | ||
836 | for (y = 0; y < m_channel.Height; y++) | ||
837 | m_channel[x, y] = (double) args[0]; | ||
838 | CheckForTerrainUpdates(); | ||
839 | } | ||
840 | |||
841 | private void InterfaceShowDebugStats(Object[] args) | ||
842 | { | ||
843 | double max = Double.MinValue; | ||
844 | double min = double.MaxValue; | ||
845 | double sum = 0; | ||
846 | |||
847 | int x; | ||
848 | for (x = 0; x < m_channel.Width; x++) | ||
849 | { | ||
850 | int y; | ||
851 | for (y = 0; y < m_channel.Height; y++) | ||
852 | { | ||
853 | sum += m_channel[x, y]; | ||
854 | if (max < m_channel[x, y]) | ||
855 | max = m_channel[x, y]; | ||
856 | if (min > m_channel[x, y]) | ||
857 | min = m_channel[x, y]; | ||
858 | } | ||
859 | } | ||
860 | |||
861 | double avg = sum / (m_channel.Height * m_channel.Width); | ||
862 | |||
863 | m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height); | ||
864 | m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum); | ||
865 | } | ||
866 | |||
867 | private void InterfaceEnableExperimentalBrushes(Object[] args) | ||
868 | { | ||
869 | if ((bool) args[0]) | ||
870 | { | ||
871 | m_painteffects[StandardTerrainEffects.Revert] = new WeatherSphere(); | ||
872 | m_painteffects[StandardTerrainEffects.Flatten] = new OlsenSphere(); | ||
873 | m_painteffects[StandardTerrainEffects.Smooth] = new ErodeSphere(); | ||
874 | } | ||
875 | else | ||
876 | { | ||
877 | InstallDefaultEffects(); | ||
878 | } | ||
879 | } | ||
880 | |||
881 | private void InterfaceRunPluginEffect(Object[] args) | ||
882 | { | ||
883 | if ((string) args[0] == "list") | ||
884 | { | ||
885 | m_log.Info("List of loaded plugins"); | ||
886 | foreach (KeyValuePair<string, ITerrainEffect> kvp in m_plugineffects) | ||
887 | { | ||
888 | m_log.Info(kvp.Key); | ||
889 | } | ||
890 | return; | ||
891 | } | ||
892 | if ((string) args[0] == "reload") | ||
893 | { | ||
894 | LoadPlugins(); | ||
895 | return; | ||
896 | } | ||
897 | if (m_plugineffects.ContainsKey((string) args[0])) | ||
898 | { | ||
899 | m_plugineffects[(string) args[0]].RunEffect(m_channel); | ||
900 | CheckForTerrainUpdates(); | ||
901 | } | ||
902 | else | ||
903 | { | ||
904 | m_log.Warn("No such plugin effect loaded."); | ||
905 | } | ||
906 | } | ||
907 | |||
908 | private void InstallInterfaces() | ||
909 | { | ||
910 | // Load / Save | ||
911 | string supportedFileExtensions = ""; | ||
912 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
913 | supportedFileExtensions += " " + loader.Key + " (" + loader.Value + ")"; | ||
914 | |||
915 | Command loadFromFileCommand = | ||
916 | new Command("load", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadFile, "Loads a terrain from a specified file."); | ||
917 | loadFromFileCommand.AddArgument("filename", | ||
918 | "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + | ||
919 | supportedFileExtensions, "String"); | ||
920 | |||
921 | Command saveToFileCommand = | ||
922 | new Command("save", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveFile, "Saves the current heightmap to a specified file."); | ||
923 | saveToFileCommand.AddArgument("filename", | ||
924 | "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " + | ||
925 | supportedFileExtensions, "String"); | ||
926 | |||
927 | Command loadFromTileCommand = | ||
928 | new Command("load-tile", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadTileFile, "Loads a terrain from a section of a larger file."); | ||
929 | loadFromTileCommand.AddArgument("filename", | ||
930 | "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + | ||
931 | supportedFileExtensions, "String"); | ||
932 | loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer"); | ||
933 | loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer"); | ||
934 | loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file", | ||
935 | "Integer"); | ||
936 | loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", | ||
937 | "Integer"); | ||
938 | |||
939 | // Terrain adjustments | ||
940 | Command fillRegionCommand = | ||
941 | new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); | ||
942 | fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.", | ||
943 | "Double"); | ||
944 | |||
945 | Command elevateCommand = | ||
946 | new Command("elevate", CommandIntentions.COMMAND_HAZARDOUS, InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); | ||
947 | elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double"); | ||
948 | |||
949 | Command lowerCommand = | ||
950 | new Command("lower", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); | ||
951 | lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double"); | ||
952 | |||
953 | Command multiplyCommand = | ||
954 | new Command("multiply", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); | ||
955 | multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); | ||
956 | |||
957 | Command bakeRegionCommand = | ||
958 | new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); | ||
959 | Command revertRegionCommand = | ||
960 | new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); | ||
961 | |||
962 | Command flipCommand = | ||
963 | new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis"); | ||
964 | flipCommand.AddArgument("direction", "[x|y] the direction to flip the terrain in", "String"); | ||
965 | |||
966 | // Debug | ||
967 | Command showDebugStatsCommand = | ||
968 | new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats, | ||
969 | "Shows some information about the regions heightmap for debugging purposes."); | ||
970 | |||
971 | Command experimentalBrushesCommand = | ||
972 | new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes, | ||
973 | "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); | ||
974 | experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); | ||
975 | |||
976 | //Plugins | ||
977 | Command pluginRunCommand = | ||
978 | new Command("effect", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRunPluginEffect, "Runs a specified plugin effect"); | ||
979 | pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String"); | ||
980 | |||
981 | m_commander.RegisterCommand("load", loadFromFileCommand); | ||
982 | m_commander.RegisterCommand("load-tile", loadFromTileCommand); | ||
983 | m_commander.RegisterCommand("save", saveToFileCommand); | ||
984 | m_commander.RegisterCommand("fill", fillRegionCommand); | ||
985 | m_commander.RegisterCommand("elevate", elevateCommand); | ||
986 | m_commander.RegisterCommand("lower", lowerCommand); | ||
987 | m_commander.RegisterCommand("multiply", multiplyCommand); | ||
988 | m_commander.RegisterCommand("bake", bakeRegionCommand); | ||
989 | m_commander.RegisterCommand("revert", revertRegionCommand); | ||
990 | m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand); | ||
991 | m_commander.RegisterCommand("stats", showDebugStatsCommand); | ||
992 | m_commander.RegisterCommand("effect", pluginRunCommand); | ||
993 | m_commander.RegisterCommand("flip", flipCommand); | ||
994 | |||
995 | // Add this to our scene so scripts can call these functions | ||
996 | m_scene.RegisterModuleCommander(m_commander); | ||
997 | } | ||
998 | |||
999 | #endregion | ||
1000 | } | ||
1001 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs new file mode 100644 index 0000000..e7f92d7 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; | ||
32 | |||
33 | namespace OpenSim.Region.CoreModules.World.Terrain.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class TerrainTest | ||
37 | { | ||
38 | [Test] | ||
39 | public void BrushTest() | ||
40 | { | ||
41 | bool[,] allowMask = new bool[256, 256]; | ||
42 | int x; | ||
43 | int y; | ||
44 | for (x=0; x<128; x++) | ||
45 | { | ||
46 | for (y=0; y<256; y++) | ||
47 | { | ||
48 | allowMask[x,y] = true; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | // | ||
53 | // Test RaiseSphere | ||
54 | // | ||
55 | TerrainChannel map = new TerrainChannel(256, 256); | ||
56 | ITerrainPaintableEffect effect = new RaiseSphere(); | ||
57 | |||
58 | effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 0.1); | ||
59 | Assert.That(map[127, 128] > 0.0, "Raise brush should raising value at this point (127,128)."); | ||
60 | Assert.That(map[124, 128] > 0.0, "Raise brush should raising value at this point (124,128)."); | ||
61 | Assert.That(map[123, 128] == 0.0, "Raise brush should not change value at this point (123,128)."); | ||
62 | Assert.That(map[128, 128] == 0.0, "Raise brush should not change value at this point (128,128)."); | ||
63 | Assert.That(map[0, 128] == 0.0, "Raise brush should not change value at this point (0,128)."); | ||
64 | |||
65 | // | ||
66 | // Test LowerSphere | ||
67 | // | ||
68 | map = new TerrainChannel(256, 256); | ||
69 | for (x=0; x<map.Width; x++) | ||
70 | { | ||
71 | for (y=0; y<map.Height; y++) | ||
72 | { | ||
73 | map[x,y] = 1.0; | ||
74 | } | ||
75 | } | ||
76 | effect = new LowerSphere(); | ||
77 | |||
78 | effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 6.0); | ||
79 | Assert.That(map[127, 128] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128)."); | ||
80 | Assert.That(map[127, 128] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128)."); | ||
81 | Assert.That(map[124, 128] < 1.0, "Lower brush should lowering value at this point (124,128)."); | ||
82 | Assert.That(map[123, 128] == 1.0, "Lower brush should not change value at this point (123,128)."); | ||
83 | Assert.That(map[128, 128] == 1.0, "Lower brush should not change value at this point (128,128)."); | ||
84 | Assert.That(map[0, 128] == 1.0, "Lower brush should not change value at this point (0,128)."); | ||
85 | } | ||
86 | |||
87 | [Test] | ||
88 | public void TerrainChannelTest() | ||
89 | { | ||
90 | TerrainChannel x = new TerrainChannel(256, 256); | ||
91 | Assert.That(x[0, 0] == 0.0, "Terrain not initialising correctly."); | ||
92 | |||
93 | x[0, 0] = 1.0; | ||
94 | Assert.That(x[0, 0] == 1.0, "Terrain not setting values correctly."); | ||
95 | |||
96 | x[0, 0] = 0; | ||
97 | x[0, 0] += 5.0; | ||
98 | x[0, 0] -= 1.0; | ||
99 | Assert.That(x[0, 0] == 4.0, "Terrain addition/subtraction error."); | ||
100 | |||
101 | x[0, 0] = Math.PI; | ||
102 | double[,] doublesExport = x.GetDoubles(); | ||
103 | Assert.That(doublesExport[0, 0] == Math.PI, "Export to double[,] array not working correctly."); | ||
104 | |||
105 | x[0, 0] = 1.0; | ||
106 | float[] floatsExport = x.GetFloatsSerialised(); | ||
107 | Assert.That(floatsExport[0] == 1.0f, "Export to float[] not working correctly."); | ||
108 | |||
109 | x[0, 0] = 1.0; | ||
110 | Assert.That(x.Tainted(0, 0), "Terrain channel tainting not working correctly."); | ||
111 | Assert.That(!x.Tainted(0, 0), "Terrain channel tainting not working correctly."); | ||
112 | |||
113 | TerrainChannel y = x.Copy(); | ||
114 | Assert.That(!ReferenceEquals(x, y), "Terrain copy not duplicating correctly."); | ||
115 | Assert.That(!ReferenceEquals(x.GetDoubles(), y.GetDoubles()), "Terrain array not duplicating correctly."); | ||
116 | } | ||
117 | } | ||
118 | } | ||