aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:22:29 +0000
committerAdam Frisby2008-04-30 21:22:29 +0000
commit4a8c1e4393ac64c84b03aeb16bacb9ddd0a2fae6 (patch)
tree49dde0575502e89aeed428b4190c68306e929b69 /OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
parent* Previous commit managed to miss some files despite me hitting 'Select all'. (diff)
downloadopensim-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 '')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs737
1 files changed, 737 insertions, 0 deletions
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using libsecondlife;
33using log4net;
34using Nini.Config;
35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Modules.Framework;
38using OpenSim.Region.Environment.Modules.World.Terrain;
39using OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders;
40using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes;
41using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes;
42using OpenSim.Region.Environment.Scenes;
43
44namespace 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