diff options
author | Adam Frisby | 2008-04-30 21:22:29 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-30 21:22:29 +0000 |
commit | 4a8c1e4393ac64c84b03aeb16bacb9ddd0a2fae6 (patch) | |
tree | 49dde0575502e89aeed428b4190c68306e929b69 /OpenSim/Region/Environment/Modules/World/Terrain | |
parent | * Previous commit managed to miss some files despite me hitting 'Select all'. (diff) | |
download | opensim-SC_OLD-4a8c1e4393ac64c84b03aeb16bacb9ddd0a2fae6.zip opensim-SC_OLD-4a8c1e4393ac64c84b03aeb16bacb9ddd0a2fae6.tar.gz opensim-SC_OLD-4a8c1e4393ac64c84b03aeb16bacb9ddd0a2fae6.tar.bz2 opensim-SC_OLD-4a8c1e4393ac64c84b03aeb16bacb9ddd0a2fae6.tar.xz |
* Commiting a bunch of missed files.
Diffstat (limited to '')
36 files changed, 4134 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs new file mode 100644 index 0000000..731326e --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs | |||
@@ -0,0 +1,124 @@ | |||
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.Environment.Interfaces; | ||
29 | using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes; | ||
30 | using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects | ||
33 | { | ||
34 | internal class CookieCutter : ITerrainEffect | ||
35 | { | ||
36 | #region ITerrainEffect Members | ||
37 | |||
38 | public void RunEffect(ITerrainChannel map) | ||
39 | { | ||
40 | SmoothArea smooth = new SmoothArea(); | ||
41 | ITerrainPaintableEffect eroder = new WeatherSphere(); | ||
42 | |||
43 | bool[,] cliffMask = new bool[map.Width,map.Height]; | ||
44 | bool[,] channelMask = new bool[map.Width,map.Height]; | ||
45 | bool[,] smoothMask = 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 | |||
58 | // Start underwater | ||
59 | map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 5; | ||
60 | // Add a little height. (terrain should now be above water, mostly.) | ||
61 | map[x, y] += 20; | ||
62 | |||
63 | int channelsX = 4; | ||
64 | int channelWidth = (map.Width / channelsX / 4); | ||
65 | int channelsY = 4; | ||
66 | int channelHeight = (map.Height / channelsY / 4); | ||
67 | |||
68 | SetLowerChannel(map, cliffMask, channelMask, x, y, channelsX, channelWidth, map.Width, x); | ||
69 | SetLowerChannel(map, cliffMask, channelMask, x, y, channelsY, channelHeight, map.Height, y); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | Console.WriteLine("S2"); | ||
74 | //smooth.FloodEffect(map, smoothMask, 4.0); | ||
75 | |||
76 | Console.WriteLine("S3"); | ||
77 | for (x = 0; x < map.Width; x++) | ||
78 | { | ||
79 | for (y = 0; y < map.Height; y++) | ||
80 | { | ||
81 | if (cliffMask[x, y] == true) | ||
82 | eroder.PaintEffect(map, x, y, 4, 0.1); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | for (x = 0; x < map.Width; x += 2) | ||
87 | { | ||
88 | for (y = 0; y < map.Height; y += 2) | ||
89 | { | ||
90 | if (map[x, y] < 0.1) | ||
91 | map[x, y] = 0.1; | ||
92 | if (map[x, y] > 256) | ||
93 | map[x, y] = 256; | ||
94 | } | ||
95 | } | ||
96 | //smooth.FloodEffect(map, smoothMask, 4.0); | ||
97 | } | ||
98 | |||
99 | #endregion | ||
100 | |||
101 | private static void SetLowerChannel(ITerrainChannel map, bool[,] cliffMask, bool[,] channelMask, int x, int y, int numChannels, int channelWidth, | ||
102 | int mapSize, int rp) | ||
103 | { | ||
104 | for (int i = 0; i < numChannels; i++) | ||
105 | { | ||
106 | double distanceToLine = Math.Abs(rp - ((mapSize / numChannels) * i)); | ||
107 | |||
108 | if (distanceToLine < channelWidth) | ||
109 | { | ||
110 | if (channelMask[x, y]) | ||
111 | return; | ||
112 | |||
113 | // Remove channels | ||
114 | map[x, y] -= 10; | ||
115 | channelMask[x, y] = true; | ||
116 | } | ||
117 | if (distanceToLine < 1) | ||
118 | { | ||
119 | cliffMask[x, y] = true; | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/Effects/DefaultTerrainGenerator.cs b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/DefaultTerrainGenerator.cs new file mode 100644 index 0000000..9c35d4e --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/DefaultTerrainGenerator.cs | |||
@@ -0,0 +1,55 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects | ||
31 | { | ||
32 | internal class DefaultTerrainGenerator : ITerrainEffect | ||
33 | { | ||
34 | #region ITerrainEffect Members | ||
35 | |||
36 | public void RunEffect(ITerrainChannel map) | ||
37 | { | ||
38 | int x, y; | ||
39 | for (x = 0; x < map.Width; x++) | ||
40 | { | ||
41 | for (y = 0; y < map.Height; y++) | ||
42 | { | ||
43 | map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; | ||
44 | double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01; | ||
45 | if (map[x, y] < spherFac) | ||
46 | { | ||
47 | map[x, y] = spherFac; | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | #endregion | ||
54 | } | ||
55 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs new file mode 100644 index 0000000..4705dad --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs | |||
@@ -0,0 +1,62 @@ | |||
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.Drawing; | ||
28 | using System.Drawing.Imaging; | ||
29 | using OpenSim.Region.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// A generic windows bitmap loader. | ||
35 | /// Should be capable of handling 24-bit RGB images. | ||
36 | /// | ||
37 | /// Uses the System.Drawing filesystem loader. | ||
38 | /// </summary> | ||
39 | internal class BMP : GenericSystemDrawing | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Exports a file to a image on the disk using a System.Drawing exporter. | ||
43 | /// </summary> | ||
44 | /// <param name="filename">The target filename</param> | ||
45 | /// <param name="map">The terrain channel being saved</param> | ||
46 | public override void SaveFile(string filename, ITerrainChannel map) | ||
47 | { | ||
48 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
49 | |||
50 | colours.Save(filename, ImageFormat.Bmp); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// The human readable version of the file format(s) this loader handles | ||
55 | /// </summary> | ||
56 | /// <returns></returns> | ||
57 | public override string ToString() | ||
58 | { | ||
59 | return "BMP"; | ||
60 | } | ||
61 | } | ||
62 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs new file mode 100644 index 0000000..1dd923a --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs | |||
@@ -0,0 +1,48 @@ | |||
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.Drawing; | ||
28 | using System.Drawing.Imaging; | ||
29 | using OpenSim.Region.Environment.Interfaces; | ||
30 | using OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
33 | { | ||
34 | internal class GIF : GenericSystemDrawing | ||
35 | { | ||
36 | public override void SaveFile(string filename, ITerrainChannel map) | ||
37 | { | ||
38 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
39 | |||
40 | colours.Save(filename, ImageFormat.Gif); | ||
41 | } | ||
42 | |||
43 | public override string ToString() | ||
44 | { | ||
45 | return "GIF"; | ||
46 | } | ||
47 | } | ||
48 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs new file mode 100644 index 0000000..b5e6bd9 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs | |||
@@ -0,0 +1,172 @@ | |||
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 OpenSim.Region.Environment.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// A virtual class designed to have methods overloaded, | ||
37 | /// this class provides an interface for a generic image | ||
38 | /// saving and loading mechanism, but does not specify the | ||
39 | /// format. It should not be insubstantiated directly. | ||
40 | /// </summary> | ||
41 | public class GenericSystemDrawing : ITerrainLoader | ||
42 | { | ||
43 | #region ITerrainLoader Members | ||
44 | |||
45 | public string FileExtension | ||
46 | { | ||
47 | get { return ".gsd"; } | ||
48 | } | ||
49 | |||
50 | /// <summary> | ||
51 | /// Loads a file from a specified filename on the disk, | ||
52 | /// parses the image using the System.Drawing parsers | ||
53 | /// then returns a terrain channel. Values are | ||
54 | /// returned based on HSL brightness between 0m and 128m | ||
55 | /// </summary> | ||
56 | /// <param name="filename">The target image to load</param> | ||
57 | /// <returns>A terrain channel generated from the image.</returns> | ||
58 | public virtual ITerrainChannel LoadFile(string filename) | ||
59 | { | ||
60 | Bitmap file = new Bitmap(filename); | ||
61 | |||
62 | ITerrainChannel retval = new TerrainChannel(file.Width, file.Height); | ||
63 | |||
64 | int x, y; | ||
65 | for (x = 0; x < file.Width; x++) | ||
66 | { | ||
67 | for (y = 0; y < file.Height; y++) | ||
68 | { | ||
69 | retval[x, y] = file.GetPixel(x, y).GetBrightness() * 128; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return retval; | ||
74 | } | ||
75 | |||
76 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
77 | { | ||
78 | throw new NotImplementedException(); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Exports a file to a image on the disk using a System.Drawing exporter. | ||
83 | /// </summary> | ||
84 | /// <param name="filename">The target filename</param> | ||
85 | /// <param name="map">The terrain channel being saved</param> | ||
86 | public virtual void SaveFile(string filename, ITerrainChannel map) | ||
87 | { | ||
88 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
89 | |||
90 | colours.Save(filename, ImageFormat.Png); | ||
91 | } | ||
92 | |||
93 | #endregion | ||
94 | |||
95 | public override string ToString() | ||
96 | { | ||
97 | return "SYS.DRAWING"; | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// Protected method, generates a grayscale bitmap | ||
102 | /// image from a specified terrain channel. | ||
103 | /// </summary> | ||
104 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
105 | /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> | ||
106 | protected Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) | ||
107 | { | ||
108 | Bitmap bmp = new Bitmap(map.Width, map.Height); | ||
109 | |||
110 | int pallete = 256; | ||
111 | |||
112 | Color[] grays = new Color[pallete]; | ||
113 | for (int i = 0; i < grays.Length; i++) | ||
114 | { | ||
115 | grays[i] = Color.FromArgb(i, i, i); | ||
116 | } | ||
117 | |||
118 | for (int y = 0; y < map.Height; y++) | ||
119 | { | ||
120 | for (int x = 0; x < map.Width; x++) | ||
121 | { | ||
122 | // 512 is the largest possible height before colours clamp | ||
123 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); | ||
124 | |||
125 | // Handle error conditions | ||
126 | if (colorindex > pallete - 1 || colorindex < 0) | ||
127 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
128 | else | ||
129 | bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); | ||
130 | } | ||
131 | } | ||
132 | return bmp; | ||
133 | } | ||
134 | |||
135 | /// <summary> | ||
136 | /// Protected method, generates a coloured bitmap | ||
137 | /// image from a specified terrain channel. | ||
138 | /// </summary> | ||
139 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
140 | /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> | ||
141 | protected Bitmap CreateBitmapFromMap(ITerrainChannel map) | ||
142 | { | ||
143 | Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); | ||
144 | |||
145 | int pallete = gradientmapLd.Height; | ||
146 | |||
147 | Bitmap bmp = new Bitmap(map.Width, map.Height); | ||
148 | Color[] colours = new Color[pallete]; | ||
149 | |||
150 | for (int i = 0; i < pallete; i++) | ||
151 | { | ||
152 | colours[i] = gradientmapLd.GetPixel(0, i); | ||
153 | } | ||
154 | |||
155 | for (int y = 0; y < map.Height; y++) | ||
156 | { | ||
157 | for (int x = 0; x < map.Width; x++) | ||
158 | { | ||
159 | // 512 is the largest possible height before colours clamp | ||
160 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
161 | |||
162 | // Handle error conditions | ||
163 | if (colorindex > pallete - 1 || colorindex < 0) | ||
164 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
165 | else | ||
166 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | ||
167 | } | ||
168 | } | ||
169 | return bmp; | ||
170 | } | ||
171 | } | ||
172 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs new file mode 100644 index 0000000..39ade10 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs | |||
@@ -0,0 +1,94 @@ | |||
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 OpenSim.Region.Environment.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | public class JPEG : ITerrainLoader | ||
36 | { | ||
37 | #region ITerrainLoader Members | ||
38 | |||
39 | public string FileExtension | ||
40 | { | ||
41 | get { return ".jpg"; } | ||
42 | } | ||
43 | |||
44 | public ITerrainChannel LoadFile(string filename) | ||
45 | { | ||
46 | throw new NotImplementedException(); | ||
47 | } | ||
48 | |||
49 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
50 | { | ||
51 | throw new NotImplementedException(); | ||
52 | } | ||
53 | |||
54 | public void SaveFile(string filename, ITerrainChannel map) | ||
55 | { | ||
56 | Bitmap colours = CreateBitmapFromMap(map); | ||
57 | |||
58 | colours.Save(filename, ImageFormat.Jpeg); | ||
59 | } | ||
60 | |||
61 | #endregion | ||
62 | |||
63 | public override string ToString() | ||
64 | { | ||
65 | return "JPEG"; | ||
66 | } | ||
67 | |||
68 | private Bitmap CreateBitmapFromMap(ITerrainChannel map) | ||
69 | { | ||
70 | Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); | ||
71 | |||
72 | int pallete = gradientmapLd.Height; | ||
73 | |||
74 | Bitmap bmp = new Bitmap(map.Width, map.Height); | ||
75 | Color[] colours = new Color[pallete]; | ||
76 | |||
77 | for (int i = 0; i < pallete; i++) | ||
78 | { | ||
79 | colours[i] = gradientmapLd.GetPixel(0, i); | ||
80 | } | ||
81 | |||
82 | for (int y = 0; y < map.Height; y++) | ||
83 | { | ||
84 | for (int x = 0; x < map.Width; x++) | ||
85 | { | ||
86 | // 512 is the largest possible height before colours clamp | ||
87 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
88 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | ||
89 | } | ||
90 | } | ||
91 | return bmp; | ||
92 | } | ||
93 | } | ||
94 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs new file mode 100644 index 0000000..468ecc9 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs | |||
@@ -0,0 +1,148 @@ | |||
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.Environment.Interfaces; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
33 | { | ||
34 | public class LLRAW : ITerrainLoader | ||
35 | { | ||
36 | #region ITerrainLoader Members | ||
37 | |||
38 | public ITerrainChannel LoadFile(string filename) | ||
39 | { | ||
40 | TerrainChannel retval = new TerrainChannel(); | ||
41 | |||
42 | FileInfo file = new FileInfo(filename); | ||
43 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
44 | BinaryReader bs = new BinaryReader(s); | ||
45 | int x, y; | ||
46 | for (y = 0; y < retval.Height; y++) | ||
47 | { | ||
48 | for (x = 0; x < retval.Width; x++) | ||
49 | { | ||
50 | retval[x, y] = (double) bs.ReadByte() * ((double) bs.ReadByte() / 127.0); | ||
51 | bs.ReadBytes(11); // Advance the stream to next bytes. | ||
52 | } | ||
53 | } | ||
54 | |||
55 | bs.Close(); | ||
56 | s.Close(); | ||
57 | |||
58 | return retval; | ||
59 | } | ||
60 | |||
61 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
62 | { | ||
63 | throw new NotImplementedException(); | ||
64 | } | ||
65 | |||
66 | public void SaveFile(string filename, ITerrainChannel map) | ||
67 | { | ||
68 | FileInfo file = new FileInfo(filename); | ||
69 | FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); | ||
70 | BinaryWriter binStream = new BinaryWriter(s); | ||
71 | |||
72 | // Generate a smegging big lookup table to speed the operation up (it needs it) | ||
73 | double[] lookupHeightTable = new double[65536]; | ||
74 | int i, j, x, y; | ||
75 | for (i = 0; i < 256; i++) | ||
76 | { | ||
77 | for (j = 0; j < 256; j++) | ||
78 | { | ||
79 | lookupHeightTable[i + (j * 256)] = ((double) i * ((double) j / 127.0)); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | // Output the calculated raw | ||
84 | for (y = 0; y < map.Height; y++) | ||
85 | { | ||
86 | for (x = 0; x < map.Width; x++) | ||
87 | { | ||
88 | double t = map[x, y]; | ||
89 | double min = double.MaxValue; | ||
90 | int index = 0; | ||
91 | |||
92 | for (i = 0; i < 65536; i++) | ||
93 | { | ||
94 | if (Math.Abs(t - lookupHeightTable[i]) < min) | ||
95 | { | ||
96 | min = Math.Abs(t - lookupHeightTable[i]); | ||
97 | index = i; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | byte red = (byte) (index & 0xFF); | ||
102 | byte green = (byte) ((index >> 8) & 0xFF); | ||
103 | byte blue = 20; | ||
104 | byte alpha1 = 0; // Land Parcels | ||
105 | byte alpha2 = 0; // For Sale Land | ||
106 | byte alpha3 = 0; // Public Edit Object | ||
107 | byte alpha4 = 0; // Public Edit Land | ||
108 | byte alpha5 = 255; // Safe Land | ||
109 | byte alpha6 = 255; // Flying Allowed | ||
110 | byte alpha7 = 255; // Create Landmark | ||
111 | byte alpha8 = 255; // Outside Scripts | ||
112 | byte alpha9 = red; | ||
113 | byte alpha10 = green; | ||
114 | |||
115 | binStream.Write(red); | ||
116 | binStream.Write(green); | ||
117 | binStream.Write(blue); | ||
118 | binStream.Write(alpha1); | ||
119 | binStream.Write(alpha2); | ||
120 | binStream.Write(alpha3); | ||
121 | binStream.Write(alpha4); | ||
122 | binStream.Write(alpha5); | ||
123 | binStream.Write(alpha6); | ||
124 | binStream.Write(alpha7); | ||
125 | binStream.Write(alpha8); | ||
126 | binStream.Write(alpha9); | ||
127 | binStream.Write(alpha10); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | binStream.Close(); | ||
132 | s.Close(); | ||
133 | } | ||
134 | |||
135 | |||
136 | public string FileExtension | ||
137 | { | ||
138 | get { return ".raw"; } | ||
139 | } | ||
140 | |||
141 | #endregion | ||
142 | |||
143 | public override string ToString() | ||
144 | { | ||
145 | return "LL/SL RAW"; | ||
146 | } | ||
147 | } | ||
148 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs new file mode 100644 index 0000000..07072be --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs | |||
@@ -0,0 +1,48 @@ | |||
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.Drawing; | ||
28 | using System.Drawing.Imaging; | ||
29 | using OpenSim.Region.Environment.Interfaces; | ||
30 | using OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
33 | { | ||
34 | internal class PNG : GenericSystemDrawing | ||
35 | { | ||
36 | public override void SaveFile(string filename, ITerrainChannel map) | ||
37 | { | ||
38 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
39 | |||
40 | colours.Save(filename, ImageFormat.Png); | ||
41 | } | ||
42 | |||
43 | public override string ToString() | ||
44 | { | ||
45 | return "PNG"; | ||
46 | } | ||
47 | } | ||
48 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs new file mode 100644 index 0000000..71f56c5 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs | |||
@@ -0,0 +1,153 @@ | |||
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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
32 | { | ||
33 | public class RAW32 : ITerrainLoader | ||
34 | { | ||
35 | #region ITerrainLoader Members | ||
36 | |||
37 | public string FileExtension | ||
38 | { | ||
39 | get { return ".r32"; } | ||
40 | } | ||
41 | |||
42 | public ITerrainChannel LoadFile(string filename) | ||
43 | { | ||
44 | TerrainChannel retval = new TerrainChannel(); | ||
45 | |||
46 | FileInfo file = new FileInfo(filename); | ||
47 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
48 | BinaryReader bs = new BinaryReader(s); | ||
49 | int x, y; | ||
50 | for (y = 0; y < retval.Height; y++) | ||
51 | { | ||
52 | for (x = 0; x < retval.Width; x++) | ||
53 | { | ||
54 | retval[x, y] = bs.ReadSingle(); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | bs.Close(); | ||
59 | s.Close(); | ||
60 | |||
61 | return retval; | ||
62 | } | ||
63 | |||
64 | public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) | ||
65 | { | ||
66 | TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); | ||
67 | |||
68 | FileInfo file = new FileInfo(filename); | ||
69 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
70 | BinaryReader bs = new BinaryReader(s); | ||
71 | |||
72 | int currFileXOffset = 0; | ||
73 | int currFileYOffset = 0; | ||
74 | |||
75 | // if our region isn't on the first Y section of the areas to be landscaped, then | ||
76 | // advance to our section of the file | ||
77 | while (currFileYOffset < offsetY) | ||
78 | { | ||
79 | // read a whole strip of regions | ||
80 | int heightsToRead = sectionHeight * (fileWidth * sectionWidth); | ||
81 | bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file | ||
82 | currFileYOffset++; | ||
83 | } | ||
84 | |||
85 | // got to the Y start offset within the file of our region | ||
86 | // so read the file bits associated with our region | ||
87 | int x, y; | ||
88 | // for each Y within our Y offset | ||
89 | for (y = 0; y < sectionHeight; y++) | ||
90 | { | ||
91 | currFileXOffset = 0; | ||
92 | |||
93 | // if our region isn't the first X section of the areas to be landscaped, then | ||
94 | // advance the stream to the X start pos of our section in the file | ||
95 | // i.e. eat X upto where we start | ||
96 | while (currFileXOffset < offsetX) | ||
97 | { | ||
98 | bs.ReadBytes(sectionWidth * 4); // 4 bytes = single | ||
99 | currFileXOffset++; | ||
100 | } | ||
101 | |||
102 | // got to our X offset, so write our regions X line | ||
103 | for (x = 0; x < sectionWidth; x++) | ||
104 | { | ||
105 | // Read a strip and continue | ||
106 | retval[x, y] = bs.ReadSingle(); | ||
107 | } | ||
108 | // record that we wrote it | ||
109 | currFileXOffset++; | ||
110 | |||
111 | // if our region isn't the last X section of the areas to be landscaped, then | ||
112 | // advance the stream to the end of this Y column | ||
113 | while (currFileXOffset < fileWidth) | ||
114 | { | ||
115 | // eat the next regions x line | ||
116 | bs.ReadBytes(sectionWidth * 4); // 4 bytes = single | ||
117 | currFileXOffset++; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | bs.Close(); | ||
122 | s.Close(); | ||
123 | |||
124 | return retval; | ||
125 | } | ||
126 | |||
127 | public void SaveFile(string filename, ITerrainChannel map) | ||
128 | { | ||
129 | FileInfo file = new FileInfo(filename); | ||
130 | FileStream s = file.Open(FileMode.Create, FileAccess.Write); | ||
131 | BinaryWriter bs = new BinaryWriter(s); | ||
132 | |||
133 | int x, y; | ||
134 | for (y = 0; y < map.Height; y++) | ||
135 | { | ||
136 | for (x = 0; x < map.Width; x++) | ||
137 | { | ||
138 | bs.Write((float) map[x, y]); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | bs.Close(); | ||
143 | s.Close(); | ||
144 | } | ||
145 | |||
146 | #endregion | ||
147 | |||
148 | public override string ToString() | ||
149 | { | ||
150 | return "RAW32"; | ||
151 | } | ||
152 | } | ||
153 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs new file mode 100644 index 0000000..d206763 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs | |||
@@ -0,0 +1,48 @@ | |||
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.Drawing; | ||
28 | using System.Drawing.Imaging; | ||
29 | using OpenSim.Region.Environment.Interfaces; | ||
30 | using OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
33 | { | ||
34 | internal class TIFF : GenericSystemDrawing | ||
35 | { | ||
36 | public override void SaveFile(string filename, ITerrainChannel map) | ||
37 | { | ||
38 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
39 | |||
40 | colours.Save(filename, ImageFormat.Tiff); | ||
41 | } | ||
42 | |||
43 | public override string ToString() | ||
44 | { | ||
45 | return "TIFF"; | ||
46 | } | ||
47 | } | ||
48 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs new file mode 100644 index 0000000..f2672ad --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs | |||
@@ -0,0 +1,127 @@ | |||
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.Environment.Interfaces; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Terragen File Format Loader | ||
37 | /// Built from specification at | ||
38 | /// http://www.planetside.co.uk/terragen/dev/tgterrain.html | ||
39 | /// </summary> | ||
40 | internal class Terragen : ITerrainLoader | ||
41 | { | ||
42 | #region ITerrainLoader Members | ||
43 | |||
44 | public ITerrainChannel LoadFile(string filename) | ||
45 | { | ||
46 | TerrainChannel retval = new TerrainChannel(); | ||
47 | |||
48 | FileInfo file = new FileInfo(filename); | ||
49 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
50 | BinaryReader bs = new BinaryReader(s); | ||
51 | |||
52 | bool eof = false; | ||
53 | if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") | ||
54 | { | ||
55 | // Terragen file | ||
56 | while (eof == false) | ||
57 | { | ||
58 | int w = 256; | ||
59 | int h = 256; | ||
60 | string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4)); | ||
61 | switch (tmp) | ||
62 | { | ||
63 | case "SIZE": | ||
64 | int sztmp = bs.ReadInt16() + 1; | ||
65 | w = sztmp; | ||
66 | h = sztmp; | ||
67 | bs.ReadInt16(); | ||
68 | break; | ||
69 | case "XPTS": | ||
70 | w = bs.ReadInt16(); | ||
71 | bs.ReadInt16(); | ||
72 | break; | ||
73 | case "YPTS": | ||
74 | h = bs.ReadInt16(); | ||
75 | bs.ReadInt16(); | ||
76 | break; | ||
77 | case "ALTW": | ||
78 | eof = true; | ||
79 | Int16 heightScale = bs.ReadInt16(); | ||
80 | Int16 baseHeight = bs.ReadInt16(); | ||
81 | retval = new TerrainChannel(w, h); | ||
82 | int x, y; | ||
83 | for (x = 0; x < w; x++) | ||
84 | { | ||
85 | for (y = 0; y < h; y++) | ||
86 | { | ||
87 | retval[x, y] = (double) baseHeight + (double) bs.ReadInt16() * (double) heightScale / 65536.0; | ||
88 | } | ||
89 | } | ||
90 | break; | ||
91 | default: | ||
92 | bs.ReadInt32(); | ||
93 | break; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | bs.Close(); | ||
99 | s.Close(); | ||
100 | |||
101 | return retval; | ||
102 | } | ||
103 | |||
104 | public void SaveFile(string filename, ITerrainChannel map) | ||
105 | { | ||
106 | char[] header = "TERRAGENTERRAIN".ToCharArray(); | ||
107 | throw new NotImplementedException(); | ||
108 | } | ||
109 | |||
110 | public string FileExtension | ||
111 | { | ||
112 | get { return ".ter"; } | ||
113 | } | ||
114 | |||
115 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
116 | { | ||
117 | throw new NotImplementedException(); | ||
118 | } | ||
119 | |||
120 | #endregion | ||
121 | |||
122 | public override string ToString() | ||
123 | { | ||
124 | return "Terragen"; | ||
125 | } | ||
126 | } | ||
127 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs new file mode 100644 index 0000000..7bf81d3 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs | |||
@@ -0,0 +1,71 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.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 | double avg; | ||
41 | |||
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 | { | ||
49 | sum += map[x, y]; | ||
50 | steps += 1.0; | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | avg = sum / steps; | ||
56 | |||
57 | double str = 0.1 * strength; // == 0.2 in the default client | ||
58 | |||
59 | for (x = 0; x < map.Width; x++) | ||
60 | { | ||
61 | for (y = 0; y < map.Height; y++) | ||
62 | { | ||
63 | if (fillArea[x, y]) | ||
64 | map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | #endregion | ||
70 | } | ||
71 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/LowerArea.cs new file mode 100644 index 0000000..a7a4431 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.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/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs new file mode 100644 index 0000000..3da3826 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.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 | |||
28 | using OpenSim.Framework; | ||
29 | using OpenSim.Region.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes | ||
32 | { | ||
33 | public class NoiseArea : ITerrainFloodEffect | ||
34 | { | ||
35 | #region ITerrainFloodEffect Members | ||
36 | |||
37 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
38 | { | ||
39 | int x, y; | ||
40 | for (x = 0; x < map.Width; x++) | ||
41 | { | ||
42 | for (y = 0; y < map.Height; y++) | ||
43 | { | ||
44 | if (fillArea[x, y]) | ||
45 | { | ||
46 | double noise = TerrainUtil.PerlinNoise2D((double) x / Constants.RegionSize, (double) y / Constants.RegionSize, 8, 1.0); | ||
47 | |||
48 | map[x, y] += noise * strength; | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | #endregion | ||
55 | } | ||
56 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs new file mode 100644 index 0000000..b57caed --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs | |||
@@ -0,0 +1,53 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.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, y; | ||
39 | for (x = 0; x < map.Width; x++) | ||
40 | { | ||
41 | for (y = 0; y < map.Height; y++) | ||
42 | { | ||
43 | if (fillArea[x, y]) | ||
44 | { | ||
45 | map[x, y] += strength; | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
51 | #endregion | ||
52 | } | ||
53 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs new file mode 100644 index 0000000..76a2cae --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs | |||
@@ -0,0 +1,60 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.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 | public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) | ||
44 | { | ||
45 | int x, y; | ||
46 | for (x = 0; x < map.Width; x++) | ||
47 | { | ||
48 | for (y = 0; y < map.Height; y++) | ||
49 | { | ||
50 | if (fillArea[x, y]) | ||
51 | { | ||
52 | map[x, y] = (map[x, y] * (1.0 - strength)) + (m_revertmap[x, y] * strength); | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | #endregion | ||
59 | } | ||
60 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs new file mode 100644 index 0000000..bdd9f18 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.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 | 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/Environment/Modules/World/Terrain/ITerrainEffect.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainEffect.cs new file mode 100644 index 0000000..821fc4b --- /dev/null +++ b/OpenSim/Region/Environment/Modules/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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.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/Environment/Modules/World/Terrain/ITerrainFloodEffect.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainFloodEffect.cs new file mode 100644 index 0000000..6b0d7f9 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.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/Environment/Modules/World/Terrain/ITerrainLoader.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainLoader.cs new file mode 100644 index 0000000..6211892 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainLoader.cs | |||
@@ -0,0 +1,39 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
31 | { | ||
32 | public interface ITerrainLoader | ||
33 | { | ||
34 | string FileExtension { get; } | ||
35 | ITerrainChannel LoadFile(string filename); | ||
36 | ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight); | ||
37 | void SaveFile(string filename, ITerrainChannel map); | ||
38 | } | ||
39 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs new file mode 100644 index 0000000..756354a --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs | |||
@@ -0,0 +1,8 @@ | |||
1 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
2 | { | ||
3 | public interface ITerrainModule | ||
4 | { | ||
5 | void LoadFromFile(string filename); | ||
6 | void SaveToFile(string filename); | ||
7 | } | ||
8 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainPaintableEffect.cs new file mode 100644 index 0000000..d73f44d --- /dev/null +++ b/OpenSim/Region/Environment/Modules/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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
31 | { | ||
32 | public interface ITerrainPaintableEffect | ||
33 | { | ||
34 | void PaintEffect(ITerrainChannel map, double x, double y, double strength, double duration); | ||
35 | } | ||
36 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs new file mode 100644 index 0000000..dbaec0f --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs | |||
@@ -0,0 +1,168 @@ | |||
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 Nini.Config; | ||
31 | using OpenJPEGNet; | ||
32 | using OpenSim.Region.Environment.Interfaces; | ||
33 | using OpenSim.Region.Environment.Scenes; | ||
34 | |||
35 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
36 | { | ||
37 | internal class MapImageModule : IMapImageGenerator, IRegionModule | ||
38 | { | ||
39 | private Scene m_scene; | ||
40 | |||
41 | #region IMapImageGenerator Members | ||
42 | |||
43 | public byte[] WriteJpeg2000Image(string gradientmap) | ||
44 | { | ||
45 | byte[] imageData = null; | ||
46 | |||
47 | Bitmap bmp = TerrainToBitmap(gradientmap); | ||
48 | |||
49 | try | ||
50 | { | ||
51 | imageData = OpenJPEG.EncodeFromImage(bmp, true); | ||
52 | } | ||
53 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
54 | { | ||
55 | Console.WriteLine("Failed generating terrain map: " + e); | ||
56 | } | ||
57 | |||
58 | return imageData; | ||
59 | } | ||
60 | |||
61 | #endregion | ||
62 | |||
63 | #region IRegionModule Members | ||
64 | |||
65 | public void Initialise(Scene scene, IConfigSource source) | ||
66 | { | ||
67 | m_scene = scene; | ||
68 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); | ||
69 | } | ||
70 | |||
71 | public void PostInitialise() | ||
72 | { | ||
73 | } | ||
74 | |||
75 | public void Close() | ||
76 | { | ||
77 | } | ||
78 | |||
79 | public string Name | ||
80 | { | ||
81 | get { return "MapImageModule"; } | ||
82 | } | ||
83 | |||
84 | public bool IsSharedModule | ||
85 | { | ||
86 | get { return false; } | ||
87 | } | ||
88 | |||
89 | #endregion | ||
90 | |||
91 | private void ShadeBuildings(ref Bitmap map) | ||
92 | { | ||
93 | lock (map) | ||
94 | { | ||
95 | lock (m_scene.Entities) | ||
96 | { | ||
97 | foreach (EntityBase entity in m_scene.Entities.Values) | ||
98 | { | ||
99 | if (entity is SceneObjectGroup) | ||
100 | { | ||
101 | SceneObjectGroup sog = (SceneObjectGroup) entity; | ||
102 | |||
103 | foreach (SceneObjectPart primitive in sog.Children.Values) | ||
104 | { | ||
105 | int x, y, w, h; | ||
106 | x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); | ||
107 | y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); | ||
108 | w = (int) primitive.Scale.X; | ||
109 | h = (int) primitive.Scale.Y; | ||
110 | |||
111 | int dx; | ||
112 | for (dx = x; dx < x + w; dx++) | ||
113 | { | ||
114 | int dy; | ||
115 | for (dy = y; dy < y + h; dy++) | ||
116 | { | ||
117 | if (x < 0 || y < 0) | ||
118 | continue; | ||
119 | if (x >= map.Width || y >= map.Height) | ||
120 | continue; | ||
121 | |||
122 | map.SetPixel(dx, dy, Color.DarkGray); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | private Bitmap TerrainToBitmap(string gradientmap) | ||
133 | { | ||
134 | Bitmap gradientmapLd = new Bitmap(gradientmap); | ||
135 | |||
136 | int pallete = gradientmapLd.Height; | ||
137 | |||
138 | Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); | ||
139 | Color[] colours = new Color[pallete]; | ||
140 | |||
141 | for (int i = 0; i < pallete; i++) | ||
142 | { | ||
143 | colours[i] = gradientmapLd.GetPixel(0, i); | ||
144 | } | ||
145 | |||
146 | lock (m_scene.Heightmap) | ||
147 | { | ||
148 | ITerrainChannel copy = m_scene.Heightmap; | ||
149 | for (int y = 0; y < copy.Height; y++) | ||
150 | { | ||
151 | for (int x = 0; x < copy.Width; x++) | ||
152 | { | ||
153 | // 512 is the largest possible height before colours clamp | ||
154 | int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
155 | |||
156 | // Handle error conditions | ||
157 | if (colorindex > pallete - 1 || colorindex < 0) | ||
158 | bmp.SetPixel(x, copy.Height - y - 1, Color.Red); | ||
159 | else | ||
160 | bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); | ||
161 | } | ||
162 | } | ||
163 | ShadeBuildings(ref bmp); | ||
164 | return bmp; | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs new file mode 100644 index 0000000..29448aa --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs | |||
@@ -0,0 +1,312 @@ | |||
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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// Hydraulic Erosion Brush | ||
35 | /// </summary> | ||
36 | public class ErodeSphere : ITerrainPaintableEffect | ||
37 | { | ||
38 | private double rainHeight = 0.2; | ||
39 | private int rounds = 10; | ||
40 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter | ||
41 | private double waterSaturation = 0.30; // Can carry 1% of water in height | ||
42 | |||
43 | #region Supporting Functions | ||
44 | |||
45 | private int[] Neighbours(NeighbourSystem type, int index) | ||
46 | { | ||
47 | int[] coord = new int[2]; | ||
48 | |||
49 | index++; | ||
50 | |||
51 | switch (type) | ||
52 | { | ||
53 | case NeighbourSystem.Moore: | ||
54 | switch (index) | ||
55 | { | ||
56 | case 1: | ||
57 | coord[0] = -1; | ||
58 | coord[1] = -1; | ||
59 | break; | ||
60 | |||
61 | case 2: | ||
62 | coord[0] = -0; | ||
63 | coord[1] = -1; | ||
64 | break; | ||
65 | |||
66 | case 3: | ||
67 | coord[0] = +1; | ||
68 | coord[1] = -1; | ||
69 | break; | ||
70 | |||
71 | case 4: | ||
72 | coord[0] = -1; | ||
73 | coord[1] = -0; | ||
74 | break; | ||
75 | |||
76 | case 5: | ||
77 | coord[0] = -0; | ||
78 | coord[1] = -0; | ||
79 | break; | ||
80 | |||
81 | case 6: | ||
82 | coord[0] = +1; | ||
83 | coord[1] = -0; | ||
84 | break; | ||
85 | |||
86 | case 7: | ||
87 | coord[0] = -1; | ||
88 | coord[1] = +1; | ||
89 | break; | ||
90 | |||
91 | case 8: | ||
92 | coord[0] = -0; | ||
93 | coord[1] = +1; | ||
94 | break; | ||
95 | |||
96 | case 9: | ||
97 | coord[0] = +1; | ||
98 | coord[1] = +1; | ||
99 | break; | ||
100 | |||
101 | default: | ||
102 | break; | ||
103 | } | ||
104 | break; | ||
105 | |||
106 | case NeighbourSystem.VonNeumann: | ||
107 | switch (index) | ||
108 | { | ||
109 | case 1: | ||
110 | coord[0] = 0; | ||
111 | coord[1] = -1; | ||
112 | break; | ||
113 | |||
114 | case 2: | ||
115 | coord[0] = -1; | ||
116 | coord[1] = 0; | ||
117 | break; | ||
118 | |||
119 | case 3: | ||
120 | coord[0] = +1; | ||
121 | coord[1] = 0; | ||
122 | break; | ||
123 | |||
124 | case 4: | ||
125 | coord[0] = 0; | ||
126 | coord[1] = +1; | ||
127 | break; | ||
128 | |||
129 | case 5: | ||
130 | coord[0] = -0; | ||
131 | coord[1] = -0; | ||
132 | break; | ||
133 | |||
134 | default: | ||
135 | break; | ||
136 | } | ||
137 | break; | ||
138 | } | ||
139 | |||
140 | return coord; | ||
141 | } | ||
142 | |||
143 | private enum NeighbourSystem | ||
144 | { | ||
145 | Moore, | ||
146 | VonNeumann | ||
147 | } ; | ||
148 | |||
149 | #endregion | ||
150 | |||
151 | #region ITerrainPaintableEffect Members | ||
152 | |||
153 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
154 | { | ||
155 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
156 | |||
157 | int x, y; | ||
158 | // Using one 'rain' round for this, so skipping a useless loop | ||
159 | // Will need to adapt back in for the Flood brush | ||
160 | |||
161 | ITerrainChannel water = new TerrainChannel(map.Width, map.Height); | ||
162 | ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); | ||
163 | |||
164 | // Fill with rain | ||
165 | for (x = 0; x < water.Width; x++) | ||
166 | for (y = 0; y < water.Height; y++) | ||
167 | water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); | ||
168 | |||
169 | for (int i = 0; i < rounds; i++) | ||
170 | { | ||
171 | // Erode underlying terrain | ||
172 | for (x = 0; x < water.Width; x++) | ||
173 | { | ||
174 | for (y = 0; y < water.Height; y++) | ||
175 | { | ||
176 | double solConst = (1.0 / rounds); | ||
177 | double sedDelta = water[x, y] * solConst; | ||
178 | map[x, y] -= sedDelta; | ||
179 | sediment[x, y] += sedDelta; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | // Move water | ||
184 | for (x = 0; x < water.Width; x++) | ||
185 | { | ||
186 | for (y = 0; y < water.Height; y++) | ||
187 | { | ||
188 | if (water[x, y] <= 0) | ||
189 | continue; | ||
190 | |||
191 | // Step 1. Calculate average of neighbours | ||
192 | |||
193 | int neighbours = 0; | ||
194 | double altitudeTotal = 0.0; | ||
195 | double altitudeMe = map[x, y] + water[x, y]; | ||
196 | |||
197 | int NEIGHBOUR_ME = 4; | ||
198 | |||
199 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | ||
200 | |||
201 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
202 | { | ||
203 | if (j != NEIGHBOUR_ME) | ||
204 | { | ||
205 | int[] coords = Neighbours(type, j); | ||
206 | |||
207 | coords[0] += x; | ||
208 | coords[1] += y; | ||
209 | |||
210 | if (coords[0] > map.Width - 1) | ||
211 | continue; | ||
212 | if (coords[1] > map.Height - 1) | ||
213 | continue; | ||
214 | if (coords[0] < 0) | ||
215 | continue; | ||
216 | if (coords[1] < 0) | ||
217 | continue; | ||
218 | |||
219 | // Calculate total height of this neighbour | ||
220 | double altitudeNeighbour = water[coords[0], coords[1]] + map[coords[0], coords[1]]; | ||
221 | |||
222 | // If it's greater than me... | ||
223 | if (altitudeNeighbour - altitudeMe < 0) | ||
224 | { | ||
225 | // Add it to our calculations | ||
226 | neighbours++; | ||
227 | altitudeTotal += altitudeNeighbour; | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | |||
232 | if (neighbours == 0) | ||
233 | continue; | ||
234 | |||
235 | double altitudeAvg = altitudeTotal / neighbours; | ||
236 | |||
237 | // Step 2. Allocate water to neighbours. | ||
238 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
239 | { | ||
240 | if (j != NEIGHBOUR_ME) | ||
241 | { | ||
242 | int[] coords = Neighbours(type, j); | ||
243 | |||
244 | coords[0] += x; | ||
245 | coords[1] += y; | ||
246 | |||
247 | if (coords[0] > map.Width - 1) | ||
248 | continue; | ||
249 | if (coords[1] > map.Height - 1) | ||
250 | continue; | ||
251 | if (coords[0] < 0) | ||
252 | continue; | ||
253 | if (coords[1] < 0) | ||
254 | continue; | ||
255 | |||
256 | // Skip if we dont have water to begin with. | ||
257 | if (water[x, y] < 0) | ||
258 | continue; | ||
259 | |||
260 | // Calculate our delta average | ||
261 | double altitudeDelta = altitudeMe - altitudeAvg; | ||
262 | |||
263 | if (altitudeDelta < 0) | ||
264 | continue; | ||
265 | |||
266 | // Calculate how much water we can move | ||
267 | double waterMin = Math.Min(water[x, y], altitudeDelta); | ||
268 | double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]]) | ||
269 | / altitudeTotal); | ||
270 | |||
271 | double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]); | ||
272 | |||
273 | if (sedimentDelta > 0) | ||
274 | { | ||
275 | sediment[x, y] -= sedimentDelta; | ||
276 | sediment[coords[0], coords[1]] += sedimentDelta; | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | // Evaporate | ||
284 | |||
285 | for (x = 0; x < water.Width; x++) | ||
286 | { | ||
287 | for (y = 0; y < water.Height; y++) | ||
288 | { | ||
289 | water[x, y] *= 1.0 - (rainHeight / rounds); | ||
290 | |||
291 | double waterCapacity = waterSaturation * water[x, y]; | ||
292 | |||
293 | double sedimentDeposit = sediment[x, y] - waterCapacity; | ||
294 | if (sedimentDeposit > 0) | ||
295 | { | ||
296 | sediment[x, y] -= sedimentDeposit; | ||
297 | map[x, y] += sedimentDeposit; | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | } | ||
302 | |||
303 | // Deposit any remainder (should be minimal) | ||
304 | for (x = 0; x < water.Width; x++) | ||
305 | for (y = 0; y < water.Height; y++) | ||
306 | if (sediment[x, y] > 0) | ||
307 | map[x, y] += sediment[x, y]; | ||
308 | } | ||
309 | |||
310 | #endregion | ||
311 | } | ||
312 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs new file mode 100644 index 0000000..6a5a166 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs | |||
@@ -0,0 +1,127 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
31 | { | ||
32 | public class FlattenSphere : ITerrainPaintableEffect | ||
33 | { | ||
34 | // TODO: unused | ||
35 | // private double GetBilinearInterpolate(double x, double y, ITerrainChannel map) | ||
36 | // { | ||
37 | // int w = map.Width; | ||
38 | // int h = map.Height; | ||
39 | |||
40 | // if (x > w - 2.0) | ||
41 | // x = w - 2.0; | ||
42 | // if (y > h - 2.0) | ||
43 | // y = h - 2.0; | ||
44 | // if (x < 0.0) | ||
45 | // x = 0.0; | ||
46 | // if (y < 0.0) | ||
47 | // y = 0.0; | ||
48 | |||
49 | // int stepSize = 1; | ||
50 | // double h00 = map[(int)x, (int)y]; | ||
51 | // double h10 = map[(int)x + stepSize, (int)y]; | ||
52 | // double h01 = map[(int)x, (int)y + stepSize]; | ||
53 | // double h11 = map[(int)x + stepSize, (int)y + stepSize]; | ||
54 | // double h1 = h00; | ||
55 | // double h2 = h10; | ||
56 | // double h3 = h01; | ||
57 | // double h4 = h11; | ||
58 | // double a00 = h1; | ||
59 | // double a10 = h2 - h1; | ||
60 | // double a01 = h3 - h1; | ||
61 | // double a11 = h1 - h2 - h3 + h4; | ||
62 | // double partialx = x - (int)x; | ||
63 | // double partialz = y - (int)y; | ||
64 | // double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); | ||
65 | // return hi; | ||
66 | // } | ||
67 | |||
68 | #region ITerrainPaintableEffect Members | ||
69 | |||
70 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
71 | { | ||
72 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
73 | |||
74 | int x, y; | ||
75 | double[,] tweak = new double[map.Width,map.Height]; | ||
76 | |||
77 | double area = strength; | ||
78 | double step = strength / 4.0; | ||
79 | |||
80 | double sum = 0.0; | ||
81 | double step2 = 0.0; | ||
82 | double avg = 0.0; | ||
83 | |||
84 | // compute delta map | ||
85 | for (x = 0; x < map.Width; x++) | ||
86 | { | ||
87 | for (y = 0; y < map.Height; y++) | ||
88 | { | ||
89 | double z = SphericalFactor(x, y, rx, ry, strength); | ||
90 | |||
91 | if (z > 0) // add in non-zero amount | ||
92 | { | ||
93 | sum += map[x, y] * z; | ||
94 | step2 += z; | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | avg = sum / step2; | ||
100 | |||
101 | // blend in map | ||
102 | for (x = 0; x < map.Width; x++) | ||
103 | { | ||
104 | for (y = 0; y < map.Height; y++) | ||
105 | { | ||
106 | double z = SphericalFactor(x, y, rx, ry, strength) * duration; | ||
107 | |||
108 | if (z > 0) // add in non-zero amount | ||
109 | { | ||
110 | if (z > 1.0) | ||
111 | z = 1.0; | ||
112 | |||
113 | map[x, y] = (map[x, y] * (1.0 - z)) + (avg * z); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | |||
119 | #endregion | ||
120 | |||
121 | private double SphericalFactor(double x, double y, double rx, double ry, double size) | ||
122 | { | ||
123 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | ||
124 | return z; | ||
125 | } | ||
126 | } | ||
127 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs new file mode 100644 index 0000000..0b80407 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.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.Region.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | public class LowerSphere : ITerrainPaintableEffect | ||
34 | { | ||
35 | #region ITerrainPaintableEffect Members | ||
36 | |||
37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
38 | { | ||
39 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
40 | |||
41 | int x, y; | ||
42 | for (x = 0; x < map.Width; x++) | ||
43 | { | ||
44 | // Skip everything unlikely to be affected | ||
45 | if (Math.Abs(x - rx) > strength * 1.1) | ||
46 | continue; | ||
47 | |||
48 | for (y = 0; y < map.Height; y++) | ||
49 | { | ||
50 | // Skip everything unlikely to be affected | ||
51 | if (Math.Abs(y - ry) > strength * 1.1) | ||
52 | continue; | ||
53 | |||
54 | // Calculate a sphere and add it to the heighmap | ||
55 | double z = strength; | ||
56 | z *= z; | ||
57 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
58 | |||
59 | if (z > 0.0) | ||
60 | map[x, y] -= z * duration; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | #endregion | ||
66 | } | ||
67 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs new file mode 100644 index 0000000..a188e9f --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.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 System; | ||
29 | using OpenSim.Framework; | ||
30 | using OpenSim.Region.Environment.Interfaces; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
33 | { | ||
34 | public class NoiseSphere : ITerrainPaintableEffect | ||
35 | { | ||
36 | #region ITerrainPaintableEffect Members | ||
37 | |||
38 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
39 | { | ||
40 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
41 | |||
42 | int x, y; | ||
43 | for (x = 0; x < map.Width; x++) | ||
44 | { | ||
45 | // Skip everything unlikely to be affected | ||
46 | if (Math.Abs(x - rx) > strength * 1.1) | ||
47 | continue; | ||
48 | |||
49 | for (y = 0; y < map.Height; y++) | ||
50 | { | ||
51 | // Skip everything unlikely to be affected | ||
52 | if (Math.Abs(y - ry) > strength * 1.1) | ||
53 | continue; | ||
54 | |||
55 | // Calculate a sphere and add it to the heighmap | ||
56 | double z = strength; | ||
57 | z *= z; | ||
58 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
59 | |||
60 | double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0); | ||
61 | |||
62 | if (z > 0.0) | ||
63 | map[x, y] += noise * z * duration; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | #endregion | ||
69 | } | ||
70 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs new file mode 100644 index 0000000..dc56cf1 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs | |||
@@ -0,0 +1,225 @@ | |||
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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// Speed-Optimised Hybrid Erosion Brush | ||
35 | /// | ||
36 | /// As per Jacob Olsen's Paper | ||
37 | /// http://www.oddlabs.com/download/terrain_generation.pdf | ||
38 | /// </summary> | ||
39 | public class OlsenSphere : ITerrainPaintableEffect | ||
40 | { | ||
41 | private double nConst = 1024.0; | ||
42 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter | ||
43 | |||
44 | #region Supporting Functions | ||
45 | |||
46 | private int[] Neighbours(NeighbourSystem type, int index) | ||
47 | { | ||
48 | int[] coord = new int[2]; | ||
49 | |||
50 | index++; | ||
51 | |||
52 | switch (type) | ||
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 double SphericalFactor(double x, double y, double rx, double ry, double size) | ||
145 | { | ||
146 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | ||
147 | return z; | ||
148 | } | ||
149 | |||
150 | private enum NeighbourSystem | ||
151 | { | ||
152 | Moore, | ||
153 | VonNeumann | ||
154 | } ; | ||
155 | |||
156 | #endregion | ||
157 | |||
158 | #region ITerrainPaintableEffect Members | ||
159 | |||
160 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
161 | { | ||
162 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
163 | |||
164 | int x, y; | ||
165 | |||
166 | for (x = 0; x < map.Width; x++) | ||
167 | { | ||
168 | for (y = 0; y < map.Height; y++) | ||
169 | { | ||
170 | double z = SphericalFactor(x, y, rx, ry, strength); | ||
171 | |||
172 | if (z > 0) // add in non-zero amount | ||
173 | { | ||
174 | int NEIGHBOUR_ME = 4; | ||
175 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | ||
176 | |||
177 | double max = Double.MinValue; | ||
178 | int loc = 0; | ||
179 | double cellmax = 0; | ||
180 | |||
181 | |||
182 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
183 | { | ||
184 | if (j != NEIGHBOUR_ME) | ||
185 | { | ||
186 | int[] coords = Neighbours(type, j); | ||
187 | |||
188 | coords[0] += x; | ||
189 | coords[1] += y; | ||
190 | |||
191 | if (coords[0] > map.Width - 1) | ||
192 | continue; | ||
193 | if (coords[1] > map.Height - 1) | ||
194 | continue; | ||
195 | if (coords[0] < 0) | ||
196 | continue; | ||
197 | if (coords[1] < 0) | ||
198 | continue; | ||
199 | |||
200 | cellmax = map[x, y] - map[coords[0], coords[1]]; | ||
201 | if (cellmax > max) | ||
202 | { | ||
203 | max = cellmax; | ||
204 | loc = j; | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | double T = nConst / ((map.Width + map.Height) / 2); | ||
210 | // Apply results | ||
211 | if (0 < max && max <= T) | ||
212 | { | ||
213 | int[] maxCoords = Neighbours(type, loc); | ||
214 | double heightDelta = 0.5 * max * z * duration; | ||
215 | map[x, y] -= heightDelta; | ||
216 | map[x + maxCoords[0], y + maxCoords[1]] += heightDelta; | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | #endregion | ||
224 | } | ||
225 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs new file mode 100644 index 0000000..cd5a22b --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.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.Region.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | public class RaiseSphere : ITerrainPaintableEffect | ||
34 | { | ||
35 | #region ITerrainPaintableEffect Members | ||
36 | |||
37 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
38 | { | ||
39 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
40 | |||
41 | int x, y; | ||
42 | for (x = 0; x < map.Width; x++) | ||
43 | { | ||
44 | // Skip everything unlikely to be affected | ||
45 | if (Math.Abs(x - rx) > strength * 1.1) | ||
46 | continue; | ||
47 | |||
48 | for (y = 0; y < map.Height; y++) | ||
49 | { | ||
50 | // Skip everything unlikely to be affected | ||
51 | if (Math.Abs(y - ry) > strength * 1.1) | ||
52 | continue; | ||
53 | |||
54 | // Calculate a sphere and add it to the heighmap | ||
55 | double z = strength; | ||
56 | z *= z; | ||
57 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
58 | |||
59 | if (z > 0.0) | ||
60 | map[x, y] += z * duration; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | #endregion | ||
66 | } | ||
67 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs new file mode 100644 index 0000000..5b92cb5 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs | |||
@@ -0,0 +1,82 @@ | |||
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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
32 | { | ||
33 | public class RevertSphere : ITerrainPaintableEffect | ||
34 | { | ||
35 | private ITerrainChannel m_revertmap; | ||
36 | |||
37 | public RevertSphere(ITerrainChannel revertmap) | ||
38 | { | ||
39 | m_revertmap = revertmap; | ||
40 | } | ||
41 | |||
42 | #region ITerrainPaintableEffect Members | ||
43 | |||
44 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
45 | { | ||
46 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
47 | |||
48 | if (duration > 1.0) | ||
49 | duration = 1.0; | ||
50 | if (duration < 0) | ||
51 | return; | ||
52 | |||
53 | int x, y; | ||
54 | for (x = 0; x < map.Width; x++) | ||
55 | { | ||
56 | // Skip everything unlikely to be affected | ||
57 | if (Math.Abs(x - rx) > strength * 1.1) | ||
58 | continue; | ||
59 | |||
60 | for (y = 0; y < map.Height; y++) | ||
61 | { | ||
62 | // Skip everything unlikely to be affected | ||
63 | if (Math.Abs(y - ry) > strength * 1.1) | ||
64 | continue; | ||
65 | |||
66 | // Calculate a sphere and add it to the heighmap | ||
67 | double z = strength; | ||
68 | z *= z; | ||
69 | z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); | ||
70 | |||
71 | if (z > 0.0) | ||
72 | { | ||
73 | z *= duration; | ||
74 | map[x, y] += (map[x, y] * (1.0 - z)) + (m_revertmap[x, y] * z); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | #endregion | ||
81 | } | ||
82 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs new file mode 100644 index 0000000..305a875 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs | |||
@@ -0,0 +1,93 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
31 | { | ||
32 | public class SmoothSphere : ITerrainPaintableEffect | ||
33 | { | ||
34 | #region ITerrainPaintableEffect Members | ||
35 | |||
36 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
37 | { | ||
38 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
39 | |||
40 | int x, y; | ||
41 | double[,] tweak = new double[map.Width,map.Height]; | ||
42 | |||
43 | double n, l; | ||
44 | double area = strength; | ||
45 | double step = strength / 4.0; | ||
46 | |||
47 | // compute delta map | ||
48 | for (x = 0; x < map.Width; x++) | ||
49 | { | ||
50 | for (y = 0; y < map.Height; y++) | ||
51 | { | ||
52 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
53 | |||
54 | if (z > 0) // add in non-zero amount | ||
55 | { | ||
56 | double average = 0.0; | ||
57 | int avgsteps = 0; | ||
58 | |||
59 | for (n = 0.0 - area; n < area; n += step) | ||
60 | { | ||
61 | for (l = 0.0 - area; l < area; l += step) | ||
62 | { | ||
63 | avgsteps++; | ||
64 | average += TerrainUtil.GetBilinearInterpolate(x + n, y + l, map); | ||
65 | } | ||
66 | } | ||
67 | tweak[x, y] = average / avgsteps; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | // blend in map | ||
72 | for (x = 0; x < map.Width; x++) | ||
73 | { | ||
74 | for (y = 0; y < map.Height; y++) | ||
75 | { | ||
76 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
77 | |||
78 | if (z > 0) // add in non-zero amount | ||
79 | { | ||
80 | double da = z; | ||
81 | double a = (map[x, y] - tweak[x, y]) * da; | ||
82 | double newz = map[x, y] - (a * duration); | ||
83 | |||
84 | if (newz > 0.0) | ||
85 | map[x, y] = newz; | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | } | ||
93 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs new file mode 100644 index 0000000..2d81054 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs | |||
@@ -0,0 +1,207 @@ | |||
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.Environment.Interfaces; | ||
29 | |||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Thermal Weathering Paint Brush | ||
34 | /// </summary> | ||
35 | public class WeatherSphere : ITerrainPaintableEffect | ||
36 | { | ||
37 | private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required. | ||
38 | private NeighbourSystem type = NeighbourSystem.Moore; // Parameter | ||
39 | |||
40 | #region Supporting Functions | ||
41 | |||
42 | private int[] Neighbours(NeighbourSystem type, int index) | ||
43 | { | ||
44 | int[] coord = new int[2]; | ||
45 | |||
46 | index++; | ||
47 | |||
48 | switch (type) | ||
49 | { | ||
50 | case NeighbourSystem.Moore: | ||
51 | switch (index) | ||
52 | { | ||
53 | case 1: | ||
54 | coord[0] = -1; | ||
55 | coord[1] = -1; | ||
56 | break; | ||
57 | |||
58 | case 2: | ||
59 | coord[0] = -0; | ||
60 | coord[1] = -1; | ||
61 | break; | ||
62 | |||
63 | case 3: | ||
64 | coord[0] = +1; | ||
65 | coord[1] = -1; | ||
66 | break; | ||
67 | |||
68 | case 4: | ||
69 | coord[0] = -1; | ||
70 | coord[1] = -0; | ||
71 | break; | ||
72 | |||
73 | case 5: | ||
74 | coord[0] = -0; | ||
75 | coord[1] = -0; | ||
76 | break; | ||
77 | |||
78 | case 6: | ||
79 | coord[0] = +1; | ||
80 | coord[1] = -0; | ||
81 | break; | ||
82 | |||
83 | case 7: | ||
84 | coord[0] = -1; | ||
85 | coord[1] = +1; | ||
86 | break; | ||
87 | |||
88 | case 8: | ||
89 | coord[0] = -0; | ||
90 | coord[1] = +1; | ||
91 | break; | ||
92 | |||
93 | case 9: | ||
94 | coord[0] = +1; | ||
95 | coord[1] = +1; | ||
96 | break; | ||
97 | |||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | break; | ||
102 | |||
103 | case NeighbourSystem.VonNeumann: | ||
104 | switch (index) | ||
105 | { | ||
106 | case 1: | ||
107 | coord[0] = 0; | ||
108 | coord[1] = -1; | ||
109 | break; | ||
110 | |||
111 | case 2: | ||
112 | coord[0] = -1; | ||
113 | coord[1] = 0; | ||
114 | break; | ||
115 | |||
116 | case 3: | ||
117 | coord[0] = +1; | ||
118 | coord[1] = 0; | ||
119 | break; | ||
120 | |||
121 | case 4: | ||
122 | coord[0] = 0; | ||
123 | coord[1] = +1; | ||
124 | break; | ||
125 | |||
126 | case 5: | ||
127 | coord[0] = -0; | ||
128 | coord[1] = -0; | ||
129 | break; | ||
130 | |||
131 | default: | ||
132 | break; | ||
133 | } | ||
134 | break; | ||
135 | } | ||
136 | |||
137 | return coord; | ||
138 | } | ||
139 | |||
140 | private enum NeighbourSystem | ||
141 | { | ||
142 | Moore, | ||
143 | VonNeumann | ||
144 | } ; | ||
145 | |||
146 | #endregion | ||
147 | |||
148 | #region ITerrainPaintableEffect Members | ||
149 | |||
150 | public void PaintEffect(ITerrainChannel map, double rx, double ry, double strength, double duration) | ||
151 | { | ||
152 | strength = TerrainUtil.MetersToSphericalStrength(strength); | ||
153 | |||
154 | int x, y; | ||
155 | |||
156 | for (x = 0; x < map.Width; x++) | ||
157 | { | ||
158 | for (y = 0; y < map.Height; y++) | ||
159 | { | ||
160 | double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); | ||
161 | |||
162 | if (z > 0) // add in non-zero amount | ||
163 | { | ||
164 | int NEIGHBOUR_ME = 4; | ||
165 | |||
166 | int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; | ||
167 | |||
168 | for (int j = 0; j < NEIGHBOUR_MAX; j++) | ||
169 | { | ||
170 | if (j != NEIGHBOUR_ME) | ||
171 | { | ||
172 | int[] coords = Neighbours(type, j); | ||
173 | |||
174 | coords[0] += x; | ||
175 | coords[1] += y; | ||
176 | |||
177 | if (coords[0] > map.Width - 1) | ||
178 | continue; | ||
179 | if (coords[1] > map.Height - 1) | ||
180 | continue; | ||
181 | if (coords[0] < 0) | ||
182 | continue; | ||
183 | if (coords[1] < 0) | ||
184 | continue; | ||
185 | |||
186 | double heightF = map[x, y]; | ||
187 | double target = map[coords[0], coords[1]]; | ||
188 | |||
189 | if (target > heightF + talus) | ||
190 | { | ||
191 | double calc = duration * ((target - heightF) - talus) * z; | ||
192 | heightF += calc; | ||
193 | target -= calc; | ||
194 | } | ||
195 | |||
196 | map[x, y] = heightF; | ||
197 | map[coords[0], coords[1]] = target; | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | |||
205 | #endregion | ||
206 | } | ||
207 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs new file mode 100644 index 0000000..e2df885 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs | |||
@@ -0,0 +1,157 @@ | |||
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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// A new version of the old Channel class, simplified | ||
35 | /// </summary> | ||
36 | public class TerrainChannel : ITerrainChannel | ||
37 | { | ||
38 | private readonly bool[,] taint; | ||
39 | private double[,] map; | ||
40 | |||
41 | public TerrainChannel() | ||
42 | { | ||
43 | map = new double[Constants.RegionSize,Constants.RegionSize]; | ||
44 | taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; | ||
45 | |||
46 | int x; | ||
47 | for (x = 0; x < Constants.RegionSize; x++) | ||
48 | { | ||
49 | int y; | ||
50 | for (y = 0; y < Constants.RegionSize; y++) | ||
51 | { | ||
52 | map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; | ||
53 | double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01; | ||
54 | if (map[x, y] < spherFac) | ||
55 | { | ||
56 | map[x, y] = spherFac; | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | public TerrainChannel(double[,] import) | ||
63 | { | ||
64 | map = import; | ||
65 | taint = new bool[import.GetLength(0),import.GetLength(1)]; | ||
66 | } | ||
67 | |||
68 | public TerrainChannel(bool createMap) | ||
69 | { | ||
70 | if (createMap) | ||
71 | { | ||
72 | map = new double[Constants.RegionSize,Constants.RegionSize]; | ||
73 | taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16]; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public TerrainChannel(int w, int h) | ||
78 | { | ||
79 | map = new double[w,h]; | ||
80 | taint = new bool[w / 16,h / 16]; | ||
81 | } | ||
82 | |||
83 | #region ITerrainChannel Members | ||
84 | |||
85 | public int Width | ||
86 | { | ||
87 | get { return map.GetLength(0); } | ||
88 | } | ||
89 | |||
90 | public int Height | ||
91 | { | ||
92 | get { return map.GetLength(1); } | ||
93 | } | ||
94 | |||
95 | public ITerrainChannel MakeCopy() | ||
96 | { | ||
97 | TerrainChannel copy = new TerrainChannel(false); | ||
98 | copy.map = (double[,]) map.Clone(); | ||
99 | |||
100 | return copy; | ||
101 | } | ||
102 | |||
103 | public float[] GetFloatsSerialised() | ||
104 | { | ||
105 | float[] heights = new float[Width * Height]; | ||
106 | int i; | ||
107 | |||
108 | for (i = 0; i < Width * Height; i++) | ||
109 | { | ||
110 | heights[i] = (float) map[i % Width, i / Width]; | ||
111 | } | ||
112 | |||
113 | return heights; | ||
114 | } | ||
115 | |||
116 | public double[,] GetDoubles() | ||
117 | { | ||
118 | return map; | ||
119 | } | ||
120 | |||
121 | public double this[int x, int y] | ||
122 | { | ||
123 | get { return map[x, y]; } | ||
124 | set | ||
125 | { | ||
126 | if (map[x, y] != value) | ||
127 | { | ||
128 | taint[x / 16, y / 16] = true; | ||
129 | map[x, y] = value; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | public bool Tainted(int x, int y) | ||
135 | { | ||
136 | if (taint[x / 16, y / 16]) | ||
137 | { | ||
138 | taint[x / 16, y / 16] = false; | ||
139 | return true; | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | return false; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | #endregion | ||
148 | |||
149 | public TerrainChannel Copy() | ||
150 | { | ||
151 | TerrainChannel copy = new TerrainChannel(false); | ||
152 | copy.map = (double[,]) map.Clone(); | ||
153 | |||
154 | return copy; | ||
155 | } | ||
156 | } | ||
157 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs new file mode 100644 index 0000000..1095cb9 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/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.Environment.Modules.World.Terrain | ||
31 | { | ||
32 | public class TerrainException : Exception | ||
33 | { | ||
34 | public TerrainException() : base() | ||
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/Environment/Modules/World/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs new file mode 100644 index 0000000..cf85aa4 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs | |||
@@ -0,0 +1,737 @@ | |||
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 libsecondlife; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Environment.Interfaces; | ||
37 | using OpenSim.Region.Environment.Modules.Framework; | ||
38 | using OpenSim.Region.Environment.Modules.World.Terrain; | ||
39 | using OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders; | ||
40 | using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes; | ||
41 | using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes; | ||
42 | using OpenSim.Region.Environment.Scenes; | ||
43 | |||
44 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
45 | { | ||
46 | public class TerrainModule : IRegionModule, ICommandableModule, ITerrainModule | ||
47 | { | ||
48 | #region StandardTerrainEffects enum | ||
49 | |||
50 | /// <summary> | ||
51 | /// A standard set of terrain brushes and effects recognised by viewers | ||
52 | /// </summary> | ||
53 | public enum StandardTerrainEffects : byte | ||
54 | { | ||
55 | Flatten = 0, | ||
56 | Raise = 1, | ||
57 | Lower = 2, | ||
58 | Smooth = 3, | ||
59 | Noise = 4, | ||
60 | Revert = 5, | ||
61 | |||
62 | // Extended brushes | ||
63 | Erode = 255, | ||
64 | Weather = 254, | ||
65 | Olsen = 253 | ||
66 | } | ||
67 | |||
68 | #endregion | ||
69 | |||
70 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
71 | |||
72 | private readonly Commander m_commander = new Commander("Terrain"); | ||
73 | |||
74 | private readonly Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects = | ||
75 | new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>(); | ||
76 | |||
77 | private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>(); | ||
78 | |||
79 | private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = | ||
80 | new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); | ||
81 | |||
82 | private Dictionary<Location, ITerrainChannel> m_channels; | ||
83 | |||
84 | private ITerrainChannel m_channel; | ||
85 | private Dictionary<string, ITerrainEffect> m_plugineffects; | ||
86 | private ITerrainChannel m_revert; | ||
87 | private Scene m_scene; | ||
88 | private bool m_tainted = false; | ||
89 | |||
90 | #region ICommandableModule Members | ||
91 | |||
92 | public ICommander CommandInterface | ||
93 | { | ||
94 | get { return m_commander; } | ||
95 | } | ||
96 | |||
97 | #endregion | ||
98 | |||
99 | #region IRegionModule Members | ||
100 | |||
101 | /// <summary> | ||
102 | /// Creates and initialises a terrain module for a region | ||
103 | /// </summary> | ||
104 | /// <param name="scene">Region initialising</param> | ||
105 | /// <param name="config">Config for the region</param> | ||
106 | public void Initialise(Scene scene, IConfigSource config) | ||
107 | { | ||
108 | m_scene = scene; | ||
109 | |||
110 | // Install terrain module in the simulator | ||
111 | if (m_scene.Heightmap == null) | ||
112 | { | ||
113 | lock (m_scene) | ||
114 | { | ||
115 | m_channel = new TerrainChannel(); | ||
116 | m_scene.Heightmap = m_channel; | ||
117 | m_revert = new TerrainChannel(); | ||
118 | UpdateRevertMap(); | ||
119 | } | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | m_channel = m_scene.Heightmap; | ||
124 | m_revert = new TerrainChannel(); | ||
125 | UpdateRevertMap(); | ||
126 | } | ||
127 | |||
128 | m_scene.RegisterModuleInterface<ITerrainModule>(this); | ||
129 | m_scene.EventManager.OnNewClient += EventManager_OnNewClient; | ||
130 | m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | ||
131 | m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// Enables terrain module when called | ||
136 | /// </summary> | ||
137 | public void PostInitialise() | ||
138 | { | ||
139 | InstallDefaultEffects(); | ||
140 | InstallInterfaces(); | ||
141 | LoadPlugins(); | ||
142 | } | ||
143 | |||
144 | public void Close() | ||
145 | { | ||
146 | } | ||
147 | |||
148 | public string Name | ||
149 | { | ||
150 | get { return "TerrainModule"; } | ||
151 | } | ||
152 | |||
153 | public bool IsSharedModule | ||
154 | { | ||
155 | get { return false; } | ||
156 | } | ||
157 | |||
158 | #endregion | ||
159 | |||
160 | #region ITerrainModule Members | ||
161 | |||
162 | /// <summary> | ||
163 | /// Loads a terrain file from disk and installs it in the scene. | ||
164 | /// </summary> | ||
165 | /// <param name="filename">Filename to terrain file. Type is determined by extension.</param> | ||
166 | public void LoadFromFile(string filename) | ||
167 | { | ||
168 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
169 | { | ||
170 | if (filename.EndsWith(loader.Key)) | ||
171 | { | ||
172 | lock (m_scene) | ||
173 | { | ||
174 | try | ||
175 | { | ||
176 | ITerrainChannel channel = loader.Value.LoadFile(filename); | ||
177 | m_scene.Heightmap = channel; | ||
178 | m_channel = channel; | ||
179 | UpdateRevertMap(); | ||
180 | } | ||
181 | catch (NotImplementedException) | ||
182 | { | ||
183 | m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value + | ||
184 | " parser does not support file loading. (May be save only)"); | ||
185 | throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value)); | ||
186 | } | ||
187 | catch (FileNotFoundException) | ||
188 | { | ||
189 | m_log.Error( | ||
190 | "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)"); | ||
191 | throw new TerrainException( | ||
192 | String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", filename)); | ||
193 | } | ||
194 | } | ||
195 | CheckForTerrainUpdates(); | ||
196 | m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully"); | ||
197 | return; | ||
198 | } | ||
199 | } | ||
200 | m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format."); | ||
201 | throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// Saves the current heightmap to a specified file. | ||
206 | /// </summary> | ||
207 | /// <param name="filename">The destination filename</param> | ||
208 | public void SaveToFile(string filename) | ||
209 | { | ||
210 | try | ||
211 | { | ||
212 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
213 | { | ||
214 | if (filename.EndsWith(loader.Key)) | ||
215 | { | ||
216 | loader.Value.SaveFile(filename, m_channel); | ||
217 | return; | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | catch (NotImplementedException) | ||
222 | { | ||
223 | m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented."); | ||
224 | throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented")); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | #region Plugin Loading Methods | ||
229 | |||
230 | private void LoadPlugins() | ||
231 | { | ||
232 | m_plugineffects = new Dictionary<string, ITerrainEffect>(); | ||
233 | // Load the files in the Terrain/ dir | ||
234 | string[] files = Directory.GetFiles("Terrain"); | ||
235 | foreach (string file in files) | ||
236 | { | ||
237 | m_log.Info("Loading effects in " + file); | ||
238 | try | ||
239 | { | ||
240 | Assembly library = Assembly.LoadFrom(file); | ||
241 | foreach (Type pluginType in library.GetTypes()) | ||
242 | { | ||
243 | try | ||
244 | { | ||
245 | if (pluginType.IsAbstract || pluginType.IsNotPublic) | ||
246 | continue; | ||
247 | |||
248 | if (pluginType.GetInterface("ITerrainEffect", false) != null) | ||
249 | { | ||
250 | ITerrainEffect terEffect = (ITerrainEffect) Activator.CreateInstance(library.GetType(pluginType.ToString())); | ||
251 | if (!m_plugineffects.ContainsKey(pluginType.Name)) | ||
252 | { | ||
253 | m_plugineffects.Add(pluginType.Name, terEffect); | ||
254 | m_log.Info("E ... " + pluginType.Name); | ||
255 | } else | ||
256 | { | ||
257 | m_log.Warn("E ... " + pluginType.Name + " (Already added)"); | ||
258 | } | ||
259 | } | ||
260 | else if (pluginType.GetInterface("ITerrainLoader", false) != null) | ||
261 | { | ||
262 | ITerrainLoader terLoader = (ITerrainLoader) Activator.CreateInstance(library.GetType(pluginType.ToString())); | ||
263 | m_loaders[terLoader.FileExtension] = terLoader; | ||
264 | m_log.Info("L ... " + pluginType.Name); | ||
265 | } | ||
266 | } | ||
267 | catch (AmbiguousMatchException) | ||
268 | { | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | catch (BadImageFormatException) | ||
273 | { | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | #endregion | ||
279 | |||
280 | #endregion | ||
281 | |||
282 | /// <summary> | ||
283 | /// Installs into terrain module the standard suite of brushes | ||
284 | /// </summary> | ||
285 | private void InstallDefaultEffects() | ||
286 | { | ||
287 | // Draggable Paint Brush Effects | ||
288 | m_painteffects[StandardTerrainEffects.Raise] = new RaiseSphere(); | ||
289 | m_painteffects[StandardTerrainEffects.Lower] = new LowerSphere(); | ||
290 | m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere(); | ||
291 | m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere(); | ||
292 | m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere(); | ||
293 | m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert); | ||
294 | m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere(); | ||
295 | m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere(); | ||
296 | m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere(); | ||
297 | |||
298 | // Area of effect selection effects | ||
299 | m_floodeffects[StandardTerrainEffects.Raise] = new RaiseArea(); | ||
300 | m_floodeffects[StandardTerrainEffects.Lower] = new LowerArea(); | ||
301 | m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea(); | ||
302 | m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea(); | ||
303 | m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); | ||
304 | m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); | ||
305 | |||
306 | // Filesystem load/save loaders | ||
307 | m_loaders[".r32"] = new RAW32(); | ||
308 | m_loaders[".f32"] = m_loaders[".r32"]; | ||
309 | m_loaders[".ter"] = new Terragen(); | ||
310 | m_loaders[".raw"] = new LLRAW(); | ||
311 | m_loaders[".jpg"] = new JPEG(); | ||
312 | m_loaders[".jpeg"] = m_loaders[".jpg"]; | ||
313 | m_loaders[".bmp"] = new BMP(); | ||
314 | m_loaders[".png"] = new PNG(); | ||
315 | m_loaders[".gif"] = new GIF(); | ||
316 | m_loaders[".tif"] = new TIFF(); | ||
317 | m_loaders[".tiff"] = m_loaders[".tif"]; | ||
318 | } | ||
319 | |||
320 | /// <summary> | ||
321 | /// Saves the current state of the region into the revert map buffer. | ||
322 | /// </summary> | ||
323 | public void UpdateRevertMap() | ||
324 | { | ||
325 | int x; | ||
326 | for (x = 0; x < m_channel.Width; x++) | ||
327 | { | ||
328 | int y; | ||
329 | for (y = 0; y < m_channel.Height; y++) | ||
330 | { | ||
331 | m_revert[x, y] = m_channel[x, y]; | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | |||
336 | /// <summary> | ||
337 | /// Loads a tile from a larger terrain file and installs it into the region. | ||
338 | /// </summary> | ||
339 | /// <param name="filename">The terrain file to load</param> | ||
340 | /// <param name="fileWidth">The width of the file in units</param> | ||
341 | /// <param name="fileHeight">The height of the file in units</param> | ||
342 | /// <param name="fileStartX">Where to begin our slice</param> | ||
343 | /// <param name="fileStartY">Where to begin our slice</param> | ||
344 | public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) | ||
345 | { | ||
346 | int offsetX = (int) m_scene.RegionInfo.RegionLocX - fileStartX; | ||
347 | int offsetY = (int) m_scene.RegionInfo.RegionLocY - fileStartY; | ||
348 | |||
349 | if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight) | ||
350 | { | ||
351 | // this region is included in the tile request | ||
352 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
353 | { | ||
354 | if (filename.EndsWith(loader.Key)) | ||
355 | { | ||
356 | lock (m_scene) | ||
357 | { | ||
358 | ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY, | ||
359 | fileWidth, fileHeight, | ||
360 | (int) Constants.RegionSize, | ||
361 | (int) Constants.RegionSize); | ||
362 | m_scene.Heightmap = channel; | ||
363 | m_channel = channel; | ||
364 | UpdateRevertMap(); | ||
365 | } | ||
366 | return; | ||
367 | } | ||
368 | } | ||
369 | } | ||
370 | } | ||
371 | |||
372 | /// <summary> | ||
373 | /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections | ||
374 | /// </summary> | ||
375 | private void EventManager_OnTerrainTick() | ||
376 | { | ||
377 | if (m_tainted) | ||
378 | { | ||
379 | m_tainted = false; | ||
380 | m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised()); | ||
381 | m_scene.SaveTerrain(); | ||
382 | m_scene.CreateTerrainTexture(true); | ||
383 | } | ||
384 | } | ||
385 | |||
386 | /// <summary> | ||
387 | /// Processes commandline input. Do not call directly. | ||
388 | /// </summary> | ||
389 | /// <param name="args">Commandline arguments</param> | ||
390 | private void EventManager_OnPluginConsole(string[] args) | ||
391 | { | ||
392 | if (args[0] == "terrain") | ||
393 | { | ||
394 | string[] tmpArgs = new string[args.Length - 2]; | ||
395 | int i; | ||
396 | for (i = 2; i < args.Length; i++) | ||
397 | tmpArgs[i - 2] = args[i]; | ||
398 | |||
399 | m_commander.ProcessConsoleCommand(args[1], tmpArgs); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | /// <summary> | ||
404 | /// Installs terrain brush hook to IClientAPI | ||
405 | /// </summary> | ||
406 | /// <param name="client"></param> | ||
407 | private void EventManager_OnNewClient(IClientAPI client) | ||
408 | { | ||
409 | client.OnModifyTerrain += client_OnModifyTerrain; | ||
410 | } | ||
411 | |||
412 | /// <summary> | ||
413 | /// Checks to see if the terrain has been modified since last check | ||
414 | /// </summary> | ||
415 | private void CheckForTerrainUpdates() | ||
416 | { | ||
417 | bool shouldTaint = false; | ||
418 | float[] serialised = m_channel.GetFloatsSerialised(); | ||
419 | int x; | ||
420 | for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize) | ||
421 | { | ||
422 | int y; | ||
423 | for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize) | ||
424 | { | ||
425 | if (m_channel.Tainted(x, y)) | ||
426 | { | ||
427 | SendToClients(serialised, x, y); | ||
428 | shouldTaint = true; | ||
429 | } | ||
430 | } | ||
431 | } | ||
432 | if (shouldTaint) | ||
433 | { | ||
434 | m_tainted = true; | ||
435 | } | ||
436 | } | ||
437 | |||
438 | /// <summary> | ||
439 | /// Sends a copy of the current terrain to the scenes clients | ||
440 | /// </summary> | ||
441 | /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param> | ||
442 | /// <param name="x">The patch corner to send</param> | ||
443 | /// <param name="y">The patch corner to send</param> | ||
444 | private void SendToClients(float[] serialised, int x, int y) | ||
445 | { | ||
446 | m_scene.ForEachClient( | ||
447 | delegate(IClientAPI controller) { controller.SendLayerData(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised); }); | ||
448 | } | ||
449 | |||
450 | private void client_OnModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, | ||
451 | float south, float east, IClientAPI remoteClient) | ||
452 | { | ||
453 | // Not a good permissions check, if in area mode, need to check the entire area. | ||
454 | if (m_scene.PermissionsMngr.CanTerraform(remoteClient.AgentId, new LLVector3(north, west, 0))) | ||
455 | { | ||
456 | if (north == south && east == west) | ||
457 | { | ||
458 | if (m_painteffects.ContainsKey((StandardTerrainEffects) action)) | ||
459 | { | ||
460 | m_painteffects[(StandardTerrainEffects) action].PaintEffect( | ||
461 | m_channel, west, south, size, seconds); | ||
462 | |||
463 | CheckForTerrainUpdates(); | ||
464 | } | ||
465 | else | ||
466 | { | ||
467 | m_log.Debug("Unknown terrain brush type " + action); | ||
468 | } | ||
469 | } | ||
470 | else | ||
471 | { | ||
472 | if (m_floodeffects.ContainsKey((StandardTerrainEffects) action)) | ||
473 | { | ||
474 | bool[,] fillArea = new bool[m_channel.Width,m_channel.Height]; | ||
475 | fillArea.Initialize(); | ||
476 | |||
477 | int x; | ||
478 | for (x = 0; x < m_channel.Width; x++) | ||
479 | { | ||
480 | int y; | ||
481 | for (y = 0; y < m_channel.Height; y++) | ||
482 | { | ||
483 | if (x < east && x > west) | ||
484 | { | ||
485 | if (y < north && y > south) | ||
486 | { | ||
487 | fillArea[x, y] = true; | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | } | ||
492 | |||
493 | m_floodeffects[(StandardTerrainEffects) action].FloodEffect( | ||
494 | m_channel, fillArea, size); | ||
495 | |||
496 | CheckForTerrainUpdates(); | ||
497 | } | ||
498 | else | ||
499 | { | ||
500 | m_log.Debug("Unknown terrain flood type " + action); | ||
501 | } | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | |||
506 | #region Console Commands | ||
507 | |||
508 | private void InterfaceLoadFile(Object[] args) | ||
509 | { | ||
510 | LoadFromFile((string) args[0]); | ||
511 | CheckForTerrainUpdates(); | ||
512 | } | ||
513 | |||
514 | private void InterfaceLoadTileFile(Object[] args) | ||
515 | { | ||
516 | LoadFromFile((string) args[0], | ||
517 | (int) args[1], | ||
518 | (int) args[2], | ||
519 | (int) args[3], | ||
520 | (int) args[4]); | ||
521 | CheckForTerrainUpdates(); | ||
522 | } | ||
523 | |||
524 | private void InterfaceSaveFile(Object[] args) | ||
525 | { | ||
526 | SaveToFile((string) args[0]); | ||
527 | } | ||
528 | |||
529 | private void InterfaceBakeTerrain(Object[] args) | ||
530 | { | ||
531 | UpdateRevertMap(); | ||
532 | } | ||
533 | |||
534 | private void InterfaceRevertTerrain(Object[] args) | ||
535 | { | ||
536 | int x, y; | ||
537 | for (x = 0; x < m_channel.Width; x++) | ||
538 | for (y = 0; y < m_channel.Height; y++) | ||
539 | m_channel[x, y] = m_revert[x, y]; | ||
540 | |||
541 | CheckForTerrainUpdates(); | ||
542 | } | ||
543 | |||
544 | private void InterfaceElevateTerrain(Object[] args) | ||
545 | { | ||
546 | int x, y; | ||
547 | for (x = 0; x < m_channel.Width; x++) | ||
548 | for (y = 0; y < m_channel.Height; y++) | ||
549 | m_channel[x, y] += (double) args[0]; | ||
550 | CheckForTerrainUpdates(); | ||
551 | } | ||
552 | |||
553 | private void InterfaceMultiplyTerrain(Object[] args) | ||
554 | { | ||
555 | int x, y; | ||
556 | for (x = 0; x < m_channel.Width; x++) | ||
557 | for (y = 0; y < m_channel.Height; y++) | ||
558 | m_channel[x, y] *= (double) args[0]; | ||
559 | CheckForTerrainUpdates(); | ||
560 | } | ||
561 | |||
562 | private void InterfaceLowerTerrain(Object[] args) | ||
563 | { | ||
564 | int x, y; | ||
565 | for (x = 0; x < m_channel.Width; x++) | ||
566 | for (y = 0; y < m_channel.Height; y++) | ||
567 | m_channel[x, y] -= (double) args[0]; | ||
568 | CheckForTerrainUpdates(); | ||
569 | } | ||
570 | |||
571 | private void InterfaceFillTerrain(Object[] args) | ||
572 | { | ||
573 | int x, y; | ||
574 | |||
575 | for (x = 0; x < m_channel.Width; x++) | ||
576 | for (y = 0; y < m_channel.Height; y++) | ||
577 | m_channel[x, y] = (double) args[0]; | ||
578 | CheckForTerrainUpdates(); | ||
579 | } | ||
580 | |||
581 | private void InterfaceShowDebugStats(Object[] args) | ||
582 | { | ||
583 | double max = Double.MinValue; | ||
584 | double min = double.MaxValue; | ||
585 | double avg; | ||
586 | double sum = 0; | ||
587 | |||
588 | int x; | ||
589 | for (x = 0; x < m_channel.Width; x++) | ||
590 | { | ||
591 | int y; | ||
592 | for (y = 0; y < m_channel.Height; y++) | ||
593 | { | ||
594 | sum += m_channel[x, y]; | ||
595 | if (max < m_channel[x, y]) | ||
596 | max = m_channel[x, y]; | ||
597 | if (min > m_channel[x, y]) | ||
598 | min = m_channel[x, y]; | ||
599 | } | ||
600 | } | ||
601 | |||
602 | avg = sum / (m_channel.Height * m_channel.Width); | ||
603 | |||
604 | m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height); | ||
605 | m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum); | ||
606 | } | ||
607 | |||
608 | private void InterfaceEnableExperimentalBrushes(Object[] args) | ||
609 | { | ||
610 | if ((bool) args[0]) | ||
611 | { | ||
612 | m_painteffects[StandardTerrainEffects.Revert] = new WeatherSphere(); | ||
613 | m_painteffects[StandardTerrainEffects.Flatten] = new OlsenSphere(); | ||
614 | m_painteffects[StandardTerrainEffects.Smooth] = new ErodeSphere(); | ||
615 | } | ||
616 | else | ||
617 | { | ||
618 | InstallDefaultEffects(); | ||
619 | } | ||
620 | } | ||
621 | |||
622 | private void InterfaceRunPluginEffect(Object[] args) | ||
623 | { | ||
624 | if ((string) args[0] == "list") | ||
625 | { | ||
626 | m_log.Info("List of loaded plugins"); | ||
627 | foreach (KeyValuePair<string, ITerrainEffect> kvp in m_plugineffects) | ||
628 | { | ||
629 | m_log.Info(kvp.Key); | ||
630 | } | ||
631 | return; | ||
632 | } | ||
633 | if ((string) args[0] == "reload") | ||
634 | { | ||
635 | LoadPlugins(); | ||
636 | return; | ||
637 | } | ||
638 | if (m_plugineffects.ContainsKey((string) args[0])) | ||
639 | { | ||
640 | m_plugineffects[(string) args[0]].RunEffect(m_channel); | ||
641 | CheckForTerrainUpdates(); | ||
642 | } | ||
643 | else | ||
644 | { | ||
645 | m_log.Warn("No such plugin effect loaded."); | ||
646 | } | ||
647 | } | ||
648 | |||
649 | private void InstallInterfaces() | ||
650 | { | ||
651 | // Load / Save | ||
652 | string supportedFileExtensions = ""; | ||
653 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
654 | supportedFileExtensions += " " + loader.Key + " (" + loader.Value + ")"; | ||
655 | |||
656 | Command loadFromFileCommand = | ||
657 | new Command("load", InterfaceLoadFile, "Loads a terrain from a specified file."); | ||
658 | loadFromFileCommand.AddArgument("filename", | ||
659 | "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + | ||
660 | supportedFileExtensions, "String"); | ||
661 | |||
662 | Command saveToFileCommand = | ||
663 | new Command("save", InterfaceSaveFile, "Saves the current heightmap to a specified file."); | ||
664 | saveToFileCommand.AddArgument("filename", | ||
665 | "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " + | ||
666 | supportedFileExtensions, "String"); | ||
667 | |||
668 | Command loadFromTileCommand = | ||
669 | new Command("load-tile", InterfaceLoadTileFile, "Loads a terrain from a section of a larger file."); | ||
670 | loadFromTileCommand.AddArgument("filename", | ||
671 | "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + | ||
672 | supportedFileExtensions, "String"); | ||
673 | loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer"); | ||
674 | loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer"); | ||
675 | loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file", | ||
676 | "Integer"); | ||
677 | loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", | ||
678 | "Integer"); | ||
679 | |||
680 | // Terrain adjustments | ||
681 | Command fillRegionCommand = | ||
682 | new Command("fill", InterfaceFillTerrain, "Fills the current heightmap with a specified value."); | ||
683 | fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.", | ||
684 | "Double"); | ||
685 | |||
686 | Command elevateCommand = | ||
687 | new Command("elevate", InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); | ||
688 | elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double"); | ||
689 | |||
690 | Command lowerCommand = | ||
691 | new Command("lower", InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); | ||
692 | lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double"); | ||
693 | |||
694 | Command multiplyCommand = | ||
695 | new Command("multiply", InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); | ||
696 | multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); | ||
697 | |||
698 | Command bakeRegionCommand = | ||
699 | new Command("bake", InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); | ||
700 | Command revertRegionCommand = | ||
701 | new Command("revert", InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); | ||
702 | |||
703 | // Debug | ||
704 | Command showDebugStatsCommand = | ||
705 | new Command("stats", InterfaceShowDebugStats, | ||
706 | "Shows some information about the regions heightmap for debugging purposes."); | ||
707 | |||
708 | Command experimentalBrushesCommand = | ||
709 | new Command("newbrushes", InterfaceEnableExperimentalBrushes, | ||
710 | "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); | ||
711 | experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); | ||
712 | |||
713 | //Plugins | ||
714 | Command pluginRunCommand = | ||
715 | new Command("effect", InterfaceRunPluginEffect, "Runs a specified plugin effect"); | ||
716 | pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String"); | ||
717 | |||
718 | m_commander.RegisterCommand("load", loadFromFileCommand); | ||
719 | m_commander.RegisterCommand("load-tile", loadFromTileCommand); | ||
720 | m_commander.RegisterCommand("save", saveToFileCommand); | ||
721 | m_commander.RegisterCommand("fill", fillRegionCommand); | ||
722 | m_commander.RegisterCommand("elevate", elevateCommand); | ||
723 | m_commander.RegisterCommand("lower", lowerCommand); | ||
724 | m_commander.RegisterCommand("multiply", multiplyCommand); | ||
725 | m_commander.RegisterCommand("bake", bakeRegionCommand); | ||
726 | m_commander.RegisterCommand("revert", revertRegionCommand); | ||
727 | m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand); | ||
728 | m_commander.RegisterCommand("stats", showDebugStatsCommand); | ||
729 | m_commander.RegisterCommand("effect", pluginRunCommand); | ||
730 | |||
731 | // Add this to our scene so scripts can call these functions | ||
732 | m_scene.RegisterModuleCommander("Terrain", m_commander); | ||
733 | } | ||
734 | |||
735 | #endregion | ||
736 | } | ||
737 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs new file mode 100644 index 0000000..b593717 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs | |||
@@ -0,0 +1,133 @@ | |||
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.Environment.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain | ||
32 | { | ||
33 | public static class TerrainUtil | ||
34 | { | ||
35 | public static double MetersToSphericalStrength(double size) | ||
36 | { | ||
37 | return Math.Pow(2, size); | ||
38 | } | ||
39 | |||
40 | public static double SphericalFactor(double x, double y, double rx, double ry, double size) | ||
41 | { | ||
42 | return size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | ||
43 | } | ||
44 | |||
45 | public static double GetBilinearInterpolate(double x, double y, ITerrainChannel map) | ||
46 | { | ||
47 | int w = map.Width; | ||
48 | int h = map.Height; | ||
49 | |||
50 | if (x > w - 2.0) | ||
51 | x = w - 2.0; | ||
52 | if (y > h - 2.0) | ||
53 | y = h - 2.0; | ||
54 | if (x < 0.0) | ||
55 | x = 0.0; | ||
56 | if (y < 0.0) | ||
57 | y = 0.0; | ||
58 | |||
59 | int stepSize = 1; | ||
60 | double h00 = map[(int) x, (int) y]; | ||
61 | double h10 = map[(int) x + stepSize, (int) y]; | ||
62 | double h01 = map[(int) x, (int) y + stepSize]; | ||
63 | double h11 = map[(int) x + stepSize, (int) y + stepSize]; | ||
64 | double h1 = h00; | ||
65 | double h2 = h10; | ||
66 | double h3 = h01; | ||
67 | double h4 = h11; | ||
68 | double a00 = h1; | ||
69 | double a10 = h2 - h1; | ||
70 | double a01 = h3 - h1; | ||
71 | double a11 = h1 - h2 - h3 + h4; | ||
72 | double partialx = x - (int) x; | ||
73 | double partialz = y - (int) y; | ||
74 | double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); | ||
75 | return hi; | ||
76 | } | ||
77 | |||
78 | private static double Noise(double x, double y) | ||
79 | { | ||
80 | int n = (int) x + (int) (y * 749); | ||
81 | n = (n << 13) ^ n; | ||
82 | return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); | ||
83 | } | ||
84 | |||
85 | private static double SmoothedNoise1(double x, double y) | ||
86 | { | ||
87 | double corners = (Noise(x - 1, y - 1) + Noise(x + 1, y - 1) + Noise(x - 1, y + 1) + Noise(x + 1, y + 1)) / 16; | ||
88 | double sides = (Noise(x - 1, y) + Noise(x + 1, y) + Noise(x, y - 1) + Noise(x, y + 1)) / 8; | ||
89 | double center = Noise(x, y) / 4; | ||
90 | return corners + sides + center; | ||
91 | } | ||
92 | |||
93 | private static double Interpolate(double x, double y, double z) | ||
94 | { | ||
95 | return (x * (1.0 - z)) + (y * z); | ||
96 | } | ||
97 | |||
98 | private static double InterpolatedNoise(double x, double y) | ||
99 | { | ||
100 | int integer_X = (int) (x); | ||
101 | double fractional_X = x - integer_X; | ||
102 | |||
103 | int integer_Y = (int) y; | ||
104 | double fractional_Y = y - integer_Y; | ||
105 | |||
106 | double v1 = SmoothedNoise1(integer_X, integer_Y); | ||
107 | double v2 = SmoothedNoise1(integer_X + 1, integer_Y); | ||
108 | double v3 = SmoothedNoise1(integer_X, integer_Y + 1); | ||
109 | double v4 = SmoothedNoise1(integer_X + 1, integer_Y + 1); | ||
110 | |||
111 | double i1 = Interpolate(v1, v2, fractional_X); | ||
112 | double i2 = Interpolate(v3, v4, fractional_X); | ||
113 | |||
114 | return Interpolate(i1, i2, fractional_Y); | ||
115 | } | ||
116 | |||
117 | public static double PerlinNoise2D(double x, double y, int octaves, double persistence) | ||
118 | { | ||
119 | double frequency = 0.0; | ||
120 | double amplitude = 0.0; | ||
121 | double total = 0.0; | ||
122 | |||
123 | for (int i = 0; i < octaves; i++) | ||
124 | { | ||
125 | frequency = Math.Pow(2, i); | ||
126 | amplitude = Math.Pow(persistence, i); | ||
127 | |||
128 | total += InterpolatedNoise(x * frequency, y * frequency) * amplitude; | ||
129 | } | ||
130 | return total; | ||
131 | } | ||
132 | } | ||
133 | } \ No newline at end of file | ||