ODEModule.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Reflection;
  3. using log4net;
  4. using Nini.Config;
  5. using Mono.Addins;
  6. using OpenSim.Framework;
  7. using OpenSim.Region.Framework.Scenes;
  8. using OpenSim.Region.Framework.Interfaces;
  9. namespace OpenSim.Region.PhysicsModule.ODE
  10. {
  11. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ODEPhysicsScene")]
  12. public class OdeModule : INonSharedRegionModule
  13. {
  14. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  15. private bool m_Enabled = false;
  16. private IConfigSource m_config;
  17. private OdeScene m_scene;
  18. #region INonSharedRegionModule
  19. public string Name
  20. {
  21. get { return "OpenDynamicsEngine"; }
  22. }
  23. public string Version
  24. {
  25. get { return "1.0"; }
  26. }
  27. public Type ReplaceableInterface
  28. {
  29. get { return null; }
  30. }
  31. public void Initialise(IConfigSource source)
  32. {
  33. IConfig config = source.Configs["Startup"];
  34. if (config != null)
  35. {
  36. string physics = config.GetString("physics", string.Empty);
  37. if (physics == Name)
  38. {
  39. m_config = source;
  40. string mesher = config.GetString("meshing", string.Empty);
  41. if (string.IsNullOrEmpty(mesher) || !mesher.Equals("Meshmerizer"))
  42. {
  43. m_log.Error("[ODE] Opensim.ini meshing option must be set to \"Meshmerizer\"");
  44. throw new Exception("Invalid physics meshing option");
  45. }
  46. m_Enabled = true;
  47. }
  48. }
  49. }
  50. public void Close()
  51. {
  52. }
  53. public void AddRegion(Scene scene)
  54. {
  55. if (!m_Enabled)
  56. return;
  57. if (Util.IsWindows())
  58. Util.LoadArchSpecificWindowsDll("ubode.dll");
  59. // Initializing ODE only when a scene is created allows alternative ODE plugins to co-habit (according to
  60. // http://opensimulator.org/mantis/view.php?id=2750).
  61. OdeNative.InitODE();
  62. m_scene = new OdeScene(scene, m_config, Name, Version);
  63. }
  64. public void RemoveRegion(Scene scene)
  65. {
  66. if (!m_Enabled || m_scene == null)
  67. return;
  68. m_scene.Dispose();
  69. m_scene = null;
  70. }
  71. public void RegionLoaded(Scene scene)
  72. {
  73. if (!m_Enabled || m_scene == null)
  74. return;
  75. m_scene.RegionLoaded();
  76. }
  77. #endregion
  78. }
  79. }