TerrainModule.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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 System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using libsecondlife;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Environment.Interfaces;
  36. using OpenSim.Region.Environment.Modules.Framework;
  37. using OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders;
  38. using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes;
  39. using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes;
  40. using OpenSim.Region.Environment.Scenes;
  41. namespace OpenSim.Region.Environment.Modules.World.Terrain
  42. {
  43. public class TerrainModule : IRegionModule, ICommandableModule, ITerrainModule
  44. {
  45. #region StandardTerrainEffects enum
  46. /// <summary>
  47. /// A standard set of terrain brushes and effects recognised by viewers
  48. /// </summary>
  49. public enum StandardTerrainEffects : byte
  50. {
  51. Flatten = 0,
  52. Raise = 1,
  53. Lower = 2,
  54. Smooth = 3,
  55. Noise = 4,
  56. Revert = 5,
  57. // Extended brushes
  58. Erode = 255,
  59. Weather = 254,
  60. Olsen = 253
  61. }
  62. #endregion
  63. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  64. private readonly Commander m_commander = new Commander("Terrain");
  65. private readonly Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects =
  66. new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>();
  67. private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
  68. private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects =
  69. new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
  70. private ITerrainChannel m_channel;
  71. private Dictionary<Location, ITerrainChannel> m_channels;
  72. private Dictionary<string, ITerrainEffect> m_plugineffects;
  73. private ITerrainChannel m_revert;
  74. private Scene m_scene;
  75. private bool m_tainted = false;
  76. #region ICommandableModule Members
  77. public ICommander CommandInterface
  78. {
  79. get { return m_commander; }
  80. }
  81. #endregion
  82. #region IRegionModule Members
  83. /// <summary>
  84. /// Creates and initialises a terrain module for a region
  85. /// </summary>
  86. /// <param name="scene">Region initialising</param>
  87. /// <param name="config">Config for the region</param>
  88. public void Initialise(Scene scene, IConfigSource config)
  89. {
  90. m_scene = scene;
  91. // Install terrain module in the simulator
  92. if (m_scene.Heightmap == null)
  93. {
  94. lock (m_scene)
  95. {
  96. m_channel = new TerrainChannel();
  97. m_scene.Heightmap = m_channel;
  98. m_revert = new TerrainChannel();
  99. UpdateRevertMap();
  100. }
  101. }
  102. else
  103. {
  104. m_channel = m_scene.Heightmap;
  105. m_revert = new TerrainChannel();
  106. UpdateRevertMap();
  107. }
  108. m_scene.RegisterModuleInterface<ITerrainModule>(this);
  109. m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
  110. m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
  111. m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
  112. }
  113. /// <summary>
  114. /// Enables terrain module when called
  115. /// </summary>
  116. public void PostInitialise()
  117. {
  118. InstallDefaultEffects();
  119. InstallInterfaces();
  120. LoadPlugins();
  121. }
  122. public void Close()
  123. {
  124. }
  125. public string Name
  126. {
  127. get { return "TerrainModule"; }
  128. }
  129. public bool IsSharedModule
  130. {
  131. get { return false; }
  132. }
  133. #endregion
  134. #region ITerrainModule Members
  135. /// <summary>
  136. /// Loads a terrain file from disk and installs it in the scene.
  137. /// </summary>
  138. /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
  139. public void LoadFromFile(string filename)
  140. {
  141. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  142. {
  143. if (filename.EndsWith(loader.Key))
  144. {
  145. lock (m_scene)
  146. {
  147. try
  148. {
  149. ITerrainChannel channel = loader.Value.LoadFile(filename);
  150. m_scene.Heightmap = channel;
  151. m_channel = channel;
  152. UpdateRevertMap();
  153. }
  154. catch (NotImplementedException)
  155. {
  156. m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value +
  157. " parser does not support file loading. (May be save only)");
  158. throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value));
  159. }
  160. catch (FileNotFoundException)
  161. {
  162. m_log.Error(
  163. "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)");
  164. throw new TerrainException(
  165. String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", filename));
  166. }
  167. }
  168. CheckForTerrainUpdates();
  169. m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
  170. return;
  171. }
  172. }
  173. m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format.");
  174. throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
  175. }
  176. /// <summary>
  177. /// Saves the current heightmap to a specified file.
  178. /// </summary>
  179. /// <param name="filename">The destination filename</param>
  180. public void SaveToFile(string filename)
  181. {
  182. try
  183. {
  184. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  185. {
  186. if (filename.EndsWith(loader.Key))
  187. {
  188. loader.Value.SaveFile(filename, m_channel);
  189. return;
  190. }
  191. }
  192. }
  193. catch (NotImplementedException)
  194. {
  195. m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented.");
  196. throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented"));
  197. }
  198. }
  199. #region Plugin Loading Methods
  200. private void LoadPlugins()
  201. {
  202. m_plugineffects = new Dictionary<string, ITerrainEffect>();
  203. // Load the files in the Terrain/ dir
  204. string[] files = Directory.GetFiles("Terrain");
  205. foreach (string file in files)
  206. {
  207. m_log.Info("Loading effects in " + file);
  208. try
  209. {
  210. Assembly library = Assembly.LoadFrom(file);
  211. foreach (Type pluginType in library.GetTypes())
  212. {
  213. try
  214. {
  215. if (pluginType.IsAbstract || pluginType.IsNotPublic)
  216. continue;
  217. if (pluginType.GetInterface("ITerrainEffect", false) != null)
  218. {
  219. ITerrainEffect terEffect = (ITerrainEffect) Activator.CreateInstance(library.GetType(pluginType.ToString()));
  220. if (!m_plugineffects.ContainsKey(pluginType.Name))
  221. {
  222. m_plugineffects.Add(pluginType.Name, terEffect);
  223. m_log.Info("E ... " + pluginType.Name);
  224. }
  225. else
  226. {
  227. m_log.Warn("E ... " + pluginType.Name + " (Already added)");
  228. }
  229. }
  230. else if (pluginType.GetInterface("ITerrainLoader", false) != null)
  231. {
  232. ITerrainLoader terLoader = (ITerrainLoader) Activator.CreateInstance(library.GetType(pluginType.ToString()));
  233. m_loaders[terLoader.FileExtension] = terLoader;
  234. m_log.Info("L ... " + pluginType.Name);
  235. }
  236. }
  237. catch (AmbiguousMatchException)
  238. {
  239. }
  240. }
  241. }
  242. catch (BadImageFormatException)
  243. {
  244. }
  245. }
  246. }
  247. #endregion
  248. #endregion
  249. /// <summary>
  250. /// Installs into terrain module the standard suite of brushes
  251. /// </summary>
  252. private void InstallDefaultEffects()
  253. {
  254. // Draggable Paint Brush Effects
  255. m_painteffects[StandardTerrainEffects.Raise] = new RaiseSphere();
  256. m_painteffects[StandardTerrainEffects.Lower] = new LowerSphere();
  257. m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere();
  258. m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere();
  259. m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere();
  260. m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert);
  261. m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere();
  262. m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere();
  263. m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere();
  264. // Area of effect selection effects
  265. m_floodeffects[StandardTerrainEffects.Raise] = new RaiseArea();
  266. m_floodeffects[StandardTerrainEffects.Lower] = new LowerArea();
  267. m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea();
  268. m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea();
  269. m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea();
  270. m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert);
  271. // Filesystem load/save loaders
  272. m_loaders[".r32"] = new RAW32();
  273. m_loaders[".f32"] = m_loaders[".r32"];
  274. m_loaders[".ter"] = new Terragen();
  275. m_loaders[".raw"] = new LLRAW();
  276. m_loaders[".jpg"] = new JPEG();
  277. m_loaders[".jpeg"] = m_loaders[".jpg"];
  278. m_loaders[".bmp"] = new BMP();
  279. m_loaders[".png"] = new PNG();
  280. m_loaders[".gif"] = new GIF();
  281. m_loaders[".tif"] = new TIFF();
  282. m_loaders[".tiff"] = m_loaders[".tif"];
  283. }
  284. /// <summary>
  285. /// Saves the current state of the region into the revert map buffer.
  286. /// </summary>
  287. public void UpdateRevertMap()
  288. {
  289. int x;
  290. for (x = 0; x < m_channel.Width; x++)
  291. {
  292. int y;
  293. for (y = 0; y < m_channel.Height; y++)
  294. {
  295. m_revert[x, y] = m_channel[x, y];
  296. }
  297. }
  298. }
  299. /// <summary>
  300. /// Loads a tile from a larger terrain file and installs it into the region.
  301. /// </summary>
  302. /// <param name="filename">The terrain file to load</param>
  303. /// <param name="fileWidth">The width of the file in units</param>
  304. /// <param name="fileHeight">The height of the file in units</param>
  305. /// <param name="fileStartX">Where to begin our slice</param>
  306. /// <param name="fileStartY">Where to begin our slice</param>
  307. public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
  308. {
  309. int offsetX = (int) m_scene.RegionInfo.RegionLocX - fileStartX;
  310. int offsetY = (int) m_scene.RegionInfo.RegionLocY - fileStartY;
  311. if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight)
  312. {
  313. // this region is included in the tile request
  314. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  315. {
  316. if (filename.EndsWith(loader.Key))
  317. {
  318. lock (m_scene)
  319. {
  320. ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY,
  321. fileWidth, fileHeight,
  322. (int) Constants.RegionSize,
  323. (int) Constants.RegionSize);
  324. m_scene.Heightmap = channel;
  325. m_channel = channel;
  326. UpdateRevertMap();
  327. }
  328. return;
  329. }
  330. }
  331. }
  332. }
  333. /// <summary>
  334. /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections
  335. /// </summary>
  336. private void EventManager_OnTerrainTick()
  337. {
  338. if (m_tainted)
  339. {
  340. m_tainted = false;
  341. m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised());
  342. m_scene.SaveTerrain();
  343. m_scene.CreateTerrainTexture(true);
  344. }
  345. }
  346. /// <summary>
  347. /// Processes commandline input. Do not call directly.
  348. /// </summary>
  349. /// <param name="args">Commandline arguments</param>
  350. private void EventManager_OnPluginConsole(string[] args)
  351. {
  352. if (args[0] == "terrain")
  353. {
  354. string[] tmpArgs = new string[args.Length - 2];
  355. int i;
  356. for (i = 2; i < args.Length; i++)
  357. tmpArgs[i - 2] = args[i];
  358. m_commander.ProcessConsoleCommand(args[1], tmpArgs);
  359. }
  360. }
  361. /// <summary>
  362. /// Installs terrain brush hook to IClientAPI
  363. /// </summary>
  364. /// <param name="client"></param>
  365. private void EventManager_OnNewClient(IClientAPI client)
  366. {
  367. client.OnModifyTerrain += client_OnModifyTerrain;
  368. }
  369. /// <summary>
  370. /// Checks to see if the terrain has been modified since last check
  371. /// </summary>
  372. private void CheckForTerrainUpdates()
  373. {
  374. bool shouldTaint = false;
  375. float[] serialised = m_channel.GetFloatsSerialised();
  376. int x;
  377. for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
  378. {
  379. int y;
  380. for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize)
  381. {
  382. if (m_channel.Tainted(x, y))
  383. {
  384. SendToClients(serialised, x, y);
  385. shouldTaint = true;
  386. }
  387. }
  388. }
  389. if (shouldTaint)
  390. {
  391. m_tainted = true;
  392. }
  393. }
  394. /// <summary>
  395. /// Sends a copy of the current terrain to the scenes clients
  396. /// </summary>
  397. /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param>
  398. /// <param name="x">The patch corner to send</param>
  399. /// <param name="y">The patch corner to send</param>
  400. private void SendToClients(float[] serialised, int x, int y)
  401. {
  402. m_scene.ForEachClient(
  403. delegate(IClientAPI controller) { controller.SendLayerData(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised); });
  404. }
  405. private void client_OnModifyTerrain(float height, float seconds, byte size, byte action, float north, float west,
  406. float south, float east, IClientAPI remoteClient)
  407. {
  408. // Not a good permissions check, if in area mode, need to check the entire area.
  409. if (m_scene.PermissionsMngr.CanTerraform(remoteClient.AgentId, new LLVector3(north, west, 0)))
  410. {
  411. if (north == south && east == west)
  412. {
  413. if (m_painteffects.ContainsKey((StandardTerrainEffects) action))
  414. {
  415. m_painteffects[(StandardTerrainEffects) action].PaintEffect(
  416. m_channel, west, south, size, seconds);
  417. CheckForTerrainUpdates();
  418. }
  419. else
  420. {
  421. m_log.Debug("Unknown terrain brush type " + action);
  422. }
  423. }
  424. else
  425. {
  426. if (m_floodeffects.ContainsKey((StandardTerrainEffects) action))
  427. {
  428. bool[,] fillArea = new bool[m_channel.Width,m_channel.Height];
  429. fillArea.Initialize();
  430. int x;
  431. for (x = 0; x < m_channel.Width; x++)
  432. {
  433. int y;
  434. for (y = 0; y < m_channel.Height; y++)
  435. {
  436. if (x < east && x > west)
  437. {
  438. if (y < north && y > south)
  439. {
  440. fillArea[x, y] = true;
  441. }
  442. }
  443. }
  444. }
  445. m_floodeffects[(StandardTerrainEffects) action].FloodEffect(
  446. m_channel, fillArea, size);
  447. CheckForTerrainUpdates();
  448. }
  449. else
  450. {
  451. m_log.Debug("Unknown terrain flood type " + action);
  452. }
  453. }
  454. }
  455. }
  456. #region Console Commands
  457. private void InterfaceLoadFile(Object[] args)
  458. {
  459. LoadFromFile((string) args[0]);
  460. CheckForTerrainUpdates();
  461. }
  462. private void InterfaceLoadTileFile(Object[] args)
  463. {
  464. LoadFromFile((string) args[0],
  465. (int) args[1],
  466. (int) args[2],
  467. (int) args[3],
  468. (int) args[4]);
  469. CheckForTerrainUpdates();
  470. }
  471. private void InterfaceSaveFile(Object[] args)
  472. {
  473. SaveToFile((string) args[0]);
  474. }
  475. private void InterfaceBakeTerrain(Object[] args)
  476. {
  477. UpdateRevertMap();
  478. }
  479. private void InterfaceRevertTerrain(Object[] args)
  480. {
  481. int x, y;
  482. for (x = 0; x < m_channel.Width; x++)
  483. for (y = 0; y < m_channel.Height; y++)
  484. m_channel[x, y] = m_revert[x, y];
  485. CheckForTerrainUpdates();
  486. }
  487. private void InterfaceElevateTerrain(Object[] args)
  488. {
  489. int x, y;
  490. for (x = 0; x < m_channel.Width; x++)
  491. for (y = 0; y < m_channel.Height; y++)
  492. m_channel[x, y] += (double) args[0];
  493. CheckForTerrainUpdates();
  494. }
  495. private void InterfaceMultiplyTerrain(Object[] args)
  496. {
  497. int x, y;
  498. for (x = 0; x < m_channel.Width; x++)
  499. for (y = 0; y < m_channel.Height; y++)
  500. m_channel[x, y] *= (double) args[0];
  501. CheckForTerrainUpdates();
  502. }
  503. private void InterfaceLowerTerrain(Object[] args)
  504. {
  505. int x, y;
  506. for (x = 0; x < m_channel.Width; x++)
  507. for (y = 0; y < m_channel.Height; y++)
  508. m_channel[x, y] -= (double) args[0];
  509. CheckForTerrainUpdates();
  510. }
  511. private void InterfaceFillTerrain(Object[] args)
  512. {
  513. int x, y;
  514. for (x = 0; x < m_channel.Width; x++)
  515. for (y = 0; y < m_channel.Height; y++)
  516. m_channel[x, y] = (double) args[0];
  517. CheckForTerrainUpdates();
  518. }
  519. private void InterfaceShowDebugStats(Object[] args)
  520. {
  521. double max = Double.MinValue;
  522. double min = double.MaxValue;
  523. double avg;
  524. double sum = 0;
  525. int x;
  526. for (x = 0; x < m_channel.Width; x++)
  527. {
  528. int y;
  529. for (y = 0; y < m_channel.Height; y++)
  530. {
  531. sum += m_channel[x, y];
  532. if (max < m_channel[x, y])
  533. max = m_channel[x, y];
  534. if (min > m_channel[x, y])
  535. min = m_channel[x, y];
  536. }
  537. }
  538. avg = sum / (m_channel.Height * m_channel.Width);
  539. m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height);
  540. m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum);
  541. }
  542. private void InterfaceEnableExperimentalBrushes(Object[] args)
  543. {
  544. if ((bool) args[0])
  545. {
  546. m_painteffects[StandardTerrainEffects.Revert] = new WeatherSphere();
  547. m_painteffects[StandardTerrainEffects.Flatten] = new OlsenSphere();
  548. m_painteffects[StandardTerrainEffects.Smooth] = new ErodeSphere();
  549. }
  550. else
  551. {
  552. InstallDefaultEffects();
  553. }
  554. }
  555. private void InterfaceRunPluginEffect(Object[] args)
  556. {
  557. if ((string) args[0] == "list")
  558. {
  559. m_log.Info("List of loaded plugins");
  560. foreach (KeyValuePair<string, ITerrainEffect> kvp in m_plugineffects)
  561. {
  562. m_log.Info(kvp.Key);
  563. }
  564. return;
  565. }
  566. if ((string) args[0] == "reload")
  567. {
  568. LoadPlugins();
  569. return;
  570. }
  571. if (m_plugineffects.ContainsKey((string) args[0]))
  572. {
  573. m_plugineffects[(string) args[0]].RunEffect(m_channel);
  574. CheckForTerrainUpdates();
  575. }
  576. else
  577. {
  578. m_log.Warn("No such plugin effect loaded.");
  579. }
  580. }
  581. private void InstallInterfaces()
  582. {
  583. // Load / Save
  584. string supportedFileExtensions = "";
  585. foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
  586. supportedFileExtensions += " " + loader.Key + " (" + loader.Value + ")";
  587. Command loadFromFileCommand =
  588. new Command("load", InterfaceLoadFile, "Loads a terrain from a specified file.");
  589. loadFromFileCommand.AddArgument("filename",
  590. "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " +
  591. supportedFileExtensions, "String");
  592. Command saveToFileCommand =
  593. new Command("save", InterfaceSaveFile, "Saves the current heightmap to a specified file.");
  594. saveToFileCommand.AddArgument("filename",
  595. "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " +
  596. supportedFileExtensions, "String");
  597. Command loadFromTileCommand =
  598. new Command("load-tile", InterfaceLoadTileFile, "Loads a terrain from a section of a larger file.");
  599. loadFromTileCommand.AddArgument("filename",
  600. "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " +
  601. supportedFileExtensions, "String");
  602. loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer");
  603. loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer");
  604. loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file",
  605. "Integer");
  606. loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file",
  607. "Integer");
  608. // Terrain adjustments
  609. Command fillRegionCommand =
  610. new Command("fill", InterfaceFillTerrain, "Fills the current heightmap with a specified value.");
  611. fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.",
  612. "Double");
  613. Command elevateCommand =
  614. new Command("elevate", InterfaceElevateTerrain, "Raises the current heightmap by the specified amount.");
  615. elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double");
  616. Command lowerCommand =
  617. new Command("lower", InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount.");
  618. lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double");
  619. Command multiplyCommand =
  620. new Command("multiply", InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified.");
  621. multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double");
  622. Command bakeRegionCommand =
  623. new Command("bake", InterfaceBakeTerrain, "Saves the current terrain into the regions revert map.");
  624. Command revertRegionCommand =
  625. new Command("revert", InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap.");
  626. // Debug
  627. Command showDebugStatsCommand =
  628. new Command("stats", InterfaceShowDebugStats,
  629. "Shows some information about the regions heightmap for debugging purposes.");
  630. Command experimentalBrushesCommand =
  631. new Command("newbrushes", InterfaceEnableExperimentalBrushes,
  632. "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time.");
  633. experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean");
  634. //Plugins
  635. Command pluginRunCommand =
  636. new Command("effect", InterfaceRunPluginEffect, "Runs a specified plugin effect");
  637. pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String");
  638. m_commander.RegisterCommand("load", loadFromFileCommand);
  639. m_commander.RegisterCommand("load-tile", loadFromTileCommand);
  640. m_commander.RegisterCommand("save", saveToFileCommand);
  641. m_commander.RegisterCommand("fill", fillRegionCommand);
  642. m_commander.RegisterCommand("elevate", elevateCommand);
  643. m_commander.RegisterCommand("lower", lowerCommand);
  644. m_commander.RegisterCommand("multiply", multiplyCommand);
  645. m_commander.RegisterCommand("bake", bakeRegionCommand);
  646. m_commander.RegisterCommand("revert", revertRegionCommand);
  647. m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
  648. m_commander.RegisterCommand("stats", showDebugStatsCommand);
  649. m_commander.RegisterCommand("effect", pluginRunCommand);
  650. // Add this to our scene so scripts can call these functions
  651. m_scene.RegisterModuleCommander("Terrain", m_commander);
  652. }
  653. #endregion
  654. }
  655. }