aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Terrain/Modifiers
diff options
context:
space:
mode:
authorDev Random2015-05-07 13:25:36 -0400
committerMichael Cerquoni2015-05-07 14:07:50 -0400
commita9dd3028b94b35fb9c504b05466522cd2f9be306 (patch)
treef9fa49f5887654feec670d1633b265d8a0866c56 /OpenSim/Region/CoreModules/World/Terrain/Modifiers
parent'terrain modify' command for area-of-effect operations (diff)
downloadopensim-SC_OLD-a9dd3028b94b35fb9c504b05466522cd2f9be306.zip
opensim-SC_OLD-a9dd3028b94b35fb9c504b05466522cd2f9be306.tar.gz
opensim-SC_OLD-a9dd3028b94b35fb9c504b05466522cd2f9be306.tar.bz2
opensim-SC_OLD-a9dd3028b94b35fb9c504b05466522cd2f9be306.tar.xz
Add 'terrain modify noise' and code cleanup
Signed-off-by: Michael Cerquoni <nebadon2025@gmail.com>
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Terrain/Modifiers')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs110
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs4
2 files changed, 112 insertions, 2 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs
new file mode 100644
index 0000000..b31bab1
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs
@@ -0,0 +1,110 @@
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 OpenSimulator 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 */
27using System;
28using OpenSim.Region.CoreModules.World.Terrain;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers
33{
34 public class NoiseModifier : TerrainModifier
35 {
36 public NoiseModifier(ITerrainModule module) : base(module)
37 {
38 }
39
40 public override string ModifyTerrain(ITerrainChannel map, string[] args)
41 {
42 string val;
43 string result;
44 if (args.Length < 3)
45 {
46 result = "Usage: " + GetUsage();
47 }
48 else
49 {
50 TerrainModifierData data;
51 result = this.parseParameters(args, out data);
52
53 // Context-specific validation
54 if (result == String.Empty)
55 {
56 if (data.bevel == "taper")
57 {
58 if (data.bevelevation < 0.0 || data.bevelevation > 1.0)
59 {
60 result = String.Format("Taper must be 0.0 to 1.0: {0}", data.bevelevation);
61 }
62 }
63 else
64 {
65 data.bevelevation = 1.0f;
66 }
67
68 if (data.elevation < 0.0 || data.elevation > 1.0)
69 {
70 result = String.Format("Noise strength must be 0.0 to 1.0: {0}", data.elevation);
71 }
72
73 if (data.shape == String.Empty)
74 {
75 data.shape = "rectangle";
76 data.x0 = 0;
77 data.y0 = 0;
78 data.dx = map.Width;
79 data.dy = map.Height;
80 }
81 }
82
83 // if it's all good, then do the work
84 if (result == String.Empty)
85 {
86 this.applyModification(map, data);
87 }
88 }
89
90 return result;
91 }
92
93 public override string GetUsage()
94 {
95 string val = "noise <delta> [ -rec=x1,y1,dx[,dy] | -ell=x0,y0,rx[,ry] ] [-taper=<delta2>]"
96 + "\nAdds noise to all points within the specified range.";
97 return val;
98 }
99
100 public override double operate(double[,] map, TerrainModifierData data, int x, int y)
101 {
102 double factor = this.computeBevel(data, x, y);
103 double noise = TerrainUtil.PerlinNoise2D((double)x / map.GetLength(0), (double)y / map.GetLength(1), 8, 1.0);
104 return map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor) * (noise - .5);
105 }
106
107 }
108
109}
110
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs
index 1731cd8..72b172c 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs
@@ -56,7 +56,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers
56 { 56 {
57 if (data.bevelevation < 0.01 || data.bevelevation > 0.99) 57 if (data.bevelevation < 0.01 || data.bevelevation > 0.99)
58 { 58 {
59 result = String.Format("Taper must be 0.01 to 0.99 {0}", data.bevelevation); 59 result = String.Format("Taper must be 0.01 to 0.99: {0}", data.bevelevation);
60 } 60 }
61 } 61 }
62 else 62 else
@@ -66,7 +66,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers
66 66
67 if (data.elevation < 0.0 || data.elevation > 1.0) 67 if (data.elevation < 0.0 || data.elevation > 1.0)
68 { 68 {
69 result = String.Format("Scaling factor must be 0.0 to 1.0: {0}", data.elevation); 69 result = String.Format("Smoothing strength must be 0.0 to 1.0: {0}", data.elevation);
70 } 70 }
71 71
72 if (data.shape == String.Empty) 72 if (data.shape == String.Empty)